From 2c77aeef2baa94d6a269af531914ab89987214aa Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 5 Aug 2024 15:09:02 +0800 Subject: [PATCH] Add quick action to pick image for selected layer --- src/game/editor/editor.h | 2 ++ src/game/editor/prompt.cpp | 5 ++++- src/game/editor/quick_actions.cpp | 35 +++++++++++++++++++++++++++++++ src/game/editor/quick_actions.h | 8 +++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 8b5212a1a..5c69cadaf 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -325,6 +325,8 @@ public: void AddGroup(); void AddTileLayer(); + void LayerSelectImage(); + bool IsNonGameTileLayerSelected() const; #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/prompt.cpp b/src/game/editor/prompt.cpp index 213466bf5..4e08852c1 100644 --- a/src/game/editor/prompt.cpp +++ b/src/game/editor/prompt.cpp @@ -107,6 +107,9 @@ void CPrompt::OnRender(CUIRect _) } for(auto *pQuickAction : m_vQuickActions) { + if(pQuickAction->Disabled()) + continue; + if(m_PromptInput.IsEmpty() || FuzzyMatch(pQuickAction->Label(), m_PromptInput.GetString())) { bool Skip = false; @@ -158,9 +161,9 @@ void CPrompt::OnRender(CUIRect _) if(m_PromptSelectedIndex >= 0) { const CQuickAction *pBtn = m_vpFilteredPromptList[m_PromptSelectedIndex]; + SetInactive(); pBtn->Call(); m_pLastAction = pBtn; - SetInactive(); } } } diff --git a/src/game/editor/quick_actions.cpp b/src/game/editor/quick_actions.cpp index b9ced6d57..80b07c787 100644 --- a/src/game/editor/quick_actions.cpp +++ b/src/game/editor/quick_actions.cpp @@ -1,3 +1,5 @@ +#include + #include "editor.h" #include "editor_actions.h" @@ -18,3 +20,36 @@ void CEditor::AddTileLayer() 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); + if(!pLayer) + return false; + if(pLayer->m_Type != LAYERTYPE_TILES) + return false; + if( + pLayer == m_Map.m_pGameLayer || + pLayer == m_Map.m_pFrontLayer || + pLayer == m_Map.m_pSwitchLayer || + pLayer == m_Map.m_pTeleLayer || + pLayer == m_Map.m_pSpeedupLayer || + pLayer == m_Map.m_pTuneLayer) + return false; + + return true; +} + +void CEditor::LayerSelectImage() +{ + if(!IsNonGameTileLayerSelected()) + return; + + std::shared_ptr pLayer = GetSelectedLayer(0); + std::shared_ptr pTiles = std::static_pointer_cast(pLayer); + + static SLayerPopupContext s_LayerPopupContext = {}; + s_LayerPopupContext.m_pEditor = this; + Ui()->DoPopupMenu(&s_LayerPopupContext, Ui()->MouseX(), Ui()->MouseY(), 120, 270, &s_LayerPopupContext, PopupLayer); + PopupSelectImageInvoke(pTiles->m_Image, Ui()->MouseX(), Ui()->MouseY()); +} diff --git a/src/game/editor/quick_actions.h b/src/game/editor/quick_actions.h index d581fd130..8264b0432 100644 --- a/src/game/editor/quick_actions.h +++ b/src/game/editor/quick_actions.h @@ -45,6 +45,14 @@ REGISTER_QUICK_ACTION( ALWAYS_FALSE, DEFAULT_BTN, "Load a new image to use in the map") +REGISTER_QUICK_ACTION( + LayerPropAddImage, + "Layer: Add Image", + [&]() { LayerSelectImage(); }, + [&]() -> bool { return !IsNonGameTileLayerSelected(); }, + ALWAYS_FALSE, + DEFAULT_BTN, + "Pick mapres image for currently selected layer") #undef ALWAYS_FALSE #undef DEFAULT_BTN