OpenTTD Source 20250205-master-gfd85ab1e2c
road_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "gui.h"
12#include "window_gui.h"
13#include "station_gui.h"
14#include "terraform_gui.h"
15#include "viewport_func.h"
16#include "command_func.h"
17#include "road_cmd.h"
18#include "station_func.h"
19#include "waypoint_func.h"
20#include "window_func.h"
21#include "vehicle_func.h"
22#include "sound_func.h"
23#include "company_func.h"
24#include "tunnelbridge.h"
25#include "tunnelbridge_map.h"
26#include "tilehighlight_func.h"
27#include "company_base.h"
28#include "hotkeys.h"
29#include "road_gui.h"
30#include "zoom_func.h"
31#include "dropdown_type.h"
32#include "dropdown_func.h"
33#include "engine_base.h"
34#include "station_base.h"
35#include "waypoint_base.h"
36#include "strings_func.h"
38#include "station_cmd.h"
39#include "waypoint_cmd.h"
40#include "road_cmd.h"
41#include "tunnelbridge_cmd.h"
42#include "newgrf_roadstop.h"
43#include "picker_gui.h"
44#include "timer/timer.h"
46
47#include "widgets/road_widget.h"
48
49#include "table/strings.h"
50
51#include "safeguards.h"
52
53static void ShowRVStationPicker(Window *parent, RoadStopType rs);
54static void ShowRoadDepotPicker(Window *parent);
55static void ShowBuildRoadWaypointPicker(Window *parent);
56
57static bool _remove_button_clicked;
58static bool _one_way_button_clicked;
59
60static Axis _place_road_dir;
61static bool _place_road_start_half_x;
62static bool _place_road_start_half_y;
63static bool _place_road_end_half;
64
65static RoadType _cur_roadtype;
66
67static DiagDirection _road_depot_orientation;
68
74
80static RoadStopPickerSelection _roadstop_gui;
81
82static bool IsRoadStopEverAvailable(const RoadStopSpec *spec, StationType type)
83{
84 if (spec == nullptr) return true;
85
86 if (spec->flags.Test(RoadStopSpecFlag::RoadOnly) && !RoadTypeIsRoad(_cur_roadtype)) return false;
87 if (spec->flags.Test(RoadStopSpecFlag::TramOnly) && !RoadTypeIsTram(_cur_roadtype)) return false;
88
89 switch (spec->stop_type) {
90 case ROADSTOPTYPE_ALL: return true;
91 case ROADSTOPTYPE_PASSENGER: return type == StationType::Bus;
92 case ROADSTOPTYPE_FREIGHT: return type == StationType::Truck;
93 default: NOT_REACHED();
94 }
95}
96
101static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
102{
103 if (spec == nullptr) return true;
104 if (!IsRoadStopEverAvailable(spec, type)) return false;
105
106 if (!spec->callback_mask.Test(RoadStopCallbackMask::Avail)) return true;
107
108 uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, nullptr, INVALID_TILE, _cur_roadtype, type, 0);
109 if (cb_res == CALLBACK_FAILED) return true;
110
112}
113
114void CcPlaySound_CONSTRUCTION_OTHER(Commands, const CommandCost &result, TileIndex tile)
115{
116 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
117}
118
123static void PlaceRoad_Bridge(TileIndex tile, Window *w)
124{
125 if (IsBridgeTile(tile)) {
126 TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
127 Point pt = {0, 0};
128 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
129 } else {
131 }
132}
133
140void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
141{
142 if (result.Succeeded()) {
143 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
145
146 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
147 ConnectRoadToStructure(start_tile, start_direction);
148
149 TileIndex end_tile = GetOtherTunnelBridgeEnd(start_tile);
150 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
151 ConnectRoadToStructure(end_tile, end_direction);
152 } else {
154 }
155}
156
163{
164 tile += TileOffsByDiagDir(direction);
165 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
166 if (IsNormalRoadTile(tile)) {
167 if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) {
168 Command<CMD_BUILD_ROAD>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, INVALID_TOWN);
169 }
170 }
171}
172
173void CcRoadDepot(Commands, const CommandCost &result, TileIndex tile, RoadType, DiagDirection dir)
174{
175 if (result.Failed()) return;
176
179 ConnectRoadToStructure(tile, dir);
180}
181
194void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through,
195 DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
196{
197 if (result.Failed()) return;
198
201
202 bool connect_to_road = true;
203 if ((uint)spec_class < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) {
204 const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index);
205 if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false;
206 }
207
208 if (connect_to_road) {
209 TileArea roadstop_area(tile, width, length);
210 for (TileIndex cur_tile : roadstop_area) {
211 ConnectRoadToStructure(cur_tile, dir);
212 /* For a drive-through road stop build connecting road for other entrance. */
213 if (is_drive_through) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
214 }
215 }
216}
217
228static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
229{
230 TileArea ta(start_tile, end_tile);
231 DiagDirection ddir = _roadstop_gui.orientation;
232 bool drive_through = ddir >= DIAGDIR_END;
233 if (drive_through) ddir = static_cast<DiagDirection>(ddir - DIAGDIR_END); // Adjust picker result to actual direction.
234 RoadStopClassID spec_class = _roadstop_gui.sel_class;
235 uint16_t spec_index = _roadstop_gui.sel_type;
236
237 auto proc = [=](bool test, StationID to_join) -> bool {
238 if (test) {
239 return Command<CMD_BUILD_ROAD_STOP>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_ROAD_STOP>()), ta.tile, ta.w, ta.h, stop_type, drive_through,
240 ddir, rt, spec_class, spec_index, INVALID_STATION, adjacent).Succeeded();
241 } else {
242 return Command<CMD_BUILD_ROAD_STOP>::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through,
243 ddir, rt, spec_class, spec_index, to_join, adjacent);
244 }
245 };
246
248}
249
255{
256 if (_remove_button_clicked) {
258 return;
259 }
260
261 Axis axis = GetAxisForNewRoadWaypoint(tile);
262 if (IsValidAxis(axis)) {
263 /* Valid tile for waypoints */
265 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
266 } else {
267 /* Tile where we can't build road waypoints. This is always going to fail,
268 * but provides the user with a proper error message. */
269 Command<CMD_BUILD_ROAD_WAYPOINT>::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, AXIS_X, 1, 1, ROADSTOP_CLASS_WAYP, 0, INVALID_STATION, false);
270 }
271}
272
278{
279 if (_remove_button_clicked) {
281 } else {
282 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
284 } else {
286 }
287 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
288 }
289}
290
296{
297 if (_remove_button_clicked) {
299 } else {
300 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
302 } else {
304 }
305 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
306 }
307}
308
309typedef void OnButtonClick(Window *w);
310
316{
319 _remove_button_clicked = w->IsWidgetLowered(WID_ROT_REMOVE);
320 SetSelectionRed(_remove_button_clicked);
321}
322
329{
330 if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
331
332 /* allow ctrl to switch remove mode only for these widgets */
333 for (WidgetID i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) {
334 if (w->IsWidgetLowered(i)) {
336 return true;
337 }
338 }
339
340 return false;
341}
342
347
349 {
350 this->roadtype = _cur_roadtype;
351 this->CreateNestedTree();
352 this->FinishInitNested(window_number);
354
355 if (RoadTypeIsRoad(this->roadtype)) {
357 }
358
359 this->OnInvalidateData();
360 this->last_started_action = INVALID_WID_ROT;
361
363 }
364
365 void Close([[maybe_unused]] int data = 0) override
366 {
367 if (_game_mode == GM_NORMAL && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true);
369 this->Window::Close();
370 }
371
377 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
378 {
379 if (!gui_scope) return;
380
381 if (!ValParamRoadType(this->roadtype)) {
382 /* Close toolbar if road type is not available. */
383 this->Close();
384 return;
385 }
386
387 RoadTramType rtt = GetRoadTramType(this->roadtype);
388
390 this->SetWidgetsDisabledState(!can_build,
395 if (!can_build) {
400 }
401
402 if (_game_mode != GM_EDITOR) {
403 if (!can_build) {
404 /* Show in the tooltip why this button is disabled. */
409 } else {
414 }
415 }
416 }
417
418 void OnInit() override
419 {
420 /* Configure the road toolbar for the roadtype. */
421 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
425 if (_game_mode != GM_EDITOR) {
427 }
430 }
431
437 {
438 this->roadtype = roadtype;
439 this->ReInit();
440 }
441
442 void SetStringParameters(WidgetID widget) const override
443 {
444 if (widget == WID_ROT_CAPTION) {
445 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
446 if (rti->max_speed > 0) {
450 } else {
452 }
453 }
454 }
455
462 {
463 /* The remove and the one way button state is driven
464 * by the other buttons so they don't act on themselves.
465 * Both are only valid if they are able to apply as options. */
466 switch (clicked_widget) {
467 case WID_ROT_REMOVE:
468 if (RoadTypeIsRoad(this->roadtype)) {
471 }
472
473 break;
474
475 case WID_ROT_ONE_WAY:
478 break;
479
483 if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
484 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
485 break;
486
487 case WID_ROT_ROAD_X:
488 case WID_ROT_ROAD_Y:
489 case WID_ROT_AUTOROAD:
490 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
491 if (RoadTypeIsRoad(this->roadtype)) {
492 this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget));
493 }
494 break;
495
496 default:
497 /* When any other buttons than road/station, raise and
498 * disable the removal button */
501
502 if (RoadTypeIsRoad(this->roadtype)) {
505 }
506
507 break;
508 }
509 }
510
511 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
512 {
513 _remove_button_clicked = false;
514 _one_way_button_clicked = false;
515 switch (widget) {
516 case WID_ROT_ROAD_X:
518 this->last_started_action = widget;
519 break;
520
521 case WID_ROT_ROAD_Y:
523 this->last_started_action = widget;
524 break;
525
526 case WID_ROT_AUTOROAD:
528 this->last_started_action = widget;
529 break;
530
531 case WID_ROT_DEMOLISH:
533 this->last_started_action = widget;
534 break;
535
536 case WID_ROT_DEPOT:
537 if (HandlePlacePushButton(this, WID_ROT_DEPOT, GetRoadTypeInfo(this->roadtype)->cursor.depot, HT_RECT)) {
538 ShowRoadDepotPicker(this);
539 this->last_started_action = widget;
540 }
541 break;
542
544 this->last_started_action = widget;
545 if (HandlePlacePushButton(this, WID_ROT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT)) {
546 ShowBuildRoadWaypointPicker(this);
547 }
548 break;
549
551 if (HandlePlacePushButton(this, WID_ROT_BUS_STATION, SPR_CURSOR_BUS_STATION, HT_RECT)) {
552 ShowRVStationPicker(this, RoadStopType::Bus);
553 this->last_started_action = widget;
554 }
555 break;
556
558 if (HandlePlacePushButton(this, WID_ROT_TRUCK_STATION, SPR_CURSOR_TRUCK_STATION, HT_RECT)) {
559 ShowRVStationPicker(this, RoadStopType::Truck);
560 this->last_started_action = widget;
561 }
562 break;
563
564 case WID_ROT_ONE_WAY:
565 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
566 this->SetDirty();
568 SetSelectionRed(false);
569 break;
570
572 HandlePlacePushButton(this, WID_ROT_BUILD_BRIDGE, SPR_CURSOR_BRIDGE, HT_RECT);
573 this->last_started_action = widget;
574 break;
575
578 this->last_started_action = widget;
579 break;
580
581 case WID_ROT_REMOVE:
582 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
583
587 break;
588
591 this->last_started_action = widget;
592 break;
593
594 default: NOT_REACHED();
595 }
598 }
599
601 {
602 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
603 return Window::OnHotkey(hotkey);
604 }
605
606 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
607 {
608 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
609 _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
610 switch (this->last_started_action) {
611 case WID_ROT_ROAD_X:
612 _place_road_dir = AXIS_X;
613 _place_road_start_half_x = _tile_fract_coords.x >= 8;
615 break;
616
617 case WID_ROT_ROAD_Y:
618 _place_road_dir = AXIS_Y;
619 _place_road_start_half_y = _tile_fract_coords.y >= 8;
621 break;
622
623 case WID_ROT_AUTOROAD:
624 _place_road_dir = INVALID_AXIS;
625 _place_road_start_half_x = _tile_fract_coords.x >= 8;
626 _place_road_start_half_y = _tile_fract_coords.y >= 8;
628 break;
629
630 case WID_ROT_DEMOLISH:
632 break;
633
634 case WID_ROT_DEPOT:
635 Command<CMD_BUILD_ROAD_DEPOT>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_depot, CcRoadDepot,
636 tile, _cur_roadtype, _road_depot_orientation);
637 break;
638
640 PlaceRoad_Waypoint(tile);
641 break;
642
645 break;
646
649 break;
650
652 PlaceRoad_Bridge(tile, this);
653 break;
654
657 tile, TRANSPORT_ROAD, _cur_roadtype);
658 break;
659
662 break;
663
664 default: NOT_REACHED();
665 }
666 }
667
688
690 {
691 /* Here we update the end tile flags
692 * of the road placement actions.
693 * At first we reset the end halfroad
694 * bits and if needed we set them again. */
695 switch (select_proc) {
697 _place_road_end_half = pt.x & 8;
698 break;
699
701 _place_road_end_half = pt.y & 8;
702 break;
703
705 /* For autoroad we need to update the
706 * direction of the road */
707 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
708 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
709 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
710 /* Set dir = X */
711 _place_road_dir = AXIS_X;
712 _place_road_end_half = pt.x & 8;
713 } else {
714 /* Set dir = Y */
715 _place_road_dir = AXIS_Y;
716 _place_road_end_half = pt.y & 8;
717 }
718
719 break;
720
721 default:
722 break;
723 }
724
725 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
726 }
727
728 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
729 {
730 if (pt.x != -1) {
731 switch (select_proc) {
732 default: NOT_REACHED();
735 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, _cur_roadtype);
736 break;
737
739 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
740 break;
741
744 case DDSP_PLACE_AUTOROAD: {
745 bool start_half = _place_road_dir == AXIS_Y ? _place_road_start_half_y : _place_road_start_half_x;
746
747 if (_remove_button_clicked) {
748 Command<CMD_REMOVE_LONG_ROAD>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_remove_road, CcPlaySound_CONSTRUCTION_OTHER,
749 end_tile, start_tile, _cur_roadtype, _place_road_dir, start_half, _place_road_end_half);
750 } else {
751 Command<CMD_BUILD_LONG_ROAD>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_build_road, CcPlaySound_CONSTRUCTION_OTHER,
752 end_tile, start_tile, _cur_roadtype, _place_road_dir, _one_way_button_clicked ? DRD_NORTHBOUND : DRD_NONE, start_half, _place_road_end_half, false);
753 }
754 break;
755 }
756
760 if (_remove_button_clicked) {
761 Command<CMD_REMOVE_FROM_ROAD_WAYPOINT>::Post(STR_ERROR_CAN_T_REMOVE_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile);
762 } else {
763 TileArea ta(start_tile, end_tile);
764 Axis axis = select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y;
765 bool adjacent = _ctrl_pressed;
766
767 auto proc = [=](bool test, StationID to_join) -> bool {
768 if (test) {
770 } else {
772 }
773 };
774
776 }
777 }
778 break;
779
782 if (this->IsWidgetLowered(WID_ROT_BUS_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Bus, _cur_roadtype)) {
783 if (_remove_button_clicked) {
784 TileArea ta(start_tile, end_tile);
786 Command<CMD_REMOVE_ROAD_STOP>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Bus, _ctrl_pressed);
787 } else {
789 PlaceRoadStop(start_tile, end_tile, RoadStopType::Bus, _ctrl_pressed, _cur_roadtype, str);
790 }
791 }
792 break;
793
796 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Truck, _cur_roadtype)) {
797 if (_remove_button_clicked) {
798 TileArea ta(start_tile, end_tile);
800 Command<CMD_REMOVE_ROAD_STOP>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Truck, _ctrl_pressed);
801 } else {
803 PlaceRoadStop(start_tile, end_tile, RoadStopType::Truck, _ctrl_pressed, _cur_roadtype, str);
804 }
805 }
806 break;
807
809 Command<CMD_CONVERT_ROAD>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_convert_road, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile, _cur_roadtype);
810 break;
811 }
812 }
813 }
814
820
822 {
823 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
824 return ES_NOT_HANDLED;
825 }
826
827 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
828 {
829 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_ROT_BUILD_WAYPOINT)) CheckRedrawRoadWaypointCoverage(this);
830 }
831
839 {
840 Window *w = nullptr;
841 switch (_game_mode) {
842 case GM_NORMAL:
844 break;
845
846 case GM_EDITOR:
847 if ((GetRoadTypes(true) & ((rtt == RTT_ROAD) ? ~_roadtypes_type : _roadtypes_type)) == ROADTYPES_NONE) return ES_NOT_HANDLED;
849 break;
850
851 default:
852 break;
853 }
854
855 if (w == nullptr) return ES_NOT_HANDLED;
856 return w->OnHotkey(hotkey);
857 }
858
859 static EventState RoadToolbarGlobalHotkeys(int hotkey)
860 {
861 extern RoadType _last_built_roadtype;
862 return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_roadtype, RTT_ROAD);
863 }
864
865 static EventState TramToolbarGlobalHotkeys(int hotkey)
866 {
867 extern RoadType _last_built_tramtype;
868 return RoadTramToolbarGlobalHotkeys(hotkey, _last_built_tramtype, RTT_TRAM);
869 }
870
871 static inline HotkeyList road_hotkeys{"roadtoolbar", {
872 Hotkey('1', "build_x", WID_ROT_ROAD_X),
873 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
874 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
875 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
876 Hotkey('5', "depot", WID_ROT_DEPOT),
877 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
878 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
879 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
880 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
881 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
882 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
883 Hotkey('R', "remove", WID_ROT_REMOVE),
884 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
885 }, RoadToolbarGlobalHotkeys};
886
887 static inline HotkeyList tram_hotkeys{"tramtoolbar", {
888 Hotkey('1', "build_x", WID_ROT_ROAD_X),
889 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
890 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
891 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
892 Hotkey('5', "depot", WID_ROT_DEPOT),
893 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
894 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
895 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
896 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
897 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
898 Hotkey('R', "remove", WID_ROT_REMOVE),
899 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
900 }, TramToolbarGlobalHotkeys};
901};
902
903static constexpr NWidgetPart _nested_build_road_widgets[] = {
905 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
906 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetStringTip(STR_JUST_STRING2, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
907 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
908 EndContainer(),
910 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
911 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
912 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
913 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
914 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
915 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
916 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
917 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
918 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
919 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
920 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
921 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT),
922 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
923 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
924 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
925 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
926 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
927 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
928 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
929 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
930 SetFill(0, 1), SetMinimalSize(43, 22), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
931 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
932 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
933 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
934 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
935 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
936 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
937 EndContainer(),
938};
939
940static WindowDesc _build_road_desc(
941 WDP_ALIGN_TOOLBAR, "toolbar_road", 0, 0,
944 _nested_build_road_widgets,
945 &BuildRoadToolbarWindow::road_hotkeys
946);
947
948static constexpr NWidgetPart _nested_build_tramway_widgets[] = {
950 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
951 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetStringTip(STR_JUST_STRING2, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
952 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
953 EndContainer(),
955 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
956 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
957 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
958 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
959 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
960 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
961 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
962 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
963 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
964 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
965 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
966 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT),
967 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
968 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
969 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
970 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
971 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
972 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
973 SetFill(0, 1), SetMinimalSize(43, 22), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
974 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
975 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
976 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
977 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
978 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
979 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
980 EndContainer(),
981};
982
983static WindowDesc _build_tramway_desc(
984 WDP_ALIGN_TOOLBAR, "toolbar_tramway", 0, 0,
987 _nested_build_tramway_widgets,
988 &BuildRoadToolbarWindow::tram_hotkeys
989);
990
999{
1000 if (!Company::IsValidID(_local_company)) return nullptr;
1001 if (!ValParamRoadType(roadtype)) return nullptr;
1002
1004 _cur_roadtype = roadtype;
1005
1006 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_desc : _build_tramway_desc, TRANSPORT_ROAD);
1007}
1008
1009static constexpr NWidgetPart _nested_build_road_scen_widgets[] = {
1011 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1012 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetStringTip(STR_JUST_STRING2, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
1013 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1014 EndContainer(),
1016 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1017 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1018 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1019 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1020 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1021 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
1022 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1023 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1024 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
1025 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
1026 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1027 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1028 SetFill(0, 1), SetMinimalSize(43, 22), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1029 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1030 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1031 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1032 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1033 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1034 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1035 EndContainer(),
1036};
1037
1038static WindowDesc _build_road_scen_desc(
1039 WDP_AUTO, "toolbar_road_scen", 0, 0,
1042 _nested_build_road_scen_widgets,
1043 &BuildRoadToolbarWindow::road_hotkeys
1044);
1045
1046static constexpr NWidgetPart _nested_build_tramway_scen_widgets[] = {
1048 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1049 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetStringTip(STR_JUST_STRING2, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), SetTextStyle(TC_WHITE),
1050 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1051 EndContainer(),
1053 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1054 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1055 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1056 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1057 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1058 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1059 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1060 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1061 NWidget(WWT_PANEL, COLOUR_DARK_GREEN, -1), SetMinimalSize(0, 22), SetFill(1, 1), EndContainer(),
1062 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1063 SetFill(0, 1), SetMinimalSize(43, 22), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1064 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1065 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1066 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1067 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1068 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1069 SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1070 EndContainer(),
1071};
1072
1073static WindowDesc _build_tramway_scen_desc(
1074 WDP_AUTO, "toolbar_tram_scen", 0, 0,
1077 _nested_build_tramway_scen_widgets,
1078 &BuildRoadToolbarWindow::tram_hotkeys
1079);
1080
1086{
1088 _cur_roadtype = roadtype;
1089
1090 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_scen_desc : _build_tramway_scen_desc, TRANSPORT_ROAD);
1091}
1092
1095 {
1096 this->CreateNestedTree();
1097
1098 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1099 if (RoadTypeIsTram(_cur_roadtype)) {
1101 for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) {
1103 }
1104 }
1105
1107 }
1108
1110 {
1111 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1112
1115 }
1116
1117 void DrawWidget(const Rect &r, WidgetID widget) const override
1118 {
1119 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1120
1123 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1125 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1126 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1127 DrawRoadDepotSprite(x, y, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
1128 }
1129 }
1130
1131 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1132 {
1133 switch (widget) {
1134 case WID_BROD_DEPOT_NW:
1135 case WID_BROD_DEPOT_NE:
1136 case WID_BROD_DEPOT_SW:
1137 case WID_BROD_DEPOT_SE:
1138 this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1139 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1140 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1142 this->SetDirty();
1143 break;
1144
1145 default:
1146 break;
1147 }
1148 }
1149};
1150
1151static constexpr NWidgetPart _nested_build_road_depot_widgets[] = {
1153 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1154 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetStringTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1155 EndContainer(),
1156 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1159 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1160 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1161 EndContainer(),
1163 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1164 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1165 EndContainer(),
1166 EndContainer(),
1167 EndContainer(),
1168};
1169
1170static WindowDesc _build_road_depot_desc(
1171 WDP_AUTO, nullptr, 0, 0,
1174 _nested_build_road_depot_widgets
1175);
1176
1177static void ShowRoadDepotPicker(Window *parent)
1178{
1179 new BuildRoadDepotWindow(_build_road_depot_desc, parent);
1180}
1181
1182template <RoadStopType roadstoptype>
1184public:
1186
1187 StringID GetClassTooltip() const override;
1188 StringID GetTypeTooltip() const override;
1189
1190 bool IsActive() const override
1191 {
1192 for (const auto &cls : RoadStopClass::Classes()) {
1193 if (IsWaypointClass(cls)) continue;
1194 for (const auto *spec : cls.Specs()) {
1195 if (spec == nullptr) continue;
1196 if (roadstoptype == RoadStopType::Truck && spec->stop_type != ROADSTOPTYPE_FREIGHT && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1197 if (roadstoptype == RoadStopType::Bus && spec->stop_type != ROADSTOPTYPE_PASSENGER && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1198 return true;
1199 }
1200 }
1201 return false;
1202 }
1203
1204 static bool IsClassChoice(const RoadStopClass &cls)
1205 {
1206 return !IsWaypointClass(cls) && GetIfClassHasNewStopsByType(&cls, roadstoptype, _cur_roadtype);
1207 }
1208
1209 bool HasClassChoice() const override
1210 {
1211 return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
1212 }
1213
1214 int GetSelectedClass() const override { return _roadstop_gui.sel_class; }
1215 void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); }
1216
1217 StringID GetClassName(int id) const override
1218 {
1219 const auto *rsc = this->GetClass(id);
1220 if (!IsClassChoice(*rsc)) return INVALID_STRING_ID;
1221 return rsc->name;
1222 }
1223
1224 int GetSelectedType() const override { return _roadstop_gui.sel_type; }
1225 void SetSelectedType(int id) const override { _roadstop_gui.sel_type = id; }
1226
1227 StringID GetTypeName(int cls_id, int id) const override
1228 {
1229 const auto *spec = this->GetSpec(cls_id, id);
1230 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return INVALID_STRING_ID;
1231 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
1232 }
1233
1234 bool IsTypeAvailable(int cls_id, int id) const override
1235 {
1236 const auto *spec = this->GetSpec(cls_id, id);
1237 return IsRoadStopAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck);
1238 }
1239
1240 void DrawType(int x, int y, int cls_id, int id) const override
1241 {
1242 const auto *spec = this->GetSpec(cls_id, id);
1243 if (spec == nullptr) {
1244 StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui.orientation);
1245 } else {
1246 DiagDirection orientation = _roadstop_gui.orientation;
1247 if (orientation < DIAGDIR_END && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DIAGDIR_END;
1248 DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, (uint8_t)orientation);
1249 }
1250 }
1251
1252 void FillUsedItems(std::set<PickerItem> &items) override
1253 {
1254 for (const Station *st : Station::Iterate()) {
1255 if (st->owner != _local_company) continue;
1256 if (roadstoptype == RoadStopType::Truck && !(st->facilities & FACIL_TRUCK_STOP)) continue;
1257 if (roadstoptype == RoadStopType::Bus && !(st->facilities & FACIL_BUS_STOP)) continue;
1258 items.insert({0, 0, ROADSTOP_CLASS_DFLT, 0}); // We would need to scan the map to find out if default is used.
1259 for (const auto &sm : st->roadstop_speclist) {
1260 if (sm.spec == nullptr) continue;
1261 if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1262 if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1263 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1264 }
1265 }
1266 }
1267};
1268
1269template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP; }
1270template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP; }
1271
1272template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP; }
1273template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP; }
1274
1275static RoadStopPickerCallbacks<RoadStopType::Bus> _bus_callback_instance("fav_passenger_roadstops");
1276static RoadStopPickerCallbacks<RoadStopType::Truck> _truck_callback_instance("fav_freight_roadstops");
1277
1278static PickerCallbacks &GetRoadStopPickerCallbacks(RoadStopType rs)
1279{
1280 return rs == RoadStopType::Bus ? static_cast<PickerCallbacks &>(_bus_callback_instance) : static_cast<PickerCallbacks &>(_truck_callback_instance);
1281}
1282
1284private:
1286
1287 void CheckOrientationValid()
1288 {
1289 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1290
1291 /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */
1292 if (RoadTypeIsRoad(_cur_roadtype)) {
1293 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1294 this->GetWidget<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0);
1295 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1296 }
1297
1298 if (_roadstop_gui.orientation >= DIAGDIR_END) return;
1299
1300 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) {
1301 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1302 _roadstop_gui.orientation = DIAGDIR_END;
1303 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1304 this->SetDirty();
1306 }
1307 }
1308
1309public:
1310 BuildRoadStationWindow(WindowDesc &desc, Window *parent, RoadStopType rs) : PickerWindow(desc, parent, TRANSPORT_ROAD, GetRoadStopPickerCallbacks(rs))
1311 {
1313
1314 /* Trams don't have non-drivethrough stations */
1315 if (RoadTypeIsTram(_cur_roadtype) && _roadstop_gui.orientation < DIAGDIR_END) {
1316 _roadstop_gui.orientation = DIAGDIR_END;
1317 }
1318 this->ConstructWindow();
1319
1320 const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1322
1323 for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1324 this->GetWidget<NWidgetCore>(i)->SetToolTip(rti->strings.picker_tooltip[to_underlying(rs)]);
1325 }
1326
1327 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1328 this->LowerWidget(WID_BROS_LT_OFF + _settings_client.gui.station_show_coverage);
1329
1331 }
1332
1333 void Close([[maybe_unused]] int data = 0) override
1334 {
1336 this->PickerWindow::Close();
1337 }
1338
1339 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1340 {
1342
1343 if (gui_scope) {
1344 this->CheckOrientationValid();
1345 }
1346 }
1347
1348 void OnPaint() override
1349 {
1350 this->DrawWidgets();
1351
1354 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1355 } else {
1356 SetTileSelectSize(1, 1);
1357 }
1358
1359 if (this->IsShaded()) return;
1360
1361 /* 'Accepts' and 'Supplies' texts. */
1363 Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
1364 const int bottom = r.bottom;
1365 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1367 r.top = DrawStationCoverageAreaText(r, sct, rad, true);
1368 /* Resize background if the window is too small.
1369 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1370 * (This is the case, if making the window bigger moves the mouse into the window.) */
1371 if (r.top > bottom) {
1372 this->coverage_height += r.top - bottom;
1373 this->ReInit();
1374 }
1375 }
1376
1378 {
1379 switch (widget) {
1384 case WID_BROS_STATION_X:
1385 case WID_BROS_STATION_Y:
1388 break;
1389
1391 size.height = this->coverage_height;
1392 break;
1393
1394 default:
1395 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1396 break;
1397 }
1398 }
1399
1404 {
1405 switch (window_class) {
1406 case WC_BUS_STATION: return StationType::Bus;
1407 case WC_TRUCK_STATION: return StationType::Truck;
1408 default: NOT_REACHED();
1409 }
1410 }
1411
1412 void DrawWidget(const Rect &r, WidgetID widget) const override
1413 {
1414 switch (widget) {
1419 case WID_BROS_STATION_X:
1420 case WID_BROS_STATION_Y: {
1422 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1425 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1427 int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT);
1428 int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM);
1429 if (spec == nullptr) {
1430 StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1431 } else {
1432 DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
1433 }
1434 }
1435 break;
1436 }
1437
1438 default:
1439 this->PickerWindow::DrawWidget(r, widget);
1440 break;
1441 }
1442 }
1443
1444 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1445 {
1446 switch (widget) {
1451 case WID_BROS_STATION_X:
1452 case WID_BROS_STATION_Y:
1453 if (widget < WID_BROS_STATION_X) {
1454 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1455 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return;
1456 }
1457 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1458 _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1459 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1461 this->SetDirty();
1463 break;
1464
1465 case WID_BROS_LT_OFF:
1466 case WID_BROS_LT_ON:
1467 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1469 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1471 this->SetDirty();
1472 SetViewportCatchmentStation(nullptr, true);
1473 break;
1474
1475 default:
1476 this->PickerWindow::OnClick(pt, widget, click_count);
1477 break;
1478 }
1479 }
1480
1481 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1482 {
1484 }
1485
1486 static inline HotkeyList road_hotkeys{"buildroadstop", {
1487 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1488 }};
1489
1490 static inline HotkeyList tram_hotkeys{"buildtramstop", {
1491 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1492 }};
1493};
1494
1498 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1499 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1500 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1501 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1502 EndContainer(),
1506 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1509 /* 6-orientation plane. */
1513 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NW), SetFill(0, 0), EndContainer(),
1514 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NE), SetFill(0, 0), EndContainer(),
1515 EndContainer(),
1516 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1517 EndContainer(),
1520 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SW), SetFill(0, 0), EndContainer(),
1521 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SE), SetFill(0, 0), EndContainer(),
1522 EndContainer(),
1523 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1524 EndContainer(),
1525 EndContainer(),
1526 /* 2-orientation plane. */
1529 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1530 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1531 EndContainer(),
1532 EndContainer(),
1533 EndContainer(),
1534 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1536 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1537 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1538 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1539 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1540 EndContainer(),
1541 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1542 EndContainer(),
1543 EndContainer(),
1544 EndContainer(),
1546 EndContainer(),
1547};
1548
1549static WindowDesc _road_station_picker_desc(
1550 WDP_AUTO, "build_station_road", 0, 0,
1554 &BuildRoadStationWindow::road_hotkeys
1555);
1556
1560 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1561 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1562 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1563 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1564 EndContainer(),
1568 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1571 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1572 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1573 EndContainer(),
1574 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1576 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1577 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1578 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1579 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1580 EndContainer(),
1581 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1582 EndContainer(),
1583 EndContainer(),
1584 EndContainer(),
1586 EndContainer(),
1587};
1588
1589static WindowDesc _tram_station_picker_desc(
1590 WDP_AUTO, "build_station_tram", 0, 0,
1594 &BuildRoadStationWindow::tram_hotkeys
1595);
1596
1597static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1598{
1599 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? _road_station_picker_desc : _tram_station_picker_desc, parent, rs);
1600}
1601
1603public:
1605
1606 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1607 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1608
1609 bool IsActive() const override
1610 {
1611 for (const auto &cls : RoadStopClass::Classes()) {
1612 if (!IsWaypointClass(cls)) continue;
1613 for (const auto *spec : cls.Specs()) {
1614 if (spec != nullptr) return true;
1615 }
1616 }
1617 return false;
1618 }
1619
1620 bool HasClassChoice() const override
1621 {
1622 return std::ranges::count_if(RoadStopClass::Classes(), IsWaypointClass) > 1;
1623 }
1624
1625 void Close(int) override { ResetObjectToPlace(); }
1626 int GetSelectedClass() const override { return _waypoint_gui.sel_class; }
1627 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1628
1629 StringID GetClassName(int id) const override
1630 {
1631 const auto *sc = GetClass(id);
1632 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1633 return sc->name;
1634 }
1635
1636 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1637 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1638
1639 StringID GetTypeName(int cls_id, int id) const override
1640 {
1641 const auto *spec = this->GetSpec(cls_id, id);
1642 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1643 }
1644
1645 bool IsTypeAvailable(int cls_id, int id) const override
1646 {
1647 return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
1648 }
1649
1650 void DrawType(int x, int y, int cls_id, int id) const override
1651 {
1652 const auto *spec = this->GetSpec(cls_id, id);
1653 if (spec == nullptr) {
1654 StationPickerDrawSprite(x, y, StationType::RoadWaypoint, INVALID_RAILTYPE, _cur_roadtype, RSV_DRIVE_THROUGH_X);
1655 } else {
1656 DrawRoadStopTile(x, y, _cur_roadtype, spec, StationType::RoadWaypoint, RSV_DRIVE_THROUGH_X);
1657 }
1658 }
1659
1660 void FillUsedItems(std::set<PickerItem> &items) override
1661 {
1662 for (const Waypoint *wp : Waypoint::Iterate()) {
1663 if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1664 items.insert({0, 0, ROADSTOP_CLASS_WAYP, 0}); // We would need to scan the map to find out if default is used.
1665 for (const auto &sm : wp->roadstop_speclist) {
1666 if (sm.spec == nullptr) continue;
1667 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1668 }
1669 }
1670 }
1671
1672 static RoadWaypointPickerCallbacks instance;
1673};
1674/* static */ RoadWaypointPickerCallbacks RoadWaypointPickerCallbacks::instance;
1675
1677 BuildRoadWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TRANSPORT_ROAD, RoadWaypointPickerCallbacks::instance)
1678 {
1679 this->ConstructWindow();
1680 this->InvalidateData();
1681 }
1682
1683 static inline HotkeyList hotkeys{"buildroadwaypoint", {
1684 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1685 }};
1686};
1687
1691 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1692 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1693 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1694 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1695 EndContainer(),
1699 EndContainer(),
1700};
1701
1702static WindowDesc _build_road_waypoint_desc(
1703 WDP_AUTO, "build_road_waypoint", 0, 0,
1707 &BuildRoadWaypointWindow::hotkeys
1708);
1709
1710static void ShowBuildRoadWaypointPicker(Window *parent)
1711{
1712 if (!RoadWaypointPickerCallbacks::instance.IsActive()) return;
1713 new BuildRoadWaypointWindow(_build_road_waypoint_desc, parent);
1714}
1715
1716void InitializeRoadGui()
1717{
1718 _road_depot_orientation = DIAGDIR_NW;
1719 _roadstop_gui.orientation = DIAGDIR_NW;
1722}
1723
1728{
1730 if (w != nullptr) w->ModifyRoadType(_cur_roadtype);
1731}
1732
1733DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1734{
1735 RoadTypes used_roadtypes;
1736 RoadTypes avail_roadtypes;
1737
1739
1740 /* Find the used roadtypes. */
1741 if (for_replacement) {
1742 avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1743 used_roadtypes = GetRoadTypes(false);
1744 } else {
1745 avail_roadtypes = c->avail_roadtypes;
1746 used_roadtypes = GetRoadTypes(true);
1747 }
1748
1749 /* Filter listed road types */
1750 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= _roadtypes_type;
1751 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~_roadtypes_type;
1752
1753 DropDownList list;
1754
1755 if (all_option) {
1756 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
1757 }
1758
1759 Dimension d = { 0, 0 };
1760 /* Get largest icon size, to ensure text is aligned on each menu item. */
1761 if (!for_replacement) {
1762 for (const auto &rt : _sorted_roadtypes) {
1763 if (!HasBit(used_roadtypes, rt)) continue;
1764 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1766 }
1767 }
1768
1769 for (const auto &rt : _sorted_roadtypes) {
1770 /* If it's not used ever, don't show it to the user. */
1771 if (!HasBit(used_roadtypes, rt)) continue;
1772
1773 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1774
1775 SetDParam(0, rti->strings.menu_text);
1776 SetDParam(1, rti->max_speed / 2);
1777 if (for_replacement) {
1778 list.push_back(MakeDropDownListStringItem(rti->strings.replace_text, rt, !HasBit(avail_roadtypes, rt)));
1779 } else {
1780 StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
1781 list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
1782 }
1783 }
1784
1785 if (list.empty()) {
1786 /* Empty dropdowns are not allowed */
1787 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1788 }
1789
1790 return list;
1791}
1792
1793DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1794{
1795 RoadTypes avail_roadtypes = GetRoadTypes(false);
1796 avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, TimerGameCalendar::date);
1797 RoadTypes used_roadtypes = GetRoadTypes(true);
1798
1799 /* Filter listed road types */
1800 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes &= _roadtypes_type;
1801 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes &= ~_roadtypes_type;
1802
1803 DropDownList list;
1804
1805 /* If it's not used ever, don't show it to the user. */
1806 Dimension d = { 0, 0 };
1807 for (const auto &rt : _sorted_roadtypes) {
1808 if (!HasBit(used_roadtypes, rt)) continue;
1809 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1811 }
1812 for (const auto &rt : _sorted_roadtypes) {
1813 if (!HasBit(used_roadtypes, rt)) continue;
1814
1815 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1816
1817 SetDParam(0, rti->strings.menu_text);
1818 SetDParam(1, rti->max_speed / 2);
1819 StringID str = rti->max_speed > 0 ? STR_TOOLBAR_RAILTYPE_VELOCITY : STR_JUST_STRING;
1820 list.push_back(MakeDropDownListIconItem(d, rti->gui_sprites.build_x_road, PAL_NONE, str, rt, !HasBit(avail_roadtypes, rt)));
1821 }
1822
1823 if (list.empty()) {
1824 /* Empty dropdowns are not allowed */
1825 list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
1826 }
1827
1828 return list;
1829}
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
constexpr bool Test(Tenum value) const
Test if the enum value is set.
Struct containing information relating to NewGRF classes for stations and airports.
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.
static uint GetClassCount()
Get the number of allocated classes.
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:100
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:37
const std::string ini_group
Ini Group for saving favourites.
Definition picker_gui.h:91
Base class for windows opened from a toolbar.
Definition window_gui.h:979
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:165
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:185
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:163
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:166
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:164
void SetSelectedType(int id) const override
Set the selected type.
bool HasClassChoice() const override
Are there multiple classes to chose from?
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
StringID GetClassName(int id) const override
Get the name of a class.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
void SetSelectedClass(int id) const override
Set the selected class.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
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?
int GetSelectedType() const override
Get the selected type.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:95
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:97
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:107
CursorID autoroad
Cursor for autorail tool.
Definition road.h:86
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:108
StringID err_build_road
Building a normal piece of road.
Definition road.h:100
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:101
CursorID depot
Cursor for building a depot.
Definition road.h:87
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:85
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:132
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:94
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:76
struct RoadTypeInfo::@27 strings
Strings associated with the rail type.
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:88
SpriteID auto_road
button for the autoroad construction
Definition road.h:77
SpriteID convert_road
button for converting road types
Definition road.h:80
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:84
StringID err_convert_road
Converting a road type.
Definition road.h:105
StringID err_depot
Building a depot.
Definition road.h:102
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:75
SpriteID build_depot
button for building depots
Definition road.h:78
SpriteID build_tunnel
button for building a tunnel
Definition road.h:79
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:103
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:104
struct RoadTypeInfo::@25 gui_sprites
struct containing the sprites for the road GUI.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
int GetSelectedType() const override
Get the selected type.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
bool IsActive() const override
Should picker class/type selection be enabled?
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
void SetSelectedType(int id) const override
Set the selected type.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
StringID GetClassName(int id) const override
Get the name of a class.
void SetSelectedClass(int id) const override
Set the selected class.
int GetSelectedClass() const override
Get the index of the selected class.
bool HasClassChoice() const override
Are there multiple classes to chose from?
static Date date
Current date in days (day counter).
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
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 DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ DC_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.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Axis
Allow incrementing of DiagDirDiff variables.
@ INVALID_AXIS
Flag for an invalid Axis.
@ 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_END
Used for iterations.
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.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:15
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:922
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
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:1548
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
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 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 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:937
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.
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:570
static debug_inline TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:404
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ Avail
Availability of road stop in construction window.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
RoadStopClassID
@ ROADSTOP_CLASS_DFLT
Default road stop class.
@ ROADSTOP_CLASS_WAYP
Waypoint class.
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
@ RSV_DRIVE_THROUGH_X
Drive through road stop, X axis.
@ NoAutoRoadConnection
No auto road connection.
@ RoadOnly
Only show in the road build menu (not tram).
@ TramOnly
Only show in the tram build menu (not road).
@ DriveThroughOnly
Stop is drive-through only.
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.
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:34
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:199
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:227
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:153
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition road.cpp:166
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition road_cmd.cpp:62
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Road related functions.
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:96
static constexpr NWidgetPart _nested_road_station_picker_widgets[]
Widget definition of the build road station window.
void InitializeRoadGUI()
I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
static constexpr NWidgetPart _nested_build_road_waypoint_widgets[]
Nested widget definition for the build NewGRF road waypoint window.
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
Command callback for building road stops.
Definition road_gui.cpp:194
static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
Place a new road stop.
Definition road_gui.cpp:228
static constexpr NWidgetPart _nested_tram_station_picker_widgets[]
Widget definition of the build tram station window.
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
Definition road_gui.cpp:295
static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
Check whether a road stop type can be built.
Definition road_gui.cpp:101
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition road_gui.cpp:123
static void PlaceRoad_BusStation(TileIndex tile)
Callback for placing a bus station.
Definition road_gui.cpp:277
static void PlaceRoad_Waypoint(TileIndex tile)
Place a road waypoint.
Definition road_gui.cpp:254
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
Definition road_gui.cpp:315
static RoadWaypointPickerSelection _waypoint_gui
Settings of the road waypoint picker.
Definition road_gui.cpp:73
static bool RoadToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition road_gui.cpp:328
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Definition road_gui.cpp:998
void ConnectRoadToStructure(TileIndex tile, DiagDirection direction)
If required, connects a new structure to an existing road or tram by building the missing roadbit.
Definition road_gui.cpp:162
Functions/types related to the road GUIs.
static debug_inline bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:74
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:128
@ ROAD_NONE
No road-part is build.
Definition road_type.h:53
RoadTypes
The different roadtypes we support, but then a bitmask of them.
Definition road_type.h:38
@ ROADTYPES_NONE
No roadtypes.
Definition road_type.h:39
RoadType
The different roadtypes we support.
Definition road_type.h:25
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:30
@ DRD_NORTHBOUND
All northbound traffic is disallowed.
Definition road_type.h:76
@ DRD_NONE
None of the directions are disallowed.
Definition road_type.h:74
Types related to the road widgets.
@ WID_BROS_LT_ON
Turn on area highlight.
Definition road_widget.h:55
@ WID_BROS_ACCEPTANCE
Station acceptance info.
Definition road_widget.h:56
@ WID_BROS_STATION_SW
Terminal station with SW entry.
Definition road_widget.h:50
@ WID_BROS_STATION_X
Drive-through station in x-direction.
Definition road_widget.h:52
@ WID_BROS_STATION_NE
Terminal station with NE entry.
Definition road_widget.h:48
@ WID_BROS_STATION_SE
Terminal station with SE entry.
Definition road_widget.h:49
@ WID_BROS_CAPTION
Caption of the window.
Definition road_widget.h:47
@ WID_BROS_AVAILABLE_ORIENTATIONS
Selection for selecting 6 or 2 orientations.
Definition road_widget.h:57
@ WID_BROS_STATION_NW
Terminal station with NW entry.
Definition road_widget.h:51
@ WID_BROS_STATION_Y
Drive-through station in y-direction.
Definition road_widget.h:53
@ WID_BROS_LT_OFF
Turn off area highlight.
Definition road_widget.h:54
RoadToolbarWidgets
Widgets of the BuildRoadToolbarWindow class.
Definition road_widget.h:14
@ WID_ROT_BUILD_BRIDGE
Build bridge.
Definition road_widget.h:26
@ WID_ROT_BUS_STATION
Build bus station.
Definition road_widget.h:23
@ WID_ROT_DEPOT
Build depot.
Definition road_widget.h:21
@ WID_ROT_CAPTION
Caption of the window.
Definition road_widget.h:16
@ WID_ROT_BUILD_WAYPOINT
Build waypoint.
Definition road_widget.h:22
@ WID_ROT_ROAD_Y
Build road in y-direction.
Definition road_widget.h:18
@ WID_ROT_AUTOROAD
Autorail.
Definition road_widget.h:19
@ WID_ROT_DEMOLISH
Demolish.
Definition road_widget.h:20
@ WID_ROT_BUILD_TUNNEL
Build tunnel.
Definition road_widget.h:27
@ WID_ROT_TRUCK_STATION
Build truck station.
Definition road_widget.h:24
@ WID_ROT_CONVERT_ROAD
Convert road.
Definition road_widget.h:29
@ WID_ROT_REMOVE
Remove road.
Definition road_widget.h:28
@ WID_ROT_ONE_WAY
Build one-way road.
Definition road_widget.h:25
@ WID_ROT_ROAD_X
Build road in x-direction.
Definition road_widget.h:17
@ WID_BROD_DEPOT_SE
Depot with SE entry.
Definition road_widget.h:39
@ WID_BROD_DEPOT_NE
Depot with NE entry.
Definition road_widget.h:38
@ WID_BROD_CAPTION
Caption of the window.
Definition road_widget.h:37
@ WID_BROD_DEPOT_NW
Depot with NW entry.
Definition road_widget.h:41
@ WID_BROD_DEPOT_SW
Depot with SW entry.
Definition road_widget.h:40
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:57
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:76
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1508
Base classes/functions for stations.
Command definitions related to stations.
Functions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station 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.
void ShowSelectRoadWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the road waypoint selection window when needed.
Contains enums and function declarations connected with stations GUI.
StationCoverageType
Types of cargo to display for station coverage.
Definition station_gui.h:21
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition station_gui.h:23
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition station_gui.h:22
RoadStopType
Types of RoadStops.
@ Bus
A standard stop for buses.
@ Truck
A standard stop for trucks.
@ FACIL_BUS_STOP
Station with bus stops.
@ FACIL_TRUCK_STOP
Station with truck stops.
StationType
Station types.
static constexpr uint CA_BUS
Catchment for bus stops with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
static constexpr uint CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition of base types and functions in a cross-platform compatible way.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
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...
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 DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint coverage_height
Height of the coverage texts.
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.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
StationType GetRoadStationTypeByWindowClass(WindowClass window_class) const
Simply to have a easier way to get the StationType for bus, truck and trams from the WindowClass.
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.
void OnPaint() override
The window must be repainted.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Road toolbar window handler.
Definition road_gui.cpp:344
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition road_gui.cpp:668
void ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition road_gui.cpp:436
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition road_gui.cpp:827
void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
The user is dragging over the map when the tile highlight mode has been set.
Definition road_gui.cpp:689
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition road_gui.cpp:365
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Definition road_gui.cpp:838
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition road_gui.cpp:606
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition road_gui.cpp:600
void OnPlacePresize(Point pt, TileIndex tile) override
The user moves over the map when a tile highlight mode has been set when the special mouse mode has b...
Definition road_gui.cpp:815
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition road_gui.cpp:418
int last_started_action
Last started user action.
Definition road_gui.cpp:346
RoadType roadtype
Road type to build.
Definition road_gui.cpp:345
void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
The user has dragged over the map when the tile highlight mode has been set.
Definition road_gui.cpp:728
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition road_gui.cpp:511
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition road_gui.cpp:442
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition road_gui.cpp:461
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition road_gui.cpp:821
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition road_gui.cpp:377
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
RoadTypes avail_roadtypes
Road 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
bool station_show_coverage
whether to highlight coverage area
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
Partial widget specification to allow NWidgets to be written nested.
Represents the covered area of e.g.
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Titem * Get(size_t index)
Returns Titem with given index.
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.
RoadStopClassID sel_class
Selected road stop class.
Definition road_gui.cpp:76
DiagDirection orientation
Selected orientation of the road stop.
Definition road_gui.cpp:78
uint16_t sel_type
Selected road stop type within the class.
Definition road_gui.cpp:77
Road stop specification.
GRFFilePropsBase< NUM_CARGO+3 > grf_prop
Properties related the the grf file.
RoadStopClassID sel_class
Selected road waypoint class.
Definition road_gui.cpp:70
uint16_t sel_type
Selected road waypoint type within the class.
Definition road_gui.cpp:71
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.
uint8_t station_spread
amount a station may spread
bool modified_catchment
different-size catchment areas
Station data structure.
Point size
Size, in tile "units", of the white/red selection area.
Point pos
Location, in tile "units", of the northern tile of the selected area.
Representation of a waypoint.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:949
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1044
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1730
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:731
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3157
Window * parent
Parent window.
Definition window_gui.h:327
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:468
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:548
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1720
WindowClass window_class
Window class.
Definition window_gui.h:300
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:409
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:522
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:556
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:829
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:970
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:562
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:449
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
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_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
@ TRANSPORT_ROAD
Transport by road vehicle.
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.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
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:1922
Functions related to vehicles.
@ VEH_ROAD
Road vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
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_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_X
drag only in X axis
@ VPM_X_OR_Y
drag in X or Y direction
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_PLACE_ROAD_Y_DIR
Road placement (Y axis)
@ DDSP_BUILD_BUSSTOP
Road stop placement (buses)
@ DDSP_REMOVE_BUSSTOP
Road stop removal (buses)
@ DDSP_REMOVE_ROAD_WAYPOINT
Road stop removal (waypoint)
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_BUILD_TRUCKSTOP
Road stop placement (trucks)
@ DDSP_REMOVE_TRUCKSTOP
Road stop removal (trucks)
@ DDSP_PLACE_AUTOROAD
Road placement (auto)
@ DDSP_BUILD_ROAD_WAYPOINT
Road stop placement (waypoint)
@ DDSP_PLACE_ROAD_X_DIR
Road placement (X axis)
@ DDSP_BUILD_BRIDGE
Bridge placement.
@ DDSP_CONVERT_ROAD
Road conversion.
Base of waypoints.
@ WPF_ROAD
This is a road waypoint.
Axis GetAxisForNewRoadWaypoint(TileIndex tile)
Get the axis for a new road 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:35
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:43
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:46
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:41
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:39
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
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:1137
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1149
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1095
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
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
WindowClass
Window classes.
Definition window_type.h:46
@ WC_SCEN_BUILD_TOOLBAR
Scenario build toolbar; Window numbers:
Definition window_type.h:82
@ 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_DEPOT
Build depot; Window numbers:
@ WC_TRUCK_STATION
Build truck station; Window numbers:
@ WC_BUS_STATION
Build bus station; 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