OpenTTD Source 20250311-master-g40ddc03423
rail_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "gui.h"
12#include "station_base.h"
13#include "waypoint_base.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_badge.h"
21#include "newgrf_station.h"
22#include "company_base.h"
23#include "strings_func.h"
24#include "window_func.h"
25#include "sound_func.h"
26#include "company_func.h"
27#include "dropdown_type.h"
28#include "dropdown_func.h"
29#include "tunnelbridge.h"
30#include "tilehighlight_func.h"
31#include "spritecache.h"
33#include "hotkeys.h"
34#include "engine_base.h"
35#include "vehicle_func.h"
36#include "zoom_func.h"
37#include "rail_gui.h"
38#include "station_cmd.h"
39#include "tunnelbridge_cmd.h"
40#include "waypoint_cmd.h"
41#include "rail_cmd.h"
42#include "timer/timer.h"
44#include "picker_gui.h"
45
46#include "station_map.h"
47#include "tunnelbridge_map.h"
48
49#include "widgets/rail_widget.h"
50
51#include "safeguards.h"
52
53
60
66
73
74
75static void HandleStationPlacement(TileIndex start, TileIndex end);
76static void ShowBuildTrainDepotPicker(Window *parent);
77static void ShowBuildWaypointPicker(Window *parent);
78static Window *ShowStationBuilder(Window *parent);
79static void ShowSignalBuilder(Window *parent);
80
85static bool IsStationAvailable(const StationSpec *statspec)
86{
87 if (statspec == nullptr || !statspec->callback_mask.Test(StationCallbackMask::Avail)) return true;
88
89 uint16_t cb_res = GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, nullptr, INVALID_TILE);
90 if (cb_res == CALLBACK_FAILED) return true;
91
93}
94
95void CcPlaySound_CONSTRUCTION_RAIL(Commands, const CommandCost &result, TileIndex tile)
96{
97 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
98}
99
100static void GenericPlaceRail(TileIndex tile, Track track)
101{
103 Command<CMD_REMOVE_SINGLE_RAIL>::Post(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
104 tile, track);
105 } else {
106 Command<CMD_BUILD_SINGLE_RAIL>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
108 }
109}
110
126
128static const Track _place_depot_extra_track[12] = {
129 TRACK_LEFT, TRACK_UPPER, TRACK_UPPER, TRACK_RIGHT, // First additional track for directions 0..3
130 TRACK_X, TRACK_Y, TRACK_X, TRACK_Y, // Second additional track
131 TRACK_LOWER, TRACK_LEFT, TRACK_RIGHT, TRACK_LOWER, // Third additional track
132};
133
140
141void CcRailDepot(Commands, const CommandCost &result, TileIndex tile, RailType, DiagDirection dir)
142{
143 if (result.Failed()) return;
144
145 if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
147
148 tile += TileOffsByDiagDir(dir);
149
150 if (IsTileType(tile, MP_RAILWAY)) {
152
153 /* Don't place the rail straight out of the depot of there is another depot across from it. */
154 Tile double_depot_tile = tile + TileOffsByDiagDir(dir);
155 bool is_double_depot = IsValidTile(double_depot_tile) && IsRailDepotTile(double_depot_tile);
156 if (!is_double_depot) PlaceExtraDepotRail(tile, _place_depot_extra_dir[dir + 4], _place_depot_extra_track[dir + 4]);
157
159 }
160}
161
167{
170 return;
171 }
172
173 Axis axis = GetAxisForNewRailWaypoint(tile);
174 if (IsValidAxis(axis)) {
175 /* Valid tile for waypoints */
177 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
178 } else {
179 /* Tile where we can't build rail waypoints. This is always going to fail,
180 * but provides the user with a proper error message. */
181 Command<CMD_BUILD_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, tile, AXIS_X, 1, 1, STAT_CLASS_WAYP, 0, StationID::Invalid(), false);
182 }
183}
184
185void CcStation(Commands, const CommandCost &result, TileIndex tile)
186{
187 if (result.Failed()) return;
188
189 if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
190 /* Only close the station builder window if the default station and non persistent building is chosen. */
192}
193
199{
202 VpSetPlaceSizingLimit(-1);
205 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
206 } else {
209 if (!_station_gui.axis) Swap(w, h);
210
213 uint8_t numtracks = _settings_client.gui.station_numtracks;
214 uint8_t platlength = _settings_client.gui.station_platlength;
215 bool adjacent = _ctrl_pressed;
216
217 auto proc = [=](bool test, StationID to_join) -> bool {
218 if (test) {
219 return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, StationID::Invalid(), adjacent).Succeeded();
220 } else {
221 return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, to_join, adjacent);
222 }
223 };
224
225 ShowSelectStationIfNeeded(TileArea(tile, w, h), proc);
226 }
227}
228
235{
237
238 if (trackbits & TRACK_BIT_VERT) { // N-S direction
239 trackbits = (_tile_fract_coords.x <= _tile_fract_coords.y) ? TRACK_BIT_RIGHT : TRACK_BIT_LEFT;
240 }
241
242 if (trackbits & TRACK_BIT_HORZ) { // E-W direction
243 trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER;
244 }
245
246 Track track = FindFirstTrack(trackbits);
247
249 Command<CMD_REMOVE_SINGLE_SIGNAL>::Post(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM, CcPlaySound_CONSTRUCTION_RAIL, tile, track);
250 } else {
251 /* Which signals should we cycle through? */
252 bool tile_has_signal = IsPlainRailTile(tile) && IsValidTrack(track) && HasSignalOnTrack(tile, track);
253 SignalType cur_signal_on_tile = tile_has_signal ? GetSignalType(tile, track) : _cur_signal_type;
254 SignalType cycle_start;
255 SignalType cycle_end;
256
257 /* Start with the least restrictive case: the player wants to cycle through all signals they can see. */
260 cycle_end = SIGTYPE_LAST;
261 } else {
262 /* Only cycle through signals of the same group (block or path) as the current signal on the tile. */
263 if (cur_signal_on_tile <= SIGTYPE_LAST_NOPBS) {
264 /* Block signals only. */
265 cycle_start = SIGTYPE_BLOCK;
266 cycle_end = SIGTYPE_LAST_NOPBS;
267 } else {
268 /* Path signals only. */
269 cycle_start = SIGTYPE_PBS;
270 cycle_end = SIGTYPE_LAST;
271 }
272 }
273
274 if (FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr) {
275 /* signal GUI is used */
276 Command<CMD_BUILD_SINGLE_SIGNAL>::Post(_convert_signal_button ? STR_ERROR_SIGNAL_CAN_T_CONVERT_SIGNALS_HERE : STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
277 tile, track, _cur_signal_type, _cur_signal_variant, _convert_signal_button, false, _ctrl_pressed, cycle_start, cycle_end, 0, 0);
278 } else {
280 Command<CMD_BUILD_SINGLE_SIGNAL>::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
281 tile, track, _settings_client.gui.default_signal_type, sigvar, false, false, _ctrl_pressed, cycle_start, cycle_end, 0, 0);
282
283 }
284 }
285}
286
292static void PlaceRail_Bridge(TileIndex tile, Window *w)
293{
294 if (IsBridgeTile(tile)) {
295 TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
296 Point pt = {0, 0};
297 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
298 } else {
300 }
301}
302
304void CcBuildRailTunnel(Commands, const CommandCost &result, TileIndex tile)
305{
306 if (result.Succeeded()) {
307 if (_settings_client.sound.confirm) SndPlayTileFx(SND_20_CONSTRUCTION_RAIL, tile);
309 } else {
311 }
312}
313
326
333{
334 if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return false;
335
336 /* allow ctrl to switch remove mode only for these widgets */
337 for (WidgetID i = WID_RAT_BUILD_NS; i <= WID_RAT_BUILD_STATION; i++) {
338 if ((i <= WID_RAT_AUTORAIL || i >= WID_RAT_BUILD_WAYPOINT) && w->IsWidgetLowered(i)) {
340 return true;
341 }
342 }
343
344 return false;
345}
346
347
354{
355 if (w->IsWidgetDisabled(WID_RAT_REMOVE)) return;
358
359 /* handle station builder */
362 /* starting drag & drop remove */
364 SetTileSelectSize(1, 1);
365 } else {
366 VpSetPlaceSizingLimit(-1);
367 }
368 } else {
369 /* starting station build mode */
373 if (_station_gui.axis == 0) Swap(x, y);
374 SetTileSelectSize(x, y);
375 } else {
376 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
377 }
378 }
379 }
380}
381
382static void DoRailroadTrack(Track track)
383{
385 Command<CMD_REMOVE_RAILROAD_TRACK>::Post(STR_ERROR_CAN_T_REMOVE_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
386 TileVirtXY(_thd.selend.x, _thd.selend.y), TileVirtXY(_thd.selstart.x, _thd.selstart.y), track);
387 } else {
388 Command<CMD_BUILD_RAILROAD_TRACK>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_TRACK, CcPlaySound_CONSTRUCTION_RAIL,
390 }
391}
392
393static void HandleAutodirPlacement()
394{
395 Track trackstat = static_cast<Track>( _thd.drawstyle & HT_DIR_MASK); // 0..5
396
397 if (_thd.drawstyle & HT_RAIL) { // one tile case
398 GenericPlaceRail(TileVirtXY(_thd.selend.x, _thd.selend.y), trackstat);
399 return;
400 }
401
402 DoRailroadTrack(trackstat);
403}
404
412{
413 Track track = (Track)GB(_thd.drawstyle, 0, 3); // 0..5
414
415 if ((_thd.drawstyle & HT_DRAG_MASK) == HT_RECT) { // one tile case
417 return;
418 }
419
420 /* _settings_client.gui.drag_signals_density is given as a parameter such that each user
421 * in a network game can specify their own signal density */
423 Command<CMD_REMOVE_SIGNAL_TRACK>::Post(STR_ERROR_CAN_T_REMOVE_SIGNALS_FROM, CcPlaySound_CONSTRUCTION_RAIL,
424 TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), track, _ctrl_pressed);
425 } else {
426 bool sig_gui = FindWindowById(WC_BUILD_SIGNAL, 0) != nullptr;
429 Command<CMD_BUILD_SIGNAL_TRACK>::Post(STR_ERROR_CAN_T_BUILD_SIGNALS_HERE, CcPlaySound_CONSTRUCTION_RAIL,
431 }
432}
433
434
438 int last_user_action = INVALID_WID_RAT;
439
441 {
442 this->CreateNestedTree();
445 this->OnInvalidateData();
446
448 }
449
458
465
466 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
467 {
468 if (!gui_scope) return;
469
470 if (!ValParamRailType(this->railtype)) {
471 /* Close toolbar if rail type is not available. */
472 this->Close();
473 return;
474 }
475
477 for (const WidgetID widget : can_build_widgets) this->SetWidgetDisabledState(widget, !can_build);
478 if (!can_build) {
484 }
485 }
486
487 bool OnTooltip([[maybe_unused]] Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
488 {
490 if (can_build) return false;
491
492 if (std::ranges::find(can_build_widgets, widget) == std::end(can_build_widgets)) return false;
493
495 return true;
496 }
497
498 void OnInit() override
499 {
500 /* Configure the rail toolbar for the railtype. */
501 const RailTypeInfo *rti = GetRailTypeInfo(this->railtype);
510 }
511
517 {
518 this->railtype = railtype;
519 this->ReInit();
520 }
521
522 void UpdateRemoveWidgetStatus(WidgetID clicked_widget)
523 {
524 switch (clicked_widget) {
525 case WID_RAT_REMOVE:
526 /* If it is the removal button that has been clicked, do nothing,
527 * as it is up to the other buttons to drive removal status */
528 return;
529
530 case WID_RAT_BUILD_NS:
531 case WID_RAT_BUILD_X:
532 case WID_RAT_BUILD_EW:
533 case WID_RAT_BUILD_Y:
534 case WID_RAT_AUTORAIL:
538 /* Removal button is enabled only if the rail/signal/waypoint/station
539 * button is still lowered. Once raised, it has to be disabled */
540 this->SetWidgetDisabledState(WID_RAT_REMOVE, !this->IsWidgetLowered(clicked_widget));
541 break;
542
543 default:
544 /* When any other buttons than rail/signal/waypoint/station, raise and
545 * disable the removal button */
548 break;
549 }
550 }
551
552 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
553 {
554 if (widget == WID_RAT_CAPTION) {
555 const RailTypeInfo *rti = GetRailTypeInfo(this->railtype);
556 if (rti->max_speed > 0) {
558 }
559 return GetString(rti->strings.toolbar_caption);
560 }
561
562 return this->Window::GetWidgetString(widget, stringid);
563 }
564
565 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
566 {
567 if (widget < WID_RAT_BUILD_NS) return;
568
570 switch (widget) {
571 case WID_RAT_BUILD_NS:
573 this->last_user_action = widget;
574 break;
575
576 case WID_RAT_BUILD_X:
578 this->last_user_action = widget;
579 break;
580
581 case WID_RAT_BUILD_EW:
583 this->last_user_action = widget;
584 break;
585
586 case WID_RAT_BUILD_Y:
588 this->last_user_action = widget;
589 break;
590
591 case WID_RAT_AUTORAIL:
593 this->last_user_action = widget;
594 break;
595
596 case WID_RAT_DEMOLISH:
598 this->last_user_action = widget;
599 break;
600
603 ShowBuildTrainDepotPicker(this);
604 this->last_user_action = widget;
605 }
606 break;
607
609 this->last_user_action = widget;
610 if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT)) {
611 ShowBuildWaypointPicker(this);
612 }
613 break;
614
616 if (HandlePlacePushButton(this, WID_RAT_BUILD_STATION, SPR_CURSOR_RAIL_STATION, HT_RECT)) {
617 ShowStationBuilder(this);
618 this->last_user_action = widget;
619 }
620 break;
621
623 this->last_user_action = widget;
625 if (started != _ctrl_pressed) {
626 ShowSignalBuilder(this);
627 }
628 break;
629 }
630
632 HandlePlacePushButton(this, WID_RAT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
633 this->last_user_action = widget;
634 break;
635
638 this->last_user_action = widget;
639 break;
640
641 case WID_RAT_REMOVE:
643 break;
644
647 this->last_user_action = widget;
648 break;
649
650 default: NOT_REACHED();
651 }
652 this->UpdateRemoveWidgetStatus(widget);
654 }
655
657 {
658 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
659 return Window::OnHotkey(hotkey);
660 }
661
662 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
663 {
664 switch (this->last_user_action) {
665 case WID_RAT_BUILD_NS:
667 break;
668
669 case WID_RAT_BUILD_X:
671 break;
672
673 case WID_RAT_BUILD_EW:
675 break;
676
677 case WID_RAT_BUILD_Y:
679 break;
680
681 case WID_RAT_AUTORAIL:
683 break;
684
685 case WID_RAT_DEMOLISH:
687 break;
688
691 break;
692
694 PlaceRail_Waypoint(tile);
695 break;
696
698 PlaceRail_Station(tile);
699 break;
700
703 break;
704
706 PlaceRail_Bridge(tile, this);
707 break;
708
711 break;
712
715 break;
716
717 default: NOT_REACHED();
718 }
719 }
720
722 {
723 /* no dragging if you have pressed the convert button */
725
726 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
727 }
728
729 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
730 {
731 if (pt.x != -1) {
732 switch (select_proc) {
733 default: NOT_REACHED();
736 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_RAIL, _cur_railtype);
737 break;
738
739 case DDSP_PLACE_RAIL:
740 HandleAutodirPlacement();
741 break;
742
745 break;
746
748 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
749 break;
750
752 Command<CMD_CONVERT_RAIL>::Post(STR_ERROR_CAN_T_CONVERT_RAIL, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, _cur_railtype, _ctrl_pressed);
753 break;
754
758 /* Station */
760 bool keep_rail = !_ctrl_pressed;
761 Command<CMD_REMOVE_FROM_RAIL_STATION>::Post(STR_ERROR_CAN_T_REMOVE_PART_OF_STATION, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, keep_rail);
762 } else {
763 HandleStationPlacement(start_tile, end_tile);
764 }
765 } else {
766 /* Waypoint */
768 bool keep_rail = !_ctrl_pressed;
769 Command<CMD_REMOVE_FROM_RAIL_WAYPOINT>::Post(STR_ERROR_CAN_T_REMOVE_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, end_tile, start_tile, keep_rail);
770 } else {
771 TileArea ta(start_tile, end_tile);
772 Axis axis = select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y;
773 bool adjacent = _ctrl_pressed;
774
775 auto proc = [=](bool test, StationID to_join) -> bool {
776 if (test) {
778 } else {
780 }
781 };
782
784 }
785 }
786 break;
787 }
788 }
789 }
790
807
813
815 {
816 /* do not toggle Remove button by Ctrl when placing station */
818 return ES_NOT_HANDLED;
819 }
820
821 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
822 {
823 if (this->IsWidgetLowered(WID_RAT_BUILD_WAYPOINT)) CheckRedrawRailWaypointCoverage(this);
824 }
825
832 {
833 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
834 extern RailType _last_built_railtype;
835 Window *w = ShowBuildRailToolbar(_last_built_railtype);
836 if (w == nullptr) return ES_NOT_HANDLED;
837 return w->OnHotkey(hotkey);
838 }
839
840 static inline HotkeyList hotkeys{"railtoolbar", {
841 Hotkey('1', "build_ns", WID_RAT_BUILD_NS),
842 Hotkey('2', "build_x", WID_RAT_BUILD_X),
843 Hotkey('3', "build_ew", WID_RAT_BUILD_EW),
844 Hotkey('4', "build_y", WID_RAT_BUILD_Y),
845 Hotkey({'5', 'A' | WKC_GLOBAL_HOTKEY}, "autorail", WID_RAT_AUTORAIL),
846 Hotkey('6', "demolish", WID_RAT_DEMOLISH),
847 Hotkey('7', "depot", WID_RAT_BUILD_DEPOT),
848 Hotkey('8', "waypoint", WID_RAT_BUILD_WAYPOINT),
849 Hotkey('9', "station", WID_RAT_BUILD_STATION),
850 Hotkey('S', "signal", WID_RAT_BUILD_SIGNALS),
851 Hotkey('B', "bridge", WID_RAT_BUILD_BRIDGE),
852 Hotkey('T', "tunnel", WID_RAT_BUILD_TUNNEL),
853 Hotkey('R', "remove", WID_RAT_REMOVE),
854 Hotkey('C', "convert", WID_RAT_CONVERT_RAIL),
856};
857
858static constexpr NWidgetPart _nested_build_rail_widgets[] = {
860 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
861 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_RAT_CAPTION), SetTextStyle(TC_WHITE),
862 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
863 EndContainer(),
865 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_NS),
866 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_RAIL_NS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
867 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_X),
868 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_RAIL_NE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
869 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_EW),
870 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_RAIL_EW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
871 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_Y),
872 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_RAIL_NW, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TRACK),
873 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_AUTORAIL),
874 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_AUTORAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_AUTORAIL),
875
876 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), EndContainer(),
877
878 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_DEMOLISH),
879 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
880 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_DEPOT),
881 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DEPOT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_TRAIN_DEPOT_FOR_BUILDING),
882 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_WAYPOINT),
883 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_WAYPOINT, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL_TO_WAYPOINT),
884 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_STATION),
885 SetFill(0, 1), SetMinimalSize(42, 22), SetSpriteTip(SPR_IMG_RAIL_STATION, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_STATION),
886 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_SIGNALS),
887 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_RAIL_SIGNALS, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_SIGNALS),
888 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_BRIDGE),
889 SetFill(0, 1), SetMinimalSize(42, 22), SetSpriteTip(SPR_IMG_BRIDGE, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_BRIDGE),
890 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_BUILD_TUNNEL),
891 SetFill(0, 1), SetMinimalSize(20, 22), SetSpriteTip(SPR_IMG_TUNNEL_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_BUILD_RAILROAD_TUNNEL),
892 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_REMOVE),
893 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_REMOVE, STR_RAIL_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR),
894 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_RAT_CONVERT_RAIL),
895 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_CONVERT_RAIL, STR_RAIL_TOOLBAR_TOOLTIP_CONVERT_RAIL),
896 EndContainer(),
897};
898
899static WindowDesc _build_rail_desc(
900 WDP_ALIGN_TOOLBAR, "toolbar_rail", 0, 0,
903 _nested_build_rail_widgets,
904 &BuildRailToolbarWindow::hotkeys
905);
906
907
917{
918 if (!Company::IsValidID(_local_company)) return nullptr;
919 if (!ValParamRailType(railtype)) return nullptr;
920
922 _cur_railtype = railtype;
924 return new BuildRailToolbarWindow(_build_rail_desc, railtype);
925}
926
927/* TODO: For custom stations, respect their allowed platforms/lengths bitmasks!
928 * --pasky */
929
930static void HandleStationPlacement(TileIndex start, TileIndex end)
931{
932 TileArea ta(start, end);
933 uint numtracks = ta.w;
934 uint platlength = ta.h;
935
936 if (_station_gui.axis == AXIS_X) Swap(numtracks, platlength);
937
940 bool adjacent = _ctrl_pressed;
941
942 auto proc = [=](bool test, StationID to_join) -> bool {
943 if (test) {
944 return Command<CMD_BUILD_RAIL_STATION>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_RAIL_STATION>()), ta.tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, StationID::Invalid(), adjacent).Succeeded();
945 } else {
946 return Command<CMD_BUILD_RAIL_STATION>::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, ta.tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, to_join, adjacent);
947 }
948 };
949
951}
952
958static bool StationUsesDefaultType(const BaseStation *bst)
959{
960 for (TileIndex t : bst->train_station) {
961 if (bst->TileBelongsToRailStation(t) && HasStationRail(t) && GetCustomStationSpecIndex(t) == 0) return true;
962 }
963 return false;
964}
965
967public:
969
970 GrfSpecFeature GetFeature() const override { return GSF_STATIONS; }
971
972 StringID GetClassTooltip() const override { return STR_PICKER_STATION_CLASS_TOOLTIP; }
973 StringID GetTypeTooltip() const override { return STR_PICKER_STATION_TYPE_TOOLTIP; }
974
975 bool IsActive() const override
976 {
977 for (const auto &cls : StationClass::Classes()) {
978 if (IsWaypointClass(cls)) continue;
979 for (const auto *spec : cls.Specs()) {
980 if (spec != nullptr) return true;
981 }
982 }
983 return false;
984 }
985
986 bool HasClassChoice() const override
987 {
988 return std::ranges::count_if(StationClass::Classes(), std::not_fn(IsWaypointClass)) > 1;
989 }
990
991 int GetSelectedClass() const override { return _station_gui.sel_class; }
992 void SetSelectedClass(int id) const override { _station_gui.sel_class = this->GetClassIndex(id); }
993
994 StringID GetClassName(int id) const override
995 {
996 const auto *sc = GetClass(id);
997 if (IsWaypointClass(*sc)) return INVALID_STRING_ID;
998 return sc->name;
999 }
1000
1001 int GetSelectedType() const override { return _station_gui.sel_type; }
1002 void SetSelectedType(int id) const override { _station_gui.sel_type = id; }
1003
1004 StringID GetTypeName(int cls_id, int id) const override
1005 {
1006 const auto *spec = this->GetSpec(cls_id, id);
1007 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_STATION : spec->name;
1008 }
1009
1010 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1011 {
1012 const auto *spec = this->GetSpec(cls_id, id);
1013 if (spec == nullptr) return {};
1014 return spec->badges;
1015 }
1016
1017 bool IsTypeAvailable(int cls_id, int id) const override
1018 {
1019 return IsStationAvailable(this->GetSpec(cls_id, id));
1020 }
1021
1022 void DrawType(int x, int y, int cls_id, int id) const override
1023 {
1024 if (!DrawStationTile(x, y, _cur_railtype, _station_gui.axis, this->GetClassIndex(cls_id), id)) {
1025 StationPickerDrawSprite(x, y, StationType::Rail, _cur_railtype, INVALID_ROADTYPE, 2 + _station_gui.axis);
1026 }
1027 }
1028
1029 void FillUsedItems(std::set<PickerItem> &items) override
1030 {
1031 bool default_added = false;
1032 for (const Station *st : Station::Iterate()) {
1033 if (st->owner != _local_company) continue;
1034 if (!default_added && StationUsesDefaultType(st)) {
1035 items.insert({0, 0, STAT_CLASS_DFLT, 0});
1036 default_added = true;
1037 }
1038 for (const auto &sm : st->speclist) {
1039 if (sm.spec == nullptr) continue;
1040 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1041 }
1042 }
1043 }
1044
1045 static StationPickerCallbacks instance;
1046};
1047/* static */ StationPickerCallbacks StationPickerCallbacks::instance;
1048
1050private:
1052
1085
1086public:
1088 {
1090 this->ConstructWindow();
1091 }
1092
1107
1108 void Close([[maybe_unused]] int data = 0) override
1109 {
1111 this->PickerWindow::Close();
1112 }
1113
1114 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1115 {
1116 if (gui_scope) {
1118 this->CheckSelectedSize(statspec);
1119 }
1120
1122 }
1123
1124 void OnPaint() override
1125 {
1127
1129 SetTileSelectSize(1, 1);
1130 } else {
1133 if (_station_gui.axis == AXIS_X) Swap(x, y);
1135 SetTileSelectSize(x, y);
1136 }
1137 }
1138
1140
1141 if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1142
1143 for (uint bits = 0; bits < 7; bits++) {
1145 if (statspec == nullptr) {
1148 } else {
1151 }
1152 }
1153
1154 this->DrawWidgets();
1155
1156 if (this->IsShaded()) return;
1157 /* 'Accepts' and 'Supplies' texts. */
1158 Rect r = this->GetWidget<NWidgetBase>(WID_BRAS_COVERAGE_TEXTS)->GetCurrentRect();
1159 const int bottom = r.bottom;
1160 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1161 if (statspec != nullptr) r.top = DrawBadgeNameList(r, statspec->badges, GSF_STATIONS);
1163 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
1164 /* Resize background if the window is too small.
1165 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1166 * (This is the case, if making the window bigger moves the mouse into the window.) */
1167 if (r.top > bottom) {
1168 this->coverage_height += r.top - bottom;
1169 this->ReInit();
1170 }
1171 }
1172
1174 {
1175 switch (widget) {
1180 break;
1181
1183 size.height = this->coverage_height;
1184 break;
1185
1186 default:
1187 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1188 break;
1189 }
1190 }
1191
1192 void DrawWidget(const Rect &r, WidgetID widget) const override
1193 {
1195
1196 switch (widget) {
1198 /* Set up a clipping area for the '/' station preview */
1200 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1202 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
1203 int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
1205 StationPickerDrawSprite(x, y, StationType::Rail, _cur_railtype, INVALID_ROADTYPE, 2);
1206 }
1207 }
1208 break;
1209 }
1210
1212 /* Set up a clipping area for the '\' station preview */
1214 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1216 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
1217 int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
1219 StationPickerDrawSprite(x, y, StationType::Rail, _cur_railtype, INVALID_ROADTYPE, 3);
1220 }
1221 }
1222 break;
1223 }
1224
1225 default:
1226 this->PickerWindow::DrawWidget(r, widget);
1227 break;
1228 }
1229 }
1230
1231 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1232 {
1233 switch (widget) {
1236 this->RaiseWidget(WID_BRAS_PLATFORM_DIR_X + _station_gui.axis);
1238 this->LowerWidget(WID_BRAS_PLATFORM_DIR_X + _station_gui.axis);
1240 this->SetDirty();
1242 break;
1243
1253
1256
1258 if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1259 /* The previously selected number of platforms in invalid */
1260 for (uint i = 0; i < 7; i++) {
1261 if (!HasBit(statspec->disallowed_lengths, i)) {
1264 break;
1265 }
1266 }
1267 }
1268
1269 this->LowerWidget(_settings_client.gui.station_numtracks + WID_BRAS_PLATFORM_NUM_BEGIN);
1272 this->SetDirty();
1274 break;
1275 }
1276
1286
1289
1291 if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1292 /* The previously selected number of tracks in invalid */
1293 for (uint i = 0; i < 7; i++) {
1294 if (!HasBit(statspec->disallowed_platforms, i)) {
1297 break;
1298 }
1299 }
1300 }
1301
1303 this->LowerWidget(_settings_client.gui.station_platlength + WID_BRAS_PLATFORM_LEN_BEGIN);
1305 this->SetDirty();
1307 break;
1308 }
1309
1312
1314
1315 /* get the first allowed length/number of platforms */
1317 if (statspec != nullptr && HasBit(statspec->disallowed_lengths, _settings_client.gui.station_platlength - 1)) {
1318 for (uint i = 0; i < 7; i++) {
1319 if (!HasBit(statspec->disallowed_lengths, i)) {
1322 break;
1323 }
1324 }
1325 }
1326 if (statspec != nullptr && HasBit(statspec->disallowed_platforms, _settings_client.gui.station_numtracks - 1)) {
1327 for (uint i = 0; i < 7; i++) {
1328 if (!HasBit(statspec->disallowed_platforms, i)) {
1331 break;
1332 }
1333 }
1334 }
1335
1339 this->SetDirty();
1341 break;
1342 }
1343
1347
1351 this->SetDirty();
1352 SetViewportCatchmentStation(nullptr, true);
1353 break;
1354
1355 default:
1356 this->PickerWindow::OnClick(pt, widget, click_count);
1357 break;
1358 }
1359 }
1360
1361 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1362 {
1364 }
1365
1372 {
1373 if (_game_mode == GM_MENU) return ES_NOT_HANDLED;
1375 if (w == nullptr) return ES_NOT_HANDLED;
1376 return w->OnHotkey(hotkey);
1377 }
1378
1379 static inline HotkeyList hotkeys{"buildrailstation", {
1380 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1382};
1383
1384static constexpr NWidgetPart _nested_station_builder_widgets[] = {
1386 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1387 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_STATION_BUILD_RAIL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1388 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1389 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1390 EndContainer(),
1394 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1396 NWidget(WWT_LABEL, INVALID_COLOUR), SetMinimalSize(144, 11), SetFill(1, 0), SetStringTip(STR_STATION_BUILD_ORIENTATION),
1398 NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAS_PLATFORM_DIR_X), SetFill(0, 0), SetToolTip(STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP), EndContainer(),
1399 NWidget(WWT_PANEL, COLOUR_GREY, WID_BRAS_PLATFORM_DIR_Y), SetFill(0, 0), SetToolTip(STR_STATION_BUILD_RAILROAD_ORIENTATION_TOOLTIP), EndContainer(),
1400 EndContainer(),
1401 NWidget(WWT_LABEL, INVALID_COLOUR), SetMinimalSize(144, 11), SetFill(1, 0), SetStringTip(STR_STATION_BUILD_NUMBER_OF_TRACKS),
1403 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_1), SetAspect(1.25f), SetStringTip(STR_BLACK_1, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1404 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_2), SetAspect(1.25f), SetStringTip(STR_BLACK_2, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1405 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_3), SetAspect(1.25f), SetStringTip(STR_BLACK_3, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1406 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_4), SetAspect(1.25f), SetStringTip(STR_BLACK_4, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1407 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_5), SetAspect(1.25f), SetStringTip(STR_BLACK_5, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1408 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_6), SetAspect(1.25f), SetStringTip(STR_BLACK_6, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1409 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_NUM_7), SetAspect(1.25f), SetStringTip(STR_BLACK_7, STR_STATION_BUILD_NUMBER_OF_TRACKS_TOOLTIP),
1410 EndContainer(),
1411 NWidget(WWT_LABEL, INVALID_COLOUR), SetMinimalSize(144, 11), SetFill(1, 0), SetStringTip(STR_STATION_BUILD_PLATFORM_LENGTH),
1413 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_1), SetAspect(1.25f), SetStringTip(STR_BLACK_1, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1414 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_2), SetAspect(1.25f), SetStringTip(STR_BLACK_2, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1415 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_3), SetAspect(1.25f), SetStringTip(STR_BLACK_3, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1416 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_4), SetAspect(1.25f), SetStringTip(STR_BLACK_4, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1417 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_5), SetAspect(1.25f), SetStringTip(STR_BLACK_5, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1418 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_6), SetAspect(1.25f), SetStringTip(STR_BLACK_6, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1419 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_LEN_7), SetAspect(1.25f), SetStringTip(STR_BLACK_7, STR_STATION_BUILD_PLATFORM_LENGTH_TOOLTIP),
1420 EndContainer(),
1422 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_PLATFORM_DRAG_N_DROP), SetMinimalSize(75, 12), SetStringTip(STR_STATION_BUILD_DRAG_DROP, STR_STATION_BUILD_DRAG_DROP_TOOLTIP),
1423 EndContainer(),
1424 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1426 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_OFF), SetMinimalSize(60, 12), SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1427 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAS_HIGHLIGHT_ON), SetMinimalSize(60, 12), SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1428 EndContainer(),
1429 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BRAS_COVERAGE_TEXTS), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1430 EndContainer(),
1431 EndContainer(),
1432 EndContainer(),
1434 EndContainer(),
1435};
1436
1439 WDP_AUTO, "build_station_rail", 0, 0,
1442 _nested_station_builder_widgets,
1443 &BuildRailStationWindow::hotkeys
1444);
1445
1448{
1450}
1451
1453private:
1456
1461 void DrawSignalSprite(const Rect &r, SpriteID image) const
1462 {
1463 Point offset;
1464 Dimension sprite_size = GetSpriteSize(image, &offset);
1466 int x = CenterBounds(ir.left, ir.right, sprite_size.width - offset.x) - offset.x; // centered
1467 int y = ir.top - sig_sprite_bottom_offset +
1468 (ir.Height() + sig_sprite_size.height) / 2; // aligned to bottom
1469
1470 DrawSprite(image, PAL_NONE, x, y);
1471 }
1472
1475 {
1477
1478 this->GetWidget<NWidgetStacked>(WID_BS_BLOCK_SEL)->SetDisplayedPlane(show_non_path_signals ? 0 : SZSP_NONE);
1479 this->GetWidget<NWidgetStacked>(WID_BS_BLOCK_SPACER_SEL)->SetDisplayedPlane(show_non_path_signals ? 0 : SZSP_NONE);
1480 }
1481
1482public:
1484 {
1485 this->CreateNestedTree();
1486 this->SetSignalUIMode();
1488 this->OnInvalidateData();
1489 }
1490
1491 void Close([[maybe_unused]] int data = 0) override
1492 {
1493 _convert_signal_button = false;
1495 }
1496
1497 void OnInit() override
1498 {
1499 /* Calculate maximum signal sprite size. */
1500 this->sig_sprite_size.width = 0;
1501 this->sig_sprite_size.height = 0;
1502 this->sig_sprite_bottom_offset = 0;
1504 for (uint type = SIGTYPE_BLOCK; type < SIGTYPE_END; type++) {
1505 for (uint variant = SIG_ELECTRIC; variant <= SIG_SEMAPHORE; variant++) {
1506 for (uint lowered = 0; lowered < 2; lowered++) {
1507 Point offset;
1509 this->sig_sprite_bottom_offset = std::max<int>(this->sig_sprite_bottom_offset, sprite_size.height);
1510 this->sig_sprite_size.width = std::max<int>(this->sig_sprite_size.width, sprite_size.width - offset.x);
1511 this->sig_sprite_size.height = std::max<int>(this->sig_sprite_size.height, sprite_size.height - offset.y);
1512 }
1513 }
1514 }
1515 }
1516
1518 {
1519 if (widget == WID_BS_DRAG_SIGNALS_DENSITY_LABEL) {
1520 /* Two digits for signals density. */
1521 size.width = std::max(size.width, 2 * GetDigitWidth() + padding.width + WidgetDimensions::scaled.framerect.Horizontal());
1523 size.width = std::max(size.width, this->sig_sprite_size.width + padding.width);
1524 size.height = std::max(size.height, this->sig_sprite_size.height + padding.height);
1525 }
1526 }
1527
1528 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1529 {
1530 switch (widget) {
1533
1534 default:
1535 return this->Window::GetWidgetString(widget, stringid);
1536 }
1537 }
1538
1539 void DrawWidget(const Rect &r, WidgetID widget) const override
1540 {
1542 /* Extract signal from widget number. */
1543 int type = (widget - WID_BS_SEMAPHORE_NORM) % SIGTYPE_END;
1544 int var = SIG_SEMAPHORE - (widget - WID_BS_SEMAPHORE_NORM) / SIGTYPE_END; // SignalVariant order is reversed compared to the widgets.
1545 SpriteID sprite = GetRailTypeInfo(_cur_railtype)->gui_sprites.signals[type][var][this->IsWidgetLowered(widget)];
1546
1547 this->DrawSignalSprite(r, sprite);
1548 }
1549 }
1550
1551 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1552 {
1553 switch (widget) {
1567
1568 _cur_signal_type = (SignalType)((uint)((widget - WID_BS_SEMAPHORE_NORM) % (SIGTYPE_LAST + 1)));
1570
1571 /* Update default (last-used) signal type in config file. */
1573
1574 /* If 'remove' button of rail build toolbar is active, disable it. */
1577 if (w != nullptr) ToggleRailButton_Remove(w);
1578 }
1579
1580 break;
1581
1582 case WID_BS_CONVERT:
1584 break;
1585
1590 }
1591 break;
1592
1597 }
1598 break;
1599
1600 case WID_BS_TOGGLE_SIZE:
1602 this->SetSignalUIMode();
1603 this->ReInit();
1604 break;
1605
1606 default: break;
1607 }
1608
1609 this->InvalidateData();
1610 }
1611
1627};
1628
1631 /* Title bar and buttons. */
1633 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1634 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BS_CAPTION), SetStringTip(STR_BUILD_SIGNAL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1635 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_BS_TOGGLE_SIZE), SetSpriteTip(SPR_LARGE_SMALL_WINDOW, STR_BUILD_SIGNAL_TOGGLE_ADVANCED_SIGNAL_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_TOGGLE_SIZE),
1636 EndContainer(),
1637
1638 /* Container for both signal groups, spacers, and convert/autofill buttons. */
1640 /* Block signals (can be hidden). */
1641 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_BS_BLOCK_SEL),
1643 /* Semaphore block signals. */
1645 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_NORM), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_NORM_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1646 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_ENTRY), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_ENTRY_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1647 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_EXIT), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_EXIT_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1648 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_COMBO), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_COMBO_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1649 EndContainer(),
1650 /* Electric block signals. */
1652 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_NORM), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_NORM_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1653 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_ENTRY), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_ENTRY_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1654 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_EXIT), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_EXIT_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1655 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_COMBO), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_COMBO_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1656 EndContainer(),
1657 EndContainer(),
1658 EndContainer(),
1659
1660 /* Divider (only shown if block signals visible). */
1662 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(0, 0), SetMinimalSize(4, 0), EndContainer(),
1663 EndContainer(),
1664
1665 /* Path signals. */
1667 /* Semaphore path signals. */
1669 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_PBS), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_PBS_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1670 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_SEMAPHORE_PBS_OWAY), SetToolTip(STR_BUILD_SIGNAL_SEMAPHORE_PBS_OWAY_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1671 EndContainer(),
1672 /* Electric path signals. */
1674 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_PBS), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_PBS_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1675 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_BS_ELECTRIC_PBS_OWAY), SetToolTip(STR_BUILD_SIGNAL_ELECTRIC_PBS_OWAY_TOOLTIP), SetMinimalSize(22, 22), EndContainer(),
1676 EndContainer(),
1677 EndContainer(),
1678
1679 /* Convert/autofill buttons. */
1681 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_BS_CONVERT), SetSpriteTip(SPR_IMG_SIGNAL_CONVERT, STR_BUILD_SIGNAL_CONVERT_TOOLTIP), SetFill(0, 1),
1682 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetToolTip(STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetFill(0, 1),
1684 NWidget(WWT_LABEL, INVALID_COLOUR, WID_BS_DRAG_SIGNALS_DENSITY_LABEL), SetToolTip(STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_TOOLTIP), SetTextStyle(TC_ORANGE), SetFill(1, 1),
1686 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_BS_DRAG_SIGNALS_DENSITY_DECREASE), SetMinimalSize(9, 12), SetArrowWidgetTypeTip(AWV_DECREASE, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_DECREASE_TOOLTIP),
1687 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_BS_DRAG_SIGNALS_DENSITY_INCREASE), SetMinimalSize(9, 12), SetArrowWidgetTypeTip(AWV_INCREASE, STR_BUILD_SIGNAL_DRAG_SIGNALS_DENSITY_INCREASE_TOOLTIP),
1688 EndContainer(),
1689 EndContainer(),
1690 EndContainer(),
1691 EndContainer(),
1692 EndContainer(),
1693};
1694
1697 WDP_AUTO, nullptr, 0, 0,
1701);
1702
1706static void ShowSignalBuilder(Window *parent)
1707{
1709}
1710
1713 {
1716 }
1717
1719 {
1720 if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1721
1724 }
1725
1726 void DrawWidget(const Rect &r, WidgetID widget) const override
1727 {
1728 if (!IsInsideMM(widget, WID_BRAD_DEPOT_NE, WID_BRAD_DEPOT_NW + 1)) return;
1729
1732 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1734 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1735 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1736 DrawTrainDepotSprite(x, y, widget - WID_BRAD_DEPOT_NE + DIAGDIR_NE, _cur_railtype);
1737 }
1738 }
1739
1740 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1741 {
1742 switch (widget) {
1743 case WID_BRAD_DEPOT_NE:
1744 case WID_BRAD_DEPOT_SE:
1745 case WID_BRAD_DEPOT_SW:
1746 case WID_BRAD_DEPOT_NW:
1751 this->SetDirty();
1752 break;
1753 }
1754 }
1755};
1756
1760 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1761 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1762 EndContainer(),
1763 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1766 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_NW), SetToolTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1767 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_SW), SetToolTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1768 EndContainer(),
1770 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_NE), SetToolTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1771 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BRAD_DEPOT_SE), SetToolTip(STR_BUILD_DEPOT_TRAIN_ORIENTATION_TOOLTIP),
1772 EndContainer(),
1773 EndContainer(),
1774 EndContainer(),
1775};
1776
1777static WindowDesc _build_depot_desc(
1778 WDP_AUTO, nullptr, 0, 0,
1782);
1783
1784static void ShowBuildTrainDepotPicker(Window *parent)
1785{
1786 new BuildRailDepotWindow(_build_depot_desc, parent);
1787}
1788
1790public:
1792
1793 GrfSpecFeature GetFeature() const override { return GSF_STATIONS; }
1794
1795 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1796 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1797
1798 bool IsActive() const override
1799 {
1800 for (const auto &cls : StationClass::Classes()) {
1801 if (!IsWaypointClass(cls)) continue;
1802 for (const auto *spec : cls.Specs()) {
1803 if (spec != nullptr) return true;
1804 }
1805 }
1806 return false;
1807 }
1808
1809 bool HasClassChoice() const override
1810 {
1811 return std::ranges::count_if(StationClass::Classes(), IsWaypointClass) > 1;
1812 }
1813
1814 void Close(int) override { ResetObjectToPlace(); }
1815 int GetSelectedClass() const override { return _waypoint_gui.sel_class; }
1816 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1817
1818 StringID GetClassName(int id) const override
1819 {
1820 const auto *sc = GetClass(id);
1821 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1822 return sc->name;
1823 }
1824
1825 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1826 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1827
1828 StringID GetTypeName(int cls_id, int id) const override
1829 {
1830 const auto *spec = this->GetSpec(cls_id, id);
1831 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1832 }
1833
1834 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1835 {
1836 const auto *spec = this->GetSpec(cls_id, id);
1837 if (spec == nullptr) return {};
1838 return spec->badges;
1839 }
1840
1841 bool IsTypeAvailable(int cls_id, int id) const override
1842 {
1843 return IsStationAvailable(this->GetSpec(cls_id, id));
1844 }
1845
1846 void DrawType(int x, int y, int cls_id, int id) const override
1847 {
1848 DrawWaypointSprite(x, y, this->GetClassIndex(cls_id), id, _cur_railtype);
1849 }
1850
1851 void FillUsedItems(std::set<PickerItem> &items) override
1852 {
1853 bool default_added = false;
1854 for (const Waypoint *wp : Waypoint::Iterate()) {
1855 if (wp->owner != _local_company || HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1856 if (!default_added && StationUsesDefaultType(wp)) {
1857 items.insert({0, 0, STAT_CLASS_WAYP, 0});
1858 default_added = true;
1859 }
1860 for (const auto &sm : wp->speclist) {
1861 if (sm.spec == nullptr) continue;
1862 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1863 }
1864 }
1865 }
1866
1867 static WaypointPickerCallbacks instance;
1868};
1869/* static */ WaypointPickerCallbacks WaypointPickerCallbacks::instance;
1870
1872 BuildRailWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TRANSPORT_RAIL, WaypointPickerCallbacks::instance)
1873 {
1874 this->ConstructWindow();
1875 }
1876
1877 static inline HotkeyList hotkeys{"buildrailwaypoint", {
1878 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1879 }};
1880};
1881
1885 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1886 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1887 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1888 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1889 EndContainer(),
1893 EndContainer(),
1894};
1895
1896static WindowDesc _build_waypoint_desc(
1897 WDP_AUTO, "build_waypoint", 0, 0,
1901 &BuildRailWaypointWindow::hotkeys
1902);
1903
1904static void ShowBuildWaypointPicker(Window *parent)
1905{
1906 if (!WaypointPickerCallbacks::instance.IsActive()) return;
1907 new BuildRailWaypointWindow(_build_waypoint_desc, parent);
1908}
1909
1921
1927{
1928 extern RailType _last_built_railtype;
1929 if (disable && _last_built_railtype == RAILTYPE_ELECTRIC) {
1930 _last_built_railtype = _cur_railtype = RAILTYPE_RAIL;
1932 if (w != nullptr) w->ModifyRailType(_cur_railtype);
1933 }
1935}
1936
1939{
1941
1942 extern RailType _last_built_railtype;
1943 RailType rt;
1945 case 2: {
1946 /* Find the most used rail type */
1947 std::array<uint, RAILTYPE_END> count{};
1948 for (const auto t : Map::Iterate()) {
1951 count[GetRailType(t)]++;
1952 }
1953 }
1954
1955 rt = static_cast<RailType>(std::distance(std::begin(count), std::ranges::max_element(count)));
1956 if (count[rt] > 0) break;
1957
1958 /* No rail, just get the first available one */
1959 [[fallthrough]];
1960 }
1961 case 0: {
1962 /* Use first available type */
1963 std::vector<RailType>::const_iterator it = std::find_if(_sorted_railtypes.begin(), _sorted_railtypes.end(),
1964 [](RailType r) { return HasRailTypeAvail(_local_company, r); });
1965 rt = it != _sorted_railtypes.end() ? *it : RAILTYPE_BEGIN;
1966 break;
1967 }
1968 case 1: {
1969 /* Use last available type */
1970 std::vector<RailType>::const_reverse_iterator it = std::find_if(_sorted_railtypes.rbegin(), _sorted_railtypes.rend(),
1971 [](RailType r){ return HasRailTypeAvail(_local_company, r); });
1972 rt = it != _sorted_railtypes.rend() ? *it : RAILTYPE_BEGIN;
1973 break;
1974 }
1975 default:
1976 NOT_REACHED();
1977 }
1978
1979 _last_built_railtype = _cur_railtype = rt;
1981 if (w != nullptr) w->ModifyRailType(_cur_railtype);
1982}
1983
1989{
1991
1992 if (new_variant != _cur_signal_variant) {
1994 if (w != nullptr) {
1995 w->SetDirty();
1997 }
1998 _cur_signal_variant = new_variant;
1999 }
2000}
2001
2002static IntervalTimer<TimerGameCalendar> _check_reset_signal({TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [](auto)
2003{
2005
2007});
2008
2021
2028DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
2029{
2030 RailTypes used_railtypes;
2031 RailTypes avail_railtypes;
2032
2034
2035 /* Find the used railtypes. */
2036 if (for_replacement) {
2037 avail_railtypes = GetCompanyRailTypes(c->index, false);
2038 used_railtypes = GetRailTypes(false);
2039 } else {
2040 avail_railtypes = c->avail_railtypes;
2041 used_railtypes = GetRailTypes(true);
2042 }
2043
2044 DropDownList list;
2045
2046 if (all_option) {
2047 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_RAILTYPE, INVALID_RAILTYPE));
2048 }
2049
2050 Dimension d = { 0, 0 };
2051 /* Get largest icon size, to ensure text is aligned on each menu item. */
2052 if (!for_replacement) {
2053 for (const auto &rt : _sorted_railtypes) {
2054 if (!HasBit(used_railtypes, rt)) continue;
2055 const RailTypeInfo *rti = GetRailTypeInfo(rt);
2057 }
2058 }
2059
2060 /* Shared list so that each item can take ownership. */
2061 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_RAILTYPES);
2062
2063 for (const auto &rt : _sorted_railtypes) {
2064 /* If it's not used ever, don't show it to the user. */
2065 if (!HasBit(used_railtypes, rt)) continue;
2066
2067 const RailTypeInfo *rti = GetRailTypeInfo(rt);
2068
2069 if (for_replacement) {
2070 list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !HasBit(avail_railtypes, rt)));
2071 } else {
2072 std::string str = rti->max_speed > 0
2073 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed)
2074 : GetString(rti->strings.menu_text);
2075 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_RAILTYPES, rti->introduction_date, d, rti->gui_sprites.build_x_rail, PAL_NONE, std::move(str), rt, !HasBit(avail_railtypes, rt)));
2076 }
2077 }
2078
2079 if (list.empty()) {
2080 /* Empty dropdowns are not allowed */
2081 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_RAILTYPE, true));
2082 }
2083
2084 return list;
2085}
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
Prepare the data for the build a bridge window.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Helper for PickerCallbacks when the class system is based on NewGRFClass.
Definition picker_gui.h:104
Base class for windows opened from a toolbar.
Definition window_gui.h:982
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3529
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static const int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:173
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:194
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:171
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static const int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:174
void OnInit() override
Notification that the nested widget tree gets initialized.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static const int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:172
This struct contains all the info that is needed to draw and construct tracks.
Definition rail.h:118
uint16_t max_speed
Maximum speed for vehicles travelling on this rail type.
Definition rail.h:222
SpriteID build_tunnel
button for building a tunnel
Definition rail.h:150
CursorID rail_swne
Cursor for building rail in X direction.
Definition rail.h:157
SpriteID convert_rail
button for converting rail
Definition rail.h:151
CursorID convert
Cursor for converting track.
Definition rail.h:163
CursorID depot
Cursor for building a depot.
Definition rail.h:161
TimerGameCalendar::Date introduction_date
Introduction date.
Definition rail.h:246
CursorID rail_nwse
Cursor for building rail in Y direction.
Definition rail.h:159
SpriteID build_x_rail
button for building single rail in X direction
Definition rail.h:145
struct RailTypeInfo::@24 strings
Strings associated with the rail type.
CursorID rail_ew
Cursor for building rail in E-W direction.
Definition rail.h:158
SpriteID auto_rail
button for the autorail construction
Definition rail.h:148
CursorID autorail
Cursor for autorail tool.
Definition rail.h:160
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition rail.h:169
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition rail.h:168
SpriteID signals[SIGTYPE_END][2][2]
signal GUI sprites (type, variant, state)
Definition rail.h:152
SpriteID build_ew_rail
button for building single rail in E-W direction
Definition rail.h:146
SpriteID build_y_rail
button for building single rail in Y direction
Definition rail.h:147
StringID replace_text
Text used in the autoreplace GUI.
Definition rail.h:171
SpriteID build_depot
button for building depots
Definition rail.h:149
SpriteID build_ns_rail
button for building single rail in N-S direction
Definition rail.h:144
CursorID rail_ns
Cursor for building rail in N-S direction.
Definition rail.h:156
struct RailTypeInfo::@22 gui_sprites
struct containing the sprites for the rail GUI.
SpriteID tunnel
tunnel sprites base
Definition rail.h:136
bool IsActive() const override
Should picker class/type selection be enabled?
Definition rail_gui.cpp:975
bool HasClassChoice() const override
Are there multiple classes to chose from?
Definition rail_gui.cpp:986
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
Definition rail_gui.cpp:972
void SetSelectedType(int id) const override
Set the selected type.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
StringID GetClassName(int id) const override
Get the name of a class.
Definition rail_gui.cpp:994
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
Definition rail_gui.cpp:973
int GetSelectedClass() const override
Get the index of the selected class.
Definition rail_gui.cpp:991
void SetSelectedClass(int id) const override
Set the selected class.
Definition rail_gui.cpp:992
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
int GetSelectedType() const override
Get the selected type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
static Year year
Current year, starting at 0.
int GetSelectedType() const override
Get the selected type.
void SetSelectedClass(int id) const override
Set the selected class.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
int GetSelectedClass() const override
Get the index of the selected class.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
bool IsActive() const override
Should picker class/type selection be enabled?
void SetSelectedType(int id) const override
Set the selected type.
StringID GetClassName(int id) const override
Get the name of a class.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
bool HasClassChoice() const override
Are there multiple classes to chose from?
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ Auto
don't allow building on structures
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Axis
Allow incrementing of DiagDirDiff variables.
@ AXIS_X
The X axis.
@ AXIS_Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_NW
Northwest.
@ DIAGDIR_SE
Southeast.
@ DIAGDIR_SW
Southwest.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Base class for engines.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:923
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
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:989
uint8_t GetDigitWidth(FontSize size)
Return the maximum width of single digit.
Definition gfx.cpp:1241
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:1519
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
@ WKC_GLOBAL_HOTKEY
Fake keycode bit to indicate global hotkeys.
Definition gfx_type.h:33
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:943
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1500
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
GUI functions that shouldn't be here.
Hotkey related functions.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:63
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:569
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:403
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr void Swap(T &a, T &b)
Type safe swap operation.
void GuiShowTooltips(Window *parent, EncodedString &&text, TooltipCloseCondition close_tooltip)
Shows a tooltip.
Definition misc_gui.cpp:690
GrfSpecFeature
Definition newgrf.h:68
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
Functions related to NewGRF badges.
@ Avail
Availability of station in construction window.
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
Draw representation of a station tile for GUI purposes.
Header file for NewGRF stations.
StationClassID
@ STAT_CLASS_DFLT
Default station class.
@ STAT_CLASS_WAYP
Waypoint class.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Functions/types etc.
RailTypes GetCompanyRailTypes(CompanyID company, bool introduces)
Get the rail types the given company can build.
Definition rail.cpp:251
RailTypes GetRailTypes(bool introduces)
Get list of rail types, regardless of company availability.
Definition rail.cpp:282
bool ValParamRailType(const RailType rail)
Validate functions for rail building.
Definition rail.cpp:206
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Definition rail.h:300
Command definitions for rail.
static WindowDesc _signal_builder_desc(WDP_AUTO, nullptr, 0, 0, WC_BUILD_SIGNAL, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_signal_builder_widgets)
Signal selection window description.
Window * ShowBuildRailToolbar(RailType railtype)
Open the build rail toolbar window for a specific rail type.
Definition rail_gui.cpp:916
static constexpr NWidgetPart _nested_signal_builder_widgets[]
Nested widget definition of the build signal window.
static bool RailToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition rail_gui.cpp:332
void ResetSignalVariant(int32_t)
Updates the current signal variant used in the signal GUI to the one adequate to current year.
static void PlaceRail_Waypoint(TileIndex tile)
Place a rail waypoint.
Definition rail_gui.cpp:166
static void SetDefaultRailGui()
Set the initial (default) railtype to use.
static RailType _cur_railtype
Rail type of the current build-rail toolbar.
Definition rail_gui.cpp:54
static constexpr NWidgetPart _nested_build_waypoint_widgets[]
Nested widget definition for the build NewGRF rail waypoint window.
static constexpr NWidgetPart _nested_build_depot_widgets[]
Nested widget definition of the build rail depot window.
static void HandleAutoSignalPlacement()
Build new signals or remove signals or (if only one tile marked) edit a signal.
Definition rail_gui.cpp:411
static SignalVariant _cur_signal_variant
set the signal variant (for signal GUI)
Definition rail_gui.cpp:58
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:118
static void PlaceRail_Bridge(TileIndex tile, Window *w)
Start placing a rail bridge.
Definition rail_gui.cpp:292
static void PlaceRail_Station(TileIndex tile)
Place a rail station.
Definition rail_gui.cpp:198
static StationPickerSelection _station_gui
Settings of the station picker.
Definition rail_gui.cpp:72
static SignalType _cur_signal_type
set the signal type (for signal GUI)
Definition rail_gui.cpp:59
static void ToggleRailButton_Remove(Window *w)
Toggles state of the Remove button of Build rail toolbar.
Definition rail_gui.cpp:318
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
static WindowDesc _station_builder_desc(WDP_AUTO, "build_station_rail", 0, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_station_builder_widgets, &BuildRailStationWindow::hotkeys)
High level window description of the station-build window (default & newGRF)
static void BuildRailClick_Remove(Window *w)
The "remove"-button click proc of the build-rail toolbar.
Definition rail_gui.cpp:353
static bool IsStationAvailable(const StationSpec *statspec)
Check whether a station type can be build.
Definition rail_gui.cpp:85
static Window * ShowStationBuilder(Window *parent)
Open station build window.
static bool StationUsesDefaultType(const BaseStation *bst)
Test if a station/waypoint uses the default graphics.
Definition rail_gui.cpp:958
static const Track _place_depot_extra_track[12]
Additional pieces of track to add at the entrance of a depot.
Definition rail_gui.cpp:128
static DiagDirection _build_depot_direction
Currently selected depot direction.
Definition rail_gui.cpp:56
void InitializeRailGui()
Initialize rail building GUI settings.
static void ShowSignalBuilder(Window *parent)
Open the signal selection window.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
Definition rail_gui.cpp:55
void ReinitGuiAfterToggleElrail(bool disable)
Re-initialize rail-build toolbar after toggling support for electric trains.
static const DiagDirection _place_depot_extra_dir[12]
Direction to check for existing track pieces.
Definition rail_gui.cpp:135
void InitializeRailGUI()
Resets the rail GUI - sets default railtype to build and resets the signal GUI.
static bool _convert_signal_button
convert signal button in the signal GUI pressed
Definition rail_gui.cpp:57
static void GenericPlaceSignals(TileIndex tile)
Build a new signal or edit/remove a present signal, use CmdBuildSingleSignal() or CmdRemoveSingleSign...
Definition rail_gui.cpp:234
static WaypointPickerSelection _waypoint_gui
Settings of the waypoint picker.
Definition rail_gui.cpp:65
Functions/types etc.
@ SIGNAL_GUI_ALL
Show all signals, including block and presignals.
Definition rail_gui.h:25
@ SIGNAL_GUI_PATH
Show path signals only.
Definition rail_gui.h:24
@ SIGNAL_CYCLE_ALL
Cycle through all signals visible to the player.
Definition rail_gui.h:31
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
Definition rail_map.h:115
static debug_inline RailTileType GetRailTileType(Tile t)
Returns the RailTileType (normal with or without signals, waypoint or depot).
Definition rail_map.h:36
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
Definition rail_map.h:136
@ RAIL_TILE_DEPOT
Depot (one entrance)
Definition rail_map.h:26
@ RAIL_TILE_SIGNALS
Normal rail tile with signals.
Definition rail_map.h:25
static debug_inline bool IsRailDepotTile(Tile t)
Is this tile rail tile and a rail depot?
Definition rail_map.h:105
bool HasSignalOnTrack(Tile tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
Definition rail_map.h:413
static debug_inline bool IsPlainRailTile(Tile t)
Checks whether the tile is a rail tile or rail tile with signals.
Definition rail_map.h:60
RailTypes
Allow incrementing of Track variables.
Definition rail_type.h:44
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:27
@ RAILTYPE_BEGIN
Used for iterations.
Definition rail_type.h:28
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:34
@ RAILTYPE_ELECTRIC
Electric rails.
Definition rail_type.h:30
@ RAILTYPE_RAIL
Standard non-electric rails.
Definition rail_type.h:29
Types related to the rail widgets.
@ WID_RAT_BUILD_SIGNALS
Build signals.
Definition rail_widget.h:26
@ WID_RAT_BUILD_NS
Build rail along the game view Y axis.
Definition rail_widget.h:17
@ WID_RAT_CONVERT_RAIL
Convert other rail to this type.
Definition rail_widget.h:30
@ WID_RAT_BUILD_Y
Build rail along the game grid Y axis.
Definition rail_widget.h:20
@ WID_RAT_BUILD_EW
Build rail along the game view X axis.
Definition rail_widget.h:19
@ WID_RAT_BUILD_BRIDGE
Build a bridge.
Definition rail_widget.h:27
@ WID_RAT_REMOVE
Bulldozer to remove rail.
Definition rail_widget.h:29
@ WID_RAT_CAPTION
Caption of the window.
Definition rail_widget.h:16
@ WID_RAT_BUILD_WAYPOINT
Build a waypoint.
Definition rail_widget.h:24
@ WID_RAT_BUILD_DEPOT
Build a depot.
Definition rail_widget.h:23
@ WID_RAT_DEMOLISH
Destroy something with dynamite!
Definition rail_widget.h:22
@ WID_RAT_BUILD_STATION
Build a station.
Definition rail_widget.h:25
@ WID_RAT_BUILD_X
Build rail along the game grid X axis.
Definition rail_widget.h:18
@ WID_RAT_BUILD_TUNNEL
Build a tunnel.
Definition rail_widget.h:28
@ WID_RAT_AUTORAIL
Autorail tool.
Definition rail_widget.h:21
@ WID_BRAS_HIGHLIGHT_OFF
Button for turning coverage highlighting off.
Definition rail_widget.h:59
@ WID_BRAS_PLATFORM_NUM_4
Button to select stations with 4 platforms.
Definition rail_widget.h:44
@ WID_BRAS_PLATFORM_NUM_7
Button to select stations with 7 platforms.
Definition rail_widget.h:47
@ WID_BRAS_PLATFORM_DIR_X
Button to select '/' view.
Definition rail_widget.h:38
@ WID_BRAS_PLATFORM_LEN_BEGIN
Helper for determining the chosen platform length.
Definition rail_widget.h:64
@ WID_BRAS_PLATFORM_LEN_3
Button to select 3 tiles length station platforms.
Definition rail_widget.h:51
@ WID_BRAS_PLATFORM_DIR_Y
Button to select '\' view.
Definition rail_widget.h:39
@ WID_BRAS_PLATFORM_LEN_6
Button to select 6 tiles length station platforms.
Definition rail_widget.h:54
@ WID_BRAS_PLATFORM_NUM_1
Button to select stations with a single platform.
Definition rail_widget.h:41
@ WID_BRAS_PLATFORM_NUM_BEGIN
Helper for determining the chosen platform width.
Definition rail_widget.h:63
@ WID_BRAS_PLATFORM_NUM_3
Button to select stations with 3 platforms.
Definition rail_widget.h:43
@ WID_BRAS_PLATFORM_LEN_5
Button to select 5 tiles length station platforms.
Definition rail_widget.h:53
@ WID_BRAS_PLATFORM_NUM_5
Button to select stations with 5 platforms.
Definition rail_widget.h:45
@ WID_BRAS_COVERAGE_TEXTS
Empty space for the coverage texts.
Definition rail_widget.h:61
@ WID_BRAS_PLATFORM_LEN_1
Button to select single tile length station platforms.
Definition rail_widget.h:49
@ WID_BRAS_HIGHLIGHT_ON
Button for turning coverage highlighting on.
Definition rail_widget.h:60
@ WID_BRAS_PLATFORM_DRAG_N_DROP
Button to enable drag and drop type station placement.
Definition rail_widget.h:57
@ WID_BRAS_PLATFORM_LEN_7
Button to select 7 tiles length station platforms.
Definition rail_widget.h:55
@ WID_BRAS_PLATFORM_NUM_6
Button to select stations with 6 platforms.
Definition rail_widget.h:46
@ WID_BRAS_PLATFORM_NUM_2
Button to select stations with 2 platforms.
Definition rail_widget.h:42
@ WID_BRAS_PLATFORM_LEN_4
Button to select 4 tiles length station platforms.
Definition rail_widget.h:52
@ WID_BRAS_PLATFORM_LEN_2
Button to select 2 tiles length station platforms.
Definition rail_widget.h:50
@ WID_BRAD_DEPOT_SE
Build a depot with the entrance in the south east.
Definition rail_widget.h:95
@ WID_BRAD_DEPOT_NE
Build a depot with the entrance in the north east.
Definition rail_widget.h:94
@ WID_BRAD_DEPOT_SW
Build a depot with the entrance in the south west.
Definition rail_widget.h:96
@ WID_BRAD_DEPOT_NW
Build a depot with the entrance in the north west.
Definition rail_widget.h:97
@ WID_BS_DRAG_SIGNALS_DENSITY_DECREASE
Decrease the signal density.
Definition rail_widget.h:85
@ WID_BS_TOGGLE_SIZE
Toggle showing advanced signal types.
Definition rail_widget.h:70
@ WID_BS_ELECTRIC_PBS
Build an electric path signal.
Definition rail_widget.h:81
@ WID_BS_SEMAPHORE_NORM
Build a semaphore normal block signal.
Definition rail_widget.h:71
@ WID_BS_ELECTRIC_NORM
Build an electric normal block signal.
Definition rail_widget.h:77
@ WID_BS_ELECTRIC_EXIT
Build an electric exit block signal.
Definition rail_widget.h:79
@ WID_BS_ELECTRIC_ENTRY
Build an electric entry block signal.
Definition rail_widget.h:78
@ WID_BS_SEMAPHORE_ENTRY
Build a semaphore entry block signal.
Definition rail_widget.h:72
@ WID_BS_BLOCK_SEL
Container for the block signal group, which can be hidden.
Definition rail_widget.h:87
@ WID_BS_CAPTION
Caption for the Signal Selection window.
Definition rail_widget.h:69
@ WID_BS_SEMAPHORE_COMBO
Build a semaphore combo block signal.
Definition rail_widget.h:74
@ WID_BS_BLOCK_SPACER_SEL
Container for the spacer between block and path signal groups, which can be hidden.
Definition rail_widget.h:88
@ WID_BS_SEMAPHORE_PBS
Build a semaphore path signal.
Definition rail_widget.h:75
@ WID_BS_DRAG_SIGNALS_DENSITY_LABEL
The current signal density.
Definition rail_widget.h:84
@ WID_BS_SEMAPHORE_EXIT
Build a semaphore exit block signal.
Definition rail_widget.h:73
@ WID_BS_SEMAPHORE_PBS_OWAY
Build a semaphore one way path signal.
Definition rail_widget.h:76
@ WID_BS_DRAG_SIGNALS_DENSITY_INCREASE
Increase the signal density.
Definition rail_widget.h:86
@ WID_BS_CONVERT
Convert the signal.
Definition rail_widget.h:83
@ WID_BS_ELECTRIC_COMBO
Build an electric combo block signal.
Definition rail_widget.h:80
@ WID_BS_ELECTRIC_PBS_OWAY
Build an electric one way path signal.
Definition rail_widget.h:82
bool IsLevelCrossingTile(Tile t)
Return whether a tile is a level crossing tile.
Definition road_map.h:95
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:30
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:58
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:57
SignalType
Type of signal, i.e.
Definition signal_type.h:23
@ SIGTYPE_PBS
normal pbs signal
Definition signal_type.h:28
@ SIGTYPE_BLOCK
block signal
Definition signal_type.h:24
SignalVariant
Variant of the signal, i.e.
Definition signal_type.h:16
@ SIG_SEMAPHORE
Old-fashioned semaphore signal.
Definition signal_type.h:18
@ SIG_ELECTRIC
Light signal.
Definition signal_type.h:17
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
@ SND_20_CONSTRUCTION_RAIL
30 == 0x1E Construction: rail infrastructure
Definition sound_type.h:77
Functions to cache sprites in memory.
static const CursorID ANIMCURSOR_BUILDSIGNALS
1292 - 1293 - build signal
Definition sprites.h:1516
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1512
Base classes/functions for stations.
Command definitions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
void ShowSelectRailWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the rail waypoint selection window when needed.
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Contains enums and function declarations connected with stations GUI.
@ SCT_ALL
Draw all cargoes.
Definition station_gui.h:24
Maps accessors for stations.
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
uint GetCustomStationSpecIndex(Tile t)
Get the custom station spec for this tile.
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
static constexpr uint CA_TRAIN
Catchment for train stations with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition of base types and functions in a cross-platform compatible way.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Base class for all station-ish types.
TileArea train_station
Tile area the train 'station' part covers.
virtual bool TileBelongsToRailStation(TileIndex tile) const =0
Check whether a specific tile belongs to this station.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void OnPaint() override
The window must be repainted.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static EventState BuildRailStationGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildRailStationWindow.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
uint coverage_height
Height of the coverage texts.
void CheckSelectedSize(const StationSpec *statspec)
Verify whether the currently selected station size is allowed after selecting a new station class/typ...
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Rail toolbar management class.
Definition rail_gui.cpp:436
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:808
RailType railtype
Rail type to build.
Definition rail_gui.cpp:437
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition rail_gui.cpp:821
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition rail_gui.cpp:466
void ModifyRailType(RailType railtype)
Switch to another rail type.
Definition rail_gui.cpp:516
int last_user_action
Last started user action.
Definition rail_gui.cpp:438
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition rail_gui.cpp:498
bool OnTooltip(Point pt, WidgetID widget, TooltipCloseCondition close_cond) override
Event to display a custom tooltip.
Definition rail_gui.cpp:487
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition rail_gui.cpp:565
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition rail_gui.cpp:814
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition rail_gui.cpp:552
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition rail_gui.cpp:791
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:721
static EventState RailToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildRailToolbarWindow.
Definition rail_gui.cpp:831
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:662
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:729
static const std::initializer_list< WidgetID > can_build_widgets
List of widgets to be disabled if infrastructure limit prevents building.
Definition rail_gui.cpp:460
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition rail_gui.cpp:656
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition rail_gui.cpp:450
Dimension sig_sprite_size
Maximum size of signal GUI sprites.
void DrawSignalSprite(const Rect &r, SpriteID image) const
Draw dynamic a signal-sprite in a button in the signal GUI.
void SetSignalUIMode()
Show or hide buttons for non-path signals in the signal GUI.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
int sig_sprite_bottom_offset
Maximum extent of signal GUI sprite from reference point towards bottom.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
RailTypes avail_railtypes
Rail types available to this company.
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Definition gfx_type.h:156
const struct GRFFile * grffile
grf file that introduced this entity
bool persistent_buildingtools
keep the building tools active after usage
SignalCycleSettings cycle_signal_types
Which signal types to cycle with the build signal tool.
uint8_t station_platlength
the platform length, in tiles, for rail stations
bool auto_remove_signals
automatically remove signals when in the way during rail construction
bool station_dragdrop
whether drag and drop is enabled for stations
bool station_show_coverage
whether to highlight coverage area
uint8_t default_rail_type
the default rail type for the rail GUI
uint8_t drag_signals_density
many signals density
uint8_t station_numtracks
the number of platforms to default on for rail stations
TimerGameCalendar::Year semaphore_build_before
build semaphore signals automatically before this year
SignalGUISettings signal_gui_mode
select which signal types are shown in the signal GUI
bool drag_signals_fixed_distance
keep fixed distance between signals when dragging
SignalType default_signal_type
The default signal type, which is set automatically by the last signal used. Not available in Setting...
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
StationSettings station
settings related to station management
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
static IterateWrapper Iterate()
Returns an iterable ensemble of all Tiles.
Definition map_func.h:362
Partial widget specification to allow NWidgets to be written nested.
Represents the covered area of e.g.
Coordinates of a point in 2D.
static Titem * Get(auto index)
Returns Titem with given index.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
StationClassID sel_class
Selected station class.
Definition rail_gui.cpp:68
uint16_t sel_type
Selected station type within the class.
Definition rail_gui.cpp:69
Axis axis
Selected orientation of the station.
Definition rail_gui.cpp:70
uint8_t station_spread
amount a station may spread
bool modified_catchment
different-size catchment areas
Station specification.
uint8_t disallowed_lengths
Bitmask of platform lengths available for the station.
VariableGRFFileProps grf_prop
Properties related the the grf file.
uint8_t disallowed_platforms
Bitmask of number of platforms available for the station.
StationCallbackMasks callback_mask
Bitmask of station callbacks that have to be called.
Station data structure.
Point selstart
The location where the dragging started.
HighLightStyle drawstyle
Lower bits 0-3 are reserved for detailed highlight information.
Point pos
Location, in tile "units", of the northern tile of the selected area.
Point selend
The location where the drag currently ends.
StationClassID sel_class
Selected station class.
Definition rail_gui.cpp:62
uint16_t sel_type
Selected station type within the class.
Definition rail_gui.cpp:63
Representation of a waypoint.
High level window description.
Definition window_gui.h:168
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:955
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1050
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1736
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3164
Window * parent
Parent window.
Definition window_gui.h:329
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:554
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:502
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1726
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:528
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:558
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:833
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1749
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:568
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:451
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
Definition tile_type.h:57
@ MP_RAILWAY
A railway.
Definition tile_type.h:49
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
@ HT_LINE
used for autorail highlighting (longer stretches), lower bits: direction
@ HT_DIR_HL
horizontal lower
@ HT_DIR_X
X direction.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_DIR_MASK
masks the drag-direction
@ HT_RAIL
autorail (one piece), lower bits: direction
@ HT_DRAG_MASK
Mask for the tile drag-type modes.
@ HT_DIR_VL
vertical left
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
@ HT_DIR_Y
Y direction.
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
bool IsValidTrack(Track track)
Checks if a Track is valid.
Definition track_func.h:28
Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition track_func.h:177
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition track_func.h:573
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition track_func.h:363
TrackBits
Allow incrementing of Track variables.
Definition track_type.h:35
@ TRACK_BIT_UPPER
Upper track.
Definition track_type.h:39
@ TRACK_BIT_LEFT
Left track.
Definition track_type.h:41
@ TRACK_BIT_HORZ
Upper and lower track.
Definition track_type.h:44
@ TRACK_BIT_LOWER
Lower track.
Definition track_type.h:40
@ TRACK_BIT_RIGHT
Right track.
Definition track_type.h:42
@ TRACK_BIT_VERT
Left and right track.
Definition track_type.h:45
Track
These are used to specify a single track.
Definition track_type.h:19
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition track_type.h:22
@ TRACK_LOWER
Track in the lower corner of the tile (south)
Definition track_type.h:24
@ TRACK_LEFT
Track in the left corner of the tile (west)
Definition track_type.h:25
@ TRACK_RIGHT
Track in the right corner of the tile (east)
Definition track_type.h:26
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition track_type.h:21
@ TRACK_UPPER
Track in the upper corner of the tile (north)
Definition track_type.h:23
@ TRANSPORT_RAIL
Transport by train.
Header file for things common for tunnels and bridges.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1913
Functions related to vehicles.
@ VEH_TRAIN
Train vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetViewportCatchmentWaypoint(const Waypoint *wp, bool sel)
Select or deselect waypoint for coverage area highlight.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
@ VPM_FIX_Y
drag only in Y axis
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ VPM_FIX_VERTICAL
drag only in vertical direction
@ VPM_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_HORIZONTAL
drag only in horizontal direction
@ VPM_FIX_X
drag only in X axis
@ VPM_SIGNALDIRS
similar to VMP_RAILDIRS, but with different cursor
@ VPM_X_OR_Y
drag in X or Y direction
@ VPM_RAILDIRS
all rail directions
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_CONVERT_RAIL
Rail conversion.
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_BUILD_SIGNALS
Signal placement.
@ DDSP_REMOVE_STATION
Station removal.
@ DDSP_BUILD_STATION
Station placement.
@ DDSP_BUILD_BRIDGE
Bridge placement.
@ DDSP_PLACE_RAIL
Rail placement.
void DrawWaypointSprite(int x, int y, StationClassID station_class, uint16_t station_type, RailType railtype)
Draw a waypoint.
Definition waypoint.cpp:28
Base of waypoints.
@ WPF_ROAD
This is a road waypoint.
Axis GetAxisForNewRailWaypoint(TileIndex tile)
Get the axis for a new rail waypoint.
Command definitions related to waypoints.
Functions related to waypoints.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:48
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:47
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:56
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:54
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:55
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:66
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:70
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:21
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:22
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1143
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1155
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1101
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3106
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:145
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:20
@ WN_GAME_OPTIONS_GAME_SETTINGS
Game settings.
Definition window_type.h:29
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:75
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_BUILD_SIGNAL
Build signal toolbar; Window numbers:
@ WC_BUILD_DEPOT
Build depot; Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_BUILD_WAYPOINT
Build waypoint; Window numbers:
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107