OpenTTD Source  1.10.0
road_gui.cpp
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #include "stdafx.h"
11 #include "gui.h"
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"
17 #include "road_cmd.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"
27 #include "hotkeys.h"
28 #include "road_gui.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"
34 
35 #include "widgets/road_widget.h"
36 
37 #include "table/strings.h"
38 
39 #include "safeguards.h"
40 
41 static void ShowRVStationPicker(Window *parent, RoadStopType rs);
42 static void ShowRoadDepotPicker(Window *parent);
43 
44 static bool _remove_button_clicked;
45 static bool _one_way_button_clicked;
46 
51 enum RoadFlags {
52  RF_NONE = 0x00,
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
59 };
61 
62 static RoadFlags _place_road_flag;
63 
64 static RoadType _cur_roadtype;
65 
66 static DiagDirection _road_depot_orientation;
67 static DiagDirection _road_station_picker_orientation;
68 
69 void CcPlaySound_SPLAT_OTHER(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
70 {
71  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
72 }
73 
79 {
80  if (IsBridgeTile(tile)) {
81  TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
82  Point pt = {0, 0};
83  w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
84  } else {
86  }
87 }
88 
99 void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
100 {
101  if (result.Succeeded()) {
102  if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, start_tile);
104 
105  DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
106  ConnectRoadToStructure(start_tile, start_direction);
107 
108  TileIndex end_tile = GetOtherTunnelBridgeEnd(start_tile);
109  DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
110  ConnectRoadToStructure(end_tile, end_direction);
111  } else {
113  }
114 }
115 
122 {
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);
128  }
129  }
130 }
131 
132 void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
133 {
134  if (result.Failed()) return;
135 
136  DiagDirection dir = (DiagDirection)GB(p1, 0, 2);
140 }
141 
158 void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
159 {
160  if (result.Failed()) return;
161 
162  DiagDirection dir = (DiagDirection)GB(p2, 3, 2);
163  if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
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));
170  }
171 }
172 
183 static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, uint32 cmd)
184 {
185  uint8 ddir = _road_station_picker_orientation;
186  SB(p2, 16, 16, INVALID_STATION); // no station to join
187 
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.
191  }
192  p2 |= ddir << 3; // Set the DiagDirecion into p2 bits 3 and 4.
193 
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);
197 }
198 
204 {
207  } else {
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);
210  } else {
212  }
213  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
214  }
215 }
216 
222 {
225  } else {
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);
228  } else {
230  }
231  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
232  }
233 }
234 
235 typedef void OnButtonClick(Window *w);
236 
242 {
246  SetSelectionRed(_remove_button_clicked);
247 }
248 
255 {
256  if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
257 
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)) {
262  return true;
263  }
264  }
265 
266  return false;
267 }
268 
272  const RoadTypeInfo *rti;
274 
276  {
277  this->Initialize(_cur_roadtype);
278  this->InitNested(window_number);
279  this->SetupRoadToolbar();
281 
282  if (RoadTypeIsRoad(this->roadtype)) {
284  }
285 
286  this->OnInvalidateData();
287  this->last_started_action = WIDGET_LIST_END;
288 
290  }
291 
293  {
294  if (_game_mode == GM_NORMAL && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true);
296  }
297 
303  void OnInvalidateData(int data = 0, bool gui_scope = true) override
304  {
305  if (!gui_scope) return;
306 
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,
314  if (!can_build) {
318  }
319  }
320 
321  void Initialize(RoadType roadtype)
322  {
323  assert(roadtype < ROADTYPE_END);
324  this->roadtype = roadtype;
325  this->rti = GetRoadTypeInfo(this->roadtype);
326  }
327 
333  {
334  this->GetWidget<NWidgetCore>(WID_ROT_ROAD_X)->widget_data = rti->gui_sprites.build_x_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;
339  }
340  this->GetWidget<NWidgetCore>(WID_ROT_CONVERT_ROAD)->widget_data = rti->gui_sprites.convert_road;
342  }
343 
348  void ModifyRoadType(RoadType roadtype)
349  {
350  this->Initialize(roadtype);
351  this->SetupRoadToolbar();
352  this->ReInit();
353  }
354 
355  void SetStringParameters(int widget) const override
356  {
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);
362  } else {
363  SetDParam(0, this->rti->strings.toolbar_caption);
364  }
365  }
366  }
367 
374  {
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) {
379  case WID_ROT_REMOVE:
380  if (RoadTypeIsRoad(this->roadtype)) {
383  }
384 
385  break;
386 
387  case WID_ROT_ONE_WAY:
390  break;
391 
392  case WID_ROT_BUS_STATION:
394  if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
395  this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
396  break;
397 
398  case WID_ROT_ROAD_X:
399  case WID_ROT_ROAD_Y:
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));
404  }
405  break;
406 
407  default:
408  /* When any other buttons than road/station, raise and
409  * disable the removal button */
412 
413  if (RoadTypeIsRoad(this->roadtype)) {
416  }
417 
418  break;
419  }
420  }
421 
422  void OnClick(Point pt, int widget, int click_count) override
423  {
424  _remove_button_clicked = false;
425  _one_way_button_clicked = false;
426  switch (widget) {
427  case WID_ROT_ROAD_X:
429  this->last_started_action = widget;
430  break;
431 
432  case WID_ROT_ROAD_Y:
434  this->last_started_action = widget;
435  break;
436 
437  case WID_ROT_AUTOROAD:
439  this->last_started_action = widget;
440  break;
441 
442  case WID_ROT_DEMOLISH:
444  this->last_started_action = widget;
445  break;
446 
447  case WID_ROT_DEPOT:
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;
452  }
453  break;
454 
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;
460  }
461  break;
462 
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;
468  }
469  break;
470 
471  case WID_ROT_ONE_WAY:
472  if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
473  this->SetDirty();
475  SetSelectionRed(false);
476  break;
477 
479  HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
480  this->last_started_action = widget;
481  break;
482 
485  this->last_started_action = widget;
486  break;
487 
488  case WID_ROT_REMOVE:
489  if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
490 
493  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
494  break;
495 
498  this->last_started_action = widget;
499  break;
500 
501  default: NOT_REACHED();
502  }
505  }
506 
507  EventState OnHotkey(int hotkey) override
508  {
509  MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
510  return Window::OnHotkey(hotkey);
511  }
512 
513  void OnPlaceObject(Point pt, TileIndex tile) override
514  {
516  _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
517  switch (this->last_started_action) {
518  case WID_ROT_ROAD_X:
519  _place_road_flag = RF_DIR_X;
520  if (_tile_fract_coords.x >= 8) _place_road_flag |= RF_START_HALFROAD_X;
522  break;
523 
524  case WID_ROT_ROAD_Y:
525  _place_road_flag = RF_DIR_Y;
526  if (_tile_fract_coords.y >= 8) _place_road_flag |= RF_START_HALFROAD_Y;
528  break;
529 
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;
535  break;
536 
537  case WID_ROT_DEMOLISH:
539  break;
540 
541  case WID_ROT_DEPOT:
542  DoCommandP(tile, _cur_roadtype << 2 | _road_depot_orientation, 0,
543  CMD_BUILD_ROAD_DEPOT | CMD_MSG(this->rti->strings.err_depot), CcRoadDepot);
544  break;
545 
546  case WID_ROT_BUS_STATION:
547  PlaceRoad_BusStation(tile);
548  break;
549 
552  break;
553 
555  PlaceRoad_Bridge(tile, this);
556  break;
557 
559  DoCommandP(tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0,
560  CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRoadTunnel);
561  break;
562 
565  break;
566 
567  default: NOT_REACHED();
568  }
569  }
570 
571  void OnPlaceObjectAbort() override
572  {
573  if (_game_mode != GM_EDITOR && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true);
574 
575  this->RaiseButtons();
578 
579  if (RoadTypeIsRoad(this->roadtype)) {
582  }
583 
589  }
590 
591  void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
592  {
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) {
599  _place_road_flag &= ~RF_END_HALFROAD_X;
600  if (pt.x & 8) _place_road_flag |= RF_END_HALFROAD_X;
601  break;
602 
604  _place_road_flag &= ~RF_END_HALFROAD_Y;
605  if (pt.y & 8) _place_road_flag |= RF_END_HALFROAD_Y;
606  break;
607 
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;
612 
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) ))) {
618  /* Set dir = X */
619  _place_road_flag &= ~RF_DIR_Y;
620  } else {
621  /* Set dir = Y */
622  _place_road_flag |= RF_DIR_Y;
623  }
624 
625  break;
626 
627  default:
628  break;
629  }
630 
631  VpSelectTilesWithMethod(pt.x, pt.y, select_method);
632  }
633 
634  void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
635  {
636  if (pt.x != -1) {
637  switch (select_proc) {
638  default: NOT_REACHED();
639  case DDSP_BUILD_BRIDGE:
641  ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, _cur_roadtype);
642  break;
643 
644  case DDSP_DEMOLISH_AREA:
645  GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
646  break;
647 
650  case DDSP_PLACE_AUTOROAD:
651  /* Flag description:
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) */
655 
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
658  * flags */
659  _place_road_flag = (RoadFlags)((_place_road_flag & RF_DIR_Y) ? (_place_road_flag & 0x07) : (_place_road_flag >> 3));
660 
661  DoCommandP(start_tile, end_tile, _place_road_flag | (_cur_roadtype << 3) | (_one_way_button_clicked << 10),
664  CMD_BUILD_LONG_ROAD | CMD_MSG(this->rti->strings.err_build_road), CcPlaySound_SPLAT_OTHER);
665  break;
666 
667  case DDSP_BUILD_BUSSTOP:
668  case DDSP_REMOVE_BUSSTOP:
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);
673  } else {
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]));
675  }
676  }
677  break;
678 
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);
685  } else {
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]));
687  }
688  }
689  break;
690 
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);
693  break;
694  }
695  }
696  }
697 
698  void OnPlacePresize(Point pt, TileIndex tile) override
699  {
700  DoCommand(tile, _cur_roadtype | (TRANSPORT_ROAD << 8), 0, DC_AUTO, CMD_BUILD_TUNNEL);
702  }
703 
705  {
706  if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
707  return ES_NOT_HANDLED;
708  }
709 
710  static HotkeyList road_hotkeys;
711  static HotkeyList tram_hotkeys;
712 };
713 
720 static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
721 {
722  Window* w = nullptr;
723  switch (_game_mode) {
724  case GM_NORMAL:
726  w = ShowBuildRoadToolbar(last_build);
727  break;
728 
729  case GM_EDITOR:
730  if ((GetRoadTypes(true) & ((rtt == RTT_ROAD) ? ~_roadtypes_type : _roadtypes_type)) == ROADTYPES_NONE) return ES_NOT_HANDLED;
731  w = ShowBuildRoadScenToolbar(last_build);
732  break;
733 
734  default:
735  break;
736  }
737 
738  if (w == nullptr) return ES_NOT_HANDLED;
739  return w->OnHotkey(hotkey);
740 }
741 
742 static EventState RoadToolbarGlobalHotkeys(int hotkey)
743 {
744  extern RoadType _last_built_roadtype;
745  return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_roadtype, RTT_ROAD);
746 }
747 
748 static EventState TramToolbarGlobalHotkeys(int hotkey)
749 {
750  extern RoadType _last_built_tramtype;
751  return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_tramtype, RTT_TRAM);
752 }
753 
754 static Hotkey roadtoolbar_hotkeys[] = {
755  Hotkey('1', "build_x", WID_ROT_ROAD_X),
756  Hotkey('2', "build_y", WID_ROT_ROAD_Y),
757  Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
758  Hotkey('4', "demolish", WID_ROT_DEMOLISH),
759  Hotkey('5', "depot", WID_ROT_DEPOT),
760  Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
761  Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
762  Hotkey('8', "oneway", WID_ROT_ONE_WAY),
763  Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
764  Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
765  Hotkey('R', "remove", WID_ROT_REMOVE),
766  Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
767  HOTKEY_LIST_END
768 };
769 HotkeyList BuildRoadToolbarWindow::road_hotkeys("roadtoolbar", roadtoolbar_hotkeys, RoadToolbarGlobalHotkeys);
770 
771 static Hotkey tramtoolbar_hotkeys[] = {
772  Hotkey('1', "build_x", WID_ROT_ROAD_X),
773  Hotkey('2', "build_y", WID_ROT_ROAD_Y),
774  Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
775  Hotkey('4', "demolish", WID_ROT_DEMOLISH),
776  Hotkey('5', "depot", WID_ROT_DEPOT),
777  Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
778  Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
779  Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
780  Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
781  Hotkey('R', "remove", WID_ROT_REMOVE),
782  Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
783  HOTKEY_LIST_END
784 };
785 HotkeyList BuildRoadToolbarWindow::tram_hotkeys("tramtoolbar", tramtoolbar_hotkeys, TramToolbarGlobalHotkeys);
786 
787 
788 static const NWidgetPart _nested_build_road_widgets[] = {
790  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
791  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
792  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
793  EndContainer(),
795  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
796  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
797  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
798  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
799  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
800  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
801  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
802  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
803  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
804  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
805  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
806  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
807  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
808  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
809  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
810  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
811  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
812  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
813  SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
814  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
815  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
816  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
817  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
818  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
819  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
820  EndContainer(),
821 };
822 
823 static WindowDesc _build_road_desc(
824  WDP_ALIGN_TOOLBAR, "toolbar_road", 0, 0,
827  _nested_build_road_widgets, lengthof(_nested_build_road_widgets),
828  &BuildRoadToolbarWindow::road_hotkeys
829 );
830 
831 static const NWidgetPart _nested_build_tramway_widgets[] = {
833  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
834  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
835  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
836  EndContainer(),
838  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
839  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
840  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
841  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
842  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
843  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
844  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
845  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
846  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
847  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
848  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
849  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
850  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
851  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
852  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
853  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
854  SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
855  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
856  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
857  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
858  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
859  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
860  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
861  EndContainer(),
862 };
863 
864 static WindowDesc _build_tramway_desc(
865  WDP_ALIGN_TOOLBAR, "toolbar_tramway", 0, 0,
868  _nested_build_tramway_widgets, lengthof(_nested_build_tramway_widgets),
869  &BuildRoadToolbarWindow::tram_hotkeys
870 );
871 
880 {
881  if (!Company::IsValidID(_local_company)) return nullptr;
882  if (!ValParamRoadType(roadtype)) return nullptr;
883 
885  _cur_roadtype = roadtype;
886 
887  return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? &_build_road_desc : &_build_tramway_desc, TRANSPORT_ROAD);
888 }
889 
890 static const NWidgetPart _nested_build_road_scen_widgets[] = {
892  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
893  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
894  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
895  EndContainer(),
897  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
898  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
899  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
900  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
901  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
902  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
903  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
904  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
905  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
906  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
907  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
908  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
909  SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
910  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
911  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
912  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
913  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
914  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
915  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
916  EndContainer(),
917 };
918 
919 static WindowDesc _build_road_scen_desc(
920  WDP_AUTO, "toolbar_road_scen", 0, 0,
923  _nested_build_road_scen_widgets, lengthof(_nested_build_road_scen_widgets),
924  &BuildRoadToolbarWindow::road_hotkeys
925 );
926 
927 static const NWidgetPart _nested_build_tramway_scen_widgets[] = {
929  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
930  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
931  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
932  EndContainer(),
934  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
935  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
936  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
937  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
938  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
939  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
940  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
941  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
942  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
943  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
944  SetFill(0, 1), SetMinimalSize(43, 22), SetDataTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
945  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
946  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
947  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
948  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
949  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
950  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
951  EndContainer(),
952 };
953 
954 static WindowDesc _build_tramway_scen_desc(
955  WDP_AUTO, "toolbar_tram_scen", 0, 0,
958  _nested_build_tramway_scen_widgets, lengthof(_nested_build_tramway_scen_widgets),
959  &BuildRoadToolbarWindow::tram_hotkeys
960 );
961 
967 {
969  _cur_roadtype = roadtype;
970 
971  return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? &_build_road_scen_desc : &_build_tramway_scen_desc, TRANSPORT_ROAD);
972 }
973 
976  {
977  this->CreateNestedTree();
978 
979  this->LowerWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
980  if (RoadTypeIsTram(_cur_roadtype)) {
981  this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION;
982  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;
983  }
984 
986  }
987 
988  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
989  {
990  if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
991 
992  size->width = ScaleGUITrad(64) + 2;
993  size->height = ScaleGUITrad(48) + 2;
994  }
995 
996  void DrawWidget(const Rect &r, int widget) const override
997  {
998  if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
999 
1000  DrawRoadDepotSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
1001  }
1002 
1003  void OnClick(Point pt, int widget, int click_count) override
1004  {
1005  switch (widget) {
1006  case WID_BROD_DEPOT_NW:
1007  case WID_BROD_DEPOT_NE:
1008  case WID_BROD_DEPOT_SW:
1009  case WID_BROD_DEPOT_SE:
1010  this->RaiseWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
1011  _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1012  this->LowerWidget(_road_depot_orientation + WID_BROD_DEPOT_NE);
1013  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1014  this->SetDirty();
1015  break;
1016 
1017  default:
1018  break;
1019  }
1020  }
1021 };
1022 
1023 static const NWidgetPart _nested_build_road_depot_widgets[] = {
1025  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1026  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetDataTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1027  EndContainer(),
1028  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1031  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1033  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1034  EndContainer(),
1036  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1037  EndContainer(),
1038  EndContainer(),
1041  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1042  EndContainer(),
1044  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1045  EndContainer(),
1046  EndContainer(),
1047  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1048  EndContainer(),
1050  EndContainer(),
1051 };
1052 
1053 static WindowDesc _build_road_depot_desc(
1054  WDP_AUTO, nullptr, 0, 0,
1057  _nested_build_road_depot_widgets, lengthof(_nested_build_road_depot_widgets)
1058 );
1059 
1060 static void ShowRoadDepotPicker(Window *parent)
1061 {
1062  new BuildRoadDepotWindow(&_build_road_depot_desc, parent);
1063 }
1064 
1066  BuildRoadStationWindow(WindowDesc *desc, Window *parent, RoadStopType rs) : PickerWindowBase(desc, parent)
1067  {
1068  this->CreateNestedTree();
1069 
1070  /* Trams don't have non-drivethrough stations */
1071  if (RoadTypeIsTram(_cur_roadtype) && _road_station_picker_orientation < DIAGDIR_END) {
1072  _road_station_picker_orientation = DIAGDIR_END;
1073  }
1074  const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1075  this->GetWidget<NWidgetCore>(WID_BROS_CAPTION)->widget_data = rti->strings.picker_title[rs];
1076 
1077  for (uint i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1078  this->GetWidget<NWidgetCore>(i)->tool_tip = rti->strings.picker_tooltip[rs];
1079  }
1080 
1081  this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
1082  this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1083 
1085 
1087  }
1088 
1089  virtual ~BuildRoadStationWindow()
1090  {
1092  }
1093 
1094  void OnPaint() override
1095  {
1096  this->DrawWidgets();
1097 
1100  SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1101  } else {
1102  SetTileSelectSize(1, 1);
1103  }
1104 
1105  /* 'Accepts' and 'Supplies' texts. */
1107  int top = this->GetWidget<NWidgetBase>(WID_BROS_LT_ON)->pos_y + this->GetWidget<NWidgetBase>(WID_BROS_LT_ON)->current_y + WD_PAR_VSEP_NORMAL;
1108  NWidgetBase *back_nwi = this->GetWidget<NWidgetBase>(WID_BROS_BACKGROUND);
1109  int right = back_nwi->pos_x + back_nwi->current_x;
1110  int bottom = back_nwi->pos_y + back_nwi->current_y;
1111  top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, false) + WD_PAR_VSEP_NORMAL;
1112  top = DrawStationCoverageAreaText(back_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, sct, rad, true) + WD_PAR_VSEP_NORMAL;
1113  /* Resize background if the window is too small.
1114  * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1115  * (This is the case, if making the window bigger moves the mouse into the window.) */
1116  if (top > bottom) {
1117  ResizeWindow(this, 0, top - bottom, false);
1118  }
1119  }
1120 
1121  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1122  {
1123  if (!IsInsideMM(widget, WID_BROS_STATION_NE, WID_BROS_STATION_Y + 1)) return;
1124 
1125  size->width = ScaleGUITrad(64) + 2;
1126  size->height = ScaleGUITrad(48) + 2;
1127  }
1128 
1129  void DrawWidget(const Rect &r, int widget) const override
1130  {
1131  if (!IsInsideMM(widget, WID_BROS_STATION_NE, WID_BROS_STATION_Y + 1)) return;
1132 
1133  StationType st = (this->window_class == WC_BUS_STATION) ? STATION_BUS : STATION_TRUCK;
1134  StationPickerDrawSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1135  }
1136 
1137  void OnClick(Point pt, int widget, int click_count) override
1138  {
1139  switch (widget) {
1140  case WID_BROS_STATION_NE:
1141  case WID_BROS_STATION_SE:
1142  case WID_BROS_STATION_SW:
1143  case WID_BROS_STATION_NW:
1144  case WID_BROS_STATION_X:
1145  case WID_BROS_STATION_Y:
1146  this->RaiseWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
1147  _road_station_picker_orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1148  this->LowerWidget(_road_station_picker_orientation + WID_BROS_STATION_NE);
1149  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1150  this->SetDirty();
1152  break;
1153 
1154  case WID_BROS_LT_OFF:
1155  case WID_BROS_LT_ON:
1159  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1160  this->SetDirty();
1161  break;
1162 
1163  default:
1164  break;
1165  }
1166  }
1167 
1168  void OnRealtimeTick(uint delta_ms) override
1169  {
1171  }
1172 };
1173 
1177  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1178  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1179  EndContainer(),
1180  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BROS_BACKGROUND),
1182  NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
1183  NWidget(NWID_SPACER), SetFill(1, 0),
1184  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NW), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1185  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NE), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1186  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1187  NWidget(NWID_SPACER), SetFill(1, 0),
1188  EndContainer(),
1190  NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
1191  NWidget(NWID_SPACER), SetFill(1, 0),
1192  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SW), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1193  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SE), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1194  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1195  NWidget(NWID_SPACER), SetFill(1, 0),
1196  EndContainer(),
1198  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1199  NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BROS_INFO), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
1200  NWidget(NWID_SPACER), SetFill(1, 0),
1201  EndContainer(),
1202  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1203  NWidget(NWID_SPACER), SetFill(1, 0),
1204  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1205  SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1206  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1207  SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1208  NWidget(NWID_SPACER), SetFill(1, 0),
1209  EndContainer(),
1210  NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1),
1211  EndContainer(),
1212 };
1213 
1214 static WindowDesc _road_station_picker_desc(
1215  WDP_AUTO, nullptr, 0, 0,
1218  _nested_road_station_picker_widgets, lengthof(_nested_road_station_picker_widgets)
1219 );
1220 
1224  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1225  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1226  EndContainer(),
1227  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BROS_BACKGROUND),
1229  NWidget(NWID_HORIZONTAL), SetPIP(0, 2, 0),
1230  NWidget(NWID_SPACER), SetFill(1, 0),
1231  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1232  NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetMinimalSize(66, 50), SetFill(0, 0), EndContainer(),
1233  NWidget(NWID_SPACER), SetFill(1, 0),
1234  EndContainer(),
1236  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1237  NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BROS_INFO), SetMinimalSize(140, 14), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL),
1238  NWidget(NWID_SPACER), SetFill(1, 0),
1239  EndContainer(),
1240  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1241  NWidget(NWID_SPACER), SetFill(1, 0),
1242  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1243  SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1244  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1245  SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1246  NWidget(NWID_SPACER), SetFill(1, 0),
1247  EndContainer(),
1248  NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1),
1249  EndContainer(),
1250 };
1251 
1252 static WindowDesc _tram_station_picker_desc(
1253  WDP_AUTO, nullptr, 0, 0,
1256  _nested_tram_station_picker_widgets, lengthof(_nested_tram_station_picker_widgets)
1257 );
1258 
1259 static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1260 {
1261  new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? &_road_station_picker_desc : &_tram_station_picker_desc, parent, rs);
1262 }
1263 
1264 void InitializeRoadGui()
1265 {
1266  _road_depot_orientation = DIAGDIR_NW;
1267  _road_station_picker_orientation = DIAGDIR_NW;
1268 }
1269 
1274 {
1276  if (w != nullptr) w->ModifyRoadType(_cur_roadtype);
1277 }
1278 
1279 DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1280 {
1281  RoadTypes used_roadtypes;
1282  RoadTypes avail_roadtypes;
1283 
1284  const Company *c = Company::Get(_local_company);
1285 
1286  /* Find the used roadtypes. */
1287  if (for_replacement) {
1288  avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1289  used_roadtypes = GetRoadTypes(false);
1290  } else {
1291  avail_roadtypes = c->avail_roadtypes;
1292  used_roadtypes = GetRoadTypes(true);
1293  }
1294 
1295  /* Filter listed road types */
1296  if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= _roadtypes_type;
1297  if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~_roadtypes_type;
1298 
1299  DropDownList list;
1300 
1301  if (all_option) {
1302  list.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE, false));
1303  }
1304 
1305  Dimension d = { 0, 0 };
1306  RoadType rt;
1307  /* Get largest icon size, to ensure text is aligned on each menu item. */
1308  if (!for_replacement) {
1310  if (!HasBit(used_roadtypes, rt)) continue;
1311  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1313  }
1314  }
1315 
1317  /* If it's not used ever, don't show it to the user. */
1318  if (!HasBit(used_roadtypes, rt)) continue;
1319 
1320  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1321 
1323  if (for_replacement) {
1324  item = new DropDownListParamStringItem(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt));
1325  } else {
1326  StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
1327  DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt));
1328  iconitem->SetDimension(d);
1329  item = iconitem;
1330  }
1331  item->SetParam(0, rti->strings.menu_text);
1332  item->SetParam(1, rti->max_speed / 2);
1333  list.emplace_back(item);
1334  }
1335 
1336  if (list.size() == 0) {
1337  /* Empty dropdowns are not allowed */
1338  list.emplace_back(new DropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1339  }
1340 
1341  return list;
1342 }
1343 
1344 DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1345 {
1346  RoadTypes avail_roadtypes = GetRoadTypes(false);
1347  avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, _date);
1348  RoadTypes used_roadtypes = GetRoadTypes(true);
1349 
1350  /* Filter listed road types */
1351  if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= _roadtypes_type;
1352  if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~_roadtypes_type;
1353 
1354  DropDownList list;
1355 
1356  /* If it's not used ever, don't show it to the user. */
1357  Dimension d = { 0, 0 };
1358  RoadType rt;
1360  if (!HasBit(used_roadtypes, rt)) continue;
1361  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1363  }
1365  if (!HasBit(used_roadtypes, rt)) continue;
1366 
1367  const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1368 
1369  StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
1370  DropDownListIconItem *item = new DropDownListIconItem(rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt));
1371  item->SetDimension(d);
1372  item->SetParam(0, rti->strings.menu_text);
1373  item->SetParam(1, rti->max_speed);
1374  list.emplace_back(item);
1375  }
1376 
1377  if (list.size() == 0) {
1378  /* Empty dropdowns are not allowed */
1379  list.emplace_back(new DropDownListStringItem(STR_NONE, -1, true));
1380  }
1381 
1382  return list;
1383 }
EventState
State of handling an event.
Definition: window_type.h:717
Functions related to OTTD&#39;s strings.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
don&#39;t allow building on structures
Definition: command_type.h:347
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
Definition: road_gui.cpp:966
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:80
int last_started_action
Last started user action.
Definition: road_gui.cpp:273
Definition of stuff that is very close to a company, like the company struct itself.
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition: road_gui.cpp:78
Caption of the window.
Definition: road_widget.h:16
uint32 widget_data
Data of the widget.
Definition: widget_type.h:303
Select station (when joining stations); Window numbers:
Definition: window_type.h:235
A standard stop for trucks.
Definition: station_type.h:46
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
Definition: settings_type.h:94
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:610
Demolish.
Definition: road_widget.h:20
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
Point pos
Location, in tile "units", of the northern tile of the selected area.
Terminal station with NE entry.
Definition: road_widget.h:46
area of land of limited size
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:57
Window * parent
Parent window.
Definition: window_gui.h:337
All data for a single hotkey.
Definition: hotkeys.h:22
High level window description.
Definition: window_gui.h:166
Road stop placement (trucks)
Build depot.
Definition: road_widget.h:21
build a complete road (not a "half" one)
Definition: command_type.h:199
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1485
CursorID autoroad
Cursor for autorail tool.
Definition: road.h:93
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:442
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit...
Definition: road_gui.cpp:121
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
bool station_show_coverage
whether to highlight coverage area
CursorID depot
Cursor for building a depot.
Definition: road.h:94
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
Scenario build toolbar; Window numbers:
Definition: window_type.h:73
SpriteID build_depot
button for building depots
Definition: road.h:85
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Hotkey related functions.
Functions related to dates.
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition: road_type.h:36
Terminal station with NW entry.
Definition: road_widget.h:49
Centered label.
Definition: widget_type.h:55
Northwest.
void ShowSelectStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Contains enums and function declarations connected with stations GUI.
remove a complete road (not a "half" one)
Definition: command_type.h:200
#define FOR_ALL_SORTED_ROADTYPES(var)
Loop header for iterating over roadtypes, sorted by sortorder.
Definition: road.h:312
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Road stop removal (trucks)
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
Used for iterations.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Draw only passenger class cargoes.
Definition: station_gui.h:20
Horizontal container.
Definition: widget_type.h:73
Functions/types related to the road GUIs.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1133
The passed event is not handled.
Definition: window_type.h:719
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2423
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
drag only in X axis
Definition: viewport_type.h:98
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:76
Turn on area highlight.
Definition: road_widget.h:53
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition: road.h:101
Autorail.
Definition: road_widget.h:19
Drag only in X axis with limited size.
Flag for invalid railtype.
Definition: rail_type.h:34
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition: road.cpp:188
Used for iterations.
Definition: road_type.h:26
Point size
Size, in tile "units", of the white/red selection area.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: road_gui.cpp:355
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Definition: road_gui.cpp:879
drag only in Y axis
Definition: viewport_type.h:99
Drag only in Y axis with limited size.
Functions related to vehicles.
Turn off area highlight.
Definition: road_widget.h:52
Drive-through station in y-direction.
Definition: road_widget.h:51
SpriteID build_x_road
button for building single rail in X direction
Definition: road.h:82
SpriteID build_tunnel
button for building a tunnel
Definition: road.h:86
A standard stop for buses.
Definition: station_type.h:45
int top
y position of top edge of the window
Definition: window_gui.h:318
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Definition: road_cmd.cpp:1780
byte station_spread
amount a station may spread
Build depot; Window numbers:
Definition: window_type.h:410
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:463
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: road_gui.cpp:422
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: road_gui.cpp:303
Tindex index
Index of this pool item.
Definition: pool_type.hpp:227
flag for invalid roadtype
Definition: road_type.h:27
Close box (at top-left of a window)
Definition: widget_type.h:67
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
Definition: viewport.cpp:2648
Build bridge.
Definition: road_widget.h:25
build a "half" road
Definition: command_type.h:201
Road stop removal (buses)
Caption of the window.
Definition: road_widget.h:44
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
Build road in x-direction.
Definition: road_widget.h:17
const RoadTypeInfo * rti
Information about current road type.
Definition: road_gui.cpp:272
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:402
Station acceptance info.
Definition: road_widget.h:54
bool persistent_buildingtools
keep the building tools active after usage
Common return value for all commands.
Definition: command_type.h:23
Catchment for bus stops with "modified catchment" enabled.
Definition: station_type.h:77
RoadType
The different roadtypes we support.
Definition: road_type.h:22
StringID err_convert_road
Converting a road type.
Definition: road.h:112
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
Common string list item.
Definition: dropdown_type.h:39
uint16 w
The width of the area.
Definition: tilearea_type.h:18
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1831
StationSettings station
settings related to station management
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition: road_gui.cpp:373
RoadStopType
Types of RoadStops.
Definition: station_type.h:44
RoadToolbarWidgets
Widgets of the BuildRoadToolbarWindow class.
Definition: road_widget.h:14
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Functions, definitions and such used only by the GUI.
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
Definition: road_gui.cpp:241
Terminal station with SE entry.
Definition: road_widget.h:47
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Functions related to (drawing on) viewports.
StringID replace_text
Text used in the autoreplace GUI.
Definition: road.h:104
Data structure for an opened window.
Definition: window_gui.h:276
Depot with NE entry.
Definition: road_widget.h:35
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
Road placement (X axis)
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1847
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:264
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1860
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: road_gui.cpp:571
static const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition: road.h:224
static RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition: road_func.h:96
Build truck station.
Definition: road_widget.h:23
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition: road.cpp:142
Invisible widget that takes some space.
Definition: widget_type.h:77
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition: road_gui.cpp:704
static const NWidgetPart _nested_road_station_picker_widgets[]
Widget definition of the build road station window.
Definition: road_gui.cpp:1175
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
Definition: station_gui.cpp:54
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:445
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition: road.h:111
static RoadBits GetRoadBits(TileIndex t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition: road_map.h:127
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
Road toolbar window handler.
Definition: road_gui.cpp:270
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
List item with icon and string.
Definition: dropdown_type.h:81
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition: road.h:115
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, Date date)
Add the road types that are to be introduced at the given date.
Definition: road.cpp:155
SoundSettings sound
sound effect settings
Header file for things common for tunnels and bridges.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2405
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition: road.h:114
Depot with SE entry.
Definition: road_widget.h:36
void OnPlacePresize(Point pt, TileIndex tile) override
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition: road_gui.cpp:698
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:173
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:96
void InitializeRoadGUI()
I really don&#39;t know why rail_gui.cpp has this too, shouldn&#39;t be included in the other one...
Definition: road_gui.cpp:1273
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:573
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:477
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
build a tunnel
Definition: command_type.h:188
drag in X or Y direction
Definition: viewport_type.h:97
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: road_gui.cpp:1137
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
StationCoverageType
Types of cargo to display for station coverage.
Definition: station_gui.h:19
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
Definition: hotkeys.h:40
Geometry functions.
rectangle (stations, depots, ...)
Depot with SW entry.
Definition: road_widget.h:37
Simple depressed panel.
Definition: widget_type.h:48
Road stop placement (buses)
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: road_gui.cpp:996
Build one-way road.
Definition: road_widget.h:24
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: road_gui.cpp:988
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:421
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition: road_gui.cpp:591
void ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition: road_gui.cpp:348
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition: road.h:102
No road-part is build.
Definition: road_type.h:51
Represents the covered area of e.g.
Definition: tilearea_type.h:16
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: road_gui.cpp:1129
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build road tunnel command has been called.
Definition: road_gui.cpp:99
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3454
GUI stuff related to terraforming.
void SetupRoadToolbar()
Configures the road toolbar for roadtype given.
Definition: road_gui.cpp:332
uint16 max_speed
Maximum speed for vehicles travelling on this road type.
Definition: road.h:139
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1938
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Baseclass for nested widgets.
Definition: widget_type.h:124
StringID err_remove_road
Removing a normal piece of road.
Definition: road.h:108
struct RoadTypeInfo::@42 strings
Strings associated with the rail type.
Functions related to stations.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:536
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition: viewport.cpp:2605
Catchment for truck stops with "modified catchment" enabled.
Definition: station_type.h:78
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:82
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte road_rail_type)
Prepare the data for the build a bridge window.
Definition: bridge_gui.cpp:361
Build bridge; Window numbers:
Definition: window_type.h:382
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: road_gui.cpp:507
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Bridge placement.
struct RoadTypeInfo::@40 gui_sprites
struct containing the sprites for the road GUI.
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition: road_gui.cpp:634
Also allow &#39;diagonal rectangles&#39;. Only usable in combination with HT_RECT or HT_POINT.
Functions related to sound.
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
build a road depot
Definition: command_type.h:202
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
bool Failed() const
Did this command fail?
Definition: command_type.h:159
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition: viewport.cpp:3078
Road placement (auto)
RoadType roadtype
Road type to build.
Definition: road_gui.cpp:271
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:20
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1754
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: road_gui.cpp:513
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
Build toolbar; Window numbers:
Definition: window_type.h:66
Road related functions.
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
Types related to the road widgets.
CursorID road_nwse
Cursor for building rail in Y direction.
Definition: road.h:92
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
The X axis.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
StringID err_depot
Building a depot.
Definition: road.h:109
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Definition: road_gui.cpp:720
Functions related to companies.
Convert road.
Definition: road_widget.h:28
build a road stop
Definition: command_type.h:197
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition: map_func.h:194
static bool _remove_button_clicked
Flag whether &#39;remove&#39; toggle-button is currently enabled.
Definition: rail_gui.cpp:45
StationType
Station types.
Definition: station_type.h:32
Base class for engines.
Build road in y-direction.
Definition: road_widget.h:18
area of land in X and Y directions
static bool IsNormalRoadTile(TileIndex t)
Return whether a tile is a normal road tile.
Definition: road_map.h:73
GUISettings gui
settings related to the GUI
Align toward the toolbar.
Definition: window_gui.h:156
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
static void PlaceRoad_BusStation(TileIndex tile)
Callback for placing a bus station.
Definition: road_gui.cpp:203
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:98
Draw all non-passenger class cargoes.
Definition: station_gui.h:21
CursorID road_swne
Cursor for building rail in X direction.
Definition: road.h:91
bool modified_catchment
different-size catchment areas
Build bus station.
Definition: road_widget.h:22
Vertical container.
Definition: widget_type.h:75
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:121
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: road_gui.cpp:1003
Build truck station; Window numbers:
Definition: window_type.h:402
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
StringID err_build_road
Building a normal piece of road.
Definition: road.h:107
Functions related to zooming.
Drive-through station in x-direction.
Definition: road_widget.h:50
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
Transport by road vehicle.
bool confirm
Play sound effect on successful constructions or other actions.
SpriteID build_y_road
button for building single rail in Y direction
Definition: road.h:83
Non-water non-rail construction.
Definition: sound_type.h:68
Functions related to commands.
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:908
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
CursorID tunnel
Cursor for building a tunnel.
Definition: road.h:95
special mode used for highlighting while dragging (and for tunnels/docks)
Functions that have tunnels and bridges in common.
Terminal station with SW entry.
Definition: road_widget.h:48
Build tunnel.
Definition: road_widget.h:26
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
Road placement (Y axis)
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
Remove road.
Definition: road_widget.h:27
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
Definition: road_gui.cpp:221
Northeast, upper right on your monitor.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:370
Build bus station; Window numbers:
Definition: window_type.h:396
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
WindowClass window_class
Window class.
Definition: window_gui.h:311
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3353
Specification of a rectangle with absolute coordinates of all edges.
The passed event is handled.
Definition: window_type.h:718
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Background of the window.
Definition: road_widget.h:45
Find a place automatically.
Definition: window_gui.h:154
static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, uint32 p2, uint32 cmd)
Place a new road stop.
Definition: road_gui.cpp:183
(Toggle) Button with image
Definition: widget_type.h:50
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: road_gui.cpp:1168
String list item with parameters.
Definition: dropdown_type.h:56
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: road_gui.cpp:1121
GUI functions that shouldn&#39;t be here.
SpriteID auto_road
button for the autoroad construction
Definition: road.h:84
struct RoadTypeInfo::@41 cursor
Cursors associated with the road type.
SpriteID convert_road
button for converting road types
Definition: road.h:87
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition: road.cpp:216
Date _date
Current date in days (day counter)
Definition: date.cpp:27
StringID err_build_station[2]
Building a bus or truck station.
Definition: road.h:110
uint16 h
The height of the area.
Definition: tilearea_type.h:19
static bool RoadToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition: road_gui.cpp:254
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building road stops.
Definition: road_gui.cpp:158
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2145
RoadFlags
Define the values of the RoadFlags.
Definition: road_gui.cpp:51
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
Dimensions (a width and height) of a rectangle in 2D.
void OnPaint() override
The window must be repainted.
Definition: road_gui.cpp:1094
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
Depot with NW entry.
Definition: road_widget.h:38
remove a road stop
Definition: command_type.h:198
convert a road type
Definition: command_type.h:203
Road vehicle type.
Definition: vehicle_type.h:25
Horizontal container that doesn&#39;t change the order of the widgets for RTL languages.
Definition: widget_type.h:74
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
Base class for windows opened from a toolbar.
Definition: window_gui.h:851
static const NWidgetPart _nested_tram_station_picker_widgets[]
Widget definition of the build tram station window.
Definition: road_gui.cpp:1222
No roadtypes.
Definition: road_type.h:37
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
The user has dragged over the map when the tile highlight mode has been set.
Definition: window_gui.h:784
(Toggle) Button with text
Definition: widget_type.h:53
Road conversion.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:282
Caption of the window.
Definition: road_widget.h:34