Skip to content

Commit

Permalink
Merge pull request ddnet#9026 from ChillerDragon/pr_qas_add_layers
Browse files Browse the repository at this point in the history
Add quick actions for adding sound, switch, front, tune, speedup and tele layers
  • Loading branch information
def- authored Sep 24, 2024
2 parents 8715a64 + 32d247d commit 09203ae
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 54 deletions.
7 changes: 6 additions & 1 deletion src/game/editor/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,14 @@ class CEditor : public IEditor
bool CanFillGameTiles() const;
void AddQuadOrSound();
void AddGroup();
void AddSoundLayer();
void AddTileLayer();
void AddFrontLayer();
void AddQuadsLayer();
void AddSwitchLayer();
void AddFrontLayer();
void AddTuneLayer();
void AddSpeedupLayer();
void AddTeleLayer();
void DeleteSelectedLayer();
void LayerSelectImage();
bool IsNonGameTileLayerSelected() const;
Expand Down
64 changes: 15 additions & 49 deletions src/game/editor/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
// new tele layer
View.HSplitBottom(5.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewTeleLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewTeleLayerButton, "Add tele layer", 0, &Button, 0, "Creates a new tele layer"))
{
std::shared_ptr<CLayer> pTeleLayer = std::make_shared<CLayerTele>(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
pEditor->m_Map.MakeTeleLayer(pTeleLayer);
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pTeleLayer);
int LayerIndex = pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1;
pEditor->SelectLayer(LayerIndex);
pEditor->m_pBrush->Clear();
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(pEditor, pEditor->m_SelectedGroup, LayerIndex));
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddTeleLayer, pEditor->m_QuickActionAddTeleLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddTeleLayer.Description()))
{
pEditor->m_QuickActionAddTeleLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}
Expand All @@ -498,16 +491,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
// new speedup layer
View.HSplitBottom(5.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewSpeedupLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewSpeedupLayerButton, "Add speedup layer", 0, &Button, 0, "Creates a new speedup layer"))
{
std::shared_ptr<CLayer> pSpeedupLayer = std::make_shared<CLayerSpeedup>(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
pEditor->m_Map.MakeSpeedupLayer(pSpeedupLayer);
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSpeedupLayer);
int LayerIndex = pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1;
pEditor->SelectLayer(LayerIndex);
pEditor->m_pBrush->Clear();
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(pEditor, pEditor->m_SelectedGroup, LayerIndex));
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddSpeedupLayer, pEditor->m_QuickActionAddSpeedupLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddSpeedupLayer.Description()))
{
pEditor->m_QuickActionAddSpeedupLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}
Expand All @@ -517,16 +503,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
// new tune layer
View.HSplitBottom(5.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewTuneLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewTuneLayerButton, "Add tune layer", 0, &Button, 0, "Creates a new tuning layer"))
{
std::shared_ptr<CLayer> pTuneLayer = std::make_shared<CLayerTune>(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
pEditor->m_Map.MakeTuneLayer(pTuneLayer);
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pTuneLayer);
int LayerIndex = pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1;
pEditor->SelectLayer(LayerIndex);
pEditor->m_pBrush->Clear();
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(pEditor, pEditor->m_SelectedGroup, LayerIndex));
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddTuneLayer, pEditor->m_QuickActionAddTuneLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddTuneLayer.Description()))
{
pEditor->m_QuickActionAddTuneLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}
Expand All @@ -548,16 +527,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
// new Switch layer
View.HSplitBottom(5.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewSwitchLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewSwitchLayerButton, "Add switch layer", 0, &Button, 0, "Creates a new switch layer"))
{
std::shared_ptr<CLayer> pSwitchLayer = std::make_shared<CLayerSwitch>(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
pEditor->m_Map.MakeSwitchLayer(pSwitchLayer);
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSwitchLayer);
int LayerIndex = pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1;
pEditor->SelectLayer(LayerIndex);
pEditor->m_pBrush->Clear();
pEditor->m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(pEditor, pEditor->m_SelectedGroup, LayerIndex));
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddSwitchLayer, pEditor->m_QuickActionAddSwitchLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddSwitchLayer.Description()))
{
pEditor->m_QuickActionAddSwitchLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}
}
Expand All @@ -583,15 +555,9 @@ CUi::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View,
// new sound layer
View.HSplitBottom(5.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_NewSoundLayerButton = 0;
if(pEditor->DoButton_Editor(&s_NewSoundLayerButton, "Add sound layer", 0, &Button, 0, "Creates a new sound layer"))
{
std::shared_ptr<CLayer> pSoundLayer = std::make_shared<CLayerSounds>(pEditor);
pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSoundLayer);
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<CEditorActionAddLayer>(pEditor, pEditor->m_SelectedGroup, LayerIndex));
if(pEditor->DoButton_Editor(&pEditor->m_QuickActionAddSoundLayer, pEditor->m_QuickActionAddSoundLayer.Label(), 0, &Button, 0, pEditor->m_QuickActionAddSoundLayer.Description()))
{
pEditor->m_QuickActionAddSoundLayer.Call();
return CUi::POPUP_CLOSE_CURRENT;
}

