OpenTTD Source 20260711-master-g3fb3006dff
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)).Any()) {
173 Command<Commands::BuildRoad>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, {}, 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 >= DiagDirection::End;
238 if (drive_through) ddir = ddir - DiagDirection::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 < DiagDirection::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 < DiagDirection::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 {
371 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WindowClass::ScenarioGenerateLandscape, 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 (_cur_roadtype != this->roadtype) {
385 bool close_build_station = this->ModifyRoadType(_cur_roadtype);
386
387 /* Update cursor and all sub windows. */
388 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
389 for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) {
391 }
392
393 if (close_build_station) {
394 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
395 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
396 }
397 }
398
399 if (!ValParamRoadType(this->roadtype)) {
400 /* Close toolbar if road type is not available. */
401 this->Close();
402 return;
403 }
404
405 RoadTramType rtt = GetRoadTramType(this->roadtype);
406
408 this->SetWidgetsDisabledState(!can_build,
413 if (!can_build) {
414 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
415 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
416 CloseWindowById(WindowClass::BuildDepot, TransportType::Road);
417 CloseWindowById(WindowClass::BuildWaypoint, TransportType::Road);
418 }
419
420 if (_game_mode != GameMode::Editor) {
421 if (!can_build) {
422 /* Show in the tooltip why this button is disabled. */
423 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
424 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
425 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
426 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
427 } else {
428 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT);
429 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT : STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT);
430 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION);
431 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION);
432 }
433 }
434 }
435
436 void OnInit() override
437 {
438 /* Configure the road toolbar for the roadtype. */
439 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
443 if (_game_mode != GameMode::Editor) {
445 }
448 }
449
456 {
457 bool result = RoadTypeIsRoad(this->roadtype) != RoadTypeIsRoad(roadtype);
458
459 this->roadtype = roadtype;
460 this->ReInit();
461 return result;
462 }
463
464 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
465 {
466 if (widget == WID_ROT_CAPTION) {
467 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
468 if (rti->max_speed > 0) {
469 return GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VehicleType::Road));
470 }
471 return GetString(rti->strings.toolbar_caption);
472
473 }
474
475 return this->Window::GetWidgetString(widget, stringid);
476 }
477
484 {
485 /* The remove and the one way button state is driven
486 * by the other buttons so they don't act on themselves.
487 * Both are only valid if they are able to apply as options. */
488 switch (clicked_widget) {
489 case WID_ROT_REMOVE:
490 if (RoadTypeIsRoad(this->roadtype)) {
493 }
494
495 break;
496
497 case WID_ROT_ONE_WAY:
500 break;
501
505 if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
506 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
507 break;
508
509 case WID_ROT_ROAD_X:
510 case WID_ROT_ROAD_Y:
511 case WID_ROT_AUTOROAD:
512 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
513 if (RoadTypeIsRoad(this->roadtype)) {
514 this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget));
515 }
516 break;
517
518 default:
519 /* When any other buttons than road/station, raise and
520 * disable the removal button */
523
524 if (RoadTypeIsRoad(this->roadtype)) {
527 }
528
529 break;
530 }
531 }
532
539 {
540 switch (widget) {
541 case WID_ROT_ROAD_X: return GetRoadTypeInfo(this->roadtype)->cursor.road_nwse;
542 case WID_ROT_ROAD_Y: return GetRoadTypeInfo(this->roadtype)->cursor.road_swne;
543 case WID_ROT_AUTOROAD: return GetRoadTypeInfo(this->roadtype)->cursor.autoroad;
545 case WID_ROT_DEPOT: return GetRoadTypeInfo(this->roadtype)->cursor.depot;
550 case WID_ROT_BUILD_TUNNEL: return GetRoadTypeInfo(this->roadtype)->cursor.tunnel;
551 case WID_ROT_CONVERT_ROAD: return GetRoadTypeInfo(this->roadtype)->cursor.convert_road;
552 default: NOT_REACHED();
553 }
554 }
555
562 {
563 switch (widget) {
564 case WID_ROT_ROAD_X: return HT_RECT;
565 case WID_ROT_ROAD_Y: return HT_RECT;
566 case WID_ROT_AUTOROAD: return HT_RECT;
567 case WID_ROT_DEMOLISH: return HT_RECT | HT_DIAGONAL;
568 case WID_ROT_DEPOT: return HT_RECT;
569 case WID_ROT_BUILD_WAYPOINT: return HT_RECT;
570 case WID_ROT_BUS_STATION: return HT_RECT;
571 case WID_ROT_TRUCK_STATION: return HT_RECT;
572 case WID_ROT_BUILD_BRIDGE: return HT_RECT;
573 case WID_ROT_BUILD_TUNNEL: return HT_SPECIAL;
575 default: NOT_REACHED();
576 }
577 }
578
579 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
580 {
581 bool started;
582 _remove_button_clicked = false;
583 _one_way_button_clicked = false;
584
585 if (widget != WID_ROT_ONE_WAY && widget != WID_ROT_REMOVE) {
586 started = HandlePlacePushButton(this, widget, this->GetCursorForWidget(widget), this->GetHighLightStyleForWidget(widget));
587 this->last_started_action = widget;
588 }
589
590 switch (widget) {
591 case WID_ROT_DEPOT:
592 if (started) {
593 ShowRoadDepotPicker(this);
594 }
595 break;
596
598 if (started) {
599 ShowBuildRoadWaypointPicker(this);
600 }
601 break;
602
604 if (started) {
605 ShowRVStationPicker(this, RoadStopType::Bus);
606 }
607 break;
608
610 if (started) {
611 ShowRVStationPicker(this, RoadStopType::Truck);
612 }
613 break;
614
615 case WID_ROT_ONE_WAY:
616 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
617 this->SetDirty();
619 SetSelectionRed(false);
620 break;
621
622 case WID_ROT_REMOVE:
623 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
624
625 CloseWindowById(WindowClass::JoinStation, 0);
627 SndClickBeep();
628 break;
629 }
630 this->UpdateOptionWidgetStatus(static_cast<RoadToolbarWidgets>(widget));
632 }
633
640 {
641 auto [index, step] = GetListIndexStep(SpecialListHotkeys(hotkey), _sorted_roadtypes, this->roadtype);
642
643 while (RoadTypeIsRoad(_sorted_roadtypes[index]) != RoadTypeIsRoad(this->roadtype) || !HasRoadTypeAvail(_local_company, _sorted_roadtypes[index])) {
644 index = (index + step) % _sorted_roadtypes.size();
645 }
646
647 _cur_roadtype = _sorted_roadtypes[index];
648 if (RoadTypeIsRoad(_cur_roadtype)) {
649 _last_built_roadtype = _cur_roadtype;
650 } else {
651 _last_built_tramtype = _cur_roadtype;
652 }
653 this->ModifyRoadType(_cur_roadtype);
654
655 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
656 for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) {
658 }
659
660 return EventState::Handled;
661 }
662
663 EventState OnHotkey(int hotkey) override
664 {
665 if (IsSpecialHotkey(hotkey)) return this->ChangeRoadTypeOnHotkey(hotkey);
666 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
667 return Window::OnHotkey(hotkey);
668 }
669
670 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
671 {
672 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
673 _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
674 switch (this->last_started_action) {
675 case WID_ROT_ROAD_X:
676 _place_road_dir = Axis::X;
677 _place_road_start_half_x = _tile_fract_coords.x >= 8;
679 break;
680
681 case WID_ROT_ROAD_Y:
682 _place_road_dir = Axis::Y;
683 _place_road_start_half_y = _tile_fract_coords.y >= 8;
685 break;
686
687 case WID_ROT_AUTOROAD:
688 _place_road_dir = Axis::Invalid;
689 _place_road_start_half_x = _tile_fract_coords.x >= 8;
690 _place_road_start_half_y = _tile_fract_coords.y >= 8;
692 break;
693
694 case WID_ROT_DEMOLISH:
696 break;
697
698 case WID_ROT_DEPOT:
699 Command<Commands::BuildRoadDepot>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_depot, CcRoadDepot,
700 tile, _cur_roadtype, _road_depot_orientation);
701 break;
702
704 PlaceRoad_Waypoint(tile);
705 break;
706
709 break;
710
713 break;
714
716 PlaceRoad_Bridge(tile, this);
717 break;
718
720 Command<Commands::BuildTunnel>::Post(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE, CcBuildRoadTunnel,
721 tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
722 break;
723
726 break;
727
728 default: NOT_REACHED();
729 }
730 }
731
732 void OnPlaceObjectAbort() override
733 {
735
736 this->RaiseButtons();
739
740 if (RoadTypeIsRoad(this->roadtype)) {
743 }
744
745 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
746 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
747 CloseWindowById(WindowClass::BuildDepot, TransportType::Road);
748 CloseWindowById(WindowClass::BuildWaypoint, TransportType::Road);
749 CloseWindowById(WindowClass::JoinStation, 0);
750 CloseWindowByClass(WindowClass::BuildBridge);
751 }
752
753 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
754 {
755 /* Here we update the end tile flags
756 * of the road placement actions.
757 * At first we reset the end halfroad
758 * bits and if needed we set them again. */
759 switch (select_proc) {
761 _place_road_end_half = pt.x & 8;
762 break;
763
765 _place_road_end_half = pt.y & 8;
766 break;
767
769 /* For autoroad we need to update the
770 * direction of the road */
771 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
772 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
773 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
774 /* Set dir = X */
775 _place_road_dir = Axis::X;
776 _place_road_end_half = pt.x & 8;
777 } else {
778 /* Set dir = Y */
779 _place_road_dir = Axis::Y;
780 _place_road_end_half = pt.y & 8;
781 }
782
783 break;
784
785 default:
786 break;
787 }
788
789 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
790 }
791
792 Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
793 {
794 return AlignInitialConstructionToolbar(sm_width);
795 }
796
797 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
798 {
799 if (pt.x != -1) {
800 switch (select_proc) {
801 default: NOT_REACHED();
803 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
804 ShowBuildBridgeWindow(start_tile, end_tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
805 break;
806
808 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
809 break;
810
813 case DDSP_PLACE_AUTOROAD: {
814 bool start_half = _place_road_dir == Axis::Y ? _place_road_start_half_y : _place_road_start_half_x;
815
816 if (_remove_button_clicked) {
817 Command<Commands::RemoveRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_remove_road, CcPlaySound_CONSTRUCTION_OTHER,
818 end_tile, start_tile, _cur_roadtype, _place_road_dir, start_half, _place_road_end_half);
819 } else {
820 Command<Commands::BuildRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_build_road, CcPlaySound_CONSTRUCTION_OTHER,
821 end_tile, start_tile, _cur_roadtype, _place_road_dir, _one_way_button_clicked ? DisallowedRoadDirection::Northbound : DisallowedRoadDirections{}, start_half, _place_road_end_half, false);
822 }
823 break;
824 }
825
829 if (_remove_button_clicked) {
830 Command<Commands::RemoveFromRoadWaypoint>::Post(STR_ERROR_CAN_T_REMOVE_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile);
831 } else {
832 TileArea ta(start_tile, end_tile);
833 Axis axis = select_method == VPM_X_LIMITED ? Axis::X : Axis::Y;
834 bool adjacent = _ctrl_pressed;
835
836 auto proc = [=](bool test, StationID to_join) -> bool {
837 if (test) {
838 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();
839 } else {
840 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);
841 }
842 };
843
845 }
846 }
847 break;
848
851 if (this->IsWidgetLowered(WID_ROT_BUS_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Bus, _cur_roadtype)) {
852 if (_remove_button_clicked) {
853 TileArea ta(start_tile, end_tile);
855 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Bus, _ctrl_pressed);
856 } else {
858 PlaceRoadStop(start_tile, end_tile, RoadStopType::Bus, _ctrl_pressed, _cur_roadtype, str);
859 }
860 }
861 break;
862
865 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Truck, _cur_roadtype)) {
866 if (_remove_button_clicked) {
867 TileArea ta(start_tile, end_tile);
869 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Truck, _ctrl_pressed);
870 } else {
872 PlaceRoadStop(start_tile, end_tile, RoadStopType::Truck, _ctrl_pressed, _cur_roadtype, str);
873 }
874 }
875 break;
876
878 Command<Commands::ConvertRoad>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_convert_road, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile, _cur_roadtype, _ctrl_pressed);
879 break;
880 }
881 }
882 }
883
884 void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile) override
885 {
886 Command<Commands::BuildTunnel>::Do(DoCommandFlag::Auto, tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
888 }
889
891 {
894 }
895
896 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
897 {
898 if (_game_mode == GameMode::Normal && this->IsWidgetLowered(WID_ROT_BUILD_WAYPOINT)) CheckRedrawRoadWaypointCoverage(this);
899 }
900
909 {
910 Window *w = nullptr;
911 switch (_game_mode) {
912 case GameMode::Normal:
913 w = ShowBuildRoadToolbar(last_build);
914 break;
915
916 case GameMode::Editor:
918 w = ShowBuildRoadScenToolbar(last_build);
919 break;
920
921 default:
922 break;
923 }
924
925 if (w == nullptr) return EventState::NotHandled;
926 return w->OnHotkey(hotkey);
927 }
928
929 static EventState RoadToolbarGlobalHotkeys(int hotkey)
930 {
932 }
933
934 static EventState TramToolbarGlobalHotkeys(int hotkey)
935 {
937 }
938
939 static inline HotkeyList road_hotkeys{"roadtoolbar", {
940 Hotkey('1', "build_x", WID_ROT_ROAD_X),
941 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
942 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
943 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
944 Hotkey('5', "depot", WID_ROT_DEPOT),
945 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
946 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
947 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
948 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
949 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
950 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
951 Hotkey('R', "remove", WID_ROT_REMOVE),
952 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
955 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_roadtype", to_underlying(SpecialListHotkeys::FirstItem)),
956 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_roadtype", to_underlying(SpecialListHotkeys::LastItem)),
957 }, RoadToolbarGlobalHotkeys};
958
959 static inline HotkeyList tram_hotkeys{"tramtoolbar", {
960 Hotkey('1', "build_x", WID_ROT_ROAD_X),
961 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
962 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
963 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
964 Hotkey('5', "depot", WID_ROT_DEPOT),
965 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
966 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
967 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
968 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
969 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
970 Hotkey('R', "remove", WID_ROT_REMOVE),
971 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
974 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_tramtype", to_underlying(SpecialListHotkeys::FirstItem)),
975 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_tramtype", to_underlying(SpecialListHotkeys::LastItem)),
976 }, TramToolbarGlobalHotkeys};
977};
978
979static constexpr std::initializer_list<NWidgetPart> _nested_build_road_widgets = {
984 EndContainer(),
987 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
989 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
991 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
993 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
995 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
997 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT),
999 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
1001 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
1002
1004
1006 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1008 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1010 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1012 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1014 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1015 EndContainer(),
1016};
1017
1020 WindowPosition::Manual, "toolbar_road", 0, 0,
1021 WindowClass::BuildToolbar, WindowClass::None,
1023 _nested_build_road_widgets,
1024 &BuildRoadToolbarWindow::road_hotkeys
1025);
1026
1027static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_widgets = {
1032 EndContainer(),
1035 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1037 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1039 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1041 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1043 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
1045 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT),
1047 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
1049 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
1050
1052
1054 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1056 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1058 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1060 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1061 EndContainer(),
1062};
1063
1066 WindowPosition::Manual, "toolbar_tramway", 0, 0,
1067 WindowClass::BuildToolbar, WindowClass::None,
1069 _nested_build_tramway_widgets,
1070 &BuildRoadToolbarWindow::tram_hotkeys
1071);
1072
1082{
1083 if (!Company::IsValidID(_local_company)) return nullptr;
1084 if (!ValParamRoadType(roadtype)) return nullptr;
1085
1086 if (GetRoadTramType(roadtype) == GetRoadTramType(_cur_roadtype)) {
1087 Window *w = BringWindowToFrontById(WindowClass::BuildToolbar, TransportType::Road);
1088
1089 if (w != nullptr) {
1090 _cur_roadtype = roadtype;
1091 w->OnInvalidateData();
1092 return w;
1093 }
1094 }
1095
1096 _cur_roadtype = roadtype;
1097 CloseWindowByClass(WindowClass::BuildToolbar);
1099}
1100
1101static constexpr std::initializer_list<NWidgetPart> _nested_build_road_scen_widgets = {
1106 EndContainer(),
1109 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1111 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1113 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
1115 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1116
1118
1120 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1122 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1124 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1126 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1128 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1129 EndContainer(),
1130};
1131
1134 WindowPosition::Automatic, "toolbar_road_scen", 0, 0,
1135 WindowClass::ScenarioBuildToolbar, WindowClass::None,
1137 _nested_build_road_scen_widgets,
1138 &BuildRoadToolbarWindow::road_hotkeys
1139);
1140
1141static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_scen_widgets = {
1146 EndContainer(),
1149 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1151 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1153 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1155 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1156
1158
1160 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1162 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1164 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1166 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1167 EndContainer(),
1168};
1169
1172 WindowPosition::Automatic, "toolbar_tram_scen", 0, 0,
1173 WindowClass::ScenarioBuildToolbar, WindowClass::None,
1175 _nested_build_tramway_scen_widgets,
1176 &BuildRoadToolbarWindow::tram_hotkeys
1177);
1178
1185{
1186 CloseWindowById(WindowClass::ScenarioBuildToolbar, TransportType::Road);
1187 _cur_roadtype = roadtype;
1188
1190}
1191
1192struct BuildRoadDepotWindow : public PickerWindowBase {
1193 BuildRoadDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
1194 {
1195 this->CreateNestedTree();
1196
1197 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1198 if (RoadTypeIsTram(_cur_roadtype)) {
1199 this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->SetString(STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION);
1200 for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) {
1201 this->GetWidget<NWidgetCore>(i)->SetToolTip(STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP);
1202 }
1203 }
1204
1206 }
1207
1208 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1209 {
1210 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1211
1212 size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal();
1213 size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical();
1214 }
1215
1216 void DrawWidget(const Rect &r, WidgetID widget) const override
1217 {
1218 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1219
1220 DrawPixelInfo tmp_dpi;
1221 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1222 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1223 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1224 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1225 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1226 DrawRoadDepotSprite(x, y, static_cast<DiagDirection>(widget - WID_BROD_DEPOT_NE + to_underlying(DiagDirection::NE)), _cur_roadtype);
1227 }
1228 }
1229
1230 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1231 {
1232 switch (widget) {
1233 case WID_BROD_DEPOT_NW:
1234 case WID_BROD_DEPOT_NE:
1235 case WID_BROD_DEPOT_SW:
1236 case WID_BROD_DEPOT_SE:
1237 this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1238 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1239 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1240 SndClickBeep();
1241 this->SetDirty();
1242 break;
1243
1244 default:
1245 break;
1246 }
1247 }
1248};
1249
1250static constexpr std::initializer_list<NWidgetPart> _nested_build_road_depot_widgets = {
1253 NWidget(WWT_CAPTION, Colours::DarkGreen, WID_BROD_CAPTION), SetStringTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1254 EndContainer(),
1258 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_NW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1259 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_SW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1260 EndContainer(),
1262 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_NE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1263 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_SE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1264 EndContainer(),
1265 EndContainer(),
1266 EndContainer(),
1267};
1268
1271 WindowPosition::Automatic, {}, 0, 0,
1272 WindowClass::BuildDepot, WindowClass::BuildToolbar,
1274 _nested_build_road_depot_widgets
1275);
1276
1277static void ShowRoadDepotPicker(Window *parent)
1278{
1280}
1281
1282template <RoadStopType roadstoptype>
1283class RoadStopPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1284public:
1285 RoadStopPickerCallbacks(const std::string &ini_group) : PickerCallbacksNewGRFClass<RoadStopClass>(ini_group) {}
1286
1288
1289 StringID GetClassTooltip() const override;
1290 StringID GetTypeTooltip() const override;
1292
1293 bool IsActive() const override
1294 {
1295 for (const auto &cls : RoadStopClass::Classes()) {
1296 if (IsWaypointClass(cls)) continue;
1297 for (const auto *spec : cls.Specs()) {
1298 if (spec == nullptr) continue;
1299 if (roadstoptype == RoadStopType::Truck && spec->stop_type != ROADSTOPTYPE_FREIGHT && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1300 if (roadstoptype == RoadStopType::Bus && spec->stop_type != ROADSTOPTYPE_PASSENGER && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1301 return true;
1302 }
1303 }
1304 return false;
1305 }
1306
1307 static bool IsClassChoice(const RoadStopClass &cls)
1308 {
1309 return !IsWaypointClass(cls) && GetIfClassHasNewStopsByType(&cls, roadstoptype, _cur_roadtype);
1310 }
1311
1312 bool HasClassChoice() const override
1313 {
1314 return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
1315 }
1316
1317 int GetSelectedClass() const override { return _roadstop_gui.sel_class.base(); }
1318 void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); }
1319
1320 StringID GetClassName(int id) const override
1321 {
1322 const auto *rsc = this->GetClass(id);
1323 if (!IsClassChoice(*rsc)) return INVALID_STRING_ID;
1324 return rsc->name;
1325 }
1326
1327 int GetSelectedType() const override { return _roadstop_gui.sel_type; }
1328 void SetSelectedType(int id) const override { _roadstop_gui.sel_type = id; }
1329
1330 StringID GetTypeName(int cls_id, int id) const override
1331 {
1332 const auto *spec = this->GetSpec(cls_id, id);
1333 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return INVALID_STRING_ID;
1334 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
1335 }
1336
1337 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1338 {
1339 const auto *spec = this->GetSpec(cls_id, id);
1340 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return {};
1341 if (spec == nullptr) return {};
1342 return spec->badges;
1343 }
1344
1345 bool IsTypeAvailable(int cls_id, int id) const override
1346 {
1347 const auto *spec = this->GetSpec(cls_id, id);
1349 }
1350
1351 void DrawType(int x, int y, int cls_id, int id) const override
1352 {
1353 const auto *spec = this->GetSpec(cls_id, id);
1354 if (spec == nullptr) {
1355 StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, to_underlying(_roadstop_gui.orientation));
1356 } else {
1357 DiagDirection orientation = _roadstop_gui.orientation;
1358 if (orientation < DiagDirection::End && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DiagDirection::End;
1359 DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, to_underlying(orientation));
1360 }
1361 }
1362
1363 void FillUsedItems(std::set<PickerItem> &items) override
1364 {
1365 for (const Station *st : Station::Iterate()) {
1366 if (st->owner != _local_company) continue;
1367 if (roadstoptype == RoadStopType::Truck && !st->facilities.Test(StationFacility::TruckStop)) continue;
1368 if (roadstoptype == RoadStopType::Bus && !st->facilities.Test(StationFacility::BusStop)) continue;
1369 items.insert({GrfID{}, 0, ROADSTOP_CLASS_DFLT.base(), 0}); // We would need to scan the map to find out if default is used.
1370 for (const auto &sm : st->roadstop_speclist) {
1371 if (sm.spec == nullptr) continue;
1372 if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1373 if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1374 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1375 }
1376 }
1377 }
1378};
1379
1380template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP; }
1381template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP; }
1382template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_BUS_COLLECTION_TOOLTIP; }
1383
1384template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP; }
1385template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP; }
1386template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_COLLECTION_TOOLTIP; }
1387
1388static RoadStopPickerCallbacks<RoadStopType::Bus> _bus_callback_instance("fav_passenger_roadstops");
1389static RoadStopPickerCallbacks<RoadStopType::Truck> _truck_callback_instance("fav_freight_roadstops");
1390
1391static PickerCallbacks &GetRoadStopPickerCallbacks(RoadStopType rs)
1392{
1393 return rs == RoadStopType::Bus ? static_cast<PickerCallbacks &>(_bus_callback_instance) : static_cast<PickerCallbacks &>(_truck_callback_instance);
1394}
1395
1396struct BuildRoadStationWindow : public PickerWindow {
1397private:
1399
1400 void CheckOrientationValid()
1401 {
1402 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1403
1404 /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */
1405 if (RoadTypeIsRoad(_cur_roadtype)) {
1406 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1407 this->GetWidget<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0);
1408 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1409 }
1410
1411 if (_roadstop_gui.orientation >= DiagDirection::End) return;
1412
1413 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) {
1414 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1415 _roadstop_gui.orientation = DiagDirection::End;
1416 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1417 this->SetDirty();
1418 CloseWindowById(WindowClass::JoinStation, 0);
1419 }
1420 }
1421
1422public:
1423 BuildRoadStationWindow(WindowDesc &desc, Window *parent, RoadStopType rs) : PickerWindow(desc, parent, TransportType::Road, GetRoadStopPickerCallbacks(rs))
1424 {
1425 this->coverage_height = 2 * GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
1426
1427 /* Trams don't have non-drivethrough stations */
1428 if (RoadTypeIsTram(_cur_roadtype) && _roadstop_gui.orientation < DiagDirection::End) {
1429 _roadstop_gui.orientation = DiagDirection::End;
1430 }
1431 this->ConstructWindow();
1432
1433 const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1434 this->GetWidget<NWidgetCore>(WID_BROS_CAPTION)->SetString(rti->strings.picker_title[rs]);
1435
1436 for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1437 this->GetWidget<NWidgetCore>(i)->SetToolTip(rti->strings.picker_tooltip[rs]);
1438 }
1439
1440 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1442
1443 this->window_class = (rs == RoadStopType::Bus) ? WindowClass::BuildBusStation : WindowClass::BuildTruckStation;
1444 }
1445
1446 void Close([[maybe_unused]] int data = 0) override
1447 {
1448 CloseWindowById(WindowClass::JoinStation, 0);
1449 this->PickerWindow::Close();
1450 }
1451
1452 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1453 {
1454 this->PickerWindow::OnInvalidateData(data, gui_scope);
1455
1456 if (gui_scope) {
1457 this->CheckOrientationValid();
1458 }
1459 }
1460
1461 void OnPaint() override
1462 {
1463 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1464
1465 this->DrawWidgets();
1466
1467 int rad = _settings_game.station.modified_catchment ? ((this->window_class == WindowClass::BuildBusStation) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
1468 if (_settings_client.gui.station_show_coverage) {
1469 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1470 } else {
1471 SetTileSelectSize(1, 1);
1472 }
1473
1474 if (this->IsShaded()) return;
1475
1476 /* 'Accepts' and 'Supplies' texts. */
1477 StationCoverageType sct = (this->window_class == WindowClass::BuildBusStation) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
1478 Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
1479 const int bottom = r.bottom;
1480 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1481 if (spec != nullptr) r.top = DrawBadgeNameList(r, spec->badges, GrfSpecFeature::RoadStops);
1482 r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
1483 r.top = DrawStationCoverageAreaText(r, sct, rad, true);
1484 /* Resize background if the window is too small.
1485 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1486 * (This is the case, if making the window bigger moves the mouse into the window.) */
1487 if (r.top > bottom) {
1488 this->coverage_height += r.top - bottom;
1489 this->ReInit();
1490 }
1491 }
1492
1493 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1494 {
1495 switch (widget) {
1500 case WID_BROS_STATION_X:
1501 case WID_BROS_STATION_Y:
1502 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
1503 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
1504 break;
1505
1507 size.height = this->coverage_height;
1508 break;
1509
1510 default:
1511 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1512 break;
1513 }
1514 }
1515
1522 {
1523 switch (window_class) {
1524 case WindowClass::BuildBusStation: return StationType::Bus;
1525 case WindowClass::BuildTruckStation: return StationType::Truck;
1526 default: NOT_REACHED();
1527 }
1528 }
1529
1530 void DrawWidget(const Rect &r, WidgetID widget) const override
1531 {
1532 switch (widget) {
1537 case WID_BROS_STATION_X:
1538 case WID_BROS_STATION_Y: {
1540 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1541 DrawPixelInfo tmp_dpi;
1542 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1543 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1544 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1547 if (spec == nullptr) {
1548 StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1549 } else {
1550 DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
1551 }
1552 }
1553 break;
1554 }
1555
1556 default:
1557 this->PickerWindow::DrawWidget(r, widget);
1558 break;
1559 }
1560 }
1561
1562 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1563 {
1564 switch (widget) {
1569 case WID_BROS_STATION_X:
1570 case WID_BROS_STATION_Y:
1571 if (widget < WID_BROS_STATION_X) {
1572 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1573 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return;
1574 }
1575 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1576 _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1577 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1578 SndClickBeep();
1579 this->SetDirty();
1580 CloseWindowById(WindowClass::JoinStation, 0);
1581 break;
1582
1583 case WID_BROS_LT_OFF:
1584 case WID_BROS_LT_ON:
1585 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1586 _settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
1587 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1588 SndClickBeep();
1589 this->SetDirty();
1590 SetViewportCatchmentStation(nullptr, true);
1591 break;
1592
1593 default:
1594 this->PickerWindow::OnClick(pt, widget, click_count);
1595 break;
1596 }
1597 }
1598
1599 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1600 {
1602 }
1603
1604 static inline HotkeyList road_hotkeys{"buildroadstop", {
1605 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1606 }};
1607
1608 static inline HotkeyList tram_hotkeys{"buildtramstop", {
1609 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1610 }};
1611};
1612
1614static constexpr std::initializer_list<NWidgetPart> _nested_road_station_picker_widgets = {
1620 EndContainer(),
1627 /* 6-orientation plane. */
1633 EndContainer(),
1635 EndContainer(),
1640 EndContainer(),
1642 EndContainer(),
1643 EndContainer(),
1644 /* 2-orientation plane. */
1649 EndContainer(),
1650 EndContainer(),
1651 EndContainer(),
1652 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1655 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1657 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1658 EndContainer(),
1660 EndContainer(),
1661 EndContainer(),
1662 EndContainer(),
1664 EndContainer(),
1665};
1666
1669 WindowPosition::Automatic, "build_station_road", 0, 0,
1670 WindowClass::BuildBusStation, WindowClass::BuildToolbar,
1673 &BuildRoadStationWindow::road_hotkeys
1674);
1675
1677static constexpr std::initializer_list<NWidgetPart> _nested_tram_station_picker_widgets = {
1683 EndContainer(),
1692 EndContainer(),
1693 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1696 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1698 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1699 EndContainer(),
1701 EndContainer(),
1702 EndContainer(),
1703 EndContainer(),
1705 EndContainer(),
1706};
1707
1710 WindowPosition::Automatic, "build_station_tram", 0, 0,
1711 WindowClass::BuildBusStation, WindowClass::BuildToolbar,
1714 &BuildRoadStationWindow::tram_hotkeys
1715);
1716
1717static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1718{
1719 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? _road_station_picker_desc : _tram_station_picker_desc, parent, rs);
1720}
1721
1722class RoadWaypointPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1723public:
1724 RoadWaypointPickerCallbacks() : PickerCallbacksNewGRFClass<RoadStopClass>("fav_road_waypoints") {}
1725
1727
1728 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1729 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1730 StringID GetCollectionTooltip() const override { return STR_PICKER_WAYPOINT_COLLECTION_TOOLTIP; }
1731
1732 bool IsActive() const override
1733 {
1734 for (const auto &cls : RoadStopClass::Classes()) {
1735 if (!IsWaypointClass(cls)) continue;
1736 for (const auto *spec : cls.Specs()) {
1737 if (spec != nullptr) return true;
1738 }
1739 }
1740 return false;
1741 }
1742
1743 bool HasClassChoice() const override
1744 {
1745 return std::ranges::count_if(RoadStopClass::Classes(), [](const auto &cls) { return IsWaypointClass(cls); }) > 1;
1746 }
1747
1748 void Close(int) override { ResetObjectToPlace(); }
1749 int GetSelectedClass() const override { return _waypoint_gui.sel_class.base(); }
1750 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1751
1752 StringID GetClassName(int id) const override
1753 {
1754 const auto *sc = GetClass(id);
1755 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1756 return sc->name;
1757 }
1758
1759 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1760 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1761
1762 StringID GetTypeName(int cls_id, int id) const override
1763 {
1764 const auto *spec = this->GetSpec(cls_id, id);
1765 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1766 }
1767
1768 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1769 {
1770 const auto *spec = this->GetSpec(cls_id, id);
1771 if (spec == nullptr) return {};
1772 return spec->badges;
1773 }
1774
1775 bool IsTypeAvailable(int cls_id, int id) const override
1776 {
1777 return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
1778 }
1779
1780 void DrawType(int x, int y, int cls_id, int id) const override
1781 {
1782 const auto *spec = this->GetSpec(cls_id, id);
1783 if (spec == nullptr) {
1784 StationPickerDrawSprite(x, y, StationType::RoadWaypoint, INVALID_RAILTYPE, _cur_roadtype, RSV_DRIVE_THROUGH_X);
1785 } else {
1787 }
1788 }
1789
1790 void FillUsedItems(std::set<PickerItem> &items) override
1791 {
1792 for (const Waypoint *wp : Waypoint::Iterate()) {
1793 if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1794 items.insert({GrfID{}, 0, ROADSTOP_CLASS_WAYP.base(), 0}); // We would need to scan the map to find out if default is used.
1795 for (const auto &sm : wp->roadstop_speclist) {
1796 if (sm.spec == nullptr) continue;
1797 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1798 }
1799 }
1800 }
1801
1802 static RoadWaypointPickerCallbacks instance;
1803};
1804/* static */ RoadWaypointPickerCallbacks RoadWaypointPickerCallbacks::instance;
1805
1806struct BuildRoadWaypointWindow : public PickerWindow {
1807 BuildRoadWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TransportType::Road, RoadWaypointPickerCallbacks::instance)
1808 {
1809 this->ConstructWindow();
1810 }
1811
1812 static inline HotkeyList hotkeys{"buildroadwaypoint", {
1813 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1814 }};
1815};
1816
1830
1833 WindowPosition::Automatic, "build_road_waypoint", 0, 0,
1834 WindowClass::BuildWaypoint, WindowClass::BuildToolbar,
1837 &BuildRoadWaypointWindow::hotkeys
1838);
1839
1840static void ShowBuildRoadWaypointPicker(Window *parent)
1841{
1842 if (!RoadWaypointPickerCallbacks::instance.IsActive()) return;
1844}
1845
1846void InitializeRoadGui()
1847{
1848 _road_depot_orientation = DiagDirection::NW;
1849 _roadstop_gui.orientation = DiagDirection::NW;
1851 _waypoint_gui.sel_type = 0;
1852}
1853
1854DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1855{
1856 RoadTypes used_roadtypes;
1857 RoadTypes avail_roadtypes;
1858
1860
1861 /* Find the used roadtypes. */
1862 if (for_replacement) {
1863 avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1864 used_roadtypes = GetRoadTypes(false);
1865 } else {
1866 avail_roadtypes = c->avail_roadtypes;
1867 used_roadtypes = GetRoadTypes(true);
1868 }
1869
1870 /* Filter listed road types */
1873
1874 DropDownList list;
1875
1876 if (all_option) {
1877 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
1878 }
1879
1880 Dimension d = { 0, 0 };
1881 /* Get largest icon size, to ensure text is aligned on each menu item. */
1882 if (!for_replacement) {
1883 used_roadtypes.Reset(_roadtypes_hidden_mask);
1884 for (const auto &rt : _sorted_roadtypes) {
1885 if (!used_roadtypes.Test(rt)) continue;
1886 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1888 }
1889 }
1890
1891 /* Shared list so that each item can take ownership. */
1892 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GrfSpecFeature::RoadTypes);
1893
1894 for (const auto &rt : _sorted_roadtypes) {
1895 /* If it's not used ever, don't show it to the user. */
1896 if (!used_roadtypes.Test(rt)) continue;
1897
1898 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1899
1900 if (for_replacement) {
1901 list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt)));
1902 } else {
1903 std::string str = rti->max_speed > 0
1904 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1905 : GetString(rti->strings.menu_text);
1906 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1907 }
1908 }
1909
1910 if (list.empty()) {
1911 /* Empty dropdowns are not allowed */
1912 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1913 }
1914
1915 return list;
1916}
1917
1918DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1919{
1920 RoadTypes avail_roadtypes = GetRoadTypes(false);
1921 avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, TimerGameCalendar::date);
1922 RoadTypes used_roadtypes = GetRoadTypes(true);
1923
1924 /* Filter listed road types */
1925 used_roadtypes.Reset(_roadtypes_hidden_mask);
1928
1929 DropDownList list;
1930
1931 /* If it's not used ever, don't show it to the user. */
1932 Dimension d = { 0, 0 };
1933 for (const auto &rt : _sorted_roadtypes) {
1934 if (!used_roadtypes.Test(rt)) continue;
1935 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1937 }
1938
1939 /* Shared list so that each item can take ownership. */
1940 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GrfSpecFeature::RoadTypes);
1941
1942 for (const auto &rt : _sorted_roadtypes) {
1943 if (!used_roadtypes.Test(rt)) continue;
1944
1945 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1946
1947 std::string str = rti->max_speed > 0
1948 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1949 : GetString(rti->strings.menu_text);
1950 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1951 }
1952
1953 if (list.empty()) {
1954 /* Empty dropdowns are not allowed */
1955 list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
1956 }
1957
1958 return list;
1959}
1960
1967{
1968 const auto find_available = [rtt]<typename It>(It begin, It end) {
1969 const RoadTypes mask = GetMaskForRoadTramType(rtt);
1970 auto it = std::find_if(begin, end, [&](RoadType r) {
1971 return HasRoadTypeAvail(_local_company, r) && mask.Test(r);
1972 });
1973 return it != end ? *it : ROADTYPE_BEGIN;
1974 };
1975
1976 switch (_settings_client.gui.default_rail_road_type) {
1979 std::array<uint, ROADTYPE_END> count{};
1980 for (RoadType rt : GetMaskForRoadTramType(rtt)) {
1981 count[rt] = c->infrastructure.road[rt];
1982 }
1983 auto best = static_cast<RoadType>(std::distance(std::begin(count), std::ranges::max_element(count)));
1984 if (c->infrastructure.road[best] > 0) return best;
1985
1986 /* No tile of this kind has been built yet, fall through to first available. */
1987 [[fallthrough]];
1988 }
1990 return find_available(_sorted_roadtypes.begin(), _sorted_roadtypes.end());
1992 return find_available(_sorted_roadtypes.rbegin(), _sorted_roadtypes.rend());
1993 default:
1994 NOT_REACHED();
1995 }
1996}
1997
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, RailType railtype, RoadType roadtype)
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)
RoadStopClass::index_type GetClassIndex(int cls_id) const
Definition picker_gui.h:242
const RoadStopClass * GetClass(int cls_id) const
Definition picker_gui.h:249
PickerCallbacksNewGRFClass(const std::string &ini_group)
Definition picker_gui.h:235
const RoadStopClass::spec_type * GetSpec(int cls_id, int id) const
Definition picker_gui.h:257
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:49
const std::string ini_group
Ini Group for saving favourites.
Definition picker_gui.h:214
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:339
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:340
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:341
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:342
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:373
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:81
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:83
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_build_station
Building a bus or truck station.
Definition road.h:89
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
CursorID autoroad
Cursor for autorail tool.
Definition road.h:72
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:142
StringID err_build_road
Building a normal piece of road.
Definition road.h:86
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:87
CursorID depot
Cursor for building a depot.
Definition road.h:73
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:71
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:118
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_title
Title for the station picker for bus or truck stations.
Definition road.h:93
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:80
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:62
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_tooltip
Tooltip for the station picker for bus or truck stations.
Definition road.h:94
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:74
SpriteID auto_road
button for the autoroad construction
Definition road.h:63
SpriteID convert_road
button for converting road types
Definition road.h:66
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:70
StringID err_convert_road
Converting a road type.
Definition road.h:91
StringID err_depot
Building a depot.
Definition road.h:88
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:61
SpriteID build_depot
button for building depots
Definition road.h:64
SpriteID build_tunnel
button for building a tunnel
Definition road.h:65
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_remove_station
Removing of a bus or truck station.
Definition road.h:90
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:95
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.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
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
Enumeration for the two axis X and Y.
@ X
The X axis.
@ Invalid
Flag for an invalid Axis.
@ Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ NW
Northwest.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
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:88
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:971
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:1737
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:1572
@ 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
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ DarkGreen
Dark green.
Definition gfx_type.h:292
@ White
White colour.
Definition gfx_type.h:330
@ 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 SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
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 SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
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.
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1688
static const CursorID SPR_CURSOR_BRIDGE
Definition sprites.h:1594
static const CursorID SPR_CURSOR_BUS_STATION
Definition sprites.h:1652
static const CursorID SPR_CURSOR_WAYPOINT
Definition sprites.h:1630
static const CursorID SPR_CURSOR_TRUCK_STATION
Definition sprites.h:1653
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:972
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
@ Road
Road livery schemes.
Definition livery.h:70
#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:78
@ RoadStops
Road stops feature.
Definition newgrf.h:99
@ RoadTypes
Road types feature.
Definition newgrf.h:97
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.
@ Any
Use first found.
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.
uint32_t GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:15
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
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:185
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
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:242
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:78
static WindowDesc _build_road_scen_desc(WindowPosition::Automatic, "toolbar_road_scen", 0, 0, WindowClass::ScenarioBuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_road_scen_widgets, &BuildRoadToolbarWindow::road_hotkeys)
Window definition for the road toolbar of the scenario editor.
static WindowDesc _build_tramway_scen_desc(WindowPosition::Automatic, "toolbar_tram_scen", 0, 0, WindowClass::ScenarioBuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_tramway_scen_widgets, &BuildRoadToolbarWindow::tram_hotkeys)
Window definition for the tram toolbar of the scenario editor.
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 WindowDesc _build_road_depot_desc(WindowPosition::Automatic, {}, 0, 0, WindowClass::BuildDepot, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_road_depot_widgets)
Window definition for the build road depot window.
static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
Check whether a road stop type can be built.
Definition road_gui.cpp:105
static RoadType GetDefaultRoadType(RoadTramType rtt)
Determine the default road type to use for a given RoadTramType.
static WindowDesc _build_road_waypoint_desc(WindowPosition::Automatic, "build_road_waypoint", 0, 0, WindowClass::BuildWaypoint, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_road_waypoint_widgets, &BuildRoadWaypointWindow::hotkeys)
Window definition for the build road waypoint window.
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition road_gui.cpp:128
static WindowDesc _road_station_picker_desc(WindowPosition::Automatic, "build_station_road", 0, 0, WindowClass::BuildBusStation, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_road_station_picker_widgets, &BuildRoadStationWindow::road_hotkeys)
Window definition for the build road station window.
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
void SetDefaultRoadGui()
Set the initial (default) road & tram type to use.
static WindowDesc _build_road_desc(WindowPosition::Manual, "toolbar_road", 0, 0, WindowClass::BuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_road_widgets, &BuildRoadToolbarWindow::road_hotkeys)
Window definition for the road toolbar.
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.
static WindowDesc _tram_station_picker_desc(WindowPosition::Automatic, "build_station_tram", 0, 0, WindowClass::BuildBusStation, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_tram_station_picker_widgets, &BuildRoadStationWindow::tram_hotkeys)
Window definition for the build tram station 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
static WindowDesc _build_tramway_desc(WindowPosition::Manual, "toolbar_tramway", 0, 0, WindowClass::BuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_tramway_widgets, &BuildRoadToolbarWindow::tram_hotkeys)
Window definition for the tram toolbar.
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
EnumBitSet< RoadTramType, uint8_t > RoadTramTypes
Bitset of RoadTramType elements.
Definition road_type.h:45
EnumBitSet< RoadType, uint64_t > RoadTypes
Bitset of RoadType elements.
Definition road_type.h:32
@ Northbound
All northbound traffic is disallowed.
Definition road_type.h:79
EnumBitSet< DisallowedRoadDirection, uint8_t > DisallowedRoadDirections
Bitset of DisallowedRoadDirection elements.
Definition road_type.h:84
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
@ ROADTYPE_BEGIN
Used for iterations.
Definition road_type.h:24
RoadTramType
The different types of road type.
Definition road_type.h:37
@ Tram
Tram type.
Definition road_type.h:39
@ Road
Road type.
Definition road_type.h:38
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
@ LastAvailable
Use the latest available to the player.
@ FirstAvailable
Use the first available to the player.
@ MostUsed
Use the most used by the company controlled by the player.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:254
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 SpriteID SPR_IMG_ROAD_TUNNEL
Definition sprites.h:1479
static const SpriteID SPR_IMG_DYNAMITE
Definition sprites.h:1230
static const SpriteID SPR_IMG_AUTOTRAM
Definition sprites.h:1484
static const SpriteID SPR_IMG_REMOVE
Definition sprites.h:1480
static const SpriteID SPR_IMG_TRAMWAY_Y_DIR
Definition sprites.h:1482
static const SpriteID SPR_IMG_AUTOROAD
Definition sprites.h:1474
static const SpriteID SPR_IMG_TRUCK_BAY
Definition sprites.h:1477
static const SpriteID SPR_IMG_ROAD_ONE_WAY
Definition sprites.h:1481
static const SpriteID SPR_IMG_BUS_STATION
Definition sprites.h:1476
static const SpriteID SPR_IMG_CONVERT_ROAD
Definition sprites.h:1486
static const SpriteID SPR_IMG_ROAD_X_DIR
Definition sprites.h:1473
static const SpriteID SPR_IMG_ROAD_DEPOT
Definition sprites.h:1475
static const SpriteID SPR_IMG_ROAD_Y_DIR
Definition sprites.h:1472
static const SpriteID SPR_IMG_BRIDGE
Definition sprites.h:1478
static const SpriteID SPR_IMG_TRAMWAY_X_DIR
Definition sprites.h:1483
static const SpriteID SPR_IMG_WAYPOINT
Definition sprites.h:1503
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.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition road_gui.cpp:732
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition road_gui.cpp:464
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition road_gui.cpp:896
HighLightStyle GetHighLightStyleForWidget(WidgetID widget)
Returns corresponding high light style for provided button.
Definition road_gui.cpp:561
CursorID GetCursorForWidget(WidgetID widget)
Returns corresponding cursor for provided button.
Definition road_gui.cpp:538
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:753
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:908
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:670
EventState ChangeRoadTypeOnHotkey(int hotkey)
Selects new RoadType based on SpecialHotkeys and order defined in _sorted_roadtypes.
Definition road_gui.cpp:639
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition road_gui.cpp:663
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:884
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition road_gui.cpp:436
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:797
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:579
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition road_gui.cpp:483
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition road_gui.cpp:890
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:792
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition road_gui.cpp:380
bool ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition road_gui.cpp:455
WidgetID last_started_action
Last started user action.
Definition road_gui.cpp:351
GUISettings gui
settings related to the GUI
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
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:172
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:984
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1109
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:798
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1814
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
Window * parent
Parent window.
Definition window_gui.h:328
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:469
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:562
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:510
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:391
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:515
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1804
WindowClass window_class
Window class.
Definition window_gui.h:301
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:491
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:410
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:536
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:441
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:562
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:849
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1838
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:989
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:460
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:576
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:381
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:450
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
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)
Prepare state for highlighting tiles while dragging 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.
TransportType
Available types of 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, RoadTramType subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1948
Functions related to vehicles.
@ 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:1201
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1214
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1285
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1707
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3193
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:155
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:146
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24
WindowClass
Window classes.
Definition window_type.h:61
@ BuildTruckStation
Build truck station; 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