From 3747fd70d40316203fbfe1eae09825807cbfb929 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Sun, 23 Mar 2025 15:13:40 +0100 Subject: [PATCH] Force object selection window to close when changing scenes --- src/openrct2-ui/WindowManager.cpp | 4 ++++ .../windows/EditorObjectSelection.cpp | 22 ++++++++++++++++++- src/openrct2-ui/windows/Windows.h | 1 + src/openrct2/scenes/game/GameScene.cpp | 5 +++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index 2ad556eb31..db892c5860 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -586,6 +586,10 @@ public: { switch (windowClass) { + case WindowClass::EditorObjectSelection: + EditorObjectSelectionClose(); + break; + case WindowClass::NetworkStatus: WindowNetworkStatusClose(); break; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index 022d645b24..9b6c9ead40 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -261,6 +261,7 @@ namespace OpenRCT2::Ui::Windows u8string _filter; uint32_t _filterFlags = FILTER_RIDES_ALL; uint8_t _selectedSubTab = 0; + bool _overrideChecks = false; public: /** @@ -292,10 +293,15 @@ namespace OpenRCT2::Ui::Windows VisibleListRefresh(); } + void SetOverrideChecks(bool newState) + { + _overrideChecks = newState; + } + bool CanClose() override { // Prevent window closure when selection is invalid - return EditorObjectSelectionWindowCheck(); + return _overrideChecks || EditorObjectSelectionWindowCheck(); } /** @@ -1625,6 +1631,20 @@ namespace OpenRCT2::Ui::Windows WindowClass::EditorObjectSelection, 755, 400, WF_10 | WF_RESIZABLE | WF_CENTRE_SCREEN); } + // Used for forced closure + void EditorObjectSelectionClose() + { + auto* windowMgr = GetWindowManager(); + auto window = windowMgr->FindByClass(WindowClass::EditorObjectSelection); + if (window == nullptr) + { + return; + } + auto objSelWindow = static_cast(window); + objSelWindow->SetOverrideChecks(true); + objSelWindow->Close(); + } + static bool VisibleListSortRideName(const ObjectListItem& a, const ObjectListItem& b) { auto nameA = a.repositoryItem->Name.c_str(); diff --git a/src/openrct2-ui/windows/Windows.h b/src/openrct2-ui/windows/Windows.h index fda2c211b8..b757e11522 100644 --- a/src/openrct2-ui/windows/Windows.h +++ b/src/openrct2-ui/windows/Windows.h @@ -81,6 +81,7 @@ namespace OpenRCT2::Ui::Windows // EditorObjectSelection WindowBase* EditorObjectSelectionOpen(); bool EditorObjectSelectionWindowCheck(); + void EditorObjectSelectionClose(); // EditorParkEntrance WindowBase* EditorParkEntranceOpen(); diff --git a/src/openrct2/scenes/game/GameScene.cpp b/src/openrct2/scenes/game/GameScene.cpp index 09ea6cdc22..cf579e7751 100644 --- a/src/openrct2/scenes/game/GameScene.cpp +++ b/src/openrct2/scenes/game/GameScene.cpp @@ -35,4 +35,9 @@ void GameScene::Tick() void GameScene::Stop() { Audio::StopAll(); + + // Force closure of any object selection windows, regardless of valid state. + // NB: this is relevant for both in-game scenes and editors, as the window + // may be opened in-game using cheats. + ContextForceCloseWindowByClass(WindowClass::EditorObjectSelection); }