summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-03-15 15:25:18 +0000
committersmatz <smatz@openttd.org>2009-03-15 15:25:18 +0000
commitaf293142fede91cc31e98c7e05d9ecfef752b077 (patch)
treec041152a492c41b5020c575b6fde72be6dc3a5b8
parent4f8eeca437a57c160364cdb97182ae1566e6c693 (diff)
downloadopenttd-af293142fede91cc31e98c7e05d9ecfef752b077.tar.xz
(svn r15725) -Fix: centering on a vehicle didn't respect its z coordinate
-rw-r--r--src/main_gui.cpp2
-rw-r--r--src/news_gui.cpp4
-rw-r--r--src/smallmap_gui.cpp12
-rw-r--r--src/vehicle_gui.cpp4
-rw-r--r--src/viewport.cpp10
-rw-r--r--src/viewport_func.h4
-rw-r--r--src/waypoint_gui.cpp2
-rw-r--r--src/window.cpp2
8 files changed, 25 insertions, 15 deletions
diff --git a/src/main_gui.cpp b/src/main_gui.cpp
index 99c4ca6f4..f7b2ee3d8 100644
--- a/src/main_gui.cpp
+++ b/src/main_gui.cpp
@@ -176,7 +176,7 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w)
Point pt = GetTileZoomCenterWindow(in, w);
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);
}
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 7de3a9370..46c18eeac 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -267,8 +267,8 @@ struct NewsWindow : Window {
case 0:
if (this->ni->flags & NF_VEHICLE) {
- Vehicle *v = GetVehicle(this->ni->data_a);
- ScrollMainWindowTo(v->x_pos, v->y_pos);
+ const Vehicle *v = GetVehicle(this->ni->data_a);
+ ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
} else if (this->ni->flags & NF_TILE) {
if (_ctrl_pressed) {
ShowExtraViewPortWindow(this->ni->data_a);
diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp
index 0619f4039..1d5c2baca 100644
--- a/src/smallmap_gui.cpp
+++ b/src/smallmap_gui.cpp
@@ -1214,9 +1214,17 @@ void ShowExtraViewPortWindow(TileIndex 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
* that tile (e.g.: pressed twice), move the smallmap to that location,
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 4d5801417..97d4df34e 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1957,7 +1957,7 @@ struct VehicleViewWindow : Window {
if (_ctrl_pressed && mainwindow->viewport->zoom == ZOOM_LVL_NORMAL) {
mainwindow->viewport->follow_vehicle = v->index;
} else {
- ScrollMainWindowTo(v->x_pos, v->y_pos);
+ ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos);
}
} break;
@@ -2037,7 +2037,7 @@ void StopGlobalFollowVehicle(const Vehicle *v)
{
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
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;
}
}
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 01dbe2f6b..60cecb03c 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -137,7 +137,7 @@ TileHighlightData _thd;
static TileInfo *_cur_ti;
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);
p.x -= vp->virtual_width / 2;
@@ -2065,10 +2065,12 @@ void PlaceObject()
/* 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. */
- 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;
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)
{
- 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)
diff --git a/src/viewport_func.h b/src/viewport_func.h
index 8e5a2b1d7..f5c9c9410 100644
--- a/src/viewport_func.h
+++ b/src/viewport_func.h
@@ -53,10 +53,10 @@ Vehicle *CheckMouseOverVehicle();
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 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;
diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp
index 1c4321e2a..21cead21c 100644
--- a/src/waypoint_gui.cpp
+++ b/src/waypoint_gui.cpp
@@ -87,7 +87,7 @@ public:
{
int x = TileX(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)
diff --git a/src/window.cpp b/src/window.cpp
index 35abaf5f3..a1b69e2d7 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1651,7 +1651,7 @@ static bool HandleViewportScroll()
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! */
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;
}