From 0f1af419115ac855a9983d03bbbfddde2bfeb6d3 Mon Sep 17 00:00:00 2001 From: Andrii Date: Fri, 15 May 2020 22:53:26 +0300 Subject: [PATCH] add binding for tele/switch/speedup/tune button --- src/game/editor/editor.cpp | 22 ++++++++++++---------- src/game/editor/editor.h | 1 + src/game/editor/popups.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 9adcc7015..b4bb9e23d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -31,6 +31,7 @@ #include "auto_map.h" #include "editor.h" + static const char *VANILLA_IMAGES[] = { "bg_cloud1", "bg_cloud2", @@ -1333,9 +1334,8 @@ void CEditor::DoToolbar(CUIRect ToolBar) // do tele/tune/switch/speedup button { int (*pPopupFunc)(CEditor *peditor, CUIRect View, void *pContext) = NULL; - const char *aButtonName = "Modifier"; + const char *aButtonName = 0; float Height = 0.0f; - int Checked = -1; CLayerTiles *pS = (CLayerTiles *)GetSelectedLayerType(0, LAYERTYPE_TILES); if(pS) { @@ -1344,43 +1344,45 @@ void CEditor::DoToolbar(CUIRect ToolBar) aButtonName = "Switch"; pPopupFunc = PopupSwitch; Height = 36; - Checked = 0; } else if(pS == m_Map.m_pSpeedupLayer) { aButtonName = "Speedup"; pPopupFunc = PopupSpeedup; Height = 53; - Checked = 0; } else if(pS == m_Map.m_pTuneLayer) { aButtonName = "Tune"; pPopupFunc = PopupTune; Height = 23; - Checked = 0; } else if(pS == m_Map.m_pTeleLayer) { aButtonName = "Tele"; pPopupFunc = PopupTele; Height = 23; - Checked = 0; } - if(Checked == 0) + if(aButtonName != 0) { + static char aBuf[64]; + str_format(aBuf, sizeof(aBuf), "[ctrl+a] %s", aButtonName); + TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom); static int s_ModifierButton = 0; - if(DoButton_Ex(&s_ModifierButton, aButtonName, Checked, &Button, 0, aButtonName, CUI::CORNER_ALL)) + if(DoButton_Ex(&s_ModifierButton, aButtonName, 0, &Button, 0, aBuf, CUI::CORNER_ALL) + || (ctrlPressed && Input()->KeyPress(KEY_A))) { static int s_ModifierPopupID = 0; - UiInvokePopupMenu(&s_ModifierPopupID, 0, UI()->MouseX(), UI()->MouseY(), 120, Height, pPopupFunc); + if(!UiPopupExists(&s_ModifierPopupID)) + { + UiInvokePopupMenu(&s_ModifierPopupID, 0, Button.x, Button.y + Button.h, 120, Height, pPopupFunc); + } } TB_Bottom.VSplitLeft(5.0f, 0, &TB_Bottom); } } - } } diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index ca43ff742..73522a7a6 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -956,6 +956,7 @@ public: void UiInvokePopupMenu(void *pID, int Flags, float X, float Y, float W, float H, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect, void *pContext), void *pExtra=0); void UiDoPopupMenu(); + bool UiPopupExists(void *pID); int UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree=false, bool IsHex=false, int corners=CUI::CORNER_ALL, ColorRGBA* Color=0); diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 9b443a0b6..2bb599367 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -98,6 +98,16 @@ void CEditor::UiDoPopupMenu() } } +bool CEditor::UiPopupExists(void *pid) +{ + for(int i = 0; i < g_UiNumPopups; i++) + { + if(s_UiPopups[i].m_pId == pid) + return true; + } + + return false; +} int CEditor::PopupGroup(CEditor *pEditor, CUIRect View, void *pContext) {