Translations update
[openttd/fttd.git] / src / road_gui.cpp
blob344723122d96318e19c11d4a2c96e345a363d7f3
1 /* $Id$ */
3 /*
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/>.
8 */
10 /** @file road_gui.cpp GUI for building roads. */
12 #include "stdafx.h"
13 #include "gui.h"
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"
19 #include "road_cmd.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"
28 #include "map/road.h"
29 #include "map/tunnel.h"
30 #include "map/bridge.h"
31 #include "tilehighlight_func.h"
32 #include "company_base.h"
33 #include "hotkeys.h"
34 #include "road_gui.h"
36 #include "widgets/road_widget.h"
38 #include "table/strings.h"
40 static void ShowRVStationPicker(Window *parent, RoadStopType rs);
41 static void ShowRoadDepotPicker(Window *parent);
43 static bool _remove_button_clicked;
44 static bool _one_way_button_clicked;
46 /**
47 * Define the values of the RoadFlags
48 * @see CmdBuildLongRoad
50 enum RoadFlags {
51 RF_NONE = 0x00,
52 RF_START_HALFROAD_Y = 0x01, // The start tile in Y-dir should have only a half road
53 RF_END_HALFROAD_Y = 0x02, // The end tile in Y-dir should have only a half road
54 RF_DIR_Y = 0x04, // The direction is Y-dir
55 RF_DIR_X = RF_NONE, // Dummy; Dir X is set when RF_DIR_Y is not set
56 RF_START_HALFROAD_X = 0x08, // The start tile in X-dir should have only a half road
57 RF_END_HALFROAD_X = 0x10, // The end tile in X-dir should have only a half road
59 DECLARE_ENUM_AS_BIT_SET(RoadFlags)
61 static RoadFlags _place_road_flag;
63 static RoadType _cur_roadtype;
65 static DiagDirection _road_depot_orientation;
66 static DiagDirection _road_station_picker_orientation;
68 void CcPlaySound1D(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
70 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, tile);
73 /**
74 * Callback to start placing a bridge.
75 * @param tile Start tile of the bridge.
77 static void PlaceRoad_Bridge(TileIndex tile, Window *w)
79 if (IsBridgeHeadTile(tile)) {
80 TileIndex other_tile = GetOtherBridgeEnd(tile);
81 Point pt = {0, 0};
82 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
83 } else {
84 VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_BUILD_BRIDGE);
88 /**
89 * Callback executed after a build road tunnel command has been called.
91 * @param result Whether the build succeeded.
92 * @param start_tile Starting tile of the tunnel.
93 * @param p1 bit 0-3 railtype or roadtypes
94 * bit 8-9 transport type
95 * @param p2 unused
97 void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
99 if (result.Succeeded()) {
100 if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_2, start_tile);
101 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
103 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
104 ConnectRoadToStructure(start_tile, start_direction);
106 TileIndex end_tile = GetOtherTunnelEnd(start_tile);
107 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
108 ConnectRoadToStructure(end_tile, end_direction);
109 } else {
110 SetRedErrorSquare(_build_tunnel_endtile);
114 /** Structure holding information per roadtype for several functions */
115 struct RoadTypeInfo {
116 StringID err_build_road; ///< Building a normal piece of road
117 StringID err_remove_road; ///< Removing a normal piece of road
118 StringID err_depot; ///< Building a depot
119 StringID err_build_station[2]; ///< Building a bus or truck station
120 StringID err_remove_station[2]; ///< Removing of a bus or truck station
122 StringID picker_title[2]; ///< Title for the station picker for bus or truck stations
123 StringID picker_tooltip[2]; ///< Tooltip for the station picker for bus or truck stations
125 SpriteID cursor_nesw; ///< Cursor for building NE and SW bits
126 SpriteID cursor_nwse; ///< Cursor for building NW and SE bits
127 SpriteID cursor_autoroad; ///< Cursor for building autoroad
130 /** What errors/cursors must be shown for several types of roads */
131 static const RoadTypeInfo _road_type_infos[] = {
133 STR_ERROR_CAN_T_BUILD_ROAD_HERE,
134 STR_ERROR_CAN_T_REMOVE_ROAD_FROM,
135 STR_ERROR_CAN_T_BUILD_ROAD_DEPOT,
136 { STR_ERROR_CAN_T_BUILD_BUS_STATION, STR_ERROR_CAN_T_BUILD_TRUCK_STATION },
137 { STR_ERROR_CAN_T_REMOVE_BUS_STATION, STR_ERROR_CAN_T_REMOVE_TRUCK_STATION },
138 { STR_STATION_BUILD_BUS_ORIENTATION, STR_STATION_BUILD_TRUCK_ORIENTATION },
139 { STR_STATION_BUILD_BUS_ORIENTATION_TOOLTIP, STR_STATION_BUILD_TRUCK_ORIENTATION_TOOLTIP },
141 SPR_CURSOR_ROAD_NESW,
142 SPR_CURSOR_ROAD_NWSE,
143 SPR_CURSOR_AUTOROAD,
146 STR_ERROR_CAN_T_BUILD_TRAMWAY_HERE,
147 STR_ERROR_CAN_T_REMOVE_TRAMWAY_FROM,
148 STR_ERROR_CAN_T_BUILD_TRAM_DEPOT,
149 { STR_ERROR_CAN_T_BUILD_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_BUILD_CARGO_TRAM_STATION },
150 { STR_ERROR_CAN_T_REMOVE_PASSENGER_TRAM_STATION, STR_ERROR_CAN_T_REMOVE_CARGO_TRAM_STATION },
151 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION },
152 { STR_STATION_BUILD_PASSENGER_TRAM_ORIENTATION_TOOLTIP, STR_STATION_BUILD_CARGO_TRAM_ORIENTATION_TOOLTIP },
154 SPR_CURSOR_TRAMWAY_NESW,
155 SPR_CURSOR_TRAMWAY_NWSE,
156 SPR_CURSOR_AUTOTRAM,
161 * If required, connects a new structure to an existing road or tram by building the missing roadbit.
162 * @param tile Tile containing the structure to connect.
163 * @param direction Direction to check.
165 void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
167 tile += TileOffsByDiagDir(direction);
168 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
169 if (IsNormalRoadTile(tile) && GetRoadBits(tile, _cur_roadtype) != ROAD_NONE) {
170 DoCommandP(tile, _cur_roadtype << 4 | DiagDirToRoadBits(ReverseDiagDir(direction)), 0, CMD_BUILD_ROAD);
174 void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
176 if (result.Failed()) return;
178 DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
179 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, tile);
180 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
181 ConnectRoadToStructure(tile, dir);
185 * Command callback for building road stops.
186 * @param result Result of the build road stop command.
187 * @param tile Start tile.
188 * @param p1 bit 0..7: Width of the road stop.
189 * bit 8..15: Length of the road stop.
190 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
191 * bit 1: 0 For normal stops, 1 for drive-through.
192 * bit 2..3: The roadtypes.
193 * bit 5: Allow stations directly adjacent to other stations.
194 * bit 6..7: Entrance direction (#DiagDirection).
195 * bit 16..31: Station ID to join (NEW_STATION if build new one).
196 * @see CmdBuildRoadStop
198 void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
200 if (result.Failed()) return;
202 DiagDirection dir = (DiagDirection)GB(p2, 6, 2);
203 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT, tile);
204 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
205 TileArea roadstop_area(tile, GB(p1, 0, 8), GB(p1, 8, 8));
206 TILE_AREA_LOOP(cur_tile, roadstop_area) {
207 ConnectRoadToStructure(cur_tile, dir);
208 /* For a drive-through road stop build connecting road for other entrance. */
209 if (HasBit(p2, 1)) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
214 * Place a new road stop.
215 * @param start_tile First tile of the area.
216 * @param end_tile Last tile of the area.
217 * @param p2 bit 0: 0 For bus stops, 1 for truck stops.
218 * bit 2..3: The roadtypes.
219 * bit 5: Allow stations directly adjacent to other stations.
220 * @param cmd Command to use.
221 * @see CcRoadStop()
223 static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, uint32 cmd)
225 uint8 ddir = _road_station_picker_orientation;
226 SB(p2, 16, 16, INVALID_STATION); // no station to join
228 if (ddir >= DIAGDIR_END) {
229 SetBit(p2, 1); // It's a drive-through stop.
230 ddir -= DIAGDIR_END; // Adjust picker result to actual direction.
232 p2 |= ddir << 6; // Set the DiagDirecion into p2 bits 6 and 7.
234 TileArea ta(start_tile, end_tile);
235 CommandContainer cmdcont = { ta.tile, ta.w | ta.h << 8, p2, cmd, CcRoadStop, "" };
236 ShowSelectStationIfNeeded(cmdcont, ta);
240 * Callback for placing a bus station.
241 * @param tile Position to place the station.
243 static void PlaceRoad_BusStation(TileIndex tile)
245 if (_remove_button_clicked) {
246 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_BUSSTOP);
247 } else {
248 if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
249 VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
250 } else {
251 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_BUSSTOP);
253 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
258 * Callback for placing a truck station.
259 * @param tile Position to place the station.
261 static void PlaceRoad_TruckStation(TileIndex tile)
263 if (_remove_button_clicked) {
264 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_REMOVE_TRUCKSTOP);
265 } else {
266 if (_road_station_picker_orientation < DIAGDIR_END) { // Not a drive-through stop.
267 VpStartPlaceSizing(tile, (DiagDirToAxis(_road_station_picker_orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_TRUCKSTOP);
268 } else {
269 VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED, DDSP_BUILD_TRUCKSTOP);
271 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
275 typedef void OnButtonClick(Window *w);
278 * Toggles state of the Remove button of Build road toolbar
279 * @param w window the button belongs to
281 static void ToggleRoadButton_Remove(Window *w)
283 w->ToggleWidgetLoweredState(WID_ROT_REMOVE);
284 w->SetWidgetDirty(WID_ROT_REMOVE);
285 _remove_button_clicked = w->IsWidgetLowered(WID_ROT_REMOVE);
286 SetSelectionRed(_remove_button_clicked);
290 * Updates the Remove button because of Ctrl state change
291 * @param w window the button belongs to
292 * @return true iff the remove button was changed
294 static bool RoadToolbar_CtrlChanged(Window *w)
296 if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
298 /* allow ctrl to switch remove mode only for these widgets */
299 for (uint i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) {
300 if (w->IsWidgetLowered(i)) {
301 ToggleRoadButton_Remove(w);
302 return true;
306 return false;
309 /** Road toolbar window handler. */
310 struct BuildRoadToolbarWindow : Window {
311 int last_started_action; ///< Last started user action.
313 BuildRoadToolbarWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
315 this->InitNested(window_number);
316 this->SetWidgetsDisabledState(true,
317 WID_ROT_REMOVE,
318 WID_ROT_ONE_WAY,
319 WIDGET_LIST_END);
321 this->OnInvalidateData();
322 this->last_started_action = WIDGET_LIST_END;
324 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
327 ~BuildRoadToolbarWindow()
329 if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
333 * Some data on this window has become invalid.
334 * @param data Information about the changed data.
335 * @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.
337 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
339 if (!gui_scope) return;
340 this->SetWidgetsDisabledState(!CanBuildVehicleInfrastructure(VEH_ROAD),
341 WID_ROT_DEPOT,
342 WID_ROT_BUS_STATION,
343 WID_ROT_TRUCK_STATION,
344 WIDGET_LIST_END);
348 * Update the remove button lowered state of the road toolbar
350 * @param clicked_widget The widget which the client clicked just now
352 void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
354 /* The remove and the one way button state is driven
355 * by the other buttons so they don't act on themselves.
356 * Both are only valid if they are able to apply as options. */
357 switch (clicked_widget) {
358 case WID_ROT_REMOVE:
359 this->RaiseWidget(WID_ROT_ONE_WAY);
360 this->SetWidgetDirty(WID_ROT_ONE_WAY);
361 break;
363 case WID_ROT_ONE_WAY:
364 this->RaiseWidget(WID_ROT_REMOVE);
365 this->SetWidgetDirty(WID_ROT_REMOVE);
366 break;
368 case WID_ROT_BUS_STATION:
369 case WID_ROT_TRUCK_STATION:
370 this->DisableWidget(WID_ROT_ONE_WAY);
371 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
372 break;
374 case WID_ROT_ROAD_X:
375 case WID_ROT_ROAD_Y:
376 case WID_ROT_AUTOROAD:
377 this->SetWidgetsDisabledState(!this->IsWidgetLowered(clicked_widget),
378 WID_ROT_REMOVE,
379 WID_ROT_ONE_WAY,
380 WIDGET_LIST_END);
381 break;
383 default:
384 /* When any other buttons than road/station, raise and
385 * disable the removal button */
386 this->SetWidgetsDisabledState(true,
387 WID_ROT_REMOVE,
388 WID_ROT_ONE_WAY,
389 WIDGET_LIST_END);
390 this->SetWidgetsLoweredState(false,
391 WID_ROT_REMOVE,
392 WID_ROT_ONE_WAY,
393 WIDGET_LIST_END);
394 break;
398 virtual void OnClick(Point pt, int widget, int click_count)
400 _remove_button_clicked = false;
401 _one_way_button_clicked = false;
402 switch (widget) {
403 case WID_ROT_ROAD_X:
404 HandlePlacePushButton(this, WID_ROT_ROAD_X, _road_type_infos[_cur_roadtype].cursor_nwse, HT_RECT);
405 this->last_started_action = widget;
406 break;
408 case WID_ROT_ROAD_Y:
409 HandlePlacePushButton(this, WID_ROT_ROAD_Y, _road_type_infos[_cur_roadtype].cursor_nesw, HT_RECT);
410 this->last_started_action = widget;
411 break;
413 case WID_ROT_AUTOROAD:
414 HandlePlacePushButton(this, WID_ROT_AUTOROAD, _road_type_infos[_cur_roadtype].cursor_autoroad, HT_RECT);
415 this->last_started_action = widget;
416 break;
418 case WID_ROT_DEMOLISH:
419 HandlePlacePushButton(this, WID_ROT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
420 this->last_started_action = widget;
421 break;
423 case WID_ROT_DEPOT:
424 if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
425 if (HandlePlacePushButton(this, WID_ROT_DEPOT, SPR_CURSOR_ROAD_DEPOT, HT_RECT)) {
426 ShowRoadDepotPicker(this);
427 this->last_started_action = widget;
429 break;
431 case WID_ROT_BUS_STATION:
432 if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
433 if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) {
434 ShowRVStationPicker(this, ROADSTOP_BUS);
435 this->last_started_action = widget;
437 break;
439 case WID_ROT_TRUCK_STATION:
440 if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
441 if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) {
442 ShowRVStationPicker(this, ROADSTOP_TRUCK);
443 this->last_started_action = widget;
445 break;
447 case WID_ROT_ONE_WAY:
448 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
449 this->SetDirty();
450 this->ToggleWidgetLoweredState(WID_ROT_ONE_WAY);
451 SetSelectionRed(false);
452 break;
454 case WID_ROT_BUILD_BRIDGE:
455 HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
456 this->last_started_action = widget;
457 break;
459 case WID_ROT_BUILD_TUNNEL:
460 HandlePlacePushButton(this, WID_ROT_BUILD_TUNNEL, SPR_CURSOR_ROAD_TUNNEL, HT_SPECIAL);
461 this->last_started_action = widget;
462 break;
464 case WID_ROT_REMOVE:
465 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
467 DeleteWindowById(WC_SELECT_STATION, 0);
468 ToggleRoadButton_Remove(this);
469 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
470 break;
472 default: NOT_REACHED();
474 this->UpdateOptionWidgetStatus((RoadToolbarWidgets)widget);
475 if (_ctrl_pressed) RoadToolbar_CtrlChanged(this);
478 virtual EventState OnHotkey(int hotkey)
480 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
481 return Window::OnHotkey(hotkey);
484 virtual void OnPlaceObject(Point pt, TileIndex tile)
486 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
487 _one_way_button_clicked = this->IsWidgetLowered(WID_ROT_ONE_WAY);
488 switch (this->last_started_action) {
489 case WID_ROT_ROAD_X:
490 _place_road_flag = RF_DIR_X;
491 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
492 VpStartPlaceSizing(tile, VPM_FIX_Y, DDSP_PLACE_ROAD_X_DIR);
493 break;
495 case WID_ROT_ROAD_Y:
496 _place_road_flag = RF_DIR_Y;
497 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
498 VpStartPlaceSizing(tile, VPM_FIX_X, DDSP_PLACE_ROAD_Y_DIR);
499 break;
501 case WID_ROT_AUTOROAD:
502 _place_road_flag = RF_NONE;
503 if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
504 if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
505 VpStartPlaceSizing(tile, VPM_X_OR_Y, DDSP_PLACE_AUTOROAD);
506 break;
508 case WID_ROT_DEMOLISH:
509 PlaceProc_DemolishArea(tile);
510 break;
512 case WID_ROT_DEPOT:
513 DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0,
514 CMD_BUILD_ROAD_DEPOT | CMD_MSG(_road_type_infos[_cur_roadtype].err_depot), CcRoadDepot);
515 break;
517 case WID_ROT_BUS_STATION:
518 PlaceRoad_BusStation(tile);
519 break;
521 case WID_ROT_TRUCK_STATION:
522 PlaceRoad_TruckStation(tile);
523 break;
525 case WID_ROT_BUILD_BRIDGE:
526 PlaceRoad_Bridge(tile, this);
527 break;
529 case WID_ROT_BUILD_TUNNEL:
530 DoCommandP(tile, RoadTypeToRoadTypes(_cur_roadtype) | (TRANSPORT_ROAD << 8), 0,
531 CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel);
532 break;
534 default: NOT_REACHED();
538 virtual void OnPlaceObjectAbort()
540 this->RaiseButtons();
541 this->SetWidgetsDisabledState(true,
542 WID_ROT_REMOVE,
543 WID_ROT_ONE_WAY,
544 WIDGET_LIST_END);
545 this->SetWidgetDirty(WID_ROT_REMOVE);
546 this->SetWidgetDirty(WID_ROT_ONE_WAY);
548 DeleteWindowById(WC_BUS_STATION, TRANSPORT_ROAD);
549 DeleteWindowById(WC_TRUCK_STATION, TRANSPORT_ROAD);
550 DeleteWindowById(WC_BUILD_DEPOT, TRANSPORT_ROAD);
551 DeleteWindowById(WC_SELECT_STATION, 0);
552 DeleteWindowByClass(WC_BUILD_BRIDGE);
555 virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
557 /* Here we update the end tile flags
558 * of the road placement actions.
559 * At first we reset the end halfroad
560 * bits and if needed we set them again. */
561 switch (select_proc) {
562 case DDSP_PLACE_ROAD_X_DIR:
563 _place_road_flag &= ~RF_END_HALFROAD_X;
564 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
565 break;
567 case DDSP_PLACE_ROAD_Y_DIR:
568 _place_road_flag &= ~RF_END_HALFROAD_Y;
569 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
570 break;
572 case DDSP_PLACE_AUTOROAD:
573 _place_road_flag &= ~(RF_END_HALFROAD_Y | RF_END_HALFROAD_X);
574 if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
575 if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
577 /* For autoroad we need to update the
578 * direction of the road */
579 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
580 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
581 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
582 /* Set dir = X */
583 _place_road_flag &= ~RF_DIR_Y;
584 } else {
585 /* Set dir = Y */
586 _place_road_flag |= RF_DIR_Y;
589 break;
591 default:
592 break;
595 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
598 virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
600 if (pt.x != -1) {
601 switch (select_proc) {
602 default: NOT_REACHED();
603 case DDSP_BUILD_BRIDGE:
604 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
605 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, RoadTypeToRoadTypes(_cur_roadtype));
606 break;
608 case DDSP_DEMOLISH_AREA:
609 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
610 break;
612 case DDSP_PLACE_ROAD_X_DIR:
613 case DDSP_PLACE_ROAD_Y_DIR:
614 case DDSP_PLACE_AUTOROAD:
615 /* Flag description:
616 * Use the first three bits (0x07) if dir == Y
617 * else use the last 2 bits (X dir has
618 * not the 3rd bit set) */
619 _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
621 DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 5),
622 _remove_button_clicked ?
623 CMD_REMOVE_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_road) :
624 CMD_BUILD_LONG_ROAD | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_road), CcPlaySound1D);
625 break;
627 case DDSP_BUILD_BUSSTOP:
628 PlaceRoadStop(start_tile, end_tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_BUS, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_BUS]));
629 break;
631 case DDSP_BUILD_TRUCKSTOP:
632 PlaceRoadStop(start_tile, end_tile, (_ctrl_pressed << 5) | RoadTypeToRoadTypes(_cur_roadtype) << 2 | ROADSTOP_TRUCK, CMD_BUILD_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_build_station[ROADSTOP_TRUCK]));
633 break;
635 case DDSP_REMOVE_BUSSTOP: {
636 TileArea ta(start_tile, end_tile);
637 DoCommandP(ta.tile, ta.w | ta.h << 8, ROADSTOP_BUS, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_BUS]), CcPlaySound1D);
638 break;
641 case DDSP_REMOVE_TRUCKSTOP: {
642 TileArea ta(start_tile, end_tile);
643 DoCommandP(ta.tile, ta.w | ta.h << 8, ROADSTOP_TRUCK, CMD_REMOVE_ROAD_STOP | CMD_MSG(_road_type_infos[_cur_roadtype].err_remove_station[ROADSTOP_TRUCK]), CcPlaySound1D);
644 break;
650 virtual void OnPlacePresize(Point pt, TileIndex tile)
652 DoCommand(tile, RoadTypeToRoadTypes(_cur_roadtype) | (TRANSPORT_ROAD << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
653 VpSetPresizeRange(tile, _build_tunnel_endtile == 0 ? tile : _build_tunnel_endtile);
656 virtual EventState OnCTRLStateChange()
658 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
659 return ES_NOT_HANDLED;
662 static HotkeyList hotkeys;
666 * Handler for global hotkeys of the BuildRoadToolbarWindow.
667 * @param hotkey Hotkey
668 * @return ES_HANDLED if hotkey was accepted.
670 static EventState RoadToolbarGlobalHotkeys(int hotkey)
672 Window *w = NULL;
673 switch (_game_mode) {
674 case GM_NORMAL: {
675 extern RoadType _last_built_roadtype;
676 w = ShowBuildRoadToolbar(_last_built_roadtype);
677 break;
680 case GM_EDITOR:
681 w = ShowBuildRoadScenToolbar();
682 break;
684 default:
685 break;
688 if (w == NULL) return ES_NOT_HANDLED;
689 return w->OnHotkey(hotkey);
692 static Hotkey roadtoolbar_hotkeys[] = {
693 Hotkey('1', "build_x", WID_ROT_ROAD_X),
694 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
695 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
696 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
697 Hotkey('5', "depot", WID_ROT_DEPOT),
698 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
699 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
700 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
701 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
702 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
703 Hotkey('R', "remove", WID_ROT_REMOVE),
704 HOTKEY_LIST_END
706 HotkeyList BuildRoadToolbarWindow::hotkeys("roadtoolbar", roadtoolbar_hotkeys, RoadToolbarGlobalHotkeys);
709 static const NWidgetPart _nested_build_road_widgets[] = {
710 NWidget(NWID_HORIZONTAL),
711 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
712 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
713 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
714 EndContainer(),
715 NWidget(NWID_HORIZONTAL),
716 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
717 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
718 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
719 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
720 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
721 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
722 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
723 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
724 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
725 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
726 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
727 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
728 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
729 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
730 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
731 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
732 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
733 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
734 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
735 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
736 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
737 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
738 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
739 EndContainer(),
742 static WindowDesc _build_road_desc(
743 WDP_ALIGN_TOOLBAR, "toolbar_road", 0, 0,
744 WC_BUILD_TOOLBAR, WC_NONE,
745 WDF_CONSTRUCTION,
746 _nested_build_road_widgets, lengthof(_nested_build_road_widgets),
747 &BuildRoadToolbarWindow::hotkeys
750 static const NWidgetPart _nested_build_tramway_widgets[] = {
751 NWidget(NWID_HORIZONTAL),
752 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
753 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_TRAM_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
754 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
755 EndContainer(),
756 NWidget(NWID_HORIZONTAL),
757 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
758 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
759 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
760 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
761 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
762 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
763 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
764 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
765 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
766 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
767 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
768 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
769 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
770 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
771 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
772 NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY), SetMinimalSize(0, 0),
773 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
774 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
775 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
776 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
777 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
778 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
779 EndContainer(),
782 static WindowDesc _build_tramway_desc(
783 WDP_ALIGN_TOOLBAR, "toolbar_tramway", 0, 0,
784 WC_BUILD_TOOLBAR, WC_NONE,
785 WDF_CONSTRUCTION,
786 _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets),
787 &BuildRoadToolbarWindow::hotkeys
791 * Open the build road toolbar window
793 * If the terraform toolbar is linked to the toolbar, that window is also opened.
795 * @return newly opened road toolbar, or NULL if the toolbar could not be opened.
797 Window *ShowBuildRoadToolbar(RoadType roadtype)
799 if (!Company::IsValidID(_local_company)) return NULL;
800 _cur_roadtype = roadtype;
802 DeleteWindowByClass(WC_BUILD_TOOLBAR);
803 return AllocateWindowDescFront<BuildRoadToolbarWindow>(roadtype == ROADTYPE_ROAD ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
806 static const NWidgetPart _nested_build_road_scen_widgets[] = {
807 NWidget(NWID_HORIZONTAL),
808 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
809 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_ROAD_TOOLBAR_ROAD_CONSTRUCTION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
810 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
811 EndContainer(),
812 NWidget(NWID_HORIZONTAL),
813 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
814 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
815 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
816 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
817 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
818 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
819 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
820 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
821 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
822 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
823 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
824 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
825 SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
826 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
827 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
828 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
829 SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
830 EndContainer(),
833 static WindowDesc _build_road_scen_desc(
834 WDP_AUTO, "toolbar_road_scen", 0, 0,
835 WC_SCEN_BUILD_TOOLBAR, WC_NONE,
836 WDF_CONSTRUCTION,
837 _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets),
838 &BuildRoadToolbarWindow::hotkeys
842 * Show the road building toolbar in the scenario editor.
843 * @return The just opened toolbar.
845 Window *ShowBuildRoadScenToolbar()
847 _cur_roadtype = ROADTYPE_ROAD;
848 return AllocateWindowDescFront<BuildRoadToolbarWindow>(&_build_road_scen_desc, TRANSPORT_ROAD);
851 struct BuildRoadDepotWindow : public PickerWindowBase {
852 BuildRoadDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
854 this->CreateNestedTree();
856 this->LowerWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
857 if ( _cur_roadtype == ROADTYPE_TRAM) {
858 this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
859 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;
862 this->FinishInitNested(TRANSPORT_ROAD);
865 virtual void DrawWidget(const Rect &r, int widget) const
867 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
869 DrawRoadDepotSprite(r.left - 1, r.top, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
872 virtual void OnClick(Point pt, int widget, int click_count)
874 switch (widget) {
875 case WID_BROD_DEPOT_NW:
876 case WID_BROD_DEPOT_NE:
877 case WID_BROD_DEPOT_SW:
878 case WID_BROD_DEPOT_SE:
879 this->RaiseWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
880 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
881 this->LowerWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
882 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
883 this->SetDirty();
884 break;
886 default:
887 break;
892 static const NWidgetPart _nested_build_road_depot_widgets[] = {
893 NWidget(NWID_HORIZONTAL),
894 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
895 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
896 EndContainer(),
897 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
898 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
899 NWidget(NWID_HORIZONTAL_LTR),
900 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
901 NWidget(NWID_VERTICAL),
902 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
903 EndContainer(),
904 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
905 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
906 EndContainer(),
907 EndContainer(),
908 NWidget(NWID_SPACER), SetMinimalSize(2, 0),
909 NWidget(NWID_VERTICAL),
910 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
911 EndContainer(),
912 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
913 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
914 EndContainer(),
915 EndContainer(),
916 NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
917 EndContainer(),
918 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
919 EndContainer(),
922 static WindowDesc _build_road_depot_desc(
923 WDP_AUTO, NULL, 0, 0,
924 WC_BUILD_DEPOT, WC_BUILD_TOOLBAR,
925 WDF_CONSTRUCTION,
926 _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets)
929 static void ShowRoadDepotPicker(Window *parent)
931 new BuildRoadDepotWindow(&_build_road_depot_desc, parent);
934 struct BuildRoadStationWindow : public PickerWindowBase {
935 BuildRoadStationWindow(WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(desc, parent)
937 this->CreateNestedTree();
939 /* Trams don't have non-drivethrough stations */
940 if (_cur_roadtype == ROADTYPE_TRAM && _road_station_picker_orientation < DIAGDIR_END) {
941 _road_station_picker_orientation = DIAGDIR_END;
943 this->SetWidgetsDisabledState(_cur_roadtype == ROADTYPE_TRAM,
944 WID_BROS_STATION_NE,
945 WID_BROS_STATION_SE,
946 WID_BROS_STATION_SW,
947 WID_BROS_STATION_NW,
948 WIDGET_LIST_END);
950 this->GetWidget<NWidgetCore>(WID_BROS_CAPTION)->widget_data = _road_type_infos[_cur_roadtype].picker_title[rs];
951 for (uint i = WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) this->GetWidget<NWidgetCore>(i)->tool_tip = _road_type_infos[_cur_roadtype].picker_tooltip[rs];
953 this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
954 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
956 this->FinishInitNested(TRANSPORT_ROAD);
958 this->window_class = (rs == ROADSTOP_BUS) ? WC_BUS_STATION : WC_TRUCK_STATION;
961 virtual ~BuildRoadStationWindow()
963 DeleteWindowById(WC_SELECT_STATION, 0);
966 virtual void OnPaint()
968 this->DrawWidgets();
970 int rad = _settings_game.station.modified_catchment ? ((this->window_class == WC_BUS_STATION) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
971 if (_settings_client.gui.station_show_coverage) {
972 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
973 } else {
974 SetTileSelectSize(1, 1);
977 /* 'Accepts' and 'Supplies' texts. */
978 StationCoverageType sct = (this->window_class == WC_BUS_STATION) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
979 int top = this->GetWidget<NWidgetBase>(WID_BROS_LT_ON)->pos_y + this->GetWidget<NWidgetBase>(WID_BROS_LT_ON)->current_y + WD_PAR_VSEP_NORMAL;
980 NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(WID_BROS_BACKGROUND);
981 int right = back_nwi->pos_x + back_nwi->current_x;
982 int bottom = back_nwi->pos_y + back_nwi->current_y;
983 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, false) + WD_PAR_VSEP_NORMAL;
984 top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, true) + WD_PAR_VSEP_NORMAL;
985 /* Resize background if the window is too small.
986 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
987 * (This is the case, if making the window bigger moves the mouse into the window.) */
988 if (top > bottom) {
989 ResizeWindow(this, 0, top - bottom);
993 virtual void DrawWidget(const Rect &r, int widget) const
995 if (!IsInsideMM(widget, WID_BROS_STATION_NE, WID_BROS_STATION_Y + 1)) return;
997 StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
998 StationPickerDrawSprite(r.left + TILE_PIXELS, r.bottom - TILE_PIXELS, st, INVALID_RAILTYPE, widget < WID_BROS_STATION_X ? ROADTYPE_ROAD : _cur_roadtype, widget - WID_BROS_STATION_NE);
1001 virtual void OnClick(Point pt, int widget, int click_count)
1003 switch (widget) {
1004 case WID_BROS_STATION_NE:
1005 case WID_BROS_STATION_SE:
1006 case WID_BROS_STATION_SW:
1007 case WID_BROS_STATION_NW:
1008 case WID_BROS_STATION_X:
1009 case WID_BROS_STATION_Y:
1010 this->RaiseWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
1011 _road_station_picker_orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1012 this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
1013 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1014 this->SetDirty();
1015 DeleteWindowById(WC_SELECT_STATION, 0);
1016 break;
1018 case WID_BROS_LT_OFF:
1019 case WID_BROS_LT_ON:
1020 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1021 _settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
1022 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1023 if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1024 this->SetDirty();
1025 break;
1027 default:
1028 break;
1032 virtual void OnTick()
1034 CheckRedrawStationCoverage(this);
1038 /** Widget definition of the build road station window */
1039 static const NWidgetPart _nested_rv_station_picker_widgets[] = {
1040 NWidget(NWID_HORIZONTAL),
1041 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1042 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1043 EndContainer(),
1044 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BROS_BACKGROUND),
1045 NWidget(NWID_SPACER), SetMinimalSize(0, 3),
1046 NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
1047 NWidget(NWID_SPACER), SetFill(1, 0),
1048 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NW), SetMinimalSize(66, 50), EndContainer(),
1049 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NE), SetMinimalSize(66, 50), EndContainer(),
1050 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetMinimalSize(66, 50), EndContainer(),
1051 NWidget(NWID_SPACER), SetFill(1, 0),
1052 EndContainer(),
1053 NWidget(NWID_SPACER), SetMinimalSize(0, 2),
1054 NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
1055 NWidget(NWID_SPACER), SetFill(1, 0),
1056 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SW), SetMinimalSize(66, 50), EndContainer(),
1057 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SE), SetMinimalSize(66, 50), EndContainer(),
1058 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetMinimalSize(66, 50), EndContainer(),
1059 NWidget(NWID_SPACER), SetFill(1, 0),
1060 EndContainer(),
1061 NWidget(NWID_SPACER), SetMinimalSize(0, 1),
1062 NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1063 NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BROS_INFO), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
1064 NWidget(NWID_SPACER), SetFill(1, 0),
1065 EndContainer(),
1066 NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1067 NWidget(NWID_SPACER), SetFill(1, 0),
1068 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1069 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1070 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1071 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1072 NWidget(NWID_SPACER), SetFill(1, 0),
1073 EndContainer(),
1074 NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1),
1075 EndContainer(),
1078 static WindowDesc _rv_station_picker_desc(
1079 WDP_AUTO, NULL, 0, 0,
1080 WC_BUS_STATION, WC_BUILD_TOOLBAR,
1081 WDF_CONSTRUCTION,
1082 _nested_rv_station_picker_widgets, lengthof(_nested_rv_station_picker_widgets)
1085 static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1087 new BuildRoadStationWindow(&_rv_station_picker_desc, parent, rs);
1090 void InitializeRoadGui()
1092 _road_depot_orientation = DIAGDIR_NW;
1093 _road_station_picker_orientation = DIAGDIR_NW;