diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index a1b03cbe72..809f02ae25 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -297,6 +297,28 @@ public: return w; } + case INTENT_ACTION_NEW_SCENERY: + { + // Check if window is already open + auto* window = window_bring_to_front_by_class(WC_SCENERY); + if (window == nullptr) + { + auto* tlbrWindow = window_find_by_class(WC_TOP_TOOLBAR); + if (tlbrWindow != nullptr) + { + tlbrWindow->Invalidate(); + if (!tool_set(tlbrWindow, WC_TOP_TOOLBAR__WIDX_SCENERY, Tool::Arrow)) + { + input_set_flag(INPUT_FLAG_6, true); + window = WindowSceneryOpen(); + } + } + } + + // Switch to new scenery tab + WindowScenerySetSelectedTab(intent->GetUIntExtra(INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX)); + return window; + } default: Console::Error::WriteLine("Unhandled window class for intent (%d)", intent->GetWindowClass()); return nullptr; diff --git a/src/openrct2-ui/windows/Scenery.cpp b/src/openrct2-ui/windows/Scenery.cpp index 0809b9e9f9..31e86d7881 100644 --- a/src/openrct2-ui/windows/Scenery.cpp +++ b/src/openrct2-ui/windows/Scenery.cpp @@ -1405,6 +1405,21 @@ bool WindowScenerySetSelectedItem(const ScenerySelection& scenery) return result; } +void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex) +{ + const auto* tabInfo = GetSceneryTabInfoForGroup(sceneryGroupIndex); + if (tabInfo == nullptr) + { + tabInfo = &_tabEntries.back(); + } + const auto tabId = std::distance(&*_tabEntries.cbegin(), tabInfo); + auto* window = window_find_by_class(WC_SCENERY); + if (window != nullptr) + { + window_event_mouse_down_call(window, WIDX_SCENERY_TAB_1 + tabId); + } +} + // Used after removing objects, in order to avoid crashes. void WindowSceneryResetSelectedSceneryItems() { diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index 0fa0a1748c..890e682aaf 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -176,6 +176,7 @@ bool WaterToolIsActive(); rct_window* WindowSceneryOpen(); bool WindowScenerySetSelectedItem(const ScenerySelection& scenery); +void WindowScenerySetSelectedTab(const ObjectEntryIndex sceneryGroupIndex); void WindowScenerySetDefaultPlacementConfiguration(); void WindowSceneryInit(); void WindowSceneryResetSelectedSceneryItems(); diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 520de9cdb4..10d9544e0f 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -391,26 +391,9 @@ void News::OpenSubject(News::ItemType type, int32_t subject) break; } - // Check if window is already open - auto window = window_bring_to_front_by_class(WC_SCENERY); - if (window == nullptr) - { - window = window_find_by_class(WC_TOP_TOOLBAR); - if (window != nullptr) - { - window->Invalidate(); - if (!tool_set(window, WC_TOP_TOOLBAR__WIDX_SCENERY, Tool::Arrow)) - { - input_set_flag(INPUT_FLAG_6, true); - context_open_window(WC_SCENERY); - } - } - } - - // Switch to new scenery tab - window = window_find_by_class(WC_SCENERY); - if (window != nullptr) - window_event_mouse_down_call(window, WC_SCENERY__WIDX_SCENERY_TAB_1 + subject); + auto intent = Intent(INTENT_ACTION_NEW_SCENERY); + intent.putExtra(INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX, item.entryIndex); + context_open_intent(&intent); break; } case News::ItemType::Peeps: diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 962479ea52..874867620a 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -82,6 +82,7 @@ enum INTENT_EXTRA_PAGE, INTENT_EXTRA_BANNER_INDEX, INTENT_EXTRA_FORMATTER, + INTENT_EXTRA_SCENERY_GROUP_ENTRY_INDEX, }; enum @@ -114,4 +115,5 @@ enum INTENT_ACTION_TRACK_DESIGN_REMOVE_PROVISIONAL, INTENT_ACTION_TRACK_DESIGN_RESTORE_PROVISIONAL, INTENT_ACTION_SET_MAP_TOOLTIP, + INTENT_ACTION_NEW_SCENERY, };