2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file road_gui.cpp GUI for building roads. */
12 #include "window_gui.h"
13 #include "station_gui.h"
14 #include "terraform_gui.h"
15 #include "viewport_func.h"
16 #include "command_func.h"
18 #include "station_func.h"
19 #include "window_func.h"
20 #include "vehicle_func.h"
21 #include "sound_func.h"
22 #include "company_func.h"
23 #include "tunnelbridge.h"
24 #include "tunnelbridge_map.h"
25 #include "tilehighlight_func.h"
26 #include "company_base.h"
29 #include "zoom_func.h"
30 #include "engine_base.h"
31 #include "strings_func.h"
32 #include "core/geometry_func.hpp"
33 #include "date_func.h"
35 #include "widgets/road_widget.h"
37 #include "table/strings.h"
39 #include "safeguards.h"
41 static void ShowRVStationPicker(Window
*parent
, RoadStopType rs
);
42 static void ShowRoadDepotPicker(Window
*parent
);
44 static bool _remove_button_clicked
;
45 static bool _one_way_button_clicked
;
48 * Define the values of the RoadFlags
49 * @see CmdBuildLongRoad
53 RF_START_HALFROAD_Y
= 0x01, // The start tile in Y-dir should have only a half road
54 RF_END_HALFROAD_Y
= 0x02, // The end tile in Y-dir should have only a half road
55 RF_DIR_Y
= 0x04, // The direction is Y-dir
56 RF_DIR_X
= RF_NONE
, // Dummy; Dir X is set when RF_DIR_Y is not set
57 RF_START_HALFROAD_X
= 0x08, // The start tile in X-dir should have only a half road
58 RF_END_HALFROAD_X
= 0x10, // The end tile in X-dir should have only a half road
60 DECLARE_ENUM_AS_BIT_SET(RoadFlags
)
62 static RoadFlags _place_road_flag
;
64 static RoadType _cur_roadtype
;
66 static DiagDirection _road_depot_orientation
;
67 static DiagDirection _road_station_picker_orientation
;
69 void CcPlaySound_CONSTRUCTION_OTHER(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
)
71 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER
, tile
);
75 * Callback to start placing a bridge.
76 * @param tile Start tile of the bridge.
78 static void PlaceRoad_Bridge(TileIndex tile
, Window
*w
)
80 if (IsBridgeTile(tile
)) {
81 TileIndex other_tile
= GetOtherTunnelBridgeEnd(tile
);
83 w
->OnPlaceMouseUp(VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
, pt
, other_tile
, tile
);
85 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DDSP_BUILD_BRIDGE
);
90 * Callback executed after a build road tunnel command has been called.
92 * @param result Whether the build succeeded.
93 * @param start_tile Starting tile of the tunnel.
94 * @param p1 bit 0-3 railtype or roadtypes
95 * bit 8-9 transport type
99 void CcBuildRoadTunnel(const CommandCost
&result
, TileIndex start_tile
, uint32 p1
, uint32 p2
, uint32 cmd
)
101 if (result
.Succeeded()) {
102 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER
, start_tile
);
103 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
105 DiagDirection start_direction
= ReverseDiagDir(GetTunnelBridgeDirection(start_tile
));
106 ConnectRoadToStructure(start_tile
, start_direction
);
108 TileIndex end_tile
= GetOtherTunnelBridgeEnd(start_tile
);
109 DiagDirection end_direction
= ReverseDiagDir(GetTunnelBridgeDirection(end_tile
));
110 ConnectRoadToStructure(end_tile
, end_direction
);
112 SetRedErrorSquare(_build_tunnel_endtile
);
117 * If required, connects a new structure to an existing road or tram by building the missing roadbit.
118 * @param tile Tile containing the structure to connect.
119 * @param direction Direction to check.
121 void ConnectRoadToStructure(TileIndex tile
, DiagDirection direction
)
123 tile
+= TileOffsByDiagDir(direction
);
124 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
125 if (IsNormalRoadTile(tile
)) {
126 if (GetRoadBits(tile
, GetRoadTramType(_cur_roadtype
)) != ROAD_NONE
) {
127 DoCommandP(tile
, _cur_roadtype
<< 4 | DiagDirToRoadBits(ReverseDiagDir(direction
)), 0, CMD_BUILD_ROAD
);
132 void CcRoadDepot(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
)
134 if (result
.Failed()) return;
136 DiagDirection dir
= (DiagDirection
)GB(p1
, 0, 2);
137 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER
, tile
);
138 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
139 ConnectRoadToStructure(tile
, dir
);
143 * Command callback for building road stops.
144 * @param result Result of the build road stop command.
145 * @param tile Start tile.
146 * @param p1 bit 0..7: Width of the road stop.
147 * bit 8..15: Length of the road stop.
148 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
149 * bit 1: 0 For normal stops, 1 for drive-through.
150 * bit 2: Allow stations directly adjacent to other stations.
151 * bit 3..4: Entrance direction (#DiagDirection) for normal stops.
152 * bit 3: #Axis of the road for drive-through stops.
153 * bit 5..9: The roadtype.
154 * bit 16..31: Station ID to join (NEW_STATION if build new one).
156 * @see CmdBuildRoadStop
158 void CcRoadStop(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
)
160 if (result
.Failed()) return;
162 DiagDirection dir
= (DiagDirection
)GB(p2
, 3, 2);
163 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER
, tile
);
164 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
165 TileArea
roadstop_area(tile
, GB(p1
, 0, 8), GB(p1
, 8, 8));
166 TILE_AREA_LOOP(cur_tile
, roadstop_area
) {
167 ConnectRoadToStructure(cur_tile
, dir
);
168 /* For a drive-through road stop build connecting road for other entrance. */
169 if (HasBit(p2
, 1)) ConnectRoadToStructure(cur_tile
, ReverseDiagDir(dir
));
174 * Place a new road stop.
175 * @param start_tile First tile of the area.
176 * @param end_tile Last tile of the area.
177 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
178 * bit 2: Allow stations directly adjacent to other stations.
179 * bit 5..10: The roadtypes.
180 * @param cmd Command to use.
183 static void PlaceRoadStop(TileIndex start_tile
, TileIndex end_tile
, uint32 p2
, uint32 cmd
)
185 uint8 ddir
= _road_station_picker_orientation
;
186 SB(p2
, 16, 16, INVALID_STATION
); // no station to join
188 if (ddir
>= DIAGDIR_END
) {
189 SetBit(p2
, 1); // It's a drive-through stop.
190 ddir
-= DIAGDIR_END
; // Adjust picker result to actual direction.
192 p2
|= ddir
<< 3; // Set the DiagDirecion into p2 bits 3 and 4.
194 TileArea
ta(start_tile
, end_tile
);
195 CommandContainer cmdcont
= { ta
.tile
, (uint32
)(ta
.w
| ta
.h
<< 8), p2
, cmd
, CcRoadStop
, "" };
196 ShowSelectStationIfNeeded(cmdcont
, ta
);
200 * Callback for placing a bus station.
201 * @param tile Position to place the station.
203 static void PlaceRoad_BusStation(TileIndex tile
)
205 if (_remove_button_clicked
) {
206 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_REMOVE_BUSSTOP
);
208 if (_road_station_picker_orientation
< DIAGDIR_END
) { // Not a drive-through stop.
209 VpStartPlaceSizing(tile
, (DiagDirToAxis(_road_station_picker_orientation
) == AXIS_X
) ? VPM_X_LIMITED
: VPM_Y_LIMITED
, DDSP_BUILD_BUSSTOP
);
211 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_BUILD_BUSSTOP
);
213 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
218 * Callback for placing a truck station.
219 * @param tile Position to place the station.
221 static void PlaceRoad_TruckStation(TileIndex tile
)
223 if (_remove_button_clicked
) {
224 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_REMOVE_TRUCKSTOP
);
226 if (_road_station_picker_orientation
< DIAGDIR_END
) { // Not a drive-through stop.
227 VpStartPlaceSizing(tile
, (DiagDirToAxis(_road_station_picker_orientation
) == AXIS_X
) ? VPM_X_LIMITED
: VPM_Y_LIMITED
, DDSP_BUILD_TRUCKSTOP
);
229 VpStartPlaceSizing(tile
, VPM_X_AND_Y_LIMITED
, DDSP_BUILD_TRUCKSTOP
);
231 VpSetPlaceSizingLimit(_settings_game
.station
.station_spread
);
235 typedef void OnButtonClick(Window
*w
);
238 * Toggles state of the Remove button of Build road toolbar
239 * @param w window the button belongs to
241 static void ToggleRoadButton_Remove(Window
*w
)
243 w
->ToggleWidgetLoweredState(WID_ROT_REMOVE
);
244 w
->SetWidgetDirty(WID_ROT_REMOVE
);
245 _remove_button_clicked
= w
->IsWidgetLowered(WID_ROT_REMOVE
);
246 SetSelectionRed(_remove_button_clicked
);
250 * Updates the Remove button because of Ctrl state change
251 * @param w window the button belongs to
252 * @return true iff the remove button was changed
254 static bool RoadToolbar_CtrlChanged(Window
*w
)
256 if (w
->IsWidgetDisabled(WID_ROT_REMOVE
)) return false;
258 /* allow ctrl to switch remove mode only for these widgets */
259 for (uint i
= WID_ROT_ROAD_X
; i
<= WID_ROT_AUTOROAD
; i
++) {
260 if (w
->IsWidgetLowered(i
)) {
261 ToggleRoadButton_Remove(w
);
269 /** Road toolbar window handler. */
270 struct BuildRoadToolbarWindow
: Window
{
271 RoadType roadtype
; ///< Road type to build.
272 const RoadTypeInfo
*rti
; ///< Information about current road type
273 int last_started_action
; ///< Last started user action.
275 BuildRoadToolbarWindow(WindowDesc
*desc
, WindowNumber window_number
) : Window(desc
)
277 this->Initialize(_cur_roadtype
);
278 this->InitNested(window_number
);
279 this->SetupRoadToolbar();
280 this->SetWidgetDisabledState(WID_ROT_REMOVE
, true);
282 if (RoadTypeIsRoad(this->roadtype
)) {
283 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, true);
286 this->OnInvalidateData();
287 this->last_started_action
= WIDGET_LIST_END
;
289 if (_settings_client
.gui
.link_terraform_toolbar
) ShowTerraformToolbar(this);
292 ~BuildRoadToolbarWindow()
294 if (_game_mode
== GM_NORMAL
&& (this->IsWidgetLowered(WID_ROT_BUS_STATION
) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION
))) SetViewportCatchmentStation(nullptr, true);
295 if (_settings_client
.gui
.link_terraform_toolbar
) DeleteWindowById(WC_SCEN_LAND_GEN
, 0, false);
299 * Some data on this window has become invalid.
300 * @param data Information about the changed data.
301 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
303 void OnInvalidateData(int data
= 0, bool gui_scope
= true) override
305 if (!gui_scope
) return;
306 RoadTramType rtt
= GetRoadTramType(this->roadtype
);
308 bool can_build
= CanBuildVehicleInfrastructure(VEH_ROAD
, rtt
);
309 this->SetWidgetsDisabledState(!can_build
,
312 WID_ROT_TRUCK_STATION
,
315 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
316 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
317 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
320 if (_game_mode
!= GM_EDITOR
) {
322 /* Show in the tooltip why this button is disabled. */
323 this->GetWidget
<NWidgetCore
>(WID_ROT_DEPOT
)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE
);
324 this->GetWidget
<NWidgetCore
>(WID_ROT_BUS_STATION
)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE
);
325 this->GetWidget
<NWidgetCore
>(WID_ROT_TRUCK_STATION
)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE
);
327 this->GetWidget
<NWidgetCore
>(WID_ROT_DEPOT
)->SetToolTip(rtt
== RTT_ROAD
? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT
: STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT
);
328 this->GetWidget
<NWidgetCore
>(WID_ROT_BUS_STATION
)->SetToolTip(rtt
== RTT_ROAD
? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION
: STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION
);
329 this->GetWidget
<NWidgetCore
>(WID_ROT_TRUCK_STATION
)->SetToolTip(rtt
== RTT_ROAD
? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY
: STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION
);
334 void Initialize(RoadType roadtype
)
336 assert(roadtype
< ROADTYPE_END
);
337 this->roadtype
= roadtype
;
338 this->rti
= GetRoadTypeInfo(this->roadtype
);
342 * Configures the road toolbar for roadtype given
343 * @param roadtype the roadtype to display
345 void SetupRoadToolbar()
347 this->GetWidget
<NWidgetCore
>(WID_ROT_ROAD_X
)->widget_data
= rti
->gui_sprites
.build_x_road
;
348 this->GetWidget
<NWidgetCore
>(WID_ROT_ROAD_Y
)->widget_data
= rti
->gui_sprites
.build_y_road
;
349 this->GetWidget
<NWidgetCore
>(WID_ROT_AUTOROAD
)->widget_data
= rti
->gui_sprites
.auto_road
;
350 if (_game_mode
!= GM_EDITOR
) {
351 this->GetWidget
<NWidgetCore
>(WID_ROT_DEPOT
)->widget_data
= rti
->gui_sprites
.build_depot
;
353 this->GetWidget
<NWidgetCore
>(WID_ROT_CONVERT_ROAD
)->widget_data
= rti
->gui_sprites
.convert_road
;
354 this->GetWidget
<NWidgetCore
>(WID_ROT_BUILD_TUNNEL
)->widget_data
= rti
->gui_sprites
.build_tunnel
;
358 * Switch to another road type.
359 * @param roadtype New road type.
361 void ModifyRoadType(RoadType roadtype
)
363 this->Initialize(roadtype
);
364 this->SetupRoadToolbar();
368 void SetStringParameters(int widget
) const override
370 if (widget
== WID_ROT_CAPTION
) {
371 if (this->rti
->max_speed
> 0) {
372 SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY
);
373 SetDParam(1, this->rti
->strings
.toolbar_caption
);
374 SetDParam(2, this->rti
->max_speed
/ 2);
376 SetDParam(0, this->rti
->strings
.toolbar_caption
);
382 * Update the remove button lowered state of the road toolbar
384 * @param clicked_widget The widget which the client clicked just now
386 void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget
)
388 /* The remove and the one way button state is driven
389 * by the other buttons so they don't act on themselves.
390 * Both are only valid if they are able to apply as options. */
391 switch (clicked_widget
) {
393 if (RoadTypeIsRoad(this->roadtype
)) {
394 this->RaiseWidget(WID_ROT_ONE_WAY
);
395 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
400 case WID_ROT_ONE_WAY
:
401 this->RaiseWidget(WID_ROT_REMOVE
);
402 this->SetWidgetDirty(WID_ROT_REMOVE
);
405 case WID_ROT_BUS_STATION
:
406 case WID_ROT_TRUCK_STATION
:
407 if (RoadTypeIsRoad(this->roadtype
)) this->DisableWidget(WID_ROT_ONE_WAY
);
408 this->SetWidgetDisabledState(WID_ROT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
413 case WID_ROT_AUTOROAD
:
414 this->SetWidgetDisabledState(WID_ROT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
415 if (RoadTypeIsRoad(this->roadtype
)) {
416 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, !this->IsWidgetLowered(clicked_widget
));
421 /* When any other buttons than road/station, raise and
422 * disable the removal button */
423 this->SetWidgetDisabledState(WID_ROT_REMOVE
, true);
424 this->SetWidgetLoweredState(WID_ROT_REMOVE
, false);
426 if (RoadTypeIsRoad(this->roadtype
)) {
427 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, true);
428 this->SetWidgetLoweredState(WID_ROT_ONE_WAY
, false);
435 void OnClick(Point pt
, int widget
, int click_count
) override
437 _remove_button_clicked
= false;
438 _one_way_button_clicked
= false;
441 HandlePlacePushButton(this, WID_ROT_ROAD_X
, this->rti
->cursor
.road_nwse
, HT_RECT
);
442 this->last_started_action
= widget
;
446 HandlePlacePushButton(this, WID_ROT_ROAD_Y
, this->rti
->cursor
.road_swne
, HT_RECT
);
447 this->last_started_action
= widget
;
450 case WID_ROT_AUTOROAD
:
451 HandlePlacePushButton(this, WID_ROT_AUTOROAD
, this->rti
->cursor
.autoroad
, HT_RECT
);
452 this->last_started_action
= widget
;
455 case WID_ROT_DEMOLISH
:
456 HandlePlacePushButton(this, WID_ROT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, HT_RECT
| HT_DIAGONAL
);
457 this->last_started_action
= widget
;
461 if (HandlePlacePushButton(this, WID_ROT_DEPOT
, this->rti
->cursor
.depot
, HT_RECT
)) {
462 ShowRoadDepotPicker(this);
463 this->last_started_action
= widget
;
467 case WID_ROT_BUS_STATION
:
468 if (HandlePlacePushButton(this, WID_ROT_BUS_STATION
, SPR_CURSOR_BUS_STATION
, HT_RECT
)) {
469 ShowRVStationPicker(this, ROADSTOP_BUS
);
470 this->last_started_action
= widget
;
474 case WID_ROT_TRUCK_STATION
:
475 if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION
, SPR_CURSOR_TRUCK_STATION
, HT_RECT
)) {
476 ShowRVStationPicker(this, ROADSTOP_TRUCK
);
477 this->last_started_action
= widget
;
481 case WID_ROT_ONE_WAY
:
482 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY
)) return;
484 this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY
);
485 SetSelectionRed(false);
488 case WID_ROT_BUILD_BRIDGE
:
489 HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, HT_RECT
);
490 this->last_started_action
= widget
;
493 case WID_ROT_BUILD_TUNNEL
:
494 HandlePlacePushButton(this, WID_ROT_BUILD_TUNNEL
, this->rti
->cursor
.tunnel
, HT_SPECIAL
);
495 this->last_started_action
= widget
;
499 if (this->IsWidgetDisabled(WID_ROT_REMOVE
)) return;
501 DeleteWindowById(WC_SELECT_STATION
, 0);
502 ToggleRoadButton_Remove(this);
503 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
506 case WID_ROT_CONVERT_ROAD
:
507 HandlePlacePushButton(this, WID_ROT_CONVERT_ROAD
, this->rti
->cursor
.convert_road
, HT_RECT
);
508 this->last_started_action
= widget
;
511 default: NOT_REACHED();
513 this->UpdateOptionWidgetStatus((RoadToolbarWidgets
)widget
);
514 if (_ctrl_pressed
) RoadToolbar_CtrlChanged(this);
517 EventState
OnHotkey(int hotkey
) override
519 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
520 return Window::OnHotkey(hotkey
);
523 void OnPlaceObject(Point pt
, TileIndex tile
) override
525 _remove_button_clicked
= this->IsWidgetLowered(WID_ROT_REMOVE
);
526 _one_way_button_clicked
= RoadTypeIsRoad(this->roadtype
) ? this->IsWidgetLowered(WID_ROT_ONE_WAY
) : false;
527 switch (this->last_started_action
) {
529 _place_road_flag
= RF_DIR_X
;
530 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
531 VpStartPlaceSizing(tile
, VPM_FIX_Y
, DDSP_PLACE_ROAD_X_DIR
);
535 _place_road_flag
= RF_DIR_Y
;
536 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
537 VpStartPlaceSizing(tile
, VPM_FIX_X
, DDSP_PLACE_ROAD_Y_DIR
);
540 case WID_ROT_AUTOROAD
:
541 _place_road_flag
= RF_NONE
;
542 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
543 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
544 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DDSP_PLACE_AUTOROAD
);
547 case WID_ROT_DEMOLISH
:
548 PlaceProc_DemolishArea(tile
);
552 DoCommandP(tile
, _cur_roadtype
<< 2 | _road_depot_orientation
, 0,
553 CMD_BUILD_ROAD_DEPOT
| CMD_MSG(this->rti
->strings
.err_depot
), CcRoadDepot
);
556 case WID_ROT_BUS_STATION
:
557 PlaceRoad_BusStation(tile
);
560 case WID_ROT_TRUCK_STATION
:
561 PlaceRoad_TruckStation(tile
);
564 case WID_ROT_BUILD_BRIDGE
:
565 PlaceRoad_Bridge(tile
, this);
568 case WID_ROT_BUILD_TUNNEL
:
569 DoCommandP(tile
, _cur_roadtype
| (TRANSPORT_ROAD
<< 8), 0,
570 CMD_BUILD_TUNNEL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE
), CcBuildRoadTunnel
);
573 case WID_ROT_CONVERT_ROAD
:
574 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_CONVERT_ROAD
);
577 default: NOT_REACHED();
581 void OnPlaceObjectAbort() override
583 if (_game_mode
!= GM_EDITOR
&& (this->IsWidgetLowered(WID_ROT_BUS_STATION
) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION
))) SetViewportCatchmentStation(nullptr, true);
585 this->RaiseButtons();
586 this->SetWidgetDisabledState(WID_ROT_REMOVE
, true);
587 this->SetWidgetDirty(WID_ROT_REMOVE
);
589 if (RoadTypeIsRoad(this->roadtype
)) {
590 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, true);
591 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
594 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
595 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
596 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
597 DeleteWindowById(WC_SELECT_STATION
, 0);
598 DeleteWindowByClass(WC_BUILD_BRIDGE
);
601 void OnPlaceDrag(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
) override
603 /* Here we update the end tile flags
604 * of the road placement actions.
605 * At first we reset the end halfroad
606 * bits and if needed we set them again. */
607 switch (select_proc
) {
608 case DDSP_PLACE_ROAD_X_DIR
:
609 _place_road_flag
&= ~RF_END_HALFROAD_X
;
610 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
613 case DDSP_PLACE_ROAD_Y_DIR
:
614 _place_road_flag
&= ~RF_END_HALFROAD_Y
;
615 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
618 case DDSP_PLACE_AUTOROAD
:
619 _place_road_flag
&= ~(RF_END_HALFROAD_Y
| RF_END_HALFROAD_X
);
620 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
621 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
623 /* For autoroad we need to update the
624 * direction of the road */
625 if (_thd
.size
.x
> _thd
.size
.y
|| (_thd
.size
.x
== _thd
.size
.y
&&
626 ( (_tile_fract_coords
.x
< _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) < 16) ||
627 (_tile_fract_coords
.x
> _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) > 16) ))) {
629 _place_road_flag
&= ~RF_DIR_Y
;
632 _place_road_flag
|= RF_DIR_Y
;
641 VpSelectTilesWithMethod(pt
.x
, pt
.y
, select_method
);
644 void OnPlaceMouseUp(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
, TileIndex start_tile
, TileIndex end_tile
) override
647 switch (select_proc
) {
648 default: NOT_REACHED();
649 case DDSP_BUILD_BRIDGE
:
650 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
651 ShowBuildBridgeWindow(start_tile
, end_tile
, TRANSPORT_ROAD
, _cur_roadtype
);
654 case DDSP_DEMOLISH_AREA
:
655 GUIPlaceProcDragXY(select_proc
, start_tile
, end_tile
);
658 case DDSP_PLACE_ROAD_X_DIR
:
659 case DDSP_PLACE_ROAD_Y_DIR
:
660 case DDSP_PLACE_AUTOROAD
:
662 * Use the first three bits (0x07) if dir == Y
663 * else use the last 2 bits (X dir has
664 * not the 3rd bit set) */
666 /* Even if _cur_roadtype_id is a uint8 we only use 5 bits so
667 * we could ignore the last 3 bits and reuse them for other
669 _place_road_flag
= (RoadFlags
)((_place_road_flag
& RF_DIR_Y
) ? (_place_road_flag
& 0x07) : (_place_road_flag
>> 3));
671 DoCommandP(start_tile
, end_tile
, _place_road_flag
| (_cur_roadtype
<< 3) | (_one_way_button_clicked
<< 10),
672 _remove_button_clicked
?
673 CMD_REMOVE_LONG_ROAD
| CMD_MSG(this->rti
->strings
.err_remove_road
) :
674 CMD_BUILD_LONG_ROAD
| CMD_MSG(this->rti
->strings
.err_build_road
), CcPlaySound_CONSTRUCTION_OTHER
);
677 case DDSP_BUILD_BUSSTOP
:
678 case DDSP_REMOVE_BUSSTOP
:
679 if (this->IsWidgetLowered(WID_ROT_BUS_STATION
)) {
680 if (_remove_button_clicked
) {
681 TileArea
ta(start_tile
, end_tile
);
682 DoCommandP(ta
.tile
, ta
.w
| ta
.h
<< 8, (_ctrl_pressed
<< 1) | ROADSTOP_BUS
, CMD_REMOVE_ROAD_STOP
| CMD_MSG(this->rti
->strings
.err_remove_station
[ROADSTOP_BUS
]), CcPlaySound_CONSTRUCTION_OTHER
);
684 PlaceRoadStop(start_tile
, end_tile
, _cur_roadtype
<< 5 | (_ctrl_pressed
<< 2) | ROADSTOP_BUS
, CMD_BUILD_ROAD_STOP
| CMD_MSG(this->rti
->strings
.err_build_station
[ROADSTOP_BUS
]));
689 case DDSP_BUILD_TRUCKSTOP
:
690 case DDSP_REMOVE_TRUCKSTOP
:
691 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION
)) {
692 if (_remove_button_clicked
) {
693 TileArea
ta(start_tile
, end_tile
);
694 DoCommandP(ta
.tile
, ta
.w
| ta
.h
<< 8, (_ctrl_pressed
<< 1) | ROADSTOP_TRUCK
, CMD_REMOVE_ROAD_STOP
| CMD_MSG(this->rti
->strings
.err_remove_station
[ROADSTOP_TRUCK
]), CcPlaySound_CONSTRUCTION_OTHER
);
696 PlaceRoadStop(start_tile
, end_tile
, _cur_roadtype
<< 5 | (_ctrl_pressed
<< 2) | ROADSTOP_TRUCK
, CMD_BUILD_ROAD_STOP
| CMD_MSG(this->rti
->strings
.err_build_station
[ROADSTOP_TRUCK
]));
701 case DDSP_CONVERT_ROAD
:
702 DoCommandP(end_tile
, start_tile
, _cur_roadtype
, CMD_CONVERT_ROAD
| CMD_MSG(rti
->strings
.err_convert_road
), CcPlaySound_CONSTRUCTION_OTHER
);
708 void OnPlacePresize(Point pt
, TileIndex tile
) override
710 DoCommand(tile
, _cur_roadtype
| (TRANSPORT_ROAD
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
711 VpSetPresizeRange(tile
, _build_tunnel_endtile
== 0 ? tile
: _build_tunnel_endtile
);
714 EventState
OnCTRLStateChange() override
716 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED
;
717 return ES_NOT_HANDLED
;
720 static HotkeyList road_hotkeys
;
721 static HotkeyList tram_hotkeys
;
725 * Handler for global hotkeys of the BuildRoadToolbarWindow.
726 * @param hotkey Hotkey
727 * @param last_build Last build road type
728 * @return ES_HANDLED if hotkey was accepted.
730 static EventState
RoadTramToolbarGlobalHotkeys(int hotkey
, RoadType last_build
, RoadTramType rtt
)
733 switch (_game_mode
) {
735 w
= ShowBuildRoadToolbar(last_build
);
739 if ((GetRoadTypes(true) & ((rtt
== RTT_ROAD
) ? ~_roadtypes_type
: _roadtypes_type
)) == ROADTYPES_NONE
) return ES_NOT_HANDLED
;
740 w
= ShowBuildRoadScenToolbar(last_build
);
747 if (w
== nullptr) return ES_NOT_HANDLED
;
748 return w
->OnHotkey(hotkey
);
751 static EventState
RoadToolbarGlobalHotkeys(int hotkey
)
753 extern RoadType _last_built_roadtype
;
754 return RoadTramToolbarGlobalHotkeys(hotkey
, _last_built_roadtype
, RTT_ROAD
);
757 static EventState
TramToolbarGlobalHotkeys(int hotkey
)
759 extern RoadType _last_built_tramtype
;
760 return RoadTramToolbarGlobalHotkeys(hotkey
, _last_built_tramtype
, RTT_TRAM
);
763 static Hotkey roadtoolbar_hotkeys
[] = {
764 Hotkey('1', "build_x", WID_ROT_ROAD_X
),
765 Hotkey('2', "build_y", WID_ROT_ROAD_Y
),
766 Hotkey('3', "autoroad", WID_ROT_AUTOROAD
),
767 Hotkey('4', "demolish", WID_ROT_DEMOLISH
),
768 Hotkey('5', "depot", WID_ROT_DEPOT
),
769 Hotkey('6', "bus_station", WID_ROT_BUS_STATION
),
770 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION
),
771 Hotkey('8', "oneway", WID_ROT_ONE_WAY
),
772 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE
),
773 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL
),
774 Hotkey('R', "remove", WID_ROT_REMOVE
),
775 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD
),
778 HotkeyList
BuildRoadToolbarWindow::road_hotkeys("roadtoolbar", roadtoolbar_hotkeys
, RoadToolbarGlobalHotkeys
);
780 static Hotkey tramtoolbar_hotkeys
[] = {
781 Hotkey('1', "build_x", WID_ROT_ROAD_X
),
782 Hotkey('2', "build_y", WID_ROT_ROAD_Y
),
783 Hotkey('3', "autoroad", WID_ROT_AUTOROAD
),
784 Hotkey('4', "demolish", WID_ROT_DEMOLISH
),
785 Hotkey('5', "depot", WID_ROT_DEPOT
),
786 Hotkey('6', "bus_station", WID_ROT_BUS_STATION
),
787 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION
),
788 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE
),
789 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL
),
790 Hotkey('R', "remove", WID_ROT_REMOVE
),
791 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD
),
794 HotkeyList
BuildRoadToolbarWindow::tram_hotkeys("tramtoolbar", tramtoolbar_hotkeys
, TramToolbarGlobalHotkeys
);
797 static const NWidgetPart _nested_build_road_widgets
[] = {
798 NWidget(NWID_HORIZONTAL
),
799 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
800 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
801 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
803 NWidget(NWID_HORIZONTAL
),
804 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
805 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
806 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
807 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
808 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
809 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
810 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
811 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
812 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
813 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT
),
814 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
815 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION
),
816 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
817 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY
),
818 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
819 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
820 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
821 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
822 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
823 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
824 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
825 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
826 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
827 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
828 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD
),
832 static WindowDesc
_build_road_desc(
833 WDP_ALIGN_TOOLBAR
, "toolbar_road", 0, 0,
834 WC_BUILD_TOOLBAR
, WC_NONE
,
836 _nested_build_road_widgets
, lengthof(_nested_build_road_widgets
),
837 &BuildRoadToolbarWindow::road_hotkeys
840 static const NWidgetPart _nested_build_tramway_widgets
[] = {
841 NWidget(NWID_HORIZONTAL
),
842 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
843 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
844 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
846 NWidget(NWID_HORIZONTAL
),
847 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
848 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
849 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
850 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
851 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
852 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM
),
853 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
854 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
855 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
856 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT
),
857 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
858 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION
),
859 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
860 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION
),
861 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
862 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
863 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE
),
864 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
865 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL
),
866 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
867 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS
),
868 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
869 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM
),
873 static WindowDesc
_build_tramway_desc(
874 WDP_ALIGN_TOOLBAR
, "toolbar_tramway", 0, 0,
875 WC_BUILD_TOOLBAR
, WC_NONE
,
877 _nested_build_tramway_widgets
, lengthof(_nested_build_tramway_widgets
),
878 &BuildRoadToolbarWindow::tram_hotkeys
882 * Open the build road toolbar window
884 * If the terraform toolbar is linked to the toolbar, that window is also opened.
886 * @return newly opened road toolbar, or nullptr if the toolbar could not be opened.
888 Window
*ShowBuildRoadToolbar(RoadType roadtype
)
890 if (!Company::IsValidID(_local_company
)) return nullptr;
891 if (!ValParamRoadType(roadtype
)) return nullptr;
893 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
894 _cur_roadtype
= roadtype
;
896 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(RoadTypeIsRoad(_cur_roadtype
) ? &_build_road_desc
: &_build_tramway_desc
, TRANSPORT_ROAD
);
899 static const NWidgetPart _nested_build_road_scen_widgets
[] = {
900 NWidget(NWID_HORIZONTAL
),
901 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
902 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
903 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
905 NWidget(NWID_HORIZONTAL
),
906 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
907 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
908 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
909 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
910 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
911 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
912 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
913 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
914 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
915 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
916 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
917 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
918 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
919 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
920 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
921 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
922 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
923 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
924 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD
),
928 static WindowDesc
_build_road_scen_desc(
929 WDP_AUTO
, "toolbar_road_scen", 0, 0,
930 WC_SCEN_BUILD_TOOLBAR
, WC_NONE
,
932 _nested_build_road_scen_widgets
, lengthof(_nested_build_road_scen_widgets
),
933 &BuildRoadToolbarWindow::road_hotkeys
936 static const NWidgetPart _nested_build_tramway_scen_widgets
[] = {
937 NWidget(NWID_HORIZONTAL
),
938 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
939 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
940 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
942 NWidget(NWID_HORIZONTAL
),
943 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
944 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
945 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
946 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
947 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
948 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM
),
949 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
950 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
951 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
952 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
953 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE
),
954 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
955 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL
),
956 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
957 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS
),
958 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
959 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM
),
963 static WindowDesc
_build_tramway_scen_desc(
964 WDP_AUTO
, "toolbar_tram_scen", 0, 0,
965 WC_SCEN_BUILD_TOOLBAR
, WC_NONE
,
967 _nested_build_tramway_scen_widgets
, lengthof(_nested_build_tramway_scen_widgets
),
968 &BuildRoadToolbarWindow::tram_hotkeys
972 * Show the road building toolbar in the scenario editor.
973 * @return The just opened toolbar, or \c nullptr if the toolbar was already open.
975 Window
*ShowBuildRoadScenToolbar(RoadType roadtype
)
977 DeleteWindowById(WC_SCEN_BUILD_TOOLBAR
, TRANSPORT_ROAD
);
978 _cur_roadtype
= roadtype
;
980 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(RoadTypeIsRoad(_cur_roadtype
) ? &_build_road_scen_desc
: &_build_tramway_scen_desc
, TRANSPORT_ROAD
);
983 struct BuildRoadDepotWindow
: public PickerWindowBase
{
984 BuildRoadDepotWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
986 this->CreateNestedTree();
988 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
989 if (RoadTypeIsTram(_cur_roadtype
)) {
990 this->GetWidget
<NWidgetCore
>(WID_BROD_CAPTION
)->widget_data
= STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION
;
991 for (int i
= WID_BROD_DEPOT_NE
; i
<= WID_BROD_DEPOT_NW
; i
++) this->GetWidget
<NWidgetCore
>(i
)->tool_tip
= STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP
;
994 this->FinishInitNested(TRANSPORT_ROAD
);
997 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
999 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
1001 size
->width
= ScaleGUITrad(64) + 2;
1002 size
->height
= ScaleGUITrad(48) + 2;
1005 void DrawWidget(const Rect
&r
, int widget
) const override
1007 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
1009 DrawRoadDepotSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
+ DIAGDIR_NE
), _cur_roadtype
);
1012 void OnClick(Point pt
, int widget
, int click_count
) override
1015 case WID_BROD_DEPOT_NW
:
1016 case WID_BROD_DEPOT_NE
:
1017 case WID_BROD_DEPOT_SW
:
1018 case WID_BROD_DEPOT_SE
:
1019 this->RaiseWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
1020 _road_depot_orientation
= (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
);
1021 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
1022 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1032 static const NWidgetPart _nested_build_road_depot_widgets
[] = {
1033 NWidget(NWID_HORIZONTAL
),
1034 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1035 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROD_CAPTION
), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1037 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1038 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1039 NWidget(NWID_HORIZONTAL_LTR
),
1040 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1041 NWidget(NWID_VERTICAL
),
1042 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1044 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1045 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1048 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1049 NWidget(NWID_VERTICAL
),
1050 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1052 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1053 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1056 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1058 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1062 static WindowDesc
_build_road_depot_desc(
1063 WDP_AUTO
, nullptr, 0, 0,
1064 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1066 _nested_build_road_depot_widgets
, lengthof(_nested_build_road_depot_widgets
)
1069 static void ShowRoadDepotPicker(Window
*parent
)
1071 new BuildRoadDepotWindow(&_build_road_depot_desc
, parent
);
1074 struct BuildRoadStationWindow
: public PickerWindowBase
{
1075 BuildRoadStationWindow(WindowDesc
*desc
, Window
*parent
, RoadStopType rs
) : PickerWindowBase(desc
, parent
)
1077 this->CreateNestedTree();
1079 /* Trams don't have non-drivethrough stations */
1080 if (RoadTypeIsTram(_cur_roadtype
) && _road_station_picker_orientation
< DIAGDIR_END
) {
1081 _road_station_picker_orientation
= DIAGDIR_END
;
1083 const RoadTypeInfo
*rti
= GetRoadTypeInfo(_cur_roadtype
);
1084 this->GetWidget
<NWidgetCore
>(WID_BROS_CAPTION
)->widget_data
= rti
->strings
.picker_title
[rs
];
1086 for (uint i
= RoadTypeIsTram(_cur_roadtype
) ? WID_BROS_STATION_X
: WID_BROS_STATION_NE
; i
< WID_BROS_LT_OFF
; i
++) {
1087 this->GetWidget
<NWidgetCore
>(i
)->tool_tip
= rti
->strings
.picker_tooltip
[rs
];
1090 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1091 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1093 this->FinishInitNested(TRANSPORT_ROAD
);
1095 this->window_class
= (rs
== ROADSTOP_BUS
) ? WC_BUS_STATION
: WC_TRUCK_STATION
;
1098 virtual ~BuildRoadStationWindow()
1100 DeleteWindowById(WC_SELECT_STATION
, 0);
1103 void OnPaint() override
1105 this->DrawWidgets();
1107 int rad
= _settings_game
.station
.modified_catchment
? ((this->window_class
== WC_BUS_STATION
) ? CA_BUS
: CA_TRUCK
) : CA_UNMODIFIED
;
1108 if (_settings_client
.gui
.station_show_coverage
) {
1109 SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1111 SetTileSelectSize(1, 1);
1114 /* 'Accepts' and 'Supplies' texts. */
1115 StationCoverageType sct
= (this->window_class
== WC_BUS_STATION
) ? SCT_PASSENGERS_ONLY
: SCT_NON_PASSENGERS_ONLY
;
1116 int top
= this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->pos_y
+ this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->current_y
+ WD_PAR_VSEP_NORMAL
;
1117 NWidgetBase
*back_nwi
= this->GetWidget
<NWidgetBase
>(WID_BROS_BACKGROUND
);
1118 int right
= back_nwi
->pos_x
+ back_nwi
->current_x
;
1119 int bottom
= back_nwi
->pos_y
+ back_nwi
->current_y
;
1120 top
= DrawStationCoverageAreaText(back_nwi
->pos_x
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, sct
, rad
, false) + WD_PAR_VSEP_NORMAL
;
1121 top
= DrawStationCoverageAreaText(back_nwi
->pos_x
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, sct
, rad
, true) + WD_PAR_VSEP_NORMAL
;
1122 /* Resize background if the window is too small.
1123 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1124 * (This is the case, if making the window bigger moves the mouse into the window.) */
1126 ResizeWindow(this, 0, top
- bottom
, false);
1130 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1132 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1134 size
->width
= ScaleGUITrad(64) + 2;
1135 size
->height
= ScaleGUITrad(48) + 2;
1138 void DrawWidget(const Rect
&r
, int widget
) const override
1140 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1142 StationType st
= (this->window_class
== WC_BUS_STATION
) ? STATION_BUS
: STATION_TRUCK
;
1143 StationPickerDrawSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), st
, INVALID_RAILTYPE
, _cur_roadtype
, widget
- WID_BROS_STATION_NE
);
1146 void OnClick(Point pt
, int widget
, int click_count
) override
1149 case WID_BROS_STATION_NE
:
1150 case WID_BROS_STATION_SE
:
1151 case WID_BROS_STATION_SW
:
1152 case WID_BROS_STATION_NW
:
1153 case WID_BROS_STATION_X
:
1154 case WID_BROS_STATION_Y
:
1155 this->RaiseWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1156 _road_station_picker_orientation
= (DiagDirection
)(widget
- WID_BROS_STATION_NE
);
1157 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1158 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1160 DeleteWindowById(WC_SELECT_STATION
, 0);
1163 case WID_BROS_LT_OFF
:
1164 case WID_BROS_LT_ON
:
1165 this->RaiseWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1166 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BROS_LT_OFF
);
1167 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1168 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1170 SetViewportCatchmentStation(nullptr, true);
1178 void OnRealtimeTick(uint delta_ms
) override
1180 CheckRedrawStationCoverage(this);
1184 /** Widget definition of the build road station window */
1185 static const NWidgetPart _nested_road_station_picker_widgets
[] = {
1186 NWidget(NWID_HORIZONTAL
),
1187 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1188 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1190 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1191 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1192 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1193 NWidget(NWID_SPACER
), SetFill(1, 0),
1194 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1195 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1196 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1197 NWidget(NWID_SPACER
), SetFill(1, 0),
1199 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1200 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1201 NWidget(NWID_SPACER
), SetFill(1, 0),
1202 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1203 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1204 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1205 NWidget(NWID_SPACER
), SetFill(1, 0),
1207 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1208 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1209 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1210 NWidget(NWID_SPACER
), SetFill(1, 0),
1212 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1213 NWidget(NWID_SPACER
), SetFill(1, 0),
1214 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1215 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1216 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1217 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1218 NWidget(NWID_SPACER
), SetFill(1, 0),
1220 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1224 static WindowDesc
_road_station_picker_desc(
1225 WDP_AUTO
, nullptr, 0, 0,
1226 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1228 _nested_road_station_picker_widgets
, lengthof(_nested_road_station_picker_widgets
)
1231 /** Widget definition of the build tram station window */
1232 static const NWidgetPart _nested_tram_station_picker_widgets
[] = {
1233 NWidget(NWID_HORIZONTAL
),
1234 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1235 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1237 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1238 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1239 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1240 NWidget(NWID_SPACER
), SetFill(1, 0),
1241 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1242 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1243 NWidget(NWID_SPACER
), SetFill(1, 0),
1245 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1246 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1247 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1248 NWidget(NWID_SPACER
), SetFill(1, 0),
1250 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1251 NWidget(NWID_SPACER
), SetFill(1, 0),
1252 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1253 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1254 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1255 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1256 NWidget(NWID_SPACER
), SetFill(1, 0),
1258 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1262 static WindowDesc
_tram_station_picker_desc(
1263 WDP_AUTO
, nullptr, 0, 0,
1264 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1266 _nested_tram_station_picker_widgets
, lengthof(_nested_tram_station_picker_widgets
)
1269 static void ShowRVStationPicker(Window
*parent
, RoadStopType rs
)
1271 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype
) ? &_road_station_picker_desc
: &_tram_station_picker_desc
, parent
, rs
);
1274 void InitializeRoadGui()
1276 _road_depot_orientation
= DIAGDIR_NW
;
1277 _road_station_picker_orientation
= DIAGDIR_NW
;
1281 * I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
1283 void InitializeRoadGUI()
1285 BuildRoadToolbarWindow
*w
= dynamic_cast<BuildRoadToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_ROAD
));
1286 if (w
!= nullptr) w
->ModifyRoadType(_cur_roadtype
);
1289 DropDownList
GetRoadTypeDropDownList(RoadTramTypes rtts
, bool for_replacement
, bool all_option
)
1291 RoadTypes used_roadtypes
;
1292 RoadTypes avail_roadtypes
;
1294 const Company
*c
= Company::Get(_local_company
);
1296 /* Find the used roadtypes. */
1297 if (for_replacement
) {
1298 avail_roadtypes
= GetCompanyRoadTypes(c
->index
, false);
1299 used_roadtypes
= GetRoadTypes(false);
1301 avail_roadtypes
= c
->avail_roadtypes
;
1302 used_roadtypes
= GetRoadTypes(true);
1305 /* Filter listed road types */
1306 if (!HasBit(rtts
, RTT_ROAD
)) used_roadtypes
&= _roadtypes_type
;
1307 if (!HasBit(rtts
, RTT_TRAM
)) used_roadtypes
&= ~_roadtypes_type
;
1312 list
.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_ROADTYPE
, INVALID_ROADTYPE
, false));
1315 Dimension d
= { 0, 0 };
1317 /* Get largest icon size, to ensure text is aligned on each menu item. */
1318 if (!for_replacement
) {
1319 FOR_ALL_SORTED_ROADTYPES(rt
) {
1320 if (!HasBit(used_roadtypes
, rt
)) continue;
1321 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1322 d
= maxdim(d
, GetSpriteSize(rti
->gui_sprites
.build_x_road
));
1326 FOR_ALL_SORTED_ROADTYPES(rt
) {
1327 /* If it's not used ever, don't show it to the user. */
1328 if (!HasBit(used_roadtypes
, rt
)) continue;
1330 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1332 DropDownListParamStringItem
*item
;
1333 if (for_replacement
) {
1334 item
= new DropDownListParamStringItem(rti
->strings
.replace_text
, rt
, !HasBit(avail_roadtypes
, rt
));
1336 StringID str
= rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
;
1337 DropDownListIconItem
*iconitem
= new DropDownListIconItem(rti
->gui_sprites
.build_x_road
, PAL_NONE
, str
, rt
, !HasBit(avail_roadtypes
, rt
));
1338 iconitem
->SetDimension(d
);
1341 item
->SetParam(0, rti
->strings
.menu_text
);
1342 item
->SetParam(1, rti
->max_speed
/ 2);
1343 list
.emplace_back(item
);
1346 if (list
.size() == 0) {
1347 /* Empty dropdowns are not allowed */
1348 list
.emplace_back(new DropDownListStringItem(STR_NONE
, INVALID_ROADTYPE
, true));
1354 DropDownList
GetScenRoadTypeDropDownList(RoadTramTypes rtts
)
1356 RoadTypes avail_roadtypes
= GetRoadTypes(false);
1357 avail_roadtypes
= AddDateIntroducedRoadTypes(avail_roadtypes
, _date
);
1358 RoadTypes used_roadtypes
= GetRoadTypes(true);
1360 /* Filter listed road types */
1361 if (!HasBit(rtts
, RTT_ROAD
)) used_roadtypes
&= _roadtypes_type
;
1362 if (!HasBit(rtts
, RTT_TRAM
)) used_roadtypes
&= ~_roadtypes_type
;
1366 /* If it's not used ever, don't show it to the user. */
1367 Dimension d
= { 0, 0 };
1369 FOR_ALL_SORTED_ROADTYPES(rt
) {
1370 if (!HasBit(used_roadtypes
, rt
)) continue;
1371 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1372 d
= maxdim(d
, GetSpriteSize(rti
->gui_sprites
.build_x_road
));
1374 FOR_ALL_SORTED_ROADTYPES(rt
) {
1375 if (!HasBit(used_roadtypes
, rt
)) continue;
1377 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1379 StringID str
= rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
;
1380 DropDownListIconItem
*item
= new DropDownListIconItem(rti
->gui_sprites
.build_x_road
, PAL_NONE
, str
, rt
, !HasBit(avail_roadtypes
, rt
));
1381 item
->SetDimension(d
);
1382 item
->SetParam(0, rti
->strings
.menu_text
);
1383 item
->SetParam(1, rti
->max_speed
/ 2);
1384 list
.emplace_back(item
);
1387 if (list
.size() == 0) {
1388 /* Empty dropdowns are not allowed */
1389 list
.emplace_back(new DropDownListStringItem(STR_NONE
, -1, true));