Skip to content

Commit

Permalink
Merge pull request ddnet#8985 from ChillerDragon/pr_qa_dl
Browse files Browse the repository at this point in the history
Add quick action "Delete layer"
  • Loading branch information
def- authored Sep 22, 2024
2 parents ec768b2 + 6a2afb6 commit 97a84f9
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 57 deletions.
91 changes: 51 additions & 40 deletions src/game/editor/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,54 @@ std::pair<int, int> CEditor::EnvGetSelectedTimeAndValue() const
return std::pair<int, int>{CurrentTime, CurrentValue};
}

void CEditor::SelectNextLayer()
{
int CurrentLayer = 0;
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = maximum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);

if(m_vSelectedLayers[0] < (int)m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1)
{
SelectLayer(m_vSelectedLayers[0] + 1);
}
else
{
for(size_t Group = m_SelectedGroup + 1; Group < m_Map.m_vpGroups.size(); Group++)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(0, Group);
break;
}
}
}
}

void CEditor::SelectPreviousLayer()
{
int CurrentLayer = std::numeric_limits<int>::max();
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = minimum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);

if(m_vSelectedLayers[0] > 0)
{
SelectLayer(m_vSelectedLayers[0] - 1);
}
else
{
for(int Group = m_SelectedGroup - 1; Group >= 0; Group--)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(m_Map.m_vpGroups[Group]->m_vpLayers.size() - 1, Group);
break;
}
}
}
}

bool CEditor::CallbackOpenMap(const char *pFileName, int StorageType, void *pUser)
{
CEditor *pEditor = (CEditor *)pUser;
Expand Down Expand Up @@ -4195,26 +4243,7 @@ void CEditor::RenderLayers(CUIRect LayersBox)
}
else
{
int CurrentLayer = 0;
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = maximum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);

if(m_vSelectedLayers[0] < (int)m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1)
{
SelectLayer(m_vSelectedLayers[0] + 1);
}
else
{
for(size_t Group = m_SelectedGroup + 1; Group < m_Map.m_vpGroups.size(); Group++)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(0, Group);
break;
}
}
}
SelectNextLayer();
}
s_ScrollToSelectionNext = true;
}
Expand All @@ -4227,27 +4256,9 @@ void CEditor::RenderLayers(CUIRect LayersBox)
}
else
{
int CurrentLayer = std::numeric_limits<int>::max();
for(const auto &Selected : m_vSelectedLayers)
CurrentLayer = minimum(Selected, CurrentLayer);
SelectLayer(CurrentLayer);

if(m_vSelectedLayers[0] > 0)
{
SelectLayer(m_vSelectedLayers[0] - 1);
}
else
{
for(int Group = m_SelectedGroup - 1; Group >= 0; Group--)
{
if(!m_Map.m_vpGroups[Group]->m_vpLayers.empty())
{
SelectLayer(m_Map.m_vpGroups[Group]->m_vpLayers.size() - 1, Group);
break;
}
}
}
SelectPreviousLayer();
}

s_ScrollToSelectionNext = true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/game/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,17 @@ class CEditor : public IEditor
const CMapView *MapView() const { return &m_MapView; }
CLayerSelector *LayerSelector() { return &m_LayerSelector; }

void SelectNextLayer();
void SelectPreviousLayer();

void FillGameTiles(EGameTileOp FillTile) const;
bool CanFillGameTiles() const;
void AddQuadOrSound();
void AddGroup();
void AddTileLayer();
void AddFrontLayer();
void AddQuadsLayer();
void DeleteSelectedLayer();
void LayerSelectImage();
bool IsNonGameTileLayerSelected() const;
void MapDetails();
Expand Down
20 changes: 3 additions & 17 deletions src/game/editor/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,23 +708,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupLayer(void *pContext, CUIRect View,
{
CUIRect DeleteButton;
View.HSplitBottom(12.0f, &View, &DeleteButton);
static int s_DeleteButton = 0;
if(pEditor->DoButton_Editor(&s_DeleteButton, "Delete layer", 0, &DeleteButton, 0, "Deletes the layer"))
{
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionDeleteLayer>(pEditor, pEditor->m_SelectedGroup, pEditor->m_vSelectedLayers[0]));

if(pCurrentLayer == pEditor->m_Map.m_pFrontLayer)
pEditor->m_Map.m_pFrontLayer = nullptr;
if(pCurrentLayer == pEditor->m_Map.m_pTeleLayer)
pEditor->m_Map.m_pTeleLayer = nullptr;
if(pCurrentLayer == pEditor->m_Map.m_pSpeedupLayer)
pEditor->m_Map.m_pSpeedupLayer = nullptr;
if(pCurrentLayer == pEditor->m_Map.m_pSwitchLayer)
pEditor->m_Map.m_pSwitchLayer = nullptr;
if(pCurrentLayer == pEditor->m_Map.m_pTuneLayer)
pEditor->m_Map.m_pTuneLayer = nullptr;
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->DeleteLayer(pEditor->m_vSelectedLayers[0]);

if(pEditor->DoButton_Editor(&pEditor->m_QuickActionDeleteLayer, pEditor->m_QuickActionDeleteLayer.Label(), 0, &DeleteButton, 0, pEditor->m_QuickActionDeleteLayer.Description()))
{
pEditor->m_QuickActionDeleteLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/game/editor/quick_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,28 @@ void CEditor::MapDetails()
PopupMapInfo);
Ui()->SetActiveItem(nullptr);
}

void CEditor::DeleteSelectedLayer()
{
std::shared_ptr<CLayer> pCurrentLayer = GetSelectedLayer(0);
if(!pCurrentLayer)
return;
if(m_Map.m_pGameLayer == pCurrentLayer)
return;

m_EditorHistory.RecordAction(std::make_shared<CEditorActionDeleteLayer>(this, m_SelectedGroup, m_vSelectedLayers[0]));

if(pCurrentLayer == m_Map.m_pFrontLayer)
m_Map.m_pFrontLayer = nullptr;
if(pCurrentLayer == m_Map.m_pTeleLayer)
m_Map.m_pTeleLayer = nullptr;
if(pCurrentLayer == m_Map.m_pSpeedupLayer)
m_Map.m_pSpeedupLayer = nullptr;
if(pCurrentLayer == m_Map.m_pSwitchLayer)
m_Map.m_pSwitchLayer = nullptr;
if(pCurrentLayer == m_Map.m_pTuneLayer)
m_Map.m_pTuneLayer = nullptr;
m_Map.m_vpGroups[m_SelectedGroup]->DeleteLayer(m_vSelectedLayers[0]);

SelectPreviousLayer();
}
13 changes: 13 additions & 0 deletions src/game/editor/quick_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ REGISTER_QUICK_ACTION(
[&]() -> bool { return m_ShowTileInfo == SHOW_TILE_HEXADECIMAL; },
DEFAULT_BTN,
"[Ctrl+Shift+I] Show tile information in hexadecimal.")
REGISTER_QUICK_ACTION(
DeleteLayer,
"Delete layer",
[&]() { DeleteSelectedLayer(); },
[&]() -> bool {
std::shared_ptr<CLayer> pCurrentLayer = GetSelectedLayer(0);
if(!pCurrentLayer)
return true;
return m_Map.m_pGameLayer == pCurrentLayer;
},
ALWAYS_FALSE,
DEFAULT_BTN,
"Deletes the layer.")
REGISTER_QUICK_ACTION(
Pipette,
"Pipette",
Expand Down

0 comments on commit 97a84f9

Please sign in to comment.