Remove some uncommon variables and break unions (#20440)

This commit is contained in:
Duncan 2023-06-27 06:34:06 +01:00 committed by GitHub
parent 3b7975f4a0
commit d40102aa9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 34 deletions

View File

@ -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;
}

View File

@ -278,7 +278,6 @@ WindowBase* WindowCreate(
w->focus = std::nullopt;
w->page = 0;
w->var_48C = 0;
ColourSchemeUpdate(w);
w->Invalidate();

View File

@ -627,6 +627,7 @@ class RideWindow final : public Window
const RideObjectEntry* _vehicleDropdownRideType = nullptr;
bool _vehicleDropdownExpanded = false;
std::vector<VehicleTypeLabel> _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<StringId>(VehicleColourSchemeNames[vehicleColourSchemeType]);
ft.Add<StringId>(GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.vehicle).singular);
ft.Add<StringId>(GetRideComponentName(ride->GetRideTypeDescriptor().NameConvention.vehicle).capitalised);
ft.Add<uint16_t>(vehicleIndex + 1);
ft.Add<uint16_t>(_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<RideWindow*>(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;

View File

@ -126,6 +126,7 @@ class StaffWindow final : public Window
private:
EntertainerCostume _availableCostumes[static_cast<uint8_t>(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);
}

View File

@ -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();

View File

@ -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

View File

@ -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