From 3af2f0e9231f0ab0fbe8d993a9f0534e076a17b8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 24 Sep 2016 22:19:01 +0100 Subject: [PATCH] When building tunnels, open new viewports at the far end of the tunnel. Loosely based on https://www.tt-forums.net/viewtopic.php?f=33&t=72639 --- src/rail_gui.cpp | 2 +- src/road_gui.cpp | 2 +- src/tilehighlight_type.h | 1 + src/viewport_gui.cpp | 14 +++++++++++--- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index c6585dcfc2..39965c4fb7 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -695,7 +695,7 @@ struct BuildRailToolbarWindow : Window { break; case WID_RAT_BUILD_TUNNEL: - HandlePlacePushButton(this, WID_RAT_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, HT_SPECIAL); + HandlePlacePushButton(this, WID_RAT_BUILD_TUNNEL, GetRailTypeInfo(_cur_railtype)->cursor.tunnel, HT_SPECIAL | HT_TUNNEL); this->last_user_action = widget; break; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 379778f7cb..d530b9d21a 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -465,7 +465,7 @@ struct BuildRoadToolbarWindow : Window { break; case WID_ROT_BUILD_TUNNEL: - HandlePlacePushButton(this, WID_ROT_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, HT_SPECIAL); + HandlePlacePushButton(this, WID_ROT_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, HT_SPECIAL | HT_TUNNEL); this->last_started_action = widget; break; diff --git a/src/tilehighlight_type.h b/src/tilehighlight_type.h index ffe2d4beed..09c1edbcf6 100644 --- a/src/tilehighlight_type.h +++ b/src/tilehighlight_type.h @@ -31,6 +31,7 @@ enum HighLightStyle { HT_POLY = 0x400, ///< polyline mode; connect highlighted track with previous one HT_NEW_POLY = 0xC00, ///< start completly new polyline; implies #HT_POLY HT_DRAG_MASK = 0x0F8, ///< Mask for the tile drag-type modes. + HT_TUNNEL = 0x1000,///< tunnel highlight hint /* lower bits (used with HT_LINE and HT_RAIL): * (see ASCII art in table/autorail.h for a visual interpretation) */ diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index b3a3f8b0d5..c74139680c 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -14,6 +14,8 @@ #include "window_gui.h" #include "viewport_func.h" #include "strings_func.h" +#include "tunnelbridge.h" +#include "tilehighlight_func.h" #include "zoom_func.h" #include "window_func.h" #include "gfx_func.h" @@ -150,7 +152,7 @@ public: ZoomInOrOutToCursorWindow(wheel < 0, this); } } - + virtual void OnMouseOver(Point pt, int widget) { if (pt.x != -1) { @@ -197,11 +199,17 @@ void ShowExtraViewPortWindow(TileIndex tile) /** * Show a new Extra Viewport window. - * Center it on the tile under the cursor, if the cursor is inside a viewport. + * When building a tunnel, the tunnel end-tile is used as center for new viewport. + * Otherwise center it on the tile under the cursor, if the cursor is inside a viewport. * If that fails, center it on main viewport center. */ void ShowExtraViewPortWindowForTileUnderCursor() { + if (_build_tunnel_endtile != 0 && _thd.place_mode & HT_TUNNEL) { + ShowExtraViewPortWindow(_build_tunnel_endtile); + return; + } + /* Use tile under mouse as center for new viewport. * Do this before creating the window, it might appear just below the mouse. */ Point pt = GetTileBelowCursor(); @@ -241,4 +249,4 @@ void ShowTooltipForTile(Window *w, const TileIndex tile) default: return; } -} \ No newline at end of file +}