mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
This commit is contained in:
parent
4f8eeca437
commit
af293142fe
@ -176,7 +176,7 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
|
|||||||
|
|
||||||
Point pt = GetTileZoomCenterWindow(in, w);
|
Point pt = GetTileZoomCenterWindow(in, w);
|
||||||
if (pt.x != -1) {
|
if (pt.x != -1) {
|
||||||
ScrollWindowTo(pt.x, pt.y, w, true);
|
ScrollWindowTo(pt.x, pt.y, -1, w, true);
|
||||||
|
|
||||||
DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
|
DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, w);
|
||||||
}
|
}
|
||||||
|
@ -267,8 +267,8 @@ struct NewsWindow : Window {
|
|||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
if (this->ni->flags & NF_VEHICLE) {
|
if (this->ni->flags & NF_VEHICLE) {
|
||||||
Vehicle *v = GetVehicle(this->ni->data_a);
|
const Vehicle *v = GetVehicle(this->ni->data_a);
|
||||||
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
|
||||||
} else if (this->ni->flags & NF_TILE) {
|
} else if (this->ni->flags & NF_TILE) {
|
||||||
if (_ctrl_pressed) {
|
if (_ctrl_pressed) {
|
||||||
ShowExtraViewPortWindow(this->ni->data_a);
|
ShowExtraViewPortWindow(this->ni->data_a);
|
||||||
|
@ -1214,9 +1214,17 @@ void ShowExtraViewPortWindow(TileIndex tile)
|
|||||||
new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
|
new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScrollMainWindowTo(int x, int y, bool instant)
|
/**
|
||||||
|
* Scrolls the main window to given coordinates.
|
||||||
|
* @param x x coordinate
|
||||||
|
* @param y y coordinate
|
||||||
|
* @param z z coordinate; -1 to scroll to terrain height
|
||||||
|
* @param instant scroll instantly (meaningful only when smooth_scrolling is active)
|
||||||
|
* @return did the viewport position change?
|
||||||
|
*/
|
||||||
|
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
|
||||||
{
|
{
|
||||||
bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0), instant);
|
bool res = ScrollWindowTo(x, y, z, FindWindowById(WC_MAIN_WINDOW, 0), instant);
|
||||||
|
|
||||||
/* If a user scrolls to a tile (via what way what so ever) and already is on
|
/* If a user scrolls to a tile (via what way what so ever) and already is on
|
||||||
* that tile (e.g.: pressed twice), move the smallmap to that location,
|
* that tile (e.g.: pressed twice), move the smallmap to that location,
|
||||||
|
@ -1957,7 +1957,7 @@ struct VehicleViewWindow : Window {
|
|||||||
if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) {
|
if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) {
|
||||||
mainwindow->viewport->follow_vehicle = v->index;
|
mainwindow->viewport->follow_vehicle = v->index;
|
||||||
} else {
|
} else {
|
||||||
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@ -2037,7 +2037,7 @@ void StopGlobalFollowVehicle(const Vehicle *v)
|
|||||||
{
|
{
|
||||||
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
if (w != NULL && w->viewport->follow_vehicle == v->index) {
|
if (w != NULL && w->viewport->follow_vehicle == v->index) {
|
||||||
ScrollMainWindowTo(v->x_pos, v->y_pos, true); // lock the main view on the vehicle's last position
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
|
||||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ TileHighlightData _thd;
|
|||||||
static TileInfo *_cur_ti;
|
static TileInfo *_cur_ti;
|
||||||
bool _draw_bounding_boxes = false;
|
bool _draw_bounding_boxes = false;
|
||||||
|
|
||||||
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z)
|
static Point MapXYZToViewport(const ViewPort *vp, int x, int y, int z)
|
||||||
{
|
{
|
||||||
Point p = RemapCoords(x, y, z);
|
Point p = RemapCoords(x, y, z);
|
||||||
p.x -= vp->virtual_width / 2;
|
p.x -= vp->virtual_width / 2;
|
||||||
@ -2065,10 +2065,12 @@ void PlaceObject()
|
|||||||
|
|
||||||
|
|
||||||
/* scrolls the viewport in a window to a given location */
|
/* scrolls the viewport in a window to a given location */
|
||||||
bool ScrollWindowTo(int x , int y, Window *w, bool instant)
|
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
|
||||||
{
|
{
|
||||||
/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
|
/* The slope cannot be acquired outside of the map, so make sure we are always within the map. */
|
||||||
Point pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(Clamp(x, 0, MapSizeX() * TILE_SIZE - 1), Clamp(y, 0, MapSizeY() * TILE_SIZE - 1)));
|
if (z == -1) z = GetSlopeZ(Clamp(x, 0, MapSizeX() * TILE_SIZE - 1), Clamp(y, 0, MapSizeY() * TILE_SIZE - 1));
|
||||||
|
|
||||||
|
Point pt = MapXYZToViewport(w->viewport, x, y, z);
|
||||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||||
|
|
||||||
if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y)
|
if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y)
|
||||||
@ -2086,7 +2088,7 @@ bool ScrollWindowTo(int x , int y, Window *w, bool instant)
|
|||||||
|
|
||||||
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
|
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
|
||||||
{
|
{
|
||||||
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, instant);
|
return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, -1, instant);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRedErrorSquare(TileIndex tile)
|
void SetRedErrorSquare(TileIndex tile)
|
||||||
|
@ -53,10 +53,10 @@ Vehicle *CheckMouseOverVehicle();
|
|||||||
|
|
||||||
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
|
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom);
|
||||||
|
|
||||||
bool ScrollWindowTo(int x, int y, Window *w, bool instant = false);
|
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant = false);
|
||||||
|
|
||||||
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
|
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
|
||||||
bool ScrollMainWindowTo(int x, int y, bool instant = false);
|
bool ScrollMainWindowTo(int x, int y, int z = -1, bool instant = false);
|
||||||
|
|
||||||
extern Point _tile_fract_coords;
|
extern Point _tile_fract_coords;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ public:
|
|||||||
{
|
{
|
||||||
int x = TileX(this->wp->xy) * TILE_SIZE;
|
int x = TileX(this->wp->xy) * TILE_SIZE;
|
||||||
int y = TileY(this->wp->xy) * TILE_SIZE;
|
int y = TileY(this->wp->xy) * TILE_SIZE;
|
||||||
ScrollWindowTo(x, y, this);
|
ScrollWindowTo(x, y, -1, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnQueryTextFinished(char *str)
|
virtual void OnQueryTextFinished(char *str)
|
||||||
|
@ -1651,7 +1651,7 @@ static bool HandleViewportScroll()
|
|||||||
if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) {
|
if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) {
|
||||||
/* If the main window is following a vehicle, then first let go of it! */
|
/* If the main window is following a vehicle, then first let go of it! */
|
||||||
const Vehicle *veh = GetVehicle(w->viewport->follow_vehicle);
|
const Vehicle *veh = GetVehicle(w->viewport->follow_vehicle);
|
||||||
ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); // This also resets follow_vehicle
|
ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user