OpenTTD
rail_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 "waypoint_func.h"
18 #include "newgrf_station.h"
19 #include "company_base.h"
20 #include "strings_func.h"
21 #include "window_func.h"
22 #include "date_func.h"
23 #include "sound_func.h"
24 #include "company_func.h"
25 #include "widgets/dropdown_type.h"
26 #include "tunnelbridge.h"
27 #include "tilehighlight_func.h"
28 #include "spritecache.h"
29 #include "core/geometry_func.hpp"
30 #include "hotkeys.h"
31 #include "engine_base.h"
32 #include "vehicle_func.h"
33 #include "zoom_func.h"
34 #include "rail_gui.h"
35 
36 #include "station_map.h"
37 #include "tunnelbridge_map.h"
38 
39 #include "widgets/rail_widget.h"
40 
41 #include "safeguards.h"
42 
43 
47 static byte _waypoint_count = 1;
48 static byte _cur_waypoint_type;
52 
53 /* Map the setting: default_signal_type to the corresponding signal type */
54 static const SignalType _default_signal_type[] = {SIGTYPE_NORMAL, SIGTYPE_PBS, SIGTYPE_PBS_ONEWAY};
55 
58 
59  bool newstations;
61  byte station_type;
63 };
65 
66 
67 static void HandleStationPlacement(TileIndex start, TileIndex end);
68 static void ShowBuildTrainDepotPicker(Window *parent);
69 static void ShowBuildWaypointPicker(Window *parent);
70 static void ShowStationBuilder(Window *parent);
71 static void ShowSignalBuilder(Window *parent);
72 
77 static bool IsStationAvailable(const StationSpec *statspec)
78 {
79  if (statspec == nullptr || !HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) return true;
80 
81  uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
82  if (cb_res == CALLBACK_FAILED) return true;
83 
85 }
86 
87 void CcPlaySound_SPLAT_RAIL(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
88 {
89  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
90 }
91 
92 static void GenericPlaceRail(TileIndex tile, int cmd)
93 {
94  DoCommandP(tile, _cur_railtype, cmd,
96  CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK) :
97  CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK),
98  CcPlaySound_SPLAT_RAIL);
99 }
100 
108 static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track)
109 {
110  if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
111  if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return;
112 
114 }
115 
117 static const Track _place_depot_extra_track[12] = {
118  TRACK_LEFT, TRACK_UPPER, TRACK_UPPER, TRACK_RIGHT, // First additional track for directions 0..3
119  TRACK_X, TRACK_Y, TRACK_X, TRACK_Y, // Second additional track
120  TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT, TRACK_LOWER, // Third additional track
121 };
122 
128 };
129 
130 void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
131 {
132  if (result.Failed()) return;
133 
134  DiagDirection dir = (DiagDirection)p2;
135 
136  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
138 
139  tile += TileOffsByDiagDir(dir);
140 
141  if (IsTileType(tile, MP_RAILWAY)) {
145  }
146 }
147 
152 static void PlaceRail_Waypoint(TileIndex tile)
153 {
156  return;
157  }
158 
159  Axis axis = GetAxisForNewWaypoint(tile);
160  if (IsValidAxis(axis)) {
161  /* Valid tile for waypoints */
163  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
164  } else {
165  /* Tile where we can't build rail waypoints. This is always going to fail,
166  * but provides the user with a proper error message. */
167  DoCommandP(tile, 1 << 8 | 1 << 16, STAT_CLASS_WAYP | INVALID_STATION << 16, CMD_BUILD_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT));
168  }
169 }
170 
171 void CcStation(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
172 {
173  if (result.Failed()) return;
174 
175  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
176  /* Only close the station builder window if the default station and non persistent building is chosen. */
178 }
179 
184 static void PlaceRail_Station(TileIndex tile)
185 {
188  VpSetPlaceSizingLimit(-1);
191  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
192  } else {
194  uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
195 
198  if (!_railstation.orientation) Swap(w, h);
199 
200  CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION), CcStation, "" };
201  ShowSelectStationIfNeeded(cmdcont, TileArea(tile, w, h));
202  }
203 }
204 
211 {
213 
214  if (trackbits & TRACK_BIT_VERT) { // N-S direction
215  trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT;
216  }
217 
218  if (trackbits & TRACK_BIT_HORZ) { // E-W direction
219  trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
220  }
221 
222  Track track = FindFirstTrack(trackbits);
223 
225  DoCommandP(tile, track, 0, CMD_REMOVE_SIGNALS | CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM), CcPlaySound_SPLAT_RAIL);
226  } else {
227  const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
228 
229  /* Map the setting cycle_signal_types to the lower and upper allowed signal type. */
230  static const uint cycle_bounds[] = {SIGTYPE_NORMAL | (SIGTYPE_LAST_NOPBS << 3), SIGTYPE_PBS | (SIGTYPE_LAST << 3), SIGTYPE_NORMAL | (SIGTYPE_LAST << 3)};
231 
232  /* various bitstuffed elements for CmdBuildSingleSignal() */
233  uint32 p1 = track;
234 
235  if (w != nullptr) {
236  /* signal GUI is used */
237  SB(p1, 3, 1, _ctrl_pressed);
238  SB(p1, 4, 1, _cur_signal_variant);
239  SB(p1, 5, 3, _cur_signal_type);
240  SB(p1, 8, 1, _convert_signal_button);
241  SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]);
242  } else {
243  SB(p1, 3, 1, _ctrl_pressed);
245  SB(p1, 5, 3, _default_signal_type[_settings_client.gui.default_signal_type]);
246  SB(p1, 8, 1, 0);
247  SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]);
248  }
249 
250  DoCommandP(tile, p1, 0, CMD_BUILD_SIGNALS |
251  CMD_MSG((w != nullptr && _convert_signal_button) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
252  CcPlaySound_SPLAT_RAIL);
253  }
254 }
255 
261 static void PlaceRail_Bridge(TileIndex tile, Window *w)
262 {
263  if (IsBridgeTile(tile)) {
264  TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
265  Point pt = {0, 0};
266  w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
267  } else {
269  }
270 }
271 
273 void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
274 {
275  if (result.Succeeded()) {
276  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
278  } else {
280  }
281 }
282 
288 {
293  SetSelectionRed(_remove_button_clicked);
294 }
295 
302 {
303  if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false;
304 
305  /* allow ctrl to switch remove mode only for these widgets */
306  for (uint i = WID_RAT_BUILD_NS; i <= WID_RAT_BUILD_STATION; i++) {
307  if ((i <= WID_RAT_AUTORAIL || i >= WID_RAT_BUILD_WAYPOINT) && w->IsWidgetLowered(i)) {
309  return true;
310  }
311  }
312 
313  return false;
314 }
315 
316 
323 {
324  if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return;
326  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
327 
328  /* handle station builder */
331  /* starting drag & drop remove */
333  SetTileSelectSize(1, 1);
334  } else {
335  VpSetPlaceSizingLimit(-1);
336  }
337  } else {
338  /* starting station build mode */
342  if (_railstation.orientation == 0) Swap(x, y);
343  SetTileSelectSize(x, y);
344  } else {
345  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
346  }
347  }
348  }
349 }
350 
351 static void DoRailroadTrack(int mode)
352 {
353  DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 6),
355  CMD_REMOVE_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK) :
356  CMD_BUILD_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK),
357  CcPlaySound_SPLAT_RAIL);
358 }
359 
360 static void HandleAutodirPlacement()
361 {
362  int trackstat = _thd.drawstyle & HT_DIR_MASK; // 0..5
363 
364  if (_thd.drawstyle & HT_RAIL) { // one tile case
365  GenericPlaceRail(TileVirtXY(_thd.selend.x, _thd.selend.y), trackstat);
366  return;
367  }
368 
369  DoRailroadTrack(trackstat);
370 }
371 
379 {
380  uint32 p2 = GB(_thd.drawstyle, 0, 3); // 0..5
381 
382  if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT) { // one tile case
383  GenericPlaceSignals(TileVirtXY(_thd.selend.x, _thd.selend.y));
384  return;
385  }
386 
387  const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
388 
389  if (w != nullptr) {
390  /* signal GUI is used */
391  SB(p2, 3, 1, 0);
392  SB(p2, 4, 1, _cur_signal_variant);
393  SB(p2, 6, 1, _ctrl_pressed);
394  SB(p2, 7, 3, _cur_signal_type);
397  } else {
398  SB(p2, 3, 1, 0);
400  SB(p2, 6, 1, _ctrl_pressed);
401  SB(p2, 7, 3, _default_signal_type[_settings_client.gui.default_signal_type]);
404  }
405 
406  /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
407  * in a network game can specify his/her own signal density */
408  DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), p2,
410  CMD_REMOVE_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM) :
411  CMD_BUILD_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
412  CcPlaySound_SPLAT_RAIL);
413 }
414 
415 
420 
421  BuildRailToolbarWindow(WindowDesc *desc, RailType railtype) : Window(desc)
422  {
423  this->InitNested(TRANSPORT_RAIL);
424  this->SetupRailToolbar(railtype);
425  this->DisableWidget(WID_RAT_REMOVE);
426  this->last_user_action = WIDGET_LIST_END;
427 
429  }
430 
432  {
433  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
435  }
436 
442  void OnInvalidateData(int data = 0, bool gui_scope = true) override
443  {
444  if (!gui_scope) return;
445 
446  if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this;
447  }
448 
453  void SetupRailToolbar(RailType railtype)
454  {
455  this->railtype = railtype;
456  const RailtypeInfo *rti = GetRailTypeInfo(railtype);
457 
458  assert(railtype < RAILTYPE_END);
459  this->GetWidget<NWidgetCore>(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail;
461  this->GetWidget<NWidgetCore>(WID_RAT_BUILD_EW)->widget_data = rti->gui_sprites.build_ew_rail;
463  this->GetWidget<NWidgetCore>(WID_RAT_AUTORAIL)->widget_data = rti->gui_sprites.auto_rail;
465  this->GetWidget<NWidgetCore>(WID_RAT_CONVERT_RAIL)->widget_data = rti->gui_sprites.convert_rail;
467  }
468 
473  void ModifyRailType(RailType railtype)
474  {
475  this->SetupRailToolbar(railtype);
476  this->ReInit();
477  }
478 
479  void UpdateRemoveWidgetStatus(int clicked_widget)
480  {
481  switch (clicked_widget) {
482  case WID_RAT_REMOVE:
483  /* If it is the removal button that has been clicked, do nothing,
484  * as it is up to the other buttons to drive removal status */
485  return;
486 
487  case WID_RAT_BUILD_NS:
488  case WID_RAT_BUILD_X:
489  case WID_RAT_BUILD_EW:
490  case WID_RAT_BUILD_Y:
491  case WID_RAT_AUTORAIL:
495  /* Removal button is enabled only if the rail/signal/waypoint/station
496  * button is still lowered. Once raised, it has to be disabled */
497  this->SetWidgetDisabledState(WID_RAT_REMOVE, !this->IsWidgetLowered(clicked_widget));
498  break;
499 
500  default:
501  /* When any other buttons than rail/signal/waypoint/station, raise and
502  * disable the removal button */
503  this->DisableWidget(WID_RAT_REMOVE);
504  this->RaiseWidget(WID_RAT_REMOVE);
505  break;
506  }
507  }
508 
509  void SetStringParameters(int widget) const override
510  {
511  if (widget == WID_RAT_CAPTION) {
512  const RailtypeInfo *rti = GetRailTypeInfo(this->railtype);
513  if (rti->max_speed > 0) {
514  SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY);
516  SetDParam(2, rti->max_speed);
517  } else {
519  }
520  }
521  }
522 
523  void OnClick(Point pt, int widget, int click_count) override
524  {
525  if (widget < WID_RAT_BUILD_NS) return;
526 
527  _remove_button_clicked = false;
528  switch (widget) {
529  case WID_RAT_BUILD_NS:
531  this->last_user_action = widget;
532  break;
533 
534  case WID_RAT_BUILD_X:
536  this->last_user_action = widget;
537  break;
538 
539  case WID_RAT_BUILD_EW:
541  this->last_user_action = widget;
542  break;
543 
544  case WID_RAT_BUILD_Y:
546  this->last_user_action = widget;
547  break;
548 
549  case WID_RAT_AUTORAIL:
551  this->last_user_action = widget;
552  break;
553 
554  case WID_RAT_DEMOLISH:
556  this->last_user_action = widget;
557  break;
558 
559  case WID_RAT_BUILD_DEPOT:
561  ShowBuildTrainDepotPicker(this);
562  this->last_user_action = widget;
563  }
564  break;
565 
567  this->last_user_action = widget;
569  if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT) && _waypoint_count > 1) {
570  ShowBuildWaypointPicker(this);
571  }
572  break;
573 
575  if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION, SPR_CURSOR_RAIL_STATION, HT_RECT)) {
576  ShowStationBuilder(this);
577  this->last_user_action = widget;
578  }
579  break;
580 
581  case WID_RAT_BUILD_SIGNALS: {
582  this->last_user_action = widget;
585  ShowSignalBuilder(this);
586  }
587  break;
588  }
589 
591  HandlePlacePushButton(this, WID_RAT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
592  this->last_user_action = widget;
593  break;
594 
597  this->last_user_action = widget;
598  break;
599 
600  case WID_RAT_REMOVE:
601  BuildRailClick_Remove(this);
602  break;
603 
606  this->last_user_action = widget;
607  break;
608 
609  default: NOT_REACHED();
610  }
611  this->UpdateRemoveWidgetStatus(widget);
613  }
614 
615  EventState OnHotkey(int hotkey) override
616  {
617  MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
618  return Window::OnHotkey(hotkey);
619  }
620 
621  void OnPlaceObject(Point pt, TileIndex tile) override
622  {
623  switch (this->last_user_action) {
624  case WID_RAT_BUILD_NS:
626  break;
627 
628  case WID_RAT_BUILD_X:
630  break;
631 
632  case WID_RAT_BUILD_EW:
634  break;
635 
636  case WID_RAT_BUILD_Y:
638  break;
639 
640  case WID_RAT_AUTORAIL:
642  break;
643 
644  case WID_RAT_DEMOLISH:
646  break;
647 
648  case WID_RAT_BUILD_DEPOT:
650  CMD_BUILD_TRAIN_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT),
651  CcRailDepot);
652  break;
653 
655  PlaceRail_Waypoint(tile);
656  break;
657 
659  PlaceRail_Station(tile);
660  break;
661 
664  break;
665 
667  PlaceRail_Bridge(tile, this);
668  break;
669 
671  DoCommandP(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRailTunnel);
672  break;
673 
676  break;
677 
678  default: NOT_REACHED();
679  }
680  }
681 
682  void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
683  {
684  /* no dragging if you have pressed the convert button */
685  if (FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr && _convert_signal_button && this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS)) return;
686 
687  VpSelectTilesWithMethod(pt.x, pt.y, select_method);
688  }
689 
690  void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
691  {
692  if (pt.x != -1) {
693  switch (select_proc) {
694  default: NOT_REACHED();
695  case DDSP_BUILD_BRIDGE:
697  ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_RAIL, _cur_railtype);
698  break;
699 
700  case DDSP_PLACE_RAIL:
701  HandleAutodirPlacement();
702  break;
703 
704  case DDSP_BUILD_SIGNALS:
706  break;
707 
708  case DDSP_DEMOLISH_AREA:
709  GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
710  break;
711 
712  case DDSP_CONVERT_RAIL:
713  DoCommandP(end_tile, start_tile, _cur_railtype | (_ctrl_pressed ? 1 << 6 : 0), CMD_CONVERT_RAIL | CMD_MSG(STR_ERROR_CAN_T_CONVERT_RAIL), CcPlaySound_SPLAT_RAIL);
714  break;
715 
716  case DDSP_REMOVE_STATION:
717  case DDSP_BUILD_STATION:
718  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) {
719  /* Station */
721  DoCommandP(end_tile, start_tile, _ctrl_pressed ? 0 : 1, CMD_REMOVE_FROM_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION), CcPlaySound_SPLAT_RAIL);
722  } else {
723  HandleStationPlacement(start_tile, end_tile);
724  }
725  } else {
726  /* Waypoint */
728  DoCommandP(end_tile, start_tile, _ctrl_pressed ? 0 : 1, CMD_REMOVE_FROM_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_REMOVE_TRAIN_WAYPOINT), CcPlaySound_SPLAT_RAIL);
729  } else {
730  TileArea ta(start_tile, end_tile);
731  uint32 p1 = _cur_railtype | (select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y) << 6 | ta.w << 8 | ta.h << 16 | _ctrl_pressed << 24;
732  uint32 p2 = STAT_CLASS_WAYP | _cur_waypoint_type << 8 | INVALID_STATION << 16;
733 
734  CommandContainer cmdcont = { ta.tile, p1, p2, CMD_BUILD_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT), CcPlaySound_SPLAT_RAIL, "" };
735  ShowSelectWaypointIfNeeded(cmdcont, ta);
736  }
737  }
738  break;
739  }
740  }
741  }
742 
743  void OnPlaceObjectAbort() override
744  {
745  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
746 
747  this->RaiseButtons();
748  this->DisableWidget(WID_RAT_REMOVE);
749  this->SetWidgetDirty(WID_RAT_REMOVE);
750 
757  }
758 
759  void OnPlacePresize(Point pt, TileIndex tile) override
760  {
763  }
764 
766  {
767  /* do not toggle Remove button by Ctrl when placing station */
768  if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT) && RailToolbar_CtrlChanged(this)) return ES_HANDLED;
769  return ES_NOT_HANDLED;
770  }
771 
772  static HotkeyList hotkeys;
773 };
774 
781 {
782  if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
783  extern RailType _last_built_railtype;
784  Window *w = ShowBuildRailToolbar(_last_built_railtype);
785  if (w == nullptr) return ES_NOT_HANDLED;
786  return w->OnHotkey(hotkey);
787 }
788 
789 const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
790 
791 static Hotkey railtoolbar_hotkeys[] = {
792  Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
793  Hotkey('2', "build_x", WID_RAT_BUILD_X),
794  Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
795  Hotkey('4', "build_y", WID_RAT_BUILD_Y),
796  Hotkey(_railtoolbar_autorail_keys, "autorail", WID_RAT_AUTORAIL),
797  Hotkey('6', "demolish", WID_RAT_DEMOLISH),
798  Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
799  Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
800  Hotkey('9', "station", WID_RAT_BUILD_STATION),
801  Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
802  Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
803  Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
804  Hotkey('R', "remove", WID_RAT_REMOVE),
805  Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
806  HOTKEY_LIST_END
807 };
808 HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys, RailToolbarGlobalHotkeys);
809 
810 static const NWidgetPart _nested_build_rail_widgets[] = {
812  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
813  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_RAT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
814  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
815  EndContainer(),
817  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_NS),
818  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
819  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_X),
820  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
821  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_EW),
822  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
823  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_Y),
824  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
825  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_AUTORAIL),
826  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL),
827 
828  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL), EndContainer(),
829 
830  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_DEMOLISH),
831  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
832  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_DEPOT),
833  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING),
834  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_WAYPOINT),
835  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT),
836  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_STATION),
837  SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION),
838  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_SIGNALS),
839  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS),
840  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_BRIDGE),
841  SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE),
842  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_TUNNEL),
843  SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL),
844  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_REMOVE),
845  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR),
846  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_CONVERT_RAIL),
847  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL),
848  EndContainer(),
849 };
850 
851 static WindowDesc _build_rail_desc(
852  WDP_ALIGN_TOOLBAR, "toolbar_rail", 0, 0,
855  _nested_build_rail_widgets, lengthof(_nested_build_rail_widgets),
856  &BuildRailToolbarWindow::hotkeys
857 );
858 
859 
869 {
870  if (!Company::IsValidID(_local_company)) return nullptr;
871  if (!ValParamRailtype(railtype)) return nullptr;
872 
874  _cur_railtype = railtype;
875  _remove_button_clicked = false;
876  return new BuildRailToolbarWindow(&_build_rail_desc, railtype);
877 }
878 
879 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
880  * --pasky */
881 
882 static void HandleStationPlacement(TileIndex start, TileIndex end)
883 {
884  TileArea ta(start, end);
885  uint numtracks = ta.w;
886  uint platlength = ta.h;
887 
888  if (_railstation.orientation == AXIS_X) Swap(numtracks, platlength);
889 
890  uint32 p1 = _cur_railtype | _railstation.orientation << 6 | numtracks << 8 | platlength << 16 | _ctrl_pressed << 24;
891  uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
892 
893  CommandContainer cmdcont = { ta.tile, p1, p2, CMD_BUILD_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION), CcStation, "" };
894  ShowSelectStationIfNeeded(cmdcont, ta);
895 }
896 
898 private:
899  uint line_height;
903 
909  void CheckSelectedSize(const StationSpec *statspec)
910  {
911  if (statspec == nullptr || _settings_client.gui.station_dragdrop) return;
912 
913  /* If current number of tracks is not allowed, make it as big as possible */
917  if (statspec->disallowed_platforms != UINT8_MAX) {
920  }
922  }
923  }
924 
928  if (statspec->disallowed_lengths != UINT8_MAX) {
931  }
933  }
934  }
935  }
936 
937 public:
938  BuildRailStationWindow(WindowDesc *desc, Window *parent, bool newstation) : PickerWindowBase(desc, parent)
939  {
940  this->coverage_height = 2 * FONT_HEIGHT_NORMAL + 3 * WD_PAR_VSEP_NORMAL;
941  this->vscroll = nullptr;
942  _railstation.newstations = newstation;
943 
944  this->CreateNestedTree();
945  NWidgetStacked *newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_ADDITIONS);
946  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
947  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_MATRIX);
948  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
949  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_DEFSIZE);
950  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
951  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_RESIZE);
952  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
953  if (newstation) {
954  this->vscroll = this->GetScrollbar(WID_BRAS_NEWST_SCROLL);
955  this->vscroll2 = this->GetScrollbar(WID_BRAS_MATRIX_SCROLL);
956  }
957  this->FinishInitNested(TRANSPORT_RAIL);
958 
959  this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
961  this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
962  } else {
965  }
966  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF, !_settings_client.gui.station_show_coverage);
967  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON, _settings_client.gui.station_show_coverage);
968 
969  if (!newstation || _railstation.station_class >= (int)StationClass::GetClassCount()) {
970  /* New stations are not available or changed, so ensure the default station
971  * type is 'selected'. */
972  _railstation.station_class = STAT_CLASS_DFLT;
973  _railstation.station_type = 0;
974  this->vscroll2 = nullptr;
975  }
976  if (newstation) {
977  _railstation.station_count = StationClass::Get(_railstation.station_class)->GetSpecCount();
978  _railstation.station_type = min(_railstation.station_type, _railstation.station_count - 1);
979 
980  int count = 0;
981  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
982  if (i == STAT_CLASS_WAYP) continue;
983  count++;
984  }
985  this->vscroll->SetCount(count);
986  this->vscroll->SetPosition(Clamp(_railstation.station_class - 2, 0, max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
987 
988  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
989  matrix->SetScrollbar(this->vscroll2);
990  matrix->SetCount(_railstation.station_count);
991  matrix->SetClicked(_railstation.station_type);
992  }
993  }
994 
995  virtual ~BuildRailStationWindow()
996  {
998  }
999 
1000  void OnPaint() override
1001  {
1002  bool newstations = _railstation.newstations;
1003  const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1004 
1006  SetTileSelectSize(1, 1);
1007  } else {
1010  if (_railstation.orientation == AXIS_X) Swap(x, y);
1011  if (!_remove_button_clicked) {
1012  SetTileSelectSize(x, y);
1013  }
1014  }
1015 
1017 
1018  if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1019 
1020  for (uint bits = 0; bits < 7; bits++) {
1021  bool disable = bits >= _settings_game.station.station_spread;
1022  if (statspec == nullptr) {
1023  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_NUM_1, disable);
1024  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_LEN_1, disable);
1025  } else {
1026  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_NUM_1, HasBit(statspec->disallowed_platforms, bits) || disable);
1027  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_LEN_1, HasBit(statspec->disallowed_lengths, bits) || disable);
1028  }
1029  }
1030 
1031  this->DrawWidgets();
1032 
1033  if (this->IsShaded()) return;
1034  /* 'Accepts' and 'Supplies' texts. */
1035  NWidgetBase *cov = this->GetWidget<NWidgetBase>(WID_BRAS_COVERAGE_TEXTS);
1036  int top = cov->pos_y + WD_PAR_VSEP_NORMAL;
1037  int left = cov->pos_x + WD_FRAMERECT_LEFT;
1038  int right = cov->pos_x + cov->current_x - WD_FRAMERECT_RIGHT;
1039  int bottom = cov->pos_y + cov->current_y;
1040  top = DrawStationCoverageAreaText(left, right, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
1041  top = DrawStationCoverageAreaText(left, right, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
1042  /* Resize background if the window is too small.
1043  * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1044  * (This is the case, if making the window bigger moves the mouse into the window.) */
1045  if (top > bottom) {
1046  this->coverage_height += top - bottom;
1047  this->ReInit();
1048  }
1049  }
1050 
1051  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1052  {
1053  switch (widget) {
1054  case WID_BRAS_NEWST_LIST: {
1055  Dimension d = {0, 0};
1056  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1057  if (i == STAT_CLASS_WAYP) continue;
1059  }
1060  size->width = max(size->width, d.width + padding.width);
1061  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
1062  size->height = 5 * this->line_height;
1063  resize->height = this->line_height;
1064  break;
1065  }
1066 
1067  case WID_BRAS_SHOW_NEWST_TYPE: {
1068  if (!_railstation.newstations) {
1069  size->width = 0;
1070  size->height = 0;
1071  break;
1072  }
1073 
1074  /* If newstations exist, compute the non-zero minimal size. */
1075  Dimension d = {0, 0};
1076  StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
1077  for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)StationClass::GetClassCount(); statclass++) {
1078  if (statclass == STAT_CLASS_WAYP) continue;
1079  StationClass *stclass = StationClass::Get(statclass);
1080  for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
1081  const StationSpec *statspec = stclass->GetSpec(j);
1082  SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
1083  d = maxdim(d, GetStringBoundingBox(str));
1084  }
1085  }
1086  size->width = max(size->width, d.width + padding.width);
1087  break;
1088  }
1089 
1092  case WID_BRAS_IMAGE:
1093  size->width = ScaleGUITrad(64) + 2;
1094  size->height = ScaleGUITrad(58) + 2;
1095  break;
1096 
1098  size->height = this->coverage_height;
1099  break;
1100 
1101  case WID_BRAS_MATRIX:
1102  fill->height = 1;
1103  resize->height = 1;
1104  break;
1105  }
1106  }
1107 
1108  void DrawWidget(const Rect &r, int widget) const override
1109  {
1110  DrawPixelInfo tmp_dpi;
1111 
1112  switch (GB(widget, 0, 16)) {
1114  /* Set up a clipping area for the '/' station preview */
1115  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1116  DrawPixelInfo *old_dpi = _cur_dpi;
1117  _cur_dpi = &tmp_dpi;
1118  int x = ScaleGUITrad(31) + 1;
1119  int y = r.bottom - r.top - ScaleGUITrad(31);
1120  if (!DrawStationTile(x, y, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) {
1121  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2);
1122  }
1123  _cur_dpi = old_dpi;
1124  }
1125  break;
1126 
1128  /* Set up a clipping area for the '\' station preview */
1129  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1130  DrawPixelInfo *old_dpi = _cur_dpi;
1131  _cur_dpi = &tmp_dpi;
1132  int x = ScaleGUITrad(31) + 1;
1133  int y = r.bottom - r.top - ScaleGUITrad(31);
1134  if (!DrawStationTile(x, y, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) {
1135  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 3);
1136  }
1137  _cur_dpi = old_dpi;
1138  }
1139  break;
1140 
1141  case WID_BRAS_NEWST_LIST: {
1142  uint statclass = 0;
1143  uint row = 0;
1144  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1145  if (i == STAT_CLASS_WAYP) continue;
1146  if (this->vscroll->IsVisible(statclass)) {
1147  DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, row * this->line_height + r.top + WD_MATRIX_TOP,
1149  (StationClassID)i == _railstation.station_class ? TC_WHITE : TC_BLACK);
1150  row++;
1151  }
1152  statclass++;
1153  }
1154  break;
1155  }
1156 
1157  case WID_BRAS_IMAGE: {
1158  byte type = GB(widget, 16, 16);
1159  assert(type < _railstation.station_count);
1160  /* Check station availability callback */
1161  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
1162  if (!IsStationAvailable(statspec)) {
1163  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
1164  }
1165 
1166  /* Set up a clipping area for the station preview. */
1167  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1168  DrawPixelInfo *old_dpi = _cur_dpi;
1169  _cur_dpi = &tmp_dpi;
1170  int x = ScaleGUITrad(31) + 1;
1171  int y = r.bottom - r.top - ScaleGUITrad(31);
1172  if (!DrawStationTile(x, y, _cur_railtype, _railstation.orientation, _railstation.station_class, type)) {
1173  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2 + _railstation.orientation);
1174  }
1175  _cur_dpi = old_dpi;
1176  }
1177  break;
1178  }
1179  }
1180  }
1181 
1182  void OnResize() override
1183  {
1184  if (this->vscroll != nullptr) { // New stations available.
1185  this->vscroll->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST);
1186  }
1187  }
1188 
1189  void SetStringParameters(int widget) const override
1190  {
1191  if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
1192  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
1193  SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
1194  }
1195  }
1196 
1197  void OnClick(Point pt, int widget, int click_count) override
1198  {
1199  switch (GB(widget, 0, 16)) {
1202  this->RaiseWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
1203  _railstation.orientation = (Axis)(widget - WID_BRAS_PLATFORM_DIR_X);
1204  this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
1205  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1206  this->SetDirty();
1208  break;
1209 
1216  case WID_BRAS_PLATFORM_NUM_7: {
1218  this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
1219 
1222 
1224 
1225  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1226  if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1227  /* The previously selected number of platforms in invalid */
1228  for (uint i = 0; i < 7; i++) {
1229  if (!HasBit(statspec->disallowed_lengths, i)) {
1232  break;
1233  }
1234  }
1235  }
1236 
1237  this->LowerWidget(_settings_client.gui.station_numtracks + WID_BRAS_PLATFORM_NUM_BEGIN);
1239  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1240  this->SetDirty();
1242  break;
1243  }
1244 
1251  case WID_BRAS_PLATFORM_LEN_7: {
1253  this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
1254 
1257 
1259 
1260  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1261  if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1262  /* The previously selected number of tracks in invalid */
1263  for (uint i = 0; i < 7; i++) {
1264  if (!HasBit(statspec->disallowed_platforms, i)) {
1267  break;
1268  }
1269  }
1270  }
1271 
1273  this->LowerWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
1274  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1275  this->SetDirty();
1277  break;
1278  }
1279 
1282 
1283  this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP);
1284 
1285  /* get the first allowed length/number of platforms */
1286  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1287  if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1288  for (uint i = 0; i < 7; i++) {
1289  if (!HasBit(statspec->disallowed_lengths, i)) {
1292  break;
1293  }
1294  }
1295  }
1296  if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1297  for (uint i = 0; i < 7; i++) {
1298  if (!HasBit(statspec->disallowed_platforms, i)) {
1301  break;
1302  }
1303  }
1304  }
1305 
1308  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1309  this->SetDirty();
1311  break;
1312  }
1313 
1315  case WID_BRAS_HIGHLIGHT_ON:
1317 
1318  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF, !_settings_client.gui.station_show_coverage);
1319  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON, _settings_client.gui.station_show_coverage);
1320  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1321  this->SetDirty();
1322  break;
1323 
1324  case WID_BRAS_NEWST_LIST: {
1325  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BRAS_NEWST_LIST, 0, this->line_height);
1326  if (y >= (int)StationClass::GetClassCount()) return;
1327  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1328  if (i == STAT_CLASS_WAYP) continue;
1329  if (y == 0) {
1330  if (_railstation.station_class != (StationClassID)i) {
1331  _railstation.station_class = (StationClassID)i;
1332  StationClass *stclass = StationClass::Get(_railstation.station_class);
1333  _railstation.station_count = stclass->GetSpecCount();
1334  _railstation.station_type = min((int)_railstation.station_type, max(0, (int)_railstation.station_count - 1));
1335 
1336  this->CheckSelectedSize(stclass->GetSpec(_railstation.station_type));
1337 
1338  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
1339  matrix->SetCount(_railstation.station_count);
1340  matrix->SetClicked(_railstation.station_type);
1341  }
1342  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1343  this->SetDirty();
1345  break;
1346  }
1347  y--;
1348  }
1349  break;
1350  }
1351 
1352  case WID_BRAS_IMAGE: {
1353  int y = GB(widget, 16, 16);
1354  if (y >= _railstation.station_count) return;
1355 
1356  /* Check station availability callback */
1357  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(y);
1358  if (!IsStationAvailable(statspec)) return;
1359 
1360  _railstation.station_type = y;
1361 
1362  this->CheckSelectedSize(statspec);
1363  this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->SetClicked(_railstation.station_type);
1364 
1365  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1366  this->SetDirty();
1368  break;
1369  }
1370  }
1371  }
1372 
1373  void OnRealtimeTick(uint delta_ms) override
1374  {
1376  }
1377 };
1378 
1379 static const NWidgetPart _nested_station_builder_widgets[] = {
1381  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1382  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1383  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1385  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1386  EndContainer(),
1387  EndContainer(),
1388  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1392  NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1393  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BRAS_NEWST_LIST), SetMinimalSize(122, 71), SetFill(1, 0),
1394  SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP), SetScrollbar(WID_BRAS_NEWST_SCROLL),
1396  EndContainer(),
1397  EndContainer(),
1398  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION, STR_NULL), SetPadding(1, 2, 0, 2),
1400  NWidget(NWID_SPACER), SetMinimalSize(7, 0), SetFill(1, 0),
1401  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAS_PLATFORM_DIR_X), SetMinimalSize(66, 60), SetFill(0, 0), SetDataTip(0x0, STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP), EndContainer(),
1402  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1403  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAS_PLATFORM_DIR_Y), SetMinimalSize(66, 60), SetFill(0, 0), SetDataTip(0x0, STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP), EndContainer(),
1404  NWidget(NWID_SPACER), SetMinimalSize(7, 0), SetFill(1, 0),
1405  EndContainer(),
1406  NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BRAS_SHOW_NEWST_TYPE), SetMinimalSize(144, 11), SetDataTip(STR_ORANGE_STRING, STR_NULL), SetPadding(1, 2, 4, 2),
1407  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS, STR_NULL), SetPadding(0, 2, 0, 2),
1409  NWidget(NWID_SPACER), SetFill(1, 0),
1410  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_1), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1411  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_2), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1412  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_3), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1413  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_4), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1414  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_5), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1415  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_6), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1416  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_7), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1417  NWidget(NWID_SPACER), SetFill(1, 0),
1418  EndContainer(),
1419  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH, STR_NULL), SetPadding(2, 2, 0, 2),
1421  NWidget(NWID_SPACER), SetFill(1, 0),
1422  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_1), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1423  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_2), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1424  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_3), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1425  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_4), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1426  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_5), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1427  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_6), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1428  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_7), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1429  NWidget(NWID_SPACER), SetFill(1, 0),
1430  EndContainer(),
1433  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1434  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_DRAG_N_DROP), SetMinimalSize(75, 12), SetDataTip(STR_STATION_BUILD_DRAG_DROP, STR_STATION_BUILD_DRAG_DROP_TOOLTIP),
1435  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1436  EndContainer(),
1437  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetPadding(3, 2, 0, 2),
1439  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1440  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_OFF), SetMinimalSize(60, 12),
1441  SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1442  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_ON), SetMinimalSize(60, 12),
1443  SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1444  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1445  EndContainer(),
1446  EndContainer(),
1448  /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1449  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BRAS_MATRIX_SCROLL),
1451  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BRAS_MATRIX), SetScrollbar(WID_BRAS_MATRIX_SCROLL), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1452  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRAS_IMAGE), SetMinimalSize(66, 60),
1453  SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP), SetScrollbar(WID_BRAS_MATRIX_SCROLL),
1454  EndContainer(),
1455  EndContainer(),
1456  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRAS_MATRIX_SCROLL),
1457  EndContainer(),
1458  EndContainer(),
1459  EndContainer(),
1460  EndContainer(),
1462  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BRAS_COVERAGE_TEXTS), SetFill(1, 1), SetResize(1, 0),
1465  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
1466  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
1467  EndContainer(),
1468  EndContainer(),
1469  EndContainer(),
1470  EndContainer(),
1471 };
1472 
1475  WDP_AUTO, "build_station_rail", 350, 0,
1478  _nested_station_builder_widgets, lengthof(_nested_station_builder_widgets)
1479 );
1480 
1482 static void ShowStationBuilder(Window *parent)
1483 {
1484  bool newstations = StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT)->GetSpecCount() != 1;
1485  new BuildRailStationWindow(&_station_builder_desc, parent, newstations);
1486 }
1487 
1489 private:
1492 
1500  void DrawSignalSprite(byte widget_index, SpriteID image) const
1501  {
1502  Point offset;
1503  Dimension sprite_size = GetSpriteSize(image, &offset);
1504  const NWidgetBase *widget = this->GetWidget<NWidgetBase>(widget_index);
1505  int x = widget->pos_x - offset.x +
1506  (widget->current_x - sprite_size.width + offset.x) / 2; // centered
1507  int y = widget->pos_y - sig_sprite_bottom_offset + WD_IMGBTN_TOP +
1508  (widget->current_y - WD_IMGBTN_TOP - WD_IMGBTN_BOTTOM + sig_sprite_size.height) / 2; // aligned to bottom
1509 
1510  DrawSprite(image, PAL_NONE,
1511  x + this->IsWidgetLowered(widget_index),
1512  y + this->IsWidgetLowered(widget_index));
1513  }
1514 
1515 public:
1516  BuildSignalWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1517  {
1518  this->InitNested(TRANSPORT_RAIL);
1519  this->OnInvalidateData();
1520  }
1521 
1523  {
1524  _convert_signal_button = false;
1525  }
1526 
1527  void OnInit() override
1528  {
1529  /* Calculate maximum signal sprite size. */
1530  this->sig_sprite_size.width = 0;
1531  this->sig_sprite_size.height = 0;
1532  this->sig_sprite_bottom_offset = 0;
1534  for (uint type = SIGTYPE_NORMAL; type < SIGTYPE_END; type++) {
1535  for (uint variant = SIG_ELECTRIC; variant <= SIG_SEMAPHORE; variant++) {
1536  for (uint lowered = 0; lowered < 2; lowered++) {
1537  Point offset;
1538  Dimension sprite_size = GetSpriteSize(rti->gui_sprites.signals[type][variant][lowered], &offset);
1539  this->sig_sprite_bottom_offset = max<int>(this->sig_sprite_bottom_offset, sprite_size.height);
1540  this->sig_sprite_size.width = max<int>(this->sig_sprite_size.width, sprite_size.width - offset.x);
1541  this->sig_sprite_size.height = max<int>(this->sig_sprite_size.height, sprite_size.height - offset.y);
1542  }
1543  }
1544  }
1545  }
1546 
1547  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1548  {
1549  if (widget == WID_BS_DRAG_SIGNALS_DENSITY_LABEL) {
1550  /* Two digits for signals density. */
1551  size->width = max(size->width, 2 * GetDigitWidth() + padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT);
1552  } else if (IsInsideMM(widget, WID_BS_SEMAPHORE_NORM, WID_BS_ELECTRIC_PBS_OWAY + 1)) {
1553  size->width = max(size->width, this->sig_sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
1554  size->height = max(size->height, this->sig_sprite_size.height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
1555  }
1556  }
1557 
1558  void SetStringParameters(int widget) const override
1559  {
1560  switch (widget) {
1563  break;
1564  }
1565  }
1566 
1567  void DrawWidget(const Rect &r, int widget) const override
1568  {
1570  /* Extract signal from widget number. */
1571  int type = (widget - WID_BS_SEMAPHORE_NORM) % SIGTYPE_END;
1572  int var = SIG_SEMAPHORE - (widget - WID_BS_SEMAPHORE_NORM) / SIGTYPE_END; // SignalVariant order is reversed compared to the widgets.
1573  SpriteID sprite = GetRailTypeInfo(_cur_railtype)->gui_sprites.signals[type][var][this->IsWidgetLowered(widget)];
1574 
1575  this->DrawSignalSprite(widget, sprite);
1576  }
1577  }
1578 
1579  void OnClick(Point pt, int widget, int click_count) override
1580  {
1581  switch (widget) {
1582  case WID_BS_SEMAPHORE_NORM:
1584  case WID_BS_SEMAPHORE_EXIT:
1586  case WID_BS_SEMAPHORE_PBS:
1588  case WID_BS_ELECTRIC_NORM:
1589  case WID_BS_ELECTRIC_ENTRY:
1590  case WID_BS_ELECTRIC_EXIT:
1591  case WID_BS_ELECTRIC_COMBO:
1592  case WID_BS_ELECTRIC_PBS:
1595 
1596  _cur_signal_type = (SignalType)((uint)((widget - WID_BS_SEMAPHORE_NORM) % (SIGTYPE_LAST + 1)));
1598 
1599  /* If 'remove' button of rail build toolbar is active, disable it. */
1600  if (_remove_button_clicked) {
1602  if (w != nullptr) ToggleRailButton_Remove(w);
1603  }
1604 
1605  break;
1606 
1607  case WID_BS_CONVERT:
1609  break;
1610 
1615  }
1616  break;
1617 
1622  }
1623  break;
1624 
1625  default: break;
1626  }
1627 
1628  this->InvalidateData();
1629  }
1630 
1636  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1637  {
1638  if (!gui_scope) return;
1640 
1641  this->SetWidgetLoweredState(WID_BS_CONVERT, _convert_signal_button);
1642 
1645  }
1646 };
1647 
1651  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1652  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_BUILD_SIGNAL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1653  EndContainer(),
1656  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_NORM), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP), EndContainer(), SetFill(1, 1),
1657  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_ENTRY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP), EndContainer(), SetFill(1, 1),
1658  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_EXIT), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP), EndContainer(), SetFill(1, 1),
1659  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_COMBO), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP), EndContainer(), SetFill(1, 1),
1660  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_PBS), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP), EndContainer(), SetFill(1, 1),
1661  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_PBS_OWAY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_PBS_OWAY_TOOLTIP), EndContainer(), SetFill(1, 1),
1662  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_BS_CONVERT), SetDataTip(SPR_IMG_SIGNAL_CONVERT, STR_BUILD_SIGNAL_CONVERT_TOOLTIP), SetFill(1, 1),
1663  EndContainer(),
1665  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_NORM), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP), EndContainer(), SetFill(1, 1),
1666  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_ENTRY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP), EndContainer(), SetFill(1, 1),
1667  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_EXIT), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP), EndContainer(), SetFill(1, 1),
1668  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_COMBO), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP), EndContainer(), SetFill(1, 1),
1669  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_PBS), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP), EndContainer(), SetFill(1, 1),
1670  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_PBS_OWAY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_PBS_OWAY_TOOLTIP), EndContainer(), SetFill(1, 1),
1671  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetFill(1, 1),
1672  NWidget(WWT_LABEL, COLOUR_DARK_GREEN, WID_BS_DRAG_SIGNALS_DENSITY_LABEL), SetDataTip(STR_ORANGE_INT, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetFill(1, 1),
1673  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1674  NWidget(NWID_SPACER), SetFill(1, 0),
1675  NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_BS_DRAG_SIGNALS_DENSITY_DECREASE), SetMinimalSize(9, 12), SetDataTip(AWV_DECREASE, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_DECREASE_TOOLTIP),
1676  NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_BS_DRAG_SIGNALS_DENSITY_INCREASE), SetMinimalSize(9, 12), SetDataTip(AWV_INCREASE, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP),
1677  NWidget(NWID_SPACER), SetFill(1, 0),
1678  EndContainer(),
1679  NWidget(NWID_SPACER), SetMinimalSize(0, 2), SetFill(1, 0),
1680  EndContainer(),
1681  EndContainer(),
1682  EndContainer(),
1683 };
1684 
1687  WDP_AUTO, "build_signal", 0, 0,
1690  _nested_signal_builder_widgets, lengthof(_nested_signal_builder_widgets)
1691 );
1692 
1696 static void ShowSignalBuilder(Window *parent)
1697 {
1698  new BuildSignalWindow(&_signal_builder_desc, parent);
1699 }
1700 
1702  BuildRailDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1703  {
1704  this->InitNested(TRANSPORT_RAIL);
1705  this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1706  }
1707 
1708  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1709  {
1710  if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1711 
1712  size->width = ScaleGUITrad(64) + 2;
1713  size->height = ScaleGUITrad(48) + 2;
1714  }
1715 
1716  void DrawWidget(const Rect &r, int widget) const override
1717  {
1718  if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1719 
1720  DrawTrainDepotSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype);
1721  }
1722 
1723  void OnClick(Point pt, int widget, int click_count) override
1724  {
1725  switch (widget) {
1726  case WID_BRAD_DEPOT_NE:
1727  case WID_BRAD_DEPOT_SE:
1728  case WID_BRAD_DEPOT_SW:
1729  case WID_BRAD_DEPOT_NW:
1730  this->RaiseWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1732  this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1733  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1734  this->SetDirty();
1735  break;
1736  }
1737  }
1738 };
1739 
1743  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1744  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1745  EndContainer(),
1746  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1749  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1751  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1752  EndContainer(),
1754  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1755  EndContainer(),
1756  EndContainer(),
1759  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1760  EndContainer(),
1762  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1763  EndContainer(),
1764  EndContainer(),
1765  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1766  EndContainer(),
1768  EndContainer(),
1769 };
1770 
1771 static WindowDesc _build_depot_desc(
1772  WDP_AUTO, nullptr, 0, 0,
1775  _nested_build_depot_widgets, lengthof(_nested_build_depot_widgets)
1776 );
1777 
1778 static void ShowBuildTrainDepotPicker(Window *parent)
1779 {
1780  new BuildRailDepotWindow(&_build_depot_desc, parent);
1781 }
1782 
1784  BuildRailWaypointWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1785  {
1786  this->CreateNestedTree();
1787 
1788  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX);
1789  matrix->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL));
1790 
1791  this->FinishInitNested(TRANSPORT_RAIL);
1792 
1793  matrix->SetCount(_waypoint_count);
1794  matrix->SetClicked(_cur_waypoint_type);
1795  }
1796 
1797  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1798  {
1799  switch (widget) {
1801  /* Three blobs high and wide. */
1802  size->width += resize->width * 2;
1803  size->height += resize->height * 2;
1804 
1805  /* Resizing in X direction only at blob size, but at pixel level in Y. */
1806  resize->height = 1;
1807  break;
1808 
1809  case WID_BRW_WAYPOINT:
1810  size->width = ScaleGUITrad(64) + 2;
1811  size->height = ScaleGUITrad(58) + 2;
1812  break;
1813  }
1814  }
1815 
1816  void DrawWidget(const Rect &r, int widget) const override
1817  {
1818  switch (GB(widget, 0, 16)) {
1819  case WID_BRW_WAYPOINT: {
1820  byte type = GB(widget, 16, 16);
1821  const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
1822  DrawWaypointSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), type, _cur_railtype);
1823 
1824  if (!IsStationAvailable(statspec)) {
1825  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
1826  }
1827  }
1828  }
1829  }
1830 
1831  void OnClick(Point pt, int widget, int click_count) override
1832  {
1833  switch (GB(widget, 0, 16)) {
1834  case WID_BRW_WAYPOINT: {
1835  byte type = GB(widget, 16, 16);
1836  this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
1837 
1838  /* Check station availability callback */
1839  const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
1840  if (!IsStationAvailable(statspec)) return;
1841 
1842  _cur_waypoint_type = type;
1843  this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
1844  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1845  this->SetDirty();
1846  break;
1847  }
1848  }
1849  }
1850 };
1851 
1855  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1856  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1857  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1858  EndContainer(),
1861  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(),
1862  EndContainer(),
1864  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL),
1865  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
1866  EndContainer(),
1867  EndContainer(),
1868 };
1869 
1870 static WindowDesc _build_waypoint_desc(
1871  WDP_AUTO, "build_waypoint", 0, 0,
1874  _nested_build_waypoint_widgets, lengthof(_nested_build_waypoint_widgets)
1875 );
1876 
1877 static void ShowBuildWaypointPicker(Window *parent)
1878 {
1879  new BuildRailWaypointWindow(&_build_waypoint_desc, parent);
1880 }
1881 
1886 {
1888 }
1889 
1894 void ReinitGuiAfterToggleElrail(bool disable)
1895 {
1896  extern RailType _last_built_railtype;
1897  if (disable && _last_built_railtype == RAILTYPE_ELECTRIC) {
1898  _last_built_railtype = _cur_railtype = RAILTYPE_RAIL;
1900  if (w != nullptr) w->ModifyRailType(_cur_railtype);
1901  }
1903 }
1904 
1906 static void SetDefaultRailGui()
1907 {
1909 
1910  extern RailType _last_built_railtype;
1911  RailType rt;
1913  case 2: {
1914  /* Find the most used rail type */
1915  uint count[RAILTYPE_END];
1916  memset(count, 0, sizeof(count));
1917  for (TileIndex t = 0; t < MapSize(); t++) {
1920  count[GetRailType(t)]++;
1921  }
1922  }
1923 
1924  rt = static_cast<RailType>(std::max_element(count + RAILTYPE_BEGIN, count + RAILTYPE_END) - count);
1925  if (count[rt] > 0) break;
1926 
1927  /* No rail, just get the first available one */
1928  FALLTHROUGH;
1929  }
1930  case 0: {
1931  /* Use first available type */
1932  std::vector<RailType>::const_iterator it = std::find_if(_sorted_railtypes.begin(), _sorted_railtypes.end(),
1933  [](RailType r){ return HasRailtypeAvail(_local_company, r); });
1934  rt = it != _sorted_railtypes.end() ? *it : RAILTYPE_BEGIN;
1935  break;
1936  }
1937  case 1: {
1938  /* Use last available type */
1939  std::vector<RailType>::const_reverse_iterator it = std::find_if(_sorted_railtypes.rbegin(), _sorted_railtypes.rend(),
1940  [](RailType r){ return HasRailtypeAvail(_local_company, r); });
1941  rt = it != _sorted_railtypes.rend() ? *it : RAILTYPE_BEGIN;
1942  break;
1943  }
1944  default:
1945  NOT_REACHED();
1946  }
1947 
1948  _last_built_railtype = _cur_railtype = rt;
1950  if (w != nullptr) w->ModifyRailType(_cur_railtype);
1951 }
1952 
1959 bool ResetSignalVariant(int32 p)
1960 {
1962 
1963  if (new_variant != _cur_signal_variant) {
1965  if (w != nullptr) {
1966  w->SetDirty();
1968  }
1969  _cur_signal_variant = new_variant;
1970  }
1971 
1972  return true;
1973 }
1974 
1980 {
1982 
1983  _convert_signal_button = false;
1984  _cur_signal_type = _default_signal_type[_settings_client.gui.default_signal_type];
1986 }
1987 
1994 DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
1995 {
1996  RailTypes used_railtypes;
1997  RailTypes avail_railtypes;
1998 
1999  const Company *c = Company::Get(_local_company);
2000 
2001  /* Find the used railtypes. */
2002  if (for_replacement) {
2003  avail_railtypes = GetCompanyRailtypes(c->index, false);
2004  used_railtypes = GetRailTypes(false);
2005  } else {
2006  avail_railtypes = c->avail_railtypes;
2007  used_railtypes = GetRailTypes(true);
2008  }
2009 
2010  DropDownList list;
2011 
2012  if (all_option) {
2013  list.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false));
2014  }
2015 
2016  Dimension d = { 0, 0 };
2017  RailType rt;
2018  /* Get largest icon size, to ensure text is aligned on each menu item. */
2019  if (!for_replacement) {
2021  if (!HasBit(used_railtypes, rt)) continue;
2022  const RailtypeInfo *rti = GetRailTypeInfo(rt);
2024  }
2025  }
2026 
2028  /* If it's not used ever, don't show it to the user. */
2029  if (!HasBit(used_railtypes, rt)) continue;
2030 
2031  const RailtypeInfo *rti = GetRailTypeInfo(rt);
2032 
2033  StringID str = for_replacement ? rti->strings.replace_text : (rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING);
2035  if (for_replacement) {
2036  item = new DropDownListParamStringItem(str, rt, !HasBit(avail_railtypes, rt));
2037  } else {
2038  DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt));
2039  iconitem->SetDimension(d);
2040  item = iconitem;
2041  }
2042  item->SetParam(0, rti->strings.menu_text);
2043  item->SetParam(1, rti->max_speed);
2044  list.emplace_back(item);
2045  }
2046 
2047  if (list.size() == 0) {
2048  /* Empty dropdowns are not allowed */
2049  list.emplace_back(new DropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true));
2050  }
2051 
2052  return list;
2053 }
EventState
State of handling an event.
Definition: window_type.h:711
Build rail along the game grid Y axis.
Definition: rail_widget.h:20
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:491
Functions related to OTTD&#39;s strings.
Window * ShowBuildRailToolbar(RailType railtype)
Open the build rail toolbar window for a specific rail type.
Definition: rail_gui.cpp:868
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
Selection for newstation class selection list.
Definition: rail_widget.h:66
Y direction.
static void ShowSignalBuilder(Window *parent)
Open the signal selection window.
Definition: rail_gui.cpp:1696
Button to select 5 tiles length station platforms.
Definition: rail_widget.h:51
don&#39;t allow building on structures
Definition: command_type.h:345
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: rail_gui.cpp:1051
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:275
Draw all cargoes.
Definition: station_gui.h:22
void SetupRailToolbar(RailType railtype)
Configures the rail toolbar for railtype given.
Definition: rail_gui.cpp:453
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
void ModifyRailType(RailType railtype)
Switch to another rail type.
Definition: rail_gui.cpp:473
Build a depot with the entrance in the south east.
Definition: rail_widget.h:101
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: rail_gui.cpp:743
Definition of stuff that is very close to a company, like the company struct itself.
#define FOR_ALL_SORTED_RAILTYPES(var)
Loop header for iterating over railtypes, sorted by sortorder.
Definition: rail.h:471
static const NWidgetPart _nested_signal_builder_widgets[]
Nested widget definition of the build signal window.
Definition: rail_gui.cpp:1649
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: rail_gui.cpp:1547
uint32 widget_data
Data of the widget.
Definition: widget_type.h:303
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:304
Build a depot with the entrance in the north west.
Definition: rail_widget.h:103
Build an electric exit block signal.
Definition: rail_widget.h:87
Select station (when joining stations); Window numbers:
Definition: window_type.h:235
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
Button to select stations with 5 platforms.
Definition: rail_widget.h:43
Data about how and where to blit pixels.
Definition: gfx_type.h:154
build a waypoint
Definition: command_type.h:193
void DrawSignalSprite(byte widget_index, SpriteID image) const
Draw dynamic a signal-sprite in a button in the signal GUI Draw the sprite +1px to the right and down...
Definition: rail_gui.cpp:1500
Helper for determining the chosen platform width.
Definition: rail_widget.h:73
Matrix container.
Definition: widget_type.h:76
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
Definition: settings_type.h:94
Button to select &#39;/&#39; view.
Definition: rail_widget.h:36
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:610
Station placement.
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
Waypoint class.
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:110
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Point pos
Location, in tile "units", of the northern tile of the selected area.
Offset at right of a matrix cell.
Definition: window_gui.h:77
static void GenericPlaceSignals(TileIndex tile)
Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSign...
Definition: rail_gui.cpp:210
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3215
SignalType
Type of signal, i.e.
Definition: signal_type.h:23
SpriteID auto_rail
button for the autorail construction
Definition: rail.h:154
bool enable_signal_gui
show the signal GUI when the signal button is pressed
area of land of limited size
Maps accessors for stations.
Build a semaphore normal block signal.
Definition: rail_widget.h:79
Track along the x-axis (north-east to south-west)
Definition: track_type.h:21
All data for a single hotkey.
Definition: hotkeys.h:22
High level window description.
Definition: window_gui.h:166
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition: rail.h:174
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1485
Track in the lower corner of the tile (south)
Definition: track_type.h:24
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:442
static void PlaceRail_Bridge(TileIndex tile, Window *w)
Start placing a rail bridge.
Definition: rail_gui.cpp:261
Build a station.
Definition: rail_widget.h:25
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Train vehicle type.
Definition: vehicle_type.h:24
bool station_show_coverage
whether to highlight coverage area
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: rail_gui.cpp:523
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:35
Hotkey related functions.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: rail_gui.cpp:1373
Functions related to dates.
SpriteID build_y_rail
button for building single rail in Y direction
Definition: rail.h:153
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition: newgrf_class.h:44
Helper for determining the chosen platform length.
Definition: rail_widget.h:74
int sig_sprite_bottom_offset
Maximum extent of signal GUI sprite from reference point towards bottom.
Definition: rail_gui.cpp:1491
Centered label.
Definition: widget_type.h:55
Northwest.
Scrollbar data structure.
Definition: widget_type.h:587
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:403
Build a semaphore one way path signal.
Definition: rail_widget.h:84
void ShowSelectStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Contains enums and function declarations connected with stations GUI.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
uint8 default_rail_type
the default rail type for the rail GUI
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Left track.
Definition: track_type.h:44
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
remove signals along a track (by dragging)
Definition: command_type.h:302
Horizontal container.
Definition: widget_type.h:73
Build an electric normal block signal.
Definition: rail_widget.h:85
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1130
byte station_type
Station type within the currently selected custom station class (if newstations is true ) ...
Definition: rail_gui.cpp:61
The passed event is not handled.
Definition: window_type.h:713
X direction.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1716
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2423
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
void CheckSelectedSize(const StationSpec *statspec)
Verify whether the currently selected station size is allowed after selecting a new station class/typ...
Definition: rail_gui.cpp:909
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
Definition: sprites.h:1489
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
Build a semaphore path signal.
Definition: rail_widget.h:83
Build a bridge.
Definition: rail_widget.h:27
Drag only in X axis with limited size.
Flag for invalid railtype.
Definition: rail_type.h:34
Button to select 6 tiles length station platforms.
Definition: rail_widget.h:52
Matrix with waypoints.
Definition: rail_widget.h:108
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1816
similar to VMP_RAILDIRS, but with different cursor
Station specification.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: rail_gui.cpp:1189
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: rail_gui.cpp:1636
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
Definition: rail.cpp:206
Default station class.
Build a depot.
Definition: rail_widget.h:23
byte drag_signals_density
many signals density
drag only in Y axis
Definition: viewport_type.h:99
Drag only in Y axis with limited size.
Build an electric combo block signal.
Definition: rail_widget.h:88
Functions related to vehicles.
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
Selection for panel and resize at bottom right for newstation.
Definition: rail_widget.h:68
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:699
Button to select 2 tiles length station platforms.
Definition: rail_widget.h:48
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
Build signals.
Definition: rail_widget.h:26
add signals along a track (by dragging)
Definition: command_type.h:301
Build an electric entry block signal.
Definition: rail_widget.h:86
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
static bool IsStationAvailable(const StationSpec *statspec)
Check whether a station type can be build.
Definition: rail_gui.cpp:77
flag for invalid roadtype
Definition: road_type.h:27
static void ShowStationBuilder(Window *parent)
Open station build window.
Definition: rail_gui.cpp:1482
Close box (at top-left of a window)
Definition: widget_type.h:67
Offset at top of a matrix cell.
Definition: window_gui.h:78
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
Definition: viewport.cpp:2648
Button for turning coverage highlighting off.
Definition: rail_widget.h:57
Build a depot with the entrance in the north east.
Definition: rail_widget.h:100
void ShowSelectWaypointIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the waypoint selection window when needed.
build a rail station
Definition: command_type.h:182
A railway.
Definition: tile_type.h:42
static bool RailToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition: rail_gui.cpp:301
Rail toolbar management class.
Definition: rail_gui.cpp:417
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1502
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1165
bool persistent_buildingtools
keep the building tools active after usage
Common return value for all commands.
Definition: command_type.h:23
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Definition: rail_gui.cpp:1994
CursorID autorail
Cursor for autorail tool.
Definition: rail.h:166
A single waypoint.
Definition: rail_widget.h:109
Types related to the rail widgets.
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
Build rail along the game view X axis.
Definition: rail_widget.h:19
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
vertical left
Scrollbar of the WID_BRAS_NEWST_LIST.
Definition: rail_widget.h:71
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:24
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: rail_gui.cpp:615
struct RailtypeInfo::@39 strings
Strings associated with the rail type.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: rail_gui.cpp:509
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: rail_gui.cpp:1723
Common string list item.
Definition: dropdown_type.h:39
uint16 w
The width of the area.
Definition: tilearea_type.h:18
Dimension sig_sprite_size
Maximum size of signal GUI sprites.
Definition: rail_gui.cpp:1490
Determine whether a newstation should be made available to build.
Rail construction.
Definition: sound_type.h:69
Build a depot with the entrance in the south west.
Definition: rail_widget.h:102
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition: rail.h:175
StationSettings station
settings related to station management
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/types etc.
Button to select stations with 6 platforms.
Definition: rail_widget.h:44
CursorID rail_ew
Cursor for building rail in E-W direction.
Definition: rail.h:164
Functions, definitions and such used only by the GUI.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1481
Button for turning coverage highlighting on.
Definition: rail_widget.h:58
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:124
Button to select single tile length station platforms.
Definition: rail_widget.h:47
Right track.
Definition: track_type.h:45
bool newstations
Are custom station definitions available?
Definition: rail_gui.cpp:59
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:668
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: rail_gui.cpp:690
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Functions related to (drawing on) viewports.
static SignalType _cur_signal_type
set the signal type (for signal GUI)
Definition: rail_gui.cpp:51
static void BuildRailClick_Remove(Window *w)
The "remove"-button click proc of the build-rail toolbar.
Definition: rail_gui.cpp:322
SpriteID signals[SIGTYPE_END][2][2]
signal GUI sprites (type, variant, state)
Definition: rail.h:158
Data structure for an opened window.
Definition: window_gui.h:276
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
Track in the right corner of the tile (east)
Definition: track_type.h:26
build a single rail track
Definition: command_type.h:178
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1030
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1044
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
Button to select stations with 7 platforms.
Definition: rail_widget.h:45
Bottom offset of image in the button.
Definition: window_gui.h:41
Point selstart
The location where the dragging started.
Display of selected station type.
Definition: rail_widget.h:69
Button to enable drag and drop type station placement.
Definition: rail_widget.h:55
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:19
Point selend
The location where the drag currently ends.
Electric rails.
Definition: rail_type.h:30
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
Build a tunnel.
Definition: rail_widget.h:28
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:96
Selection for default-size button for newstation.
Definition: rail_widget.h:65
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Decrease the signal density.
Definition: rail_widget.h:93
Invisible widget that takes some space.
Definition: widget_type.h:77
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
static const NWidgetPart _nested_build_depot_widgets[]
Nested widget definition of the build rail depot window.
Definition: rail_gui.cpp:1741
Southeast.
Offset at bottom of a matrix cell.
Definition: window_gui.h:79
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
Caption of the window.
Definition: rail_widget.h:16
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:441
The y axis.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1108
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1957
masks the drag-direction
Signal placement.
Button to select 4 tiles length station platforms.
Definition: rail_widget.h:50
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:208
The client is spectating.
Definition: company_type.h:35
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
Button to select &#39;\&#39; view.
Definition: rail_widget.h:37
List item with icon and string.
Definition: dropdown_type.h:81
SoundSettings sound
sound effect settings
Header file for things common for tunnels and bridges.
static WindowDesc _station_builder_desc(WDP_AUTO, "build_station_rail", 350, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_station_builder_widgets, lengthof(_nested_station_builder_widgets))
High level window description of the station-build window (default & newGRF)
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
Definition: viewport.cpp:2405
Button to select 7 tiles length station platforms.
Definition: rail_widget.h:53
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
Definition: rail_gui.cpp:1894
int last_user_action
Last started user action.
Definition: rail_gui.cpp:419
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
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:475
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
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
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
drag in X or Y direction
Definition: viewport_type.h:97
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
Standard non-electric rails.
Definition: rail_type.h:29
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
Left and right track.
Definition: track_type.h:48
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
static bool HasStationTileRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition: station_map.h:146
Definition of base types and functions in a cross-platform compatible way.
Build waypoint; Window numbers:
Definition: window_type.h:416
Build rail along the game grid X axis.
Definition: rail_widget.h:18
A number of safeguards to prevent using unsafe methods.
SpriteID build_ns_rail
button for building single rail in N-S direction
Definition: rail.h:150
uint8 default_signal_type
the signal type to build by default.
List of hotkeys for a window.
Definition: hotkeys.h:40
uint line_height
Height of a single line in the newstation selection matrix (WID_BRAS_NEWST_LIST widget).
Definition: rail_gui.cpp:899
no-entry signal
Definition: signal_type.h:29
static void ToggleRailButton_Remove(Window *w)
Toggles state of the Remove button of Build rail toolbar.
Definition: rail_gui.cpp:287
RailTypes GetRailTypes(bool introduces)
Get list of rail types, regardless of company availability.
Definition: rail.cpp:282
Geometry functions.
rectangle (stations, depots, ...)
bool ResetSignalVariant(int32 p)
Updates the current signal variant used in the signal GUI to the one adequate to current year...
Definition: rail_gui.cpp:1959
Simple depressed panel.
Definition: widget_type.h:48
Year semaphore_build_before
build semaphore signals automatically before this year
static EventState RailToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildRailToolbarWindow.
Definition: rail_gui.cpp:780
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:421
static void PlaceRail_Station(TileIndex tile)
Place a rail station.
Definition: rail_gui.cpp:184
Station removal.
Represents the covered area of e.g.
Definition: tilearea_type.h:16
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
static const NWidgetPart _nested_build_waypoint_widgets[]
Nested widget definition for the build NewGRF rail waypoint window.
Definition: rail_gui.cpp:1853
Offset at left of a matrix cell.
Definition: window_gui.h:76
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3454
GUI stuff related to terraforming.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:228
the lowest valid value
CursorID rail_nwse
Cursor for building rail in Y direction.
Definition: rail.h:165
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
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:498
byte station_numtracks
the number of platforms to default on for rail stations
Build station; Window numbers:
Definition: window_type.h:390
Build rail along the game view Y axis.
Definition: rail_widget.h:17
SpriteID convert_rail
button for converting rail
Definition: rail.h:157
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
List with available newstation classes.
Definition: rail_widget.h:70
autorail (one piece), lower bits: direction
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building a tunnel.
Definition: rail_gui.cpp:273
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition: viewport.cpp:2605
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
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Build a waypoint.
Definition: rail_widget.h:24
Bridge placement.
Grid of rows and columns.
Definition: widget_type.h:57
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:40
The current signal density.
Definition: rail_widget.h:92
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:388
Scrollbar for the matrix.
Definition: rail_widget.h:110
Right offset of the image in the button.
Definition: window_gui.h:39
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:46
static WindowDesc _signal_builder_desc(WDP_AUTO, "build_signal", 0, 0, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WDF_CONSTRUCTION, _nested_signal_builder_widgets, lengthof(_nested_signal_builder_widgets))
Signal selection window description.
Also allow &#39;diagonal rectangles&#39;. Only usable in combination with HT_RECT or HT_POINT.
Functions related to sound.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Functions to cache sprites in memory.
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.
static SignalVariant _cur_signal_variant
set the signal variant (for signal GUI)
Definition: rail_gui.cpp:50
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1175
bool Failed() const
Did this command fail?
Definition: command_type.h:159
drag only in horizontal direction
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:203
static void PlaceRail_Waypoint(TileIndex tile)
Place a rail waypoint.
Definition: rail_gui.cpp:152
void OnPaint() override
The window must be repainted.
Definition: rail_gui.cpp:1000
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition: viewport.cpp:3078
static bool _convert_signal_button
convert signal button in the signal GUI pressed
Definition: rail_gui.cpp:49
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:20
Autorail tool.
Definition: rail_widget.h:21
build a signal
Definition: command_type.h:184
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1754
static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track)
Try to add an additional rail-track at the entrance of a depot.
Definition: rail_gui.cpp:108
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:589
byte station_platlength
the platform length, in tiles, for rail stations
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
bool drag_signals_fixed_distance
keep fixed distance between signals when dragging
StringID replace_text
Text used in the autoreplace GUI.
Definition: rail.h:177
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:639
Build toolbar; Window numbers:
Definition: window_type.h:66
SpriteID build_depot
button for building depots
Definition: rail.h:155
static TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction...
Definition: track_func.h:581
CursorID depot
Cursor for building a depot.
Definition: rail.h:167
Rail placement.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
Build signal toolbar; Window numbers:
Definition: window_type.h:91
Panel used at each cell of the matrix.
Definition: rail_widget.h:62
static byte _cur_waypoint_type
Currently selected waypoint type.
Definition: rail_gui.cpp:48
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: rail_gui.cpp:1708
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:36
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:611
Mask for the tile drag-type modes.
convert a rail type
Definition: command_type.h:191
Convert other rail to this type.
Definition: rail_widget.h:30
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
static DiagDirection _build_depot_direction
Currently selected depot direction.
Definition: rail_gui.cpp:46
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
The X axis.
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
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:1162
CursorID convert
Cursor for converting track.
Definition: rail.h:169
Lower track.
Definition: track_type.h:43
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1567
Transport by train.
Functions related to companies.
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
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
Base class for engines.
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1526
Button to select stations with 4 platforms.
Definition: rail_widget.h:42
area of land in X and Y directions
Header file for NewGRF stations.
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
GUISettings gui
settings related to the GUI
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:50
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: rail_gui.cpp:1579
Align toward the toolbar.
Definition: window_gui.h:156
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
StationClassID
Increase the signal density.
Definition: rail_widget.h:94
Rail conversion.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
CursorID rail_swne
Cursor for building rail in X direction.
Definition: rail.h:163
static void HandleAutoSignalPlacement()
Build new signals or remove signals or (if only one tile marked) edit a signal.
Definition: rail_gui.cpp:378
Upper track.
Definition: track_type.h:42
Build a semaphore exit block signal.
Definition: rail_widget.h:81
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
bool HasRailtypeAvail(const CompanyID company, const RailType railtype)
Finds out if a company has a certain buildable railtype available.
Definition: rail.cpp:186
bool modified_catchment
different-size catchment areas
static bool IsLevelCrossingTile(TileIndex t)
Return whether a tile is a level crossing tile.
Definition: road_map.h:94
Track
These are used to specify a single track.
Definition: track_type.h:19
Top offset of image in the button.
Definition: window_gui.h:40
Catchment for train stations with "modified catchment" enabled.
Definition: station_type.h:79
Vertical container.
Definition: widget_type.h:75
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Old-fashioned semaphore signal.
Definition: signal_type.h:18
Availability of station in construction window.
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.
Functions related to zooming.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: rail_gui.cpp:1197
Bulldozer to remove rail.
Definition: rail_widget.h:29
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
SpriteID build_tunnel
button for building a tunnel
Definition: rail.h:156
bool station_dragdrop
whether drag and drop is enabled for stations
uint8 cycle_signal_types
what signal types to cycle with the build signal tool.
Normal rail tile without signals.
Definition: rail_map.h:24
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:185
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
StationClassID station_class
Currently selected custom station class (if newstations is true )
Definition: rail_gui.cpp:60
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
uint coverage_height
Height of the coverage texts.
Definition: rail_gui.cpp:900
bool confirm
Play sound effect on successful constructions or other actions.
Button to select stations with a single platform.
Definition: rail_widget.h:39
Axis orientation
Currently selected rail station orientation.
Definition: rail_gui.cpp:57
Button to select 3 tiles length station platforms.
Definition: rail_widget.h:49
Functions related to commands.
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: rail_gui.cpp:1527
static RailType _cur_railtype
Rail type of the current build-rail toolbar.
Definition: rail_gui.cpp:44
Coordinates of a point in 2D.
remove a single rail track
Definition: command_type.h:179
struct RailtypeInfo::@37 gui_sprites
struct containing the sprites for the rail GUI.
Build a semaphore combo block signal.
Definition: rail_widget.h:82
used for autorail highlighting (longer stretches), lower bits: direction
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:770
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1082
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition: rail_gui.cpp:1979
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
build a train depot
Definition: command_type.h:183
Convert the signal.
Definition: rail_widget.h:91
Scrollbar * vscroll2
Vertical scrollbar of the matrix with new stations.
Definition: rail_gui.cpp:902
special mode used for highlighting while dragging (and for tunnels/docks)
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:620
Matrix widget displaying the available stations.
Definition: rail_widget.h:61
Build a semaphore entry block signal.
Definition: rail_widget.h:80
Button to select stations with 3 platforms.
Definition: rail_widget.h:41
Scrollbar * vscroll
Vertical scrollbar of the new station list.
Definition: rail_gui.cpp:901
static const Track _place_depot_extra_track[12]
Additional pieces of track to add at the entrance of a depot.
Definition: rail_gui.cpp:117
Functions that have tunnels and bridges in common.
Functions related to waypoints.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: rail_gui.cpp:1558
drag only in vertical direction
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
const struct GRFFile * grffile
grf file that introduced this entity
remove a signal
Definition: command_type.h:185
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:64
horizontal lower
Used for iterations.
Definition: rail_type.h:33
SpriteID tunnel
tunnel sprites base
Definition: rail.h:142
CursorID rail_ns
Cursor for building rail in N-S direction.
Definition: rail.h:162
remove a (rectangle of) tiles from a rail station
Definition: command_type.h:190
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:120
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.
Button to select stations with 2 platforms.
Definition: rail_widget.h:40
DiagDirection
Enumeration for diagonal directions.
Light signal.
Definition: signal_type.h:17
byte callback_mask
Bitmask of station callbacks that have to be called.
remove a rail track
Definition: command_type.h:177
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
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: rail_gui.cpp:682
byte disallowed_lengths
Bitmask of platform lengths available for the station.
Northeast, upper right on your monitor.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:368
Empty space for the coverage texts.
Definition: rail_widget.h:59
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1971
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.
Vertical scrollbar.
Definition: widget_type.h:82
The passed event is handled.
Definition: window_type.h:712
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: rail_gui.cpp:442
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:251
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
all rail directions
Destroy something with dynamite!
Definition: rail_widget.h:22
StringID name
Name of this station.
Find a place automatically.
Definition: window_gui.h:154
(Toggle) Button with image
Definition: widget_type.h:50
SpriteID build_x_rail
button for building single rail in X direction
Definition: rail.h:151
String list item with parameters.
Definition: dropdown_type.h:56
static RailStationGUISettings _railstation
Settings of the station builder GUI.
Definition: rail_gui.cpp:64
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: rail_gui.cpp:1831
RailType railtype
Rail type to build.
Definition: rail_gui.cpp:418
void InitializeRailGui()
Initialize rail building GUI settings.
Definition: rail_gui.cpp:1885
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition: rail_gui.cpp:621
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
Track in the left corner of the tile (west)
Definition: track_type.h:25
byte disallowed_platforms
Bitmask of number of platforms available for the station.
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition: rail_gui.cpp:765
GUI functions that shouldn&#39;t be here.
static const DiagDirection _place_depot_extra_dir[12]
Direction to check for existing track pieces.
Definition: rail_gui.cpp:124
SignalVariant
Variant of the signal, i.e.
Definition: signal_type.h:16
normal pbs signal
Definition: signal_type.h:28
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: rail_gui.cpp:759
void SetClicked(int clicked)
Sets the clicked widget in the matrix.
Definition: widget.cpp:1485
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
Draw a waypoint.
Definition: waypoint.cpp:27
uint16 h
The height of the area.
Definition: tilearea_type.h:19
Build an electric one way path signal.
Definition: rail_widget.h:90
normal signal
Definition: signal_type.h:24
static byte _waypoint_count
Number of waypoint types.
Definition: rail_gui.cpp:47
SpriteID build_ew_rail
button for building single rail in E-W direction
Definition: rail.h:152
Left offset of the image in the button.
Definition: window_gui.h:38
Selection for newstation image matrix.
Definition: rail_widget.h:67
byte station_count
Number of custom stations (if newstations is true )
Definition: rail_gui.cpp:62
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:33
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1093
void OnResize() override
Called after the window got resized.
Definition: rail_gui.cpp:1182
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
remove a (rectangle of) tiles from a rail waypoint
Definition: command_type.h:195
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: rail_gui.cpp:1797
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:62
Axis
Allow incrementing of DiagDirDiff variables.
Game options window; Window numbers:
Definition: window_type.h:606
Used for iterations.
Definition: rail_type.h:28
Horizontal container that doesn&#39;t change the order of the widgets for RTL languages.
Definition: widget_type.h:74
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:835
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:115
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
Build an electric path signal.
Definition: rail_widget.h:89
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
Track in the upper corner of the tile (north)
Definition: track_type.h:23
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
Scrollbar of the matrix widget.
Definition: rail_widget.h:63
(Toggle) Button with text
Definition: widget_type.h:53
Upper and lower track.
Definition: track_type.h:47
Southwest.
static void SetDefaultRailGui()
Set the initial (default) railtype to use.
Definition: rail_gui.cpp:1906
build a rail track
Definition: command_type.h:176
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
StringID name
Name of this class.
Definition: newgrf_class.h:39