OpenTTD Source 20260311-master-g511d3794ce
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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 "toolbar_gui.h"
31#include "zoom_func.h"
32#include "dropdown_type.h"
33#include "dropdown_func.h"
34#include "engine_base.h"
35#include "station_base.h"
36#include "waypoint_base.h"
37#include "strings_func.h"
39#include "station_cmd.h"
40#include "waypoint_cmd.h"
41#include "road_cmd.h"
42#include "tunnelbridge_cmd.h"
43#include "newgrf_badge_gui.h"
44#include "newgrf_roadstop.h"
45#include "picker_gui.h"
46#include "timer/timer.h"
48
49#include "widgets/road_widget.h"
50
51#include "table/strings.h"
52
53#include "safeguards.h"
54
55static void ShowRVStationPicker(Window *parent, RoadStopType rs);
56static void ShowRoadDepotPicker(Window *parent);
57static void ShowBuildRoadWaypointPicker(Window *parent);
58
59static bool _remove_button_clicked;
60static bool _one_way_button_clicked;
61
62static Axis _place_road_dir;
63static bool _place_road_start_half_x;
64static bool _place_road_start_half_y;
65static bool _place_road_end_half;
66
67static RoadType _cur_roadtype;
68
69static DiagDirection _road_depot_orientation;
70
76
82static RoadStopPickerSelection _roadstop_gui;
83
84static bool IsRoadStopEverAvailable(const RoadStopSpec *spec, StationType type)
85{
86 if (spec == nullptr) return true;
87
88 if (spec->flags.Test(RoadStopSpecFlag::RoadOnly) && !RoadTypeIsRoad(_cur_roadtype)) return false;
89 if (spec->flags.Test(RoadStopSpecFlag::TramOnly) && !RoadTypeIsTram(_cur_roadtype)) return false;
90
91 switch (spec->stop_type) {
92 case ROADSTOPTYPE_ALL: return true;
93 case ROADSTOPTYPE_PASSENGER: return type == StationType::Bus;
94 case ROADSTOPTYPE_FREIGHT: return type == StationType::Truck;
95 default: NOT_REACHED();
96 }
97}
98
105static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
106{
107 if (spec == nullptr) return true;
108 if (!IsRoadStopEverAvailable(spec, type)) return false;
109
110 if (!spec->callback_mask.Test(RoadStopCallbackMask::Avail)) return true;
111
112 uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, nullptr, INVALID_TILE, _cur_roadtype, type, 0);
113 if (cb_res == CALLBACK_FAILED) return true;
114
116}
117
118void CcPlaySound_CONSTRUCTION_OTHER(Commands, const CommandCost &result, TileIndex tile)
119{
120 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
121}
122
128static void PlaceRoad_Bridge(TileIndex tile, Window *w)
129{
130 if (IsBridgeTile(tile)) {
131 TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
132 Point pt = {0, 0};
133 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
134 } else {
136 }
137}
138
145void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
146{
147 if (result.Succeeded()) {
148 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
149 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
150
151 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
152 ConnectRoadToStructure(start_tile, start_direction);
153
154 TileIndex end_tile = GetOtherTunnelBridgeEnd(start_tile);
155 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
156 ConnectRoadToStructure(end_tile, end_direction);
157 } else {
159 }
160}
161
168{
169 tile += TileOffsByDiagDir(direction);
170 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
171 if (IsNormalRoadTile(tile)) {
172 if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) {
173 Command<Commands::BuildRoad>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, TownID::Invalid());
174 }
175 }
176}
177
178void CcRoadDepot(Commands, const CommandCost &result, TileIndex tile, RoadType, DiagDirection dir)
179{
180 if (result.Failed()) return;
181
182 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
183 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
184 ConnectRoadToStructure(tile, dir);
185}
186
199void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through,
200 DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
201{
202 if (result.Failed()) return;
203
204 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
205 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
206
207 bool connect_to_road = true;
208 if (spec_class.base() < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) {
209 const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index);
210 if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false;
211 }
212
213 if (connect_to_road) {
214 TileArea roadstop_area(tile, width, length);
215 for (TileIndex cur_tile : roadstop_area) {
216 ConnectRoadToStructure(cur_tile, dir);
217 /* For a drive-through road stop build connecting road for other entrance. */
218 if (is_drive_through) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
219 }
220 }
221}
222
233static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
234{
235 TileArea ta(start_tile, end_tile);
236 DiagDirection ddir = _roadstop_gui.orientation;
237 bool drive_through = ddir >= DIAGDIR_END;
238 if (drive_through) ddir = static_cast<DiagDirection>(ddir - DIAGDIR_END); // Adjust picker result to actual direction.
239 RoadStopClassID spec_class = _roadstop_gui.sel_class;
240 uint16_t spec_index = _roadstop_gui.sel_type;
241
242 auto proc = [=](bool test, StationID to_join) -> bool {
243 if (test) {
244 return Command<Commands::BuildRoadStop>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildRoadStop>()), ta.tile, ta.w, ta.h, stop_type, drive_through,
245 ddir, rt, spec_class, spec_index, StationID::Invalid(), adjacent).Succeeded();
246 } else {
247 return Command<Commands::BuildRoadStop>::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through,
248 ddir, rt, spec_class, spec_index, to_join, adjacent);
249 }
250 };
251
253}
254
260{
263 return;
264 }
265
266 Axis axis = GetAxisForNewRoadWaypoint(tile);
267 if (IsValidAxis(axis)) {
268 /* Valid tile for waypoints */
270 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
271 } else {
272 /* Tile where we can't build road waypoints. This is always going to fail,
273 * but provides the user with a proper error message. */
274 Command<Commands::BuildRoadWaypoint>::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, AXIS_X, 1, 1, ROADSTOP_CLASS_WAYP, 0, StationID::Invalid(), false);
275 }
276}
277
283{
286 } else {
287 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
288 VpStartPlaceSizing(tile, (DiagDirToAxis(_roadstop_gui.orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
289 } else {
291 }
292 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
293 }
294}
295
301{
304 } else {
305 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
307 } else {
309 }
310 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
311 }
312}
313
314typedef void OnButtonClick(Window *w);
315
327
334{
335 if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
336
337 /* allow ctrl to switch remove mode only for these widgets */
338 for (WidgetID i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) {
339 if (w->IsWidgetLowered(i)) {
341 return true;
342 }
343 }
344
345 return false;
346}
347
349struct BuildRoadToolbarWindow : Window {
352
353 BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc), roadtype(_cur_roadtype)
354 {
355 this->CreateNestedTree();
356 this->FinishInitNested(window_number);
358
359 if (RoadTypeIsRoad(this->roadtype)) {
361 }
362
363 this->OnInvalidateData();
364
365 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
366 }
367
368 void Close([[maybe_unused]] int data = 0) override
369 {
370 if (_game_mode == GM_NORMAL && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true);
371 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
372 this->Window::Close();
373 }
374
380 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
381 {
382 if (!gui_scope) return;
383
384 if (!ValParamRoadType(this->roadtype)) {
385 /* Close toolbar if road type is not available. */
386 this->Close();
387 return;
388 }
389
390 RoadTramType rtt = GetRoadTramType(this->roadtype);
391
392 bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, rtt);
393 this->SetWidgetsDisabledState(!can_build,
398 if (!can_build) {
403 }
404
405 if (_game_mode != GM_EDITOR) {
406 if (!can_build) {
407 /* Show in the tooltip why this button is disabled. */
408 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
409 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
410 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
411 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
412 } else {
413 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT);
414 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT : STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT);
415 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION);
416 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION);
417 }
418 }
419 }
420
421 void OnInit() override
422 {
423 /* Configure the road toolbar for the roadtype. */
424 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
428 if (_game_mode != GM_EDITOR) {
430 }
433 }
434
440 {
441 this->roadtype = roadtype;
442 this->ReInit();
443 }
444
445 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
446 {
447 if (widget == WID_ROT_CAPTION) {
448 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
449 if (rti->max_speed > 0) {
450 return GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VEH_ROAD));
451 }
452 return GetString(rti->strings.toolbar_caption);
453
454 }
455
456 return this->Window::GetWidgetString(widget, stringid);
457 }
458
465 {
466 /* The remove and the one way button state is driven
467 * by the other buttons so they don't act on themselves.
468 * Both are only valid if they are able to apply as options. */
469 switch (clicked_widget) {
470 case WID_ROT_REMOVE:
471 if (RoadTypeIsRoad(this->roadtype)) {
474 }
475
476 break;
477
478 case WID_ROT_ONE_WAY:
481 break;
482
486 if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
487 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
488 break;
489
490 case WID_ROT_ROAD_X:
491 case WID_ROT_ROAD_Y:
492 case WID_ROT_AUTOROAD:
493 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
494 if (RoadTypeIsRoad(this->roadtype)) {
495 this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget));
496 }
497 break;
498
499 default:
500 /* When any other buttons than road/station, raise and
501 * disable the removal button */
504
505 if (RoadTypeIsRoad(this->roadtype)) {
508 }
509
510 break;
511 }
512 }
513
520 {
521 switch (widget) {
522 case WID_ROT_ROAD_X: return GetRoadTypeInfo(this->roadtype)->cursor.road_nwse;
523 case WID_ROT_ROAD_Y: return GetRoadTypeInfo(this->roadtype)->cursor.road_swne;
524 case WID_ROT_AUTOROAD: return GetRoadTypeInfo(this->roadtype)->cursor.autoroad;
526 case WID_ROT_DEPOT: return GetRoadTypeInfo(this->roadtype)->cursor.depot;
527 case WID_ROT_BUILD_WAYPOINT: return SPR_CURSOR_WAYPOINT;
528 case WID_ROT_BUS_STATION: return SPR_CURSOR_BUS_STATION;
529 case WID_ROT_TRUCK_STATION: return SPR_CURSOR_TRUCK_STATION;
530 case WID_ROT_BUILD_BRIDGE: return SPR_CURSOR_BRIDGE;
531 case WID_ROT_BUILD_TUNNEL: return GetRoadTypeInfo(this->roadtype)->cursor.tunnel;
532 case WID_ROT_CONVERT_ROAD: return GetRoadTypeInfo(this->roadtype)->cursor.convert_road;
533 default: NOT_REACHED();
534 }
535 }
536
543 {
544 switch (widget) {
545 case WID_ROT_ROAD_X: return HT_RECT;
546 case WID_ROT_ROAD_Y: return HT_RECT;
547 case WID_ROT_AUTOROAD: return HT_RECT;
548 case WID_ROT_DEMOLISH: return HT_RECT | HT_DIAGONAL;
549 case WID_ROT_DEPOT: return HT_RECT;
550 case WID_ROT_BUILD_WAYPOINT: return HT_RECT;
551 case WID_ROT_BUS_STATION: return HT_RECT;
552 case WID_ROT_TRUCK_STATION: return HT_RECT;
553 case WID_ROT_BUILD_BRIDGE: return HT_RECT;
554 case WID_ROT_BUILD_TUNNEL: return HT_SPECIAL;
556 default: NOT_REACHED();
557 }
558 }
559
560 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
561 {
562 bool started;
563 _remove_button_clicked = false;
564 _one_way_button_clicked = false;
565
566 if (widget != WID_ROT_ONE_WAY && widget != WID_ROT_REMOVE) {
567 started = HandlePlacePushButton(this, widget, this->GetCursorForWidget(widget), this->GetHighLightStyleForWidget(widget));
568 this->last_started_action = widget;
569 }
570
571 switch (widget) {
572 case WID_ROT_DEPOT:
573 if (started) {
574 ShowRoadDepotPicker(this);
575 }
576 break;
577
579 if (started) {
580 ShowBuildRoadWaypointPicker(this);
581 }
582 break;
583
585 if (started) {
586 ShowRVStationPicker(this, RoadStopType::Bus);
587 }
588 break;
589
591 if (started) {
592 ShowRVStationPicker(this, RoadStopType::Truck);
593 }
594 break;
595
596 case WID_ROT_ONE_WAY:
597 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
598 this->SetDirty();
600 SetSelectionRed(false);
601 break;
602
603 case WID_ROT_REMOVE:
604 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
605
608 SndClickBeep();
609 break;
610 }
611 this->UpdateOptionWidgetStatus(static_cast<RoadToolbarWidgets>(widget));
613 }
614
621 {
622 auto [index, step] = GetListIndexStep(SpecialListHotkeys(hotkey), _sorted_roadtypes, this->roadtype);
623
624 while (RoadTypeIsRoad(_sorted_roadtypes[index]) != RoadTypeIsRoad(this->roadtype) || !HasRoadTypeAvail(_local_company, _sorted_roadtypes[index])) {
625 index = (index + step) % _sorted_roadtypes.size();
626 }
627
628 _cur_roadtype = _sorted_roadtypes[index];
629 if (RoadTypeIsRoad(_cur_roadtype)) {
630 _last_built_roadtype = _cur_roadtype;
631 } else {
632 _last_built_tramtype = _cur_roadtype;
633 }
634 this->ModifyRoadType(_cur_roadtype);
635
636 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
638
639 return ES_HANDLED;
640 }
641
642 EventState OnHotkey(int hotkey) override
643 {
644 if (IsSpecialHotkey(hotkey)) return this->ChangeRoadTypeOnHotkey(hotkey);
645 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
646 return Window::OnHotkey(hotkey);
647 }
648
649 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
650 {
651 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
652 _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
653 switch (this->last_started_action) {
654 case WID_ROT_ROAD_X:
655 _place_road_dir = AXIS_X;
656 _place_road_start_half_x = _tile_fract_coords.x >= 8;
658 break;
659
660 case WID_ROT_ROAD_Y:
661 _place_road_dir = AXIS_Y;
662 _place_road_start_half_y = _tile_fract_coords.y >= 8;
664 break;
665
666 case WID_ROT_AUTOROAD:
667 _place_road_dir = INVALID_AXIS;
668 _place_road_start_half_x = _tile_fract_coords.x >= 8;
669 _place_road_start_half_y = _tile_fract_coords.y >= 8;
671 break;
672
673 case WID_ROT_DEMOLISH:
675 break;
676
677 case WID_ROT_DEPOT:
678 Command<Commands::BuildRoadDepot>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_depot, CcRoadDepot,
679 tile, _cur_roadtype, _road_depot_orientation);
680 break;
681
683 PlaceRoad_Waypoint(tile);
684 break;
685
688 break;
689
692 break;
693
695 PlaceRoad_Bridge(tile, this);
696 break;
697
699 Command<Commands::BuildTunnel>::Post(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE, CcBuildRoadTunnel,
700 tile, TRANSPORT_ROAD, _cur_roadtype);
701 break;
702
705 break;
706
707 default: NOT_REACHED();
708 }
709 }
710
731
732 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
733 {
734 /* Here we update the end tile flags
735 * of the road placement actions.
736 * At first we reset the end halfroad
737 * bits and if needed we set them again. */
738 switch (select_proc) {
740 _place_road_end_half = pt.x & 8;
741 break;
742
744 _place_road_end_half = pt.y & 8;
745 break;
746
748 /* For autoroad we need to update the
749 * direction of the road */
750 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
751 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
752 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
753 /* Set dir = X */
754 _place_road_dir = AXIS_X;
755 _place_road_end_half = pt.x & 8;
756 } else {
757 /* Set dir = Y */
758 _place_road_dir = AXIS_Y;
759 _place_road_end_half = pt.y & 8;
760 }
761
762 break;
763
764 default:
765 break;
766 }
767
768 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
769 }
770
771 Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
772 {
773 return AlignInitialConstructionToolbar(sm_width);
774 }
775
776 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
777 {
778 if (pt.x != -1) {
779 switch (select_proc) {
780 default: NOT_REACHED();
782 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
783 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, _cur_roadtype);
784 break;
785
787 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
788 break;
789
792 case DDSP_PLACE_AUTOROAD: {
793 bool start_half = _place_road_dir == AXIS_Y ? _place_road_start_half_y : _place_road_start_half_x;
794
795 if (_remove_button_clicked) {
796 Command<Commands::RemoveRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_remove_road, CcPlaySound_CONSTRUCTION_OTHER,
797 end_tile, start_tile, _cur_roadtype, _place_road_dir, start_half, _place_road_end_half);
798 } else {
799 Command<Commands::BuildRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_build_road, CcPlaySound_CONSTRUCTION_OTHER,
800 end_tile, start_tile, _cur_roadtype, _place_road_dir, _one_way_button_clicked ? DRD_NORTHBOUND : DRD_NONE, start_half, _place_road_end_half, false);
801 }
802 break;
803 }
804
808 if (_remove_button_clicked) {
809 Command<Commands::RemoveFromRoadWaypoint>::Post(STR_ERROR_CAN_T_REMOVE_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile);
810 } else {
811 TileArea ta(start_tile, end_tile);
812 Axis axis = select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y;
813 bool adjacent = _ctrl_pressed;
814
815 auto proc = [=](bool test, StationID to_join) -> bool {
816 if (test) {
817 return Command<Commands::BuildRoadWaypoint>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildRoadWaypoint>()), ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, StationID::Invalid(), adjacent).Succeeded();
818 } else {
819 return Command<Commands::BuildRoadWaypoint>::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, to_join, adjacent);
820 }
821 };
822
824 }
825 }
826 break;
827
830 if (this->IsWidgetLowered(WID_ROT_BUS_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Bus, _cur_roadtype)) {
831 if (_remove_button_clicked) {
832 TileArea ta(start_tile, end_tile);
834 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Bus, _ctrl_pressed);
835 } else {
837 PlaceRoadStop(start_tile, end_tile, RoadStopType::Bus, _ctrl_pressed, _cur_roadtype, str);
838 }
839 }
840 break;
841
844 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Truck, _cur_roadtype)) {
845 if (_remove_button_clicked) {
846 TileArea ta(start_tile, end_tile);
848 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Truck, _ctrl_pressed);
849 } else {
851 PlaceRoadStop(start_tile, end_tile, RoadStopType::Truck, _ctrl_pressed, _cur_roadtype, str);
852 }
853 }
854 break;
855
857 Command<Commands::ConvertRoad>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_convert_road, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile, _cur_roadtype, _ctrl_pressed);
858 break;
859 }
860 }
861 }
862
863 void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile) override
864 {
865 Command<Commands::BuildTunnel>::Do(DoCommandFlag::Auto, tile, TRANSPORT_ROAD, _cur_roadtype);
867 }
868
870 {
871 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
872 return ES_NOT_HANDLED;
873 }
874
875 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
876 {
877 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_ROT_BUILD_WAYPOINT)) CheckRedrawRoadWaypointCoverage(this);
878 }
879
888 {
889 Window *w = nullptr;
890 switch (_game_mode) {
891 case GM_NORMAL:
892 w = ShowBuildRoadToolbar(last_build);
893 break;
894
895 case GM_EDITOR:
896 if (!GetRoadTypes(true).Any(GetMaskForRoadTramType(rtt))) return ES_NOT_HANDLED;
897 w = ShowBuildRoadScenToolbar(last_build);
898 break;
899
900 default:
901 break;
902 }
903
904 if (w == nullptr) return ES_NOT_HANDLED;
905 return w->OnHotkey(hotkey);
906 }
907
908 static EventState RoadToolbarGlobalHotkeys(int hotkey)
909 {
911 }
912
913 static EventState TramToolbarGlobalHotkeys(int hotkey)
914 {
916 }
917
918 static inline HotkeyList road_hotkeys{"roadtoolbar", {
919 Hotkey('1', "build_x", WID_ROT_ROAD_X),
920 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
921 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
922 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
923 Hotkey('5', "depot", WID_ROT_DEPOT),
924 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
925 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
926 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
927 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
928 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
929 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
930 Hotkey('R', "remove", WID_ROT_REMOVE),
931 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
934 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_roadtype", to_underlying(SpecialListHotkeys::FirstItem)),
935 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_roadtype", to_underlying(SpecialListHotkeys::LastItem)),
936 }, RoadToolbarGlobalHotkeys};
937
938 static inline HotkeyList tram_hotkeys{"tramtoolbar", {
939 Hotkey('1', "build_x", WID_ROT_ROAD_X),
940 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
941 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
942 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
943 Hotkey('5', "depot", WID_ROT_DEPOT),
944 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
945 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
946 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
947 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
948 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
949 Hotkey('R', "remove", WID_ROT_REMOVE),
950 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
953 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_tramtype", to_underlying(SpecialListHotkeys::FirstItem)),
954 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_tramtype", to_underlying(SpecialListHotkeys::LastItem)),
955 }, TramToolbarGlobalHotkeys};
956};
957
958static constexpr std::initializer_list<NWidgetPart> _nested_build_road_widgets = {
960 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
961 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
962 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
963 EndContainer(),
965 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
966 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
967 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
968 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
969 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
970 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
971 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
972 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
973 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
974 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
975 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
976 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT),
977 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
978 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
979 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
980 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
981
982 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
983
984 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
985 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
986 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
987 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
988 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
989 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
990 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
991 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
992 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
993 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
994 EndContainer(),
995};
996
997static WindowDesc _build_road_desc(
998 WDP_MANUAL, "toolbar_road", 0, 0,
1001 _nested_build_road_widgets,
1002 &BuildRoadToolbarWindow::road_hotkeys
1003);
1004
1005static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_widgets = {
1007 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1008 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1009 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1010 EndContainer(),
1012 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1013 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1014 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1015 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1016 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1017 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1018 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1019 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1020 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
1021 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
1022 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
1023 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT),
1024 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
1025 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
1026 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
1027 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
1028
1029 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1030
1031 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1032 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1033 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1034 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1035 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1036 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1037 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1038 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1039 EndContainer(),
1040};
1041
1042static WindowDesc _build_tramway_desc(
1043 WDP_MANUAL, "toolbar_tramway", 0, 0,
1046 _nested_build_tramway_widgets,
1047 &BuildRoadToolbarWindow::tram_hotkeys
1048);
1049
1059{
1060 if (!Company::IsValidID(_local_company)) return nullptr;
1061 if (!ValParamRoadType(roadtype)) return nullptr;
1062
1064 _cur_roadtype = roadtype;
1065
1066 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_desc : _build_tramway_desc, TRANSPORT_ROAD);
1067}
1068
1069static constexpr std::initializer_list<NWidgetPart> _nested_build_road_scen_widgets = {
1071 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1072 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1073 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1074 EndContainer(),
1076 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1077 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1078 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1079 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1080 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1081 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
1082 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1083 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1084
1085 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1086
1087 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
1088 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1089 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1090 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1091 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1092 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1093 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1094 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1095 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1096 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1097 EndContainer(),
1098};
1099
1100static WindowDesc _build_road_scen_desc(
1101 WDP_AUTO, "toolbar_road_scen", 0, 0,
1104 _nested_build_road_scen_widgets,
1105 &BuildRoadToolbarWindow::road_hotkeys
1106);
1107
1108static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_scen_widgets = {
1110 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1111 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1112 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1113 EndContainer(),
1115 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1116 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1117 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1118 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1119 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1120 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1121 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1122 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1123
1124 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1125
1126 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1127 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1128 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1129 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1130 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1131 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1132 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1133 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1134 EndContainer(),
1135};
1136
1137static WindowDesc _build_tramway_scen_desc(
1138 WDP_AUTO, "toolbar_tram_scen", 0, 0,
1141 _nested_build_tramway_scen_widgets,
1142 &BuildRoadToolbarWindow::tram_hotkeys
1143);
1144
1151{
1153 _cur_roadtype = roadtype;
1154
1155 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_scen_desc : _build_tramway_scen_desc, TRANSPORT_ROAD);
1156}
1157
1158struct BuildRoadDepotWindow : public PickerWindowBase {
1159 BuildRoadDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
1160 {
1161 this->CreateNestedTree();
1162
1163 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1164 if (RoadTypeIsTram(_cur_roadtype)) {
1165 this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->SetString(STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION);
1166 for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) {
1167 this->GetWidget<NWidgetCore>(i)->SetToolTip(STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP);
1168 }
1169 }
1170
1172 }
1173
1174 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1175 {
1176 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1177
1178 size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal();
1179 size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical();
1180 }
1181
1182 void DrawWidget(const Rect &r, WidgetID widget) const override
1183 {
1184 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1185
1186 DrawPixelInfo tmp_dpi;
1187 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1188 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1189 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1190 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1191 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1192 DrawRoadDepotSprite(x, y, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
1193 }
1194 }
1195
1196 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1197 {
1198 switch (widget) {
1199 case WID_BROD_DEPOT_NW:
1200 case WID_BROD_DEPOT_NE:
1201 case WID_BROD_DEPOT_SW:
1202 case WID_BROD_DEPOT_SE:
1203 this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1204 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1205 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1206 SndClickBeep();
1207 this->SetDirty();
1208 break;
1209
1210 default:
1211 break;
1212 }
1213 }
1214};
1215
1216static constexpr std::initializer_list<NWidgetPart> _nested_build_road_depot_widgets = {
1218 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1219 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetStringTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1220 EndContainer(),
1221 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1224 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1225 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1226 EndContainer(),
1228 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1229 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1230 EndContainer(),
1231 EndContainer(),
1232 EndContainer(),
1233};
1234
1235static WindowDesc _build_road_depot_desc(
1236 WDP_AUTO, {}, 0, 0,
1239 _nested_build_road_depot_widgets
1240);
1241
1242static void ShowRoadDepotPicker(Window *parent)
1243{
1244 new BuildRoadDepotWindow(_build_road_depot_desc, parent);
1245}
1246
1247template <RoadStopType roadstoptype>
1248class RoadStopPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1249public:
1250 RoadStopPickerCallbacks(const std::string &ini_group) : PickerCallbacksNewGRFClass<RoadStopClass>(ini_group) {}
1251
1252 GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
1253
1254 StringID GetClassTooltip() const override;
1255 StringID GetTypeTooltip() const override;
1257
1258 bool IsActive() const override
1259 {
1260 for (const auto &cls : RoadStopClass::Classes()) {
1261 if (IsWaypointClass(cls)) continue;
1262 for (const auto *spec : cls.Specs()) {
1263 if (spec == nullptr) continue;
1264 if (roadstoptype == RoadStopType::Truck && spec->stop_type != ROADSTOPTYPE_FREIGHT && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1265 if (roadstoptype == RoadStopType::Bus && spec->stop_type != ROADSTOPTYPE_PASSENGER && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1266 return true;
1267 }
1268 }
1269 return false;
1270 }
1271
1272 static bool IsClassChoice(const RoadStopClass &cls)
1273 {
1274 return !IsWaypointClass(cls) && GetIfClassHasNewStopsByType(&cls, roadstoptype, _cur_roadtype);
1275 }
1276
1277 bool HasClassChoice() const override
1278 {
1279 return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
1280 }
1281
1282 int GetSelectedClass() const override { return _roadstop_gui.sel_class.base(); }
1283 void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); }
1284
1285 StringID GetClassName(int id) const override
1286 {
1287 const auto *rsc = this->GetClass(id);
1288 if (!IsClassChoice(*rsc)) return INVALID_STRING_ID;
1289 return rsc->name;
1290 }
1291
1292 int GetSelectedType() const override { return _roadstop_gui.sel_type; }
1293 void SetSelectedType(int id) const override { _roadstop_gui.sel_type = id; }
1294
1295 StringID GetTypeName(int cls_id, int id) const override
1296 {
1297 const auto *spec = this->GetSpec(cls_id, id);
1298 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return INVALID_STRING_ID;
1299 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
1300 }
1301
1302 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1303 {
1304 const auto *spec = this->GetSpec(cls_id, id);
1305 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return {};
1306 if (spec == nullptr) return {};
1307 return spec->badges;
1308 }
1309
1310 bool IsTypeAvailable(int cls_id, int id) const override
1311 {
1312 const auto *spec = this->GetSpec(cls_id, id);
1314 }
1315
1316 void DrawType(int x, int y, int cls_id, int id) const override
1317 {
1318 const auto *spec = this->GetSpec(cls_id, id);
1319 if (spec == nullptr) {
1320 StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui.orientation);
1321 } else {
1322 DiagDirection orientation = _roadstop_gui.orientation;
1323 if (orientation < DIAGDIR_END && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DIAGDIR_END;
1324 DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, (uint8_t)orientation);
1325 }
1326 }
1327
1328 void FillUsedItems(std::set<PickerItem> &items) override
1329 {
1330 for (const Station *st : Station::Iterate()) {
1331 if (st->owner != _local_company) continue;
1332 if (roadstoptype == RoadStopType::Truck && !st->facilities.Test(StationFacility::TruckStop)) continue;
1333 if (roadstoptype == RoadStopType::Bus && !st->facilities.Test(StationFacility::BusStop)) continue;
1334 items.insert({0, 0, ROADSTOP_CLASS_DFLT.base(), 0}); // We would need to scan the map to find out if default is used.
1335 for (const auto &sm : st->roadstop_speclist) {
1336 if (sm.spec == nullptr) continue;
1337 if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1338 if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1339 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1340 }
1341 }
1342 }
1343};
1344
1345template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP; }
1346template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP; }
1347template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_BUS_COLLECTION_TOOLTIP; }
1348
1349template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP; }
1350template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP; }
1351template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_COLLECTION_TOOLTIP; }
1352
1353static RoadStopPickerCallbacks<RoadStopType::Bus> _bus_callback_instance("fav_passenger_roadstops");
1354static RoadStopPickerCallbacks<RoadStopType::Truck> _truck_callback_instance("fav_freight_roadstops");
1355
1356static PickerCallbacks &GetRoadStopPickerCallbacks(RoadStopType rs)
1357{
1358 return rs == RoadStopType::Bus ? static_cast<PickerCallbacks &>(_bus_callback_instance) : static_cast<PickerCallbacks &>(_truck_callback_instance);
1359}
1360
1361struct BuildRoadStationWindow : public PickerWindow {
1362private:
1364
1365 void CheckOrientationValid()
1366 {
1367 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1368
1369 /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */
1370 if (RoadTypeIsRoad(_cur_roadtype)) {
1371 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1372 this->GetWidget<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0);
1373 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1374 }
1375
1376 if (_roadstop_gui.orientation >= DIAGDIR_END) return;
1377
1378 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) {
1379 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1380 _roadstop_gui.orientation = DIAGDIR_END;
1381 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1382 this->SetDirty();
1384 }
1385 }
1386
1387public:
1388 BuildRoadStationWindow(WindowDesc &desc, Window *parent, RoadStopType rs) : PickerWindow(desc, parent, TRANSPORT_ROAD, GetRoadStopPickerCallbacks(rs))
1389 {
1390 this->coverage_height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1391
1392 /* Trams don't have non-drivethrough stations */
1393 if (RoadTypeIsTram(_cur_roadtype) && _roadstop_gui.orientation < DIAGDIR_END) {
1394 _roadstop_gui.orientation = DIAGDIR_END;
1395 }
1396 this->ConstructWindow();
1397
1398 const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1400
1401 for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1402 this->GetWidget<NWidgetCore>(i)->SetToolTip(rti->strings.picker_tooltip[to_underlying(rs)]);
1403 }
1404
1405 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1407
1409 }
1410
1411 void Close([[maybe_unused]] int data = 0) override
1412 {
1414 this->PickerWindow::Close();
1415 }
1416
1417 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1418 {
1419 this->PickerWindow::OnInvalidateData(data, gui_scope);
1420
1421 if (gui_scope) {
1422 this->CheckOrientationValid();
1423 }
1424 }
1425
1426 void OnPaint() override
1427 {
1428 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1429
1430 this->DrawWidgets();
1431
1432 int rad = _settings_game.station.modified_catchment ? ((this->window_class == WC_BUS_STATION) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
1433 if (_settings_client.gui.station_show_coverage) {
1434 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1435 } else {
1436 SetTileSelectSize(1, 1);
1437 }
1438
1439 if (this->IsShaded()) return;
1440
1441 /* 'Accepts' and 'Supplies' texts. */
1443 Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
1444 const int bottom = r.bottom;
1445 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1446 if (spec != nullptr) r.top = DrawBadgeNameList(r, spec->badges, GSF_ROADSTOPS);
1447 r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
1448 r.top = DrawStationCoverageAreaText(r, sct, rad, true);
1449 /* Resize background if the window is too small.
1450 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1451 * (This is the case, if making the window bigger moves the mouse into the window.) */
1452 if (r.top > bottom) {
1453 this->coverage_height += r.top - bottom;
1454 this->ReInit();
1455 }
1456 }
1457
1458 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1459 {
1460 switch (widget) {
1465 case WID_BROS_STATION_X:
1466 case WID_BROS_STATION_Y:
1467 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
1468 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
1469 break;
1470
1472 size.height = this->coverage_height;
1473 break;
1474
1475 default:
1476 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1477 break;
1478 }
1479 }
1480
1487 {
1488 switch (window_class) {
1489 case WC_BUS_STATION: return StationType::Bus;
1491 default: NOT_REACHED();
1492 }
1493 }
1494
1495 void DrawWidget(const Rect &r, WidgetID widget) const override
1496 {
1497 switch (widget) {
1502 case WID_BROS_STATION_X:
1503 case WID_BROS_STATION_Y: {
1505 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1506 DrawPixelInfo tmp_dpi;
1507 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1508 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1509 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1512 if (spec == nullptr) {
1513 StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1514 } else {
1515 DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
1516 }
1517 }
1518 break;
1519 }
1520
1521 default:
1522 this->PickerWindow::DrawWidget(r, widget);
1523 break;
1524 }
1525 }
1526
1527 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1528 {
1529 switch (widget) {
1534 case WID_BROS_STATION_X:
1535 case WID_BROS_STATION_Y:
1536 if (widget < WID_BROS_STATION_X) {
1537 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1538 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return;
1539 }
1540 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1541 _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1542 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1543 SndClickBeep();
1544 this->SetDirty();
1546 break;
1547
1548 case WID_BROS_LT_OFF:
1549 case WID_BROS_LT_ON:
1550 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1551 _settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
1552 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1553 SndClickBeep();
1554 this->SetDirty();
1555 SetViewportCatchmentStation(nullptr, true);
1556 break;
1557
1558 default:
1559 this->PickerWindow::OnClick(pt, widget, click_count);
1560 break;
1561 }
1562 }
1563
1564 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1565 {
1567 }
1568
1569 static inline HotkeyList road_hotkeys{"buildroadstop", {
1570 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1571 }};
1572
1573 static inline HotkeyList tram_hotkeys{"buildtramstop", {
1574 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1575 }};
1576};
1577
1579static constexpr std::initializer_list<NWidgetPart> _nested_road_station_picker_widgets = {
1581 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1582 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1583 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1584 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1585 EndContainer(),
1589 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1592 /* 6-orientation plane. */
1596 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NW), SetFill(0, 0), EndContainer(),
1597 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NE), SetFill(0, 0), EndContainer(),
1598 EndContainer(),
1599 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1600 EndContainer(),
1603 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SW), SetFill(0, 0), EndContainer(),
1604 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SE), SetFill(0, 0), EndContainer(),
1605 EndContainer(),
1606 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1607 EndContainer(),
1608 EndContainer(),
1609 /* 2-orientation plane. */
1612 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1613 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1614 EndContainer(),
1615 EndContainer(),
1616 EndContainer(),
1617 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1619 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1620 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1621 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1622 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1623 EndContainer(),
1624 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1625 EndContainer(),
1626 EndContainer(),
1627 EndContainer(),
1629 EndContainer(),
1630};
1631
1632static WindowDesc _road_station_picker_desc(
1633 WDP_AUTO, "build_station_road", 0, 0,
1637 &BuildRoadStationWindow::road_hotkeys
1638);
1639
1641static constexpr std::initializer_list<NWidgetPart> _nested_tram_station_picker_widgets = {
1643 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1644 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1645 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1646 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1647 EndContainer(),
1651 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1654 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1655 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1656 EndContainer(),
1657 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1659 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1660 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1661 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1662 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1663 EndContainer(),
1664 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1665 EndContainer(),
1666 EndContainer(),
1667 EndContainer(),
1669 EndContainer(),
1670};
1671
1672static WindowDesc _tram_station_picker_desc(
1673 WDP_AUTO, "build_station_tram", 0, 0,
1677 &BuildRoadStationWindow::tram_hotkeys
1678);
1679
1680static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1681{
1682 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? _road_station_picker_desc : _tram_station_picker_desc, parent, rs);
1683}
1684
1685class RoadWaypointPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1686public:
1687 RoadWaypointPickerCallbacks() : PickerCallbacksNewGRFClass<RoadStopClass>("fav_road_waypoints") {}
1688
1689 GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
1690
1691 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1692 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1693 StringID GetCollectionTooltip() const override { return STR_PICKER_WAYPOINT_COLLECTION_TOOLTIP; }
1694
1695 bool IsActive() const override
1696 {
1697 for (const auto &cls : RoadStopClass::Classes()) {
1698 if (!IsWaypointClass(cls)) continue;
1699 for (const auto *spec : cls.Specs()) {
1700 if (spec != nullptr) return true;
1701 }
1702 }
1703 return false;
1704 }
1705
1706 bool HasClassChoice() const override
1707 {
1708 return std::ranges::count_if(RoadStopClass::Classes(), [](const auto &cls) { return IsWaypointClass(cls); }) > 1;
1709 }
1710
1711 void Close(int) override { ResetObjectToPlace(); }
1712 int GetSelectedClass() const override { return _waypoint_gui.sel_class.base(); }
1713 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1714
1715 StringID GetClassName(int id) const override
1716 {
1717 const auto *sc = GetClass(id);
1718 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1719 return sc->name;
1720 }
1721
1722 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1723 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1724
1725 StringID GetTypeName(int cls_id, int id) const override
1726 {
1727 const auto *spec = this->GetSpec(cls_id, id);
1728 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1729 }
1730
1731 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1732 {
1733 const auto *spec = this->GetSpec(cls_id, id);
1734 if (spec == nullptr) return {};
1735 return spec->badges;
1736 }
1737
1738 bool IsTypeAvailable(int cls_id, int id) const override
1739 {
1740 return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
1741 }
1742
1743 void DrawType(int x, int y, int cls_id, int id) const override
1744 {
1745 const auto *spec = this->GetSpec(cls_id, id);
1746 if (spec == nullptr) {
1747 StationPickerDrawSprite(x, y, StationType::RoadWaypoint, INVALID_RAILTYPE, _cur_roadtype, RSV_DRIVE_THROUGH_X);
1748 } else {
1750 }
1751 }
1752
1753 void FillUsedItems(std::set<PickerItem> &items) override
1754 {
1755 for (const Waypoint *wp : Waypoint::Iterate()) {
1756 if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1757 items.insert({0, 0, ROADSTOP_CLASS_WAYP.base(), 0}); // We would need to scan the map to find out if default is used.
1758 for (const auto &sm : wp->roadstop_speclist) {
1759 if (sm.spec == nullptr) continue;
1760 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1761 }
1762 }
1763 }
1764
1765 static RoadWaypointPickerCallbacks instance;
1766};
1767/* static */ RoadWaypointPickerCallbacks RoadWaypointPickerCallbacks::instance;
1768
1769struct BuildRoadWaypointWindow : public PickerWindow {
1770 BuildRoadWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TRANSPORT_ROAD, RoadWaypointPickerCallbacks::instance)
1771 {
1772 this->ConstructWindow();
1773 }
1774
1775 static inline HotkeyList hotkeys{"buildroadwaypoint", {
1776 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1777 }};
1778};
1779
1781static constexpr std::initializer_list<NWidgetPart> _nested_build_road_waypoint_widgets = {
1783 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1784 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1785 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1786 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1787 EndContainer(),
1791 EndContainer(),
1792};
1793
1794static WindowDesc _build_road_waypoint_desc(
1795 WDP_AUTO, "build_road_waypoint", 0, 0,
1799 &BuildRoadWaypointWindow::hotkeys
1800);
1801
1802static void ShowBuildRoadWaypointPicker(Window *parent)
1803{
1804 if (!RoadWaypointPickerCallbacks::instance.IsActive()) return;
1805 new BuildRoadWaypointWindow(_build_road_waypoint_desc, parent);
1806}
1807
1808void InitializeRoadGui()
1809{
1810 _road_depot_orientation = DIAGDIR_NW;
1811 _roadstop_gui.orientation = DIAGDIR_NW;
1813 _waypoint_gui.sel_type = 0;
1814}
1815
1820{
1822 if (w != nullptr) w->ModifyRoadType(_cur_roadtype);
1823}
1824
1825DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1826{
1827 RoadTypes used_roadtypes;
1828 RoadTypes avail_roadtypes;
1829
1831
1832 /* Find the used roadtypes. */
1833 if (for_replacement) {
1834 avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1835 used_roadtypes = GetRoadTypes(false);
1836 } else {
1837 avail_roadtypes = c->avail_roadtypes;
1838 used_roadtypes = GetRoadTypes(true);
1839 }
1840
1841 /* Filter listed road types */
1842 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
1843 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
1844
1845 DropDownList list;
1846
1847 if (all_option) {
1848 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
1849 }
1850
1851 Dimension d = { 0, 0 };
1852 /* Get largest icon size, to ensure text is aligned on each menu item. */
1853 if (!for_replacement) {
1854 used_roadtypes.Reset(_roadtypes_hidden_mask);
1855 for (const auto &rt : _sorted_roadtypes) {
1856 if (!used_roadtypes.Test(rt)) continue;
1857 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1859 }
1860 }
1861
1862 /* Shared list so that each item can take ownership. */
1863 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
1864
1865 for (const auto &rt : _sorted_roadtypes) {
1866 /* If it's not used ever, don't show it to the user. */
1867 if (!used_roadtypes.Test(rt)) continue;
1868
1869 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1870
1871 if (for_replacement) {
1872 list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt)));
1873 } else {
1874 std::string str = rti->max_speed > 0
1875 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1876 : GetString(rti->strings.menu_text);
1877 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1878 }
1879 }
1880
1881 if (list.empty()) {
1882 /* Empty dropdowns are not allowed */
1883 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1884 }
1885
1886 return list;
1887}
1888
1889DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1890{
1891 RoadTypes avail_roadtypes = GetRoadTypes(false);
1892 avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, TimerGameCalendar::date);
1893 RoadTypes used_roadtypes = GetRoadTypes(true);
1894
1895 /* Filter listed road types */
1896 used_roadtypes.Reset(_roadtypes_hidden_mask);
1897 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
1898 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
1899
1900 DropDownList list;
1901
1902 /* If it's not used ever, don't show it to the user. */
1903 Dimension d = { 0, 0 };
1904 for (const auto &rt : _sorted_roadtypes) {
1905 if (!used_roadtypes.Test(rt)) continue;
1906 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1908 }
1909
1910 /* Shared list so that each item can take ownership. */
1911 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
1912
1913 for (const auto &rt : _sorted_roadtypes) {
1914 if (!used_roadtypes.Test(rt)) continue;
1915
1916 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1917
1918 std::string str = rti->max_speed > 0
1919 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1920 : GetString(rti->strings.menu_text);
1921 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1922 }
1923
1924 if (list.empty()) {
1925 /* Empty dropdowns are not allowed */
1926 list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
1927 }
1928
1929 return list;
1930}
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
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static std::span< NewGRFClass< RoadStopSpec, RoadStopClassID > const > Classes()
static NewGRFClass * Get(RoadStopClassID class_index)
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:39
const std::string ini_group
Ini Group for saving favourites.
Definition picker_gui.h:204
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:298
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:299
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:300
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:301
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:332
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
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 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.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item's badges of a type.
StringID GetTypeName(int cls_id, int id) const override
Get the item name of a type.
bool IsActive() const override
Should picker class/type selection be enabled?
GrfSpecFeature GetFeature() const override
NewGRF feature this picker is for.
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 GetCollectionTooltip() const override
Get the tooltip string for the collection list.
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:79
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:81
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:91
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
CursorID autoroad
Cursor for autorail tool.
Definition road.h:70
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:140
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:92
StringID err_build_road
Building a normal piece of road.
Definition road.h:84
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:85
CursorID depot
Cursor for building a depot.
Definition road.h:71
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:69
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:116
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:78
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:60
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:72
SpriteID auto_road
button for the autoroad construction
Definition road.h:61
SpriteID convert_road
button for converting road types
Definition road.h:64
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:68
StringID err_convert_road
Converting a road type.
Definition road.h:89
StringID err_depot
Building a depot.
Definition road.h:86
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:59
SpriteID build_depot
button for building depots
Definition road.h:62
SpriteID build_tunnel
button for building a tunnel
Definition road.h:63
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:87
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:88
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
int GetSelectedType() const override
Get the selected type.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item's badges of a 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 Close(int) override
Hide the window and all its child windows, and mark them for a later deletion.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
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 name 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.
GrfSpecFeature GetFeature() const override
NewGRF feature this picker is for.
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:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Definition command.cpp:113
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ Auto
don't allow building on structures
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
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.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
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:21
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
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:972
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
void SetCursor(CursorID icon, PaletteID pal)
Assign an animation or a non-animated sprite to the cursor.
Definition gfx.cpp:1738
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:1573
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
uint32_t CursorID
The number of the cursor (sprite).
Definition gfx_type.h:19
@ WKC_R_BRACKET
] Right square bracket
Definition gfx_type.h:102
@ WKC_L_BRACKET
[ Left square bracket
Definition gfx_type.h:100
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 SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
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 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 NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
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:980
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.
std::tuple< size_t, size_t > GetListIndexStep(SpecialListHotkeys hotkey, const ListType &list, const ItemType &current_item)
Gets the first index in the list for given hotkey and the step to look for another if first is invali...
Definition hotkeys.h:110
SpecialListHotkeys
Indexes for special hotkeys to navigate in lists.
Definition hotkeys.h:93
@ NextItem
Hotkey to select next item in the list.
Definition hotkeys.h:95
@ FirstItem
Hotkey to select first item in the list.
Definition hotkeys.h:96
@ LastItem
Hotkey to select last item in the list.
Definition hotkeys.h:97
@ PreviousItem
Hotkey to select previous item in the list.
Definition hotkeys.h:94
bool IsSpecialHotkey(const int &hotkey)
Checks if hotkey index is special or not.
Definition hotkeys.h:84
#define Point
Macro that prevents name conflicts between included headers.
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
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:407
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
GrfSpecFeature
Definition newgrf.h:71
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
@ 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.
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
Draw representation of a road stop tile for GUI purposes.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
PoolID< uint16_t, struct RoadStopClassIDTag, UINT16_MAX, UINT16_MAX > RoadStopClassID
Class IDs for stations.
static constexpr RoadStopClassID ROADSTOP_CLASS_DFLT
Default road stop class.
static constexpr RoadStopClassID 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.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
Definition rail_gui.cpp:58
static WaypointPickerSelection _waypoint_gui
Settings of the waypoint picker.
Definition rail_gui.cpp:68
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:32
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:210
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:238
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:165
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition road.cpp:177
bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction.
Definition road.cpp:123
RoadTypes _roadtypes_hidden_mask
Bitset of hidden roadtypes.
Definition road_cmd.cpp:56
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:183
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:55
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:240
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Road related functions.
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:199
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:96
void InitializeRoadGUI()
I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
static constexpr std::initializer_list< 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:199
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:233
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
Definition road_gui.cpp:300
static constexpr std::initializer_list< NWidgetPart > _nested_tram_station_picker_widgets
Widget definition of the build tram station window.
static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
Check whether a road stop type can be built.
Definition road_gui.cpp:105
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition road_gui.cpp:128
static constexpr std::initializer_list< NWidgetPart > _nested_road_station_picker_widgets
Widget definition of the build road station window.
static void PlaceRoad_BusStation(TileIndex tile)
Callback for placing a bus station.
Definition road_gui.cpp:282
static void PlaceRoad_Waypoint(TileIndex tile)
Place a road waypoint.
Definition road_gui.cpp:259
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
Definition road_gui.cpp:320
static RoadWaypointPickerSelection _waypoint_gui
Settings of the road waypoint picker.
Definition road_gui.cpp:75
static bool RoadToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition road_gui.cpp:333
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
Callback executed after a build road tunnel command has been called.
Definition road_gui.cpp:145
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:167
Functions/types related to the road GUIs.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
@ ROAD_NONE
No road-part is build.
Definition road_type.h:57
RoadTramType
The different types of road type.
Definition road_type.h:37
@ RTT_ROAD
Road road type.
Definition road_type.h:38
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
RoadTramTypes
Definition road_type.h:42
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
@ DRD_NORTHBOUND
All northbound traffic is disallowed.
Definition road_type.h:80
@ DRD_NONE
None of the directions are disallowed.
Definition road_type.h:78
Types related to the road widgets.
@ WID_BROS_LT_ON
Turn on area highlight.
Definition road_widget.h:53
@ WID_BROS_ACCEPTANCE
Station acceptance info.
Definition road_widget.h:54
@ WID_BROS_STATION_SW
Terminal station with SW entry.
Definition road_widget.h:48
@ WID_BROS_STATION_X
Drive-through station in x-direction.
Definition road_widget.h:50
@ WID_BROS_STATION_NE
Terminal station with NE entry.
Definition road_widget.h:46
@ WID_BROS_STATION_SE
Terminal station with SE entry.
Definition road_widget.h:47
@ WID_BROS_CAPTION
Caption of the window.
Definition road_widget.h:45
@ WID_BROS_AVAILABLE_ORIENTATIONS
Selection for selecting 6 or 2 orientations.
Definition road_widget.h:55
@ WID_BROS_STATION_NW
Terminal station with NW entry.
Definition road_widget.h:49
@ WID_BROS_STATION_Y
Drive-through station in y-direction.
Definition road_widget.h:51
@ WID_BROS_LT_OFF
Turn off area highlight.
Definition road_widget.h:52
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:37
@ WID_BROD_DEPOT_NE
Depot with NE entry.
Definition road_widget.h:36
@ WID_BROD_CAPTION
Caption of the window.
Definition road_widget.h:35
@ WID_BROD_DEPOT_NW
Depot with NW entry.
Definition road_widget.h:39
@ WID_BROD_DEPOT_SW
Depot with SW entry.
Definition road_widget.h:38
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:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:77
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1522
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.
@ TruckStop
Station with truck stops.
@ BusStop
Station with bus stops.
StationType
Station types.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RoadWaypoint
Waypoint for trucks and busses.
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.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
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:349
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition road_gui.cpp:711
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition road_gui.cpp:445
void ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition road_gui.cpp:439
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition road_gui.cpp:875
HighLightStyle GetHighLightStyleForWidget(WidgetID widget)
Returns corresponding high light style for provided button.
Definition road_gui.cpp:542
CursorID GetCursorForWidget(WidgetID widget)
Returns corresponding cursor for provided button.
Definition road_gui.cpp:519
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:732
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:368
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Definition road_gui.cpp:887
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:649
EventState ChangeRoadTypeOnHotkey(int hotkey)
Selects new RoadType based on SpecialHotkeys and order defined in _sorted_roadtypes.
Definition road_gui.cpp:620
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition road_gui.cpp:642
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:863
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition road_gui.cpp:421
RoadType roadtype
Road type to build.
Definition road_gui.cpp:350
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:776
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:560
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition road_gui.cpp:464
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition road_gui.cpp:869
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition road_gui.cpp:771
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition road_gui.cpp:380
WidgetID last_started_action
Last started user action.
Definition road_gui.cpp:351
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:157
const struct GRFFile * grffile
grf file that introduced this entity
bool station_show_coverage
whether to highlight coverage area
List of hotkeys for a window.
Definition hotkeys.h:46
All data for a single hotkey.
Definition hotkeys.h:22
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
static Company * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int Height() const
Get height of Rect.
RoadStopClassID sel_class
Selected road stop class.
Definition road_gui.cpp:78
DiagDirection orientation
Selected orientation of the road stop.
Definition road_gui.cpp:80
uint16_t sel_type
Selected road stop type within the class.
Definition road_gui.cpp:79
Road stop specification.
CargoGRFFileProps grf_prop
Link to NewGRF.
RoadStopClassID sel_class
Selected road waypoint class.
Definition road_gui.cpp:72
uint16_t sel_type
Selected road waypoint type within the class.
Definition road_gui.cpp:73
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Station data structure.
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:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:992
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1117
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1822
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:768
Window * parent
Parent window.
Definition window_gui.h:329
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:570
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:518
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1812
WindowClass window_class
Window class.
Definition window_gui.h:302
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:544
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:563
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:850
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1845
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:990
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:584
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:451
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
HighLightStyle
Highlighting draw styles.
@ 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.
RoadType _last_built_tramtype
The most recently used type of tram track.
RoadType _last_built_roadtype
The most recently used type of road.
Stuff related to the (main) toolbar.
@ 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:1944
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:49
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ 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:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ 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:37
@ 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:1209
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1222
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1715
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1166
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3199
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.
Definition window_gui.h:153
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
Definition window_gui.h:143
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.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:23
@ WC_SCEN_BUILD_TOOLBAR
Scenario build toolbar; Window numbers:
Definition window_type.h:85
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
@ 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