diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 205e575cd..ddec451f6 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1095,6 +1095,21 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Bottom.VSplitLeft(5.0f, nullptr, &TB_Bottom); } + // goto xy button + { + TB_Bottom.VSplitLeft(50.0, &Button, &TB_Bottom); + static int s_GotoButton = 0; + if(DoButton_Editor(&s_GotoButton, "Goto XY", 0, &Button, 0, "Go to a specified coordinate point on the map")) + { + static int s_ModifierPopupID = 0; + if(!UiPopupExists(&s_ModifierPopupID)) + { + UiInvokePopupMenu(&s_ModifierPopupID, 0, Button.x, Button.y + Button.h, 120, 52, PopupGoto); + } + } + TB_Bottom.VSplitLeft(5.0f, nullptr, &TB_Bottom); + } + // tile manipulation { static int s_BorderBut = 0; @@ -6064,6 +6079,12 @@ void CEditor::ZoomMouseTarget(float ZoomFactor) m_WorldOffsetY += (Mwy - m_WorldOffsetY) * (1 - ZoomFactor); } +void CEditor::Goto(float X, float Y) +{ + m_WorldOffsetX = X * 32; + m_WorldOffsetY = Y * 32; +} + void CEditorMap::DeleteEnvelope(int Index) { if(Index < 0 || Index >= (int)m_vpEnvelopes.size()) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index ce716c96d..a1dbd2698 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -835,6 +835,8 @@ public: m_PreventUnusedTilesWasWarned = false; m_AllowPlaceUnusedTiles = 0; m_BrushDrawDestructive = true; + m_GotoX = 0; + m_GotoY = 0; m_Mentions = 0; } @@ -1239,6 +1241,8 @@ public: static int PopupSpeedup(CEditor *pEditor, CUIRect View, void *pContext); static int PopupSwitch(CEditor *pEditor, CUIRect View, void *pContext); static int PopupTune(CEditor *pEditor, CUIRect View, void *pContext); + static int PopupGoto(CEditor *pEditor, CUIRect View, void *pContext); + void Goto(float X, float Y); unsigned char m_TeleNumber; unsigned char m_TuningNum; @@ -1249,6 +1253,9 @@ public: unsigned char m_SwitchNum; unsigned char m_SwitchDelay; + + int m_GotoX; + int m_GotoY; }; // make sure to inline this function diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 8a03bc0fe..0d29e0e9e 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -1698,6 +1699,54 @@ int CEditor::PopupTune(CEditor *pEditor, CUIRect View, void *pContext) return 0; } +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 + { + PROP_CoordX = 0, + PROP_CoordY, + NUM_PROPS, + }; + + CProperty aProps[] = { + {"X", pEditor->m_GotoX, PROPTYPE_INT_STEP, std::numeric_limits::min(), std::numeric_limits::max()}, + {"Y", pEditor->m_GotoY, PROPTYPE_INT_STEP, std::numeric_limits::min(), std::numeric_limits::max()}, + {nullptr}, + }; + + static int s_aIds[NUM_PROPS] = {0}; + int NewVal = 0; + int Prop = pEditor->DoProperties(&CoordXPicker, aProps, s_aIds, &NewVal, s_Color); + + if(Prop == PROP_CoordX) + { + pEditor->m_GotoX = NewVal; + } + else if(Prop == PROP_CoordY) + { + pEditor->m_GotoY = NewVal; + } + + CUIRect Button; + View.HSplitBottom(12.0f, &View, &Button); + + static int s_Button; + if(pEditor->DoButton_Editor(&s_Button, "Go", 0, &Button, 0, "")) + { + pEditor->Goto(pEditor->m_GotoX + 0.5f, pEditor->m_GotoY + 0.5f); + } + + return 0; +} + int CEditor::PopupColorPicker(CEditor *pEditor, CUIRect View, void *pContext) { CUIRect SVPicker, HuePicker;