From d40102aa9ded9d8ef6d5e434d9dcde959ced44dc Mon Sep 17 00:00:00 2001 From: Duncan Date: Tue, 27 Jun 2023 06:34:06 +0100 Subject: [PATCH] Remove some uncommon variables and break unions (#20440) --- src/openrct2-ui/WindowManager.cpp | 10 +---- src/openrct2-ui/interface/Window.cpp | 1 - src/openrct2-ui/windows/Ride.cpp | 51 +++++++++++++++++------- src/openrct2-ui/windows/Staff.cpp | 5 ++- src/openrct2-ui/windows/StaffList.cpp | 1 - src/openrct2-ui/windows/Window.h | 1 + src/openrct2/interface/Window_internal.h | 6 --- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/WindowManager.cpp b/src/openrct2-ui/WindowManager.cpp index abdaa10535..93ac21f428 100644 --- a/src/openrct2-ui/WindowManager.cpp +++ b/src/openrct2-ui/WindowManager.cpp @@ -465,15 +465,7 @@ public: case INTENT_ACTION_RIDE_PAINT_RESET_VEHICLE: { auto rideIndex = intent.GetUIntExtra(INTENT_EXTRA_RIDE_ID); - auto w = WindowFindByNumber(WindowClass::Ride, rideIndex); - if (w != nullptr) - { - if (w->page == 4) // WINDOW_RIDE_PAGE_COLOUR - { - w->vehicleIndex = 0; - } - w->Invalidate(); - } + WindowRidePaintResetVehicle(RideId::FromUnderlying(rideIndex)); break; } diff --git a/src/openrct2-ui/interface/Window.cpp b/src/openrct2-ui/interface/Window.cpp index ba74bddda7..64b8a77057 100644 --- a/src/openrct2-ui/interface/Window.cpp +++ b/src/openrct2-ui/interface/Window.cpp @@ -278,7 +278,6 @@ WindowBase* WindowCreate( w->focus = std::nullopt; w->page = 0; - w->var_48C = 0; ColourSchemeUpdate(w); w->Invalidate(); diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 073ff010fd..4b8e9428b5 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -627,6 +627,7 @@ class RideWindow final : public Window const RideObjectEntry* _vehicleDropdownRideType = nullptr; bool _vehicleDropdownExpanded = false; std::vector _vehicleDropdownData; + int16_t _vehicleIndex; public: RideWindow(const Ride& ride) @@ -636,7 +637,7 @@ public: hold_down_widgets = PageHoldDownWidgets[WINDOW_RIDE_PAGE_MAIN]; page = WINDOW_RIDE_PAGE_MAIN; - vehicleIndex = 0; + _vehicleIndex = 0; frame_no = 0; list_information_type = 0; picked_peep_frame = 0; @@ -1067,6 +1068,11 @@ public: return _viewIndex; } + void ResetVehicleIndex() + { + _vehicleIndex = 0; + } + private: void DrawTabImage(DrawPixelInfo& dpi, int32_t tab, int32_t spriteIndex) { @@ -4195,18 +4201,18 @@ private: { windowPos.x + dropdownWidget->left, windowPos.y + dropdownWidget->top }, dropdownWidget->height() + 1, colours[1], 0, Dropdown::Flag::StayOpen, numItems, widgets[widgetIndex].right - dropdownWidget->left); - Dropdown::SetChecked(vehicleIndex, true); + Dropdown::SetChecked(_vehicleIndex, true); break; case WIDX_VEHICLE_BODY_COLOUR: - vehicleColour = RideGetVehicleColour(*ride, vehicleIndex); + vehicleColour = RideGetVehicleColour(*ride, _vehicleIndex); WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], vehicleColour.Body); break; case WIDX_VEHICLE_TRIM_COLOUR: - vehicleColour = RideGetVehicleColour(*ride, vehicleIndex); + vehicleColour = RideGetVehicleColour(*ride, _vehicleIndex); WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], vehicleColour.Trim); break; case WIDX_VEHICLE_TERNARY_COLOUR: - vehicleColour = RideGetVehicleColour(*ride, vehicleIndex); + vehicleColour = RideGetVehicleColour(*ride, _vehicleIndex); WindowDropdownShowColour(this, &widgets[widgetIndex], colours[1], vehicleColour.Tertiary); break; } @@ -4284,24 +4290,26 @@ private: auto rideSetAppearanceAction = RideSetAppearanceAction( rideId, RideSetAppearanceType::VehicleColourScheme, dropdownIndex, 0); GameActions::Execute(&rideSetAppearanceAction); - vehicleIndex = 0; + _vehicleIndex = 0; } break; case WIDX_VEHICLE_COLOUR_INDEX_DROPDOWN: - vehicleIndex = dropdownIndex; + _vehicleIndex = dropdownIndex; Invalidate(); break; case WIDX_VEHICLE_BODY_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - rideId, RideSetAppearanceType::VehicleColourBody, ColourDropDownIndexToColour(dropdownIndex), vehicleIndex); + rideId, RideSetAppearanceType::VehicleColourBody, ColourDropDownIndexToColour(dropdownIndex), + _vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; case WIDX_VEHICLE_TRIM_COLOUR: { auto rideSetAppearanceAction = RideSetAppearanceAction( - rideId, RideSetAppearanceType::VehicleColourTrim, ColourDropDownIndexToColour(dropdownIndex), vehicleIndex); + rideId, RideSetAppearanceType::VehicleColourTrim, ColourDropDownIndexToColour(dropdownIndex), + _vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; @@ -4309,7 +4317,7 @@ private: { auto rideSetAppearanceAction = RideSetAppearanceAction( rideId, RideSetAppearanceType::VehicleColourTernary, ColourDropDownIndexToColour(dropdownIndex), - vehicleIndex); + _vehicleIndex); GameActions::Execute(&rideSetAppearanceAction); } break; @@ -4482,9 +4490,9 @@ private: { int32_t vehicleColourSchemeType = ride->colour_scheme_type & 3; if (vehicleColourSchemeType == 0) - vehicleIndex = 0; + _vehicleIndex = 0; - vehicleColour = RideGetVehicleColour(*ride, vehicleIndex); + vehicleColour = RideGetVehicleColour(*ride, _vehicleIndex); _colourWidgets[WIDX_VEHICLE_PREVIEW].type = WindowWidgetType::Scroll; _colourWidgets[WIDX_VEHICLE_BODY_COLOUR].type = WindowWidgetType::ColourBtn; @@ -4545,7 +4553,7 @@ private: ft.Add(VehicleColourSchemeNames[vehicleColourSchemeType]); ft.Add(GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.vehicle).singular); ft.Add(GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.vehicle).capitalised); - ft.Add(vehicleIndex + 1); + ft.Add(_vehicleIndex + 1); // Vehicle index if (vehicleColourSchemeType != 0) @@ -4708,7 +4716,7 @@ private: return; auto vehiclePreviewWidget = &_colourWidgets[WIDX_VEHICLE_PREVIEW]; - auto vehicleColour = RideGetVehicleColour(*ride, vehicleIndex); + auto vehicleColour = RideGetVehicleColour(*ride, _vehicleIndex); // Background colour GfxFillRect(dpi, { { dpi.x, dpi.y }, { dpi.x + dpi.width - 1, dpi.y + dpi.height - 1 } }, PALETTE_INDEX_12); @@ -4717,7 +4725,7 @@ private: auto screenCoords = ScreenCoordsXY{ vehiclePreviewWidget->width() / 2, vehiclePreviewWidget->height() - 15 }; // ? - auto trainCarIndex = (ride->colour_scheme_type & 3) == RIDE_COLOUR_SCHEME_MODE_DIFFERENT_PER_CAR ? vehicleIndex + auto trainCarIndex = (ride->colour_scheme_type & 3) == RIDE_COLOUR_SCHEME_MODE_DIFFERENT_PER_CAR ? _vehicleIndex : rideEntry->TabCar; const auto& carEntry = rideEntry->Cars[RideEntryGetVehicleAtPosition( @@ -6801,6 +6809,19 @@ void WindowRideInvalidateVehicle(const Vehicle& vehicle) w->Invalidate(); } +void WindowRidePaintResetVehicle(RideId rideIndex) +{ + auto w = static_cast(WindowFindByNumber(WindowClass::Ride, rideIndex.ToUnderlying())); + if (w != nullptr) + { + if (w->page == 4) // WINDOW_RIDE_PAGE_COLOUR + { + w->ResetVehicleIndex(); + } + w->Invalidate(); + } +} + static void CancelScenerySelection() { gGamePaused &= ~GAME_PAUSED_SAVING_TRACK; diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index a5690e9209..527818df02 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -126,6 +126,7 @@ class StaffWindow final : public Window private: EntertainerCostume _availableCostumes[static_cast(EntertainerCostume::Count)]{}; uint16_t _tabAnimationOffset = 0; + int32_t _pickedPeepOldX = LOCATION_NULL; public: void Initialise(EntityId entityId) @@ -361,7 +362,7 @@ private: { case WIDX_PICKUP: { - picked_peep_old_x = staff->x; + _pickedPeepOldX = staff->x; CoordsXYZ nullLoc{}; nullLoc.SetNull(); PeepPickupAction pickupAction{ PeepPickupType::Pickup, EntityId::FromUnderlying(number), nullLoc, @@ -710,7 +711,7 @@ private: return; PeepPickupAction pickupAction{ - PeepPickupType::Cancel, EntityId::FromUnderlying(number), { picked_peep_old_x, 0, 0 }, NetworkGetCurrentPlayerId() + PeepPickupType::Cancel, EntityId::FromUnderlying(number), { _pickedPeepOldX, 0, 0 }, NetworkGetCurrentPlayerId() }; GameActions::Execute(&pickupAction); } diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 504b53e362..6b04f7dfef 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -545,7 +545,6 @@ private: // If autoposition of staff is disabled, pickup peep and then open the staff window if (staff->State == PeepState::Picked) { - picked_peep_old_x = staff->x; CoordsXYZ nullLoc{}; nullLoc.SetNull(); diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index 0bb21aea4f..a95d805e4f 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -141,6 +141,7 @@ WindowBase* WindowRideMainOpen(const Ride& ride); WindowBase* WindowRideOpenTrack(TileElement* tileElement); WindowBase* WindowRideOpenVehicle(Vehicle* vehicle); void WindowRideInvalidateVehicle(const Vehicle& vehicle); +void WindowRidePaintResetVehicle(RideId rideIndex); void WindowRideMeasurementsDesignCancel(); // rct2: 0x00F635EE diff --git a/src/openrct2/interface/Window_internal.h b/src/openrct2/interface/Window_internal.h index de738f6bab..2d770a7590 100644 --- a/src/openrct2/interface/Window_internal.h +++ b/src/openrct2/interface/Window_internal.h @@ -64,12 +64,6 @@ struct WindowBase int16_t page; TileInspectorPage tileInspectorPage; }; - union - { - int16_t picked_peep_old_x; // staff window: peep x gets set to 0x8000 on pickup, this is the old value - int16_t vehicleIndex; // Ride window: selected car when setting vehicle colours - int16_t var_48C; - }; uint16_t frame_no{}; // updated every tic for motion in windows sprites uint16_t list_information_type{}; // 0 for none int16_t picked_peep_frame; // Animation frame of picked peep in staff window and guest window