From c29d4b984c593414cfcd471b142effe7060e35d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 1 Nov 2022 22:29:12 +0100 Subject: [PATCH 1/4] Remove redundant CUIRects, improve find button height Some of the CUIRects were calculated but never used. The height of the "Find empty slot" button is made consistent with the height of the properties shifters. --- src/game/editor/popups.cpp | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index b1cf7884f..36f002e5e 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1508,6 +1508,8 @@ int CEditor::PopupTele(CEditor *pEditor, CUIRect View, void *pContext) View.VSplitRight(15.f, &NumberPicker, &FindEmptySlot); NumberPicker.VSplitRight(2.f, &NumberPicker, nullptr); + FindEmptySlot.HSplitTop(13.0f, &FindEmptySlot, nullptr); + FindEmptySlot.HMargin(1.0f, &FindEmptySlot); // find empty number button { @@ -1567,9 +1569,6 @@ int CEditor::PopupTele(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupSpeedup(CEditor *pEditor, CUIRect View, void *pContext) { - CUIRect Button; - View.HSplitBottom(12.0f, &View, &Button); - enum { PROP_FORCE = 0, @@ -1606,11 +1605,10 @@ int CEditor::PopupSwitch(CEditor *pEditor, CUIRect View, void *pContext) CUIRect NumberPicker; CUIRect FindEmptySlot; - CUIRect DelayPicker; - - View.HSplitMid(&NumberPicker, &DelayPicker); - NumberPicker.VSplitRight(15.f, &NumberPicker, &FindEmptySlot); + View.VSplitRight(15.f, &NumberPicker, &FindEmptySlot); NumberPicker.VSplitRight(2.f, &NumberPicker, nullptr); + FindEmptySlot.HSplitTop(13.0f, &FindEmptySlot, nullptr); + FindEmptySlot.HMargin(1.0f, &FindEmptySlot); // find empty number button { @@ -1676,9 +1674,6 @@ int CEditor::PopupSwitch(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupTune(CEditor *pEditor, CUIRect View, void *pContext) { - CUIRect Button; - View.HSplitBottom(12.0f, &View, &Button); - enum { PROP_TUNE = 0, @@ -1702,12 +1697,6 @@ int CEditor::PopupTune(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupGoto(CEditor *pEditor, CUIRect View, void *pContext) { - CUIRect CoordXPicker; - CUIRect CoordYPicker; - - View.HSplitMid(&CoordXPicker, &CoordYPicker); - CoordXPicker.VSplitRight(2.f, &CoordXPicker, nullptr); - static ColorRGBA s_Color = ColorRGBA(1, 1, 1, 0.5f); enum @@ -1725,7 +1714,7 @@ int CEditor::PopupGoto(CEditor *pEditor, CUIRect View, void *pContext) static int s_aIds[NUM_PROPS] = {0}; int NewVal = 0; - int Prop = pEditor->DoProperties(&CoordXPicker, aProps, s_aIds, &NewVal, s_Color); + int Prop = pEditor->DoProperties(&View, aProps, s_aIds, &NewVal, s_Color); if(Prop == PROP_CoordX) { From 0db4b5fe0cddf59b25fddb607676e6868866ebf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 1 Nov 2022 22:30:56 +0100 Subject: [PATCH 2/4] Refactor border button condition, move button variable The conditions can be combined into one if-statement to better readability. --- src/game/editor/editor.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 3a60964f2..756929ccd 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1112,15 +1112,10 @@ void CEditor::DoToolbar(CUIRect ToolBar) // tile manipulation { - static int s_BorderBut = 0; CLayerTiles *pT = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); - - // no border for tele layer, speedup, front and switch - if(pT && (pT->m_Tele || pT->m_Speedup || pT->m_Switch || pT->m_Front || pT->m_Tune)) - pT = nullptr; - - if(pT) + if(pT && !pT->m_Tele && !pT->m_Speedup && !pT->m_Switch && !pT->m_Front && !pT->m_Tune) { + static int s_BorderBut = 0; TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom); if(DoButton_Ex(&s_BorderBut, "Border", 0, &Button, 0, "Place tiles in a 2-tile wide border at the edges of the layer", IGraphics::CORNER_ALL)) { From 8e9b4ddcd25655b2765370f9f34cfa97864cd672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 1 Nov 2022 22:34:25 +0100 Subject: [PATCH 3/4] Refactor tile details popup height, variable names The height is calculated based on the number of rows and the row height instead of being entirely hardcoded, which makes maintenance easier. The total height of the speedup popup was slightly too large, which is also fixed by this. Variable names and their declaration positions are also refactored. --- src/game/editor/editor.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 756929ccd..cd18b320f 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1127,35 +1127,35 @@ void CEditor::DoToolbar(CUIRect ToolBar) // do tele/tune/switch/speedup button { - int (*pPopupFunc)(CEditor * peditor, CUIRect View, void *pContext) = nullptr; - const char *pButtonName = nullptr; - float Height = 0.0f; CLayerTiles *pS = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); if(pS) { + const char *pButtonName = nullptr; + int (*pfnPopupFunc)(CEditor * pEditor, CUIRect View, void *pContext) = nullptr; + int Rows = 0; if(pS == m_Map.m_pSwitchLayer) { pButtonName = "Switch"; - pPopupFunc = PopupSwitch; - Height = 36; + pfnPopupFunc = PopupSwitch; + Rows = 2; } else if(pS == m_Map.m_pSpeedupLayer) { pButtonName = "Speedup"; - pPopupFunc = PopupSpeedup; - Height = 53; + pfnPopupFunc = PopupSpeedup; + Rows = 3; } else if(pS == m_Map.m_pTuneLayer) { pButtonName = "Tune"; - pPopupFunc = PopupTune; - Height = 23; + pfnPopupFunc = PopupTune; + Rows = 1; } else if(pS == m_Map.m_pTeleLayer) { pButtonName = "Tele"; - pPopupFunc = PopupTele; - Height = 23; + pfnPopupFunc = PopupTele; + Rows = 1; } if(pButtonName != nullptr) @@ -1170,7 +1170,7 @@ void CEditor::DoToolbar(CUIRect ToolBar) static int s_ModifierPopupID = 0; if(!UiPopupExists(&s_ModifierPopupID)) { - UiInvokePopupMenu(&s_ModifierPopupID, 0, Button.x, Button.y + Button.h, 120, Height, pPopupFunc); + UiInvokePopupMenu(&s_ModifierPopupID, 0, Button.x, Button.y + Button.h, 120, 10.0f + Rows * 13.0f, pfnPopupFunc); } } TB_Bottom.VSplitLeft(5.0f, nullptr, &TB_Bottom); From 886ec990fea4dec211ca765e74096a04ba8503ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 1 Nov 2022 22:35:31 +0100 Subject: [PATCH 4/4] Add missing check for modifier of Ctrl+F hotkey The hotkey for the "Find empty slot" button was not correctly checking for a pressed modifier, so it was already being trigger by just the key F instead of the desired Ctrl+F. --- src/game/editor/popups.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 36f002e5e..b3b0f9272 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -1514,7 +1514,7 @@ int CEditor::PopupTele(CEditor *pEditor, CUIRect View, void *pContext) // find empty number button { static int s_EmptySlotPid = 0; - if(pEditor->DoButton_Editor(&s_EmptySlotPid, "F", 0, &FindEmptySlot, 0, "[ctrl+f] Find empty slot") || pEditor->Input()->KeyPress(KEY_F)) + if(pEditor->DoButton_Editor(&s_EmptySlotPid, "F", 0, &FindEmptySlot, 0, "[ctrl+f] Find empty slot") || (pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(KEY_F))) { int number = -1; for(int i = 1; i <= 255; i++) @@ -1613,7 +1613,7 @@ int CEditor::PopupSwitch(CEditor *pEditor, CUIRect View, void *pContext) // find empty number button { static int s_EmptySlotPid = 0; - if(pEditor->DoButton_Editor(&s_EmptySlotPid, "F", 0, &FindEmptySlot, 0, "[ctrl+f] Find empty slot") || pEditor->Input()->KeyPress(KEY_F)) + if(pEditor->DoButton_Editor(&s_EmptySlotPid, "F", 0, &FindEmptySlot, 0, "[ctrl+f] Find empty slot") || (pEditor->Input()->ModifierIsPressed() && pEditor->Input()->KeyPress(KEY_F))) { int number = -1; for(int i = 1; i <= 255; i++)