From ec6ddc5ef7997e20a54230f9d83f132de6841ca8 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 18 Sep 2024 19:23:11 +0800 Subject: [PATCH] Add quick action "Add quads layer" --- src/game/editor/editor.h | 1 + src/game/editor/popups.cpp | 10 ++-------- src/game/editor/quick_actions.cpp | 10 ++++++++++ src/game/editor/quick_actions.h | 2 ++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 4fe6498ff41..22c518a9b88 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -329,6 +329,7 @@ class CEditor : public IEditor void AddGroup(); void AddTileLayer(); void AddFrontLayer(); + void AddQuadsLayer(); void LayerSelectImage(); bool IsNonGameTileLayerSelected() const; void MapDetails(); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 4acc033d20f..e251ff240db 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -565,15 +565,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, // new quad layer View.HSplitBottom(5.0f, &View, nullptr); View.HSplitBottom(12.0f, &View, &Button); - static int s_NewQuadLayerButton = 0; - if(pEditor->DoButton_Editor(&s_NewQuadLayerButton, "Add quads layer", 0, &Button, 0, "Creates a new quad layer")) + if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddQuadsLayer, pEditor->m_QuickActionAddQuadsLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddQuadsLayer.Description())) { - std::shared_ptr pQuadLayer = std::make_shared(pEditor); - pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pQuadLayer); - int LayerIndex = pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1; - pEditor->SelectLayer(LayerIndex); - pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_Collapse = false; - pEditor->m_EditorHistory.RecordAction(std::make_shared(pEditor, pEditor->m_SelectedGroup, LayerIndex)); + pEditor->m_QuickActionAddQuadsLayer.Call(); return CUi::POPUP_CLOSE_CURRENT; } diff --git a/src/game/editor/quick_actions.cpp b/src/game/editor/quick_actions.cpp index 1ea46c45dc5..deb38fc99bb 100644 --- a/src/game/editor/quick_actions.cpp +++ b/src/game/editor/quick_actions.cpp @@ -48,6 +48,16 @@ void CEditor::AddFrontLayer() m_EditorHistory.RecordAction(std::make_shared(this, m_SelectedGroup, LayerIndex)); } +void CEditor::AddQuadsLayer() +{ + std::shared_ptr pQuadLayer = std::make_shared(this); + m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pQuadLayer); + int LayerIndex = m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1; + SelectLayer(LayerIndex); + m_Map.m_vpGroups[m_SelectedGroup]->m_Collapse = false; + m_EditorHistory.RecordAction(std::make_shared(this, m_SelectedGroup, LayerIndex)); +} + bool CEditor::IsNonGameTileLayerSelected() const { std::shared_ptr pLayer = GetSelectedLayer(0); diff --git a/src/game/editor/quick_actions.h b/src/game/editor/quick_actions.h index cf5d49333b3..46cf117f023 100644 --- a/src/game/editor/quick_actions.h +++ b/src/game/editor/quick_actions.h @@ -177,6 +177,8 @@ REGISTER_QUICK_ACTION( ALWAYS_FALSE, DEFAULT_BTN, "Creates a new item layer.") +REGISTER_QUICK_ACTION( + AddQuadsLayer, "Add quads layer", [&]() { AddQuadsLayer(); }, ALWAYS_FALSE, ALWAYS_FALSE, DEFAULT_BTN, "Creates a new quads layer.") REGISTER_QUICK_ACTION( SaveAs, "Save As",