diff --git a/src/openrct2-ui/ProvisionalElements.cpp b/src/openrct2-ui/ProvisionalElements.cpp index 3fa1161dd0..0d16339bdc 100644 --- a/src/openrct2-ui/ProvisionalElements.cpp +++ b/src/openrct2-ui/ProvisionalElements.cpp @@ -30,7 +30,7 @@ namespace OpenRCT2::Ui FootpathRemoveProvisionalTemporarily(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::RideConstruction) != nullptr) { RideRemoveProvisionalTrackPiece(); @@ -50,7 +50,7 @@ namespace OpenRCT2::Ui FootpathRestoreProvisional(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::RideConstruction) != nullptr) { RideRestoreProvisionalTrackPiece(); diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index ae8f33e839..6f1068b239 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -30,6 +32,7 @@ #include #include #include +#include #include using namespace OpenRCT2; @@ -323,7 +326,7 @@ public: case INTENT_ACTION_NEW_SCENERY: { // Check if window is already open - auto* window = WindowBringToFrontByClass(WindowClass::Scenery); + auto* window = BringToFrontByClass(WindowClass::Scenery); if (window == nullptr) ToggleSceneryWindow(); @@ -647,6 +650,270 @@ public: return nullptr; } + static bool WindowFitsBetweenOthers(const ScreenCoordsXY& loc, int32_t width, int32_t height) + { + for (auto& w : g_window_list) + { + if (w->flags & WF_DEAD) + continue; + if (w->flags & WF_STICK_TO_BACK) + continue; + + if (loc.x + width <= w->windowPos.x) + continue; + if (loc.x >= w->windowPos.x + w->width) + continue; + if (loc.y + height <= w->windowPos.y) + continue; + if (loc.y >= w->windowPos.y + w->height) + continue; + return false; + } + + return true; + } + + static bool WindowFitsWithinSpace(const ScreenCoordsXY& loc, int32_t width, int32_t height) + { + if (loc.x < 0) + return false; + if (loc.y <= kTopToolbarHeight && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) + return false; + if (loc.x + width > ContextGetWidth()) + return false; + if (loc.y + height > ContextGetHeight()) + return false; + return WindowFitsBetweenOthers(loc, width, height); + } + + static bool WindowFitsOnScreen(const ScreenCoordsXY& loc, int32_t width, int32_t height) + { + uint16_t screenWidth = ContextGetWidth(); + uint16_t screenHeight = ContextGetHeight(); + int32_t unk; + + unk = -(width / 4); + if (loc.x < unk) + return false; + unk = screenWidth + (unk * 2); + if (loc.x > unk) + return false; + if (loc.y <= kTopToolbarHeight && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) + return false; + unk = screenHeight - (height / 4); + if (loc.y > unk) + return false; + return WindowFitsBetweenOthers(loc, width, height); + } + + static ScreenCoordsXY ClampWindowToScreen( + const ScreenCoordsXY& pos, const int32_t screenWidth, const int32_t screenHeight, const int32_t width, + const int32_t height) + { + auto screenPos = pos; + if (width > screenWidth || screenPos.x < 0) + screenPos.x = 0; + else if (screenPos.x + width > screenWidth) + screenPos.x = screenWidth - width; + + auto toolbarAllowance = (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) ? 0 : (kTopToolbarHeight + 1); + if (height - toolbarAllowance > screenHeight || screenPos.y < toolbarAllowance) + screenPos.y = toolbarAllowance; + else if (screenPos.y + height - toolbarAllowance > screenHeight) + screenPos.y = screenHeight + toolbarAllowance - height; + + return screenPos; + } + + static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) + { + auto uiContext = GetContext()->GetUiContext(); + auto screenWidth = uiContext->GetWidth(); + auto screenHeight = uiContext->GetHeight(); + + // Place window in an empty corner of the screen + const ScreenCoordsXY cornerPositions[] = { + { 0, 30 }, // topLeft + { screenWidth - width, 30 }, // topRight + { 0, screenHeight - 34 - height }, // bottomLeft + { screenWidth - width, screenHeight - 34 - height }, // bottomRight + }; + + for (const auto& cornerPos : cornerPositions) + { + if (WindowFitsWithinSpace(cornerPos, width, height)) + { + return ClampWindowToScreen(cornerPos, screenWidth, screenHeight, width, height); + } + } + + // Place window next to another + for (auto& w : g_window_list) + { + if (w->flags & WF_DEAD) + continue; + if (w->flags & WF_STICK_TO_BACK) + continue; + + const ScreenCoordsXY offsets[] = { + { w->width + 2, 0 }, + { -w->width - 2, 0 }, + { 0, w->height + 2 }, + { 0, -w->height - 2 }, + { w->width + 2, -w->height - 2 }, + { -w->width - 2, -w->height - 2 }, + { w->width + 2, w->height + 2 }, + { -w->width - 2, w->height + 2 }, + }; + + for (const auto& offset : offsets) + { + auto screenPos = w->windowPos + offset; + if (WindowFitsWithinSpace(screenPos, width, height)) + { + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); + } + } + } + + // Overlap + for (auto& w : g_window_list) + { + if (w->flags & WF_DEAD) + continue; + if (w->flags & WF_STICK_TO_BACK) + continue; + + const ScreenCoordsXY offsets[] = { + { w->width + 2, 0 }, + { -w->width - 2, 0 }, + { 0, w->height + 2 }, + { 0, -w->height - 2 }, + }; + + for (const auto& offset : offsets) + { + auto screenPos = w->windowPos + offset; + if (WindowFitsOnScreen(screenPos, width, height)) + { + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); + } + } + } + + // Cascade + auto screenPos = ScreenCoordsXY{ 0, 30 }; + for (auto& w : g_window_list) + { + if (screenPos == w->windowPos) + { + screenPos.x += 5; + screenPos.y += 5; + } + } + + return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); + } + + static ScreenCoordsXY GetCentrePositionForNewWindow(int32_t width, int32_t height) + { + auto uiContext = GetContext()->GetUiContext(); + auto screenWidth = uiContext->GetWidth(); + auto screenHeight = uiContext->GetHeight(); + return ScreenCoordsXY{ (screenWidth - width) / 2, std::max(kTopToolbarHeight + 1, (screenHeight - height) / 2) }; + } + + WindowBase* Create( + std::unique_ptr&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, + uint32_t flags) override + { + if (flags & WF_AUTO_POSITION) + { + if (flags & WF_CENTRE_SCREEN) + { + pos = GetCentrePositionForNewWindow(width, height); + } + else + { + pos = GetAutoPositionForNewWindow(width, height); + } + } + + // Check if there are any window slots left + // include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted. + if (g_window_list.size() >= static_cast(Config::Get().general.WindowLimit + kWindowLimitReserved)) + { + // Close least recently used window + for (auto& w : g_window_list) + { + if (w->flags & WF_DEAD) + continue; + if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT | WF_NO_AUTO_CLOSE))) + { + WindowClose(*w.get()); + break; + } + } + } + + // Find right position to insert new window + auto itDestPos = g_window_list.end(); + if (flags & WF_STICK_TO_BACK) + { + for (auto it = g_window_list.begin(); it != g_window_list.end(); it++) + { + if ((*it)->flags & WF_DEAD) + continue; + if (!((*it)->flags & WF_STICK_TO_BACK)) + { + itDestPos = it; + } + } + } + else if (!(flags & WF_STICK_TO_FRONT)) + { + for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) + { + if ((*it)->flags & WF_DEAD) + continue; + if (!((*it)->flags & WF_STICK_TO_FRONT)) + { + itDestPos = it.base(); + break; + } + } + } + + auto itNew = g_window_list.insert(itDestPos, std::move(wp)); + auto w = itNew->get(); + + // Setup window + w->classification = cls; + w->flags = flags; + + // Play sounds and flash the window + if (!(flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) + { + w->flags |= WF_WHITE_BORDER_MASK; + OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::WindowOpen, 0, pos.x + (width / 2)); + } + + w->windowPos = pos; + w->width = width; + w->height = height; + w->min_width = width; + w->max_width = width; + w->min_height = height; + w->max_height = height; + + w->focus = std::nullopt; + + ColourSchemeUpdate(w); + w->Invalidate(); + w->OnOpen(); + return w; + } + /** * Finds the first window with the specified window class. * rct2: 0x006EA8A0 @@ -762,6 +1029,82 @@ public: // Return the widget index return widget_index; } + + /** + * + * rct2: 0x006ECDA4 + */ + WindowBase* BringToFront(WindowBase& w) override + { + if (!(w.flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) + { + auto itSourcePos = WindowGetIterator(&w); + if (itSourcePos != g_window_list.end()) + { + // Insert in front of the first non-stick-to-front window + auto itDestPos = g_window_list.begin(); + for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) + { + auto& w2 = *it; + if (!(w2->flags & WF_STICK_TO_FRONT)) + { + itDestPos = it.base(); + break; + } + } + + g_window_list.splice(itDestPos, g_window_list, itSourcePos); + w.Invalidate(); + + if (w.windowPos.x + w.width < 20) + { + int32_t i = 20 - w.windowPos.x; + w.windowPos.x += i; + if (w.viewport != nullptr) + w.viewport->pos.x += i; + w.Invalidate(); + } + } + } + return &w; + } + + WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) override + { + WindowBase* w = FindByClass(cls); + if (w != nullptr) + { + w->flags |= flags; + w->Invalidate(); + w = BringToFront(*w); + } + + return w; + } + + WindowBase* BringToFrontByClass(WindowClass cls) override + { + return BringToFrontByClassWithFlags(cls, WF_WHITE_BORDER_MASK); + } + + /** + * + * rct2: 0x006ED78A + * cls (cl) + * number (dx) + */ + WindowBase* BringToFrontByNumber(WindowClass cls, rct_windownumber number) override + { + WindowBase* w = FindByNumber(cls, number); + if (w != nullptr) + { + w->flags |= WF_WHITE_BORDER_MASK; + w->Invalidate(); + w = BringToFront(*w); + } + + return w; + } }; std::unique_ptr OpenRCT2::Ui::CreateWindowManager() diff --git a/src/openrct2-ui/input/InputManager.cpp b/src/openrct2-ui/input/InputManager.cpp index c76d9ed364..0ec239cabe 100644 --- a/src/openrct2-ui/input/InputManager.cpp +++ b/src/openrct2-ui/input/InputManager.cpp @@ -210,7 +210,7 @@ void InputManager::Process(const InputEvent& e) if (e.DeviceKind == InputDeviceKind::Keyboard) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); // TODO: replace with event auto w = windowMgr->FindByClass(WindowClass::Textinput); @@ -424,7 +424,7 @@ bool InputManager::HasTextInputFocus() const if (OpenRCT2::Ui::Windows::IsUsingWidgetTextBox() || gChatOpen) return true; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::Textinput); if (w != nullptr) return true; diff --git a/src/openrct2-ui/input/MouseInput.cpp b/src/openrct2-ui/input/MouseInput.cpp index 2821567c0b..49fef8388e 100644 --- a/src/openrct2-ui/input/MouseInput.cpp +++ b/src/openrct2-ui/input/MouseInput.cpp @@ -246,7 +246,7 @@ namespace OpenRCT2 */ static void InputScrollRight(const ScreenCoordsXY& screenCoords, MouseState state) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(_dragWidget.window_classification, _dragWidget.window_number); if (w == nullptr) { @@ -286,7 +286,7 @@ namespace OpenRCT2 Widget* widget; WidgetIndex widgetIndex; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); // Get window and widget under cursor position w = windowMgr->FindFromPoint(screenCoords); @@ -312,7 +312,7 @@ namespace OpenRCT2 if (w != nullptr) { - w = WindowBringToFront(*w); + w = windowMgr->BringToFront(*w); } if (widgetIndex != kWidgetIndexNull) @@ -566,7 +566,7 @@ namespace OpenRCT2 if (differentialCoords.x == 0 && differentialCoords.y == 0) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); w = windowMgr->FindByNumber(_dragWidget.window_classification, _dragWidget.window_number); // #3294: Window can be closed during a drag session, so just finish @@ -776,7 +776,7 @@ namespace OpenRCT2 const auto& widget = w.widgets[widgetIndex]; auto& scroll = w.scrolls[scroll_id]; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { int32_t newLeft; @@ -816,7 +816,7 @@ namespace OpenRCT2 const auto& widget = w.widgets[widgetIndex]; auto& scroll = w.scrolls[scroll_id]; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { int32_t newTop; @@ -853,7 +853,7 @@ namespace OpenRCT2 */ static void InputScrollPartUpdateHLeft(WindowBase& w, WidgetIndex widgetIndex, int32_t scroll_id) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { auto& scroll = w.scrolls[scroll_id]; @@ -873,7 +873,7 @@ namespace OpenRCT2 { const auto& widget = w.widgets[widgetIndex]; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { auto& scroll = w.scrolls[scroll_id]; @@ -899,7 +899,7 @@ namespace OpenRCT2 */ static void InputScrollPartUpdateVTop(WindowBase& w, WidgetIndex widgetIndex, int32_t scroll_id) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { auto& scroll = w.scrolls[scroll_id]; @@ -919,7 +919,7 @@ namespace OpenRCT2 { const auto& widget = w.widgets[widgetIndex]; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(w.classification, w.number) != nullptr) { auto& scroll = w.scrolls[scroll_id]; @@ -1016,7 +1016,7 @@ namespace OpenRCT2 */ static void InputWidgetOverFlatbuttonInvalidate() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(gHoverWidget.window_classification, gHoverWidget.window_number); if (w != nullptr) { @@ -1048,12 +1048,12 @@ namespace OpenRCT2 WindowCloseByClass(WindowClass::Tooltip); // Window might have changed position in the list, therefore find it again - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); w = windowMgr->FindByNumber(windowClass, windowNumber); if (w == nullptr) return; - w = WindowBringToFront(*w); + w = windowMgr->BringToFront(*w); if (widgetIndex == kWidgetIndexNull) return; @@ -1145,7 +1145,7 @@ namespace OpenRCT2 ft.Add(STR_NONE); SetMapTooltip(ft); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindFromPoint(screenCoords); if (window != nullptr) @@ -1223,7 +1223,7 @@ namespace OpenRCT2 { if (_inputFlags & INPUT_FLAG_TOOL_ACTIVE) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number); if (w == nullptr) @@ -1305,7 +1305,7 @@ namespace OpenRCT2 cursor_w_number = gPressedWidget.window_number; WidgetIndex cursor_widgetIndex = gPressedWidget.widget_index; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* cursor_w = windowMgr->FindByNumber(cursor_w_class, cursor_w_number); if (cursor_w == nullptr) { @@ -1612,7 +1612,7 @@ namespace OpenRCT2 */ void InvalidateScroll() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(gPressedWidget.window_classification, gPressedWidget.window_number); if (w != nullptr) { diff --git a/src/openrct2-ui/input/Shortcuts.cpp b/src/openrct2-ui/input/Shortcuts.cpp index 136e2dac9a..4f7e51738f 100644 --- a/src/openrct2-ui/input/Shortcuts.cpp +++ b/src/openrct2-ui/input/Shortcuts.cpp @@ -89,7 +89,7 @@ static void ShortcutRotateConstructionObject() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); // Rotate scenery WindowBase* w = windowMgr->FindByClass(WindowClass::Scenery); @@ -152,7 +152,7 @@ static void ShortcutRotateConstructionObject() static void ShortcutRemoveTopBottomToolbarToggle() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) { @@ -372,7 +372,7 @@ static void ShortcutOpenCheatWindow() return; // Check if window is already open - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Cheats); if (window != nullptr) { @@ -441,7 +441,7 @@ static void ShortcutOpenSceneryPicker() || (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR && GetGameState().EditorStep != EditorStep::LandscapeEditor)) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window_scenery = windowMgr->FindByClass(WindowClass::Scenery); if (window_scenery == nullptr) ToggleSceneryWindow(); @@ -477,7 +477,7 @@ static void ShortcutScaleDown() // Tile inspector shortcuts static void TileInspectorMouseUp(WidgetIndex widgetIndex) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::TileInspector); if (w != nullptr && !WidgetIsDisabled(*w, widgetIndex) && w->widgets[widgetIndex].type != WindowWidgetType::Empty) { @@ -487,7 +487,7 @@ static void TileInspectorMouseUp(WidgetIndex widgetIndex) static void TileInspectorMouseDown(WidgetIndex widgetIndex) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::TileInspector); if (w != nullptr && !WidgetIsDisabled(*w, widgetIndex) && w->widgets[widgetIndex].type != WindowWidgetType::Empty) { @@ -497,7 +497,7 @@ static void TileInspectorMouseDown(WidgetIndex widgetIndex) static void ShortcutToggleWallSlope() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::TileInspector); if (window == nullptr) { @@ -529,7 +529,7 @@ static void ShortcutToggleWallSlope() static void ShortcutIncreaseElementHeight() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::TileInspector); if (w != nullptr) { @@ -569,7 +569,7 @@ static void ShortcutIncreaseElementHeight() static void ShortcutDecreaseElementHeight() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::TileInspector); if (w != nullptr) { @@ -633,7 +633,7 @@ static void ShortcutConstructionTurnLeft() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -650,7 +650,7 @@ static void ShortcutConstructionTurnRight() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -667,7 +667,7 @@ static void ShortcutConstructionSlopeUp() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -684,7 +684,7 @@ static void ShortcutConstructionBuildCurrent() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -701,7 +701,7 @@ static void ShortcutConstructionSlopeDown() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -718,7 +718,7 @@ static void ShortcutConstructionDemolishCurrent() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindByClass(WindowClass::Footpath); if (window != nullptr) { @@ -763,7 +763,7 @@ void ShortcutManager::RegisterDefaultShortcuts() RegisterShortcut(ShortcutId::kInterfaceCancelConstruction, STR_SHORTCUT_CANCEL_CONSTRUCTION_MODE, "ESCAPE", []() { if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = windowMgr->FindByClass(WindowClass::Error); if (window != nullptr) { @@ -900,7 +900,7 @@ void ShortcutManager::RegisterDefaultShortcuts() RegisterShortcut(ShortcutId::kDebugTogglePaintDebugWindow, STR_SHORTCUT_DEBUG_PAINT_TOGGLE, []() { if (!(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = windowMgr->FindByClass(WindowClass::DebugPaint); if (window != nullptr) { diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index d8475d5f79..e8dd7577e6 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -469,7 +469,7 @@ namespace OpenRCT2::Ui if (!(InputTestFlag(INPUT_FLAG_6)) || !(InputTestFlag(INPUT_FLAG_TOOL_ACTIVE))) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::RideConstruction) == nullptr && windowMgr->FindByClass(WindowClass::Footpath) == nullptr) { @@ -637,7 +637,7 @@ namespace OpenRCT2::Ui */ static void ViewportInteractionRemoveFootpath(const PathElement& pathElement, const CoordsXY& mapCoords) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) FootpathUpdateProvisional(); @@ -765,7 +765,7 @@ namespace OpenRCT2::Ui static Peep* ViewportInteractionGetClosestPeep(ScreenCoordsXY screenCoords, int32_t maxDistance) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindFromPoint(screenCoords); if (w == nullptr) return nullptr; @@ -790,7 +790,7 @@ namespace OpenRCT2::Ui */ CoordsXY ViewportInteractionGetTileStartAtCursor(const ScreenCoordsXY& screenCoords) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindFromPoint(screenCoords); if (window == nullptr || window->viewport == nullptr) { diff --git a/src/openrct2-ui/interface/ViewportQuery.cpp b/src/openrct2-ui/interface/ViewportQuery.cpp index 3b485c43df..5b56b3e3f3 100644 --- a/src/openrct2-ui/interface/ViewportQuery.cpp +++ b/src/openrct2-ui/interface/ViewportQuery.cpp @@ -39,7 +39,7 @@ namespace OpenRCT2::Ui */ CoordsXY FootpathGetCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindFromPoint(screenCoords); if (window == nullptr || window->viewport == nullptr) { @@ -138,7 +138,7 @@ namespace OpenRCT2::Ui CoordsXY FootpathBridgeGetInfoFromPos(const ScreenCoordsXY& screenCoords, int32_t* direction, TileElement** tileElement) { // First check if we point at an entrance or exit. In that case, we would want the path coming from the entrance/exit. - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* window = windowMgr->FindFromPoint(screenCoords); if (window == nullptr || window->viewport == nullptr) { diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index c22f6ecb4e..970a8408f6 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -41,179 +41,6 @@ namespace OpenRCT2 static int32_t _previousAbsoluteWheel = 0; - static bool WindowFitsBetweenOthers(const ScreenCoordsXY& loc, int32_t width, int32_t height) - { - for (auto& w : g_window_list) - { - if (w->flags & WF_DEAD) - continue; - if (w->flags & WF_STICK_TO_BACK) - continue; - - if (loc.x + width <= w->windowPos.x) - continue; - if (loc.x >= w->windowPos.x + w->width) - continue; - if (loc.y + height <= w->windowPos.y) - continue; - if (loc.y >= w->windowPos.y + w->height) - continue; - return false; - } - - return true; - } - - static bool WindowFitsWithinSpace(const ScreenCoordsXY& loc, int32_t width, int32_t height) - { - if (loc.x < 0) - return false; - if (loc.y <= kTopToolbarHeight && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) - return false; - if (loc.x + width > ContextGetWidth()) - return false; - if (loc.y + height > ContextGetHeight()) - return false; - return WindowFitsBetweenOthers(loc, width, height); - } - - static bool WindowFitsOnScreen(const ScreenCoordsXY& loc, int32_t width, int32_t height) - { - uint16_t screenWidth = ContextGetWidth(); - uint16_t screenHeight = ContextGetHeight(); - int32_t unk; - - unk = -(width / 4); - if (loc.x < unk) - return false; - unk = screenWidth + (unk * 2); - if (loc.x > unk) - return false; - if (loc.y <= kTopToolbarHeight && !(gScreenFlags & SCREEN_FLAGS_TITLE_DEMO)) - return false; - unk = screenHeight - (height / 4); - if (loc.y > unk) - return false; - return WindowFitsBetweenOthers(loc, width, height); - } - - static ScreenCoordsXY ClampWindowToScreen( - const ScreenCoordsXY& pos, const int32_t screenWidth, const int32_t screenHeight, const int32_t width, - const int32_t height) - { - auto screenPos = pos; - if (width > screenWidth || screenPos.x < 0) - screenPos.x = 0; - else if (screenPos.x + width > screenWidth) - screenPos.x = screenWidth - width; - - auto toolbarAllowance = (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) ? 0 : (kTopToolbarHeight + 1); - if (height - toolbarAllowance > screenHeight || screenPos.y < toolbarAllowance) - screenPos.y = toolbarAllowance; - else if (screenPos.y + height - toolbarAllowance > screenHeight) - screenPos.y = screenHeight + toolbarAllowance - height; - - return screenPos; - } - - static ScreenCoordsXY GetAutoPositionForNewWindow(int32_t width, int32_t height) - { - auto uiContext = GetContext()->GetUiContext(); - auto screenWidth = uiContext->GetWidth(); - auto screenHeight = uiContext->GetHeight(); - - // Place window in an empty corner of the screen - const ScreenCoordsXY cornerPositions[] = { - { 0, 30 }, // topLeft - { screenWidth - width, 30 }, // topRight - { 0, screenHeight - 34 - height }, // bottomLeft - { screenWidth - width, screenHeight - 34 - height }, // bottomRight - }; - - for (const auto& cornerPos : cornerPositions) - { - if (WindowFitsWithinSpace(cornerPos, width, height)) - { - return ClampWindowToScreen(cornerPos, screenWidth, screenHeight, width, height); - } - } - - // Place window next to another - for (auto& w : g_window_list) - { - if (w->flags & WF_DEAD) - continue; - if (w->flags & WF_STICK_TO_BACK) - continue; - - const ScreenCoordsXY offsets[] = { - { w->width + 2, 0 }, - { -w->width - 2, 0 }, - { 0, w->height + 2 }, - { 0, -w->height - 2 }, - { w->width + 2, -w->height - 2 }, - { -w->width - 2, -w->height - 2 }, - { w->width + 2, w->height + 2 }, - { -w->width - 2, w->height + 2 }, - }; - - for (const auto& offset : offsets) - { - auto screenPos = w->windowPos + offset; - if (WindowFitsWithinSpace(screenPos, width, height)) - { - return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); - } - } - } - - // Overlap - for (auto& w : g_window_list) - { - if (w->flags & WF_DEAD) - continue; - if (w->flags & WF_STICK_TO_BACK) - continue; - - const ScreenCoordsXY offsets[] = { - { w->width + 2, 0 }, - { -w->width - 2, 0 }, - { 0, w->height + 2 }, - { 0, -w->height - 2 }, - }; - - for (const auto& offset : offsets) - { - auto screenPos = w->windowPos + offset; - if (WindowFitsOnScreen(screenPos, width, height)) - { - return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); - } - } - } - - // Cascade - auto screenPos = ScreenCoordsXY{ 0, 30 }; - for (auto& w : g_window_list) - { - if (screenPos == w->windowPos) - { - screenPos.x += 5; - screenPos.y += 5; - } - } - - return ClampWindowToScreen(screenPos, screenWidth, screenHeight, width, height); - } - - static ScreenCoordsXY GetCentrePositionForNewWindow(int32_t width, int32_t height) - { - auto uiContext = GetContext()->GetUiContext(); - auto screenWidth = uiContext->GetWidth(); - auto screenHeight = uiContext->GetHeight(); - return ScreenCoordsXY{ (screenWidth - width) / 2, std::max(kTopToolbarHeight + 1, (screenHeight - height) / 2) }; - } - static int32_t WindowGetWidgetIndex(const WindowBase& w, Widget* widget) { const auto it = std::find_if( @@ -441,7 +268,7 @@ namespace OpenRCT2 // Check window cursor is over if (!(InputTestFlag(INPUT_FLAG_5))) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindFromPoint(cursorState->position); if (w != nullptr) { @@ -734,96 +561,6 @@ namespace OpenRCT2::Ui::Windows static TextInputSession* _textInput; static WidgetIdentifier _currentTextBox = { { WindowClass::Null, 0 }, 0 }; - WindowBase* WindowCreate( - std::unique_ptr&& wp, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, uint32_t flags) - { - if (flags & WF_AUTO_POSITION) - { - if (flags & WF_CENTRE_SCREEN) - { - pos = GetCentrePositionForNewWindow(width, height); - } - else - { - pos = GetAutoPositionForNewWindow(width, height); - } - } - - // Check if there are any window slots left - // include kWindowLimitReserved for items such as the main viewport and toolbars to not appear to be counted. - if (g_window_list.size() >= static_cast(Config::Get().general.WindowLimit + kWindowLimitReserved)) - { - // Close least recently used window - for (auto& w : g_window_list) - { - if (w->flags & WF_DEAD) - continue; - if (!(w->flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT | WF_NO_AUTO_CLOSE))) - { - WindowClose(*w.get()); - break; - } - } - } - - // Find right position to insert new window - auto itDestPos = g_window_list.end(); - if (flags & WF_STICK_TO_BACK) - { - for (auto it = g_window_list.begin(); it != g_window_list.end(); it++) - { - if ((*it)->flags & WF_DEAD) - continue; - if (!((*it)->flags & WF_STICK_TO_BACK)) - { - itDestPos = it; - } - } - } - else if (!(flags & WF_STICK_TO_FRONT)) - { - for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) - { - if ((*it)->flags & WF_DEAD) - continue; - if (!((*it)->flags & WF_STICK_TO_FRONT)) - { - itDestPos = it.base(); - break; - } - } - } - - auto itNew = g_window_list.insert(itDestPos, std::move(wp)); - auto w = itNew->get(); - - // Setup window - w->classification = cls; - w->flags = flags; - - // Play sounds and flash the window - if (!(flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) - { - w->flags |= WF_WHITE_BORDER_MASK; - OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::WindowOpen, 0, pos.x + (width / 2)); - } - - w->windowPos = pos; - w->width = width; - w->height = height; - w->min_width = width; - w->max_width = width; - w->min_height = height; - w->max_height = height; - - w->focus = std::nullopt; - - ColourSchemeUpdate(w); - w->Invalidate(); - w->OnOpen(); - return w; - } - WindowBase* WindowGetListening() { for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) @@ -871,7 +608,7 @@ namespace OpenRCT2::Ui::Windows { if (_usingWidgetTextBox) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(_currentTextBox.window.classification, _currentTextBox.window.number); _currentTextBox.window.classification = WindowClass::Null; _currentTextBox.window.number = 0; @@ -897,7 +634,7 @@ namespace OpenRCT2::Ui::Windows if (_usingWidgetTextBox) { _textBoxFrameNo = 0; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(_currentTextBox.window.classification, _currentTextBox.window.number); WidgetInvalidate(*w, _currentTextBox.widget_index); w->OnTextInput(_currentTextBox.widget_index, _textBoxInput); diff --git a/src/openrct2-ui/interface/Window.h b/src/openrct2-ui/interface/Window.h index d5003c07c0..107610f47d 100644 --- a/src/openrct2-ui/interface/Window.h +++ b/src/openrct2-ui/interface/Window.h @@ -55,42 +55,6 @@ namespace OpenRCT2 namespace OpenRCT2::Ui::Windows { - WindowBase* WindowCreate( - std::unique_ptr&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, uint32_t flags); - template::value>::type* = nullptr> - T* WindowCreate( - WindowClass cls, const ScreenCoordsXY& pos = {}, int32_t width = 0, int32_t height = 0, uint32_t flags = 0, - TArgs&&... args) - { - return static_cast(WindowCreate(std::make_unique(std::forward(args)...), cls, pos, width, height, flags)); - } - template::value>::type* = nullptr> - T* WindowCreate(WindowClass cls, int32_t width, int32_t height, uint32_t flags, TArgs&&... args) - { - return static_cast( - WindowCreate(std::make_unique(std::forward(args)...), cls, {}, width, height, flags | WF_AUTO_POSITION)); - } - template::value>::type* = nullptr> - T* WindowFocusOrCreate(WindowClass cls, const ScreenCoordsXY& pos, int32_t width, int32_t height, uint32_t flags = 0) - { - auto* w = WindowBringToFrontByClass(cls); - if (w == nullptr) - { - w = WindowCreate(cls, pos, width, height, flags); - } - return static_cast(w); - } - template::value>::type* = nullptr> - T* WindowFocusOrCreate(WindowClass cls, int32_t width, int32_t height, uint32_t flags = 0) - { - auto* w = WindowBringToFrontByClass(cls); - if (w == nullptr) - { - w = WindowCreate(cls, width, height, flags); - } - return static_cast(w); - } - void RideConstructionToolupdateEntranceExit(const ScreenCoordsXY& screenCoords); void RideConstructionToolupdateConstruct(const ScreenCoordsXY& screenCoords); void RideConstructionTooldownConstruct(const ScreenCoordsXY& screenCoords); diff --git a/src/openrct2-ui/scripting/CustomMenu.cpp b/src/openrct2-ui/scripting/CustomMenu.cpp index 6b0548b0cc..d085254a99 100644 --- a/src/openrct2-ui/scripting/CustomMenu.cpp +++ b/src/openrct2-ui/scripting/CustomMenu.cpp @@ -268,7 +268,7 @@ namespace OpenRCT2::Scripting customTool.onUp = dukValue["onUp"]; customTool.onFinish = dukValue["onFinish"]; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto toolbarWindow = windowMgr->FindByClass(WindowClass::TopToolbar); if (toolbarWindow != nullptr) { diff --git a/src/openrct2-ui/scripting/CustomWindow.cpp b/src/openrct2-ui/scripting/CustomWindow.cpp index c89f8ce91c..b1dffc6b3e 100644 --- a/src/openrct2-ui/scripting/CustomWindow.cpp +++ b/src/openrct2-ui/scripting/CustomWindow.cpp @@ -1111,7 +1111,7 @@ namespace OpenRCT2::Ui::Windows static rct_windownumber GetNewWindowNumber() { auto result = _nextWindowNumber++; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); while (windowMgr->FindByNumber(WindowClass::Custom, result) != nullptr) { result++; @@ -1126,15 +1126,17 @@ namespace OpenRCT2::Ui::Windows { auto desc = CustomWindowDesc::FromDukValue(dukDesc); uint16_t windowFlags = WF_RESIZABLE | WF_TRANSPARENT; + auto* windowMgr = GetWindowManager(); + CustomWindow* window{}; if (desc.X && desc.Y) { - window = WindowCreate( + window = windowMgr->Create( WindowClass::Custom, { *desc.X, *desc.Y }, desc.Width, desc.Height, windowFlags, owner, desc); } else { - window = WindowCreate(WindowClass::Custom, desc.Width, desc.Height, windowFlags, owner, desc); + window = windowMgr->Create(WindowClass::Custom, desc.Width, desc.Height, windowFlags, owner, desc); } return window; } diff --git a/src/openrct2-ui/scripting/ScViewport.hpp b/src/openrct2-ui/scripting/ScViewport.hpp index 0f81cccc01..c0910bd891 100644 --- a/src/openrct2-ui/scripting/ScViewport.hpp +++ b/src/openrct2-ui/scripting/ScViewport.hpp @@ -253,7 +253,7 @@ namespace OpenRCT2::Scripting if (_class == WindowClass::MainWindow) return WindowGetMain(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); return windowMgr->FindByNumber(_class, _number); } diff --git a/src/openrct2-ui/scripting/ScWidget.hpp b/src/openrct2-ui/scripting/ScWidget.hpp index aeb056e531..46478fd8d0 100644 --- a/src/openrct2-ui/scripting/ScWidget.hpp +++ b/src/openrct2-ui/scripting/ScWidget.hpp @@ -393,7 +393,7 @@ namespace OpenRCT2::Scripting if (_class == WindowClass::MainWindow) return WindowGetMain(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); return windowMgr->FindByNumber(_class, _number); } diff --git a/src/openrct2-ui/scripting/ScWindow.hpp b/src/openrct2-ui/scripting/ScWindow.hpp index 872ac02bd2..2d973a81bb 100644 --- a/src/openrct2-ui/scripting/ScWindow.hpp +++ b/src/openrct2-ui/scripting/ScWindow.hpp @@ -326,10 +326,11 @@ namespace OpenRCT2::Scripting void bringToFront() { - auto w = GetWindow(); + auto* w = GetWindow(); if (w != nullptr) { - WindowBringToFront(*w); + auto* windowMgr = Ui::GetWindowManager(); + w = windowMgr->BringToFront(*w); w->flags |= WF_WHITE_BORDER_MASK; } } @@ -360,7 +361,7 @@ namespace OpenRCT2::Scripting private: WindowBase* GetWindow() const { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); return windowMgr->FindByNumber(_class, _number); } }; diff --git a/src/openrct2-ui/title/TitleSequencePlayer.cpp b/src/openrct2-ui/title/TitleSequencePlayer.cpp index 9ffe187727..f4da02696f 100644 --- a/src/openrct2-ui/title/TitleSequencePlayer.cpp +++ b/src/openrct2-ui/title/TitleSequencePlayer.cpp @@ -430,7 +430,7 @@ namespace OpenRCT2::Title void PrepareParkForPlayback() { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); auto& gameState = GetGameState(); windowManager->SetMainView(gameState.SavedView, gameState.SavedViewZoom, gameState.SavedViewRotation); ResetEntitySpatialIndices(); diff --git a/src/openrct2-ui/windows/About.cpp b/src/openrct2-ui/windows/About.cpp index 70c771dd61..4e1c58483f 100644 --- a/src/openrct2-ui/windows/About.cpp +++ b/src/openrct2-ui/windows/About.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -280,6 +280,7 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* AboutOpen() { - return WindowFocusOrCreate(WindowClass::About, WW, WH, WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::About, WW, WH, WF_CENTRE_SCREEN); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/AssetPacks.cpp b/src/openrct2-ui/windows/AssetPacks.cpp index 5d0aa86878..4ed2ca6fc0 100644 --- a/src/openrct2-ui/windows/AssetPacks.cpp +++ b/src/openrct2-ui/windows/AssetPacks.cpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -343,7 +344,9 @@ namespace OpenRCT2::Ui::Windows WindowBase* AssetPacksOpen() { + auto* windowMgr = GetWindowManager(); auto flags = WF_AUTO_POSITION | WF_CENTRE_SCREEN; - return WindowFocusOrCreate(WindowClass::AssetPacks, WW, WH, flags); + + return windowMgr->FocusOrCreate(WindowClass::AssetPacks, WW, WH, flags); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Banner.cpp b/src/openrct2-ui/windows/Banner.cpp index 0d675ba2d5..6f7b77a772 100644 --- a/src/openrct2-ui/windows/Banner.cpp +++ b/src/openrct2-ui/windows/Banner.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -312,12 +313,13 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* BannerOpen(rct_windownumber number) { - auto w = static_cast(WindowBringToFrontByNumber(WindowClass::Banner, number)); + auto* windowMgr = GetWindowManager(); + auto w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Banner, number)); if (w != nullptr) return w; - w = WindowCreate(WindowClass::Banner, WW, WH, 0); + w = windowMgr->Create(WindowClass::Banner, WW, WH, 0); if (w != nullptr) w->Initialise(number); diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index a77331bdbf..39f95be5e8 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -318,7 +318,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ChangelogOpen(int personality) { - auto* window = WindowBringToFrontByClass(WindowClass::Changelog); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::Changelog); if (window == nullptr) { // Create a new centred window @@ -328,7 +329,7 @@ namespace OpenRCT2::Ui::Windows int32_t height = (screenHeight * 4) / 5; auto pos = ChangelogWindow::GetCentrePositionForNewWindow(width, height); - auto* newWindow = WindowCreate(WindowClass::Changelog, pos, width, height, WF_RESIZABLE); + auto* newWindow = windowMgr->Create(WindowClass::Changelog, pos, width, height, WF_RESIZABLE); newWindow->SetPersonality(personality); return newWindow; } diff --git a/src/openrct2-ui/windows/Cheats.cpp b/src/openrct2-ui/windows/Cheats.cpp index f294b55ac6..e1db565d5d 100644 --- a/src/openrct2-ui/windows/Cheats.cpp +++ b/src/openrct2-ui/windows/Cheats.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1345,10 +1346,11 @@ static StringId window_cheats_page_titles[] = { WindowBase* CheatsOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::Cheats); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::Cheats); if (window == nullptr) { - window = WindowCreate(WindowClass::Cheats, ScreenCoordsXY(32, 32), WW, WH); + window = windowMgr->Create(WindowClass::Cheats, ScreenCoordsXY(32, 32), WW, WH); } return window; } diff --git a/src/openrct2-ui/windows/ClearScenery.cpp b/src/openrct2-ui/windows/ClearScenery.cpp index 7749b36ef7..998046d7c1 100644 --- a/src/openrct2-ui/windows/ClearScenery.cpp +++ b/src/openrct2-ui/windows/ClearScenery.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -343,7 +342,7 @@ namespace OpenRCT2::Ui::Windows { case WIDX_BACKGROUND: { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::Error) == nullptr && (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE)) { auto action = GetClearAction(); @@ -380,7 +379,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ClearSceneryOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::ClearScenery, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); } diff --git a/src/openrct2-ui/windows/CustomCurrency.cpp b/src/openrct2-ui/windows/CustomCurrency.cpp index ef5ae15b85..8046781859 100644 --- a/src/openrct2-ui/windows/CustomCurrency.cpp +++ b/src/openrct2-ui/windows/CustomCurrency.cpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -227,6 +228,7 @@ namespace OpenRCT2::Ui::Windows WindowBase* CustomCurrencyOpen() { - return WindowFocusOrCreate(WindowClass::CustomCurrencyConfig, WW, WH, WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::CustomCurrencyConfig, WW, WH, WF_CENTRE_SCREEN); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/DebugPaint.cpp b/src/openrct2-ui/windows/DebugPaint.cpp index 0973e14888..776136cf4a 100644 --- a/src/openrct2-ui/windows/DebugPaint.cpp +++ b/src/openrct2-ui/windows/DebugPaint.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -153,7 +154,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* DebugPaintOpen() { - auto* window = WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate( WindowClass::DebugPaint, { 16, ContextGetHeight() - 16 - 33 - WINDOW_HEIGHT }, WINDOW_WIDTH, WINDOW_HEIGHT, WF_STICK_TO_FRONT | WF_TRANSPARENT); diff --git a/src/openrct2-ui/windows/DemolishRidePrompt.cpp b/src/openrct2-ui/windows/DemolishRidePrompt.cpp index 1ae9cdc9b8..d3d87a8f5c 100644 --- a/src/openrct2-ui/windows/DemolishRidePrompt.cpp +++ b/src/openrct2-ui/windows/DemolishRidePrompt.cpp @@ -9,13 +9,11 @@ #include #include -#include #include #include #include #include #include -#include #include #include #include @@ -103,21 +101,20 @@ namespace OpenRCT2::Ui::Windows WindowBase* RideDemolishPromptOpen(const Ride& ride) { - WindowBase* w; - DemolishRidePromptWindow* newWindow; + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->FindByClass(WindowClass::DemolishRidePrompt); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); - w = windowMgr->FindByClass(WindowClass::DemolishRidePrompt); + DemolishRidePromptWindow* newWindow; if (w != nullptr) { auto windowPos = w->windowPos; WindowClose(*w); - newWindow = WindowCreate( + newWindow = windowMgr->Create( WindowClass::DemolishRidePrompt, windowPos, WW, WH, WF_TRANSPARENT); } else { - newWindow = WindowCreate( + newWindow = windowMgr->Create( WindowClass::DemolishRidePrompt, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/Dropdown.cpp b/src/openrct2-ui/windows/Dropdown.cpp index 0a46a16f4c..80ddfec2ef 100644 --- a/src/openrct2-ui/windows/Dropdown.cpp +++ b/src/openrct2-ui/windows/Dropdown.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -357,7 +358,8 @@ namespace OpenRCT2::Ui::Windows WindowDropdownClose(); // Create the window (width/height position are set later) - auto* w = WindowCreate(WindowClass::Dropdown, width, custom_height, WF_STICK_TO_FRONT); + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->Create(WindowClass::Dropdown, width, custom_height, WF_STICK_TO_FRONT); if (w != nullptr) { w->SetTextItems(screenPos, extray, colour, custom_height, flags, num_items, width); @@ -390,7 +392,8 @@ namespace OpenRCT2::Ui::Windows WindowDropdownClose(); // Create the window (width/height position are set later) - auto* w = WindowCreate(WindowClass::Dropdown, itemWidth, itemHeight, WF_STICK_TO_FRONT); + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->Create(WindowClass::Dropdown, itemWidth, itemHeight, WF_STICK_TO_FRONT); if (w != nullptr) { w->SetImageItems({ x, y }, extray, colour, numItems, itemWidth, itemHeight, numColumns); diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 47ccc32949..c0264ffd2c 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -381,7 +382,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* EditorBottomToolbarOpen() { - auto* window = WindowCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->Create( WindowClass::BottomToolbar, ScreenCoordsXY(0, ContextGetHeight() - 32), ContextGetWidth(), 32, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND); diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 14819b9bc6..3b535d9915 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -26,7 +25,6 @@ #include #include #include -#include #include #include @@ -490,7 +488,7 @@ namespace OpenRCT2::Ui::Windows if (windowPos.x <= screenCoords.x && windowPos.y < screenCoords.y && windowPos.x + width > screenCoords.x && windowPos.y + height > screenCoords.y) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WidgetIndex widgetIndex = windowMgr->FindWidgetFromPoint(*this, screenCoords); auto& widget = widgets[widgetIndex]; @@ -595,7 +593,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* EditorInventionsListOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::EditorInventionList, WW, WH, WF_NO_SCROLLING | WF_RESIZABLE | WF_CENTRE_SCREEN); } #pragma endregion @@ -615,7 +614,7 @@ namespace OpenRCT2::Ui::Windows CursorID OnCursor(const WidgetIndex widx, const ScreenCoordsXY& screenCoords, const CursorID defaultCursor) override { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* inventionListWindow = static_cast( windowMgr->FindByClass(WindowClass::EditorInventionList)); if (inventionListWindow != nullptr) @@ -634,7 +633,7 @@ namespace OpenRCT2::Ui::Windows void OnMoved(const ScreenCoordsXY& screenCoords) override { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* inventionListWindow = static_cast( windowMgr->FindByClass(WindowClass::EditorInventionList)); if (inventionListWindow == nullptr) @@ -691,8 +690,9 @@ namespace OpenRCT2::Ui::Windows static void WindowEditorInventionsListDragOpen( ResearchItem* researchItem, const ScreenCoordsXY& editorPos, int objectSelectionScrollWidth) { + auto* windowMgr = Ui::GetWindowManager(); WindowCloseByClass(WindowClass::EditorInventionListDrag); - auto* wnd = WindowCreate( + auto* wnd = windowMgr->Create( WindowClass::EditorInventionListDrag, 10, 14, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_SNAPPING); if (wnd != nullptr) { @@ -702,7 +702,7 @@ namespace OpenRCT2::Ui::Windows static const ResearchItem* WindowEditorInventionsListDragGetItem() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* wnd = static_cast(windowMgr->FindByClass(WindowClass::EditorInventionListDrag)); if (wnd == nullptr) { diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 092e3e7de2..fd5ccec6c6 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -1644,7 +1643,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* EditorObjectSelectionOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::EditorObjectSelection, 755, 400, WF_10 | WF_RESIZABLE | WF_CENTRE_SCREEN); } @@ -1746,7 +1746,7 @@ namespace OpenRCT2::Ui::Windows ContextShowError(STR_INVALID_SELECTION_OF_OBJECTS, errorString, {}); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::EditorObjectSelection); if (w != nullptr) { diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index d920650264..2a7002d732 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -1169,11 +1170,12 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* EditorObjectiveOptionsOpen() { - auto window = WindowBringToFrontByClass(WindowClass::EditorObjectiveOptions); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::EditorObjectiveOptions); if (window != nullptr) return window; - window = WindowCreate( + window = windowMgr->Create( WindowClass::EditorObjectiveOptions, 450, 225, WF_10 | WF_CENTRE_SCREEN); return window; diff --git a/src/openrct2-ui/windows/EditorParkEntrance.cpp b/src/openrct2-ui/windows/EditorParkEntrance.cpp index 90ef9fa509..b5633a30c5 100644 --- a/src/openrct2-ui/windows/EditorParkEntrance.cpp +++ b/src/openrct2-ui/windows/EditorParkEntrance.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -391,14 +392,13 @@ namespace OpenRCT2::Ui::Windows WindowBase* EditorParkEntranceOpen() { - WindowBase* window; - // Check if window is already open - window = WindowBringToFrontByClass(WindowClass::EditorParkEntrance); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::EditorParkEntrance); if (window != nullptr) return window; - window = WindowCreate( + window = windowMgr->Create( WindowClass::EditorParkEntrance, kWindowWidth, kWindowHeight, WF_10 | WF_RESIZABLE); return window; diff --git a/src/openrct2-ui/windows/EditorScenarioOptions.cpp b/src/openrct2-ui/windows/EditorScenarioOptions.cpp index e70fd52cec..f391348aad 100644 --- a/src/openrct2-ui/windows/EditorScenarioOptions.cpp +++ b/src/openrct2-ui/windows/EditorScenarioOptions.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -1254,6 +1255,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* EditorScenarioOptionsOpen() { - return WindowFocusOrCreate(WindowClass::EditorScenarioOptions, 280, 148, WF_NO_SCROLLING); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( + WindowClass::EditorScenarioOptions, 280, 148, WF_NO_SCROLLING); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Error.cpp b/src/openrct2-ui/windows/Error.cpp index 47d8686099..7321420fa0 100644 --- a/src/openrct2-ui/windows/Error.cpp +++ b/src/openrct2-ui/windows/Error.cpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -138,7 +139,9 @@ namespace OpenRCT2::Ui::Windows windowPosition.y = std::clamp(windowPosition.y, 22, ContextGetHeight() - height - 40); auto errorWindow = std::make_unique(std::move(buffer), numLines, autoClose); - return WindowCreate( + + auto* windowMgr = GetWindowManager(); + return windowMgr->Create( std::move(errorWindow), WindowClass::Error, windowPosition, width, height, WF_STICK_TO_FRONT | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 045214ed34..4805454247 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -879,7 +879,8 @@ namespace OpenRCT2::Ui::Windows static FinancesWindow* FinancesWindowOpen(uint8_t page) { - auto* window = WindowFocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); + auto* windowMgr = Ui::GetWindowManager(); + auto* window = windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); if (window != nullptr && page != WINDOW_FINANCES_PAGE_SUMMARY) window->SetPage(page); @@ -889,7 +890,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* FinancesOpen() { - return WindowFocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); + auto* windowMgr = Ui::GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Finances, WW_OTHER_TABS, WH_SUMMARY, WF_10); } WindowBase* FinancesResearchOpen() diff --git a/src/openrct2-ui/windows/Footpath.cpp b/src/openrct2-ui/windows/Footpath.cpp index 05e5a3f302..86721e5db8 100644 --- a/src/openrct2-ui/windows/Footpath.cpp +++ b/src/openrct2-ui/windows/Footpath.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -1236,7 +1235,7 @@ namespace OpenRCT2::Ui::Windows Audio::Play3D(OpenRCT2::Audio::SoundId::PlaceItem, result->Position); } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* self = static_cast(windowMgr->FindByClass(WindowClass::Footpath)); if (self == nullptr) { @@ -1627,7 +1626,8 @@ namespace OpenRCT2::Ui::Windows return nullptr; } - return WindowFocusOrCreate(WindowClass::Footpath, WW_WINDOW, WH_WINDOW, 0); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Footpath, WW_WINDOW, WH_WINDOW, 0); } void WindowFootpathResetSelectedPath() @@ -1637,7 +1637,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutTurnLeft() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1651,7 +1651,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutTurnRight() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1665,7 +1665,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutSlopeDown() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1679,7 +1679,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutSlopeUp() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1693,7 +1693,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutDemolishCurrent() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1707,7 +1707,7 @@ namespace OpenRCT2::Ui::Windows void WindowFootpathKeyboardShortcutBuildCurrent() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::Footpath); if (w != nullptr) { @@ -1725,7 +1725,7 @@ namespace OpenRCT2::Ui::Windows */ void ToggleFootpathWindow() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::Footpath) == nullptr) { ContextOpenWindow(WindowClass::Footpath); diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 636c64f942..427a004750 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -677,7 +678,8 @@ namespace OpenRCT2::Ui::Windows uint32_t line_height = FontGetLineHeight(FontStyle::Medium); uint32_t toolbar_height = line_height * 2 + 12; - GameBottomToolbar* window = WindowCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->Create( WindowClass::BottomToolbar, ScreenCoordsXY(0, screenHeight - toolbar_height), screenWidth, toolbar_height, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND); diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index fb8372231d..d980fa7b19 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -639,7 +638,7 @@ namespace OpenRCT2::Ui::Windows pickupAction.SetCallback([peepnum = number](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* wind = windowMgr->FindByNumber(WindowClass::Peep, peepnum); if (wind != nullptr) { @@ -1911,14 +1910,15 @@ namespace OpenRCT2::Ui::Windows return StaffOpen(peep); } - auto* window = static_cast(WindowBringToFrontByNumber(WindowClass::Peep, peep->Id.ToUnderlying())); + auto* windowMgr = GetWindowManager(); + auto* window = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Peep, peep->Id.ToUnderlying())); if (window == nullptr) { int32_t windowWidth = 192; if (Config::Get().general.DebuggingTools) windowWidth += TabWidth; - window = WindowCreate(WindowClass::Peep, windowWidth, 157, WF_RESIZABLE); + window = windowMgr->Create(WindowClass::Peep, windowWidth, 157, WF_RESIZABLE); if (window == nullptr) { return nullptr; diff --git a/src/openrct2-ui/windows/GuestList.cpp b/src/openrct2-ui/windows/GuestList.cpp index 353e5037c1..e4b5d54208 100644 --- a/src/openrct2-ui/windows/GuestList.cpp +++ b/src/openrct2-ui/windows/GuestList.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -971,10 +970,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* GuestListOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::GuestList); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::GuestList); if (window == nullptr) { - window = WindowCreate(WindowClass::GuestList, 350, 330, WF_10 | WF_RESIZABLE); + window = windowMgr->Create(WindowClass::GuestList, 350, 330, WF_10 | WF_RESIZABLE); } return window; } @@ -994,7 +994,7 @@ namespace OpenRCT2::Ui::Windows void WindowGuestListRefreshList() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::GuestList); if (w != nullptr) { diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index fd3aa0eda0..b6fbae9d20 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -430,7 +431,8 @@ namespace OpenRCT2::Ui::Windows int32_t screenHeight = ContextGetHeight(); auto screenPos = ScreenCoordsXY{ screenWidth / 2 - 201, std::max(kTopToolbarHeight + 1, screenHeight / 2 - 200) }; - auto* window = WindowFocusOrCreate(WindowClass::InstallTrack, screenPos, WW, WH, 0); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate(WindowClass::InstallTrack, screenPos, WW, WH, 0); window->SetupTrack(path, std::move(trackDesign)); return window; diff --git a/src/openrct2-ui/windows/Land.cpp b/src/openrct2-ui/windows/Land.cpp index 077ba3569c..d2284302af 100644 --- a/src/openrct2-ui/windows/Land.cpp +++ b/src/openrct2-ui/windows/Land.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -400,7 +399,7 @@ namespace OpenRCT2::Ui::Windows */ void LandToolDrag(const ScreenCoordsXY& screenPos) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindFromPoint(screenPos); if (window == nullptr) return; @@ -873,7 +872,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* LandOpen() { - return WindowFocusOrCreate(WindowClass::Land, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Land, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); } /** diff --git a/src/openrct2-ui/windows/LandRights.cpp b/src/openrct2-ui/windows/LandRights.cpp index 157835ec2e..9fc9a52a12 100644 --- a/src/openrct2-ui/windows/LandRights.cpp +++ b/src/openrct2-ui/windows/LandRights.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -585,7 +586,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* LandRightsOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::LandRights, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index c260c2e776..b5f907984b 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1335,7 +1335,8 @@ namespace OpenRCT2::Ui::Windows const u8string path = GetDir(type); - auto* w = static_cast(WindowBringToFrontByClass(WindowClass::Loadsave)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByClass(WindowClass::Loadsave)); if (w == nullptr) { if (config.FileBrowserWidth < kWindowSizeMin.width || config.FileBrowserHeight < kWindowSizeMin.height @@ -1349,7 +1350,7 @@ namespace OpenRCT2::Ui::Windows auto width = config.FileBrowserWidth; auto height = config.FileBrowserHeight; - w = WindowCreate( + w = windowMgr->Create( WindowClass::Loadsave, width, height, WF_STICK_TO_FRONT | WF_RESIZABLE | WF_AUTO_POSITION | WF_CENTRE_SCREEN, type); } @@ -1483,7 +1484,8 @@ namespace OpenRCT2::Ui::Windows { WindowCloseByClass(WindowClass::LoadsaveOverwritePrompt); - return WindowCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->Create( WindowClass::LoadsaveOverwritePrompt, OVERWRITE_WW, OVERWRITE_WH, WF_TRANSPARENT | WF_STICK_TO_FRONT | WF_CENTRE_SCREEN, name, path); } diff --git a/src/openrct2-ui/windows/Main.cpp b/src/openrct2-ui/windows/Main.cpp index 7710a0fce7..f77f751ff5 100644 --- a/src/openrct2-ui/windows/Main.cpp +++ b/src/openrct2-ui/windows/Main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -75,7 +76,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* MainOpen() { - return WindowCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->Create( WindowClass::MainWindow, { 0, 0 }, ContextGetWidth(), ContextGetHeight(), WF_STICK_TO_BACK); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Map.cpp b/src/openrct2-ui/windows/Map.cpp index a67ce9e820..1e0cd726de 100644 --- a/src/openrct2-ui/windows/Map.cpp +++ b/src/openrct2-ui/windows/Map.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -276,7 +275,7 @@ namespace OpenRCT2::Ui::Windows void OnMouseUp(WidgetIndex widgetIndex) override { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); switch (widgetIndex) { case WIDX_CLOSE: @@ -356,7 +355,7 @@ namespace OpenRCT2::Ui::Windows void OnUpdate() override { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); // the flickering frequency is reduced by 4, compared to the original // it was done due to inability to reproduce original frequency @@ -600,7 +599,7 @@ namespace OpenRCT2::Ui::Windows void OnPrepareDraw() override { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); // Set the pressed widgets pressed_widgets = 0; @@ -1253,7 +1252,8 @@ namespace OpenRCT2::Ui::Windows { try { - WindowBase* w = WindowFocusOrCreate(WindowClass::Map, 245, 259, WF_10); + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->FocusOrCreate(WindowClass::Map, 245, 259, WF_10); w->selected_tab = 0; w->list_information_type = 0; return w; @@ -1266,10 +1266,9 @@ namespace OpenRCT2::Ui::Windows void WindowMapReset() { - WindowBase* w; - // Check if window is even opened - w = WindowBringToFrontByClass(WindowClass::Map); + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->BringToFrontByClass(WindowClass::Map); if (w == nullptr) { return; diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index 23e52cd643..d5d71c1015 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -1529,7 +1530,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* MapgenOpen() { - return WindowFocusOrCreate(WindowClass::Mapgen, WW, WH, WF_10 | WF_AUTO_POSITION | WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Mapgen, WW, WH, WF_10 | WF_AUTO_POSITION | WF_CENTRE_SCREEN); } static void HeightmapLoadsaveCallback(int32_t result, const utf8* path) diff --git a/src/openrct2-ui/windows/MapTooltip.cpp b/src/openrct2-ui/windows/MapTooltip.cpp index 3a77481343..847bb67ff7 100644 --- a/src/openrct2-ui/windows/MapTooltip.cpp +++ b/src/openrct2-ui/windows/MapTooltip.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -97,7 +96,7 @@ namespace OpenRCT2::Ui::Windows std::memcpy(&stringId, _mapTooltipArgs.Data(), sizeof(StringId)); auto& im = GetInputManager(); - auto* wm = GetContext()->GetUiContext()->GetWindowManager(); + auto* wm = GetWindowManager(); if (_cursorHoldDuration < 25 || stringId == STR_NONE || im.IsModifierKeyPressed(ModifierKey::ctrl) || im.IsModifierKeyPressed(ModifierKey::shift) || wm->FindByClass(WindowClass::Error) != nullptr) { @@ -116,7 +115,7 @@ namespace OpenRCT2::Ui::Windows const CursorState* state = ContextGetCursorState(); auto pos = state->position + ScreenCoordsXY{ -width / 2, 15 }; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (auto w = windowMgr->FindByClass(WindowClass::MapTooltip)) { w->Invalidate(); @@ -126,7 +125,7 @@ namespace OpenRCT2::Ui::Windows } else { - w = WindowCreate( + w = windowMgr->Create( WindowClass::MapTooltip, pos, width, height, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND); } } diff --git a/src/openrct2-ui/windows/MazeConstruction.cpp b/src/openrct2-ui/windows/MazeConstruction.cpp index b64393bb22..65644d6846 100644 --- a/src/openrct2-ui/windows/MazeConstruction.cpp +++ b/src/openrct2-ui/windows/MazeConstruction.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -437,13 +436,14 @@ namespace OpenRCT2::Ui::Windows WindowBase* MazeConstructionOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::RideConstruction, ScreenCoordsXY(0, 29), WW, WH, WF_NO_AUTO_CLOSE); } void WindowMazeConstructionUpdatePressedWidgets() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr) return; diff --git a/src/openrct2-ui/windows/Multiplayer.cpp b/src/openrct2-ui/windows/Multiplayer.cpp index a846142952..86620fa64a 100644 --- a/src/openrct2-ui/windows/Multiplayer.cpp +++ b/src/openrct2-ui/windows/Multiplayer.cpp @@ -18,6 +18,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -184,10 +185,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* MultiplayerOpen() { // Check if window is already open - WindowBase* window = WindowBringToFrontByClass(WindowClass::Multiplayer); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::Multiplayer); if (window == nullptr) { - window = WindowCreate( + window = windowMgr->Create( WindowClass::Multiplayer, 320, 144, WF_10 | WF_RESIZABLE | WF_AUTO_POSITION); } diff --git a/src/openrct2-ui/windows/NetworkStatus.cpp b/src/openrct2-ui/windows/NetworkStatus.cpp index 0b80ce3268..0872cbf66c 100644 --- a/src/openrct2-ui/windows/NetworkStatus.cpp +++ b/src/openrct2-ui/windows/NetworkStatus.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -136,16 +135,16 @@ namespace OpenRCT2::Ui::Windows { ContextForceCloseWindowByClass(WindowClass::ProgressWindow); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); NetworkStatusWindow* window; if ((window = static_cast(windowMgr->FindByClass(WindowClass::NetworkStatus))) != nullptr) { - WindowBringToFront(*window); + windowMgr->BringToFront(*window); } else { - window = WindowCreate( + window = windowMgr->Create( WindowClass::NetworkStatus, 400, 90, WF_10 | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); } @@ -157,7 +156,7 @@ namespace OpenRCT2::Ui::Windows // force close void WindowNetworkStatusClose() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = windowMgr->FindByClass(WindowClass::NetworkStatus); if (window == nullptr) { @@ -172,8 +171,10 @@ namespace OpenRCT2::Ui::Windows { ContextForceCloseWindowByClass(WindowClass::ProgressWindow); - auto window = WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate( WindowClass::NetworkStatus, 400, 90, WF_10 | WF_TRANSPARENT | WF_CENTRE_SCREEN); + char password[33]{}; WindowTextInputRawOpen(window, WIDX_PASSWORD, STR_PASSWORD_REQUIRED, STR_PASSWORD_REQUIRED_DESC, {}, password, 32); window->SetPassword(password); diff --git a/src/openrct2-ui/windows/NewCampaign.cpp b/src/openrct2-ui/windows/NewCampaign.cpp index 1fb2cdcc57..054fbc3973 100644 --- a/src/openrct2-ui/windows/NewCampaign.cpp +++ b/src/openrct2-ui/windows/NewCampaign.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,7 +22,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -404,7 +402,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* NewCampaignOpen(int16_t campaignType) { - auto w = static_cast(WindowBringToFrontByClass(WindowClass::NewCampaign)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByClass(WindowClass::NewCampaign)); if (w != nullptr) { if (w->GetCampaignType() == campaignType) @@ -413,7 +412,7 @@ namespace OpenRCT2::Ui::Windows WindowClose(*w); } - w = WindowCreate(WindowClass::NewCampaign, WW, WH, 0); + w = windowMgr->Create(WindowClass::NewCampaign, WW, WH, 0); if (w != nullptr) { w->SetCampaign(campaignType); @@ -423,7 +422,7 @@ namespace OpenRCT2::Ui::Windows void WindowCampaignRefreshRides() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = static_cast(windowMgr->FindByClass(WindowClass::NewCampaign)); if (w != nullptr) { diff --git a/src/openrct2-ui/windows/NewRide.cpp b/src/openrct2-ui/windows/NewRide.cpp index e17681f485..1cc4a7b5ee 100644 --- a/src/openrct2-ui/windows/NewRide.cpp +++ b/src/openrct2-ui/windows/NewRide.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include #include @@ -1071,9 +1070,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* NewRideOpen() { - WindowBase* window; - - window = WindowBringToFrontByClass(WindowClass::ConstructRide); + auto* windowMgr = Ui::GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::ConstructRide); if (window) { return window; @@ -1082,7 +1080,8 @@ namespace OpenRCT2::Ui::Windows WindowCloseByClass(WindowClass::TrackDesignList); WindowCloseByClass(WindowClass::TrackDesignPlace); - window = WindowCreate(WindowClass::ConstructRide, WindowWidth, WindowHeight, WF_10 | WF_AUTO_POSITION); + window = windowMgr->Create( + WindowClass::ConstructRide, WindowWidth, WindowHeight, WF_10 | WF_AUTO_POSITION); return window; } @@ -1099,7 +1098,7 @@ namespace OpenRCT2::Ui::Windows */ void WindowNewRideFocus(RideSelection rideItem) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = static_cast(windowMgr->FindByClass(WindowClass::ConstructRide)); if (!w) { diff --git a/src/openrct2-ui/windows/News.cpp b/src/openrct2-ui/windows/News.cpp index 3881d3b223..17119ac073 100644 --- a/src/openrct2-ui/windows/News.cpp +++ b/src/openrct2-ui/windows/News.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -323,6 +324,7 @@ namespace OpenRCT2::Ui::Windows WindowBase* NewsOpen() { - return WindowFocusOrCreate(WindowClass::RecentNews, WW, WH, 0); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::RecentNews, WW, WH, 0); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/NewsOptions.cpp b/src/openrct2-ui/windows/NewsOptions.cpp index d4f374c8fa..8e2e6de69b 100644 --- a/src/openrct2-ui/windows/NewsOptions.cpp +++ b/src/openrct2-ui/windows/NewsOptions.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -282,6 +283,7 @@ namespace OpenRCT2::Ui::Windows WindowBase* NewsOptionsOpen() { - return WindowFocusOrCreate(WindowClass::NotificationOptions, WW, WH, WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::NotificationOptions, WW, WH, WF_CENTRE_SCREEN); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/ObjectLoadError.cpp b/src/openrct2-ui/windows/ObjectLoadError.cpp index e10784baa6..f64c3c873f 100644 --- a/src/openrct2-ui/windows/ObjectLoadError.cpp +++ b/src/openrct2-ui/windows/ObjectLoadError.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -576,10 +576,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* ObjectLoadErrorOpen(utf8* path, size_t numMissingObjects, const ObjectEntryDescriptor* missingObjects) { // Check if window is already open - auto* window = WindowBringToFrontByClass(WindowClass::ObjectLoadError); + auto* windowMgr = Ui::GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::ObjectLoadError); if (window == nullptr) { - window = WindowCreate(WindowClass::ObjectLoadError, WW, WH, 0); + window = windowMgr->Create(WindowClass::ObjectLoadError, WW, WH, 0); } static_cast(window)->Initialise(path, numMissingObjects, missingObjects); diff --git a/src/openrct2-ui/windows/Options.cpp b/src/openrct2-ui/windows/Options.cpp index 99dc413ab8..8b44038a59 100644 --- a/src/openrct2-ui/windows/Options.cpp +++ b/src/openrct2-ui/windows/Options.cpp @@ -12,14 +12,12 @@ * the window has been changed to a tab interface similar to the options window seen in Locomotion. */ -#include "../interface/Theme.h" - #include #include +#include #include #include #include -#include #include #include #include @@ -45,6 +43,7 @@ #include #include #include +#include using namespace OpenRCT2; using namespace OpenRCT2::Audio; @@ -2216,6 +2215,7 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* OptionsOpen() { - return WindowFocusOrCreate(WindowClass::Options, WW, WH, WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Options, WW, WH, WF_CENTRE_SCREEN); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 47b0589674..8ecee3d564 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -7,17 +7,15 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ -#include "../interface/Theme.h" - #include #include #include #include #include +#include #include #include #include -#include #include #include #include @@ -32,6 +30,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -1298,7 +1297,8 @@ namespace OpenRCT2::Ui::Windows static ParkWindow* ParkWindowOpen(uint8_t page) { - auto* wnd = WindowFocusOrCreate(WindowClass::ParkInformation, 230, 174 + 9, WF_10); + auto* windowMgr = GetWindowManager(); + auto* wnd = windowMgr->FocusOrCreate(WindowClass::ParkInformation, 230, 174 + 9, WF_10); if (wnd != nullptr && page != WINDOW_PARK_PAGE_ENTRANCE) { wnd->OnMouseUp(WIDX_TAB_1 + page); diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index 0c0129f24e..0cc33b2eab 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -275,7 +274,7 @@ namespace OpenRCT2::Ui::Windows bool IsStaffWindowOpen() { // If staff window for this patrol area was closed, tool is no longer active - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto staffWindow = windowMgr->FindByNumber(WindowClass::Peep, _staffId); return staffWindow != nullptr; } @@ -294,7 +293,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* PatrolAreaOpen(EntityId staffId) { - auto w = WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->FocusOrCreate( WindowClass::PatrolArea, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); if (w != nullptr) { @@ -305,7 +305,7 @@ namespace OpenRCT2::Ui::Windows EntityId WindowPatrolAreaGetCurrentStaffId() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto current = reinterpret_cast(windowMgr->FindByClass(WindowClass::PatrolArea)); return current != nullptr ? current->GetStaffId() : EntityId::GetNull(); } diff --git a/src/openrct2-ui/windows/Player.cpp b/src/openrct2-ui/windows/Player.cpp index a191327c4a..e068814e95 100644 --- a/src/openrct2-ui/windows/Player.cpp +++ b/src/openrct2-ui/windows/Player.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -624,10 +625,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* PlayerOpen(uint8_t id) { - auto* window = static_cast(WindowBringToFrontByNumber(WindowClass::Player, id)); + auto* windowMgr = GetWindowManager(); + auto* window = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Player, id)); if (window == nullptr) { - window = WindowCreate(WindowClass::Player, 240, 170, WF_RESIZABLE); + window = windowMgr->Create(WindowClass::Player, 240, 170, WF_RESIZABLE); } window->Init(id); diff --git a/src/openrct2-ui/windows/ProgressWindow.cpp b/src/openrct2-ui/windows/ProgressWindow.cpp index dec1db3bec..4cd6dc0a35 100644 --- a/src/openrct2-ui/windows/ProgressWindow.cpp +++ b/src/openrct2-ui/windows/ProgressWindow.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -236,16 +235,16 @@ namespace OpenRCT2::Ui::Windows { ContextForceCloseWindowByClass(WindowClass::NetworkStatus); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); ProgressWindow* window; if ((window = static_cast(windowMgr->FindByClass(WindowClass::ProgressWindow))) != nullptr) { - WindowBringToFront(*window); + windowMgr->BringToFront(*window); } else { - window = WindowCreate( + window = windowMgr->Create( WindowClass::ProgressWindow, kWindowWidth, kWindowHeight, WF_10 | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); } @@ -257,7 +256,7 @@ namespace OpenRCT2::Ui::Windows void ProgressWindowSet(uint32_t currentProgress, uint32_t totalCount, StringId format) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = windowMgr->FindByClass(WindowClass::ProgressWindow); if (window == nullptr) { @@ -270,7 +269,7 @@ namespace OpenRCT2::Ui::Windows // Closes the window, deliberately *without* executing the callback. void ProgressWindowClose() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = windowMgr->FindByClass(WindowClass::ProgressWindow); if (window == nullptr) { diff --git a/src/openrct2-ui/windows/RefurbishRidePrompt.cpp b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp index e157fb33b8..8c1c42a794 100644 --- a/src/openrct2-ui/windows/RefurbishRidePrompt.cpp +++ b/src/openrct2-ui/windows/RefurbishRidePrompt.cpp @@ -9,12 +9,10 @@ #include #include -#include #include #include #include #include -#include #include #include #include @@ -104,18 +102,18 @@ namespace OpenRCT2::Ui::Windows { RefurbishRidePromptWindow* newWindow; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::DemolishRidePrompt); if (w != nullptr) { auto windowPos = w->windowPos; WindowClose(*w); - newWindow = WindowCreate( + newWindow = windowMgr->Create( WindowClass::DemolishRidePrompt, windowPos, WW, WH, WF_TRANSPARENT); } else { - newWindow = WindowCreate( + newWindow = windowMgr->Create( WindowClass::DemolishRidePrompt, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/Research.cpp b/src/openrct2-ui/windows/Research.cpp index 7b627ef14c..6dfcf99581 100644 --- a/src/openrct2-ui/windows/Research.cpp +++ b/src/openrct2-ui/windows/Research.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -304,7 +305,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ResearchOpen() { - ResearchWindow* window = WindowFocusOrCreate(WindowClass::Research, WW_FUNDING, WH_FUNDING, WF_10); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate(WindowClass::Research, WW_FUNDING, WH_FUNDING, WF_10); window->SetPage(WINDOW_RESEARCH_PAGE_DEVELOPMENT); return window; } diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index bffe17ffba..9ecf0f8142 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -64,7 +64,6 @@ #include #include #include -#include #include #include #include @@ -1137,7 +1136,7 @@ namespace OpenRCT2::Ui::Windows if (newPage == WINDOW_RIDE_PAGE_VEHICLE) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto constructionWindow = windowMgr->FindByClass(WindowClass::RideConstruction); if (constructionWindow != nullptr && constructionWindow->number == number) { @@ -1633,7 +1632,7 @@ namespace OpenRCT2::Ui::Windows if (ride != nullptr) { RideConstructionStart(*ride); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByNumber(WindowClass::RideConstruction, ride->id.ToUnderlying()) != nullptr) { Close(); @@ -6939,7 +6938,8 @@ namespace OpenRCT2::Ui::Windows */ static RideWindow* WindowRideOpen(const Ride& ride) { - return WindowCreate(WindowClass::Ride, 316, 207, WF_10 | WF_RESIZABLE, ride); + auto* windowMgr = GetWindowManager(); + return windowMgr->Create(WindowClass::Ride, 316, 207, WF_10 | WF_RESIZABLE, ride); } /** @@ -6953,7 +6953,8 @@ namespace OpenRCT2::Ui::Windows return nullptr; } - RideWindow* w = static_cast(WindowBringToFrontByNumber(WindowClass::Ride, ride.id.ToUnderlying())); + auto* windowMgr = GetWindowManager(); + RideWindow* w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Ride, ride.id.ToUnderlying())); if (w == nullptr) { w = WindowRideOpen(ride); @@ -6990,7 +6991,8 @@ namespace OpenRCT2::Ui::Windows if (ride.GetRideTypeDescriptor().HasFlag(RtdFlag::noVehicles)) return RideMainOpen(ride); - auto* w = static_cast(WindowBringToFrontByNumber(WindowClass::Ride, ride.id.ToUnderlying())); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Ride, ride.id.ToUnderlying())); if (w == nullptr) { w = WindowRideOpen(ride); @@ -7080,7 +7082,7 @@ namespace OpenRCT2::Ui::Windows view++; } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = static_cast(windowMgr->FindByNumber(WindowClass::Ride, ride->id.ToUnderlying())); if (w != nullptr) { @@ -7118,7 +7120,7 @@ namespace OpenRCT2::Ui::Windows w = static_cast( openedPeepWindow ? windowMgr->FindByNumber(WindowClass::Ride, ride->id.ToUnderlying()) - : WindowBringToFrontByNumber(WindowClass::Ride, ride->id.ToUnderlying())); + : windowMgr->BringToFrontByNumber(WindowClass::Ride, ride->id.ToUnderlying())); } if (w == nullptr) @@ -7134,7 +7136,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideInvalidateVehicle(const Vehicle& vehicle) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = static_cast(windowMgr->FindByNumber(WindowClass::Ride, vehicle.ride.ToUnderlying())); if (w == nullptr) return; @@ -7152,7 +7154,7 @@ namespace OpenRCT2::Ui::Windows void WindowRidePaintResetVehicle(RideId rideIndex) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = static_cast(windowMgr->FindByNumber(WindowClass::Ride, rideIndex.ToUnderlying())); if (w != nullptr) { diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index a073404c10..0730fff378 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -212,7 +211,7 @@ namespace OpenRCT2::Ui::Windows /* move to ride.c */ static void CloseRideWindowForConstruction(RideId rideId) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(WindowClass::Ride, rideId.ToUnderlying()); if (w != nullptr && w->page == 1) WindowClose(*w); @@ -2803,16 +2802,18 @@ namespace OpenRCT2::Ui::Windows WindowRideConstructionUpdateDisabledPieces(currentRide->type); + auto* windowMgr = GetWindowManager(); + const auto& rtd = currentRide->GetRideTypeDescriptor(); switch (rtd.ConstructionWindowContext) { case RideConstructionWindowContext::Maze: return ContextOpenWindowView(WV_MAZE_CONSTRUCTION); case RideConstructionWindowContext::Default: - return WindowCreate( + return windowMgr->Create( WindowClass::RideConstruction, ScreenCoordsXY(0, 29), WW, WH, WF_NO_AUTO_CLOSE); } - return WindowCreate( + return windowMgr->Create( WindowClass::RideConstruction, ScreenCoordsXY(0, 29), WW, WH, WF_NO_AUTO_CLOSE); } @@ -2820,7 +2821,7 @@ namespace OpenRCT2::Ui::Windows { if (_rideConstructionState == RideConstructionState::State0) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr) { @@ -2838,7 +2839,7 @@ namespace OpenRCT2::Ui::Windows static void WindowRideConstructionDoEntranceExitCheck() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::RideConstruction); auto ride = GetRide(_currentRideIndex); if (w == nullptr || ride == nullptr) @@ -3074,7 +3075,7 @@ namespace OpenRCT2::Ui::Windows { return; } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = static_cast(windowMgr->FindByClass(WindowClass::RideConstruction)); if (!window) { @@ -3306,7 +3307,7 @@ namespace OpenRCT2::Ui::Windows const auto& rtd = ride->GetRideTypeDescriptor(); if (rtd.specialType != RtdSpecialType::maze) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto window = static_cast(windowMgr->FindByClass(WindowClass::RideConstruction)); if (!window) { @@ -3610,7 +3611,7 @@ namespace OpenRCT2::Ui::Windows auto intent = Intent(INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION); ContextBroadcastIntent(&intent); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr) break; @@ -3677,7 +3678,7 @@ namespace OpenRCT2::Ui::Windows _currentTrackSelectionFlags = 0; WindowRideConstructionUpdateActiveElements(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr) break; @@ -3731,7 +3732,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutTurnLeft() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_STRAIGHT) || w->widgets[WIDX_STRAIGHT].type == WindowWidgetType::Empty) { @@ -3982,7 +3983,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutTurnRight() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_STRAIGHT) || w->widgets[WIDX_STRAIGHT].type == WindowWidgetType::Empty) { @@ -4236,7 +4237,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutUseTrackDefault() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_STRAIGHT) || w->widgets[WIDX_STRAIGHT].type == WindowWidgetType::Empty) { @@ -4267,7 +4268,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutSlopeDown() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_STRAIGHT) || w->widgets[WIDX_STRAIGHT].type == WindowWidgetType::Empty) { @@ -4378,7 +4379,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutSlopeUp() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_STRAIGHT) || w->widgets[WIDX_STRAIGHT].type == WindowWidgetType::Empty) { @@ -4489,7 +4490,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutChainLiftToggle() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_CHAIN_LIFT) || w->widgets[WIDX_CHAIN_LIFT].type == WindowWidgetType::Empty) @@ -4502,7 +4503,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutBankLeft() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_BANK_STRAIGHT) || w->widgets[WIDX_BANK_STRAIGHT].type == WindowWidgetType::Empty) @@ -4539,7 +4540,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutBankRight() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_BANK_STRAIGHT) || w->widgets[WIDX_BANK_STRAIGHT].type == WindowWidgetType::Empty) @@ -4576,7 +4577,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutPreviousTrack() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_PREVIOUS_SECTION) || w->widgets[WIDX_PREVIOUS_SECTION].type == WindowWidgetType::Empty) @@ -4589,7 +4590,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutNextTrack() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_NEXT_SECTION) || w->widgets[WIDX_NEXT_SECTION].type == WindowWidgetType::Empty) @@ -4602,7 +4603,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutBuildCurrent() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_CONSTRUCT) || w->widgets[WIDX_CONSTRUCT].type == WindowWidgetType::Empty) { @@ -4614,7 +4615,7 @@ namespace OpenRCT2::Ui::Windows void WindowRideConstructionKeyboardShortcutDemolishCurrent() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w == nullptr || WidgetIsDisabled(*w, WIDX_DEMOLISH) || w->widgets[WIDX_DEMOLISH].type == WindowWidgetType::Empty) { diff --git a/src/openrct2-ui/windows/RideList.cpp b/src/openrct2-ui/windows/RideList.cpp index 5d2c49ac9c..07c974170b 100644 --- a/src/openrct2-ui/windows/RideList.cpp +++ b/src/openrct2-ui/windows/RideList.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -977,10 +978,12 @@ namespace OpenRCT2::Ui::Windows WindowBase* RideListOpen() { // Check if window is already open - auto* window = WindowBringToFrontByClass(WindowClass::RideList); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::RideList); if (window == nullptr) { - window = WindowCreate(WindowClass::RideList, ScreenCoordsXY(32, 32), WW, WH, WF_10 | WF_RESIZABLE); + window = windowMgr->Create( + WindowClass::RideList, ScreenCoordsXY(32, 32), WW, WH, WF_10 | WF_RESIZABLE); } return window; } diff --git a/src/openrct2-ui/windows/SavePrompt.cpp b/src/openrct2-ui/windows/SavePrompt.cpp index e454126c35..2a100d9f2a 100644 --- a/src/openrct2-ui/windows/SavePrompt.cpp +++ b/src/openrct2-ui/windows/SavePrompt.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -229,8 +230,10 @@ namespace OpenRCT2::Ui::Windows } } + auto* windowMgr = GetWindowManager(); + // Check if window is already open - WindowBase* window = WindowBringToFrontByClass(WindowClass::SavePrompt); + auto* window = windowMgr->BringToFrontByClass(WindowClass::SavePrompt); if (window != nullptr) { WindowClose(*window); @@ -251,7 +254,7 @@ namespace OpenRCT2::Ui::Windows } auto savePromptWindow = std::make_unique(prompt_mode); - return WindowCreate( + return windowMgr->Create( std::move(savePromptWindow), WindowClass::SavePrompt, {}, width, height, WF_TRANSPARENT | WF_STICK_TO_FRONT | WF_CENTRE_SCREEN | WF_AUTO_POSITION); } diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index 65003c5362..b524bfa72a 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -767,7 +768,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ScenarioselectOpen(std::function callback) { - auto* window = static_cast(WindowBringToFrontByClass(WindowClass::ScenarioSelect)); + auto* windowMgr = GetWindowManager(); + auto* window = static_cast(windowMgr->BringToFrontByClass(WindowClass::ScenarioSelect)); if (window != nullptr) { return window; @@ -776,7 +778,7 @@ namespace OpenRCT2::Ui::Windows int32_t screenWidth = ContextGetWidth(); int32_t screenHeight = ContextGetHeight(); ScreenCoordsXY screenPos = { (screenWidth - WW) / 2, std::max(kTopToolbarHeight + 1, (screenHeight - WH) / 2) }; - window = WindowCreate(WindowClass::ScenarioSelect, screenPos, WW, WH, 0, callback); + window = windowMgr->Create(WindowClass::ScenarioSelect, screenPos, WW, WH, 0, callback); return window; } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 73730c0195..08e315a076 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -422,7 +421,7 @@ namespace OpenRCT2::Ui::Windows // Find out what scenery the cursor is over const CursorState* state = ContextGetCursorState(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WidgetIndex widgetIndex = windowMgr->FindWidgetFromPoint(*this, state->position); if (widgetIndex == WIDX_SCENERY_LIST) { @@ -451,7 +450,7 @@ namespace OpenRCT2::Ui::Windows { const CursorState* state = ContextGetCursorState(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* other = windowMgr->FindFromPoint(state->position); if (other == this) { @@ -2435,7 +2434,7 @@ namespace OpenRCT2::Ui::Windows const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, uint8_t* outQuadrant, Direction* outRotation) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::Scenery); if (w == nullptr) @@ -2633,7 +2632,7 @@ namespace OpenRCT2::Ui::Windows void Sub6E1F34PathItem( const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, int32_t* outZ) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::Scenery); if (w == nullptr) @@ -2667,7 +2666,7 @@ namespace OpenRCT2::Ui::Windows void Sub6E1F34Wall( const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, uint8_t* outEdges) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::Scenery); if (w == nullptr) @@ -2758,7 +2757,7 @@ namespace OpenRCT2::Ui::Windows void Sub6E1F34LargeScenery( const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, Direction* outDirection) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::Scenery); if (w == nullptr) @@ -2860,7 +2859,7 @@ namespace OpenRCT2::Ui::Windows const ScreenCoordsXY& sourceScreenPos, ObjectEntryIndex sceneryIndex, CoordsXY& gridPos, int32_t* outZ, Direction* outDirection) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = windowMgr->FindByClass(WindowClass::Scenery); if (w == nullptr) @@ -3210,10 +3209,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* SceneryOpen() { - auto* w = static_cast(WindowBringToFrontByClass(WindowClass::Scenery)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByClass(WindowClass::Scenery)); if (w == nullptr) { - w = WindowCreate(WindowClass::Scenery); + w = windowMgr->Create(WindowClass::Scenery); } return w; } @@ -3222,7 +3222,8 @@ namespace OpenRCT2::Ui::Windows const ScenerySelection& scenery, const std::optional primary, const std::optional secondary, const std::optional tertiary, const std::optional rotation) { - auto* w = static_cast(WindowBringToFrontByClass(WindowClass::Scenery)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByClass(WindowClass::Scenery)); if (w != nullptr) { w->SetSelectedItem(scenery, primary, secondary, tertiary, rotation); @@ -3232,7 +3233,7 @@ namespace OpenRCT2::Ui::Windows void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex) { // Should this bring to front? - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = static_cast(windowMgr->FindByClass(WindowClass::Scenery)); if (w != nullptr) { @@ -3259,7 +3260,7 @@ namespace OpenRCT2::Ui::Windows const ScenerySelection WindowSceneryGetTabSelection() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = static_cast(windowMgr->FindByClass(WindowClass::Scenery)); if (w != nullptr) { @@ -3273,7 +3274,7 @@ namespace OpenRCT2::Ui::Windows void WindowSceneryInit() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* w = static_cast(windowMgr->FindByClass(WindowClass::Scenery)); if (w != nullptr) { diff --git a/src/openrct2-ui/windows/SceneryScatter.cpp b/src/openrct2-ui/windows/SceneryScatter.cpp index 57a10df675..5c05106491 100644 --- a/src/openrct2-ui/windows/SceneryScatter.cpp +++ b/src/openrct2-ui/windows/SceneryScatter.cpp @@ -11,11 +11,9 @@ #include #include #include -#include #include #include #include -#include #include #include @@ -207,11 +205,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* SceneryScatterOpen() { // Check if window is already open - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindByClass(WindowClass::SceneryScatter); if (window == nullptr) { - window = WindowCreate(WindowClass::SceneryScatter, 86, 100, 0); + window = windowMgr->Create(WindowClass::SceneryScatter, 86, 100, 0); } return window; diff --git a/src/openrct2-ui/windows/ServerList.cpp b/src/openrct2-ui/windows/ServerList.cpp index 0a2789fb23..8974796987 100644 --- a/src/openrct2-ui/windows/ServerList.cpp +++ b/src/openrct2-ui/windows/ServerList.cpp @@ -25,6 +25,7 @@ #include #include #include + #include #include namespace OpenRCT2::Ui::Windows @@ -546,11 +547,12 @@ namespace OpenRCT2::Ui::Windows WindowBase* ServerListOpen() { // Check if window is already open - auto* window = WindowBringToFrontByClass(WindowClass::ServerList); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::ServerList); if (window != nullptr) return window; - window = WindowCreate( + window = windowMgr->Create( WindowClass::ServerList, WWIDTH_MIN, WHEIGHT_MIN, WF_10 | WF_RESIZABLE | WF_CENTRE_SCREEN); return window; diff --git a/src/openrct2-ui/windows/ServerStart.cpp b/src/openrct2-ui/windows/ServerStart.cpp index 0c966df47c..543b74b3c9 100644 --- a/src/openrct2-ui/windows/ServerStart.cpp +++ b/src/openrct2-ui/windows/ServerStart.cpp @@ -19,6 +19,7 @@ #include #include #include + #include #include namespace OpenRCT2::Ui::Windows @@ -283,7 +284,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ServerStartOpen() { - return WindowFocusOrCreate(WindowClass::ServerStart, WW, WH, WF_CENTRE_SCREEN); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::ServerStart, WW, WH, WF_CENTRE_SCREEN); } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/ShortcutKeys.cpp b/src/openrct2-ui/windows/ShortcutKeys.cpp index 9b079d8c5c..781c17b7b0 100644 --- a/src/openrct2-ui/windows/ShortcutKeys.cpp +++ b/src/openrct2-ui/windows/ShortcutKeys.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -81,8 +80,9 @@ namespace OpenRCT2::Ui::Windows auto registeredShortcut = shortcutManager.GetShortcut(shortcutId); if (registeredShortcut != nullptr) { + auto* windowMgr = GetWindowManager(); WindowCloseByClass(WindowClass::ChangeKeyboardShortcut); - auto w = WindowCreate( + auto* w = windowMgr->Create( WindowClass::ChangeKeyboardShortcut, CHANGE_WW, CHANGE_WH, WF_CENTRE_SCREEN); if (w != nullptr) { @@ -544,7 +544,7 @@ namespace OpenRCT2::Ui::Windows void ChangeShortcutWindow::NotifyShortcutKeysWindow() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::KeyboardShortcutList); if (w != nullptr) { @@ -554,10 +554,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* ShortcutKeysOpen() { - auto w = WindowBringToFrontByClass(WindowClass::KeyboardShortcutList); + auto* windowMgr = GetWindowManager(); + auto w = windowMgr->BringToFrontByClass(WindowClass::KeyboardShortcutList); if (w == nullptr) { - w = WindowCreate(WindowClass::KeyboardShortcutList, WW, WH, WF_RESIZABLE); + w = windowMgr->Create(WindowClass::KeyboardShortcutList, WW, WH, WF_RESIZABLE); } return w; } @@ -600,7 +601,7 @@ namespace OpenRCT2::Ui::Windows { case WIDX_RESET_PROMPT_RESET: { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::KeyboardShortcutList); if (w != nullptr) { @@ -619,7 +620,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* ResetShortcutKeysPromptOpen() { - return WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate( WindowClass::ResetShortcutKeysPrompt, RESET_PROMPT_WW, RESET_PROMPT_WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); } #pragma endregion diff --git a/src/openrct2-ui/windows/Sign.cpp b/src/openrct2-ui/windows/Sign.cpp index 3f3bf92f19..3f140a5256 100644 --- a/src/openrct2-ui/windows/Sign.cpp +++ b/src/openrct2-ui/windows/Sign.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -334,12 +335,13 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* SignOpen(rct_windownumber number) { - auto* w = static_cast(WindowBringToFrontByNumber(WindowClass::Banner, number)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Banner, number)); if (w != nullptr) return w; - w = WindowCreate(WindowClass::Banner, WW, WH, 0); + w = windowMgr->Create(WindowClass::Banner, WW, WH, 0); if (w == nullptr) return nullptr; @@ -357,12 +359,13 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* SignSmallOpen(rct_windownumber number) { - auto* w = static_cast(WindowBringToFrontByNumber(WindowClass::Banner, number)); + auto* windowMgr = GetWindowManager(); + auto* w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Banner, number)); if (w != nullptr) return w; - w = WindowCreate(WindowClass::Banner, WW, WH, 0); + w = windowMgr->Create(WindowClass::Banner, WW, WH, 0); if (w == nullptr) return nullptr; diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index eed00969f7..9eeb6bf6e4 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -381,7 +380,7 @@ namespace OpenRCT2::Ui::Windows if (result->Error != GameActions::Status::Ok) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); WindowBase* wind = windowMgr->FindByNumber(WindowClass::Peep, peepnum); if (wind != nullptr) { @@ -1276,13 +1275,13 @@ namespace OpenRCT2::Ui::Windows WindowBase* StaffOpen(Peep* peep) { - auto w = static_cast(WindowBringToFrontByNumber(WindowClass::Peep, peep->Id.ToUnderlying())); + auto* windowMgr = GetWindowManager(); + auto w = static_cast(windowMgr->BringToFrontByNumber(WindowClass::Peep, peep->Id.ToUnderlying())); if (w != nullptr) return w; - w = WindowCreate(WindowClass::Peep, WW, WH, WF_10 | WF_RESIZABLE); - + w = windowMgr->Create(WindowClass::Peep, WW, WH, WF_10 | WF_RESIZABLE); if (w == nullptr) return nullptr; diff --git a/src/openrct2-ui/windows/StaffFirePrompt.cpp b/src/openrct2-ui/windows/StaffFirePrompt.cpp index 3b24b3b7a2..e8c1336db0 100644 --- a/src/openrct2-ui/windows/StaffFirePrompt.cpp +++ b/src/openrct2-ui/windows/StaffFirePrompt.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -98,7 +99,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* StaffFirePromptOpen(Peep* peep) { // Check if the confirm window already exists - auto* window = WindowFocusOrCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate( WindowClass::FirePrompt, WW, WH, WF_CENTRE_SCREEN | WF_TRANSPARENT); window->SetWindowNumber(peep->Id.ToUnderlying()); return window; diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 24928e529b..63984bc27e 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include @@ -202,7 +201,7 @@ namespace OpenRCT2::Ui::Windows } // Enable highlighting of these staff members in map window - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::Map) != nullptr) { for (auto peep : EntityList()) @@ -745,12 +744,13 @@ namespace OpenRCT2::Ui::Windows WindowBase* StaffListOpen() { - return WindowFocusOrCreate(WindowClass::StaffList, WW, WH, WF_10 | WF_RESIZABLE); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::StaffList, WW, WH, WF_10 | WF_RESIZABLE); } void WindowStaffListRefresh() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindByClass(WindowClass::StaffList); if (window != nullptr) { diff --git a/src/openrct2-ui/windows/TextInput.cpp b/src/openrct2-ui/windows/TextInput.cpp index 79db7aef42..d8f458a533 100644 --- a/src/openrct2-ui/windows/TextInput.cpp +++ b/src/openrct2-ui/windows/TextInput.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -364,7 +363,7 @@ namespace OpenRCT2::Ui::Windows WindowBase* GetParentWindow() const { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); return HasParentWindow() ? windowMgr->FindByNumber(_parentWidget.window.classification, _parentWidget.window.number) : nullptr; } @@ -374,10 +373,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* call_w, WidgetIndex call_widget, StringId title, StringId description, const Formatter& descriptionArgs, const_utf8string existing_text, int32_t maxLength) { + auto* windowMgr = GetWindowManager(); WindowCloseByClass(WindowClass::Textinput); auto height = TextInputWindow::CalculateWindowHeight(existing_text); - auto w = WindowCreate(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); + auto w = windowMgr->Create(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); if (w != nullptr) { w->SetParentWindow(call_w, call_widget); @@ -390,8 +390,9 @@ namespace OpenRCT2::Ui::Windows std::string_view title, std::string_view description, std::string_view initialValue, size_t maxLength, std::function callback, std::function cancelCallback) { + auto* windowMgr = GetWindowManager(); auto height = TextInputWindow::CalculateWindowHeight(initialValue); - auto w = WindowCreate(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); + auto w = windowMgr->Create(WindowClass::Textinput, WW, height, WF_CENTRE_SCREEN | WF_STICK_TO_FRONT); if (w != nullptr) { w->SetTitle(title, description); @@ -424,7 +425,7 @@ namespace OpenRCT2::Ui::Windows } // The window can be potentially closed within a callback, we need to check if its still alive. - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); w = windowMgr->FindByNumber(wndClass, wndNumber); if (w != nullptr) w->Invalidate(); diff --git a/src/openrct2-ui/windows/Themes.cpp b/src/openrct2-ui/windows/Themes.cpp index 05a5c1e849..0bf940d865 100644 --- a/src/openrct2-ui/windows/Themes.cpp +++ b/src/openrct2-ui/windows/Themes.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows @@ -387,7 +386,7 @@ namespace OpenRCT2::Ui::Windows pressed_widgets = pressedWidgets | (1 << widgetIndex); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::Dropdown) == nullptr) { _classIndex = -1; @@ -972,14 +971,13 @@ namespace OpenRCT2::Ui::Windows WindowBase* ThemesOpen() { - WindowBase* window; - // Check if window is already open - window = WindowBringToFrontByClass(WindowClass::Themes); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::Themes); if (window != nullptr) return window; - window = WindowCreate(WindowClass::Themes, 320, 107, WF_10 | WF_RESIZABLE); + window = windowMgr->Create(WindowClass::Themes, 320, 107, WF_10 | WF_RESIZABLE); return window; } diff --git a/src/openrct2-ui/windows/TileInspector.cpp b/src/openrct2-ui/windows/TileInspector.cpp index 04b5faaae8..43b4473e88 100644 --- a/src/openrct2-ui/windows/TileInspector.cpp +++ b/src/openrct2-ui/windows/TileInspector.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -2440,15 +2439,16 @@ static uint64_t PageDisabledWidgets[] = { WindowBase* TileInspectorOpen() { - WindowBase* window = WindowBringToFrontByClass(WindowClass::TileInspector); + auto* windowMgr = GetWindowManager(); + WindowBase* window = windowMgr->BringToFrontByClass(WindowClass::TileInspector); if (window == nullptr) - window = WindowCreate(WindowClass::TileInspector, ScreenCoordsXY(0, 29), WW, WH, WF_RESIZABLE); + window = windowMgr->Create(WindowClass::TileInspector, ScreenCoordsXY(0, 29), WW, WH, WF_RESIZABLE); return window; } void WindowTileInspectorClearClipboard() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindByClass(WindowClass::TileInspector); if (window != nullptr) static_cast(window)->ClearClipboard(); @@ -2456,7 +2456,7 @@ static uint64_t PageDisabledWidgets[] = { void WindowTileInspectorKeyboardShortcutToggleInvisibility() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindByClass(WindowClass::TileInspector); if (window != nullptr) static_cast(window)->ToggleInvisibility(); diff --git a/src/openrct2-ui/windows/TitleExit.cpp b/src/openrct2-ui/windows/TitleExit.cpp index ef4b3d5837..27f8a17f2d 100644 --- a/src/openrct2-ui/windows/TitleExit.cpp +++ b/src/openrct2-ui/windows/TitleExit.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -54,7 +55,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* TitleExitOpen() { - return WindowCreate( + auto* windowMgr = GetWindowManager(); + return windowMgr->Create( WindowClass::TitleExit, ScreenCoordsXY(ContextGetWidth() - 40, ContextGetHeight() - 64), 40, 64, WF_STICK_TO_BACK | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/TitleLogo.cpp b/src/openrct2-ui/windows/TitleLogo.cpp index 81ab20ddf2..fc2502b098 100644 --- a/src/openrct2-ui/windows/TitleLogo.cpp +++ b/src/openrct2-ui/windows/TitleLogo.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -67,10 +68,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* TitleLogoOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::TitleLogo); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::TitleLogo); if (window == nullptr) { - window = WindowCreate( + window = windowMgr->Create( WindowClass::TitleLogo, ScreenCoordsXY(0, 0), WW, WH, WF_STICK_TO_BACK | WF_TRANSPARENT); } return window; diff --git a/src/openrct2-ui/windows/TitleMenu.cpp b/src/openrct2-ui/windows/TitleMenu.cpp index ce3731dc7f..fa60549afd 100644 --- a/src/openrct2-ui/windows/TitleMenu.cpp +++ b/src/openrct2-ui/windows/TitleMenu.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -121,7 +120,7 @@ namespace OpenRCT2::Ui::Windows { WindowBase* windowToOpen = nullptr; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); switch (widgetIndex) { @@ -129,7 +128,7 @@ namespace OpenRCT2::Ui::Windows windowToOpen = windowMgr->FindByClass(WindowClass::ScenarioSelect); if (windowToOpen != nullptr) { - WindowBringToFront(*windowToOpen); + windowMgr->BringToFront(*windowToOpen); } else { @@ -142,7 +141,7 @@ namespace OpenRCT2::Ui::Windows windowToOpen = windowMgr->FindByClass(WindowClass::Loadsave); if (windowToOpen != nullptr) { - WindowBringToFront(*windowToOpen); + windowMgr->BringToFront(*windowToOpen); } else { @@ -156,7 +155,7 @@ namespace OpenRCT2::Ui::Windows windowToOpen = windowMgr->FindByClass(WindowClass::ServerList); if (windowToOpen != nullptr) { - WindowBringToFront(*windowToOpen); + windowMgr->BringToFront(*windowToOpen); } else { @@ -287,7 +286,9 @@ namespace OpenRCT2::Ui::Windows WindowBase* TitleMenuOpen() { const uint16_t windowHeight = MenuButtonDims.height + UpdateButtonDims.height; - return WindowCreate( + + auto* windowMgr = GetWindowManager(); + return windowMgr->Create( WindowClass::TitleMenu, ScreenCoordsXY(0, ContextGetHeight() - 182), 0, windowHeight, WF_STICK_TO_BACK | WF_TRANSPARENT | WF_NO_BACKGROUND); } diff --git a/src/openrct2-ui/windows/TitleOptions.cpp b/src/openrct2-ui/windows/TitleOptions.cpp index 4657f236e5..6aa1ba29ec 100644 --- a/src/openrct2-ui/windows/TitleOptions.cpp +++ b/src/openrct2-ui/windows/TitleOptions.cpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -52,10 +53,11 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* TitleOptionsOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::TitleOptions); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::TitleOptions); if (window == nullptr) { - window = WindowCreate( + window = windowMgr->Create( WindowClass::TitleOptions, ScreenCoordsXY(ContextGetWidth() - 80, 0), 80, 15, WF_STICK_TO_BACK | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/TitleVersion.cpp b/src/openrct2-ui/windows/TitleVersion.cpp index 791a9049fb..f117afc087 100644 --- a/src/openrct2-ui/windows/TitleVersion.cpp +++ b/src/openrct2-ui/windows/TitleVersion.cpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -39,10 +40,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* TitleVersionOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::TitleVersion); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::TitleVersion); if (window == nullptr) { - window = WindowCreate( + window = windowMgr->Create( WindowClass::TitleVersion, ScreenCoordsXY(kTextOffset, ContextGetHeight() - 30), WW, WH, WF_STICK_TO_BACK | WF_TRANSPARENT); } diff --git a/src/openrct2-ui/windows/Tooltip.cpp b/src/openrct2-ui/windows/Tooltip.cpp index 16454fbc4b..848d391444 100644 --- a/src/openrct2-ui/windows/Tooltip.cpp +++ b/src/openrct2-ui/windows/Tooltip.cpp @@ -16,6 +16,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -158,7 +159,9 @@ namespace OpenRCT2::Ui::Windows auto windowPos = tooltipWindow->windowPos; auto width = tooltipWindow->width; auto height = tooltipWindow->height; - WindowCreate( + + auto* windowMgr = GetWindowManager(); + windowMgr->Create( std::move(tooltipWindow), WindowClass::Tooltip, windowPos, width, height, WF_TRANSPARENT | WF_STICK_TO_FRONT); } diff --git a/src/openrct2-ui/windows/TopToolbar.cpp b/src/openrct2-ui/windows/TopToolbar.cpp index 098851dd15..845dc8b122 100644 --- a/src/openrct2-ui/windows/TopToolbar.cpp +++ b/src/openrct2-ui/windows/TopToolbar.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -777,7 +776,7 @@ namespace OpenRCT2::Ui::Windows void ApplyFootpathPressed() { // Footpath button pressed down - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::Footpath) == nullptr) pressed_widgets &= ~(1uLL << WIDX_PATH); else @@ -998,7 +997,8 @@ namespace OpenRCT2::Ui::Windows */ WindowBase* TopToolbarOpen() { - TopToolbar* window = WindowCreate( + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->Create( WindowClass::TopToolbar, ScreenCoordsXY(0, 0), ContextGetWidth(), kTopToolbarHeight + 1, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_BACKGROUND); @@ -1140,7 +1140,7 @@ namespace OpenRCT2::Ui::Windows break; case DDIDX_VIEW_CLIPPING: { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::ViewClipping) == nullptr) { ContextOpenWindow(WindowClass::ViewClipping); @@ -1509,7 +1509,7 @@ namespace OpenRCT2::Ui::Windows { windowPos.x + widget.left, windowPos.y + widget.top }, widget.height() + 1, colours[0].withFlag(ColourFlag::translucent, true), Dropdown::Flag::StayOpen, TOP_TOOLBAR_DEBUG_COUNT); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); Dropdown::SetChecked(DDIDX_DEBUG_PAINT, windowMgr->FindByClass(WindowClass::DebugPaint) != nullptr); } @@ -1528,7 +1528,7 @@ namespace OpenRCT2::Ui::Windows } case DDIDX_DEBUG_PAINT: { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (windowMgr->FindByClass(WindowClass::DebugPaint) == nullptr) { ContextOpenWindow(WindowClass::DebugPaint); diff --git a/src/openrct2-ui/windows/TrackDesignManage.cpp b/src/openrct2-ui/windows/TrackDesignManage.cpp index c82fbb3c58..dd1153d6c0 100644 --- a/src/openrct2-ui/windows/TrackDesignManage.cpp +++ b/src/openrct2-ui/windows/TrackDesignManage.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace OpenRCT2::Ui::Windows { @@ -109,7 +110,9 @@ namespace OpenRCT2::Ui::Windows { WindowCloseByClass(WindowClass::ManageTrackDesign); auto trackDesignManageWindow = std::make_unique(tdFileRef); - auto* window = WindowCreate( + + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->Create( std::move(trackDesignManageWindow), WindowClass::ManageTrackDesign, {}, WW, WH, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_CENTRE_SCREEN | WF_AUTO_POSITION); @@ -194,7 +197,9 @@ namespace OpenRCT2::Ui::Windows int32_t screenWidth = ContextGetWidth(); int32_t screenHeight = ContextGetHeight(); auto trackDeletePromptWindow = std::make_unique(tdFileRef); - WindowCreate( + + auto* windowMgr = GetWindowManager(); + windowMgr->Create( std::move(trackDeletePromptWindow), WindowClass::TrackDeletePrompt, ScreenCoordsXY( std::max(kTopToolbarHeight + 1, (screenWidth - WW_DELETE_PROMPT) / 2), (screenHeight - WH_DELETE_PROMPT) / 2), diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index d35e59895e..b92f2983d5 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -279,7 +278,7 @@ namespace OpenRCT2::Ui::Windows // Unable to build track Audio::Play3D(Audio::SoundId::Error, trackLoc); - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = GetWindowManager(); windowManager->ShowError(res.GetErrorTitle(), res.GetErrorMessage()); return; } @@ -301,7 +300,7 @@ namespace OpenRCT2::Ui::Windows _currentRideIndex = rideId; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); if (TrackDesignAreEntranceAndExitPlaced()) { auto intent = Intent(WindowClass::Ride); @@ -737,7 +736,8 @@ namespace OpenRCT2::Ui::Windows WindowCloseConstructionWindows(); - auto* window = WindowFocusOrCreate(WindowClass::TrackDesignPlace, WW, WH, 0); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->FocusOrCreate(WindowClass::TrackDesignPlace, WW, WH, 0); if (window != nullptr) { window->Init(std::move(openTrackDesign)); @@ -747,7 +747,7 @@ namespace OpenRCT2::Ui::Windows void TrackPlaceClearProvisionalTemporarily() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* trackPlaceWnd = static_cast(windowMgr->FindByClass(WindowClass::TrackDesignPlace)); if (trackPlaceWnd != nullptr) { @@ -757,7 +757,7 @@ namespace OpenRCT2::Ui::Windows void TrackPlaceRestoreProvisional() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* trackPlaceWnd = static_cast(windowMgr->FindByClass(WindowClass::TrackDesignPlace)); if (trackPlaceWnd != nullptr) { diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index bbb102b292..d52cd5b8a4 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -770,12 +769,13 @@ namespace OpenRCT2::Ui::Windows { screenPos = { 0, kTopToolbarHeight + 2 }; } - return WindowCreate(WindowClass::TrackDesignList, WW, WH, 0, item); + auto* windowMgr = GetWindowManager(); + return windowMgr->Create(WindowClass::TrackDesignList, WW, WH, 0, item); } void WindowTrackDesignListReloadTracks() { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* trackListWindow = static_cast(windowMgr->FindByClass(WindowClass::TrackDesignList)); if (trackListWindow != nullptr) { @@ -785,7 +785,7 @@ namespace OpenRCT2::Ui::Windows void WindowTrackDesignListSetBeingUpdated(const bool beingUpdated) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* trackListWindow = static_cast(windowMgr->FindByClass(WindowClass::TrackDesignList)); if (trackListWindow != nullptr) { diff --git a/src/openrct2-ui/windows/Transparency.cpp b/src/openrct2-ui/windows/Transparency.cpp index 77381784cb..9324e76085 100644 --- a/src/openrct2-ui/windows/Transparency.cpp +++ b/src/openrct2-ui/windows/Transparency.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -24,6 +23,7 @@ #include #include #include +#include #include #include @@ -249,9 +249,10 @@ namespace OpenRCT2::Ui::Windows WindowBase* TransparencyOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::Transparency); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::Transparency); if (window == nullptr) - window = WindowCreate(WindowClass::Transparency, ScreenCoordsXY(32, 32), WW, WH); + window = windowMgr->Create(WindowClass::Transparency, ScreenCoordsXY(32, 32), WW, WH); return window; } diff --git a/src/openrct2-ui/windows/ViewClipping.cpp b/src/openrct2-ui/windows/ViewClipping.cpp index 15e30a91d1..9acb3b3836 100644 --- a/src/openrct2-ui/windows/ViewClipping.cpp +++ b/src/openrct2-ui/windows/ViewClipping.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -400,10 +401,11 @@ namespace OpenRCT2::Ui::Windows WindowBase* ViewClippingOpen() { - auto* window = WindowBringToFrontByClass(WindowClass::ViewClipping); + auto* windowMgr = GetWindowManager(); + auto* window = windowMgr->BringToFrontByClass(WindowClass::ViewClipping); if (window == nullptr) { - window = WindowCreate(WindowClass::ViewClipping, ScreenCoordsXY(32, 32), WW, WH); + window = windowMgr->Create(WindowClass::ViewClipping, ScreenCoordsXY(32, 32), WW, WH); } return window; } diff --git a/src/openrct2-ui/windows/Viewport.cpp b/src/openrct2-ui/windows/Viewport.cpp index 13476843d1..2c9b7d3e80 100644 --- a/src/openrct2-ui/windows/Viewport.cpp +++ b/src/openrct2-ui/windows/Viewport.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include namespace OpenRCT2::Ui::Windows @@ -229,7 +230,9 @@ namespace OpenRCT2::Ui::Windows int32_t width = (screenWidth / 2); int32_t height = (screenHeight / 2); - auto* w = WindowCreate(WindowClass::Viewport, std::max(WW, width), std::max(WH, height), WF_RESIZABLE); + auto* windowMgr = GetWindowManager(); + auto* w = windowMgr->Create( + WindowClass::Viewport, std::max(WW, width), std::max(WH, height), WF_RESIZABLE); if (w != nullptr) return w; diff --git a/src/openrct2-ui/windows/Water.cpp b/src/openrct2-ui/windows/Water.cpp index 8427e3ef88..50f56e7a36 100644 --- a/src/openrct2-ui/windows/Water.cpp +++ b/src/openrct2-ui/windows/Water.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -253,7 +252,7 @@ namespace OpenRCT2::Ui::Windows */ void WaterToolDrag(const ScreenCoordsXY& screenPos) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = GetWindowManager(); auto* window = windowMgr->FindFromPoint(screenPos); if (window == nullptr || window->viewport == nullptr) return; @@ -426,7 +425,8 @@ namespace OpenRCT2::Ui::Windows WindowBase* WaterOpen() { - return WindowFocusOrCreate(WindowClass::Water, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); + auto* windowMgr = GetWindowManager(); + return windowMgr->FocusOrCreate(WindowClass::Water, ScreenCoordsXY(ContextGetWidth() - WW, 29), WW, WH, 0); } /** diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index d3b12419b4..d9df787f52 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -1558,7 +1558,7 @@ namespace OpenRCT2 void ContextInit() { - GetContext()->GetUiContext()->GetWindowManager()->Init(); + GetWindowManager()->Init(); } bool ContextLoadParkFromStream(void* stream) @@ -1676,55 +1676,55 @@ void ContextSetCursorTrap(bool value) WindowBase* ContextOpenWindow(WindowClass wc) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); return windowManager->OpenWindow(wc); } WindowBase* ContextOpenWindowView(uint8_t wc) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); return windowManager->OpenView(wc); } WindowBase* ContextOpenDetailWindow(uint8_t type, int32_t id) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); return windowManager->OpenDetails(type, id); } WindowBase* ContextOpenIntent(Intent* intent) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); return windowManager->OpenIntent(intent); } void ContextBroadcastIntent(Intent* intent) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->BroadcastIntent(*intent); } void ContextForceCloseWindowByClass(WindowClass windowClass) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->ForceClose(windowClass); } WindowBase* ContextShowError(StringId title, StringId message, const Formatter& args, const bool autoClose /* = false */) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); return windowManager->ShowError(title, message, args, autoClose); } void ContextHandleInput() { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->HandleInput(); } void ContextInputHandleKeyboard(bool isTitle) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->HandleKeyboard(isTitle); } diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 7bef462b2f..9639c82e57 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -325,7 +325,7 @@ namespace OpenRCT2::Editor return; } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); switch (GetGameState().EditorStep) { @@ -382,7 +382,7 @@ namespace OpenRCT2::Editor static void FinaliseMainView() { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); auto& gameState = GetGameState(); windowManager->SetMainView(gameState.SavedView, gameState.SavedViewZoom, gameState.SavedViewRotation); diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index ffb6c1eaf5..37dc1a304d 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -451,7 +451,7 @@ namespace OpenRCT2::GameActions if (result.Error != GameActions::Status::Ok && shouldShowError) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->ShowError(result.GetErrorTitle(), result.GetErrorMessage()); } diff --git a/src/openrct2/actions/ParkMarketingAction.cpp b/src/openrct2/actions/ParkMarketingAction.cpp index 0868583de1..a3fbede755 100644 --- a/src/openrct2/actions/ParkMarketingAction.cpp +++ b/src/openrct2/actions/ParkMarketingAction.cpp @@ -83,7 +83,7 @@ GameActions::Result ParkMarketingAction::Execute() const MarketingNewCampaign(campaign); // We are only interested in invalidating the finances (marketing) window - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_UPDATE_CASH)); return CreateResult(); diff --git a/src/openrct2/actions/ParkSetLoanAction.cpp b/src/openrct2/actions/ParkSetLoanAction.cpp index 38d92fd65f..75ea2d3a71 100644 --- a/src/openrct2/actions/ParkSetLoanAction.cpp +++ b/src/openrct2/actions/ParkSetLoanAction.cpp @@ -71,7 +71,7 @@ GameActions::Result ParkSetLoanAction::Execute() const gameState.Cash -= (gameState.BankLoan - _value); gameState.BankLoan = _value; - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_UPDATE_CASH)); return GameActions::Result(); } diff --git a/src/openrct2/actions/ParkSetResearchFundingAction.cpp b/src/openrct2/actions/ParkSetResearchFundingAction.cpp index f170d5139b..2539fd7c12 100644 --- a/src/openrct2/actions/ParkSetResearchFundingAction.cpp +++ b/src/openrct2/actions/ParkSetResearchFundingAction.cpp @@ -61,7 +61,7 @@ GameActions::Result ParkSetResearchFundingAction::Execute() const gameState.ResearchPriorities = _priorities; gameState.ResearchFundingLevel = _fundingAmount; - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_UPDATE_RESEARCH)); return GameActions::Result(); } diff --git a/src/openrct2/actions/RideDemolishAction.cpp b/src/openrct2/actions/RideDemolishAction.cpp index 51d45621ed..a878603ff0 100644 --- a/src/openrct2/actions/RideDemolishAction.cpp +++ b/src/openrct2/actions/RideDemolishAction.cpp @@ -166,7 +166,7 @@ GameActions::Result RideDemolishAction::DemolishRide(Ride& ride) const WindowCloseByClass(WindowClass::NewCampaign); // Refresh windows that display the ride name - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_GUEST_LIST)); diff --git a/src/openrct2/actions/RideSetNameAction.cpp b/src/openrct2/actions/RideSetNameAction.cpp index f03851e16f..1709bcb776 100644 --- a/src/openrct2/actions/RideSetNameAction.cpp +++ b/src/openrct2/actions/RideSetNameAction.cpp @@ -89,7 +89,7 @@ GameActions::Result RideSetNameAction::Execute() const GfxInvalidateScreen(); // Refresh windows that display ride name - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_RIDE_LIST)); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_GUEST_LIST)); diff --git a/src/openrct2/actions/RideSetStatusAction.cpp b/src/openrct2/actions/RideSetStatusAction.cpp index fb347cb3fb..b3d4e86c86 100644 --- a/src/openrct2/actions/RideSetStatusAction.cpp +++ b/src/openrct2/actions/RideSetStatusAction.cpp @@ -202,7 +202,7 @@ GameActions::Result RideSetStatusAction::Execute() const // Fix #3183: Make sure we close the construction window so the ride finishes any editing code before opening // otherwise vehicles get added to the ride incorrectly (such as to a ghost station) - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* constructionWindow = windowMgr->FindByNumber(WindowClass::RideConstruction, _rideIndex.ToUnderlying()); if (constructionWindow != nullptr) { @@ -243,7 +243,7 @@ GameActions::Result RideSetStatusAction::Execute() const Guard::Assert(false, "Invalid ride status %u", _status); break; } - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_REFRESH_CAMPAIGN_RIDE_LIST)); return res; diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index bec70cc448..560183e494 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1455,7 +1455,7 @@ void Guest::CheckCantFindRide() GuestHeadingToRideId = RideId::GetNull(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(WindowClass::Peep, Id); if (w != nullptr) @@ -3145,7 +3145,7 @@ static void PeepLeavePark(Guest* peep) peep->InsertNewThought(PeepThoughtType::GoHome); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(WindowClass::Peep, peep->Id); if (w != nullptr) w->OnPrepareDraw(); diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 2c2e98ec92..95ae2d9957 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -591,7 +591,7 @@ void PeepDecrementNumRiders(Peep* peep) */ void PeepWindowStateUpdate(Peep* peep) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByNumber(WindowClass::Peep, peep->Id.ToUnderlying()); if (w != nullptr) w->OnPrepareDraw(); diff --git a/src/openrct2/interface/Viewport.cpp b/src/openrct2/interface/Viewport.cpp index 83acf71165..bc4daf17e2 100644 --- a/src/openrct2/interface/Viewport.cpp +++ b/src/openrct2/interface/Viewport.cpp @@ -1730,7 +1730,7 @@ namespace OpenRCT2 */ InteractionInfo GetMapCoordinatesFromPos(const ScreenCoordsXY& screenCoords, int32_t flags) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* window = windowMgr->FindFromPoint(screenCoords); return GetMapCoordinatesFromPosWindow(window, screenCoords, flags); } @@ -1783,7 +1783,7 @@ namespace OpenRCT2 // if unknown viewport visibility, use the containing window to discover the status if (viewport->visibility == VisibilityCache::Unknown) { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); auto owner = windowManager->GetOwner(viewport); if (owner != nullptr && owner->classification != WindowClass::MainWindow) { @@ -1819,7 +1819,7 @@ namespace OpenRCT2 static Viewport* ViewportFindFromPoint(const ScreenCoordsXY& screenCoords) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindFromPoint(screenCoords); if (w == nullptr) return nullptr; @@ -1848,7 +1848,7 @@ namespace OpenRCT2 */ std::optional ScreenGetMapXY(const ScreenCoordsXY& screenCoords, Viewport** viewport) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); // This will get the tile location but we will need the more accuracy WindowBase* window = windowMgr->FindFromPoint(screenCoords); diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index 82e1285862..184c3351e4 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -165,7 +165,7 @@ static constexpr float window_scroll_locations[][2] = { } }); - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); windowManager->UpdateMouseWheel(); } @@ -472,84 +472,6 @@ static constexpr float window_scroll_locations[][2] = { return result; } - /** - * - * rct2: 0x006ECDA4 - */ - WindowBase* WindowBringToFront(WindowBase& w) - { - if (!(w.flags & (WF_STICK_TO_BACK | WF_STICK_TO_FRONT))) - { - auto itSourcePos = WindowGetIterator(&w); - if (itSourcePos != g_window_list.end()) - { - // Insert in front of the first non-stick-to-front window - auto itDestPos = g_window_list.begin(); - for (auto it = g_window_list.rbegin(); it != g_window_list.rend(); it++) - { - auto& w2 = *it; - if (!(w2->flags & WF_STICK_TO_FRONT)) - { - itDestPos = it.base(); - break; - } - } - - g_window_list.splice(itDestPos, g_window_list, itSourcePos); - w.Invalidate(); - - if (w.windowPos.x + w.width < 20) - { - int32_t i = 20 - w.windowPos.x; - w.windowPos.x += i; - if (w.viewport != nullptr) - w.viewport->pos.x += i; - w.Invalidate(); - } - } - } - return &w; - } - - WindowBase* WindowBringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) - { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); - WindowBase* w = windowMgr->FindByClass(cls); - if (w != nullptr) - { - w->flags |= flags; - w->Invalidate(); - w = WindowBringToFront(*w); - } - - return w; - } - - WindowBase* WindowBringToFrontByClass(WindowClass cls) - { - return WindowBringToFrontByClassWithFlags(cls, WF_WHITE_BORDER_MASK); - } - - /** - * - * rct2: 0x006ED78A - * cls (cl) - * number (dx) - */ - WindowBase* WindowBringToFrontByNumber(WindowClass cls, rct_windownumber number) - { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); - WindowBase* w = windowMgr->FindByNumber(cls, number); - if (w != nullptr) - { - w->flags |= WF_WHITE_BORDER_MASK; - w->Invalidate(); - w = WindowBringToFront(*w); - } - - return w; - } - /** * * rct2: 0x006EE65A @@ -834,7 +756,8 @@ static constexpr float window_scroll_locations[][2] = { // HACK: Prevents the redraw from failing when there is // a window on top of the viewport. - WindowBringToFront(w); + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->BringToFront(w); w.Invalidate(); } @@ -1063,7 +986,7 @@ static constexpr float window_scroll_locations[][2] = { gCurrentToolWidget.widget_index); // Abort tool event - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByNumber( gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number); if (w != nullptr) @@ -1081,7 +1004,7 @@ static constexpr float window_scroll_locations[][2] = { if (gScreenFlags & SCREEN_FLAGS_EDITOR) return; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* titleWind = windowMgr->FindByClass(WindowClass::TitleMenu); if (titleWind != nullptr) { @@ -1145,7 +1068,7 @@ static constexpr float window_scroll_locations[][2] = { } } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* topWind = windowMgr->FindByClass(WindowClass::TopToolbar); if (topWind != nullptr) @@ -1338,4 +1261,10 @@ static constexpr float window_scroll_locations[][2] = { return w->viewport; } + + // TODO: declared in WindowManager.h; move when refactors continue + Ui::IWindowManager* Ui::GetWindowManager() + { + return GetContext()->GetUiContext()->GetWindowManager(); + } } // namespace OpenRCT2 diff --git a/src/openrct2/interface/Window.h b/src/openrct2/interface/Window.h index 668e9445d8..b58a62431d 100644 --- a/src/openrct2/interface/Window.h +++ b/src/openrct2/interface/Window.h @@ -380,11 +380,6 @@ namespace OpenRCT2 void WindowSetWindowLimit(int32_t value); - WindowBase* WindowBringToFront(WindowBase& w); - WindowBase* WindowBringToFrontByClass(WindowClass cls); - WindowBase* WindowBringToFrontByClassWithFlags(WindowClass cls, uint16_t flags); - WindowBase* WindowBringToFrontByNumber(WindowClass cls, rct_windownumber number); - void WindowClose(WindowBase& window); void WindowCloseByClass(WindowClass cls); void WindowCloseByNumber(WindowClass cls, rct_windownumber number); diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 0194e5ab8c..927cdba6b3 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -3543,7 +3543,7 @@ const char* NetworkGetGroupName(uint32_t index) void NetworkChatShowConnectedMessage() { - auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = Ui::GetWindowManager(); std::string s = windowManager->GetKeyboardShortcutString("interface.misc.multiplayer_chat"); const char* sptr = s.c_str(); diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index 8e91a15e74..2776b271a9 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -99,7 +99,7 @@ static bool ShouldShowFPS() if (gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) return true; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); return windowMgr->FindByClass(WindowClass::TopToolbar); } diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index a376e5443f..c55117b4d6 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -765,7 +765,7 @@ bool Ride::FindTrackGap(const CoordsXYE& input, CoordsXYE* output) const if (rtd.specialType == RtdSpecialType::maze) return false; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == id) { @@ -2702,7 +2702,7 @@ static ResultWithMessage RideCheckBlockBrakes(const CoordsXYE& input, CoordsXYE* RideId rideIndex = input.element->AsTrack()->GetRideIndex(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == rideIndex) RideConstructionInvalidateCurrentTrack(); @@ -2767,7 +2767,7 @@ static bool RideCheckTrackContainsInversions(const CoordsXYE& input, CoordsXYE* return true; } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && rideIndex == _currentRideIndex) { @@ -2828,7 +2828,7 @@ static bool RideCheckTrackContainsBanked(const CoordsXYE& input, CoordsXYE* outp if (rtd.specialType == RtdSpecialType::maze) return true; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && rideIndex == _currentRideIndex) { @@ -2870,7 +2870,7 @@ static bool RideCheckTrackContainsBanked(const CoordsXYE& input, CoordsXYE* outp */ static int32_t RideCheckStationLength(const CoordsXYE& input, CoordsXYE* output) { - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == input.element->AsTrack()->GetRideIndex()) @@ -2933,7 +2933,7 @@ static bool RideCheckStartAndEndIsStation(const CoordsXYE& input) if (ride == nullptr) return false; - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); auto w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && rideIndex == _currentRideIndex) { @@ -3971,7 +3971,7 @@ void Ride::ConstructMissingEntranceOrExit() const return; } - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr) w->OnMouseUp(entranceOrExit); @@ -5018,7 +5018,7 @@ static int32_t RideGetTrackLength(const Ride& ride) RideId rideIndex = tileElement->AsTrack()->GetRideIndex(); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); WindowBase* w = windowMgr->FindByClass(WindowClass::RideConstruction); if (w != nullptr && _rideConstructionState != RideConstructionState::State0 && _currentRideIndex == rideIndex) { diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index e97cc55fc0..000a34435e 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -119,7 +119,7 @@ static int32_t ride_check_if_construction_allowed(Ride& ride) static WindowBase* ride_create_or_find_construction_window(RideId rideIndex) { - auto* windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowManager = Ui::GetWindowManager(); auto intent = Intent(INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS); intent.PutExtra(INTENT_EXTRA_RIDE_ID, rideIndex.ToUnderlying()); windowManager->BroadcastIntent(intent); @@ -238,7 +238,7 @@ void RideClearForConstruction(Ride& ride) ride.RemoveVehicles(); RideClearBlockedTiles(ride); - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); auto w = windowMgr->FindByNumber(WindowClass::Ride, ride.id.ToUnderlying()); if (w != nullptr) w->OnResize(); @@ -833,7 +833,7 @@ static bool ride_modify_entrance_or_exit(const CoordsXYE& tileElement) auto stationIndex = entranceElement->GetStationIndex(); // Get or create construction window for ride - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); auto constructionWindow = windowMgr->FindByClass(WindowClass::RideConstruction); if (constructionWindow == nullptr) { diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index d8c4b290f2..32ef8bed0b 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -592,7 +592,7 @@ Vehicle* TryGetVehicle(EntityId spriteIndex) void VehicleSoundsUpdate() { - auto windowManager = OpenRCT2::GetContext()->GetUiContext()->GetWindowManager(); + auto windowManager = OpenRCT2::Ui::GetWindowManager(); windowManager->BroadcastIntent(Intent(INTENT_ACTION_UPDATE_VEHICLE_SOUNDS)); } diff --git a/src/openrct2/ui/DummyWindowManager.cpp b/src/openrct2/ui/DummyWindowManager.cpp index 383a5c7b6a..7b5b848baf 100644 --- a/src/openrct2/ui/DummyWindowManager.cpp +++ b/src/openrct2/ui/DummyWindowManager.cpp @@ -69,6 +69,14 @@ namespace OpenRCT2::Ui { return nullptr; } + + WindowBase* Create( + std::unique_ptr&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, + uint32_t flags) override + { + return nullptr; + } + WindowBase* FindByClass(WindowClass cls) override { return nullptr; @@ -89,6 +97,23 @@ namespace OpenRCT2::Ui { return kWidgetIndexNull; } + + WindowBase* BringToFront(WindowBase& w) override + { + return nullptr; + } + WindowBase* BringToFrontByClass(WindowClass cls) override + { + return nullptr; + } + WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) override + { + return nullptr; + } + WindowBase* BringToFrontByNumber(WindowClass cls, rct_windownumber number) override + { + return nullptr; + } }; std::unique_ptr CreateDummyWindowManager() diff --git a/src/openrct2/ui/WindowManager.h b/src/openrct2/ui/WindowManager.h index 7fb6ca2c2d..de40498631 100644 --- a/src/openrct2/ui/WindowManager.h +++ b/src/openrct2/ui/WindowManager.h @@ -43,12 +43,60 @@ namespace OpenRCT2::Ui virtual void UpdateMouseWheel() = 0; virtual WindowBase* GetOwner(const Viewport* viewport) = 0; + virtual WindowBase* Create( + std::unique_ptr&& w, WindowClass cls, ScreenCoordsXY pos, int32_t width, int32_t height, uint32_t flags) + = 0; + + template::value>::type* = nullptr> + T* Create( + WindowClass cls, const ScreenCoordsXY& pos = {}, int32_t width = 0, int32_t height = 0, uint32_t flags = 0, + TArgs&&... args) + { + return static_cast(Create(std::make_unique(std::forward(args)...), cls, pos, width, height, flags)); + } + + template::value>::type* = nullptr> + T* Create(WindowClass cls, int32_t width, int32_t height, uint32_t flags, TArgs&&... args) + { + return static_cast( + Create(std::make_unique(std::forward(args)...), cls, {}, width, height, flags | WF_AUTO_POSITION)); + } + + template::value>::type* = nullptr> + T* FocusOrCreate(WindowClass cls, const ScreenCoordsXY& pos, int32_t width, int32_t height, uint32_t flags = 0) + { + auto* w = BringToFrontByClass(cls); + if (w == nullptr) + { + w = Create(cls, pos, width, height, flags); + } + return static_cast(w); + } + + template::value>::type* = nullptr> + T* FocusOrCreate(WindowClass cls, int32_t width, int32_t height, uint32_t flags = 0) + { + auto* w = BringToFrontByClass(cls); + if (w == nullptr) + { + w = Create(cls, width, height, flags); + } + return static_cast(w); + } + virtual WindowBase* FindByClass(WindowClass cls) = 0; virtual WindowBase* FindByNumber(WindowClass cls, rct_windownumber number) = 0; virtual WindowBase* FindByNumber(WindowClass cls, EntityId id) = 0; virtual WindowBase* FindFromPoint(const ScreenCoordsXY& screenCoords) = 0; virtual WidgetIndex FindWidgetFromPoint(WindowBase& w, const ScreenCoordsXY& screenCoords) = 0; + + virtual WindowBase* BringToFront(WindowBase& w) = 0; + virtual WindowBase* BringToFrontByClass(WindowClass cls) = 0; + virtual WindowBase* BringToFrontByClassWithFlags(WindowClass cls, uint16_t flags) = 0; + virtual WindowBase* BringToFrontByNumber(WindowClass cls, rct_windownumber number) = 0; }; std::unique_ptr CreateDummyWindowManager(); + + IWindowManager* GetWindowManager(); } // namespace OpenRCT2::Ui diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 843e74dc3b..0fea265f76 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -86,7 +86,7 @@ namespace OpenRCT2::TileInspector static bool IsTileSelected(const CoordsXY& loc) { // Return true for everyone who has the window open and tile selected - auto* windowMgr = GetContext()->GetUiContext()->GetWindowManager(); + auto* windowMgr = Ui::GetWindowManager(); auto* window = windowMgr->FindByClass(WindowClass::TileInspector); return window != nullptr && loc == windowTileInspectorTile.ToCoordsXY(); }