From bc1d2252aa2debc9f6da69698ff478f068f03fd2 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 2 Jun 2018 11:55:07 +0100 Subject: [PATCH] Remove window dependency from Ride.cpp --- src/openrct2-ui/WindowManager.cpp | 32 +++++++++++++++++++++++++++++ src/openrct2/ride/Ride.cpp | 34 ++++++++++++------------------- src/openrct2/windows/Intent.h | 2 ++ 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index e9070949f0..ebc58c7c2a 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -307,6 +307,24 @@ public: window_maze_construction_update_pressed_widgets(); break; + case INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS: + { + auto rideIndex = intent.GetUIntExtra(INTENT_EXTRA_RIDE_ID); + auto w = window_find_by_class(WC_RIDE_CONSTRUCTION); + if (w == nullptr || w->number != rideIndex) + { + window_close_construction_windows(); + _currentRideIndex = rideIndex; + w = OpenWindow(WC_RIDE_CONSTRUCTION); + } + else + { + ride_construction_invalidate_current_track(); + _currentRideIndex = rideIndex; + } + break; + } + case INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_PIECES: window_ride_construction_update_enabled_track_pieces(); break; @@ -372,6 +390,20 @@ public: break; } + case INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE: + { + auto rideIndex = intent.GetUIntExtra(INTENT_EXTRA_RIDE_ID); + auto w = window_find_by_number(WC_RIDE, rideIndex); + if (w != nullptr) + { + if (w->page == 4) // WINDOW_RIDE_PAGE_COLOUR + { + w->vehicleIndex = 0; + } + window_invalidate(w); + } + } + case INTENT_ACTION_UPDATE_CLIMATE: gToolbarDirtyFlags |= BTM_TB_DIRTY_FLAG_CLIMATE; window_invalidate_by_class(WC_GUEST_LIST); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index b584d4cc32..5666a04367 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -28,7 +28,6 @@ #include "../Game.h" #include "../Input.h" #include "../interface/Window.h" -#include "../interface/Window_internal.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" #include "../management/Finance.h" @@ -64,6 +63,10 @@ #include "TrackData.h" #include "../core/Math.hpp" #include "../core/Util.hpp" +#include "../ui/UiContext.h" +#include "../ui/WindowManager.h" + +using namespace OpenRCT2; #pragma region Ride classification table @@ -993,19 +996,11 @@ static sint32 ride_check_if_construction_allowed(Ride *ride) static rct_window *ride_create_or_find_construction_window(sint32 rideIndex) { - rct_window *w; - - w = window_find_by_class(WC_RIDE_CONSTRUCTION); - if (w == nullptr || w->number != rideIndex) { - window_close_construction_windows(); - _currentRideIndex = rideIndex; - w = context_open_window(WC_RIDE_CONSTRUCTION); - } else { - ride_construction_invalidate_current_track(); - _currentRideIndex = rideIndex; - } - - return w; + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto intent = Intent(INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS); + intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex); + windowManager->BroadcastIntent(intent); + return window_find_by_class(WC_RIDE_CONSTRUCTION); } /** @@ -7394,13 +7389,10 @@ static money32 ride_set_vehicles(uint8 rideIndex, uint8 setting, uint8 value, ui network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); } - rct_window *w = window_find_by_number(WC_RIDE, rideIndex); - if (w != nullptr) { - if (w->page == 4) { // WINDOW_RIDE_PAGE_COLOUR - w->vehicleIndex = 0; - } - window_invalidate(w); - } + auto windowManager = GetContext()->GetUiContext()->GetWindowManager(); + auto intent = Intent(INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE); + intent.putExtra(INTENT_EXTRA_RIDE_ID, rideIndex); + windowManager->BroadcastIntent(intent); gfx_invalidate_screen(); return 0; diff --git a/src/openrct2/windows/Intent.h b/src/openrct2/windows/Intent.h index 9762bbbfdb..669003256b 100644 --- a/src/openrct2/windows/Intent.h +++ b/src/openrct2/windows/Intent.h @@ -81,6 +81,7 @@ enum INTENT_ACTION_REFRESH_NEW_RIDES, INTENT_ACTION_REFRESH_RIDE_LIST, INTENT_ACTION_UPDATE_MAZE_CONSTRUCTION, + INTENT_ACTION_RIDE_CONSTRUCTION_FOCUS, INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_PIECES, INTENT_ACTION_RIDE_CONSTRUCTION_UPDATE_ACTIVE_ELEMENTS, INTENT_ACTION_INIT_SCENERY, @@ -91,6 +92,7 @@ enum INTENT_ACTION_CLEAR_TILE_INSPECTOR_CLIPBOARD, INTENT_ACTION_REFRESH_STAFF_LIST, INTENT_ACTION_INVALIDATE_VEHICLE_WINDOW, + INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE, INTENT_ACTION_UPDATE_CLIMATE, INTENT_ACTION_UPDATE_GUEST_COUNT, INTENT_ACTION_UPDATE_PARK_RATING,