OpenTTD
rail_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "gui.h"
14 #include "window_gui.h"
15 #include "station_gui.h"
16 #include "terraform_gui.h"
17 #include "viewport_func.h"
18 #include "command_func.h"
19 #include "waypoint_func.h"
20 #include "newgrf_station.h"
21 #include "company_base.h"
22 #include "strings_func.h"
23 #include "window_func.h"
24 #include "date_func.h"
25 #include "sound_func.h"
26 #include "company_func.h"
27 #include "widgets/dropdown_type.h"
28 #include "tunnelbridge.h"
29 #include "tilehighlight_func.h"
30 #include "spritecache.h"
31 #include "core/geometry_func.hpp"
32 #include "hotkeys.h"
33 #include "engine_base.h"
34 #include "vehicle_func.h"
35 #include "zoom_func.h"
36 #include "rail_gui.h"
37 
38 #include "station_map.h"
39 #include "tunnelbridge_map.h"
40 
41 #include "widgets/rail_widget.h"
42 
43 #include "safeguards.h"
44 
45 
49 static byte _waypoint_count = 1;
50 static byte _cur_waypoint_type;
54 
55 /* Map the setting: default_signal_type to the corresponding signal type */
56 static const SignalType _default_signal_type[] = {SIGTYPE_NORMAL, SIGTYPE_PBS, SIGTYPE_PBS_ONEWAY};
57 
60 
61  bool newstations;
63  byte station_type;
65 };
67 
68 
69 static void HandleStationPlacement(TileIndex start, TileIndex end);
70 static void ShowBuildTrainDepotPicker(Window *parent);
71 static void ShowBuildWaypointPicker(Window *parent);
72 static void ShowStationBuilder(Window *parent);
73 static void ShowSignalBuilder(Window *parent);
74 
79 static bool IsStationAvailable(const StationSpec *statspec)
80 {
81  if (statspec == nullptr || !HasBit(statspec->callback_mask, CBM_STATION_AVAIL)) return true;
82 
83  uint16 cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
84  if (cb_res == CALLBACK_FAILED) return true;
85 
87 }
88 
89 void CcPlaySound_SPLAT_RAIL(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
90 {
91  if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
92 }
93 
94 static void GenericPlaceRail(TileIndex tile, int cmd)
95 {
96  DoCommandP(tile, _cur_railtype, cmd,
98  CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK) :
99  CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK),
100  CcPlaySound_SPLAT_RAIL);
101 }
102 
110 static void PlaceExtraDepotRail(TileIndex tile, DiagDirection dir, Track track)
111 {
112  if (GetRailTileType(tile) != RAIL_TILE_NORMAL) return;
113  if ((GetTrackBits(tile) & DiagdirReachesTracks(dir)) == 0) return;
114 
116 }
117 
119 static const Track _place_depot_extra_track[12] = {
120  TRACK_LEFT, TRACK_UPPER, TRACK_UPPER, TRACK_RIGHT, // First additional track for directions 0..3
121  TRACK_X, TRACK_Y, TRACK_X, TRACK_Y, // Second additional track
122  TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT, TRACK_LOWER, // Third additional track
123 };
124 
130 };
131 
132 void CcRailDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
133 {
134  if (result.Failed()) return;
135 
136  DiagDirection dir = (DiagDirection)p2;
137 
138  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
140 
141  tile += TileOffsByDiagDir(dir);
142 
143  if (IsTileType(tile, MP_RAILWAY)) {
147  }
148 }
149 
154 static void PlaceRail_Waypoint(TileIndex tile)
155 {
158  return;
159  }
160 
161  Axis axis = GetAxisForNewWaypoint(tile);
162  if (IsValidAxis(axis)) {
163  /* Valid tile for waypoints */
165  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
166  } else {
167  /* Tile where we can't build rail waypoints. This is always going to fail,
168  * but provides the user with a proper error message. */
169  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));
170  }
171 }
172 
173 void CcStation(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
174 {
175  if (result.Failed()) return;
176 
177  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
178  /* Only close the station builder window if the default station and non persistent building is chosen. */
180 }
181 
186 static void PlaceRail_Station(TileIndex tile)
187 {
190  VpSetPlaceSizingLimit(-1);
193  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
194  } else {
196  uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
197 
200  if (!_railstation.orientation) Swap(w, h);
201 
202  CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION), CcStation, "" };
203  ShowSelectStationIfNeeded(cmdcont, TileArea(tile, w, h));
204  }
205 }
206 
213 {
215 
216  if (trackbits & TRACK_BIT_VERT) { // N-S direction
217  trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT;
218  }
219 
220  if (trackbits & TRACK_BIT_HORZ) { // E-W direction
221  trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
222  }
223 
224  Track track = FindFirstTrack(trackbits);
225 
227  DoCommandP(tile, track, 0, CMD_REMOVE_SIGNALS | CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM), CcPlaySound_SPLAT_RAIL);
228  } else {
229  const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
230 
231  /* Map the setting cycle_signal_types to the lower and upper allowed signal type. */
232  static const uint cycle_bounds[] = {SIGTYPE_NORMAL | (SIGTYPE_LAST_NOPBS << 3), SIGTYPE_PBS | (SIGTYPE_LAST << 3), SIGTYPE_NORMAL | (SIGTYPE_LAST << 3)};
233 
234  /* various bitstuffed elements for CmdBuildSingleSignal() */
235  uint32 p1 = track;
236 
237  if (w != nullptr) {
238  /* signal GUI is used */
239  SB(p1, 3, 1, _ctrl_pressed);
240  SB(p1, 4, 1, _cur_signal_variant);
241  SB(p1, 5, 3, _cur_signal_type);
242  SB(p1, 8, 1, _convert_signal_button);
243  SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]);
244  } else {
245  SB(p1, 3, 1, _ctrl_pressed);
247  SB(p1, 5, 3, _default_signal_type[_settings_client.gui.default_signal_type]);
248  SB(p1, 8, 1, 0);
249  SB(p1, 9, 6, cycle_bounds[_settings_client.gui.cycle_signal_types]);
250  }
251 
252  DoCommandP(tile, p1, 0, CMD_BUILD_SIGNALS |
253  CMD_MSG((w != nullptr && _convert_signal_button) ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
254  CcPlaySound_SPLAT_RAIL);
255  }
256 }
257 
263 static void PlaceRail_Bridge(TileIndex tile, Window *w)
264 {
265  if (IsBridgeTile(tile)) {
266  TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
267  Point pt = {0, 0};
268  w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
269  } else {
271  }
272 }
273 
275 void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
276 {
277  if (result.Succeeded()) {
278  if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_SPLAT_RAIL, tile);
280  } else {
282  }
283 }
284 
290 {
295  SetSelectionRed(_remove_button_clicked);
296 }
297 
304 {
305  if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false;
306 
307  /* allow ctrl to switch remove mode only for these widgets */
308  for (uint i = WID_RAT_BUILD_NS; i <= WID_RAT_BUILD_STATION; i++) {
309  if ((i <= WID_RAT_AUTORAIL || i >= WID_RAT_BUILD_WAYPOINT) && w->IsWidgetLowered(i)) {
311  return true;
312  }
313  }
314 
315  return false;
316 }
317 
318 
325 {
326  if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return;
328  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
329 
330  /* handle station builder */
333  /* starting drag & drop remove */
335  SetTileSelectSize(1, 1);
336  } else {
337  VpSetPlaceSizingLimit(-1);
338  }
339  } else {
340  /* starting station build mode */
344  if (_railstation.orientation == 0) Swap(x, y);
345  SetTileSelectSize(x, y);
346  } else {
347  VpSetPlaceSizingLimit(_settings_game.station.station_spread);
348  }
349  }
350  }
351 }
352 
353 static void DoRailroadTrack(int mode)
354 {
355  DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 6),
357  CMD_REMOVE_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK) :
358  CMD_BUILD_RAILROAD_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK),
359  CcPlaySound_SPLAT_RAIL);
360 }
361 
362 static void HandleAutodirPlacement()
363 {
364  int trackstat = _thd.drawstyle & HT_DIR_MASK; // 0..5
365 
366  if (_thd.drawstyle & HT_RAIL) { // one tile case
367  GenericPlaceRail(TileVirtXY(_thd.selend.x, _thd.selend.y), trackstat);
368  return;
369  }
370 
371  DoRailroadTrack(trackstat);
372 }
373 
381 {
382  uint32 p2 = GB(_thd.drawstyle, 0, 3); // 0..5
383 
384  if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT) { // one tile case
385  GenericPlaceSignals(TileVirtXY(_thd.selend.x, _thd.selend.y));
386  return;
387  }
388 
389  const Window *w = FindWindowById(WC_BUILD_SIGNAL, 0);
390 
391  if (w != nullptr) {
392  /* signal GUI is used */
393  SB(p2, 3, 1, 0);
394  SB(p2, 4, 1, _cur_signal_variant);
395  SB(p2, 6, 1, _ctrl_pressed);
396  SB(p2, 7, 3, _cur_signal_type);
399  } else {
400  SB(p2, 3, 1, 0);
402  SB(p2, 6, 1, _ctrl_pressed);
403  SB(p2, 7, 3, _default_signal_type[_settings_client.gui.default_signal_type]);
406  }
407 
408  /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
409  * in a network game can specify his/her own signal density */
410  DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), p2,
412  CMD_REMOVE_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM) :
413  CMD_BUILD_SIGNAL_TRACK | CMD_MSG(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE),
414  CcPlaySound_SPLAT_RAIL);
415 }
416 
417 
422 
423  BuildRailToolbarWindow(WindowDesc *desc, RailType railtype) : Window(desc)
424  {
425  this->InitNested(TRANSPORT_RAIL);
426  this->SetupRailToolbar(railtype);
427  this->DisableWidget(WID_RAT_REMOVE);
428  this->last_user_action = WIDGET_LIST_END;
429 
431  }
432 
434  {
435  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
437  }
438 
444  void OnInvalidateData(int data = 0, bool gui_scope = true) override
445  {
446  if (!gui_scope) return;
447 
448  if (!CanBuildVehicleInfrastructure(VEH_TRAIN)) delete this;
449  }
450 
455  void SetupRailToolbar(RailType railtype)
456  {
457  this->railtype = railtype;
458  const RailtypeInfo *rti = GetRailTypeInfo(railtype);
459 
460  assert(railtype < RAILTYPE_END);
461  this->GetWidget<NWidgetCore>(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail;
463  this->GetWidget<NWidgetCore>(WID_RAT_BUILD_EW)->widget_data = rti->gui_sprites.build_ew_rail;
465  this->GetWidget<NWidgetCore>(WID_RAT_AUTORAIL)->widget_data = rti->gui_sprites.auto_rail;
467  this->GetWidget<NWidgetCore>(WID_RAT_CONVERT_RAIL)->widget_data = rti->gui_sprites.convert_rail;
469  }
470 
475  void ModifyRailType(RailType railtype)
476  {
477  this->SetupRailToolbar(railtype);
478  this->ReInit();
479  }
480 
481  void UpdateRemoveWidgetStatus(int clicked_widget)
482  {
483  switch (clicked_widget) {
484  case WID_RAT_REMOVE:
485  /* If it is the removal button that has been clicked, do nothing,
486  * as it is up to the other buttons to drive removal status */
487  return;
488 
489  case WID_RAT_BUILD_NS:
490  case WID_RAT_BUILD_X:
491  case WID_RAT_BUILD_EW:
492  case WID_RAT_BUILD_Y:
493  case WID_RAT_AUTORAIL:
497  /* Removal button is enabled only if the rail/signal/waypoint/station
498  * button is still lowered. Once raised, it has to be disabled */
499  this->SetWidgetDisabledState(WID_RAT_REMOVE, !this->IsWidgetLowered(clicked_widget));
500  break;
501 
502  default:
503  /* When any other buttons than rail/signal/waypoint/station, raise and
504  * disable the removal button */
505  this->DisableWidget(WID_RAT_REMOVE);
506  this->RaiseWidget(WID_RAT_REMOVE);
507  break;
508  }
509  }
510 
511  void SetStringParameters(int widget) const override
512  {
513  if (widget == WID_RAT_CAPTION) {
514  const RailtypeInfo *rti = GetRailTypeInfo(this->railtype);
515  if (rti->max_speed > 0) {
516  SetDParam(0, STR_TOOLBAR_RAILTYPE_VELOCITY);
518  SetDParam(2, rti->max_speed);
519  } else {
521  }
522  }
523  }
524 
525  void OnClick(Point pt, int widget, int click_count) override
526  {
527  if (widget < WID_RAT_BUILD_NS) return;
528 
529  _remove_button_clicked = false;
530  switch (widget) {
531  case WID_RAT_BUILD_NS:
533  this->last_user_action = widget;
534  break;
535 
536  case WID_RAT_BUILD_X:
538  this->last_user_action = widget;
539  break;
540 
541  case WID_RAT_BUILD_EW:
543  this->last_user_action = widget;
544  break;
545 
546  case WID_RAT_BUILD_Y:
548  this->last_user_action = widget;
549  break;
550 
551  case WID_RAT_AUTORAIL:
553  this->last_user_action = widget;
554  break;
555 
556  case WID_RAT_DEMOLISH:
558  this->last_user_action = widget;
559  break;
560 
561  case WID_RAT_BUILD_DEPOT:
563  ShowBuildTrainDepotPicker(this);
564  this->last_user_action = widget;
565  }
566  break;
567 
569  this->last_user_action = widget;
571  if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT) && _waypoint_count > 1) {
572  ShowBuildWaypointPicker(this);
573  }
574  break;
575 
577  if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION, SPR_CURSOR_RAIL_STATION, HT_RECT)) {
578  ShowStationBuilder(this);
579  this->last_user_action = widget;
580  }
581  break;
582 
583  case WID_RAT_BUILD_SIGNALS: {
584  this->last_user_action = widget;
587  ShowSignalBuilder(this);
588  }
589  break;
590  }
591 
593  HandlePlacePushButton(this, WID_RAT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
594  this->last_user_action = widget;
595  break;
596 
599  this->last_user_action = widget;
600  break;
601 
602  case WID_RAT_REMOVE:
603  BuildRailClick_Remove(this);
604  break;
605 
608  this->last_user_action = widget;
609  break;
610 
611  default: NOT_REACHED();
612  }
613  this->UpdateRemoveWidgetStatus(widget);
615  }
616 
617  EventState OnHotkey(int hotkey) override
618  {
619  MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
620  return Window::OnHotkey(hotkey);
621  }
622 
623  void OnPlaceObject(Point pt, TileIndex tile) override
624  {
625  switch (this->last_user_action) {
626  case WID_RAT_BUILD_NS:
628  break;
629 
630  case WID_RAT_BUILD_X:
632  break;
633 
634  case WID_RAT_BUILD_EW:
636  break;
637 
638  case WID_RAT_BUILD_Y:
640  break;
641 
642  case WID_RAT_AUTORAIL:
644  break;
645 
646  case WID_RAT_DEMOLISH:
648  break;
649 
650  case WID_RAT_BUILD_DEPOT:
652  CMD_BUILD_TRAIN_DEPOT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_DEPOT),
653  CcRailDepot);
654  break;
655 
657  PlaceRail_Waypoint(tile);
658  break;
659 
661  PlaceRail_Station(tile);
662  break;
663 
666  break;
667 
669  PlaceRail_Bridge(tile, this);
670  break;
671 
673  DoCommandP(tile, _cur_railtype | (TRANSPORT_RAIL << 8), 0, CMD_BUILD_TUNNEL | CMD_MSG(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE), CcBuildRailTunnel);
674  break;
675 
678  break;
679 
680  default: NOT_REACHED();
681  }
682  }
683 
684  void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
685  {
686  /* no dragging if you have pressed the convert button */
687  if (FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr && _convert_signal_button && this->IsWidgetLowered(WID_RAT_BUILD_SIGNALS)) return;
688 
689  VpSelectTilesWithMethod(pt.x, pt.y, select_method);
690  }
691 
692  void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
693  {
694  if (pt.x != -1) {
695  switch (select_proc) {
696  default: NOT_REACHED();
697  case DDSP_BUILD_BRIDGE:
699  ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_RAIL, _cur_railtype);
700  break;
701 
702  case DDSP_PLACE_RAIL:
703  HandleAutodirPlacement();
704  break;
705 
706  case DDSP_BUILD_SIGNALS:
708  break;
709 
710  case DDSP_DEMOLISH_AREA:
711  GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
712  break;
713 
714  case DDSP_CONVERT_RAIL:
715  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);
716  break;
717 
718  case DDSP_REMOVE_STATION:
719  case DDSP_BUILD_STATION:
720  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) {
721  /* Station */
723  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);
724  } else {
725  HandleStationPlacement(start_tile, end_tile);
726  }
727  } else {
728  /* Waypoint */
730  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);
731  } else {
732  TileArea ta(start_tile, end_tile);
733  uint32 p1 = _cur_railtype | (select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y) << 6 | ta.w << 8 | ta.h << 16 | _ctrl_pressed << 24;
734  uint32 p2 = STAT_CLASS_WAYP | _cur_waypoint_type << 8 | INVALID_STATION << 16;
735 
736  CommandContainer cmdcont = { ta.tile, p1, p2, CMD_BUILD_RAIL_WAYPOINT | CMD_MSG(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT), CcPlaySound_SPLAT_RAIL, "" };
737  ShowSelectWaypointIfNeeded(cmdcont, ta);
738  }
739  }
740  break;
741  }
742  }
743  }
744 
745  void OnPlaceObjectAbort() override
746  {
747  if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true);
748 
749  this->RaiseButtons();
750  this->DisableWidget(WID_RAT_REMOVE);
751  this->SetWidgetDirty(WID_RAT_REMOVE);
752 
759  }
760 
761  void OnPlacePresize(Point pt, TileIndex tile) override
762  {
765  }
766 
768  {
769  /* do not toggle Remove button by Ctrl when placing station */
770  if (!this->IsWidgetLowered(WID_RAT_BUILD_STATION) && !this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT) && RailToolbar_CtrlChanged(this)) return ES_HANDLED;
771  return ES_NOT_HANDLED;
772  }
773 
774  static HotkeyList hotkeys;
775 };
776 
783 {
784  if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_TRAIN)) return ES_NOT_HANDLED;
785  extern RailType _last_built_railtype;
786  Window *w = ShowBuildRailToolbar(_last_built_railtype);
787  if (w == nullptr) return ES_NOT_HANDLED;
788  return w->OnHotkey(hotkey);
789 }
790 
791 const uint16 _railtoolbar_autorail_keys[] = {'5', 'A' | WKC_GLOBAL_HOTKEY, 0};
792 
793 static Hotkey railtoolbar_hotkeys[] = {
794  Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
795  Hotkey('2', "build_x", WID_RAT_BUILD_X),
796  Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
797  Hotkey('4', "build_y", WID_RAT_BUILD_Y),
798  Hotkey(_railtoolbar_autorail_keys, "autorail", WID_RAT_AUTORAIL),
799  Hotkey('6', "demolish", WID_RAT_DEMOLISH),
800  Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
801  Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
802  Hotkey('9', "station", WID_RAT_BUILD_STATION),
803  Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
804  Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
805  Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
806  Hotkey('R', "remove", WID_RAT_REMOVE),
807  Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
808  HOTKEY_LIST_END
809 };
810 HotkeyList BuildRailToolbarWindow::hotkeys("railtoolbar", railtoolbar_hotkeys, RailToolbarGlobalHotkeys);
811 
812 static const NWidgetPart _nested_build_rail_widgets[] = {
814  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
815  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_RAT_CAPTION), SetDataTip(STR_WHITE_STRING, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
816  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
817  EndContainer(),
819  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_NS),
820  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
821  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_X),
822  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
823  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_EW),
824  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_EW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
825  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_Y),
826  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_NW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
827  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_AUTORAIL),
828  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_AUTORAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL),
829 
830  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetDataTip(0x0, STR_NULL), EndContainer(),
831 
832  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_DEMOLISH),
833  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
834  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_DEPOT),
835  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DEPOT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING),
836  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_WAYPOINT),
837  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_WAYPOINT, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT),
838  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_STATION),
839  SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_RAIL_STATION, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION),
840  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_SIGNALS),
841  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_RAIL_SIGNALS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS),
842  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_BRIDGE),
843  SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_BRIDGE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE),
844  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_TUNNEL),
845  SetFill(0, 1), SetMinimalSize(20, 22), SetDataTip(SPR_IMG_TUNNEL_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL),
846  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_REMOVE),
847  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_REMOVE, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR),
848  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_CONVERT_RAIL),
849  SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_CONVERT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL),
850  EndContainer(),
851 };
852 
853 static WindowDesc _build_rail_desc(
854  WDP_ALIGN_TOOLBAR, "toolbar_rail", 0, 0,
857  _nested_build_rail_widgets, lengthof(_nested_build_rail_widgets),
858  &BuildRailToolbarWindow::hotkeys
859 );
860 
861 
871 {
872  if (!Company::IsValidID(_local_company)) return nullptr;
873  if (!ValParamRailtype(railtype)) return nullptr;
874 
876  _cur_railtype = railtype;
877  _remove_button_clicked = false;
878  return new BuildRailToolbarWindow(&_build_rail_desc, railtype);
879 }
880 
881 /* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
882  * --pasky */
883 
884 static void HandleStationPlacement(TileIndex start, TileIndex end)
885 {
886  TileArea ta(start, end);
887  uint numtracks = ta.w;
888  uint platlength = ta.h;
889 
890  if (_railstation.orientation == AXIS_X) Swap(numtracks, platlength);
891 
892  uint32 p1 = _cur_railtype | _railstation.orientation << 6 | numtracks << 8 | platlength << 16 | _ctrl_pressed << 24;
893  uint32 p2 = _railstation.station_class | _railstation.station_type << 8 | INVALID_STATION << 16;
894 
895  CommandContainer cmdcont = { ta.tile, p1, p2, CMD_BUILD_RAIL_STATION | CMD_MSG(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION), CcStation, "" };
896  ShowSelectStationIfNeeded(cmdcont, ta);
897 }
898 
900 private:
901  uint line_height;
905 
911  void CheckSelectedSize(const StationSpec *statspec)
912  {
913  if (statspec == nullptr || _settings_client.gui.station_dragdrop) return;
914 
915  /* If current number of tracks is not allowed, make it as big as possible */
919  if (statspec->disallowed_platforms != UINT8_MAX) {
922  }
924  }
925  }
926 
930  if (statspec->disallowed_lengths != UINT8_MAX) {
933  }
935  }
936  }
937  }
938 
939 public:
940  BuildRailStationWindow(WindowDesc *desc, Window *parent, bool newstation) : PickerWindowBase(desc, parent)
941  {
942  this->coverage_height = 2 * FONT_HEIGHT_NORMAL + 3 * WD_PAR_VSEP_NORMAL;
943  this->vscroll = nullptr;
944  _railstation.newstations = newstation;
945 
946  this->CreateNestedTree();
947  NWidgetStacked *newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_ADDITIONS);
948  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
949  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_MATRIX);
950  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
951  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_DEFSIZE);
952  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
953  newst_additions = this->GetWidget<NWidgetStacked>(WID_BRAS_SHOW_NEWST_RESIZE);
954  newst_additions->SetDisplayedPlane(newstation ? 0 : SZSP_NONE);
955  if (newstation) {
956  this->vscroll = this->GetScrollbar(WID_BRAS_NEWST_SCROLL);
957  this->vscroll2 = this->GetScrollbar(WID_BRAS_MATRIX_SCROLL);
958  }
959  this->FinishInitNested(TRANSPORT_RAIL);
960 
961  this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
963  this->LowerWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
964  } else {
967  }
968  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF, !_settings_client.gui.station_show_coverage);
969  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON, _settings_client.gui.station_show_coverage);
970 
971  if (!newstation || _railstation.station_class >= (int)StationClass::GetClassCount()) {
972  /* New stations are not available or changed, so ensure the default station
973  * type is 'selected'. */
974  _railstation.station_class = STAT_CLASS_DFLT;
975  _railstation.station_type = 0;
976  this->vscroll2 = nullptr;
977  }
978  if (newstation) {
979  _railstation.station_count = StationClass::Get(_railstation.station_class)->GetSpecCount();
980  _railstation.station_type = min(_railstation.station_type, _railstation.station_count - 1);
981 
982  int count = 0;
983  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
984  if (i == STAT_CLASS_WAYP) continue;
985  count++;
986  }
987  this->vscroll->SetCount(count);
988  this->vscroll->SetPosition(Clamp(_railstation.station_class - 2, 0, max(this->vscroll->GetCount() - this->vscroll->GetCapacity(), 0)));
989 
990  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
991  matrix->SetScrollbar(this->vscroll2);
992  matrix->SetCount(_railstation.station_count);
993  matrix->SetClicked(_railstation.station_type);
994  }
995  }
996 
997  virtual ~BuildRailStationWindow()
998  {
1000  }
1001 
1002  void OnPaint() override
1003  {
1004  bool newstations = _railstation.newstations;
1005  const StationSpec *statspec = newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1006 
1008  SetTileSelectSize(1, 1);
1009  } else {
1012  if (_railstation.orientation == AXIS_X) Swap(x, y);
1013  if (!_remove_button_clicked) {
1014  SetTileSelectSize(x, y);
1015  }
1016  }
1017 
1019 
1020  if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1021 
1022  for (uint bits = 0; bits < 7; bits++) {
1023  bool disable = bits >= _settings_game.station.station_spread;
1024  if (statspec == nullptr) {
1025  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_NUM_1, disable);
1026  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_LEN_1, disable);
1027  } else {
1028  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_NUM_1, HasBit(statspec->disallowed_platforms, bits) || disable);
1029  this->SetWidgetDisabledState(bits + WID_BRAS_PLATFORM_LEN_1, HasBit(statspec->disallowed_lengths, bits) || disable);
1030  }
1031  }
1032 
1033  this->DrawWidgets();
1034 
1035  if (this->IsShaded()) return;
1036  /* 'Accepts' and 'Supplies' texts. */
1037  NWidgetBase *cov = this->GetWidget<NWidgetBase>(WID_BRAS_COVERAGE_TEXTS);
1038  int top = cov->pos_y + WD_PAR_VSEP_NORMAL;
1039  int left = cov->pos_x + WD_FRAMERECT_LEFT;
1040  int right = cov->pos_x + cov->current_x - WD_FRAMERECT_RIGHT;
1041  int bottom = cov->pos_y + cov->current_y;
1042  top = DrawStationCoverageAreaText(left, right, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
1043  top = DrawStationCoverageAreaText(left, right, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
1044  /* Resize background if the window is too small.
1045  * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1046  * (This is the case, if making the window bigger moves the mouse into the window.) */
1047  if (top > bottom) {
1048  this->coverage_height += top - bottom;
1049  this->ReInit();
1050  }
1051  }
1052 
1053  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1054  {
1055  switch (widget) {
1056  case WID_BRAS_NEWST_LIST: {
1057  Dimension d = {0, 0};
1058  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1059  if (i == STAT_CLASS_WAYP) continue;
1061  }
1062  size->width = max(size->width, d.width + padding.width);
1063  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
1064  size->height = 5 * this->line_height;
1065  resize->height = this->line_height;
1066  break;
1067  }
1068 
1069  case WID_BRAS_SHOW_NEWST_TYPE: {
1070  if (!_railstation.newstations) {
1071  size->width = 0;
1072  size->height = 0;
1073  break;
1074  }
1075 
1076  /* If newstations exist, compute the non-zero minimal size. */
1077  Dimension d = {0, 0};
1078  StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
1079  for (StationClassID statclass = STAT_CLASS_BEGIN; statclass < (StationClassID)StationClass::GetClassCount(); statclass++) {
1080  if (statclass == STAT_CLASS_WAYP) continue;
1081  StationClass *stclass = StationClass::Get(statclass);
1082  for (uint16 j = 0; j < stclass->GetSpecCount(); j++) {
1083  const StationSpec *statspec = stclass->GetSpec(j);
1084  SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
1085  d = maxdim(d, GetStringBoundingBox(str));
1086  }
1087  }
1088  size->width = max(size->width, d.width + padding.width);
1089  break;
1090  }
1091 
1094  case WID_BRAS_IMAGE:
1095  size->width = ScaleGUITrad(64) + 2;
1096  size->height = ScaleGUITrad(58) + 2;
1097  break;
1098 
1100  size->height = this->coverage_height;
1101  break;
1102 
1103  case WID_BRAS_MATRIX:
1104  fill->height = 1;
1105  resize->height = 1;
1106  break;
1107  }
1108  }
1109 
1110  void DrawWidget(const Rect &r, int widget) const override
1111  {
1112  DrawPixelInfo tmp_dpi;
1113 
1114  switch (GB(widget, 0, 16)) {
1116  /* Set up a clipping area for the '/' station preview */
1117  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1118  DrawPixelInfo *old_dpi = _cur_dpi;
1119  _cur_dpi = &tmp_dpi;
1120  int x = ScaleGUITrad(31) + 1;
1121  int y = r.bottom - r.top - ScaleGUITrad(31);
1122  if (!DrawStationTile(x, y, _cur_railtype, AXIS_X, _railstation.station_class, _railstation.station_type)) {
1123  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2);
1124  }
1125  _cur_dpi = old_dpi;
1126  }
1127  break;
1128 
1130  /* Set up a clipping area for the '\' station preview */
1131  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1132  DrawPixelInfo *old_dpi = _cur_dpi;
1133  _cur_dpi = &tmp_dpi;
1134  int x = ScaleGUITrad(31) + 1;
1135  int y = r.bottom - r.top - ScaleGUITrad(31);
1136  if (!DrawStationTile(x, y, _cur_railtype, AXIS_Y, _railstation.station_class, _railstation.station_type)) {
1137  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 3);
1138  }
1139  _cur_dpi = old_dpi;
1140  }
1141  break;
1142 
1143  case WID_BRAS_NEWST_LIST: {
1144  uint statclass = 0;
1145  uint row = 0;
1146  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1147  if (i == STAT_CLASS_WAYP) continue;
1148  if (this->vscroll->IsVisible(statclass)) {
1149  DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, row * this->line_height + r.top + WD_MATRIX_TOP,
1151  (StationClassID)i == _railstation.station_class ? TC_WHITE : TC_BLACK);
1152  row++;
1153  }
1154  statclass++;
1155  }
1156  break;
1157  }
1158 
1159  case WID_BRAS_IMAGE: {
1160  byte type = GB(widget, 16, 16);
1161  assert(type < _railstation.station_count);
1162  /* Check station availability callback */
1163  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type);
1164  if (!IsStationAvailable(statspec)) {
1165  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
1166  }
1167 
1168  /* Set up a clipping area for the station preview. */
1169  if (FillDrawPixelInfo(&tmp_dpi, r.left, r.top, r.right - r.left + 1, r.bottom - r.top + 1)) {
1170  DrawPixelInfo *old_dpi = _cur_dpi;
1171  _cur_dpi = &tmp_dpi;
1172  int x = ScaleGUITrad(31) + 1;
1173  int y = r.bottom - r.top - ScaleGUITrad(31);
1174  if (!DrawStationTile(x, y, _cur_railtype, _railstation.orientation, _railstation.station_class, type)) {
1175  StationPickerDrawSprite(x, y, STATION_RAIL, _cur_railtype, INVALID_ROADTYPE, 2 + _railstation.orientation);
1176  }
1177  _cur_dpi = old_dpi;
1178  }
1179  break;
1180  }
1181  }
1182  }
1183 
1184  void OnResize() override
1185  {
1186  if (this->vscroll != nullptr) { // New stations available.
1187  this->vscroll->SetCapacityFromWidget(this, WID_BRAS_NEWST_LIST);
1188  }
1189  }
1190 
1191  void SetStringParameters(int widget) const override
1192  {
1193  if (widget == WID_BRAS_SHOW_NEWST_TYPE) {
1194  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type);
1195  SetDParam(0, (statspec != nullptr && statspec->name != 0) ? statspec->name : STR_STATION_CLASS_DFLT);
1196  }
1197  }
1198 
1199  void OnClick(Point pt, int widget, int click_count) override
1200  {
1201  switch (GB(widget, 0, 16)) {
1204  this->RaiseWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
1205  _railstation.orientation = (Axis)(widget - WID_BRAS_PLATFORM_DIR_X);
1206  this->LowerWidget(_railstation.orientation + WID_BRAS_PLATFORM_DIR_X);
1207  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1208  this->SetDirty();
1210  break;
1211 
1218  case WID_BRAS_PLATFORM_NUM_7: {
1220  this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
1221 
1224 
1226 
1227  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1228  if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1229  /* The previously selected number of platforms in invalid */
1230  for (uint i = 0; i < 7; i++) {
1231  if (!HasBit(statspec->disallowed_lengths, i)) {
1234  break;
1235  }
1236  }
1237  }
1238 
1239  this->LowerWidget(_settings_client.gui.station_numtracks + WID_BRAS_PLATFORM_NUM_BEGIN);
1241  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1242  this->SetDirty();
1244  break;
1245  }
1246 
1253  case WID_BRAS_PLATFORM_LEN_7: {
1255  this->RaiseWidget(WID_BRAS_PLATFORM_DRAG_N_DROP);
1256 
1259 
1261 
1262  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1263  if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1264  /* The previously selected number of tracks in invalid */
1265  for (uint i = 0; i < 7; i++) {
1266  if (!HasBit(statspec->disallowed_platforms, i)) {
1269  break;
1270  }
1271  }
1272  }
1273 
1275  this->LowerWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
1276  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1277  this->SetDirty();
1279  break;
1280  }
1281 
1284 
1285  this->ToggleWidgetLoweredState(WID_BRAS_PLATFORM_DRAG_N_DROP);
1286 
1287  /* get the first allowed length/number of platforms */
1288  const StationSpec *statspec = _railstation.newstations ? StationClass::Get(_railstation.station_class)->GetSpec(_railstation.station_type) : nullptr;
1289  if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1290  for (uint i = 0; i < 7; i++) {
1291  if (!HasBit(statspec->disallowed_lengths, i)) {
1294  break;
1295  }
1296  }
1297  }
1298  if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1299  for (uint i = 0; i < 7; i++) {
1300  if (!HasBit(statspec->disallowed_platforms, i)) {
1303  break;
1304  }
1305  }
1306  }
1307 
1310  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1311  this->SetDirty();
1313  break;
1314  }
1315 
1317  case WID_BRAS_HIGHLIGHT_ON:
1319 
1320  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_OFF, !_settings_client.gui.station_show_coverage);
1321  this->SetWidgetLoweredState(WID_BRAS_HIGHLIGHT_ON, _settings_client.gui.station_show_coverage);
1322  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1323  this->SetDirty();
1324  break;
1325 
1326  case WID_BRAS_NEWST_LIST: {
1327  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BRAS_NEWST_LIST, 0, this->line_height);
1328  if (y >= (int)StationClass::GetClassCount()) return;
1329  for (uint i = 0; i < StationClass::GetClassCount(); i++) {
1330  if (i == STAT_CLASS_WAYP) continue;
1331  if (y == 0) {
1332  if (_railstation.station_class != (StationClassID)i) {
1333  _railstation.station_class = (StationClassID)i;
1334  StationClass *stclass = StationClass::Get(_railstation.station_class);
1335  _railstation.station_count = stclass->GetSpecCount();
1336  _railstation.station_type = min((int)_railstation.station_type, max(0, (int)_railstation.station_count - 1));
1337 
1338  this->CheckSelectedSize(stclass->GetSpec(_railstation.station_type));
1339 
1340  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX);
1341  matrix->SetCount(_railstation.station_count);
1342  matrix->SetClicked(_railstation.station_type);
1343  }
1344  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1345  this->SetDirty();
1347  break;
1348  }
1349  y--;
1350  }
1351  break;
1352  }
1353 
1354  case WID_BRAS_IMAGE: {
1355  int y = GB(widget, 16, 16);
1356  if (y >= _railstation.station_count) return;
1357 
1358  /* Check station availability callback */
1359  const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(y);
1360  if (!IsStationAvailable(statspec)) return;
1361 
1362  _railstation.station_type = y;
1363 
1364  this->CheckSelectedSize(statspec);
1365  this->GetWidget<NWidgetMatrix>(WID_BRAS_MATRIX)->SetClicked(_railstation.station_type);
1366 
1367  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1368  this->SetDirty();
1370  break;
1371  }
1372  }
1373  }
1374 
1375  void OnRealtimeTick(uint delta_ms) override
1376  {
1378  }
1379 };
1380 
1381 static const NWidgetPart _nested_station_builder_widgets[] = {
1383  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1384  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_RAIL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1385  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1387  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1388  EndContainer(),
1389  EndContainer(),
1390  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1394  NWidget(NWID_HORIZONTAL), SetPIP(7, 0, 7), SetPadding(2, 0, 1, 0),
1395  NWidget(WWT_MATRIX, COLOUR_GREY, WID_BRAS_NEWST_LIST), SetMinimalSize(122, 71), SetFill(1, 0),
1396  SetMatrixDataTip(1, 0, STR_STATION_BUILD_STATION_CLASS_TOOLTIP), SetScrollbar(WID_BRAS_NEWST_SCROLL),
1398  EndContainer(),
1399  EndContainer(),
1400  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_ORIENTATION, STR_NULL), SetPadding(1, 2, 0, 2),
1402  NWidget(NWID_SPACER), SetMinimalSize(7, 0), SetFill(1, 0),
1403  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(),
1404  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1405  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(),
1406  NWidget(NWID_SPACER), SetMinimalSize(7, 0), SetFill(1, 0),
1407  EndContainer(),
1408  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),
1409  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_NUMBER_OF_TRACKS, STR_NULL), SetPadding(0, 2, 0, 2),
1411  NWidget(NWID_SPACER), SetFill(1, 0),
1412  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_1), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1413  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_2), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1414  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_3), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1415  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_4), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1416  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_5), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1417  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_6), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1418  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_7), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1419  NWidget(NWID_SPACER), SetFill(1, 0),
1420  EndContainer(),
1421  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_PLATFORM_LENGTH, STR_NULL), SetPadding(2, 2, 0, 2),
1423  NWidget(NWID_SPACER), SetFill(1, 0),
1424  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_1), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_1, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1425  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_2), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_2, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1426  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_3), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_3, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1427  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_4), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_4, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1428  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_5), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_5, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1429  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_6), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_6, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1430  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_7), SetMinimalSize(15, 12), SetDataTip(STR_BLACK_7, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1431  NWidget(NWID_SPACER), SetFill(1, 0),
1432  EndContainer(),
1435  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1436  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),
1437  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1438  EndContainer(),
1439  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(144, 11), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetPadding(3, 2, 0, 2),
1441  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1442  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_OFF), SetMinimalSize(60, 12),
1443  SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1444  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_ON), SetMinimalSize(60, 12),
1445  SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1446  NWidget(NWID_SPACER), SetMinimalSize(2, 0), SetFill(1, 0),
1447  EndContainer(),
1448  EndContainer(),
1450  /* We need an additional background for the matrix, as the matrix cannot handle the scrollbar due to not being an NWidgetCore. */
1451  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_BRAS_MATRIX_SCROLL),
1453  NWidget(NWID_MATRIX, COLOUR_DARK_GREEN, WID_BRAS_MATRIX), SetScrollbar(WID_BRAS_MATRIX_SCROLL), SetPIP(0, 2, 0), SetPadding(2, 0, 0, 0),
1454  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRAS_IMAGE), SetMinimalSize(66, 60),
1455  SetFill(0, 0), SetResize(0, 0), SetDataTip(0x0, STR_STATION_BUILD_STATION_TYPE_TOOLTIP), SetScrollbar(WID_BRAS_MATRIX_SCROLL),
1456  EndContainer(),
1457  EndContainer(),
1458  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRAS_MATRIX_SCROLL),
1459  EndContainer(),
1460  EndContainer(),
1461  EndContainer(),
1462  EndContainer(),
1464  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BRAS_COVERAGE_TEXTS), SetFill(1, 1), SetResize(1, 0),
1467  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 1), EndContainer(),
1468  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
1469  EndContainer(),
1470  EndContainer(),
1471  EndContainer(),
1472  EndContainer(),
1473 };
1474 
1477  WDP_AUTO, "build_station_rail", 350, 0,
1480  _nested_station_builder_widgets, lengthof(_nested_station_builder_widgets)
1481 );
1482 
1484 static void ShowStationBuilder(Window *parent)
1485 {
1486  bool newstations = StationClass::GetClassCount() > 2 || StationClass::Get(STAT_CLASS_DFLT)->GetSpecCount() != 1;
1487  new BuildRailStationWindow(&_station_builder_desc, parent, newstations);
1488 }
1489 
1491 private:
1494 
1502  void DrawSignalSprite(byte widget_index, SpriteID image) const
1503  {
1504  Point offset;
1505  Dimension sprite_size = GetSpriteSize(image, &offset);
1506  const NWidgetBase *widget = this->GetWidget<NWidgetBase>(widget_index);
1507  int x = widget->pos_x - offset.x +
1508  (widget->current_x - sprite_size.width + offset.x) / 2; // centered
1509  int y = widget->pos_y - sig_sprite_bottom_offset + WD_IMGBTN_TOP +
1510  (widget->current_y - WD_IMGBTN_TOP - WD_IMGBTN_BOTTOM + sig_sprite_size.height) / 2; // aligned to bottom
1511 
1512  DrawSprite(image, PAL_NONE,
1513  x + this->IsWidgetLowered(widget_index),
1514  y + this->IsWidgetLowered(widget_index));
1515  }
1516 
1517 public:
1518  BuildSignalWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1519  {
1520  this->InitNested(TRANSPORT_RAIL);
1521  this->OnInvalidateData();
1522  }
1523 
1525  {
1526  _convert_signal_button = false;
1527  }
1528 
1529  void OnInit() override
1530  {
1531  /* Calculate maximum signal sprite size. */
1532  this->sig_sprite_size.width = 0;
1533  this->sig_sprite_size.height = 0;
1534  this->sig_sprite_bottom_offset = 0;
1536  for (uint type = SIGTYPE_NORMAL; type < SIGTYPE_END; type++) {
1537  for (uint variant = SIG_ELECTRIC; variant <= SIG_SEMAPHORE; variant++) {
1538  for (uint lowered = 0; lowered < 2; lowered++) {
1539  Point offset;
1540  Dimension sprite_size = GetSpriteSize(rti->gui_sprites.signals[type][variant][lowered], &offset);
1541  this->sig_sprite_bottom_offset = max<int>(this->sig_sprite_bottom_offset, sprite_size.height);
1542  this->sig_sprite_size.width = max<int>(this->sig_sprite_size.width, sprite_size.width - offset.x);
1543  this->sig_sprite_size.height = max<int>(this->sig_sprite_size.height, sprite_size.height - offset.y);
1544  }
1545  }
1546  }
1547  }
1548 
1549  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1550  {
1551  if (widget == WID_BS_DRAG_SIGNALS_DENSITY_LABEL) {
1552  /* Two digits for signals density. */
1553  size->width = max(size->width, 2 * GetDigitWidth() + padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT);
1554  } else if (IsInsideMM(widget, WID_BS_SEMAPHORE_NORM, WID_BS_ELECTRIC_PBS_OWAY + 1)) {
1555  size->width = max(size->width, this->sig_sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT);
1556  size->height = max(size->height, this->sig_sprite_size.height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
1557  }
1558  }
1559 
1560  void SetStringParameters(int widget) const override
1561  {
1562  switch (widget) {
1565  break;
1566  }
1567  }
1568 
1569  void DrawWidget(const Rect &r, int widget) const override
1570  {
1572  /* Extract signal from widget number. */
1573  int type = (widget - WID_BS_SEMAPHORE_NORM) % SIGTYPE_END;
1574  int var = SIG_SEMAPHORE - (widget - WID_BS_SEMAPHORE_NORM) / SIGTYPE_END; // SignalVariant order is reversed compared to the widgets.
1575  SpriteID sprite = GetRailTypeInfo(_cur_railtype)->gui_sprites.signals[type][var][this->IsWidgetLowered(widget)];
1576 
1577  this->DrawSignalSprite(widget, sprite);
1578  }
1579  }
1580 
1581  void OnClick(Point pt, int widget, int click_count) override
1582  {
1583  switch (widget) {
1584  case WID_BS_SEMAPHORE_NORM:
1586  case WID_BS_SEMAPHORE_EXIT:
1588  case WID_BS_SEMAPHORE_PBS:
1590  case WID_BS_ELECTRIC_NORM:
1591  case WID_BS_ELECTRIC_ENTRY:
1592  case WID_BS_ELECTRIC_EXIT:
1593  case WID_BS_ELECTRIC_COMBO:
1594  case WID_BS_ELECTRIC_PBS:
1597 
1598  _cur_signal_type = (SignalType)((uint)((widget - WID_BS_SEMAPHORE_NORM) % (SIGTYPE_LAST + 1)));
1600 
1601  /* If 'remove' button of rail build toolbar is active, disable it. */
1602  if (_remove_button_clicked) {
1604  if (w != nullptr) ToggleRailButton_Remove(w);
1605  }
1606 
1607  break;
1608 
1609  case WID_BS_CONVERT:
1611  break;
1612 
1617  }
1618  break;
1619 
1624  }
1625  break;
1626 
1627  default: break;
1628  }
1629 
1630  this->InvalidateData();
1631  }
1632 
1638  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1639  {
1640  if (!gui_scope) return;
1642 
1643  this->SetWidgetLoweredState(WID_BS_CONVERT, _convert_signal_button);
1644 
1647  }
1648 };
1649 
1653  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1654  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_BUILD_SIGNAL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1655  EndContainer(),
1658  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_NORM), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP), EndContainer(), SetFill(1, 1),
1659  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_ENTRY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP), EndContainer(), SetFill(1, 1),
1660  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_EXIT), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP), EndContainer(), SetFill(1, 1),
1661  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_COMBO), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP), EndContainer(), SetFill(1, 1),
1662  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_PBS), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP), EndContainer(), SetFill(1, 1),
1663  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),
1664  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_BS_CONVERT), SetDataTip(SPR_IMG_SIGNAL_CONVERT, STR_BUILD_SIGNAL_CONVERT_TOOLTIP), SetFill(1, 1),
1665  EndContainer(),
1667  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_NORM), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP), EndContainer(), SetFill(1, 1),
1668  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_ENTRY), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP), EndContainer(), SetFill(1, 1),
1669  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_EXIT), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP), EndContainer(), SetFill(1, 1),
1670  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_COMBO), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP), EndContainer(), SetFill(1, 1),
1671  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_PBS), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP), EndContainer(), SetFill(1, 1),
1672  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),
1673  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetDataTip(STR_NULL, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetFill(1, 1),
1674  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),
1675  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1676  NWidget(NWID_SPACER), SetFill(1, 0),
1677  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),
1678  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),
1679  NWidget(NWID_SPACER), SetFill(1, 0),
1680  EndContainer(),
1681  NWidget(NWID_SPACER), SetMinimalSize(0, 2), SetFill(1, 0),
1682  EndContainer(),
1683  EndContainer(),
1684  EndContainer(),
1685 };
1686 
1689  WDP_AUTO, "build_signal", 0, 0,
1692  _nested_signal_builder_widgets, lengthof(_nested_signal_builder_widgets)
1693 );
1694 
1698 static void ShowSignalBuilder(Window *parent)
1699 {
1700  new BuildSignalWindow(&_signal_builder_desc, parent);
1701 }
1702 
1704  BuildRailDepotWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1705  {
1706  this->InitNested(TRANSPORT_RAIL);
1707  this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1708  }
1709 
1710  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1711  {
1712  if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1713 
1714  size->width = ScaleGUITrad(64) + 2;
1715  size->height = ScaleGUITrad(48) + 2;
1716  }
1717 
1718  void DrawWidget(const Rect &r, int widget) const override
1719  {
1720  if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1721 
1722  DrawTrainDepotSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype);
1723  }
1724 
1725  void OnClick(Point pt, int widget, int click_count) override
1726  {
1727  switch (widget) {
1728  case WID_BRAD_DEPOT_NE:
1729  case WID_BRAD_DEPOT_SE:
1730  case WID_BRAD_DEPOT_SW:
1731  case WID_BRAD_DEPOT_NW:
1732  this->RaiseWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1734  this->LowerWidget(_build_depot_direction + WID_BRAD_DEPOT_NE);
1735  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1736  this->SetDirty();
1737  break;
1738  }
1739  }
1740 };
1741 
1745  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1746  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1747  EndContainer(),
1748  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1751  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1753  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1754  EndContainer(),
1756  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SW), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1757  EndContainer(),
1758  EndContainer(),
1761  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_NE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1762  EndContainer(),
1764  NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAD_DEPOT_SE), SetMinimalSize(66, 50), SetDataTip(0x0, STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1765  EndContainer(),
1766  EndContainer(),
1767  NWidget(NWID_SPACER), SetMinimalSize(3, 0), SetFill(1, 0),
1768  EndContainer(),
1770  EndContainer(),
1771 };
1772 
1773 static WindowDesc _build_depot_desc(
1774  WDP_AUTO, nullptr, 0, 0,
1777  _nested_build_depot_widgets, lengthof(_nested_build_depot_widgets)
1778 );
1779 
1780 static void ShowBuildTrainDepotPicker(Window *parent)
1781 {
1782  new BuildRailDepotWindow(&_build_depot_desc, parent);
1783 }
1784 
1786  BuildRailWaypointWindow(WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
1787  {
1788  this->CreateNestedTree();
1789 
1790  NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX);
1791  matrix->SetScrollbar(this->GetScrollbar(WID_BRW_SCROLL));
1792 
1793  this->FinishInitNested(TRANSPORT_RAIL);
1794 
1795  matrix->SetCount(_waypoint_count);
1796  matrix->SetClicked(_cur_waypoint_type);
1797  }
1798 
1799  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1800  {
1801  switch (widget) {
1803  /* Three blobs high and wide. */
1804  size->width += resize->width * 2;
1805  size->height += resize->height * 2;
1806 
1807  /* Resizing in X direction only at blob size, but at pixel level in Y. */
1808  resize->height = 1;
1809  break;
1810 
1811  case WID_BRW_WAYPOINT:
1812  size->width = ScaleGUITrad(64) + 2;
1813  size->height = ScaleGUITrad(58) + 2;
1814  break;
1815  }
1816  }
1817 
1818  void DrawWidget(const Rect &r, int widget) const override
1819  {
1820  switch (GB(widget, 0, 16)) {
1821  case WID_BRW_WAYPOINT: {
1822  byte type = GB(widget, 16, 16);
1823  const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
1824  DrawWaypointSprite(r.left + 1 + ScaleGUITrad(31), r.bottom - ScaleGUITrad(31), type, _cur_railtype);
1825 
1826  if (!IsStationAvailable(statspec)) {
1827  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_BLACK, FILLRECT_CHECKER);
1828  }
1829  }
1830  }
1831  }
1832 
1833  void OnClick(Point pt, int widget, int click_count) override
1834  {
1835  switch (GB(widget, 0, 16)) {
1836  case WID_BRW_WAYPOINT: {
1837  byte type = GB(widget, 16, 16);
1838  this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
1839 
1840  /* Check station availability callback */
1841  const StationSpec *statspec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(type);
1842  if (!IsStationAvailable(statspec)) return;
1843 
1844  _cur_waypoint_type = type;
1845  this->GetWidget<NWidgetMatrix>(WID_BRW_WAYPOINT_MATRIX)->SetClicked(_cur_waypoint_type);
1846  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1847  this->SetDirty();
1848  break;
1849  }
1850  }
1851  }
1852 };
1853 
1857  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1858  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1859  NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1860  EndContainer(),
1863  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BRW_WAYPOINT), SetMinimalSize(66, 60), SetDataTip(0x0, STR_WAYPOINT_GRAPHICS_TOOLTIP), SetScrollbar(WID_BRW_SCROLL), EndContainer(),
1864  EndContainer(),
1866  NWidget(NWID_VSCROLLBAR, COLOUR_DARK_GREEN, WID_BRW_SCROLL),
1867  NWidget(WWT_RESIZEBOX, COLOUR_DARK_GREEN),
1868  EndContainer(),
1869  EndContainer(),
1870 };
1871 
1872 static WindowDesc _build_waypoint_desc(
1873  WDP_AUTO, "build_waypoint", 0, 0,
1876  _nested_build_waypoint_widgets, lengthof(_nested_build_waypoint_widgets)
1877 );
1878 
1879 static void ShowBuildWaypointPicker(Window *parent)
1880 {
1881  new BuildRailWaypointWindow(&_build_waypoint_desc, parent);
1882 }
1883 
1888 {
1890 }
1891 
1896 void ReinitGuiAfterToggleElrail(bool disable)
1897 {
1898  extern RailType _last_built_railtype;
1899  if (disable && _last_built_railtype == RAILTYPE_ELECTRIC) {
1900  _last_built_railtype = _cur_railtype = RAILTYPE_RAIL;
1902  if (w != nullptr) w->ModifyRailType(_cur_railtype);
1903  }
1905 }
1906 
1908 static void SetDefaultRailGui()
1909 {
1911 
1912  extern RailType _last_built_railtype;
1914  if (rt == DEF_RAILTYPE_MOST_USED) {
1915  /* Find the most used rail type */
1916  uint count[RAILTYPE_END];
1917  memset(count, 0, sizeof(count));
1918  for (TileIndex t = 0; t < MapSize(); t++) {
1921  count[GetRailType(t)]++;
1922  }
1923  }
1924 
1925  rt = RAILTYPE_RAIL;
1926  for (RailType r = RAILTYPE_ELECTRIC; r < RAILTYPE_END; r++) {
1927  if (count[r] >= count[rt]) rt = r;
1928  }
1929 
1930  /* No rail, just get the first available one */
1931  if (count[rt] == 0) rt = DEF_RAILTYPE_FIRST;
1932  }
1933  switch (rt) {
1934  case DEF_RAILTYPE_FIRST:
1935  rt = RAILTYPE_RAIL;
1936  while (rt < RAILTYPE_END && !HasRailtypeAvail(_local_company, rt)) rt++;
1937  break;
1938 
1939  case DEF_RAILTYPE_LAST:
1941  break;
1942 
1943  default:
1944  break;
1945  }
1946 
1947  _last_built_railtype = _cur_railtype = rt;
1949  if (w != nullptr) w->ModifyRailType(_cur_railtype);
1950 }
1951 
1958 bool ResetSignalVariant(int32 p)
1959 {
1961 
1962  if (new_variant != _cur_signal_variant) {
1964  if (w != nullptr) {
1965  w->SetDirty();
1967  }
1968  _cur_signal_variant = new_variant;
1969  }
1970 
1971  return true;
1972 }
1973 
1979 {
1981 
1982  _convert_signal_button = false;
1983  _cur_signal_type = _default_signal_type[_settings_client.gui.default_signal_type];
1985 }
1986 
1993 DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
1994 {
1995  RailTypes used_railtypes;
1996  RailTypes avail_railtypes;
1997 
1998  const Company *c = Company::Get(_local_company);
1999 
2000  /* Find the used railtypes. */
2001  if (for_replacement) {
2002  avail_railtypes = GetCompanyRailtypes(c->index, false);
2003  used_railtypes = GetRailTypes(false);
2004  } else {
2005  avail_railtypes = c->avail_railtypes;
2006  used_railtypes = GetRailTypes(true);
2007  }
2008 
2009  DropDownList list;
2010 
2011  if (all_option) {
2012  list.emplace_back(new DropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE, false));
2013  }
2014 
2015  Dimension d = { 0, 0 };
2016  RailType rt;
2017  /* Get largest icon size, to ensure text is aligned on each menu item. */
2018  if (!for_replacement) {
2020  if (!HasBit(used_railtypes, rt)) continue;
2021  const RailtypeInfo *rti = GetRailTypeInfo(rt);
2023  }
2024  }
2025 
2027  /* If it's not used ever, don't show it to the user. */
2028  if (!HasBit(used_railtypes, rt)) continue;
2029 
2030  const RailtypeInfo *rti = GetRailTypeInfo(rt);
2031 
2032  StringID str = for_replacement ? rti->strings.replace_text : (rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING);
2034  if (for_replacement) {
2035  item = new DropDownListParamStringItem(str, rt, !HasBit(avail_railtypes, rt));
2036  } else {
2037  DropDownListIconItem *iconitem = new DropDownListIconItem(rti->gui_sprites.build_x_rail, PAL_NONE, str, rt, !HasBit(avail_railtypes, rt));
2038  iconitem->SetDimension(d);
2039  item = iconitem;
2040  }
2041  item->SetParam(0, rti->strings.menu_text);
2042  item->SetParam(1, rti->max_speed);
2043  list.emplace_back(item);
2044  }
2045 
2046  if (list.size() == 0) {
2047  /* Empty dropdowns are not allowed */
2048  list.emplace_back(new DropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true));
2049  }
2050 
2051  return list;
2052 }
EventState
State of handling an event.
Definition: window_type.h:713
Build rail along the game grid Y axis.
Definition: rail_widget.h:22
Matrix container with implicitly equal sized (virtual) sub-widgets.
Definition: widget_type.h:493
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:870
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
Definition: viewport_type.h:97
Selection for newstation class selection list.
Definition: rail_widget.h:68
Y direction.
static void ShowSignalBuilder(Window *parent)
Open the signal selection window.
Definition: rail_gui.cpp:1698
Button to select 5 tiles length station platforms.
Definition: rail_widget.h:53
don&#39;t allow building on structures
Definition: command_type.h:347
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:1053
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:277
Draw all cargoes.
Definition: station_gui.h:24
void SetupRailToolbar(RailType railtype)
Configures the rail toolbar for railtype given.
Definition: rail_gui.cpp:455
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
void ModifyRailType(RailType railtype)
Switch to another rail type.
Definition: rail_gui.cpp:475
Build a depot with the entrance in the south east.
Definition: rail_widget.h:103
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: rail_gui.cpp:745
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:474
static const NWidgetPart _nested_signal_builder_widgets[]
Nested widget definition of the build signal window.
Definition: rail_gui.cpp:1651
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:1549
uint32 widget_data
Data of the widget.
Definition: widget_type.h:305
static const RailtypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition: rail.h:306
Build a depot with the entrance in the north west.
Definition: rail_widget.h:105
Build an electric exit block signal.
Definition: rail_widget.h:89
Select station (when joining stations); Window numbers:
Definition: window_type.h:237
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:45
Data about how and where to blit pixels.
Definition: gfx_type.h:156
build a waypoint
Definition: command_type.h:195
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:1502
Helper for determining the chosen platform width.
Definition: rail_widget.h:75
Matrix container.
Definition: widget_type.h:78
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
Definition: settings_type.h:96
Button to select &#39;/&#39; view.
Definition: rail_widget.h:38
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:594
Station placement.
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
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:112
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:79
static void GenericPlaceSignals(TileIndex tile)
Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSign...
Definition: rail_gui.cpp:212
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3199
SignalType
Type of signal, i.e.
Definition: signal_type.h:25
SpriteID auto_rail
button for the autorail construction
Definition: rail.h:156
bool enable_signal_gui
show the signal GUI when the signal button is pressed
area of land of limited size
Definition: viewport_type.h:83
Maps accessors for stations.
Build a semaphore normal block signal.
Definition: rail_widget.h:81
Track along the x-axis (north-east to south-west)
Definition: track_type.h:23
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition: rail.h:176
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1487
Track in the lower corner of the tile (south)
Definition: track_type.h:26
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:444
static void PlaceRail_Bridge(TileIndex tile, Window *w)
Start placing a rail bridge.
Definition: rail_gui.cpp:263
Build a station.
Definition: rail_widget.h:27
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:26
bool station_show_coverage
whether to highlight coverage area
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
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:525
static bool IsBridgeTile(TileIndex t)
checks if there is a bridge on this tile
Definition: bridge_map.h:37
Hotkey related functions.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition: rail_gui.cpp:1375
Functions related to dates.
SpriteID build_y_rail
button for building single rail in Y direction
Definition: rail.h:155
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition: newgrf_class.h:46
Helper for determining the chosen platform length.
Definition: rail_widget.h:76
int sig_sprite_bottom_offset
Maximum extent of signal GUI sprite from reference point towards bottom.
Definition: rail_gui.cpp:1493
Default railtype: last available.
Definition: rail_type.h:39
Centered label.
Definition: widget_type.h:57
Northwest.
Scrollbar data structure.
Definition: widget_type.h:589
Stacked widgets, widgets all occupying the same space in the window.
Definition: widget_type.h:405
Build a semaphore one way path signal.
Definition: rail_widget.h:86
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:581
Left track.
Definition: track_type.h:46
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:139
remove signals along a track (by dragging)
Definition: command_type.h:304
Horizontal container.
Definition: widget_type.h:75
Build an electric normal block signal.
Definition: rail_widget.h:87
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1114
byte station_type
Station type within the currently selected custom station class (if newstations is true ) ...
Definition: rail_gui.cpp:63
The passed event is not handled.
Definition: window_type.h:715
X direction.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1718
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2444
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:38
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:37
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:911
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
Definition: sprites.h:1491
drag only in X axis
Definition: viewport_type.h:80
static int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:78
Build a semaphore path signal.
Definition: rail_widget.h:85
Build a bridge.
Definition: rail_widget.h:29
Drag only in X axis with limited size.
Definition: viewport_type.h:86
Flag for invalid railtype.
Definition: rail_type.h:36
Button to select 6 tiles length station platforms.
Definition: rail_widget.h:54
Matrix with waypoints.
Definition: rail_widget.h:110
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1818
similar to VMP_RAILDIRS, but with different cursor
Definition: viewport_type.h:89
Station specification.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: rail_gui.cpp:1191
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: rail_gui.cpp:1638
bool ValParamRailtype(const RailType rail)
Validate functions for rail building.
Definition: rail.cpp:208
Default station class.
Build a depot.
Definition: rail_widget.h:25
Default railtype: first available.
Definition: rail_type.h:38
byte drag_signals_density
many signals density
drag only in Y axis
Definition: viewport_type.h:81
Drag only in Y axis with limited size.
Definition: viewport_type.h:87
Build an electric combo block signal.
Definition: rail_widget.h:90
Functions related to vehicles.
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:68
Selection for panel and resize at bottom right for newstation.
Definition: rail_widget.h:70
void SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:701
Button to select 2 tiles length station platforms.
Definition: rail_widget.h:50
byte station_spread
amount a station may spread
Build depot; Window numbers:
Definition: window_type.h:412
void ToggleWidgetLoweredState(byte widget_index)
Invert the lowered/raised status of a widget.
Definition: window_gui.h:465
Build signals.
Definition: rail_widget.h:28
add signals along a track (by dragging)
Definition: command_type.h:303
Build an electric entry block signal.
Definition: rail_widget.h:88
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
static bool IsStationAvailable(const StationSpec *statspec)
Check whether a station type can be build.
Definition: rail_gui.cpp:79
flag for invalid roadtype
Definition: road_type.h:32
static void ShowStationBuilder(Window *parent)
Open station build window.
Definition: rail_gui.cpp:1484
Close box (at top-left of a window)
Definition: widget_type.h:69
Offset at top of a matrix cell.
Definition: window_gui.h:80
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
Definition: viewport.cpp:2669
Button for turning coverage highlighting off.
Definition: rail_widget.h:59
Build a depot with the entrance in the north east.
Definition: rail_widget.h:102
void ShowSelectWaypointIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the waypoint selection window when needed.
build a rail station
Definition: command_type.h:184
A railway.
Definition: tile_type.h:44
static bool RailToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition: rail_gui.cpp:303
Rail toolbar management class.
Definition: rail_gui.cpp:419
void SetCount(int count)
Set the number of elements in this matrix.
Definition: widget.cpp:1504
byte GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition: gfx.cpp:1162
bool persistent_buildingtools
keep the building tools active after usage
Common return value for all commands.
Definition: command_type.h:25
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:1993
CursorID autorail
Cursor for autorail tool.
Definition: rail.h:168
A single waypoint.
Definition: rail_widget.h:111
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:26
Build rail along the game view X axis.
Definition: rail_widget.h:21
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:485
vertical left
Scrollbar of the WID_BRAS_NEWST_LIST.
Definition: rail_widget.h:73
Year _cur_year
Current year, starting at 0.
Definition: date.cpp:26
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: rail_gui.cpp:617
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:511
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:1725
Common string list item.
Definition: dropdown_type.h:41
uint16 w
The width of the area.
Definition: tilearea_type.h:20
Dimension sig_sprite_size
Maximum size of signal GUI sprites.
Definition: rail_gui.cpp:1492
Determine whether a newstation should be made available to build.
Rail construction.
Definition: sound_type.h:71
Build a depot with the entrance in the south west.
Definition: rail_widget.h:104
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition: rail.h:177
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:46
CursorID rail_ew
Cursor for building rail in E-W direction.
Definition: rail.h:166
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:1478
Button for turning coverage highlighting on.
Definition: rail_widget.h:60
This struct contains all the info that is needed to draw and construct tracks.
Definition: rail.h:126
Button to select single tile length station platforms.
Definition: rail_widget.h:49
Right track.
Definition: track_type.h:47
bool newstations
Are custom station definitions available?
Definition: rail_gui.cpp:61
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
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:692
RailType GetBestRailtype(const CompanyID company)
Returns the "best" railtype a company can build.
Definition: rail.cpp:220
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
static SignalType _cur_signal_type
set the signal type (for signal GUI)
Definition: rail_gui.cpp:53
static void BuildRailClick_Remove(Window *w)
The "remove"-button click proc of the build-rail toolbar.
Definition: rail_gui.cpp:324
SpriteID signals[SIGTYPE_END][2][2]
signal GUI sprites (type, variant, state)
Definition: rail.h:160
Data structure for an opened window.
Definition: window_gui.h:278
Clear area.
Definition: viewport_type.h:98
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
Track in the right corner of the tile (east)
Definition: track_type.h:28
build a single rail track
Definition: command_type.h:180
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:1032
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:1046
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:266
Button to select stations with 7 platforms.
Definition: rail_widget.h:47
Bottom offset of image in the button.
Definition: window_gui.h:43
Point selstart
The location where the dragging started.
Display of selected station type.
Definition: rail_widget.h:71
Button to enable drag and drop type station placement.
Definition: rail_widget.h:57
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
Point selend
The location where the drag currently ends.
Electric rails.
Definition: rail_type.h:32
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:343
Build a tunnel.
Definition: rail_widget.h:30
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:98
Selection for default-size button for newstation.
Definition: rail_widget.h:67
Axis GetAxisForNewWaypoint(TileIndex tile)
Get the axis for a new waypoint.
Decrease the signal density.
Definition: rail_widget.h:95
Invisible widget that takes some space.
Definition: widget_type.h:79
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
static const NWidgetPart _nested_build_depot_widgets[]
Nested widget definition of the build rail depot window.
Definition: rail_gui.cpp:1743
Southeast.
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
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:56
Caption of the window.
Definition: rail_widget.h:18
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:443
The y axis.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: rail_gui.cpp:1110
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:65
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:1959
masks the drag-direction
Signal placement.
Button to select 4 tiles length station platforms.
Definition: rail_widget.h:52
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
The client is spectating.
Definition: company_type.h:37
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:495
Button to select &#39;\&#39; view.
Definition: rail_widget.h:39
List item with icon and string.
Definition: dropdown_type.h:83
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:2426
Button to select 7 tiles length station platforms.
Definition: rail_widget.h:55
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
Definition: rail_gui.cpp:1896
int last_user_action
Last started user action.
Definition: rail_gui.cpp:421
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:175
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:78
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:477
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:178
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
build a tunnel
Definition: command_type.h:190
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
drag in X or Y direction
Definition: viewport_type.h:79
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:80
Standard non-electric rails.
Definition: rail_type.h:31
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
Left and right track.
Definition: track_type.h:50
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:152
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:148
Definition of base types and functions in a cross-platform compatible way.
Build waypoint; Window numbers:
Definition: window_type.h:418
Build rail along the game grid X axis.
Definition: rail_widget.h:20
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:152
uint8 default_signal_type
the signal type to build by default.
List of hotkeys for a window.
Definition: hotkeys.h:42
uint line_height
Height of a single line in the newstation selection matrix (WID_BRAS_NEWST_LIST widget).
Definition: rail_gui.cpp:901
no-entry signal
Definition: signal_type.h:31
static void ToggleRailButton_Remove(Window *w)
Toggles state of the Remove button of Build rail toolbar.
Definition: rail_gui.cpp:289
RailTypes GetRailTypes(bool introduces)
Get list of rail types, regardless of company availability.
Definition: rail.cpp:300
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:1958
Simple depressed panel.
Definition: widget_type.h:50
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:782
bool IsWidgetDisabled(byte widget_index) const
Gets the enabled/disabled status of a widget.
Definition: window_gui.h:423
static void PlaceRail_Station(TileIndex tile)
Place a rail station.
Definition: rail_gui.cpp:186
Station removal.
Represents the covered area of e.g.
Definition: tilearea_type.h:18
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
static const NWidgetPart _nested_build_waypoint_widgets[]
Nested widget definition for the build NewGRF rail waypoint window.
Definition: rail_gui.cpp:1855
Offset at left of a matrix cell.
Definition: window_gui.h:78
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:40
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3475
GUI stuff related to terraforming.
uint16 max_speed
Maximum speed for vehicles travelling on this rail type.
Definition: rail.h:230
the lowest valid value
CursorID rail_nwse
Cursor for building rail in Y direction.
Definition: rail.h:167
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:1114
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:1940
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:126
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:499
byte station_numtracks
the number of platforms to default on for rail stations
Build station; Window numbers:
Definition: window_type.h:392
Build rail along the game view Y axis.
Definition: rail_widget.h:19
SpriteID convert_rail
button for converting rail
Definition: rail.h:159
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:534
List with available newstation classes.
Definition: rail_widget.h:72
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:275
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
Definition: viewport.cpp:2626
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:84
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
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:363
Build bridge; Window numbers:
Definition: window_type.h:384
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Build a waypoint.
Definition: rail_widget.h:26
Bridge placement.
Grid of rows and columns.
Definition: widget_type.h:59
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
The current signal density.
Definition: rail_widget.h:94
Display plane with zero size in both directions (none filling and resizing).
Definition: widget_type.h:390
Scrollbar for the matrix.
Definition: rail_widget.h:112
Right offset of the image in the button.
Definition: window_gui.h:41
RailTypes
The different railtypes we support, but then a bitmask of them.
Definition: rail_type.h:52
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:18
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:52
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1159
bool Failed() const
Did this command fail?
Definition: command_type.h:161
drag only in horizontal direction
Definition: viewport_type.h:84
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:205
static void PlaceRail_Waypoint(TileIndex tile)
Place a rail waypoint.
Definition: rail_gui.cpp:154
void OnPaint() override
The window must be repainted.
Definition: rail_gui.cpp:1002
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition: viewport.cpp:3099
static bool _convert_signal_button
convert signal button in the signal GUI pressed
Definition: rail_gui.cpp:51
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:22
Autorail tool.
Definition: rail_widget.h:23
build a signal
Definition: command_type.h:186
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1760
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:110
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:591
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:139
bool drag_signals_fixed_distance
keep fixed distance between signals when dragging
StringID replace_text
Text used in the autoreplace GUI.
Definition: rail.h:179
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:968
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
Build toolbar; Window numbers:
Definition: window_type.h:68
SpriteID build_depot
button for building depots
Definition: rail.h:157
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:583
CursorID depot
Cursor for building a depot.
Definition: rail.h:169
Rail placement.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:698
Build signal toolbar; Window numbers:
Definition: window_type.h:93
Panel used at each cell of the matrix.
Definition: rail_widget.h:64
static byte _cur_waypoint_type
Currently selected waypoint type.
Definition: rail_gui.cpp:50
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:1710
static RailTileType GetRailTileType(TileIndex t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition: rail_map.h:38
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:613
Mask for the tile drag-type modes.
convert a rail type
Definition: command_type.h:193
Convert other rail to this type.
Definition: rail_widget.h:32
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:138
static DiagDirection _build_depot_direction
Currently selected depot direction.
Definition: rail_gui.cpp:48
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:284
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
CursorID convert
Cursor for converting track.
Definition: rail.h:171
Lower track.
Definition: track_type.h:45
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:1569
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:196
static bool _remove_button_clicked
Flag whether &#39;remove&#39; toggle-button is currently enabled.
Definition: rail_gui.cpp:47
static uint MapSize()
Get the size of the map.
Definition: map_func.h:94
Base class for engines.
void SetScrollbar(Scrollbar *sb)
Assign a scrollbar to this matrix.
Definition: widget.cpp:1528
Button to select stations with 4 platforms.
Definition: rail_widget.h:44
area of land in X and Y directions
Definition: viewport_type.h:82
Header file for NewGRF stations.
Track along the y-axis (north-west to south-east)
Definition: track_type.h:24
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
GUISettings gui
settings related to the GUI
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:52
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:1581
Align toward the toolbar.
Definition: window_gui.h:158
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
StationClassID
Increase the signal density.
Definition: rail_widget.h:96
Rail conversion.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
CursorID rail_swne
Cursor for building rail in X direction.
Definition: rail.h:165
static void HandleAutoSignalPlacement()
Build new signals or remove signals or (if only one tile marked) edit a signal.
Definition: rail_gui.cpp:380
Upper track.
Definition: track_type.h:44
Build a semaphore exit block signal.
Definition: rail_widget.h:83
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:100
bool HasRailtypeAvail(const CompanyID company, const RailType railtype)
Finds out if a company has a certain buildable railtype available.
Definition: rail.cpp:188
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:96
Track
These are used to specify a single track.
Definition: track_type.h:21
Top offset of image in the button.
Definition: window_gui.h:42
Catchment for train stations with "modified catchment" enabled.
Definition: station_type.h:81
Vertical container.
Definition: widget_type.h:77
static bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Old-fashioned semaphore signal.
Definition: signal_type.h:20
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:999
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:1199
Bulldozer to remove rail.
Definition: rail_widget.h:31
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
SpriteID build_tunnel
button for building a tunnel
Definition: rail.h:158
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:26
static Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:187
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:373
StationClassID station_class
Currently selected custom station class (if newstations is true )
Definition: rail_gui.cpp:62
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
uint coverage_height
Height of the coverage texts.
Definition: rail_gui.cpp:902
bool confirm
Play sound effect on successful constructions or other actions.
Button to select stations with a single platform.
Definition: rail_widget.h:41
Axis orientation
Currently selected rail station orientation.
Definition: rail_gui.cpp:59
Button to select 3 tiles length station platforms.
Definition: rail_widget.h:51
Functions related to commands.
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: rail_gui.cpp:1529
static RailType _cur_railtype
Rail type of the current build-rail toolbar.
Definition: rail_gui.cpp:46
Coordinates of a point in 2D.
remove a single rail track
Definition: command_type.h:181
struct RailtypeInfo::@37 gui_sprites
struct containing the sprites for the rail GUI.
Build a semaphore combo block signal.
Definition: rail_widget.h:84
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:767
void SetDisplayedPlane(int plane)
Select which plane to show (for NWID_SELECTION only).
Definition: widget.cpp:1084
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
Definition: rail_gui.cpp:1978
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
build a train depot
Definition: command_type.h:185
Convert the signal.
Definition: rail_widget.h:93
Scrollbar * vscroll2
Vertical scrollbar of the matrix with new stations.
Definition: rail_gui.cpp:904
special mode used for highlighting while dragging (and for tunnels/docks)
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:622
Matrix widget displaying the available stations.
Definition: rail_widget.h:63
Build a semaphore entry block signal.
Definition: rail_widget.h:82
Button to select stations with 3 platforms.
Definition: rail_widget.h:43
Scrollbar * vscroll
Vertical scrollbar of the new station list.
Definition: rail_gui.cpp:903
static const Track _place_depot_extra_track[12]
Additional pieces of track to add at the entrance of a depot.
Definition: rail_gui.cpp:119
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:1560
drag only in vertical direction
Definition: viewport_type.h:85
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
const struct GRFFile * grffile
grf file that introduced this entity
remove a signal
Definition: command_type.h:187
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
horizontal lower
Used for iterations.
Definition: rail_type.h:35
SpriteID tunnel
tunnel sprites base
Definition: rail.h:144
CursorID rail_ns
Cursor for building rail in N-S direction.
Definition: rail.h:164
remove a (rectangle of) tiles from a rail station
Definition: command_type.h:192
RailTypes avail_railtypes
Rail types available to this company.
Definition: company_base.h:122
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
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:42
DiagDirection
Enumeration for diagonal directions.
Light signal.
Definition: signal_type.h:19
byte callback_mask
Bitmask of station callbacks that have to be called.
remove a rail track
Definition: command_type.h:179
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
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:684
byte disallowed_lengths
Bitmask of platform lengths available for the station.
Default railtype: most used.
Definition: rail_type.h:40
Northeast, upper right on your monitor.
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:370
Empty space for the coverage texts.
Definition: rail_widget.h:61
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:1973
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3374
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
The passed event is handled.
Definition: window_type.h:714
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: rail_gui.cpp:444
RailTypes GetCompanyRailtypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition: rail.cpp:268
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
all rail directions
Definition: viewport_type.h:88
Destroy something with dynamite!
Definition: rail_widget.h:24
StringID name
Name of this station.
Find a place automatically.
Definition: window_gui.h:156
(Toggle) Button with image
Definition: widget_type.h:52
SpriteID build_x_rail
button for building single rail in X direction
Definition: rail.h:153
String list item with parameters.
Definition: dropdown_type.h:58
static RailStationGUISettings _railstation
Settings of the station builder GUI.
Definition: rail_gui.cpp:66
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:1833
RailType railtype
Rail type to build.
Definition: rail_gui.cpp:420
void InitializeRailGui()
Initialize rail building GUI settings.
Definition: rail_gui.cpp:1887
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:623
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:80
Track in the left corner of the tile (west)
Definition: track_type.h:27
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:767
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:126
SignalVariant
Variant of the signal, i.e.
Definition: signal_type.h:18
normal pbs signal
Definition: signal_type.h:30
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:761
void SetClicked(int clicked)
Sets the clicked widget in the matrix.
Definition: widget.cpp:1487
void DrawWaypointSprite(int x, int y, int stat_id, RailType railtype)
Draw a waypoint.
Definition: waypoint.cpp:29
uint16 h
The height of the area.
Definition: tilearea_type.h:21
Build an electric one way path signal.
Definition: rail_widget.h:92
normal signal
Definition: signal_type.h:26
static byte _waypoint_count
Number of waypoint types.
Definition: rail_gui.cpp:49
SpriteID build_ew_rail
button for building single rail in E-W direction
Definition: rail.h:154
Left offset of the image in the button.
Definition: window_gui.h:40
Selection for newstation image matrix.
Definition: rail_widget.h:69
byte station_count
Number of custom stations (if newstations is true )
Definition: rail_gui.cpp:64
Fake keycode bit to indicate global hotkeys.
Definition: gfx_type.h:35
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
void OnResize() override
Called after the window got resized.
Definition: rail_gui.cpp:1184
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
remove a (rectangle of) tiles from a rail waypoint
Definition: command_type.h:197
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:1799
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:64
Axis
Allow incrementing of DiagDirDiff variables.
Game options window; Window numbers:
Definition: window_type.h:608
Horizontal container that doesn&#39;t change the order of the widgets for RTL languages.
Definition: widget_type.h:76
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:832
static RailType GetRailType(TileIndex t)
Gets the rail type of the given tile.
Definition: rail_map.h:117
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
Base class for windows opened from a toolbar.
Definition: window_gui.h:856
Build an electric path signal.
Definition: rail_widget.h:91
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
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:789
Track in the upper corner of the tile (north)
Definition: track_type.h:25
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1459
Scrollbar of the matrix widget.
Definition: rail_widget.h:65
(Toggle) Button with text
Definition: widget_type.h:55
Upper and lower track.
Definition: track_type.h:49
Southwest.
static void SetDefaultRailGui()
Set the initial (default) railtype to use.
Definition: rail_gui.cpp:1908
build a rail track
Definition: command_type.h:178
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:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
StringID name
Name of this class.
Definition: newgrf_class.h:41