OpenTTD Source 20260206-master-g4d4e37dbf1
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
103static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
104{
105 if (spec == nullptr) return true;
106 if (!IsRoadStopEverAvailable(spec, type)) return false;
107
108 if (!spec->callback_mask.Test(RoadStopCallbackMask::Avail)) return true;
109
110 uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, nullptr, INVALID_TILE, _cur_roadtype, type, 0);
111 if (cb_res == CALLBACK_FAILED) return true;
112
114}
115
116void CcPlaySound_CONSTRUCTION_OTHER(Commands, const CommandCost &result, TileIndex tile)
117{
118 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
119}
120
126static void PlaceRoad_Bridge(TileIndex tile, Window *w)
127{
128 if (IsBridgeTile(tile)) {
129 TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
130 Point pt = {0, 0};
131 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
132 } else {
134 }
135}
136
143void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
144{
145 if (result.Succeeded()) {
146 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
147 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
148
149 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
150 ConnectRoadToStructure(start_tile, start_direction);
151
152 TileIndex end_tile = GetOtherTunnelBridgeEnd(start_tile);
153 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
154 ConnectRoadToStructure(end_tile, end_direction);
155 } else {
157 }
158}
159
166{
167 tile += TileOffsByDiagDir(direction);
168 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
169 if (IsNormalRoadTile(tile)) {
170 if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) {
171 Command<Commands::BuildRoad>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, TownID::Invalid());
172 }
173 }
174}
175
176void CcRoadDepot(Commands, const CommandCost &result, TileIndex tile, RoadType, DiagDirection dir)
177{
178 if (result.Failed()) return;
179
180 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
181 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
182 ConnectRoadToStructure(tile, dir);
183}
184
197void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through,
198 DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
199{
200 if (result.Failed()) return;
201
202 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
203 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
204
205 bool connect_to_road = true;
206 if ((uint)spec_class < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) {
207 const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index);
208 if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false;
209 }
210
211 if (connect_to_road) {
212 TileArea roadstop_area(tile, width, length);
213 for (TileIndex cur_tile : roadstop_area) {
214 ConnectRoadToStructure(cur_tile, dir);
215 /* For a drive-through road stop build connecting road for other entrance. */
216 if (is_drive_through) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
217 }
218 }
219}
220
231static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
232{
233 TileArea ta(start_tile, end_tile);
234 DiagDirection ddir = _roadstop_gui.orientation;
235 bool drive_through = ddir >= DIAGDIR_END;
236 if (drive_through) ddir = static_cast<DiagDirection>(ddir - DIAGDIR_END); // Adjust picker result to actual direction.
237 RoadStopClassID spec_class = _roadstop_gui.sel_class;
238 uint16_t spec_index = _roadstop_gui.sel_type;
239
240 auto proc = [=](bool test, StationID to_join) -> bool {
241 if (test) {
242 return Command<Commands::BuildRoadStop>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildRoadStop>()), ta.tile, ta.w, ta.h, stop_type, drive_through,
243 ddir, rt, spec_class, spec_index, StationID::Invalid(), adjacent).Succeeded();
244 } else {
245 return Command<Commands::BuildRoadStop>::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through,
246 ddir, rt, spec_class, spec_index, to_join, adjacent);
247 }
248 };
249
251}
252
258{
261 return;
262 }
263
264 Axis axis = GetAxisForNewRoadWaypoint(tile);
265 if (IsValidAxis(axis)) {
266 /* Valid tile for waypoints */
268 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
269 } else {
270 /* Tile where we can't build road waypoints. This is always going to fail,
271 * but provides the user with a proper error message. */
272 Command<Commands::BuildRoadWaypoint>::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, AXIS_X, 1, 1, ROADSTOP_CLASS_WAYP, 0, StationID::Invalid(), false);
273 }
274}
275
281{
284 } else {
285 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
286 VpStartPlaceSizing(tile, (DiagDirToAxis(_roadstop_gui.orientation) == AXIS_X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
287 } else {
289 }
290 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
291 }
292}
293
299{
302 } else {
303 if (_roadstop_gui.orientation < DIAGDIR_END) { // Not a drive-through stop.
305 } else {
307 }
308 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
309 }
310}
311
312typedef void OnButtonClick(Window *w);
313
325
332{
333 if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
334
335 /* allow ctrl to switch remove mode only for these widgets */
336 for (WidgetID i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) {
337 if (w->IsWidgetLowered(i)) {
339 return true;
340 }
341 }
342
343 return false;
344}
345
347struct BuildRoadToolbarWindow : Window {
350
351 BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc), roadtype(_cur_roadtype)
352 {
353 this->CreateNestedTree();
354 this->FinishInitNested(window_number);
356
357 if (RoadTypeIsRoad(this->roadtype)) {
359 }
360
361 this->OnInvalidateData();
362
363 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
364 }
365
366 void Close([[maybe_unused]] int data = 0) override
367 {
368 if (_game_mode == GM_NORMAL && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true);
369 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
370 this->Window::Close();
371 }
372
378 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
379 {
380 if (!gui_scope) return;
381
382 if (!ValParamRoadType(this->roadtype)) {
383 /* Close toolbar if road type is not available. */
384 this->Close();
385 return;
386 }
387
388 RoadTramType rtt = GetRoadTramType(this->roadtype);
389
390 bool can_build = CanBuildVehicleInfrastructure(VEH_ROAD, rtt);
391 this->SetWidgetsDisabledState(!can_build,
396 if (!can_build) {
401 }
402
403 if (_game_mode != GM_EDITOR) {
404 if (!can_build) {
405 /* Show in the tooltip why this button is disabled. */
406 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
407 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
408 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
409 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
410 } else {
411 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT);
412 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT : STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT);
413 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION);
414 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RTT_ROAD ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION);
415 }
416 }
417 }
418
419 void OnInit() override
420 {
421 /* Configure the road toolbar for the roadtype. */
422 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
426 if (_game_mode != GM_EDITOR) {
428 }
431 }
432
438 {
439 this->roadtype = roadtype;
440 this->ReInit();
441 }
442
443 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
444 {
445 if (widget == WID_ROT_CAPTION) {
446 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
447 if (rti->max_speed > 0) {
448 return GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VEH_ROAD));
449 }
450 return GetString(rti->strings.toolbar_caption);
451
452 }
453
454 return this->Window::GetWidgetString(widget, stringid);
455 }
456
463 {
464 /* The remove and the one way button state is driven
465 * by the other buttons so they don't act on themselves.
466 * Both are only valid if they are able to apply as options. */
467 switch (clicked_widget) {
468 case WID_ROT_REMOVE:
469 if (RoadTypeIsRoad(this->roadtype)) {
472 }
473
474 break;
475
476 case WID_ROT_ONE_WAY:
479 break;
480
484 if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
485 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
486 break;
487
488 case WID_ROT_ROAD_X:
489 case WID_ROT_ROAD_Y:
490 case WID_ROT_AUTOROAD:
491 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
492 if (RoadTypeIsRoad(this->roadtype)) {
493 this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget));
494 }
495 break;
496
497 default:
498 /* When any other buttons than road/station, raise and
499 * disable the removal button */
502
503 if (RoadTypeIsRoad(this->roadtype)) {
506 }
507
508 break;
509 }
510 }
511
518 {
519 switch (widget) {
520 case WID_ROT_ROAD_X: return GetRoadTypeInfo(this->roadtype)->cursor.road_nwse;
521 case WID_ROT_ROAD_Y: return GetRoadTypeInfo(this->roadtype)->cursor.road_swne;
522 case WID_ROT_AUTOROAD: return GetRoadTypeInfo(this->roadtype)->cursor.autoroad;
524 case WID_ROT_DEPOT: return GetRoadTypeInfo(this->roadtype)->cursor.depot;
525 case WID_ROT_BUILD_WAYPOINT: return SPR_CURSOR_WAYPOINT;
526 case WID_ROT_BUS_STATION: return SPR_CURSOR_BUS_STATION;
527 case WID_ROT_TRUCK_STATION: return SPR_CURSOR_TRUCK_STATION;
528 case WID_ROT_BUILD_BRIDGE: return SPR_CURSOR_BRIDGE;
529 case WID_ROT_BUILD_TUNNEL: return GetRoadTypeInfo(this->roadtype)->cursor.tunnel;
530 case WID_ROT_CONVERT_ROAD: return GetRoadTypeInfo(this->roadtype)->cursor.convert_road;
531 default: NOT_REACHED();
532 }
533 }
534
541 {
542 switch (widget) {
543 case WID_ROT_ROAD_X: return HT_RECT;
544 case WID_ROT_ROAD_Y: return HT_RECT;
545 case WID_ROT_AUTOROAD: return HT_RECT;
546 case WID_ROT_DEMOLISH: return HT_RECT | HT_DIAGONAL;
547 case WID_ROT_DEPOT: return HT_RECT;
548 case WID_ROT_BUILD_WAYPOINT: return HT_RECT;
549 case WID_ROT_BUS_STATION: return HT_RECT;
550 case WID_ROT_TRUCK_STATION: return HT_RECT;
551 case WID_ROT_BUILD_BRIDGE: return HT_RECT;
552 case WID_ROT_BUILD_TUNNEL: return HT_SPECIAL;
554 default: NOT_REACHED();
555 }
556 }
557
558 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
559 {
560 bool started;
561 _remove_button_clicked = false;
562 _one_way_button_clicked = false;
563
564 if (widget != WID_ROT_ONE_WAY && widget != WID_ROT_REMOVE) {
565 started = HandlePlacePushButton(this, widget, this->GetCursorForWidget(widget), this->GetHighLightStyleForWidget(widget));
566 this->last_started_action = widget;
567 }
568
569 switch (widget) {
570 case WID_ROT_DEPOT:
571 if (started) {
572 ShowRoadDepotPicker(this);
573 }
574 break;
575
577 if (started) {
578 ShowBuildRoadWaypointPicker(this);
579 }
580 break;
581
583 if (started) {
584 ShowRVStationPicker(this, RoadStopType::Bus);
585 }
586 break;
587
589 if (started) {
590 ShowRVStationPicker(this, RoadStopType::Truck);
591 }
592 break;
593
594 case WID_ROT_ONE_WAY:
595 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
596 this->SetDirty();
598 SetSelectionRed(false);
599 break;
600
601 case WID_ROT_REMOVE:
602 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
603
606 SndClickBeep();
607 break;
608 }
609 this->UpdateOptionWidgetStatus(static_cast<RoadToolbarWidgets>(widget));
611 }
612
619 {
620 auto [index, step] = GetListIndexStep(SpecialListHotkeys(hotkey), _sorted_roadtypes, this->roadtype);
621
622 while (RoadTypeIsRoad(_sorted_roadtypes[index]) != RoadTypeIsRoad(this->roadtype) || !HasRoadTypeAvail(_local_company, _sorted_roadtypes[index])) {
623 index = (index + step) % _sorted_roadtypes.size();
624 }
625
626 _cur_roadtype = _sorted_roadtypes[index];
627 if (RoadTypeIsRoad(_cur_roadtype)) {
628 _last_built_roadtype = _cur_roadtype;
629 } else {
630 _last_built_tramtype = _cur_roadtype;
631 }
632 this->ModifyRoadType(_cur_roadtype);
633
634 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
636
637 return ES_HANDLED;
638 }
639
640 EventState OnHotkey(int hotkey) override
641 {
642 if (IsSpecialHotkey(hotkey)) return this->ChangeRoadTypeOnHotkey(hotkey);
643 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
644 return Window::OnHotkey(hotkey);
645 }
646
647 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
648 {
649 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
650 _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
651 switch (this->last_started_action) {
652 case WID_ROT_ROAD_X:
653 _place_road_dir = AXIS_X;
654 _place_road_start_half_x = _tile_fract_coords.x >= 8;
656 break;
657
658 case WID_ROT_ROAD_Y:
659 _place_road_dir = AXIS_Y;
660 _place_road_start_half_y = _tile_fract_coords.y >= 8;
662 break;
663
664 case WID_ROT_AUTOROAD:
665 _place_road_dir = INVALID_AXIS;
666 _place_road_start_half_x = _tile_fract_coords.x >= 8;
667 _place_road_start_half_y = _tile_fract_coords.y >= 8;
669 break;
670
671 case WID_ROT_DEMOLISH:
673 break;
674
675 case WID_ROT_DEPOT:
676 Command<Commands::BuildRoadDepot>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_depot, CcRoadDepot,
677 tile, _cur_roadtype, _road_depot_orientation);
678 break;
679
681 PlaceRoad_Waypoint(tile);
682 break;
683
686 break;
687
690 break;
691
693 PlaceRoad_Bridge(tile, this);
694 break;
695
697 Command<Commands::BuildTunnel>::Post(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE, CcBuildRoadTunnel,
698 tile, TRANSPORT_ROAD, _cur_roadtype);
699 break;
700
703 break;
704
705 default: NOT_REACHED();
706 }
707 }
708
729
730 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
731 {
732 /* Here we update the end tile flags
733 * of the road placement actions.
734 * At first we reset the end halfroad
735 * bits and if needed we set them again. */
736 switch (select_proc) {
738 _place_road_end_half = pt.x & 8;
739 break;
740
742 _place_road_end_half = pt.y & 8;
743 break;
744
746 /* For autoroad we need to update the
747 * direction of the road */
748 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
749 ( (_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) < 16) ||
750 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) > 16) ))) {
751 /* Set dir = X */
752 _place_road_dir = AXIS_X;
753 _place_road_end_half = pt.x & 8;
754 } else {
755 /* Set dir = Y */
756 _place_road_dir = AXIS_Y;
757 _place_road_end_half = pt.y & 8;
758 }
759
760 break;
761
762 default:
763 break;
764 }
765
766 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
767 }
768
769 Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
770 {
771 return AlignInitialConstructionToolbar(sm_width);
772 }
773
774 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
775 {
776 if (pt.x != -1) {
777 switch (select_proc) {
778 default: NOT_REACHED();
780 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
781 ShowBuildBridgeWindow(start_tile, end_tile, TRANSPORT_ROAD, _cur_roadtype);
782 break;
783
785 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
786 break;
787
790 case DDSP_PLACE_AUTOROAD: {
791 bool start_half = _place_road_dir == AXIS_Y ? _place_road_start_half_y : _place_road_start_half_x;
792
793 if (_remove_button_clicked) {
794 Command<Commands::RemoveRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_remove_road, CcPlaySound_CONSTRUCTION_OTHER,
795 end_tile, start_tile, _cur_roadtype, _place_road_dir, start_half, _place_road_end_half);
796 } else {
797 Command<Commands::BuildRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_build_road, CcPlaySound_CONSTRUCTION_OTHER,
798 end_tile, start_tile, _cur_roadtype, _place_road_dir, _one_way_button_clicked ? DRD_NORTHBOUND : DRD_NONE, start_half, _place_road_end_half, false);
799 }
800 break;
801 }
802
806 if (_remove_button_clicked) {
807 Command<Commands::RemoveFromRoadWaypoint>::Post(STR_ERROR_CAN_T_REMOVE_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile);
808 } else {
809 TileArea ta(start_tile, end_tile);
810 Axis axis = select_method == VPM_X_LIMITED ? AXIS_X : AXIS_Y;
811 bool adjacent = _ctrl_pressed;
812
813 auto proc = [=](bool test, StationID to_join) -> bool {
814 if (test) {
815 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();
816 } else {
817 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);
818 }
819 };
820
822 }
823 }
824 break;
825
828 if (this->IsWidgetLowered(WID_ROT_BUS_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Bus, _cur_roadtype)) {
829 if (_remove_button_clicked) {
830 TileArea ta(start_tile, end_tile);
832 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Bus, _ctrl_pressed);
833 } else {
835 PlaceRoadStop(start_tile, end_tile, RoadStopType::Bus, _ctrl_pressed, _cur_roadtype, str);
836 }
837 }
838 break;
839
842 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Truck, _cur_roadtype)) {
843 if (_remove_button_clicked) {
844 TileArea ta(start_tile, end_tile);
846 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Truck, _ctrl_pressed);
847 } else {
849 PlaceRoadStop(start_tile, end_tile, RoadStopType::Truck, _ctrl_pressed, _cur_roadtype, str);
850 }
851 }
852 break;
853
855 Command<Commands::ConvertRoad>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_convert_road, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile, _cur_roadtype, _ctrl_pressed);
856 break;
857 }
858 }
859 }
860
861 void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile) override
862 {
863 Command<Commands::BuildTunnel>::Do(DoCommandFlag::Auto, tile, TRANSPORT_ROAD, _cur_roadtype);
865 }
866
868 {
869 if (RoadToolbar_CtrlChanged(this)) return ES_HANDLED;
870 return ES_NOT_HANDLED;
871 }
872
873 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
874 {
875 if (_game_mode == GM_NORMAL && this->IsWidgetLowered(WID_ROT_BUILD_WAYPOINT)) CheckRedrawRoadWaypointCoverage(this);
876 }
877
886 {
887 Window *w = nullptr;
888 switch (_game_mode) {
889 case GM_NORMAL:
890 w = ShowBuildRoadToolbar(last_build);
891 break;
892
893 case GM_EDITOR:
894 if (!GetRoadTypes(true).Any(GetMaskForRoadTramType(rtt))) return ES_NOT_HANDLED;
895 w = ShowBuildRoadScenToolbar(last_build);
896 break;
897
898 default:
899 break;
900 }
901
902 if (w == nullptr) return ES_NOT_HANDLED;
903 return w->OnHotkey(hotkey);
904 }
905
906 static EventState RoadToolbarGlobalHotkeys(int hotkey)
907 {
909 }
910
911 static EventState TramToolbarGlobalHotkeys(int hotkey)
912 {
914 }
915
916 static inline HotkeyList road_hotkeys{"roadtoolbar", {
917 Hotkey('1', "build_x", WID_ROT_ROAD_X),
918 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
919 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
920 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
921 Hotkey('5', "depot", WID_ROT_DEPOT),
922 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
923 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
924 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
925 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
926 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
927 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
928 Hotkey('R', "remove", WID_ROT_REMOVE),
929 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
932 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_roadtype", to_underlying(SpecialListHotkeys::FirstItem)),
933 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_roadtype", to_underlying(SpecialListHotkeys::LastItem)),
934 }, RoadToolbarGlobalHotkeys};
935
936 static inline HotkeyList tram_hotkeys{"tramtoolbar", {
937 Hotkey('1', "build_x", WID_ROT_ROAD_X),
938 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
939 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
940 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
941 Hotkey('5', "depot", WID_ROT_DEPOT),
942 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
943 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
944 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
945 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
946 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
947 Hotkey('R', "remove", WID_ROT_REMOVE),
948 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
951 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_tramtype", to_underlying(SpecialListHotkeys::FirstItem)),
952 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_tramtype", to_underlying(SpecialListHotkeys::LastItem)),
953 }, TramToolbarGlobalHotkeys};
954};
955
956static constexpr std::initializer_list<NWidgetPart> _nested_build_road_widgets = {
958 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
959 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
960 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
961 EndContainer(),
963 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
964 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
965 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
966 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
967 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
968 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
969 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
970 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
971 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
972 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
973 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
974 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT),
975 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
976 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
977 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
978 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
979
980 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
981
982 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
983 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
984 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
985 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
986 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
987 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
988 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
989 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
990 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
991 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
992 EndContainer(),
993};
994
995static WindowDesc _build_road_desc(
996 WDP_MANUAL, "toolbar_road", 0, 0,
999 _nested_build_road_widgets,
1000 &BuildRoadToolbarWindow::road_hotkeys
1001);
1002
1003static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_widgets = {
1005 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1006 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1007 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1008 EndContainer(),
1010 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1011 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1012 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1013 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1014 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1015 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1016 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1017 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1018 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEPOT),
1019 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
1020 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_WAYPOINT),
1021 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT),
1022 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUS_STATION),
1023 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
1024 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_TRUCK_STATION),
1025 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
1026
1027 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1028
1029 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1030 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1031 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1032 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1033 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1034 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1035 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1036 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1037 EndContainer(),
1038};
1039
1040static WindowDesc _build_tramway_desc(
1041 WDP_MANUAL, "toolbar_tramway", 0, 0,
1044 _nested_build_tramway_widgets,
1045 &BuildRoadToolbarWindow::tram_hotkeys
1046);
1047
1056{
1057 if (!Company::IsValidID(_local_company)) return nullptr;
1058 if (!ValParamRoadType(roadtype)) return nullptr;
1059
1061 _cur_roadtype = roadtype;
1062
1063 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_desc : _build_tramway_desc, TRANSPORT_ROAD);
1064}
1065
1066static constexpr std::initializer_list<NWidgetPart> _nested_build_road_scen_widgets = {
1068 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1069 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1070 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1071 EndContainer(),
1073 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1074 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1075 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1076 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1077 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1078 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
1079 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1080 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1081
1082 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1083
1084 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ONE_WAY),
1085 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1086 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1087 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1088 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1089 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1090 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1091 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1092 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1093 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1094 EndContainer(),
1095};
1096
1097static WindowDesc _build_road_scen_desc(
1098 WDP_AUTO, "toolbar_road_scen", 0, 0,
1101 _nested_build_road_scen_widgets,
1102 &BuildRoadToolbarWindow::road_hotkeys
1103);
1104
1105static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_scen_widgets = {
1107 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1108 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_ROT_CAPTION), SetTextStyle(TC_WHITE),
1109 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1110 EndContainer(),
1112 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_X),
1113 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1114 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_ROAD_Y),
1115 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1116 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_AUTOROAD),
1117 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1118 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_DEMOLISH),
1119 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1120
1121 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 1), EndContainer(),
1122
1123 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_BRIDGE),
1124 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1125 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_BUILD_TUNNEL),
1126 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1127 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_REMOVE),
1128 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1129 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_ROT_CONVERT_ROAD),
1130 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1131 EndContainer(),
1132};
1133
1134static WindowDesc _build_tramway_scen_desc(
1135 WDP_AUTO, "toolbar_tram_scen", 0, 0,
1138 _nested_build_tramway_scen_widgets,
1139 &BuildRoadToolbarWindow::tram_hotkeys
1140);
1141
1147{
1149 _cur_roadtype = roadtype;
1150
1151 return AllocateWindowDescFront<BuildRoadToolbarWindow>(RoadTypeIsRoad(_cur_roadtype) ? _build_road_scen_desc : _build_tramway_scen_desc, TRANSPORT_ROAD);
1152}
1153
1154struct BuildRoadDepotWindow : public PickerWindowBase {
1155 BuildRoadDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
1156 {
1157 this->CreateNestedTree();
1158
1159 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1160 if (RoadTypeIsTram(_cur_roadtype)) {
1161 this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->SetString(STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION);
1162 for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) {
1163 this->GetWidget<NWidgetCore>(i)->SetToolTip(STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP);
1164 }
1165 }
1166
1168 }
1169
1170 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1171 {
1172 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1173
1174 size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal();
1175 size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical();
1176 }
1177
1178 void DrawWidget(const Rect &r, WidgetID widget) const override
1179 {
1180 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1181
1182 DrawPixelInfo tmp_dpi;
1183 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1184 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1185 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1186 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1187 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1188 DrawRoadDepotSprite(x, y, (DiagDirection)(widget - WID_BROD_DEPOT_NE + DIAGDIR_NE), _cur_roadtype);
1189 }
1190 }
1191
1192 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1193 {
1194 switch (widget) {
1195 case WID_BROD_DEPOT_NW:
1196 case WID_BROD_DEPOT_NE:
1197 case WID_BROD_DEPOT_SW:
1198 case WID_BROD_DEPOT_SE:
1199 this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1200 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1201 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1202 SndClickBeep();
1203 this->SetDirty();
1204 break;
1205
1206 default:
1207 break;
1208 }
1209 }
1210};
1211
1212static constexpr std::initializer_list<NWidgetPart> _nested_build_road_depot_widgets = {
1214 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1215 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROD_CAPTION), SetStringTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1216 EndContainer(),
1217 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1220 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1221 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1222 EndContainer(),
1224 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_NE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1225 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROD_DEPOT_SE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1226 EndContainer(),
1227 EndContainer(),
1228 EndContainer(),
1229};
1230
1231static WindowDesc _build_road_depot_desc(
1232 WDP_AUTO, {}, 0, 0,
1235 _nested_build_road_depot_widgets
1236);
1237
1238static void ShowRoadDepotPicker(Window *parent)
1239{
1240 new BuildRoadDepotWindow(_build_road_depot_desc, parent);
1241}
1242
1243template <RoadStopType roadstoptype>
1244class RoadStopPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1245public:
1246 RoadStopPickerCallbacks(const std::string &ini_group) : PickerCallbacksNewGRFClass<RoadStopClass>(ini_group) {}
1247
1248 GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
1249
1250 StringID GetClassTooltip() const override;
1251 StringID GetTypeTooltip() const override;
1253
1254 bool IsActive() const override
1255 {
1256 for (const auto &cls : RoadStopClass::Classes()) {
1257 if (IsWaypointClass(cls)) continue;
1258 for (const auto *spec : cls.Specs()) {
1259 if (spec == nullptr) continue;
1260 if (roadstoptype == RoadStopType::Truck && spec->stop_type != ROADSTOPTYPE_FREIGHT && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1261 if (roadstoptype == RoadStopType::Bus && spec->stop_type != ROADSTOPTYPE_PASSENGER && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1262 return true;
1263 }
1264 }
1265 return false;
1266 }
1267
1268 static bool IsClassChoice(const RoadStopClass &cls)
1269 {
1270 return !IsWaypointClass(cls) && GetIfClassHasNewStopsByType(&cls, roadstoptype, _cur_roadtype);
1271 }
1272
1273 bool HasClassChoice() const override
1274 {
1275 return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
1276 }
1277
1278 int GetSelectedClass() const override { return _roadstop_gui.sel_class; }
1279 void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); }
1280
1281 StringID GetClassName(int id) const override
1282 {
1283 const auto *rsc = this->GetClass(id);
1284 if (!IsClassChoice(*rsc)) return INVALID_STRING_ID;
1285 return rsc->name;
1286 }
1287
1288 int GetSelectedType() const override { return _roadstop_gui.sel_type; }
1289 void SetSelectedType(int id) const override { _roadstop_gui.sel_type = id; }
1290
1291 StringID GetTypeName(int cls_id, int id) const override
1292 {
1293 const auto *spec = this->GetSpec(cls_id, id);
1294 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return INVALID_STRING_ID;
1295 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
1296 }
1297
1298 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1299 {
1300 const auto *spec = this->GetSpec(cls_id, id);
1301 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return {};
1302 if (spec == nullptr) return {};
1303 return spec->badges;
1304 }
1305
1306 bool IsTypeAvailable(int cls_id, int id) const override
1307 {
1308 const auto *spec = this->GetSpec(cls_id, id);
1310 }
1311
1312 void DrawType(int x, int y, int cls_id, int id) const override
1313 {
1314 const auto *spec = this->GetSpec(cls_id, id);
1315 if (spec == nullptr) {
1316 StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, _roadstop_gui.orientation);
1317 } else {
1318 DiagDirection orientation = _roadstop_gui.orientation;
1319 if (orientation < DIAGDIR_END && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DIAGDIR_END;
1320 DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, (uint8_t)orientation);
1321 }
1322 }
1323
1324 void FillUsedItems(std::set<PickerItem> &items) override
1325 {
1326 for (const Station *st : Station::Iterate()) {
1327 if (st->owner != _local_company) continue;
1328 if (roadstoptype == RoadStopType::Truck && !st->facilities.Test(StationFacility::TruckStop)) continue;
1329 if (roadstoptype == RoadStopType::Bus && !st->facilities.Test(StationFacility::BusStop)) continue;
1330 items.insert({0, 0, ROADSTOP_CLASS_DFLT, 0}); // We would need to scan the map to find out if default is used.
1331 for (const auto &sm : st->roadstop_speclist) {
1332 if (sm.spec == nullptr) continue;
1333 if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1334 if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1335 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1336 }
1337 }
1338 }
1339};
1340
1341template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP; }
1342template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP; }
1343template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_BUS_COLLECTION_TOOLTIP; }
1344
1345template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP; }
1346template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP; }
1347template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_COLLECTION_TOOLTIP; }
1348
1349static RoadStopPickerCallbacks<RoadStopType::Bus> _bus_callback_instance("fav_passenger_roadstops");
1350static RoadStopPickerCallbacks<RoadStopType::Truck> _truck_callback_instance("fav_freight_roadstops");
1351
1352static PickerCallbacks &GetRoadStopPickerCallbacks(RoadStopType rs)
1353{
1354 return rs == RoadStopType::Bus ? static_cast<PickerCallbacks &>(_bus_callback_instance) : static_cast<PickerCallbacks &>(_truck_callback_instance);
1355}
1356
1357struct BuildRoadStationWindow : public PickerWindow {
1358private:
1360
1361 void CheckOrientationValid()
1362 {
1363 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1364
1365 /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */
1366 if (RoadTypeIsRoad(_cur_roadtype)) {
1367 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1368 this->GetWidget<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0);
1369 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1370 }
1371
1372 if (_roadstop_gui.orientation >= DIAGDIR_END) return;
1373
1374 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) {
1375 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1376 _roadstop_gui.orientation = DIAGDIR_END;
1377 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1378 this->SetDirty();
1380 }
1381 }
1382
1383public:
1384 BuildRoadStationWindow(WindowDesc &desc, Window *parent, RoadStopType rs) : PickerWindow(desc, parent, TRANSPORT_ROAD, GetRoadStopPickerCallbacks(rs))
1385 {
1386 this->coverage_height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
1387
1388 /* Trams don't have non-drivethrough stations */
1389 if (RoadTypeIsTram(_cur_roadtype) && _roadstop_gui.orientation < DIAGDIR_END) {
1390 _roadstop_gui.orientation = DIAGDIR_END;
1391 }
1392 this->ConstructWindow();
1393
1394 const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1396
1397 for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1398 this->GetWidget<NWidgetCore>(i)->SetToolTip(rti->strings.picker_tooltip[to_underlying(rs)]);
1399 }
1400
1401 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1403
1405 }
1406
1407 void Close([[maybe_unused]] int data = 0) override
1408 {
1410 this->PickerWindow::Close();
1411 }
1412
1413 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1414 {
1415 this->PickerWindow::OnInvalidateData(data, gui_scope);
1416
1417 if (gui_scope) {
1418 this->CheckOrientationValid();
1419 }
1420 }
1421
1422 void OnPaint() override
1423 {
1424 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1425
1426 this->DrawWidgets();
1427
1428 int rad = _settings_game.station.modified_catchment ? ((this->window_class == WC_BUS_STATION) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
1429 if (_settings_client.gui.station_show_coverage) {
1430 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1431 } else {
1432 SetTileSelectSize(1, 1);
1433 }
1434
1435 if (this->IsShaded()) return;
1436
1437 /* 'Accepts' and 'Supplies' texts. */
1439 Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
1440 const int bottom = r.bottom;
1441 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1442 if (spec != nullptr) r.top = DrawBadgeNameList(r, spec->badges, GSF_ROADSTOPS);
1443 r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
1444 r.top = DrawStationCoverageAreaText(r, sct, rad, true);
1445 /* Resize background if the window is too small.
1446 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1447 * (This is the case, if making the window bigger moves the mouse into the window.) */
1448 if (r.top > bottom) {
1449 this->coverage_height += r.top - bottom;
1450 this->ReInit();
1451 }
1452 }
1453
1454 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1455 {
1456 switch (widget) {
1461 case WID_BROS_STATION_X:
1462 case WID_BROS_STATION_Y:
1463 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
1464 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
1465 break;
1466
1468 size.height = this->coverage_height;
1469 break;
1470
1471 default:
1472 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1473 break;
1474 }
1475 }
1476
1481 {
1482 switch (window_class) {
1483 case WC_BUS_STATION: return StationType::Bus;
1485 default: NOT_REACHED();
1486 }
1487 }
1488
1489 void DrawWidget(const Rect &r, WidgetID widget) const override
1490 {
1491 switch (widget) {
1496 case WID_BROS_STATION_X:
1497 case WID_BROS_STATION_Y: {
1499 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1500 DrawPixelInfo tmp_dpi;
1501 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1502 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1503 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1506 if (spec == nullptr) {
1507 StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1508 } else {
1509 DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
1510 }
1511 }
1512 break;
1513 }
1514
1515 default:
1516 this->PickerWindow::DrawWidget(r, widget);
1517 break;
1518 }
1519 }
1520
1521 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1522 {
1523 switch (widget) {
1528 case WID_BROS_STATION_X:
1529 case WID_BROS_STATION_Y:
1530 if (widget < WID_BROS_STATION_X) {
1531 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1532 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return;
1533 }
1534 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1535 _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1536 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1537 SndClickBeep();
1538 this->SetDirty();
1540 break;
1541
1542 case WID_BROS_LT_OFF:
1543 case WID_BROS_LT_ON:
1544 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1545 _settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
1546 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1547 SndClickBeep();
1548 this->SetDirty();
1549 SetViewportCatchmentStation(nullptr, true);
1550 break;
1551
1552 default:
1553 this->PickerWindow::OnClick(pt, widget, click_count);
1554 break;
1555 }
1556 }
1557
1558 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1559 {
1561 }
1562
1563 static inline HotkeyList road_hotkeys{"buildroadstop", {
1564 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1565 }};
1566
1567 static inline HotkeyList tram_hotkeys{"buildtramstop", {
1568 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1569 }};
1570};
1571
1573static constexpr std::initializer_list<NWidgetPart> _nested_road_station_picker_widgets = {
1575 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1576 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1577 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1578 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1579 EndContainer(),
1583 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1586 /* 6-orientation plane. */
1590 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NW), SetFill(0, 0), EndContainer(),
1591 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_NE), SetFill(0, 0), EndContainer(),
1592 EndContainer(),
1593 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1594 EndContainer(),
1597 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SW), SetFill(0, 0), EndContainer(),
1598 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_SE), SetFill(0, 0), EndContainer(),
1599 EndContainer(),
1600 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1601 EndContainer(),
1602 EndContainer(),
1603 /* 2-orientation plane. */
1606 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1607 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1608 EndContainer(),
1609 EndContainer(),
1610 EndContainer(),
1611 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1613 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1614 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1615 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1616 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1617 EndContainer(),
1618 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1619 EndContainer(),
1620 EndContainer(),
1621 EndContainer(),
1623 EndContainer(),
1624};
1625
1626static WindowDesc _road_station_picker_desc(
1627 WDP_AUTO, "build_station_road", 0, 0,
1631 &BuildRoadStationWindow::road_hotkeys
1632);
1633
1635static constexpr std::initializer_list<NWidgetPart> _nested_tram_station_picker_widgets = {
1637 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1638 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN, WID_BROS_CAPTION),
1639 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1640 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1641 EndContainer(),
1645 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1648 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_X), SetFill(0, 0), EndContainer(),
1649 NWidget(WWT_PANEL, COLOUR_GREY, WID_BROS_STATION_Y), SetFill(0, 0), EndContainer(),
1650 EndContainer(),
1651 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1653 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_OFF), SetMinimalSize(60, 12),
1654 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1655 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BROS_LT_ON), SetMinimalSize(60, 12),
1656 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1657 EndContainer(),
1658 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BROS_ACCEPTANCE), SetFill(1, 1), SetResize(1, 0), SetMinimalTextLines(2, 0),
1659 EndContainer(),
1660 EndContainer(),
1661 EndContainer(),
1663 EndContainer(),
1664};
1665
1666static WindowDesc _tram_station_picker_desc(
1667 WDP_AUTO, "build_station_tram", 0, 0,
1671 &BuildRoadStationWindow::tram_hotkeys
1672);
1673
1674static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1675{
1676 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? _road_station_picker_desc : _tram_station_picker_desc, parent, rs);
1677}
1678
1679class RoadWaypointPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1680public:
1681 RoadWaypointPickerCallbacks() : PickerCallbacksNewGRFClass<RoadStopClass>("fav_road_waypoints") {}
1682
1683 GrfSpecFeature GetFeature() const override { return GSF_ROADSTOPS; }
1684
1685 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1686 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1687 StringID GetCollectionTooltip() const override { return STR_PICKER_WAYPOINT_COLLECTION_TOOLTIP; }
1688
1689 bool IsActive() const override
1690 {
1691 for (const auto &cls : RoadStopClass::Classes()) {
1692 if (!IsWaypointClass(cls)) continue;
1693 for (const auto *spec : cls.Specs()) {
1694 if (spec != nullptr) return true;
1695 }
1696 }
1697 return false;
1698 }
1699
1700 bool HasClassChoice() const override
1701 {
1702 return std::ranges::count_if(RoadStopClass::Classes(), IsWaypointClass) > 1;
1703 }
1704
1705 void Close(int) override { ResetObjectToPlace(); }
1706 int GetSelectedClass() const override { return _waypoint_gui.sel_class; }
1707 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1708
1709 StringID GetClassName(int id) const override
1710 {
1711 const auto *sc = GetClass(id);
1712 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1713 return sc->name;
1714 }
1715
1716 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1717 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1718
1719 StringID GetTypeName(int cls_id, int id) const override
1720 {
1721 const auto *spec = this->GetSpec(cls_id, id);
1722 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1723 }
1724
1725 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1726 {
1727 const auto *spec = this->GetSpec(cls_id, id);
1728 if (spec == nullptr) return {};
1729 return spec->badges;
1730 }
1731
1732 bool IsTypeAvailable(int cls_id, int id) const override
1733 {
1734 return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
1735 }
1736
1737 void DrawType(int x, int y, int cls_id, int id) const override
1738 {
1739 const auto *spec = this->GetSpec(cls_id, id);
1740 if (spec == nullptr) {
1741 StationPickerDrawSprite(x, y, StationType::RoadWaypoint, INVALID_RAILTYPE, _cur_roadtype, RSV_DRIVE_THROUGH_X);
1742 } else {
1744 }
1745 }
1746
1747 void FillUsedItems(std::set<PickerItem> &items) override
1748 {
1749 for (const Waypoint *wp : Waypoint::Iterate()) {
1750 if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1751 items.insert({0, 0, ROADSTOP_CLASS_WAYP, 0}); // We would need to scan the map to find out if default is used.
1752 for (const auto &sm : wp->roadstop_speclist) {
1753 if (sm.spec == nullptr) continue;
1754 items.insert({sm.grfid, sm.localidx, sm.spec->class_index, sm.spec->index});
1755 }
1756 }
1757 }
1758
1759 static RoadWaypointPickerCallbacks instance;
1760};
1761/* static */ RoadWaypointPickerCallbacks RoadWaypointPickerCallbacks::instance;
1762
1763struct BuildRoadWaypointWindow : public PickerWindow {
1764 BuildRoadWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TRANSPORT_ROAD, RoadWaypointPickerCallbacks::instance)
1765 {
1766 this->ConstructWindow();
1767 }
1768
1769 static inline HotkeyList hotkeys{"buildroadwaypoint", {
1770 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1771 }};
1772};
1773
1775static constexpr std::initializer_list<NWidgetPart> _nested_build_road_waypoint_widgets = {
1777 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1778 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_WAYPOINT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1779 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1780 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1781 EndContainer(),
1785 EndContainer(),
1786};
1787
1788static WindowDesc _build_road_waypoint_desc(
1789 WDP_AUTO, "build_road_waypoint", 0, 0,
1793 &BuildRoadWaypointWindow::hotkeys
1794);
1795
1796static void ShowBuildRoadWaypointPicker(Window *parent)
1797{
1798 if (!RoadWaypointPickerCallbacks::instance.IsActive()) return;
1799 new BuildRoadWaypointWindow(_build_road_waypoint_desc, parent);
1800}
1801
1802void InitializeRoadGui()
1803{
1804 _road_depot_orientation = DIAGDIR_NW;
1805 _roadstop_gui.orientation = DIAGDIR_NW;
1807 _waypoint_gui.sel_type = 0;
1808}
1809
1814{
1816 if (w != nullptr) w->ModifyRoadType(_cur_roadtype);
1817}
1818
1819DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1820{
1821 RoadTypes used_roadtypes;
1822 RoadTypes avail_roadtypes;
1823
1825
1826 /* Find the used roadtypes. */
1827 if (for_replacement) {
1828 avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1829 used_roadtypes = GetRoadTypes(false);
1830 } else {
1831 avail_roadtypes = c->avail_roadtypes;
1832 used_roadtypes = GetRoadTypes(true);
1833 }
1834
1835 /* Filter listed road types */
1836 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
1837 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
1838
1839 DropDownList list;
1840
1841 if (all_option) {
1842 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
1843 }
1844
1845 Dimension d = { 0, 0 };
1846 /* Get largest icon size, to ensure text is aligned on each menu item. */
1847 if (!for_replacement) {
1848 used_roadtypes.Reset(_roadtypes_hidden_mask);
1849 for (const auto &rt : _sorted_roadtypes) {
1850 if (!used_roadtypes.Test(rt)) continue;
1851 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1853 }
1854 }
1855
1856 /* Shared list so that each item can take ownership. */
1857 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
1858
1859 for (const auto &rt : _sorted_roadtypes) {
1860 /* If it's not used ever, don't show it to the user. */
1861 if (!used_roadtypes.Test(rt)) continue;
1862
1863 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1864
1865 if (for_replacement) {
1866 list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt)));
1867 } else {
1868 std::string str = rti->max_speed > 0
1869 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1870 : GetString(rti->strings.menu_text);
1871 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1872 }
1873 }
1874
1875 if (list.empty()) {
1876 /* Empty dropdowns are not allowed */
1877 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1878 }
1879
1880 return list;
1881}
1882
1883DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1884{
1885 RoadTypes avail_roadtypes = GetRoadTypes(false);
1886 avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, TimerGameCalendar::date);
1887 RoadTypes used_roadtypes = GetRoadTypes(true);
1888
1889 /* Filter listed road types */
1890 used_roadtypes.Reset(_roadtypes_hidden_mask);
1891 if (!HasBit(rtts, RTT_ROAD)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_ROAD));
1892 if (!HasBit(rtts, RTT_TRAM)) used_roadtypes.Reset(GetMaskForRoadTramType(RTT_TRAM));
1893
1894 DropDownList list;
1895
1896 /* If it's not used ever, don't show it to the user. */
1897 Dimension d = { 0, 0 };
1898 for (const auto &rt : _sorted_roadtypes) {
1899 if (!used_roadtypes.Test(rt)) continue;
1900 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1902 }
1903
1904 /* Shared list so that each item can take ownership. */
1905 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GSF_ROADTYPES);
1906
1907 for (const auto &rt : _sorted_roadtypes) {
1908 if (!used_roadtypes.Test(rt)) continue;
1909
1910 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1911
1912 std::string str = rti->max_speed > 0
1913 ? GetString(STR_TOOLBAR_RAILTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1914 : GetString(rti->strings.menu_text);
1915 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GSF_ROADTYPES, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1916 }
1917
1918 if (list.empty()) {
1919 /* Empty dropdowns are not allowed */
1920 list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
1921 }
1922
1923 return list;
1924}
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
Prepare the data for the build a bridge window.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
static std::span< NewGRFClass< RoadStopSpec, RoadStopClassID, Tmax > const > Classes()
static NewGRFClass * Get(RoadStopClassID class_index)
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:39
const std::string ini_group
Ini Group for saving favourites.
Definition picker_gui.h:125
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:219
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:220
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:221
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:222
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:253
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 of a type.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
bool IsActive() const override
Should picker class/type selection be enabled?
int GetSelectedType() const override
Get the selected type.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:79
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:81
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
StringID picker_title[2]
Title for the station picker for bus or truck stations.
Definition road.h:91
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
CursorID autoroad
Cursor for autorail tool.
Definition road.h:70
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:140
StringID picker_tooltip[2]
Tooltip for the station picker for bus or truck stations.
Definition road.h:92
StringID err_build_road
Building a normal piece of road.
Definition road.h:84
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:85
CursorID depot
Cursor for building a depot.
Definition road.h:71
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:69
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:116
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:78
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:60
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:72
SpriteID auto_road
button for the autoroad construction
Definition road.h:61
SpriteID convert_road
button for converting road types
Definition road.h:64
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:68
StringID err_convert_road
Converting a road type.
Definition road.h:89
StringID err_depot
Building a depot.
Definition road.h:86
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:59
SpriteID build_depot
button for building depots
Definition road.h:62
SpriteID build_tunnel
button for building a tunnel
Definition road.h:63
StringID err_build_station[2]
Building a bus or truck station.
Definition road.h:87
StringID err_remove_station[2]
Removing of a bus or truck station.
Definition road.h:88
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
int GetSelectedType() const override
Get the selected type.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item 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.
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 of a type.
StringID GetClassName(int id) const override
Get the name of a class.
void SetSelectedClass(int id) const override
Set the selected class.
int GetSelectedClass() const override
Get the index of the selected class.
bool HasClassChoice() const override
Are there multiple classes to chose from?
static Date date
Current date in days (day counter).
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Definition command.cpp:113
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ Auto
don't allow building on structures
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Axis
Allow incrementing of DiagDirDiff variables.
@ INVALID_AXIS
Flag for an invalid Axis.
@ AXIS_X
The X axis.
@ AXIS_Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
@ DIAGDIR_NW
Northwest.
@ DIAGDIR_END
Used for iterations.
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:17
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:972
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
void SetCursor(CursorID icon, PaletteID pal)
Assign an animation or a non-animated sprite to the cursor.
Definition gfx.cpp:1738
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition gfx.cpp:1573
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
uint32_t CursorID
The number of the cursor (sprite).
Definition gfx_type.h:19
@ WKC_R_BRACKET
] Right square bracket
Definition gfx_type.h:102
@ WKC_L_BRACKET
[ Left square bracket
Definition gfx_type.h:100
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:969
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:100
SpecialListHotkeys
Indexes for special hotkeys to navigate in lists.
Definition hotkeys.h:83
@ NextItem
Hotkey to select next item in the list.
Definition hotkeys.h:85
@ FirstItem
Hotkey to select first item in the list.
Definition hotkeys.h:86
@ LastItem
Hotkey to select last item in the list.
Definition hotkeys.h:87
@ PreviousItem
Hotkey to select previous item in the list.
Definition hotkeys.h:84
bool IsSpecialHotkey(const int &hotkey)
Checks if hotkey index is special or not.
Definition hotkeys.h:74
#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:406
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:572
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
GrfSpecFeature
Definition newgrf.h:71
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ Avail
Availability of road stop in construction window.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
Draw representation of a road stop tile for GUI purposes.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
RoadStopClassID
@ ROADSTOP_CLASS_DFLT
Default road stop class.
@ ROADSTOP_CLASS_WAYP
Waypoint class.
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
@ RSV_DRIVE_THROUGH_X
Drive through road stop, X axis.
@ NoAutoRoadConnection
No auto road connection.
@ RoadOnly
Only show in the road build menu (not tram).
@ TramOnly
Only show in the tram build menu (not road).
@ DriveThroughOnly
Stop is drive-through only.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Functions/types etc.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
Definition rail_gui.cpp:58
static WaypointPickerSelection _waypoint_gui
Settings of the waypoint picker.
Definition rail_gui.cpp:68
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:32
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:210
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:238
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:165
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition road.cpp:177
bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction.
Definition road.cpp:123
RoadTypes _roadtypes_hidden_mask
Bitset of hidden roadtypes.
Definition road_cmd.cpp:56
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:183
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:215
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:55
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:240
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Road related functions.
void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
Command callback for building road stops.
Definition road_gui.cpp:197
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:96
void InitializeRoadGUI()
I really don't know why rail_gui.cpp has this too, shouldn't be included in the other one?
static constexpr std::initializer_list< NWidgetPart > _nested_build_road_waypoint_widgets
Nested widget definition for the build NewGRF road waypoint window.
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
Command callback for building road stops.
Definition road_gui.cpp:197
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:231
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
Definition road_gui.cpp:298
static constexpr std::initializer_list< NWidgetPart > _nested_tram_station_picker_widgets
Widget definition of the build tram station window.
static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
Check whether a road stop type can be built.
Definition road_gui.cpp:103
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition road_gui.cpp:126
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:280
static void PlaceRoad_Waypoint(TileIndex tile)
Place a road waypoint.
Definition road_gui.cpp:257
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
Definition road_gui.cpp:318
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:331
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
Callback executed after a build road tunnel command has been called.
Definition road_gui.cpp:143
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:165
Functions/types related to the road GUIs.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
@ ROAD_NONE
No road-part is build.
Definition road_type.h:57
RoadTramType
The different types of road type.
Definition road_type.h:37
@ RTT_ROAD
Road road type.
Definition road_type.h:38
@ RTT_TRAM
Tram road type.
Definition road_type.h:39
RoadTramTypes
Definition road_type.h:42
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:28
@ DRD_NORTHBOUND
All northbound traffic is disallowed.
Definition road_type.h:80
@ DRD_NONE
None of the directions are disallowed.
Definition road_type.h:78
Types related to the road widgets.
@ WID_BROS_LT_ON
Turn on area highlight.
Definition road_widget.h:53
@ WID_BROS_ACCEPTANCE
Station acceptance info.
Definition road_widget.h:54
@ WID_BROS_STATION_SW
Terminal station with SW entry.
Definition road_widget.h:48
@ WID_BROS_STATION_X
Drive-through station in x-direction.
Definition road_widget.h:50
@ WID_BROS_STATION_NE
Terminal station with NE entry.
Definition road_widget.h:46
@ WID_BROS_STATION_SE
Terminal station with SE entry.
Definition road_widget.h:47
@ WID_BROS_CAPTION
Caption of the window.
Definition road_widget.h:45
@ WID_BROS_AVAILABLE_ORIENTATIONS
Selection for selecting 6 or 2 orientations.
Definition road_widget.h:55
@ WID_BROS_STATION_NW
Terminal station with NW entry.
Definition road_widget.h:49
@ WID_BROS_STATION_Y
Drive-through station in y-direction.
Definition road_widget.h:51
@ WID_BROS_LT_OFF
Turn off area highlight.
Definition road_widget.h:52
RoadToolbarWidgets
Widgets of the BuildRoadToolbarWindow class.
Definition road_widget.h:14
@ WID_ROT_BUILD_BRIDGE
Build bridge.
Definition road_widget.h:26
@ WID_ROT_BUS_STATION
Build bus station.
Definition road_widget.h:23
@ WID_ROT_DEPOT
Build depot.
Definition road_widget.h:21
@ WID_ROT_CAPTION
Caption of the window.
Definition road_widget.h:16
@ WID_ROT_BUILD_WAYPOINT
Build waypoint.
Definition road_widget.h:22
@ WID_ROT_ROAD_Y
Build road in y-direction.
Definition road_widget.h:18
@ WID_ROT_AUTOROAD
Autorail.
Definition road_widget.h:19
@ WID_ROT_DEMOLISH
Demolish.
Definition road_widget.h:20
@ WID_ROT_BUILD_TUNNEL
Build tunnel.
Definition road_widget.h:27
@ WID_ROT_TRUCK_STATION
Build truck station.
Definition road_widget.h:24
@ WID_ROT_CONVERT_ROAD
Convert road.
Definition road_widget.h:29
@ WID_ROT_REMOVE
Remove road.
Definition road_widget.h:28
@ WID_ROT_ONE_WAY
Build one-way road.
Definition road_widget.h:25
@ WID_ROT_ROAD_X
Build road in x-direction.
Definition road_widget.h:17
@ WID_BROD_DEPOT_SE
Depot with SE entry.
Definition road_widget.h:37
@ WID_BROD_DEPOT_NE
Depot with NE entry.
Definition road_widget.h:36
@ WID_BROD_CAPTION
Caption of the window.
Definition road_widget.h:35
@ WID_BROD_DEPOT_NW
Depot with NW entry.
Definition road_widget.h:39
@ WID_BROD_DEPOT_SW
Depot with SW entry.
Definition road_widget.h:38
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:77
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1522
Base classes/functions for stations.
Command definitions related to stations.
Functions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s).
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
void ShowSelectRoadWaypointIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the road waypoint selection window when needed.
Contains enums and function declarations connected with stations GUI.
StationCoverageType
Types of cargo to display for station coverage.
Definition station_gui.h:21
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition station_gui.h:23
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition station_gui.h:22
RoadStopType
Types of RoadStops.
@ Bus
A standard stop for buses.
@ Truck
A standard stop for trucks.
@ TruckStop
Station with truck stops.
@ BusStop
Station with bus stops.
StationType
Station types.
@ Bus
Road stop for busses.
@ Truck
Road stop for trucks.
@ RoadWaypoint
Waypoint for trucks and busses.
static constexpr uint CA_BUS
Catchment for bus stops with "modified catchment" enabled.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
static constexpr uint CA_TRUCK
Catchment for truck stops with "modified catchment" enabled.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint coverage_height
Height of the coverage texts.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
StationType GetRoadStationTypeByWindowClass(WindowClass window_class) const
Simply to have a easier way to get the StationType for bus, truck and trams from the WindowClass.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Road toolbar window handler.
Definition road_gui.cpp:347
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition road_gui.cpp:709
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition road_gui.cpp:443
void ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition road_gui.cpp:437
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition road_gui.cpp:873
HighLightStyle GetHighLightStyleForWidget(WidgetID widget)
Returns corresponding high light style for provided button.
Definition road_gui.cpp:540
CursorID GetCursorForWidget(WidgetID widget)
Returns corresponding cursor for provided button.
Definition road_gui.cpp:517
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:730
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:366
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Definition road_gui.cpp:885
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:647
EventState ChangeRoadTypeOnHotkey(int hotkey)
Selects new RoadType based on SpecialHotkeys and order defined in _sorted_roadtypes.
Definition road_gui.cpp:618
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition road_gui.cpp:640
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:861
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition road_gui.cpp:419
RoadType roadtype
Road type to build.
Definition road_gui.cpp:348
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:774
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:558
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition road_gui.cpp:462
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition road_gui.cpp:867
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:769
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition road_gui.cpp:378
WidgetID last_started_action
Last started user action.
Definition road_gui.cpp:349
GUISettings gui
settings related to the GUI
RoadTypes avail_roadtypes
Road types available to this company.
Dimensions (a width and height) of a rectangle in 2D.
Data about how and where to blit pixels.
Definition gfx_type.h:157
const struct GRFFile * grffile
grf file that introduced this entity
bool station_show_coverage
whether to highlight coverage area
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
static Company * Get(auto index)
Specification of a rectangle with absolute coordinates of all edges.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
int Height() const
Get height of Rect.
RoadStopClassID sel_class
Selected road stop class.
Definition road_gui.cpp:78
DiagDirection orientation
Selected orientation of the road stop.
Definition road_gui.cpp:80
uint16_t sel_type
Selected road stop type within the class.
Definition road_gui.cpp:79
Road stop specification.
CargoGRFFileProps grf_prop
Link to NewGRF.
RoadStopClassID sel_class
Selected road waypoint class.
Definition road_gui.cpp:72
uint16_t sel_type
Selected road waypoint type within the class.
Definition road_gui.cpp:73
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Station data structure.
Representation of a waypoint.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:981
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1106
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1812
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
Window * parent
Parent window.
Definition window_gui.h:329
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:559
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:507
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1802
WindowClass window_class
Window class.
Definition window_gui.h:302
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:411
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:533
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:560
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:846
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1835
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:986
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:573
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:451
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
highlighting tiles while only going over them with the mouse
HighLightStyle
Highlighting draw styles.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
RoadType _last_built_tramtype
The most recently used type of tram track.
RoadType _last_built_roadtype
The most recently used type of road.
Stuff related to the (main) toolbar.
@ TRANSPORT_ROAD
Transport by road vehicle.
Header file for things common for tunnels and bridges.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1916
Functions related to vehicles.
@ VEH_ROAD
Road vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
@ VPM_FIX_Y
drag only in Y axis
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ VPM_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_X
drag only in X axis
@ VPM_X_OR_Y
drag in X or Y direction
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_PLACE_ROAD_Y_DIR
Road placement (Y axis).
@ DDSP_BUILD_BUSSTOP
Road stop placement (buses).
@ DDSP_REMOVE_BUSSTOP
Road stop removal (buses).
@ DDSP_REMOVE_ROAD_WAYPOINT
Road stop removal (waypoint).
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_BUILD_TRUCKSTOP
Road stop placement (trucks).
@ DDSP_REMOVE_TRUCKSTOP
Road stop removal (trucks).
@ DDSP_PLACE_AUTOROAD
Road placement (auto).
@ DDSP_BUILD_ROAD_WAYPOINT
Road stop placement (waypoint).
@ DDSP_PLACE_ROAD_X_DIR
Road placement (X axis).
@ DDSP_BUILD_BRIDGE
Bridge placement.
@ DDSP_CONVERT_ROAD
Road conversion.
Base of waypoints.
@ WPF_ROAD
This is a road waypoint.
Axis GetAxisForNewRoadWaypoint(TileIndex tile)
Get the axis for a new road waypoint.
Command definitions related to waypoints.
Functions related to waypoints.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1198
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1211
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1705
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1155
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3188
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:153
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
Definition window_gui.h:143
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:23
@ WC_SCEN_BUILD_TOOLBAR
Scenario build toolbar; Window numbers:
Definition window_type.h:85
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
@ WC_BUILD_DEPOT
Build depot; Window numbers:
@ WC_TRUCK_STATION
Build truck station; Window numbers:
@ WC_BUS_STATION
Build bus station; Window numbers:
@ WC_BUILD_WAYPOINT
Build waypoint; Window numbers:
@ WC_BUILD_BRIDGE
Build bridge; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107