Expand Down
62 changes: 58 additions & 4 deletions src/game/editor/quick_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ void CEditor::AddGroup()
m_EditorHistory.RecordAction(std::make_shared<CEditorActionGroup>(this, m_SelectedGroup, false));
}

void CEditor::AddSoundLayer()
{
std::shared_ptr<CLayer> pSoundLayer = std::make_shared<CLayerSounds>(this);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pSoundLayer);
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<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddTileLayer()
{
std::shared_ptr<CLayer> pTileLayer = std::make_shared<CLayerTiles>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
Expand All @@ -64,6 +74,27 @@ void CEditor::AddTileLayer()
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddQuadsLayer()
{
std::shared_ptr<CLayer> pQuadLayer = std::make_shared<CLayerQuads>(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<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddSwitchLayer()
{
std::shared_ptr<CLayer> pSwitchLayer = std::make_shared<CLayerSwitch>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
m_Map.MakeSwitchLayer(pSwitchLayer);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pSwitchLayer);
int LayerIndex = m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1;
SelectLayer(LayerIndex);
m_pBrush->Clear();
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddFrontLayer()
{
std::shared_ptr<CLayer> pFrontLayer = std::make_shared<CLayerFront>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
Expand All @@ -75,13 +106,36 @@ void CEditor::AddFrontLayer()
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddQuadsLayer()
void CEditor::AddTuneLayer()
{
std::shared_ptr<CLayer> pQuadLayer = std::make_shared<CLayerQuads>(this);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pQuadLayer);
std::shared_ptr<CLayer> pTuneLayer = std::make_shared<CLayerTune>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
m_Map.MakeTuneLayer(pTuneLayer);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pTuneLayer);
int LayerIndex = m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1;
SelectLayer(LayerIndex);
m_Map.m_vpGroups[m_SelectedGroup]->m_Collapse = false;
m_pBrush->Clear();
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddSpeedupLayer()
{
std::shared_ptr<CLayer> pSpeedupLayer = std::make_shared<CLayerSpeedup>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
m_Map.MakeSpeedupLayer(pSpeedupLayer);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pSpeedupLayer);
int LayerIndex = m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1;
SelectLayer(LayerIndex);
m_pBrush->Clear();
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

void CEditor::AddTeleLayer()
{
std::shared_ptr<CLayer> pTeleLayer = std::make_shared<CLayerTele>(this, m_Map.m_pGameLayer->m_Width, m_Map.m_pGameLayer->m_Height);
m_Map.MakeTeleLayer(pTeleLayer);
m_Map.m_vpGroups[m_SelectedGroup]->AddLayer(pTeleLayer);
int LayerIndex = m_Map.m_vpGroups[m_SelectedGroup]->m_vpLayers.size() - 1;
SelectLayer(LayerIndex);
m_pBrush->Clear();
m_EditorHistory.RecordAction(std::make_shared<CEditorActionAddLayer>(this, m_SelectedGroup, LayerIndex));
}

Expand Down
34 changes: 34 additions & 0 deletions src/game/editor/quick_actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ REGISTER_QUICK_ACTION(
"Toggles proof borders. These borders represent the area that a player can see with default zoom.")
REGISTER_QUICK_ACTION(
AddTileLayer, "Add tile layer", [&]() { AddTileLayer(); }, ALWAYS_FALSE, ALWAYS_FALSE, DEFAULT_BTN, "Creates a new tile layer.")
REGISTER_QUICK_ACTION(
AddSwitchLayer,
"Add switch layer",
[&]() { AddSwitchLayer(); },
[&]() -> bool { return !GetSelectedGroup()->m_GameGroup || m_Map.m_pSwitchLayer; },
ALWAYS_FALSE,
DEFAULT_BTN,
"Creates a new switch layer.")
REGISTER_QUICK_ACTION(
AddTuneLayer,
"Add tune layer",
[&]() { AddTuneLayer(); },
[&]() -> bool { return !GetSelectedGroup()->m_GameGroup || m_Map.m_pTuneLayer; },
ALWAYS_FALSE,
DEFAULT_BTN,
"Creates a new tuning layer.")
REGISTER_QUICK_ACTION(
AddSpeedupLayer,
"Add speedup layer",
[&]() { AddSpeedupLayer(); },
[&]() -> bool { return !GetSelectedGroup()->m_GameGroup || m_Map.m_pSpeedupLayer; },
ALWAYS_FALSE,
DEFAULT_BTN,
"Creates a new speedup layer.")
REGISTER_QUICK_ACTION(
AddTeleLayer,
"Add tele layer",
[&]() { AddTeleLayer(); },
[&]() -> bool { return !GetSelectedGroup()->m_GameGroup || m_Map.m_pTeleLayer; },
ALWAYS_FALSE,
DEFAULT_BTN,
"Creates a new tele layer.")
REGISTER_QUICK_ACTION(
AddFrontLayer,
"Add front layer",
Expand All @@ -179,6 +211,8 @@ REGISTER_QUICK_ACTION(
"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(
AddSoundLayer, "Add sound layer", [&]() { AddSoundLayer(); }, ALWAYS_FALSE, ALWAYS_FALSE, DEFAULT_BTN, "Creates a new sound layer.")
REGISTER_QUICK_ACTION(
SaveAs,
"Save As",
Expand Down

0 comments on commit 09203ae

Please sign in to comment.