From 32e8bb1f054f461ec420a0478445407dbb5d6e2a Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 18 Sep 2024 19:13:29 +0800 Subject: [PATCH] Add quick action "Map details" --- src/game/editor/editor.h | 1 + src/game/editor/popups.cpp | 11 ++--------- src/game/editor/quick_actions.cpp | 18 ++++++++++++++++++ src/game/editor/quick_actions.h | 8 ++++++++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 6206cea25..ab0fb0076 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -330,6 +330,7 @@ public: void AddTileLayer(); void LayerSelectImage(); bool IsNonGameTileLayerSelected() const; + void MapDetails(); #define REGISTER_QUICK_ACTION(name, text, callback, disabled, active, button_color, description) CQuickAction m_QuickAction##name; #include #undef REGISTER_QUICK_ACTION diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index d1f0d8ab3..1dbff38d8 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -32,7 +32,6 @@ CUi::EPopupMenuFunctionResult CEditor::PopupMenuFile(void *pContext, CUIRect Vie static int s_OpenButton = 0; static int s_OpenCurrentMapButton = 0; static int s_AppendButton = 0; - static int s_MapInfoButton = 0; static int s_ExitButton = 0; CUIRect Slot; @@ -115,15 +114,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupMenuFile(void *pContext, CUIRect Vie View.HSplitTop(10.0f, nullptr, &View); View.HSplitTop(12.0f, &Slot, &View); - if(pEditor->DoButton_MenuItem(&s_MapInfoButton, "Map details", 0, &Slot, 0, "Adjust the map details of the current map")) + if(pEditor->DoButton_MenuItem(&pEditor->m_QuickActionMapDetails, pEditor->m_QuickActionMapDetails.Label(), 0, &Slot, 0, pEditor->m_QuickActionMapDetails.Description())) { - const CUIRect *pScreen = pEditor->Ui()->Screen(); - pEditor->m_Map.m_MapInfoTmp.Copy(pEditor->m_Map.m_MapInfo); - static SPopupMenuId s_PopupMapInfoId; - constexpr float PopupWidth = 400.0f; - constexpr float PopupHeight = 170.0f; - pEditor->Ui()->DoPopupMenu(&s_PopupMapInfoId, pScreen->w / 2.0f - PopupWidth / 2.0f, pScreen->h / 2.0f - PopupHeight / 2.0f, PopupWidth, PopupHeight, pEditor, PopupMapInfo); - pEditor->Ui()->SetActiveItem(nullptr); + pEditor->m_QuickActionMapDetails.Call(); return CUi::POPUP_CLOSE_CURRENT; } diff --git a/src/game/editor/quick_actions.cpp b/src/game/editor/quick_actions.cpp index d1a063949..b78e36113 100644 --- a/src/game/editor/quick_actions.cpp +++ b/src/game/editor/quick_actions.cpp @@ -69,3 +69,21 @@ void CEditor::LayerSelectImage() Ui()->DoPopupMenu(&s_LayerPopupContext, Ui()->MouseX(), Ui()->MouseY(), 120, 270, &s_LayerPopupContext, PopupLayer); PopupSelectImageInvoke(pTiles->m_Image, Ui()->MouseX(), Ui()->MouseY()); } + +void CEditor::MapDetails() +{ + const CUIRect *pScreen = Ui()->Screen(); + m_Map.m_MapInfoTmp.Copy(m_Map.m_MapInfo); + static SPopupMenuId s_PopupMapInfoId; + constexpr float PopupWidth = 400.0f; + constexpr float PopupHeight = 170.0f; + Ui()->DoPopupMenu( + &s_PopupMapInfoId, + pScreen->w / 2.0f - PopupWidth / 2.0f, + pScreen->h / 2.0f - PopupHeight / 2.0f, + PopupWidth, + PopupHeight, + this, + PopupMapInfo); + Ui()->SetActiveItem(nullptr); +} diff --git a/src/game/editor/quick_actions.h b/src/game/editor/quick_actions.h index 5e1a04fe8..cafeab44b 100644 --- a/src/game/editor/quick_actions.h +++ b/src/game/editor/quick_actions.h @@ -276,6 +276,14 @@ REGISTER_QUICK_ACTION( [&]() -> bool { return m_ColorPipetteActive; }, DEFAULT_BTN, "[Ctrl+Shift+C] Color pipette. Pick a color from the screen by clicking on it.") +REGISTER_QUICK_ACTION( + MapDetails, + "Map details", + [&]() { MapDetails(); }, + ALWAYS_FALSE, + ALWAYS_FALSE, + DEFAULT_BTN, + "Adjust the map details of the current map.") #undef ALWAYS_FALSE #undef DEFAULT_BTN