From bf20a6d14674f193a2c18ba2f35b1e5d15392d96 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Tue, 26 Mar 2024 12:53:32 +0000 Subject: [PATCH] Fix #21317: Track designer allows proceeding without an object selected Co-authored-by: Gymnasiast --- distribution/changelog.txt | 2 + .../windows/EditorBottomToolbar.cpp | 23 +----------- .../windows/EditorObjectSelection.cpp | 37 ++++++++++++++++++- src/openrct2-ui/windows/Window.h | 1 + 4 files changed, 40 insertions(+), 23 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 36f979021c..eb7820597f 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -18,6 +18,8 @@ - Fix: [#910] Extra viewport does not preserve the location when rotating. - Fix: [#18413] Crash when mouse over a hacked train. - Fix: [#20338] Cannot select Scenery Picker or Scatter Tool when the scenery recolouring tool is active. +- Fix: [#21317] Track designer allows proceeding without an object selected. +- Fix: [#21360] If the object selection is missing certain types, the Object Selection window will switch to an incorrect tab. - Fix: [#21419] Cannot place walls underground beneath sloped tiles with clearance checks disabled. - Fix: [#21434] Number of guests overflows in objective text. - Fix: [#21543] Crash with creating a TrackIterator with invalid arguments. diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 4e8308eddb..b8b3adb368 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -186,30 +186,9 @@ static Widget _editorBottomToolbarWidgets[] = { GfxInvalidateScreen(); } - bool CheckObjectSelection() const - { - WindowBase* w; - - auto [missingObjectType, errorString] = Editor::CheckObjectSelection(); - if (missingObjectType == ObjectType::None) - { - WindowCloseByClass(WindowClass::EditorObjectSelection); - return true; - } - - ContextShowError(STR_INVALID_SELECTION_OF_OBJECTS, errorString, {}); - w = WindowFindByClass(WindowClass::EditorObjectSelection); - if (w != nullptr) - { - // Click tab with missing object - w->OnMouseUp(WC_EDITOR_OBJECT_SELECTION__WIDX_TAB_1 + EnumValue(missingObjectType)); - } - return false; - } - void JumpForwardFromObjectSelection() const { - if (!CheckObjectSelection()) + if (!EditorObjectSelectionWindowCheck()) return; FinishObjectSelection(); diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index d460443d17..35df6ed24b 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -357,7 +357,9 @@ static std::vector _window_editor_object_selection_widgets = { switch (widgetIndex) { case WIDX_CLOSE: - WindowClose(*this); + if (!(gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER) && !EditorObjectSelectionWindowCheck()) + return; + if (gScreenFlags & SCREEN_FLAGS_EDITOR) { FinishObjectSelection(); @@ -1108,6 +1110,18 @@ static std::vector _window_editor_object_selection_widgets = { DrawDebugData(dpi); } + void GoToTab(ObjectType objectType) + { + for (size_t offset = 0; offset < std::size(TabOrder); offset++) + { + if (TabOrder[offset] == objectType) + { + SetPage(offset); + return; + } + } + } + private: void InitWidgets() { @@ -1660,4 +1674,25 @@ static std::vector _window_editor_object_selection_widgets = { if (showFallbackWarning) ContextShowError(STR_OBJECT_SELECTION_FALLBACK_IMAGES_WARNING, STR_EMPTY, Formatter::Common()); } + + bool EditorObjectSelectionWindowCheck() + { + WindowBase* w; + + auto [missingObjectType, errorString] = Editor::CheckObjectSelection(); + if (missingObjectType == ObjectType::None) + { + WindowCloseByClass(WindowClass::EditorObjectSelection); + return true; + } + + ContextShowError(STR_INVALID_SELECTION_OF_OBJECTS, errorString, {}); + w = WindowFindByClass(WindowClass::EditorObjectSelection); + if (w != nullptr) + { + // Click tab with missing object + static_cast(w)->GoToTab(missingObjectType); + } + return false; + } } // namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index c750d60d1d..2219833e1f 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -207,6 +207,7 @@ namespace OpenRCT2::Ui::Windows void WindowTileInspectorClearClipboard(); WindowBase* EditorObjectSelectionOpen(); + bool EditorObjectSelectionWindowCheck(); void WindowTooltipReset(const ScreenCoordsXY& screenCoords); void WindowTooltipShow(const OpenRCT2String& message, ScreenCoordsXY screenCoords);