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_SPLAT_OTHER(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
)
71 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_SPLAT_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_SPLAT_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_SPLAT_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_SPLAT_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;
307 if (_game_mode
!= GM_EDITOR
&& !CanBuildVehicleInfrastructure(VEH_ROAD
, GetRoadTramType(this->roadtype
))) delete this;
308 bool can_build
= _game_mode
!= GM_EDITOR
;
309 this->SetWidgetsDisabledState(!can_build
,
312 WID_ROT_TRUCK_STATION
,
315 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
316 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
317 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
321 void Initialize(RoadType roadtype
)
323 assert(roadtype
< ROADTYPE_END
);
324 this->roadtype
= roadtype
;
325 this->rti
= GetRoadTypeInfo(this->roadtype
);
329 * Configures the road toolbar for roadtype given
330 * @param roadtype the roadtype to display
332 void SetupRoadToolbar()
334 this->GetWidget
<NWidgetCore
>(WID_ROT_ROAD_X
)->widget_data
= rti
->gui_sprites
.build_x_road
;
335 this->GetWidget
<NWidgetCore
>(WID_ROT_ROAD_Y
)->widget_data
= rti
->gui_sprites
.build_y_road
;
336 this->GetWidget
<NWidgetCore
>(WID_ROT_AUTOROAD
)->widget_data
= rti
->gui_sprites
.auto_road
;
337 if (_game_mode
!= GM_EDITOR
) {
338 this->GetWidget
<NWidgetCore
>(WID_ROT_DEPOT
)->widget_data
= rti
->gui_sprites
.build_depot
;
340 this->GetWidget
<NWidgetCore
>(WID_ROT_CONVERT_ROAD
)->widget_data
= rti
->gui_sprites
.convert_road
;
341 this->GetWidget
<NWidgetCore
>(WID_ROT_BUILD_TUNNEL
)->widget_data
= rti
->gui_sprites
.build_tunnel
;
345 * Switch to another road type.
346 * @param roadtype New road type.
348 void ModifyRoadType(RoadType roadtype
)
350 this->Initialize(roadtype
);
351 this->SetupRoadToolbar();
355 void SetStringParameters(int widget
) const override
357 if (widget
== WID_ROT_CAPTION
) {
358 if (this->rti
->max_speed
> 0) {
359 SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY
);
360 SetDParam(1, this->rti
->strings
.toolbar_caption
);
361 SetDParam(2, this->rti
->max_speed
/ 2);
363 SetDParam(0, this->rti
->strings
.toolbar_caption
);
369 * Update the remove button lowered state of the road toolbar
371 * @param clicked_widget The widget which the client clicked just now
373 void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget
)
375 /* The remove and the one way button state is driven
376 * by the other buttons so they don't act on themselves.
377 * Both are only valid if they are able to apply as options. */
378 switch (clicked_widget
) {
380 if (RoadTypeIsRoad(this->roadtype
)) {
381 this->RaiseWidget(WID_ROT_ONE_WAY
);
382 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
387 case WID_ROT_ONE_WAY
:
388 this->RaiseWidget(WID_ROT_REMOVE
);
389 this->SetWidgetDirty(WID_ROT_REMOVE
);
392 case WID_ROT_BUS_STATION
:
393 case WID_ROT_TRUCK_STATION
:
394 if (RoadTypeIsRoad(this->roadtype
)) this->DisableWidget(WID_ROT_ONE_WAY
);
395 this->SetWidgetDisabledState(WID_ROT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
400 case WID_ROT_AUTOROAD
:
401 this->SetWidgetDisabledState(WID_ROT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
402 if (RoadTypeIsRoad(this->roadtype
)) {
403 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, !this->IsWidgetLowered(clicked_widget
));
408 /* When any other buttons than road/station, raise and
409 * disable the removal button */
410 this->SetWidgetDisabledState(WID_ROT_REMOVE
, true);
411 this->SetWidgetLoweredState(WID_ROT_REMOVE
, false);
413 if (RoadTypeIsRoad(this->roadtype
)) {
414 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, true);
415 this->SetWidgetLoweredState(WID_ROT_ONE_WAY
, false);
422 void OnClick(Point pt
, int widget
, int click_count
) override
424 _remove_button_clicked
= false;
425 _one_way_button_clicked
= false;
428 HandlePlacePushButton(this, WID_ROT_ROAD_X
, this->rti
->cursor
.road_nwse
, HT_RECT
);
429 this->last_started_action
= widget
;
433 HandlePlacePushButton(this, WID_ROT_ROAD_Y
, this->rti
->cursor
.road_swne
, HT_RECT
);
434 this->last_started_action
= widget
;
437 case WID_ROT_AUTOROAD
:
438 HandlePlacePushButton(this, WID_ROT_AUTOROAD
, this->rti
->cursor
.autoroad
, HT_RECT
);
439 this->last_started_action
= widget
;
442 case WID_ROT_DEMOLISH
:
443 HandlePlacePushButton(this, WID_ROT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, HT_RECT
| HT_DIAGONAL
);
444 this->last_started_action
= widget
;
448 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
, GetRoadTramType(this->roadtype
))) return;
449 if (HandlePlacePushButton(this, WID_ROT_DEPOT
, this->rti
->cursor
.depot
, HT_RECT
)) {
450 ShowRoadDepotPicker(this);
451 this->last_started_action
= widget
;
455 case WID_ROT_BUS_STATION
:
456 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
, GetRoadTramType(this->roadtype
))) return;
457 if (HandlePlacePushButton(this, WID_ROT_BUS_STATION
, SPR_CURSOR_BUS_STATION
, HT_RECT
)) {
458 ShowRVStationPicker(this, ROADSTOP_BUS
);
459 this->last_started_action
= widget
;
463 case WID_ROT_TRUCK_STATION
:
464 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
, GetRoadTramType(this->roadtype
))) return;
465 if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION
, SPR_CURSOR_TRUCK_STATION
, HT_RECT
)) {
466 ShowRVStationPicker(this, ROADSTOP_TRUCK
);
467 this->last_started_action
= widget
;
471 case WID_ROT_ONE_WAY
:
472 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY
)) return;
474 this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY
);
475 SetSelectionRed(false);
478 case WID_ROT_BUILD_BRIDGE
:
479 HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, HT_RECT
);
480 this->last_started_action
= widget
;
483 case WID_ROT_BUILD_TUNNEL
:
484 HandlePlacePushButton(this, WID_ROT_BUILD_TUNNEL
, this->rti
->cursor
.tunnel
, HT_SPECIAL
);
485 this->last_started_action
= widget
;
489 if (this->IsWidgetDisabled(WID_ROT_REMOVE
)) return;
491 DeleteWindowById(WC_SELECT_STATION
, 0);
492 ToggleRoadButton_Remove(this);
493 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
496 case WID_ROT_CONVERT_ROAD
:
497 HandlePlacePushButton(this, WID_ROT_CONVERT_ROAD
, this->rti
->cursor
.convert_road
, HT_RECT
);
498 this->last_started_action
= widget
;
501 default: NOT_REACHED();
503 this->UpdateOptionWidgetStatus((RoadToolbarWidgets
)widget
);
504 if (_ctrl_pressed
) RoadToolbar_CtrlChanged(this);
507 EventState
OnHotkey(int hotkey
) override
509 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
510 return Window::OnHotkey(hotkey
);
513 void OnPlaceObject(Point pt
, TileIndex tile
) override
515 _remove_button_clicked
= this->IsWidgetLowered(WID_ROT_REMOVE
);
516 _one_way_button_clicked
= RoadTypeIsRoad(this->roadtype
) ? this->IsWidgetLowered(WID_ROT_ONE_WAY
) : false;
517 switch (this->last_started_action
) {
519 _place_road_flag
= RF_DIR_X
;
520 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
521 VpStartPlaceSizing(tile
, VPM_FIX_Y
, DDSP_PLACE_ROAD_X_DIR
);
525 _place_road_flag
= RF_DIR_Y
;
526 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
527 VpStartPlaceSizing(tile
, VPM_FIX_X
, DDSP_PLACE_ROAD_Y_DIR
);
530 case WID_ROT_AUTOROAD
:
531 _place_road_flag
= RF_NONE
;
532 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
533 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
534 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DDSP_PLACE_AUTOROAD
);
537 case WID_ROT_DEMOLISH
:
538 PlaceProc_DemolishArea(tile
);
542 DoCommandP(tile
, _cur_roadtype
<< 2 | _road_depot_orientation
, 0,
543 CMD_BUILD_ROAD_DEPOT
| CMD_MSG(this->rti
->strings
.err_depot
), CcRoadDepot
);
546 case WID_ROT_BUS_STATION
:
547 PlaceRoad_BusStation(tile
);
550 case WID_ROT_TRUCK_STATION
:
551 PlaceRoad_TruckStation(tile
);
554 case WID_ROT_BUILD_BRIDGE
:
555 PlaceRoad_Bridge(tile
, this);
558 case WID_ROT_BUILD_TUNNEL
:
559 DoCommandP(tile
, _cur_roadtype
| (TRANSPORT_ROAD
<< 8), 0,
560 CMD_BUILD_TUNNEL
| CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE
), CcBuildRoadTunnel
);
563 case WID_ROT_CONVERT_ROAD
:
564 VpStartPlaceSizing(tile
, VPM_X_AND_Y
, DDSP_CONVERT_ROAD
);
567 default: NOT_REACHED();
571 void OnPlaceObjectAbort() override
573 if (_game_mode
!= GM_EDITOR
&& (this->IsWidgetLowered(WID_ROT_BUS_STATION
) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION
))) SetViewportCatchmentStation(nullptr, true);
575 this->RaiseButtons();
576 this->SetWidgetDisabledState(WID_ROT_REMOVE
, true);
577 this->SetWidgetDirty(WID_ROT_REMOVE
);
579 if (RoadTypeIsRoad(this->roadtype
)) {
580 this->SetWidgetDisabledState(WID_ROT_ONE_WAY
, true);
581 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
584 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
585 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
586 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
587 DeleteWindowById(WC_SELECT_STATION
, 0);
588 DeleteWindowByClass(WC_BUILD_BRIDGE
);
591 void OnPlaceDrag(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
) override
593 /* Here we update the end tile flags
594 * of the road placement actions.
595 * At first we reset the end halfroad
596 * bits and if needed we set them again. */
597 switch (select_proc
) {
598 case DDSP_PLACE_ROAD_X_DIR
:
599 _place_road_flag
&= ~RF_END_HALFROAD_X
;
600 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
603 case DDSP_PLACE_ROAD_Y_DIR
:
604 _place_road_flag
&= ~RF_END_HALFROAD_Y
;
605 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
608 case DDSP_PLACE_AUTOROAD
:
609 _place_road_flag
&= ~(RF_END_HALFROAD_Y
| RF_END_HALFROAD_X
);
610 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
611 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
613 /* For autoroad we need to update the
614 * direction of the road */
615 if (_thd
.size
.x
> _thd
.size
.y
|| (_thd
.size
.x
== _thd
.size
.y
&&
616 ( (_tile_fract_coords
.x
< _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) < 16) ||
617 (_tile_fract_coords
.x
> _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) > 16) ))) {
619 _place_road_flag
&= ~RF_DIR_Y
;
622 _place_road_flag
|= RF_DIR_Y
;
631 VpSelectTilesWithMethod(pt
.x
, pt
.y
, select_method
);
634 void OnPlaceMouseUp(ViewportPlaceMethod select_method
, ViewportDragDropSelectionProcess select_proc
, Point pt
, TileIndex start_tile
, TileIndex end_tile
) override
637 switch (select_proc
) {
638 default: NOT_REACHED();
639 case DDSP_BUILD_BRIDGE
:
640 if (!_settings_client
.gui
.persistent_buildingtools
) ResetObjectToPlace();
641 ShowBuildBridgeWindow(start_tile
, end_tile
, TRANSPORT_ROAD
, _cur_roadtype
);
644 case DDSP_DEMOLISH_AREA
:
645 GUIPlaceProcDragXY(select_proc
, start_tile
, end_tile
);
648 case DDSP_PLACE_ROAD_X_DIR
:
649 case DDSP_PLACE_ROAD_Y_DIR
:
650 case DDSP_PLACE_AUTOROAD
:
652 * Use the first three bits (0x07) if dir == Y
653 * else use the last 2 bits (X dir has
654 * not the 3rd bit set) */
656 /* Even if _cur_roadtype_id is a uint8 we only use 5 bits so
657 * we could ignore the last 3 bits and reuse them for other
659 _place_road_flag
= (RoadFlags
)((_place_road_flag
& RF_DIR_Y
) ? (_place_road_flag
& 0x07) : (_place_road_flag
>> 3));
661 DoCommandP(start_tile
, end_tile
, _place_road_flag
| (_cur_roadtype
<< 3) | (_one_way_button_clicked
<< 10),
662 _remove_button_clicked
?
663 CMD_REMOVE_LONG_ROAD
| CMD_MSG(this->rti
->strings
.err_remove_road
) :
664 CMD_BUILD_LONG_ROAD
| CMD_MSG(this->rti
->strings
.err_build_road
), CcPlaySound_SPLAT_OTHER
);
667 case DDSP_BUILD_BUSSTOP
:
668 case DDSP_REMOVE_BUSSTOP
:
669 if (this->IsWidgetLowered(WID_ROT_BUS_STATION
)) {
670 if (_remove_button_clicked
) {
671 TileArea
ta(start_tile
, end_tile
);
672 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_SPLAT_OTHER
);
674 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
]));
679 case DDSP_BUILD_TRUCKSTOP
:
680 case DDSP_REMOVE_TRUCKSTOP
:
681 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION
)) {
682 if (_remove_button_clicked
) {
683 TileArea
ta(start_tile
, end_tile
);
684 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_SPLAT_OTHER
);
686 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
]));
691 case DDSP_CONVERT_ROAD
:
692 DoCommandP(end_tile
, start_tile
, _cur_roadtype
, CMD_CONVERT_ROAD
| CMD_MSG(rti
->strings
.err_convert_road
), CcPlaySound_SPLAT_OTHER
);
698 void OnPlacePresize(Point pt
, TileIndex tile
) override
700 DoCommand(tile
, _cur_roadtype
| (TRANSPORT_ROAD
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
701 VpSetPresizeRange(tile
, _build_tunnel_endtile
== 0 ? tile
: _build_tunnel_endtile
);
704 EventState
OnCTRLStateChange() override
706 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED
;
707 return ES_NOT_HANDLED
;
710 static HotkeyList road_hotkeys
;
711 static HotkeyList tram_hotkeys
;
715 * Handler for global hotkeys of the BuildRoadToolbarWindow.
716 * @param hotkey Hotkey
717 * @param last_build Last build road type
718 * @return ES_HANDLED if hotkey was accepted.
720 static EventState
RoadTramToolbarGlobalHotkeys(int hotkey
, RoadType last_build
)
722 Window
*w
= (_game_mode
== GM_NORMAL
) ? ShowBuildRoadToolbar(last_build
) : ShowBuildRoadScenToolbar(last_build
);
723 if (w
== nullptr) return ES_NOT_HANDLED
;
724 return w
->OnHotkey(hotkey
);
727 static EventState
RoadToolbarGlobalHotkeys(int hotkey
)
729 if (_game_mode
== GM_NORMAL
&& !CanBuildVehicleInfrastructure(VEH_ROAD
, RTT_ROAD
)) return ES_NOT_HANDLED
;
731 extern RoadType _last_built_roadtype
;
732 return RoadTramToolbarGlobalHotkeys(hotkey
, _last_built_roadtype
);
735 static EventState
TramToolbarGlobalHotkeys(int hotkey
)
737 if (_game_mode
!= GM_NORMAL
|| !CanBuildVehicleInfrastructure(VEH_ROAD
, RTT_TRAM
)) return ES_NOT_HANDLED
;
738 extern RoadType _last_built_tramtype
;
739 return RoadTramToolbarGlobalHotkeys(hotkey
, _last_built_tramtype
);
742 static Hotkey roadtoolbar_hotkeys
[] = {
743 Hotkey('1', "build_x", WID_ROT_ROAD_X
),
744 Hotkey('2', "build_y", WID_ROT_ROAD_Y
),
745 Hotkey('3', "autoroad", WID_ROT_AUTOROAD
),
746 Hotkey('4', "demolish", WID_ROT_DEMOLISH
),
747 Hotkey('5', "depot", WID_ROT_DEPOT
),
748 Hotkey('6', "bus_station", WID_ROT_BUS_STATION
),
749 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION
),
750 Hotkey('8', "oneway", WID_ROT_ONE_WAY
),
751 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE
),
752 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL
),
753 Hotkey('R', "remove", WID_ROT_REMOVE
),
754 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD
),
757 HotkeyList
BuildRoadToolbarWindow::road_hotkeys("roadtoolbar", roadtoolbar_hotkeys
, RoadToolbarGlobalHotkeys
);
759 static Hotkey tramtoolbar_hotkeys
[] = {
760 Hotkey('1', "build_x", WID_ROT_ROAD_X
),
761 Hotkey('2', "build_y", WID_ROT_ROAD_Y
),
762 Hotkey('3', "autoroad", WID_ROT_AUTOROAD
),
763 Hotkey('4', "demolish", WID_ROT_DEMOLISH
),
764 Hotkey('5', "depot", WID_ROT_DEPOT
),
765 Hotkey('6', "bus_station", WID_ROT_BUS_STATION
),
766 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION
),
767 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE
),
768 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL
),
769 Hotkey('R', "remove", WID_ROT_REMOVE
),
770 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD
),
773 HotkeyList
BuildRoadToolbarWindow::tram_hotkeys("tramtoolbar", tramtoolbar_hotkeys
, TramToolbarGlobalHotkeys
);
776 static const NWidgetPart _nested_build_road_widgets
[] = {
777 NWidget(NWID_HORIZONTAL
),
778 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
779 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
780 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
782 NWidget(NWID_HORIZONTAL
),
783 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
784 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
785 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
786 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
787 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
788 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
789 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
790 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
791 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
792 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT
),
793 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
794 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION
),
795 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
796 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY
),
797 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
798 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
799 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
800 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
801 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
802 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
803 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
804 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
805 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
806 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
807 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD
),
811 static WindowDesc
_build_road_desc(
812 WDP_ALIGN_TOOLBAR
, "toolbar_road", 0, 0,
813 WC_BUILD_TOOLBAR
, WC_NONE
,
815 _nested_build_road_widgets
, lengthof(_nested_build_road_widgets
),
816 &BuildRoadToolbarWindow::road_hotkeys
819 static const NWidgetPart _nested_build_tramway_widgets
[] = {
820 NWidget(NWID_HORIZONTAL
),
821 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
822 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
823 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
825 NWidget(NWID_HORIZONTAL
),
826 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
827 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
828 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
829 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
830 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
831 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM
),
832 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
833 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
834 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
835 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT
),
836 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
837 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION
),
838 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
839 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION
),
840 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
841 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
842 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE
),
843 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
844 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL
),
845 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
846 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS
),
847 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
848 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM
),
852 static WindowDesc
_build_tramway_desc(
853 WDP_ALIGN_TOOLBAR
, "toolbar_tramway", 0, 0,
854 WC_BUILD_TOOLBAR
, WC_NONE
,
856 _nested_build_tramway_widgets
, lengthof(_nested_build_tramway_widgets
),
857 &BuildRoadToolbarWindow::tram_hotkeys
861 * Open the build road toolbar window
863 * If the terraform toolbar is linked to the toolbar, that window is also opened.
865 * @return newly opened road toolbar, or nullptr if the toolbar could not be opened.
867 Window
*ShowBuildRoadToolbar(RoadType roadtype
)
869 if (!Company::IsValidID(_local_company
)) return nullptr;
870 if (!ValParamRoadType(roadtype
)) return nullptr;
872 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
873 _cur_roadtype
= roadtype
;
875 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(RoadTypeIsRoad(_cur_roadtype
) ? &_build_road_desc
: &_build_tramway_desc
, TRANSPORT_ROAD
);
878 static const NWidgetPart _nested_build_road_scen_widgets
[] = {
879 NWidget(NWID_HORIZONTAL
),
880 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
881 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
882 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
884 NWidget(NWID_HORIZONTAL
),
885 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
886 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
887 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
888 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
889 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
890 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
891 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
892 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
893 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
894 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
895 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
896 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
897 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
898 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
899 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
900 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
901 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
902 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
903 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD
),
907 static WindowDesc
_build_road_scen_desc(
908 WDP_AUTO
, "toolbar_road_scen", 0, 0,
909 WC_SCEN_BUILD_TOOLBAR
, WC_NONE
,
911 _nested_build_road_scen_widgets
, lengthof(_nested_build_road_scen_widgets
),
912 &BuildRoadToolbarWindow::road_hotkeys
915 static const NWidgetPart _nested_build_tramway_scen_widgets
[] = {
916 NWidget(NWID_HORIZONTAL
),
917 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
918 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_ROT_CAPTION
), SetDataTip(STR_WHITE_STRING
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
919 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
921 NWidget(NWID_HORIZONTAL
),
922 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
923 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
924 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
925 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
926 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
927 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM
),
928 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
929 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
930 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
931 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
932 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE
),
933 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
934 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL
),
935 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
936 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS
),
937 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_CONVERT_ROAD
),
938 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD
, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM
),
942 static WindowDesc
_build_tramway_scen_desc(
943 WDP_AUTO
, "toolbar_tram_scen", 0, 0,
944 WC_SCEN_BUILD_TOOLBAR
, WC_NONE
,
946 _nested_build_tramway_scen_widgets
, lengthof(_nested_build_tramway_scen_widgets
),
947 &BuildRoadToolbarWindow::tram_hotkeys
951 * Show the road building toolbar in the scenario editor.
952 * @return The just opened toolbar, or \c nullptr if the toolbar was already open.
954 Window
*ShowBuildRoadScenToolbar(RoadType roadtype
)
956 DeleteWindowById(WC_SCEN_BUILD_TOOLBAR
, TRANSPORT_ROAD
);
957 _cur_roadtype
= roadtype
;
959 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(RoadTypeIsRoad(_cur_roadtype
) ? &_build_road_scen_desc
: &_build_tramway_scen_desc
, TRANSPORT_ROAD
);
962 struct BuildRoadDepotWindow
: public PickerWindowBase
{
963 BuildRoadDepotWindow(WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
965 this->CreateNestedTree();
967 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
968 if (RoadTypeIsTram(_cur_roadtype
)) {
969 this->GetWidget
<NWidgetCore
>(WID_BROD_CAPTION
)->widget_data
= STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION
;
970 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
;
973 this->FinishInitNested(TRANSPORT_ROAD
);
976 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
978 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
980 size
->width
= ScaleGUITrad(64) + 2;
981 size
->height
= ScaleGUITrad(48) + 2;
984 void DrawWidget(const Rect
&r
, int widget
) const override
986 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
988 DrawRoadDepotSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
+ DIAGDIR_NE
), _cur_roadtype
);
991 void OnClick(Point pt
, int widget
, int click_count
) override
994 case WID_BROD_DEPOT_NW
:
995 case WID_BROD_DEPOT_NE
:
996 case WID_BROD_DEPOT_SW
:
997 case WID_BROD_DEPOT_SE
:
998 this->RaiseWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
999 _road_depot_orientation
= (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
);
1000 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
1001 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1011 static const NWidgetPart _nested_build_road_depot_widgets
[] = {
1012 NWidget(NWID_HORIZONTAL
),
1013 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1014 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROD_CAPTION
), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
1016 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
1017 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1018 NWidget(NWID_HORIZONTAL_LTR
),
1019 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1020 NWidget(NWID_VERTICAL
),
1021 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1023 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1024 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1027 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
1028 NWidget(NWID_VERTICAL
),
1029 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1031 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1032 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
1035 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
1037 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1041 static WindowDesc
_build_road_depot_desc(
1042 WDP_AUTO
, nullptr, 0, 0,
1043 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
1045 _nested_build_road_depot_widgets
, lengthof(_nested_build_road_depot_widgets
)
1048 static void ShowRoadDepotPicker(Window
*parent
)
1050 new BuildRoadDepotWindow(&_build_road_depot_desc
, parent
);
1053 struct BuildRoadStationWindow
: public PickerWindowBase
{
1054 BuildRoadStationWindow(WindowDesc
*desc
, Window
*parent
, RoadStopType rs
) : PickerWindowBase(desc
, parent
)
1056 this->CreateNestedTree();
1058 /* Trams don't have non-drivethrough stations */
1059 if (RoadTypeIsTram(_cur_roadtype
) && _road_station_picker_orientation
< DIAGDIR_END
) {
1060 _road_station_picker_orientation
= DIAGDIR_END
;
1062 const RoadTypeInfo
*rti
= GetRoadTypeInfo(_cur_roadtype
);
1063 this->GetWidget
<NWidgetCore
>(WID_BROS_CAPTION
)->widget_data
= rti
->strings
.picker_title
[rs
];
1065 for (uint i
= RoadTypeIsTram(_cur_roadtype
) ? WID_BROS_STATION_X
: WID_BROS_STATION_NE
; i
< WID_BROS_LT_OFF
; i
++) {
1066 this->GetWidget
<NWidgetCore
>(i
)->tool_tip
= rti
->strings
.picker_tooltip
[rs
];
1069 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1070 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1072 this->FinishInitNested(TRANSPORT_ROAD
);
1074 this->window_class
= (rs
== ROADSTOP_BUS
) ? WC_BUS_STATION
: WC_TRUCK_STATION
;
1077 virtual ~BuildRoadStationWindow()
1079 DeleteWindowById(WC_SELECT_STATION
, 0);
1082 void OnPaint() override
1084 this->DrawWidgets();
1086 int rad
= _settings_game
.station
.modified_catchment
? ((this->window_class
== WC_BUS_STATION
) ? CA_BUS
: CA_TRUCK
) : CA_UNMODIFIED
;
1087 if (_settings_client
.gui
.station_show_coverage
) {
1088 SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
1090 SetTileSelectSize(1, 1);
1093 /* 'Accepts' and 'Supplies' texts. */
1094 StationCoverageType sct
= (this->window_class
== WC_BUS_STATION
) ? SCT_PASSENGERS_ONLY
: SCT_NON_PASSENGERS_ONLY
;
1095 int top
= this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->pos_y
+ this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->current_y
+ WD_PAR_VSEP_NORMAL
;
1096 NWidgetBase
*back_nwi
= this->GetWidget
<NWidgetBase
>(WID_BROS_BACKGROUND
);
1097 int right
= back_nwi
->pos_x
+ back_nwi
->current_x
;
1098 int bottom
= back_nwi
->pos_y
+ back_nwi
->current_y
;
1099 top
= DrawStationCoverageAreaText(back_nwi
->pos_x
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, sct
, rad
, false) + WD_PAR_VSEP_NORMAL
;
1100 top
= DrawStationCoverageAreaText(back_nwi
->pos_x
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, sct
, rad
, true) + WD_PAR_VSEP_NORMAL
;
1101 /* Resize background if the window is too small.
1102 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1103 * (This is the case, if making the window bigger moves the mouse into the window.) */
1105 ResizeWindow(this, 0, top
- bottom
, false);
1109 void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
) override
1111 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1113 size
->width
= ScaleGUITrad(64) + 2;
1114 size
->height
= ScaleGUITrad(48) + 2;
1117 void DrawWidget(const Rect
&r
, int widget
) const override
1119 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1121 StationType st
= (this->window_class
== WC_BUS_STATION
) ? STATION_BUS
: STATION_TRUCK
;
1122 StationPickerDrawSprite(r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), st
, INVALID_RAILTYPE
, _cur_roadtype
, widget
- WID_BROS_STATION_NE
);
1125 void OnClick(Point pt
, int widget
, int click_count
) override
1128 case WID_BROS_STATION_NE
:
1129 case WID_BROS_STATION_SE
:
1130 case WID_BROS_STATION_SW
:
1131 case WID_BROS_STATION_NW
:
1132 case WID_BROS_STATION_X
:
1133 case WID_BROS_STATION_Y
:
1134 this->RaiseWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1135 _road_station_picker_orientation
= (DiagDirection
)(widget
- WID_BROS_STATION_NE
);
1136 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1137 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1139 DeleteWindowById(WC_SELECT_STATION
, 0);
1142 case WID_BROS_LT_OFF
:
1143 case WID_BROS_LT_ON
:
1144 this->RaiseWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1145 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BROS_LT_OFF
);
1146 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1147 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1156 void OnRealtimeTick(uint delta_ms
) override
1158 CheckRedrawStationCoverage(this);
1162 /** Widget definition of the build road station window */
1163 static const NWidgetPart _nested_road_station_picker_widgets
[] = {
1164 NWidget(NWID_HORIZONTAL
),
1165 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1166 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1168 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1169 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1170 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1171 NWidget(NWID_SPACER
), SetFill(1, 0),
1172 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1173 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1174 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1175 NWidget(NWID_SPACER
), SetFill(1, 0),
1177 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1178 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1179 NWidget(NWID_SPACER
), SetFill(1, 0),
1180 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1181 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1182 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1183 NWidget(NWID_SPACER
), SetFill(1, 0),
1185 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1186 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1187 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1188 NWidget(NWID_SPACER
), SetFill(1, 0),
1190 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1191 NWidget(NWID_SPACER
), SetFill(1, 0),
1192 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1193 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1194 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1195 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1196 NWidget(NWID_SPACER
), SetFill(1, 0),
1198 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1202 static WindowDesc
_road_station_picker_desc(
1203 WDP_AUTO
, nullptr, 0, 0,
1204 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1206 _nested_road_station_picker_widgets
, lengthof(_nested_road_station_picker_widgets
)
1209 /** Widget definition of the build tram station window */
1210 static const NWidgetPart _nested_tram_station_picker_widgets
[] = {
1211 NWidget(NWID_HORIZONTAL
),
1212 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1213 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1215 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1216 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1217 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1218 NWidget(NWID_SPACER
), SetFill(1, 0),
1219 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1220 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1221 NWidget(NWID_SPACER
), SetFill(1, 0),
1223 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1224 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1225 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1226 NWidget(NWID_SPACER
), SetFill(1, 0),
1228 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1229 NWidget(NWID_SPACER
), SetFill(1, 0),
1230 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1231 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1232 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1233 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1234 NWidget(NWID_SPACER
), SetFill(1, 0),
1236 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1240 static WindowDesc
_tram_station_picker_desc(
1241 WDP_AUTO
, nullptr, 0, 0,
1242 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1244 _nested_tram_station_picker_widgets
, lengthof(_nested_tram_station_picker_widgets
)
1247 static void ShowRVStationPicker(Window
*parent
, RoadStopType rs
)
1249 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype
) ? &_road_station_picker_desc
: &_tram_station_picker_desc
, parent
, rs
);
1252 void InitializeRoadGui()
1254 _road_depot_orientation
= DIAGDIR_NW
;
1255 _road_station_picker_orientation
= DIAGDIR_NW
;
1259 * I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
1261 void InitializeRoadGUI()
1263 BuildRoadToolbarWindow
*w
= dynamic_cast<BuildRoadToolbarWindow
*>(FindWindowById(WC_BUILD_TOOLBAR
, TRANSPORT_ROAD
));
1264 if (w
!= nullptr) w
->ModifyRoadType(_cur_roadtype
);
1267 DropDownList
GetRoadTypeDropDownList(RoadTramTypes rtts
, bool for_replacement
, bool all_option
)
1269 RoadTypes used_roadtypes
;
1270 RoadTypes avail_roadtypes
;
1272 const Company
*c
= Company::Get(_local_company
);
1274 /* Find the used roadtypes. */
1275 if (for_replacement
) {
1276 avail_roadtypes
= GetCompanyRoadTypes(c
->index
, false);
1277 used_roadtypes
= GetRoadTypes(false);
1279 avail_roadtypes
= c
->avail_roadtypes
;
1280 used_roadtypes
= GetRoadTypes(true);
1283 /* Filter listed road types */
1284 if (!HasBit(rtts
, RTT_ROAD
)) used_roadtypes
&= _roadtypes_type
;
1285 if (!HasBit(rtts
, RTT_TRAM
)) used_roadtypes
&= ~_roadtypes_type
;
1290 list
.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_ROADTYPE
, INVALID_ROADTYPE
, false));
1293 Dimension d
= { 0, 0 };
1295 /* Get largest icon size, to ensure text is aligned on each menu item. */
1296 if (!for_replacement
) {
1297 FOR_ALL_SORTED_ROADTYPES(rt
) {
1298 if (!HasBit(used_roadtypes
, rt
)) continue;
1299 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1300 d
= maxdim(d
, GetSpriteSize(rti
->gui_sprites
.build_x_road
));
1304 FOR_ALL_SORTED_ROADTYPES(rt
) {
1305 /* If it's not used ever, don't show it to the user. */
1306 if (!HasBit(used_roadtypes
, rt
)) continue;
1308 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1310 DropDownListParamStringItem
*item
;
1311 if (for_replacement
) {
1312 item
= new DropDownListParamStringItem(rti
->strings
.replace_text
, rt
, !HasBit(avail_roadtypes
, rt
));
1314 StringID str
= rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
;
1315 DropDownListIconItem
*iconitem
= new DropDownListIconItem(rti
->gui_sprites
.build_x_road
, PAL_NONE
, str
, rt
, !HasBit(avail_roadtypes
, rt
));
1316 iconitem
->SetDimension(d
);
1319 item
->SetParam(0, rti
->strings
.menu_text
);
1320 item
->SetParam(1, rti
->max_speed
/ 2);
1321 list
.emplace_back(item
);
1324 if (list
.size() == 0) {
1325 /* Empty dropdowns are not allowed */
1326 list
.emplace_back(new DropDownListStringItem(STR_NONE
, INVALID_ROADTYPE
, true));
1332 DropDownList
GetScenRoadTypeDropDownList(RoadTramTypes rtts
)
1334 RoadTypes avail_roadtypes
= GetRoadTypes(false);
1335 avail_roadtypes
= AddDateIntroducedRoadTypes(avail_roadtypes
, _date
);
1336 RoadTypes used_roadtypes
= GetRoadTypes(true);
1338 /* Filter listed road types */
1339 if (!HasBit(rtts
, RTT_ROAD
)) used_roadtypes
&= _roadtypes_type
;
1340 if (!HasBit(rtts
, RTT_TRAM
)) used_roadtypes
&= ~_roadtypes_type
;
1344 /* If it's not used ever, don't show it to the user. */
1345 Dimension d
= { 0, 0 };
1347 FOR_ALL_SORTED_ROADTYPES(rt
) {
1348 if (!HasBit(used_roadtypes
, rt
)) continue;
1349 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1350 d
= maxdim(d
, GetSpriteSize(rti
->gui_sprites
.build_x_road
));
1352 FOR_ALL_SORTED_ROADTYPES(rt
) {
1353 if (!HasBit(used_roadtypes
, rt
)) continue;
1355 const RoadTypeInfo
*rti
= GetRoadTypeInfo(rt
);
1357 StringID str
= rti
->max_speed
> 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY
: STR_JUST_STRING
;
1358 DropDownListIconItem
*item
= new DropDownListIconItem(rti
->gui_sprites
.build_x_road
, PAL_NONE
, str
, rt
, !HasBit(avail_roadtypes
, rt
));
1359 item
->SetDimension(d
);
1360 item
->SetParam(0, rti
->strings
.menu_text
);
1361 item
->SetParam(1, rti
->max_speed
);
1362 list
.emplace_back(item
);
1365 if (list
.size() == 0) {
1366 /* Empty dropdowns are not allowed */
1367 list
.emplace_back(new DropDownListStringItem(STR_NONE
, -1, true));