forked from rosebudai/OpenRCT2-Web
Fix #26222: "Follow this on Main View" follows invisible first car instead of the actual car (#27068)
Add getFirstVisibleCar(), which walks a train from the head to the first car with CarEntry::isVisible(). The main-view follow used the train head directly, and the ride window's own viewport focus skipped exactly one car when rideEntry->TabCar != 0, which names the car drawn on the vehicle tab rather than the first visible one. Both now use the helper.
This commit is contained in:
1 parent
66b81c502b
commit
caad293b2d
2 files changed
+24
-19
No files matched your search
@@ -17,6 +17,7 @@
|
||||
- Fix: [#21576] RCT1 Wooden wild mouse track designs with 2-car trains are not imported correctly.
|
||||
- Fix: [#22298] [Plugin] Crash when changing a large scenery element whose object is not loaded.
|
||||
- Fix: [#24457] Yellow is always rendered as third remap in Ride window.
|
||||
- Fix: [#26222] ‘Follow this on Main View’ follows the invisible first car on ride types that have one, making the view turn too early.
|
||||
- Fix: [#26754] Switching window tabs by touch could crash the game on some Linux builds.
|
||||
- Fix: [#26998] Crash when generating a `Simplex Height Map` with a higher width than height.
|
||||
- Fix: [#27052] Unnamed rides in RCT2 base and Wacky Worlds scenarios have hardcoded English names.
|
||||
|
||||
@@ -764,6 +764,24 @@ namespace OpenRCT2::Ui::Windows
|
||||
return selectedCarIndex;
|
||||
}
|
||||
|
||||
static Vehicle* getFirstVisibleCar(EntityId trainHead)
|
||||
{
|
||||
auto& entities = getGameState().entities;
|
||||
auto* head = entities.getEntity<Vehicle>(trainHead);
|
||||
|
||||
auto* vehicle = head;
|
||||
for (auto remaining = Limits::kMaxCarsPerTrain; vehicle != nullptr && remaining > 0; remaining--)
|
||||
{
|
||||
const auto* carEntry = vehicle->Entry();
|
||||
if (carEntry == nullptr || carEntry->isVisible())
|
||||
return vehicle;
|
||||
|
||||
vehicle = entities.getEntity<Vehicle>(vehicle->next_vehicle_on_train);
|
||||
}
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
public:
|
||||
RideWindow(const Ride& ride)
|
||||
{
|
||||
@@ -1551,23 +1569,10 @@ namespace OpenRCT2::Ui::Windows
|
||||
|
||||
if (viewSelectionIndex >= 0 && viewSelectionIndex < ride->numTrains && ride->flags.has(RideFlag::onTrack))
|
||||
{
|
||||
auto vehId = ride->vehicles[viewSelectionIndex];
|
||||
const auto* rideEntry = ride->getRideEntry();
|
||||
if (rideEntry != nullptr && rideEntry->TabCar != 0)
|
||||
const auto* vehicle = getFirstVisibleCar(ride->vehicles[viewSelectionIndex]);
|
||||
if (vehicle != nullptr)
|
||||
{
|
||||
Vehicle* vehicle = getGameState().entities.getEntity<Vehicle>(vehId);
|
||||
if (vehicle == nullptr)
|
||||
{
|
||||
vehId = EntityId::GetNull();
|
||||
}
|
||||
else if (!vehicle->next_vehicle_on_train.IsNull())
|
||||
{
|
||||
vehId = vehicle->next_vehicle_on_train;
|
||||
}
|
||||
}
|
||||
if (!vehId.IsNull())
|
||||
{
|
||||
newFocus = Focus(vehId);
|
||||
newFocus = Focus(vehicle->id);
|
||||
}
|
||||
}
|
||||
else if (viewSelectionIndex >= ride->numTrains && viewSelectionIndex < (ride->numTrains + ride->numStations))
|
||||
@@ -2035,12 +2040,11 @@ namespace OpenRCT2::Ui::Windows
|
||||
{
|
||||
if (_viewIndex <= ride->numTrains)
|
||||
{
|
||||
Vehicle* vehicle = getGameState().entities.getEntity<Vehicle>(ride->vehicles[_viewIndex - 1]);
|
||||
const auto* vehicle = getFirstVisibleCar(ride->vehicles[_viewIndex - 1]);
|
||||
if (vehicle != nullptr)
|
||||
{
|
||||
auto headVehicleSpriteIndex = vehicle->id;
|
||||
WindowBase* w_main = WindowGetMain();
|
||||
WindowFollowSprite(*w_main, headVehicleSpriteIndex);
|
||||
WindowFollowSprite(*w_main, vehicle->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user