Add quick action "Delete layer"

This commit is contained in:
ChillerDragon 2024-09-18 20:22:36 +08:00
parent be74009fbf
commit e5fffb0ab8
4 changed files with 39 additions and 16 deletions

View file

@ -331,6 +331,7 @@ public:
void AddTileLayer();
void AddFrontLayer();
void AddQuadsLayer();
void DeleteSelectedLayer();
void LayerSelectImage();
bool IsNonGameTileLayerSelected() const;
void MapDetails();

View file

@ -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"))
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionDeleteLayer, pEditor->m_QuickActionDeleteLayer.Label(), 0, &DeleteButton, 0, pEditor->m_QuickActionDeleteLayer.Description()))
{
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]);
pEditor->m_QuickActionDeleteLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}

View file

@ -135,3 +135,26 @@ 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]);
}

View file

@ -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",