4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file road_gui.cpp GUI for building roads. */
14 #include "window_gui.h"
15 #include "station_gui.h"
16 #include "terraform_gui.h"
17 #include "viewport_func.h"
18 #include "command_func.h"
20 #include "station_func.h"
21 #include "window_func.h"
22 #include "vehicle_func.h"
23 #include "sound_func.h"
24 #include "company_func.h"
25 #include "tunnelbridge.h"
26 #include "map/class.h"
27 #include "map/common.h"
29 #include "map/tunnel.h"
30 #include "map/bridge.h"
31 #include "tilehighlight_func.h"
32 #include "company_base.h"
35 #include "zoom_func.h"
37 #include "widgets/road_widget.h"
39 #include "table/strings.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
;
70 /** Dragging actions in the road toolbar. */
72 DRAG_DEMOLISH_AREA
, ///< Clear area
73 DRAG_BUILD_BRIDGE
, ///< Bridge placement
74 DRAG_PLACE_ROAD_X_DIR
, ///< Road placement (X axis)
75 DRAG_PLACE_ROAD_Y_DIR
, ///< Road placement (Y axis)
76 DRAG_PLACE_AUTOROAD
, ///< Road placement (auto)
77 DRAG_BUILD_BUSSTOP
, ///< Road stop placement (buses)
78 DRAG_BUILD_TRUCKSTOP
, ///< Road stop placement (trucks)
79 DRAG_REMOVE_BUSSTOP
, ///< Road stop removal (buses)
80 DRAG_REMOVE_TRUCKSTOP
, ///< Road stop removal (trucks)
84 void CcPlaySound_SPLAT_OTHER(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
86 if (result
.Succeeded() && _settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_SPLAT_OTHER
, tile
);
89 /** Show the bridge building window between a pair of tiles. */
90 static void HandleBuildRoadBridge (TileIndex start_tile
, TileIndex end_tile
)
92 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
93 ShowBuildBridgeWindow (start_tile
, end_tile
, TRANSPORT_ROAD
, RoadTypeToRoadTypes(_cur_roadtype
));
97 * Callback executed after a build tunnel command has been called.
99 * @param result Whether the build succeeded.
100 * @param start_tile Starting tile of the tunnel.
101 * @param p1 bit 0-3 railtype or roadtypes
102 * bit 8-9 transport type
105 void CcBuildTunnel(const CommandCost
&result
, TileIndex start_tile
, uint32 p1
, uint32 p2
)
107 if (result
.Succeeded()) {
108 bool road
= ((TransportType
)GB(p1
, 8, 2) == TRANSPORT_ROAD
);
110 if (_settings_client
.sound
.confirm
) SndPlayTileFx (road
? SND_1F_SPLAT_OTHER
: SND_20_SPLAT_RAIL
, start_tile
);
111 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
114 DiagDirection start_direction
= ReverseDiagDir(GetTunnelBridgeDirection(start_tile
));
115 ConnectRoadToStructure(start_tile
, start_direction
);
117 TileIndex end_tile
= GetOtherTunnelEnd(start_tile
);
118 DiagDirection end_direction
= ReverseDiagDir(GetTunnelBridgeDirection(end_tile
));
119 ConnectRoadToStructure(end_tile
, end_direction
);
122 SetRedErrorSquare(_build_tunnel_endtile
);
126 /** Structure holding information per roadtype for several functions */
127 struct RoadTypeInfo
{
128 StringID err_build_road
; ///< Building a normal piece of road
129 StringID err_remove_road
; ///< Removing a normal piece of road
130 StringID err_depot
; ///< Building a depot
131 StringID err_build_station
[2]; ///< Building a bus or truck station
132 StringID err_remove_station
[2]; ///< Removing of a bus or truck station
134 StringID picker_title
[2]; ///< Title for the station picker for bus or truck stations
135 StringID picker_tooltip
[2]; ///< Tooltip for the station picker for bus or truck stations
137 SpriteID cursor_nesw
; ///< Cursor for building NE and SW bits
138 SpriteID cursor_nwse
; ///< Cursor for building NW and SE bits
139 SpriteID cursor_autoroad
; ///< Cursor for building autoroad
142 /** What errors/cursors must be shown for several types of roads */
143 static const RoadTypeInfo _road_type_infos
[] = {
145 STR_ERROR_CAN_T_BUILD_ROAD_HERE
,
146 STR_ERROR_CAN_T_REMOVE_ROAD_FROM
,
147 STR_ERROR_CAN_T_BUILD_ROAD_DEPOT
,
148 { STR_ERROR_CAN_T_BUILD_BUS_STATION
, STR_ERROR_CAN_T_BUILD_TRUCK_STATION
},
149 { STR_ERROR_CAN_T_REMOVE_BUS_STATION
, STR_ERROR_CAN_T_REMOVE_TRUCK_STATION
},
150 { STR_STATION_BUILD_BUS_ORIENTATION
, STR_STATION_BUILD_TRUCK_ORIENTATION
},
151 { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP
, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP
},
153 SPR_CURSOR_ROAD_NESW
,
154 SPR_CURSOR_ROAD_NWSE
,
158 STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE
,
159 STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM
,
160 STR_ERROR_CAN_T_BUILD_TRAM_DEPOT
,
161 { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION
, STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION
},
162 { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION
, STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION
},
163 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION
, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION
},
164 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP
, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP
},
166 SPR_CURSOR_TRAMWAY_NESW
,
167 SPR_CURSOR_TRAMWAY_NWSE
,
173 * If required, connects a new structure to an existing road or tram by building the missing roadbit.
174 * @param tile Tile containing the structure to connect.
175 * @param direction Direction to check.
177 void ConnectRoadToStructure(TileIndex tile
, DiagDirection direction
)
179 tile
+= TileOffsByDiagDir(direction
);
180 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
181 if (IsRoadTile(tile
) && GetRoadBits(tile
, _cur_roadtype
) != ROAD_NONE
) {
182 DoCommandP(tile
, _cur_roadtype
<< 4 | DiagDirToRoadBits(ReverseDiagDir(direction
)), 0, CMD_BUILD_ROAD
);
186 void CcRoadDepot(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
188 if (result
.Failed()) return;
190 DiagDirection dir
= (DiagDirection
)GB(p1
, 0, 2);
191 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_SPLAT_OTHER
, tile
);
192 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
193 ConnectRoadToStructure(tile
, dir
);
197 * Command callback for building road stops.
198 * @param result Result of the build road stop command.
199 * @param tile Start tile.
200 * @param p1 bit 0..7: Width of the road stop.
201 * bit 8..15: Length of the road stop.
202 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
203 * bit 1: 0 For normal stops, 1 for drive-through.
204 * bit 2..3: The roadtypes.
205 * bit 5: Allow stations directly adjacent to other stations.
206 * bit 6..7: Entrance direction (#DiagDirection).
207 * bit 16..31: Station ID to join (INVALID_STATION if build new one).
208 * @see CmdBuildRoadStop
210 void CcRoadStop(const CommandCost
&result
, TileIndex tile
, uint32 p1
, uint32 p2
)
212 if (result
.Failed()) return;
214 DiagDirection dir
= (DiagDirection
)GB(p2
, 6, 2);
215 if (_settings_client
.sound
.confirm
) SndPlayTileFx(SND_1F_SPLAT_OTHER
, tile
);
216 if (!_settings_client
.gui
.persistent_buildingtools
) ResetPointerMode();
217 TileArea
roadstop_area(tile
, GB(p1
, 0, 8), GB(p1
, 8, 8));
218 TILE_AREA_LOOP(cur_tile
, roadstop_area
) {
219 ConnectRoadToStructure(cur_tile
, dir
);
220 /* For a drive-through road stop build connecting road for other entrance. */
221 if (HasBit(p2
, 1)) ConnectRoadToStructure(cur_tile
, ReverseDiagDir(dir
));
225 StringID
GetErrBuildRoadStop (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
227 return _road_type_infos
[FIND_FIRST_BIT(GB(p2
, 2, 2))].err_build_station
[GB(p2
, 0, 1)];
230 StringID
GetErrRemoveRoadStop (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
232 return _road_type_infos
[GB(p2
, 2, 2)].err_remove_station
[GB(p2
, 0, 1)];
235 StringID
GetErrBuildRoad (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
237 return _road_type_infos
[GB(p2
, 3, 2)].err_build_road
;
240 StringID
GetErrRemoveRoad (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
242 return _road_type_infos
[GB(p2
, 3, 2)].err_remove_road
;
245 StringID
GetErrBuildRoadDepot (TileIndex tile
, uint32 p1
, uint32 p2
, const char *text
)
247 return _road_type_infos
[GB(p1
, 2, 2)].err_depot
;
250 typedef void OnButtonClick(Window
*w
);
253 * Toggles state of the Remove button of Build road toolbar
254 * @param w window the button belongs to
256 static void ToggleRoadButton_Remove(Window
*w
)
258 w
->ToggleWidgetLoweredState(WID_ROT_REMOVE
);
259 w
->SetWidgetDirty(WID_ROT_REMOVE
);
260 _remove_button_clicked
= w
->IsWidgetLowered(WID_ROT_REMOVE
);
261 SetSelectionRed(_remove_button_clicked
);
265 * Updates the Remove button because of Ctrl state change
266 * @param w window the button belongs to
267 * @return true iff the remove button was changed
269 static bool RoadToolbar_CtrlChanged(Window
*w
)
271 if (w
->IsWidgetDisabled(WID_ROT_REMOVE
)) return false;
273 /* allow ctrl to switch remove mode only for these widgets */
274 for (uint i
= WID_ROT_ROAD_X
; i
<= WID_ROT_AUTOROAD
; i
++) {
275 if (w
->IsWidgetLowered(i
)) {
276 ToggleRoadButton_Remove(w
);
284 /** Road toolbar window handler. */
285 struct BuildRoadToolbarWindow
: Window
{
286 int last_started_action
; ///< Last started user action.
288 BuildRoadToolbarWindow (const WindowDesc
*desc
, WindowNumber window_number
) :
289 Window (desc
), last_started_action (WIDGET_LIST_END
)
291 this->InitNested(window_number
);
292 this->SetWidgetsDisabledState(true,
297 this->OnInvalidateData();
299 if (_settings_client
.gui
.link_terraform_toolbar
) ShowTerraformToolbar(this);
302 void OnDelete (void) FINAL_OVERRIDE
304 if (_settings_client
.gui
.link_terraform_toolbar
) DeleteWindowById(WC_SCEN_LAND_GEN
, 0, false);
308 * Some data on this window has become invalid.
309 * @param data Information about the changed data.
310 * @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.
312 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
314 if (!gui_scope
) return;
316 bool can_build
= CanBuildVehicleInfrastructure(VEH_ROAD
);
317 this->SetWidgetsDisabledState(!can_build
,
320 WID_ROT_TRUCK_STATION
,
323 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
324 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
325 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
330 * Update the remove button lowered state of the road toolbar
332 * @param clicked_widget The widget which the client clicked just now
334 void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget
)
336 /* The remove and the one way button state is driven
337 * by the other buttons so they don't act on themselves.
338 * Both are only valid if they are able to apply as options. */
339 switch (clicked_widget
) {
341 this->RaiseWidget(WID_ROT_ONE_WAY
);
342 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
345 case WID_ROT_ONE_WAY
:
346 this->RaiseWidget(WID_ROT_REMOVE
);
347 this->SetWidgetDirty(WID_ROT_REMOVE
);
350 case WID_ROT_BUS_STATION
:
351 case WID_ROT_TRUCK_STATION
:
352 this->DisableWidget(WID_ROT_ONE_WAY
);
353 this->SetWidgetDisabledState(WID_ROT_REMOVE
, !this->IsWidgetLowered(clicked_widget
));
358 case WID_ROT_AUTOROAD
:
359 this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget
),
366 /* When any other buttons than road/station, raise and
367 * disable the removal button */
368 this->SetWidgetsDisabledState(true,
372 this->SetWidgetsLoweredState(false,
380 virtual void OnClick(Point pt
, int widget
, int click_count
)
382 _remove_button_clicked
= false;
383 _one_way_button_clicked
= false;
386 HandlePlacePushButton (this, WID_ROT_ROAD_X
, _road_type_infos
[_cur_roadtype
].cursor_nwse
, POINTER_TILE
);
387 this->last_started_action
= widget
;
391 HandlePlacePushButton (this, WID_ROT_ROAD_Y
, _road_type_infos
[_cur_roadtype
].cursor_nesw
, POINTER_TILE
);
392 this->last_started_action
= widget
;
395 case WID_ROT_AUTOROAD
:
396 HandlePlacePushButton (this, WID_ROT_AUTOROAD
, _road_type_infos
[_cur_roadtype
].cursor_autoroad
, POINTER_TILE
);
397 this->last_started_action
= widget
;
400 case WID_ROT_DEMOLISH
:
401 HandlePlacePushButton (this, WID_ROT_DEMOLISH
, ANIMCURSOR_DEMOLISH
, POINTER_TILE
);
402 this->last_started_action
= widget
;
406 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
)) return;
407 if (HandlePlacePushButton (this, WID_ROT_DEPOT
, SPR_CURSOR_ROAD_DEPOT
, POINTER_TILE
)) {
408 ShowRoadDepotPicker(this);
409 this->last_started_action
= widget
;
413 case WID_ROT_BUS_STATION
:
414 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
)) return;
415 if (HandlePlacePushButton (this, WID_ROT_BUS_STATION
, SPR_CURSOR_BUS_STATION
, POINTER_TILE
)) {
416 ShowRVStationPicker(this, ROADSTOP_BUS
);
417 this->last_started_action
= widget
;
421 case WID_ROT_TRUCK_STATION
:
422 if (_game_mode
== GM_EDITOR
|| !CanBuildVehicleInfrastructure(VEH_ROAD
)) return;
423 if (HandlePlacePushButton (this, WID_ROT_TRUCK_STATION
, SPR_CURSOR_TRUCK_STATION
, POINTER_TILE
)) {
424 ShowRVStationPicker(this, ROADSTOP_TRUCK
);
425 this->last_started_action
= widget
;
429 case WID_ROT_ONE_WAY
:
430 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY
)) return;
432 this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY
);
433 SetSelectionRed(false);
436 case WID_ROT_BUILD_BRIDGE
:
437 HandlePlacePushButton (this, WID_ROT_BUILD_BRIDGE
, SPR_CURSOR_BRIDGE
, POINTER_TILE
);
438 this->last_started_action
= widget
;
441 case WID_ROT_BUILD_TUNNEL
:
442 HandlePlacePushButton (this, WID_ROT_BUILD_TUNNEL
, SPR_CURSOR_ROAD_TUNNEL
, POINTER_AREA
);
443 this->last_started_action
= widget
;
447 if (this->IsWidgetDisabled(WID_ROT_REMOVE
)) return;
449 DeleteWindowById(WC_SELECT_STATION
, 0);
450 ToggleRoadButton_Remove(this);
451 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
454 default: NOT_REACHED();
456 this->UpdateOptionWidgetStatus((RoadToolbarWidgets
)widget
);
457 if (_ctrl_pressed
) RoadToolbar_CtrlChanged(this);
460 bool OnHotkey (int hotkey
) OVERRIDE
462 MarkTileDirtyByTile(TileVirtXY(_thd
.pos
.x
, _thd
.pos
.y
)); // redraw tile selection
463 return Window::OnHotkey(hotkey
);
466 virtual void OnPlaceObject(Point pt
, TileIndex tile
)
468 _remove_button_clicked
= this->IsWidgetLowered(WID_ROT_REMOVE
);
469 _one_way_button_clicked
= this->IsWidgetLowered(WID_ROT_ONE_WAY
);
470 switch (this->last_started_action
) {
472 _place_road_flag
= RF_DIR_X
;
473 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
474 VpStartPlaceSizing (tile
, VPM_X
, DRAG_PLACE_ROAD_X_DIR
);
478 _place_road_flag
= RF_DIR_Y
;
479 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
480 VpStartPlaceSizing (tile
, VPM_Y
, DRAG_PLACE_ROAD_Y_DIR
);
483 case WID_ROT_AUTOROAD
:
484 _place_road_flag
= RF_NONE
;
485 if (_tile_fract_coords
.x
>= 8) _place_road_flag
|= RF_START_HALFROAD_X
;
486 if (_tile_fract_coords
.y
>= 8) _place_road_flag
|= RF_START_HALFROAD_Y
;
487 VpStartPlaceSizing(tile
, VPM_X_OR_Y
, DRAG_PLACE_AUTOROAD
);
490 case WID_ROT_DEMOLISH
:
491 VpStartPlaceSizing (tile
, VPM_X_AND_Y_ROTATED
, DRAG_DEMOLISH_AREA
);
495 DoCommandP(tile
, _cur_roadtype
<< 2 | _road_depot_orientation
, 0, CMD_BUILD_ROAD_DEPOT
);
498 case WID_ROT_BUS_STATION
:
499 case WID_ROT_TRUCK_STATION
: {
500 bool bus
= this->last_started_action
== WID_ROT_BUS_STATION
;
501 if (_remove_button_clicked
) {
502 VpStartPlaceSizing (tile
, VPM_X_AND_Y
, bus
? DRAG_REMOVE_BUSSTOP
: DRAG_REMOVE_TRUCKSTOP
);
504 VpStartPlaceSizing (tile
,
505 (_road_station_picker_orientation
>= DIAGDIR_END
) ? VPM_X_AND_Y
: // drive-through stop
506 (DiagDirToAxis(_road_station_picker_orientation
) == AXIS_X
) ? VPM_Y
: VPM_X
,
507 bus
? DRAG_BUILD_BUSSTOP
: DRAG_BUILD_TRUCKSTOP
,
508 _settings_game
.station
.station_spread
);
513 case WID_ROT_BUILD_BRIDGE
:
514 if (IsBridgeHeadTile(tile
)) {
515 TileIndex other_tile
= GetOtherBridgeEnd (tile
);
516 HandleBuildRoadBridge (other_tile
, tile
);
518 VpStartPlaceSizing (tile
, VPM_X_OR_Y
, DRAG_BUILD_BRIDGE
);
522 case WID_ROT_BUILD_TUNNEL
:
523 DoCommandP(tile
, RoadTypeToRoadTypes(_cur_roadtype
) | (TRANSPORT_ROAD
<< 8), 0, CMD_BUILD_TUNNEL
);
526 default: NOT_REACHED();
530 virtual void OnPlaceObjectAbort()
532 this->RaiseButtons();
533 this->SetWidgetsDisabledState(true,
537 this->SetWidgetDirty(WID_ROT_REMOVE
);
538 this->SetWidgetDirty(WID_ROT_ONE_WAY
);
540 DeleteWindowById(WC_BUS_STATION
, TRANSPORT_ROAD
);
541 DeleteWindowById(WC_TRUCK_STATION
, TRANSPORT_ROAD
);
542 DeleteWindowById(WC_BUILD_DEPOT
, TRANSPORT_ROAD
);
543 DeleteWindowById(WC_SELECT_STATION
, 0);
544 DeleteWindowByClass(WC_BUILD_BRIDGE
);
547 bool OnPlaceDrag (int userdata
, Point pt
) OVERRIDE
549 /* Here we update the end tile flags
550 * of the road placement actions.
551 * At first we reset the end halfroad
552 * bits and if needed we set them again. */
554 case DRAG_PLACE_ROAD_X_DIR
:
555 _place_road_flag
&= ~RF_END_HALFROAD_X
;
556 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
559 case DRAG_PLACE_ROAD_Y_DIR
:
560 _place_road_flag
&= ~RF_END_HALFROAD_Y
;
561 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
564 case DRAG_PLACE_AUTOROAD
:
565 _place_road_flag
&= ~(RF_END_HALFROAD_Y
| RF_END_HALFROAD_X
);
566 if (pt
.y
& 8) _place_road_flag
|= RF_END_HALFROAD_Y
;
567 if (pt
.x
& 8) _place_road_flag
|= RF_END_HALFROAD_X
;
569 /* For autoroad we need to update the
570 * direction of the road */
571 if (_thd
.size
.x
> _thd
.size
.y
|| (_thd
.size
.x
== _thd
.size
.y
&&
572 ( (_tile_fract_coords
.x
< _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) < 16) ||
573 (_tile_fract_coords
.x
> _tile_fract_coords
.y
&& (_tile_fract_coords
.x
+ _tile_fract_coords
.y
) > 16) ))) {
575 _place_road_flag
&= ~RF_DIR_Y
;
578 _place_road_flag
|= RF_DIR_Y
;
590 void OnPlaceMouseUp (int userdata
, Point pt
, TileIndex start_tile
, TileIndex end_tile
) OVERRIDE
594 default: NOT_REACHED();
595 case DRAG_BUILD_BRIDGE
:
596 HandleBuildRoadBridge (start_tile
, end_tile
);
599 case DRAG_DEMOLISH_AREA
:
600 HandleDemolishMouseUp (start_tile
, end_tile
);
603 case DRAG_PLACE_ROAD_X_DIR
:
604 case DRAG_PLACE_ROAD_Y_DIR
:
605 case DRAG_PLACE_AUTOROAD
:
607 * Use the first three bits (0x07) if dir == Y
608 * else use the last 2 bits (X dir has
609 * not the 3rd bit set) */
610 _place_road_flag
= (RoadFlags
)((_place_road_flag
& RF_DIR_Y
) ? (_place_road_flag
& 0x07) : (_place_road_flag
>> 3));
612 DoCommandP(start_tile
, end_tile
, _place_road_flag
| (_cur_roadtype
<< 3) | (_one_way_button_clicked
<< 5),
613 _remove_button_clicked
? CMD_REMOVE_LONG_ROAD
: CMD_BUILD_LONG_ROAD
);
616 case DRAG_BUILD_BUSSTOP
:
617 case DRAG_BUILD_TRUCKSTOP
: {
618 uint32 p2
= (INVALID_STATION
<< 16) | (_ctrl_pressed
<< 5) |
619 RoadTypeToRoadTypes(_cur_roadtype
) << 2 |
620 (userdata
== DRAG_BUILD_TRUCKSTOP
? ROADSTOP_TRUCK
: ROADSTOP_BUS
);
622 uint8 ddir
= _road_station_picker_orientation
;
623 if (ddir
>= DIAGDIR_END
) {
624 SetBit (p2
, 1); // It's a drive-through stop.
625 ddir
-= DIAGDIR_END
; // Adjust picker result to actual direction.
627 p2
|= ddir
<< 6; // Set the DiagDirecion into p2 bits 6 and 7.
629 TileArea
ta (start_tile
, end_tile
);
630 Command
cmdcont (ta
.tile
, ta
.w
| ta
.h
<< 8, p2
, CMD_BUILD_ROAD_STOP
);
631 ShowSelectStationIfNeeded (&cmdcont
, ta
);
635 case DRAG_REMOVE_BUSSTOP
: {
636 TileArea
ta(start_tile
, end_tile
);
637 DoCommandP(ta
.tile
, ta
.w
| ta
.h
<< 8, (_ctrl_pressed
<< 1) | ROADSTOP_BUS
| (_cur_roadtype
<< 2), CMD_REMOVE_ROAD_STOP
);
641 case DRAG_REMOVE_TRUCKSTOP
: {
642 TileArea
ta(start_tile
, end_tile
);
643 DoCommandP(ta
.tile
, ta
.w
| ta
.h
<< 8, (_ctrl_pressed
<< 1) | ROADSTOP_TRUCK
| (_cur_roadtype
<< 2), CMD_REMOVE_ROAD_STOP
);
650 void OnPlacePresize (TileIndex
*tile
, TileIndex
*tile2
) OVERRIDE
652 DoCommand (*tile
, RoadTypeToRoadTypes(_cur_roadtype
) | (TRANSPORT_ROAD
<< 8), 0, DC_AUTO
, CMD_BUILD_TUNNEL
);
653 if (_build_tunnel_endtile
!= 0) *tile2
= _build_tunnel_endtile
;
656 bool OnCTRLStateChange (void) OVERRIDE
658 return RoadToolbar_CtrlChanged (this);
661 static HotkeyList hotkeys
;
665 * Handler for global hotkeys of the BuildRoadToolbarWindow.
666 * @param hotkey Hotkey
667 * @return Whether the hotkey was handled.
669 static bool RoadToolbarGlobalHotkeys (int hotkey
)
672 switch (_game_mode
) {
674 extern RoadType _last_built_roadtype
;
675 w
= ShowBuildRoadToolbar(_last_built_roadtype
);
680 w
= ShowBuildRoadScenToolbar();
687 return (w
!= NULL
) && w
->OnHotkey (hotkey
);
690 static const Hotkey roadtoolbar_hotkeys
[] = {
691 Hotkey ("build_x", WID_ROT_ROAD_X
, '1'),
692 Hotkey ("build_y", WID_ROT_ROAD_Y
, '2'),
693 Hotkey ("autoroad", WID_ROT_AUTOROAD
, '3'),
694 Hotkey ("demolish", WID_ROT_DEMOLISH
, '4'),
695 Hotkey ("depot", WID_ROT_DEPOT
, '5'),
696 Hotkey ("bus_station", WID_ROT_BUS_STATION
, '6'),
697 Hotkey ("truck_station", WID_ROT_TRUCK_STATION
, '7'),
698 Hotkey ("oneway", WID_ROT_ONE_WAY
, '8'),
699 Hotkey ("bridge", WID_ROT_BUILD_BRIDGE
, 'B'),
700 Hotkey ("tunnel", WID_ROT_BUILD_TUNNEL
, 'T'),
701 Hotkey ("remove", WID_ROT_REMOVE
, 'R'),
703 HotkeyList
BuildRoadToolbarWindow::hotkeys("roadtoolbar", roadtoolbar_hotkeys
, RoadToolbarGlobalHotkeys
);
706 static const NWidgetPart _nested_build_road_widgets
[] = {
707 NWidget(NWID_HORIZONTAL
),
708 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
709 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
710 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
712 NWidget(NWID_HORIZONTAL
),
713 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
714 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
715 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
716 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
717 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
718 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
719 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
720 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
721 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
722 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT
),
723 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
724 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION
),
725 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
726 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY
),
727 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
728 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
729 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
730 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
731 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
732 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
733 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
734 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
735 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
739 static WindowDesc::Prefs
_build_road_prefs ("toolbar_road");
741 static const WindowDesc
_build_road_desc(
742 WDP_ALIGN_TOOLBAR
, 0, 0,
743 WC_BUILD_TOOLBAR
, WC_NONE
,
745 _nested_build_road_widgets
, lengthof(_nested_build_road_widgets
),
746 &_build_road_prefs
, &BuildRoadToolbarWindow::hotkeys
749 static const NWidgetPart _nested_build_tramway_widgets
[] = {
750 NWidget(NWID_HORIZONTAL
),
751 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
752 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_ROAD_TOOLBAR_TRAM_CONSTRUCTION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
753 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
755 NWidget(NWID_HORIZONTAL
),
756 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
757 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
758 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
759 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION
),
760 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
761 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM
),
762 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
763 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
764 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEPOT
),
765 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT
),
766 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUS_STATION
),
767 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION
),
768 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_TRUCK_STATION
),
769 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION
),
770 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
771 NWidget(WWT_EMPTY
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
), SetMinimalSize(0, 0),
772 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
773 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE
),
774 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
775 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL
),
776 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
777 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS
),
781 static WindowDesc::Prefs
_build_tramway_prefs ("toolbar_tramway");
783 static const WindowDesc
_build_tramway_desc(
784 WDP_ALIGN_TOOLBAR
, 0, 0,
785 WC_BUILD_TOOLBAR
, WC_NONE
,
787 _nested_build_tramway_widgets
, lengthof(_nested_build_tramway_widgets
),
788 &_build_tramway_prefs
, &BuildRoadToolbarWindow::hotkeys
792 * Open the build road toolbar window
794 * If the terraform toolbar is linked to the toolbar, that window is also opened.
796 * @return newly opened road toolbar, or NULL if the toolbar could not be opened.
798 Window
*ShowBuildRoadToolbar(RoadType roadtype
)
800 if (!Company::IsValidID(_local_company
)) return NULL
;
801 _cur_roadtype
= roadtype
;
803 DeleteWindowByClass(WC_BUILD_TOOLBAR
);
804 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(roadtype
== ROADTYPE_ROAD
? &_build_road_desc
: &_build_tramway_desc
, TRANSPORT_ROAD
);
807 static const NWidgetPart _nested_build_road_scen_widgets
[] = {
808 NWidget(NWID_HORIZONTAL
),
809 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
810 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
811 NWidget(WWT_STICKYBOX
, COLOUR_DARK_GREEN
),
813 NWidget(NWID_HORIZONTAL
),
814 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_X
),
815 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
816 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ROAD_Y
),
817 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION
),
818 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_AUTOROAD
),
819 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD
),
820 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_DEMOLISH
),
821 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE
, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC
),
822 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
823 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_ONE_WAY
),
824 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD
),
825 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_BRIDGE
),
826 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE
),
827 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_BUILD_TUNNEL
),
828 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL
, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL
),
829 NWidget(WWT_IMGBTN
, COLOUR_DARK_GREEN
, WID_ROT_REMOVE
),
830 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE
, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD
),
834 static WindowDesc::Prefs
_build_road_scen_prefs ("toolbar_road_scen");
836 static const WindowDesc
_build_road_scen_desc(
838 WC_SCEN_BUILD_TOOLBAR
, WC_NONE
,
840 _nested_build_road_scen_widgets
, lengthof(_nested_build_road_scen_widgets
),
841 &_build_road_scen_prefs
, &BuildRoadToolbarWindow::hotkeys
845 * Show the road building toolbar in the scenario editor.
846 * @return The just opened toolbar, or \c NULL if the toolbar was already open.
848 Window
*ShowBuildRoadScenToolbar()
850 _cur_roadtype
= ROADTYPE_ROAD
;
851 return AllocateWindowDescFront
<BuildRoadToolbarWindow
>(&_build_road_scen_desc
, TRANSPORT_ROAD
);
854 struct BuildRoadDepotWindow
: public PickerWindowBase
{
855 BuildRoadDepotWindow (const WindowDesc
*desc
, Window
*parent
) : PickerWindowBase(desc
, parent
)
857 this->CreateNestedTree();
859 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
860 if ( _cur_roadtype
== ROADTYPE_TRAM
) {
861 this->GetWidget
<NWidgetCore
>(WID_BROD_CAPTION
)->widget_data
= STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION
;
862 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
;
865 this->InitNested(TRANSPORT_ROAD
);
868 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
870 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
872 size
->width
= ScaleGUITrad(64) + 2;
873 size
->height
= ScaleGUITrad(48) + 2;
876 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
878 if (!IsInsideMM(widget
, WID_BROD_DEPOT_NE
, WID_BROD_DEPOT_NW
+ 1)) return;
880 DrawRoadDepotSprite (dpi
, r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31), (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
+ DIAGDIR_NE
), _cur_roadtype
);
883 virtual void OnClick(Point pt
, int widget
, int click_count
)
886 case WID_BROD_DEPOT_NW
:
887 case WID_BROD_DEPOT_NE
:
888 case WID_BROD_DEPOT_SW
:
889 case WID_BROD_DEPOT_SE
:
890 this->RaiseWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
891 _road_depot_orientation
= (DiagDirection
)(widget
- WID_BROD_DEPOT_NE
);
892 this->LowerWidget(_road_depot_orientation
+ WID_BROD_DEPOT_NE
);
893 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
903 static const NWidgetPart _nested_build_road_depot_widgets
[] = {
904 NWidget(NWID_HORIZONTAL
),
905 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
906 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROD_CAPTION
), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
908 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
),
909 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
910 NWidget(NWID_HORIZONTAL_LTR
),
911 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
912 NWidget(NWID_VERTICAL
),
913 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
915 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
916 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SW
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
919 NWidget(NWID_SPACER
), SetMinimalSize(2, 0),
920 NWidget(NWID_VERTICAL
),
921 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_NE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
923 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
924 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROD_DEPOT_SE
), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP
),
927 NWidget(NWID_SPACER
), SetMinimalSize(3, 0), SetFill(1, 0),
929 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
933 static const WindowDesc
_build_road_depot_desc(
935 WC_BUILD_DEPOT
, WC_BUILD_TOOLBAR
,
937 _nested_build_road_depot_widgets
, lengthof(_nested_build_road_depot_widgets
)
940 static void ShowRoadDepotPicker(Window
*parent
)
942 new BuildRoadDepotWindow(&_build_road_depot_desc
, parent
);
945 struct BuildRoadStationWindow
: public PickerWindowBase
{
946 BuildRoadStationWindow (const WindowDesc
*desc
, Window
*parent
, RoadStopType rs
) : PickerWindowBase(desc
, parent
)
948 this->CreateNestedTree();
950 /* Trams don't have non-drivethrough stations */
951 if (_cur_roadtype
== ROADTYPE_TRAM
&& _road_station_picker_orientation
< DIAGDIR_END
) {
952 _road_station_picker_orientation
= DIAGDIR_END
;
955 this->GetWidget
<NWidgetCore
>(WID_BROS_CAPTION
)->widget_data
= _road_type_infos
[_cur_roadtype
].picker_title
[rs
];
956 for (uint i
= (_cur_roadtype
== ROADTYPE_TRAM
? WID_BROS_STATION_X
: WID_BROS_STATION_NE
); i
< WID_BROS_LT_OFF
; i
++) {
957 this->GetWidget
<NWidgetCore
>(i
)->tool_tip
= _road_type_infos
[_cur_roadtype
].picker_tooltip
[rs
];
960 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
961 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
963 this->InitNested(TRANSPORT_ROAD
);
965 this->window_class
= (rs
== ROADSTOP_BUS
) ? WC_BUS_STATION
: WC_TRUCK_STATION
;
968 void OnDelete (void) FINAL_OVERRIDE
970 DeleteWindowById(WC_SELECT_STATION
, 0);
971 this->PickerWindowBase::OnDelete();
974 void OnPaint (BlitArea
*dpi
) OVERRIDE
976 this->DrawWidgets (dpi
);
978 int rad
= _settings_game
.station
.modified_catchment
? ((this->window_class
== WC_BUS_STATION
) ? CA_BUS
: CA_TRUCK
) : CA_UNMODIFIED
;
979 if (_settings_client
.gui
.station_show_coverage
) {
980 SetTileSelectBigSize(-rad
, -rad
, 2 * rad
, 2 * rad
);
982 SetTileSelectSize(1, 1);
985 /* 'Accepts' and 'Supplies' texts. */
986 StationCoverageType sct
= (this->window_class
== WC_BUS_STATION
) ? SCT_PASSENGERS_ONLY
: SCT_NON_PASSENGERS_ONLY
;
987 int top
= this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->pos_y
+ this->GetWidget
<NWidgetBase
>(WID_BROS_LT_ON
)->current_y
+ WD_PAR_VSEP_NORMAL
;
988 NWidgetBase
*back_nwi
= this->GetWidget
<NWidgetBase
>(WID_BROS_BACKGROUND
);
989 int right
= back_nwi
->pos_x
+ back_nwi
->current_x
;
990 int bottom
= back_nwi
->pos_y
+ back_nwi
->current_y
;
991 top
= DrawStationCoverageAreaText (dpi
, back_nwi
->pos_x
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, rad
, sct
);
992 /* Resize background if the window is too small.
993 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
994 * (This is the case, if making the window bigger moves the mouse into the window.) */
996 ResizeWindow(this, 0, top
- bottom
, false);
1000 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1002 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1004 size
->width
= ScaleGUITrad(64) + 2;
1005 size
->height
= ScaleGUITrad(48) + 2;
1008 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
1010 if (!IsInsideMM(widget
, WID_BROS_STATION_NE
, WID_BROS_STATION_Y
+ 1)) return;
1012 RoadStationPickerDrawSprite (dpi
, r
.left
+ 1 + ScaleGUITrad(31), r
.bottom
- ScaleGUITrad(31),
1013 this->window_class
== WC_BUS_STATION
,
1014 (widget
>= WID_BROS_STATION_X
) && (_cur_roadtype
== ROADTYPE_TRAM
),
1015 widget
- WID_BROS_STATION_NE
);
1018 virtual void OnClick(Point pt
, int widget
, int click_count
)
1021 case WID_BROS_STATION_NE
:
1022 case WID_BROS_STATION_SE
:
1023 case WID_BROS_STATION_SW
:
1024 case WID_BROS_STATION_NW
:
1025 case WID_BROS_STATION_X
:
1026 case WID_BROS_STATION_Y
:
1027 this->RaiseWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1028 _road_station_picker_orientation
= (DiagDirection
)(widget
- WID_BROS_STATION_NE
);
1029 this->LowerWidget(_road_station_picker_orientation
+ WID_BROS_STATION_NE
);
1030 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1032 DeleteWindowById(WC_SELECT_STATION
, 0);
1035 case WID_BROS_LT_OFF
:
1036 case WID_BROS_LT_ON
:
1037 this->RaiseWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1038 _settings_client
.gui
.station_show_coverage
= (widget
!= WID_BROS_LT_OFF
);
1039 this->LowerWidget(_settings_client
.gui
.station_show_coverage
+ WID_BROS_LT_OFF
);
1040 if (_settings_client
.sound
.click_beep
) SndPlayFx(SND_15_BEEP
);
1049 virtual void OnTick()
1051 CheckRedrawStationCoverage(this);
1055 /** Widget definition of the build road station window */
1056 static const NWidgetPart _nested_road_station_picker_widgets
[] = {
1057 NWidget(NWID_HORIZONTAL
),
1058 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1059 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1061 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1062 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1063 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1064 NWidget(NWID_SPACER
), SetFill(1, 0),
1065 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1066 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_NE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1067 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1068 NWidget(NWID_SPACER
), SetFill(1, 0),
1070 NWidget(NWID_SPACER
), SetMinimalSize(0, 2),
1071 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1072 NWidget(NWID_SPACER
), SetFill(1, 0),
1073 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SW
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1074 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_SE
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1075 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1076 NWidget(NWID_SPACER
), SetFill(1, 0),
1078 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1079 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1080 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1081 NWidget(NWID_SPACER
), SetFill(1, 0),
1083 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1084 NWidget(NWID_SPACER
), SetFill(1, 0),
1085 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1086 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1087 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1088 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1089 NWidget(NWID_SPACER
), SetFill(1, 0),
1091 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1095 static const WindowDesc
_road_station_picker_desc(
1097 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1099 _nested_road_station_picker_widgets
, lengthof(_nested_road_station_picker_widgets
)
1102 /** Widget definition of the build tram station window */
1103 static const NWidgetPart _nested_tram_station_picker_widgets
[] = {
1104 NWidget(NWID_HORIZONTAL
),
1105 NWidget(WWT_CLOSEBOX
, COLOUR_DARK_GREEN
),
1106 NWidget(WWT_CAPTION
, COLOUR_DARK_GREEN
, WID_BROS_CAPTION
),
1108 NWidget(WWT_PANEL
, COLOUR_DARK_GREEN
, WID_BROS_BACKGROUND
),
1109 NWidget(NWID_SPACER
), SetMinimalSize(0, 3),
1110 NWidget(NWID_HORIZONTAL
), SetPIP(0, 2, 0),
1111 NWidget(NWID_SPACER
), SetFill(1, 0),
1112 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_X
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1113 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_BROS_STATION_Y
), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1114 NWidget(NWID_SPACER
), SetFill(1, 0),
1116 NWidget(NWID_SPACER
), SetMinimalSize(0, 1),
1117 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1118 NWidget(WWT_LABEL
, COLOUR_DARK_GREEN
, WID_BROS_INFO
), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE
, STR_NULL
),
1119 NWidget(NWID_SPACER
), SetFill(1, 0),
1121 NWidget(NWID_HORIZONTAL
), SetPIP(2, 0, 2),
1122 NWidget(NWID_SPACER
), SetFill(1, 0),
1123 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_OFF
), SetMinimalSize(60, 12),
1124 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF
, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP
),
1125 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_BROS_LT_ON
), SetMinimalSize(60, 12),
1126 SetDataTip(STR_STATION_BUILD_COVERAGE_ON
, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP
),
1127 NWidget(NWID_SPACER
), SetFill(1, 0),
1129 NWidget(NWID_SPACER
), SetMinimalSize(0, 10), SetResize(0, 1),
1133 static const WindowDesc
_tram_station_picker_desc(
1135 WC_BUS_STATION
, WC_BUILD_TOOLBAR
,
1137 _nested_tram_station_picker_widgets
, lengthof(_nested_tram_station_picker_widgets
)
1140 static void ShowRVStationPicker(Window
*parent
, RoadStopType rs
)
1142 new BuildRoadStationWindow(_cur_roadtype
== ROADTYPE_ROAD
? &_road_station_picker_desc
: &_tram_station_picker_desc
, parent
, rs
);
1145 void InitializeRoadGui()
1147 _road_depot_orientation
= DIAGDIR_NW
;
1148 _road_station_picker_orientation
= DIAGDIR_NW
;