Fix #11577: Extra viewport opened in wrong location. (#11578)

ExtraViewportWindow calls IninitializeViewport() with focus as 0, which is ambiguous as focus should be either a TileIndex or a VehicleID.

Instead, pass the tile and let InitializeViewport() handle setting all the coordinates.
This commit is contained in:
Peter Nelson 2023-12-13 02:19:16 +00:00 committed by GitHub
parent 0a8bcdd344
commit 6c5aeae01b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 21 deletions

View File

@ -242,11 +242,22 @@ void InitializeWindowViewport(Window *w, int x, int y,
veh = Vehicle::Get(vp->follow_vehicle);
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
} else {
x = TileX(std::get<TileIndex>(focus)) * TILE_SIZE;
y = TileY(std::get<TileIndex>(focus)) * TILE_SIZE;
TileIndex tile = std::get<TileIndex>(focus);
if (tile == INVALID_TILE) {
/* No tile? Use center of main viewport. */
const Window *mw = GetMainWindow();
/* center on same place as main window (zoom is maximum, no adjustment needed) */
pt.x = mw->viewport->scrollpos_x + mw->viewport->virtual_width / 2;
pt.x -= vp->virtual_width / 2;
pt.y = mw->viewport->scrollpos_y + mw->viewport->virtual_height / 2;
pt.y -= vp->virtual_height / 2;
} else {
x = TileX(tile) * TILE_SIZE;
y = TileY(tile) * TILE_SIZE;
pt = MapXYZToViewport(vp, x, y, GetSlopePixelZ(x, y));
}
vp->follow_vehicle = INVALID_VEHICLE;
pt = MapXYZToViewport(vp, x, y, GetSlopePixelZ(x, y));
}
vp->scrollpos_x = pt.x;

View File

@ -57,25 +57,8 @@ public:
this->InitNested(window_number);
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_EV_VIEWPORT);
nvp->InitializeViewport(this, 0, ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
nvp->InitializeViewport(this, tile, ScaleZoomGUI(ZOOM_LVL_VIEWPORT));
if (_settings_client.gui.zoom_min == viewport->zoom) this->DisableWidget(WID_EV_ZOOM_IN);
Point pt;
if (tile == INVALID_TILE) {
/* No tile? Use center of main viewport. */
const Window *w = GetMainWindow();
/* center on same place as main window (zoom is maximum, no adjustment needed) */
pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2;
pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
} else {
pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TilePixelHeight(tile));
}
this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2;
this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2;
this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
}
void SetStringParameters(int widget) const override