Changeset - r28284:5d7c5780cb9b
[Not reviewed]
master
0 2 0
Peter Nelson - 6 months ago 2023-12-13 02:19:16
peter1138@openttd.org
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.
2 files changed with 16 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/viewport.cpp
Show inline comments
 
@@ -242,11 +242,22 @@ void InitializeWindowViewport(Window *w,
 
		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;
src/viewport_gui.cpp
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)