Add quick action to pick image for selected layer

This commit is contained in:
ChillerDragon 2024-08-05 15:09:02 +08:00
parent f053a29463
commit 2c77aeef2b
4 changed files with 49 additions and 1 deletions

View file

@ -325,6 +325,8 @@ public:
void AddGroup(); void AddGroup();
void AddTileLayer(); void AddTileLayer();
void LayerSelectImage();
bool IsNonGameTileLayerSelected() const;
#define REGISTER_QUICK_ACTION(name, text, callback, disabled, active, button_color, description) CQuickAction m_QuickAction##name; #define REGISTER_QUICK_ACTION(name, text, callback, disabled, active, button_color, description) CQuickAction m_QuickAction##name;
#include <game/editor/quick_actions.h> #include <game/editor/quick_actions.h>
#undef REGISTER_QUICK_ACTION #undef REGISTER_QUICK_ACTION

View file

@ -107,6 +107,9 @@ void CPrompt::OnRender(CUIRect _)
} }
for(auto *pQuickAction : m_vQuickActions) for(auto *pQuickAction : m_vQuickActions)
{ {
if(pQuickAction->Disabled())
continue;
if(m_PromptInput.IsEmpty() || FuzzyMatch(pQuickAction->Label(), m_PromptInput.GetString())) if(m_PromptInput.IsEmpty() || FuzzyMatch(pQuickAction->Label(), m_PromptInput.GetString()))
{ {
bool Skip = false; bool Skip = false;
@ -158,9 +161,9 @@ void CPrompt::OnRender(CUIRect _)
if(m_PromptSelectedIndex >= 0) if(m_PromptSelectedIndex >= 0)
{ {
const CQuickAction *pBtn = m_vpFilteredPromptList[m_PromptSelectedIndex]; const CQuickAction *pBtn = m_vpFilteredPromptList[m_PromptSelectedIndex];
SetInactive();
pBtn->Call(); pBtn->Call();
m_pLastAction = pBtn; m_pLastAction = pBtn;
SetInactive();
} }
} }
} }

View file

@ -1,3 +1,5 @@
#include <game/mapitems.h>
#include "editor.h" #include "editor.h"
#include "editor_actions.h" #include "editor_actions.h"
@ -18,3 +20,36 @@ void CEditor::AddTileLayer()
m_Map.m_vpGroups[m_SelectedGroup]->m_Collapse = false; m_Map.m_vpGroups[m_SelectedGroup]->m_Collapse = false;
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex)); m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
} }
bool CEditor::IsNonGameTileLayerSelected() const
{
std::shared_ptr<CLayer> 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<CLayer> pLayer = GetSelectedLayer(0);
std::shared_ptr<CLayerTiles> pTiles = std::static_pointer_cast<CLayerTiles>(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());
}

View file

@ -45,6 +45,14 @@ REGISTER_QUICK_ACTION(
ALWAYS_FALSE, ALWAYS_FALSE,
DEFAULT_BTN, DEFAULT_BTN,
"Load a new image to use in the map") "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 ALWAYS_FALSE
#undef DEFAULT_BTN #undef DEFAULT_BTN