diff options
author | alberth <alberth@openttd.org> | 2010-10-23 20:39:21 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-10-23 20:39:21 +0000 |
commit | 83094e5e58f5674df04e204ba946315da25fad3c (patch) | |
tree | d67362685f0da1672b03d76ae0e13e1f831ceb48 /src/waypoint_gui.cpp | |
parent | cccbc8f418b578d4ad378e5c0570b7f473391ce8 (diff) | |
download | openttd-83094e5e58f5674df04e204ba946315da25fad3c.tar.xz |
(svn r21020) -Add: Use center of waypoint in waypoint gui, if available.
Diffstat (limited to 'src/waypoint_gui.cpp')
-rw-r--r-- | src/waypoint_gui.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/waypoint_gui.cpp b/src/waypoint_gui.cpp index 71c96b7fb..c6e84d21b 100644 --- a/src/waypoint_gui.cpp +++ b/src/waypoint_gui.cpp @@ -34,10 +34,20 @@ enum WaypointWindowWidgets { WAYPVW_SHOW_VEHICLES, }; +/** GUI for accessing waypoints and buoys. */ struct WaypointWindow : Window { private: - VehicleType vt; - Waypoint *wp; + VehicleType vt; ///< Vehicle type using the waypoint. + Waypoint *wp; ///< Waypoint displayed by the window. + + /** + * Get the center tile of the waypoint. + * @return The center tile if the waypoint exists, otherwise the tile with the waypoint name. + */ + TileIndex GetCenterTile() const + { + return this->wp->IsInUse() ? this->wp->train_station.GetCenterTile() : this->wp->xy; + } public: WaypointWindow(const WindowDesc *desc, WindowNumber window_number) : Window() @@ -57,7 +67,7 @@ public: this->flags4 |= WF_DISABLE_VP_SCROLL; NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WAYPVW_VIEWPORT); - nvp->InitializeViewport(this, this->wp->xy, ZOOM_LVL_MIN); + nvp->InitializeViewport(this, this->GetCenterTile(), ZOOM_LVL_MIN); this->OnInvalidateData(0); } @@ -84,9 +94,9 @@ public: switch (widget) { case WAYPVW_CENTERVIEW: // scroll to location if (_ctrl_pressed) { - ShowExtraViewPortWindow(this->wp->xy); + ShowExtraViewPortWindow(this->GetCenterTile()); } else { - ScrollMainWindowToTile(this->wp->xy); + ScrollMainWindowToTile(this->GetCenterTile()); } break; @@ -108,9 +118,7 @@ public: /* Disable the widget for waypoints with no use */ this->SetWidgetDisabledState(WAYPVW_SHOW_VEHICLES, !this->wp->IsInUse()); - int x = TileX(this->wp->xy) * TILE_SIZE; - int y = TileY(this->wp->xy) * TILE_SIZE; - ScrollWindowTo(x, y, -1, this, true); + ScrollWindowToTile(this->GetCenterTile(), this, true); } virtual void OnResize() |