Add quick actions for adding quads and sounds

This commit is contained in:
ChillerDragon 2024-09-18 19:52:14 +08:00
parent e72ace24f2
commit 5b9602f97f
4 changed files with 63 additions and 25 deletions

View file

@ -1293,39 +1293,23 @@ void CEditor::DoToolbarLayers(CUIRect ToolBar)
{
TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom);
bool Invoked = false;
static int s_AddItemButton = 0;
if(pLayer->m_Type == LAYERTYPE_QUADS)
{
Invoked = DoButton_Editor(&s_AddItemButton, "Add Quad", 0, &Button, 0, "[ctrl+q] Add a new quad") ||
(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed);
if(DoButton_Editor(&m_QuickActionAddQuad, m_QuickActionAddQuad.Label(), 0, &Button, 0, m_QuickActionAddQuad.Description()) ||
(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed))
{
m_QuickActionAddQuad.Call();
}
}
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{
Invoked = DoButton_Editor(&s_AddItemButton, "Add Sound", 0, &Button, 0, "[ctrl+q] Add a new sound source") ||
(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed);
}
if(Invoked)
{
std::shared_ptr<CLayerGroup> pGroup = GetSelectedGroup();
float aMapping[4];
pGroup->Mapping(aMapping);
int x = aMapping[0] + (aMapping[2] - aMapping[0]) / 2;
int y = aMapping[1] + (aMapping[3] - aMapping[1]) / 2;
if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed)
if(DoButton_Editor(&m_QuickActionAddSound, m_QuickActionAddSound.Label(), 0, &Button, 0, m_QuickActionAddSound.Description()) ||
(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && ModPressed))
{
x += Ui()->MouseWorldX() - (MapView()->GetWorldOffset().x * pGroup->m_ParallaxX / 100) - pGroup->m_OffsetX;
y += Ui()->MouseWorldY() - (MapView()->GetWorldOffset().y * pGroup->m_ParallaxY / 100) - pGroup->m_OffsetY;
m_QuickActionAddSound.Call();
}
if(pLayer->m_Type == LAYERTYPE_QUADS)
m_EditorHistory.Execute(std::make_shared<CEditorActionNewEmptyQuad>(this, m_SelectedGroup, m_vSelectedLayers[0], x, y));
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
m_EditorHistory.Execute(std::make_shared<CEditorActionNewEmptySound>(this, m_SelectedGroup, m_vSelectedLayers[0], x, y));
}
TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom);
}

View file

@ -326,6 +326,7 @@ public:
void FillGameTiles(EGameTileOp FillTile) const;
bool CanFillGameTiles() const;
void AddQuadOrSound();
void AddGroup();
void AddTileLayer();
void AddFrontLayer();

View file

@ -1,3 +1,4 @@
#include <engine/keys.h>
#include <game/mapitems.h>
#include "editor.h"
@ -19,6 +20,32 @@ bool CEditor::CanFillGameTiles() const
return false;
}
void CEditor::AddQuadOrSound()
{
std::shared_ptr<CLayer> pLayer = GetSelectedLayer(0);
if(!pLayer)
return;
if(pLayer->m_Type != LAYERTYPE_QUADS && pLayer->m_Type != LAYERTYPE_SOUNDS)
return;
std::shared_ptr<CLayerGroup> pGroup = GetSelectedGroup();
float aMapping[4];
pGroup->Mapping(aMapping);
int x = aMapping[0] + (aMapping[2] - aMapping[0]) / 2;
int y = aMapping[1] + (aMapping[3] - aMapping[1]) / 2;
if(m_Dialog == DIALOG_NONE && CLineInput::GetActiveInput() == nullptr && Input()->KeyPress(KEY_Q) && Input()->ModifierIsPressed())
{
x += Ui()->MouseWorldX() - (MapView()->GetWorldOffset().x * pGroup->m_ParallaxX / 100) - pGroup->m_OffsetX;
y += Ui()->MouseWorldY() - (MapView()->GetWorldOffset().y * pGroup->m_ParallaxY / 100) - pGroup->m_OffsetY;
}
if(pLayer->m_Type == LAYERTYPE_QUADS)
m_EditorHistory.Execute(std::make_shared<CEditorActionNewEmptyQuad>(this, m_SelectedGroup, m_vSelectedLayers[0], x, y));
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
m_EditorHistory.Execute(std::make_shared<CEditorActionNewEmptySound>(this, m_SelectedGroup, m_vSelectedLayers[0], x, y));
}
void CEditor::AddGroup()
{
m_Map.NewGroup();

View file

@ -292,6 +292,32 @@ REGISTER_QUICK_ACTION(
ALWAYS_FALSE,
DEFAULT_BTN,
"Adjust the map details of the current map.")
REGISTER_QUICK_ACTION(
AddQuad,
"Add Quad",
[&]() { AddQuadOrSound(); },
[&]() -> bool {
std::shared_ptr<CLayer> pLayer = GetSelectedLayer(0);
if(!pLayer)
return false;
return pLayer->m_Type != LAYERTYPE_QUADS;
},
ALWAYS_FALSE,
DEFAULT_BTN,
"[Ctrl+Q] Add a new quad.")
REGISTER_QUICK_ACTION(
AddSound,
"Add Sound",
[&]() { AddQuadOrSound(); },
[&]() -> bool {
std::shared_ptr<CLayer> pLayer = GetSelectedLayer(0);
if(!pLayer)
return false;
return pLayer->m_Type != LAYERTYPE_SOUNDS;
},
ALWAYS_FALSE,
DEFAULT_BTN,
"[Ctrl+Q] Add a new sound source.")
#undef ALWAYS_FALSE
#undef DEFAULT_BTN