OpenTTD Source 20261112-master-gbcbec5e63f
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 "station_base.h"
35#include "station_func.h"
36#include "waypoint_base.h"
37#include "strings_func.h"
39#include "station_cmd.h"
40#include "tunnelbridge_cmd.h"
41#include "waypoint_cmd.h"
42#include "road_cmd.h"
43#include "newgrf_badge_gui.h"
44#include "newgrf_roadstop.h"
45#include "picker_gui.h"
47
48#include "widgets/road_widget.h"
49
50#include "table/strings.h"
51
52#include "safeguards.h"
53
54static void ShowRVStationPicker(Window *parent, RoadStopType rs);
55static void ShowRoadDepotPicker(Window *parent);
56static void ShowBuildRoadWaypointPicker(Window *parent);
57
58static bool _remove_button_clicked;
59static bool _one_way_button_clicked;
60
61static Axis _place_road_dir;
62static bool _place_road_start_half_x;
63static bool _place_road_start_half_y;
64static bool _place_road_end_half;
65
66static RoadType _cur_roadtype;
67
68static DiagDirection _road_depot_orientation;
69
75
81static RoadStopPickerSelection _roadstop_gui;
82
83static bool IsRoadStopEverAvailable(const RoadStopSpec *spec, StationType type)
84{
85 if (spec == nullptr) return true;
86
87 if (spec->flags.Test(RoadStopSpecFlag::RoadOnly) && !RoadTypeIsRoad(_cur_roadtype)) return false;
88 if (spec->flags.Test(RoadStopSpecFlag::TramOnly) && !RoadTypeIsTram(_cur_roadtype)) return false;
89
90 switch (spec->stop_type) {
91 case ROADSTOPTYPE_ALL: return true;
92 case ROADSTOPTYPE_PASSENGER: return type == StationType::Bus;
93 case ROADSTOPTYPE_FREIGHT: return type == StationType::Truck;
94 default: NOT_REACHED();
95 }
96}
97
104static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
105{
106 if (spec == nullptr) return true;
107 if (!IsRoadStopEverAvailable(spec, type)) return false;
108
109 if (!spec->callback_mask.Test(RoadStopCallbackMask::Avail)) return true;
110
111 uint16_t cb_res = GetRoadStopCallback(CBID_STATION_AVAILABILITY, 0, 0, spec, nullptr, INVALID_TILE, _cur_roadtype, type, 0);
112 if (cb_res == CALLBACK_FAILED) return true;
113
115}
116
117void CcPlaySound_CONSTRUCTION_OTHER(Commands, const CommandCost &result, TileIndex tile)
118{
119 if (result.Succeeded() && _settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
120}
121
127static void PlaceRoad_Bridge(TileIndex tile, Window *w)
128{
129 if (IsBridgeTile(tile)) {
130 TileIndex other_tile = GetOtherTunnelBridgeEnd(tile);
131 Point pt = {0, 0};
132 w->OnPlaceMouseUp(VPM_X_OR_Y, DDSP_BUILD_BRIDGE, pt, other_tile, tile);
133 } else {
135 }
136}
137
144void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
145{
146 if (result.Succeeded()) {
147 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, start_tile);
148 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
149
150 DiagDirection start_direction = ReverseDiagDir(GetTunnelBridgeDirection(start_tile));
151 ConnectRoadToStructure(start_tile, start_direction);
152
153 TileIndex end_tile = GetOtherTunnelBridgeEnd(start_tile);
154 DiagDirection end_direction = ReverseDiagDir(GetTunnelBridgeDirection(end_tile));
155 ConnectRoadToStructure(end_tile, end_direction);
156 } else {
158 }
159}
160
167{
168 tile += TileOffsByDiagDir(direction);
169 /* if there is a roadpiece just outside of the station entrance, build a connecting route */
170 if (IsNormalRoadTile(tile)) {
171 if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)).Any()) {
172 Command<Commands::BuildRoad>::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, {}, TownID::Invalid());
173 }
174 }
175}
176
177void CcRoadDepot(Commands, const CommandCost &result, TileIndex tile, RoadType, DiagDirection dir)
178{
179 if (result.Failed()) return;
180
181 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
182 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
183 ConnectRoadToStructure(tile, dir);
184}
185
198void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through,
199 DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
200{
201 if (result.Failed()) return;
202
203 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
204 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
205
206 bool connect_to_road = true;
207 if (spec_class.base() < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) {
208 const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index);
209 if (roadstopspec != nullptr && roadstopspec->flags.Test(RoadStopSpecFlag::NoAutoRoadConnection)) connect_to_road = false;
210 }
211
212 if (connect_to_road) {
213 TileArea roadstop_area(tile, width, length);
214 for (TileIndex cur_tile : roadstop_area) {
215 ConnectRoadToStructure(cur_tile, dir);
216 /* For a drive-through road stop build connecting road for other entrance. */
217 if (is_drive_through) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
218 }
219 }
220}
221
232static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType stop_type, bool adjacent, RoadType rt, StringID err_msg)
233{
234 TileArea ta(start_tile, end_tile);
235 DiagDirection ddir = _roadstop_gui.orientation;
236 bool drive_through = ddir >= DiagDirection::End;
237 if (drive_through) ddir = ddir - DiagDirection::End; // Adjust picker result to actual direction.
238 RoadStopClassID spec_class = _roadstop_gui.sel_class;
239 uint16_t spec_index = _roadstop_gui.sel_type;
240
241 auto proc = [=](bool test, StationID to_join) -> bool {
242 if (test) {
243 return Command<Commands::BuildRoadStop>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildRoadStop>()), ta.tile, ta.w, ta.h, stop_type, drive_through,
244 ddir, rt, spec_class, spec_index, StationID::Invalid(), adjacent).Succeeded();
245 } else {
246 return Command<Commands::BuildRoadStop>::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through,
247 ddir, rt, spec_class, spec_index, to_join, adjacent);
248 }
249 };
250
252}
253
259{
262 return;
263 }
264
265 Axis axis = GetAxisForNewRoadWaypoint(tile);
266 if (IsValidAxis(axis)) {
267 /* Valid tile for waypoints */
269 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
270 } else {
271 /* Tile where we can't build road waypoints. This is always going to fail,
272 * but provides the user with a proper error message. */
273 Command<Commands::BuildRoadWaypoint>::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, Axis::X, 1, 1, ROADSTOP_CLASS_WAYP, 0, StationID::Invalid(), false);
274 }
275}
276
282{
285 } else {
286 if (_roadstop_gui.orientation < DiagDirection::End) { // Not a drive-through stop.
287 VpStartPlaceSizing(tile, (DiagDirToAxis(_roadstop_gui.orientation) == Axis::X) ? VPM_X_LIMITED : VPM_Y_LIMITED, DDSP_BUILD_BUSSTOP);
288 } else {
290 }
291 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
292 }
293}
294
300{
303 } else {
304 if (_roadstop_gui.orientation < DiagDirection::End) { // Not a drive-through stop.
306 } else {
308 }
309 VpSetPlaceSizingLimit(_settings_game.station.station_spread);
310 }
311}
312
313typedef void OnButtonClick(Window *w);
314
326
333{
334 if (w->IsWidgetDisabled(WID_ROT_REMOVE)) return false;
335
336 /* allow ctrl to switch remove mode only for these widgets */
337 for (WidgetID i = WID_ROT_ROAD_X; i <= WID_ROT_AUTOROAD; i++) {
338 if (w->IsWidgetLowered(i)) {
340 return true;
341 }
342 }
343
344 return false;
345}
346
348struct BuildRoadToolbarWindow : Window {
351
352 BuildRoadToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc), roadtype(_cur_roadtype)
353 {
354 this->CreateNestedTree();
355 this->FinishInitNested(window_number);
357
358 if (RoadTypeIsRoad(this->roadtype)) {
360 }
361
362 this->OnInvalidateData();
363
364 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
365 }
366
367 void Close([[maybe_unused]] int data = 0) override
368 {
370 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WindowClass::ScenarioGenerateLandscape, 0, false);
371 this->Window::Close();
372 }
373
379 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
380 {
381 if (!gui_scope) return;
382
383 if (_cur_roadtype != this->roadtype) {
384 bool close_build_station = this->ModifyRoadType(_cur_roadtype);
385
386 /* Update cursor and all sub windows. */
387 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
388 for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) {
390 }
391
392 if (close_build_station) {
393 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
394 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
395 }
396 }
397
398 if (!ValParamRoadType(this->roadtype)) {
399 /* Close toolbar if road type is not available. */
400 this->Close();
401 return;
402 }
403
404 RoadTramType rtt = GetRoadTramType(this->roadtype);
405
407 this->SetWidgetsDisabledState(!can_build,
412 if (!can_build) {
413 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
414 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
415 CloseWindowById(WindowClass::BuildDepot, TransportType::Road);
416 CloseWindowById(WindowClass::BuildWaypoint, TransportType::Road);
417 }
418
419 if (_game_mode != GameMode::Editor) {
420 if (!can_build) {
421 /* Show in the tooltip why this button is disabled. */
422 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
423 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
424 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
425 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
426 } else {
427 this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT);
428 this->GetWidget<NWidgetCore>(WID_ROT_BUILD_WAYPOINT)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT : STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT);
429 this->GetWidget<NWidgetCore>(WID_ROT_BUS_STATION)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION);
430 this->GetWidget<NWidgetCore>(WID_ROT_TRUCK_STATION)->SetToolTip(rtt == RoadTramType::Road ? STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY : STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION);
431 }
432 }
433 }
434
435 void OnInit() override
436 {
437 /* Configure the road toolbar for the roadtype. */
438 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
442 if (_game_mode != GameMode::Editor) {
444 }
447 }
448
455 {
456 bool result = RoadTypeIsRoad(this->roadtype) != RoadTypeIsRoad(roadtype);
457
458 this->roadtype = roadtype;
459 this->ReInit();
460 return result;
461 }
462
463 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
464 {
465 if (widget == WID_ROT_CAPTION) {
466 const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
467 if (rti->max_speed > 0) {
468 return GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.toolbar_caption, PackVelocity(rti->max_speed / 2, VehicleType::Road));
469 }
470 return GetString(rti->strings.toolbar_caption);
471
472 }
473
474 return this->Window::GetWidgetString(widget, stringid);
475 }
476
483 {
484 /* The remove and the one way button state is driven
485 * by the other buttons so they don't act on themselves.
486 * Both are only valid if they are able to apply as options. */
487 switch (clicked_widget) {
488 case WID_ROT_REMOVE:
489 if (RoadTypeIsRoad(this->roadtype)) {
492 }
493
494 break;
495
496 case WID_ROT_ONE_WAY:
499 break;
500
504 if (RoadTypeIsRoad(this->roadtype)) this->DisableWidget(WID_ROT_ONE_WAY);
505 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
506 break;
507
508 case WID_ROT_ROAD_X:
509 case WID_ROT_ROAD_Y:
510 case WID_ROT_AUTOROAD:
511 this->SetWidgetDisabledState(WID_ROT_REMOVE, !this->IsWidgetLowered(clicked_widget));
512 if (RoadTypeIsRoad(this->roadtype)) {
513 this->SetWidgetDisabledState(WID_ROT_ONE_WAY, !this->IsWidgetLowered(clicked_widget));
514 }
515 break;
516
517 default:
518 /* When any other buttons than road/station, raise and
519 * disable the removal button */
522
523 if (RoadTypeIsRoad(this->roadtype)) {
526 }
527
528 break;
529 }
530 }
531
538 {
539 switch (widget) {
540 case WID_ROT_ROAD_X: return GetRoadTypeInfo(this->roadtype)->cursor.road_nwse;
541 case WID_ROT_ROAD_Y: return GetRoadTypeInfo(this->roadtype)->cursor.road_swne;
542 case WID_ROT_AUTOROAD: return GetRoadTypeInfo(this->roadtype)->cursor.autoroad;
544 case WID_ROT_DEPOT: return GetRoadTypeInfo(this->roadtype)->cursor.depot;
549 case WID_ROT_BUILD_TUNNEL: return GetRoadTypeInfo(this->roadtype)->cursor.tunnel;
550 case WID_ROT_CONVERT_ROAD: return GetRoadTypeInfo(this->roadtype)->cursor.convert_road;
551 default: NOT_REACHED();
552 }
553 }
554
561 {
562 switch (widget) {
563 case WID_ROT_ROAD_X: return HT_RECT;
564 case WID_ROT_ROAD_Y: return HT_RECT;
565 case WID_ROT_AUTOROAD: return HT_RECT;
566 case WID_ROT_DEMOLISH: return HT_RECT | HT_DIAGONAL;
567 case WID_ROT_DEPOT: return HT_RECT;
568 case WID_ROT_BUILD_WAYPOINT: return HT_RECT;
569 case WID_ROT_BUS_STATION: return HT_RECT;
570 case WID_ROT_TRUCK_STATION: return HT_RECT;
571 case WID_ROT_BUILD_BRIDGE: return HT_RECT;
572 case WID_ROT_BUILD_TUNNEL: return HT_SPECIAL;
574 default: NOT_REACHED();
575 }
576 }
577
578 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
579 {
580 bool started;
581 _remove_button_clicked = false;
582 _one_way_button_clicked = false;
583
584 if (widget != WID_ROT_ONE_WAY && widget != WID_ROT_REMOVE) {
585 started = HandlePlacePushButton(this, widget, this->GetCursorForWidget(widget), this->GetHighLightStyleForWidget(widget));
586 this->last_started_action = widget;
587 }
588
589 switch (widget) {
590 case WID_ROT_DEPOT:
591 if (started) {
592 ShowRoadDepotPicker(this);
593 }
594 break;
595
597 if (started) {
598 ShowBuildRoadWaypointPicker(this);
599 }
600 break;
601
603 if (started) {
604 ShowRVStationPicker(this, RoadStopType::Bus);
605 }
606 break;
607
609 if (started) {
610 ShowRVStationPicker(this, RoadStopType::Truck);
611 }
612 break;
613
614 case WID_ROT_ONE_WAY:
615 if (this->IsWidgetDisabled(WID_ROT_ONE_WAY)) return;
616 this->SetDirty();
618 SetSelectionRed(false);
619 break;
620
621 case WID_ROT_REMOVE:
622 if (this->IsWidgetDisabled(WID_ROT_REMOVE)) return;
623
624 CloseWindowById(WindowClass::JoinStation, 0);
626 SndClickBeep();
627 break;
628 }
629 this->UpdateOptionWidgetStatus(static_cast<RoadToolbarWidgets>(widget));
631 }
632
639 {
640 auto [index, step] = GetListIndexStep(SpecialListHotkeys(hotkey), _sorted_roadtypes, this->roadtype);
641
642 while (RoadTypeIsRoad(_sorted_roadtypes[index]) != RoadTypeIsRoad(this->roadtype) || !HasRoadTypeAvail(_local_company, _sorted_roadtypes[index])) {
643 index = (index + step) % _sorted_roadtypes.size();
644 }
645
646 _cur_roadtype = _sorted_roadtypes[index];
647 if (RoadTypeIsRoad(_cur_roadtype)) {
648 _last_built_roadtype = _cur_roadtype;
649 } else {
650 _last_built_tramtype = _cur_roadtype;
651 }
652 this->ModifyRoadType(_cur_roadtype);
653
654 if (_thd.GetCallbackWnd() == this) SetCursor(this->GetCursorForWidget(this->last_started_action), PAL_NONE);
655 for (WindowClass cls : {WindowClass::BuildBusStation, WindowClass::BuildTruckStation, WindowClass::BuildWaypoint, WindowClass::BuildDepot}) {
657 }
658
659 return EventState::Handled;
660 }
661
662 EventState OnHotkey(int hotkey) override
663 {
664 if (IsSpecialHotkey(hotkey)) return this->ChangeRoadTypeOnHotkey(hotkey);
665 MarkTileDirtyByTile(TileVirtXY(_thd.pos.x, _thd.pos.y)); // redraw tile selection
666 return Window::OnHotkey(hotkey);
667 }
668
669 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
670 {
671 _remove_button_clicked = this->IsWidgetLowered(WID_ROT_REMOVE);
672 _one_way_button_clicked = RoadTypeIsRoad(this->roadtype) ? this->IsWidgetLowered(WID_ROT_ONE_WAY) : false;
673 switch (this->last_started_action) {
674 case WID_ROT_ROAD_X:
675 _place_road_dir = Axis::X;
676 _place_road_start_half_x = _tile_fract_coords.x >= 8;
678 break;
679
680 case WID_ROT_ROAD_Y:
681 _place_road_dir = Axis::Y;
682 _place_road_start_half_y = _tile_fract_coords.y >= 8;
684 break;
685
686 case WID_ROT_AUTOROAD:
687 _place_road_dir = Axis::Invalid;
688 _place_road_start_half_x = _tile_fract_coords.x >= 8;
689 _place_road_start_half_y = _tile_fract_coords.y >= 8;
691 break;
692
693 case WID_ROT_DEMOLISH:
695 break;
696
697 case WID_ROT_DEPOT:
698 Command<Commands::BuildRoadDepot>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_depot, CcRoadDepot,
699 tile, _cur_roadtype, _road_depot_orientation);
700 break;
701
703 PlaceRoad_Waypoint(tile);
704 break;
705
708 break;
709
712 break;
713
715 PlaceRoad_Bridge(tile, this);
716 break;
717
719 Command<Commands::BuildTunnel>::Post(STR_ERROR_CAN_T_BUILD_TUNNEL_HERE, CcBuildRoadTunnel,
720 tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
721 break;
722
725 break;
726
727 default: NOT_REACHED();
728 }
729 }
730
731 void OnPlaceObjectAbort() override
732 {
734
735 this->RaiseButtons();
738
739 if (RoadTypeIsRoad(this->roadtype)) {
742 }
743
744 CloseWindowById(WindowClass::BuildBusStation, TransportType::Road);
745 CloseWindowById(WindowClass::BuildTruckStation, TransportType::Road);
746 CloseWindowById(WindowClass::BuildDepot, TransportType::Road);
747 CloseWindowById(WindowClass::BuildWaypoint, TransportType::Road);
748 CloseWindowById(WindowClass::JoinStation, 0);
749 CloseWindowByClass(WindowClass::BuildBridge);
750 }
751
752 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
753 {
754 /* Here we update the end tile flags
755 * of the road placement actions.
756 * At first we reset the end halfroad
757 * bits and if needed we set them again. */
758 switch (select_proc) {
760 _place_road_end_half = pt.x & 8;
761 break;
762
764 _place_road_end_half = pt.y & 8;
765 break;
766
768 /* For autoroad we need to update the
769 * direction of the road */
770 if (_thd.size.x > _thd.size.y || (_thd.size.x == _thd.size.y &&
771 ((_tile_fract_coords.x < _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) <= 15) ||
772 (_tile_fract_coords.x > _tile_fract_coords.y && (_tile_fract_coords.x + _tile_fract_coords.y) >= 15)))) {
773 /* Set dir = X */
774 _place_road_dir = Axis::X;
775 _place_road_end_half = pt.x & 8;
776 } else {
777 /* Set dir = Y */
778 _place_road_dir = Axis::Y;
779 _place_road_end_half = pt.y & 8;
780 }
781
782 break;
783
784 default:
785 break;
786 }
787
788 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
789 }
790
791 Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
792 {
793 return AlignInitialConstructionToolbar(sm_width);
794 }
795
796 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
797 {
798 if (pt.x != -1) {
799 switch (select_proc) {
800 default: NOT_REACHED();
802 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
803 ShowBuildBridgeWindow(start_tile, end_tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
804 break;
805
807 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
808 break;
809
812 case DDSP_PLACE_AUTOROAD: {
813 bool start_half = _place_road_dir == Axis::Y ? _place_road_start_half_y : _place_road_start_half_x;
814
815 if (_remove_button_clicked) {
816 Command<Commands::RemoveRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_remove_road, CcPlaySound_CONSTRUCTION_OTHER,
817 end_tile, start_tile, _cur_roadtype, _place_road_dir, start_half, _place_road_end_half);
818 } else {
819 Command<Commands::BuildRoadLong>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_build_road, CcPlaySound_CONSTRUCTION_OTHER,
820 end_tile, start_tile, _cur_roadtype, _place_road_dir, _one_way_button_clicked ? DisallowedRoadDirection::Northbound : DisallowedRoadDirections{}, start_half, _place_road_end_half, false);
821 }
822 break;
823 }
824
828 if (_remove_button_clicked) {
829 Command<Commands::RemoveFromRoadWaypoint>::Post(STR_ERROR_CAN_T_REMOVE_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile);
830 } else {
831 TileArea ta(start_tile, end_tile);
832 Axis axis = select_method == VPM_X_LIMITED ? Axis::X : Axis::Y;
833 bool adjacent = IsCtrlPressed();
834
835 auto proc = [=](bool test, StationID to_join) -> bool {
836 if (test) {
837 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();
838 } else {
839 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);
840 }
841 };
842
844 }
845 }
846 break;
847
850 if (this->IsWidgetLowered(WID_ROT_BUS_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Bus, _cur_roadtype)) {
851 if (_remove_button_clicked) {
852 TileArea ta(start_tile, end_tile);
854 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Bus, IsCtrlPressed());
855 } else {
857 PlaceRoadStop(start_tile, end_tile, RoadStopType::Bus, IsCtrlPressed(), _cur_roadtype, str);
858 }
859 }
860 break;
861
864 if (this->IsWidgetLowered(WID_ROT_TRUCK_STATION) && GetIfClassHasNewStopsByType(RoadStopClass::Get(_roadstop_gui.sel_class), RoadStopType::Truck, _cur_roadtype)) {
865 if (_remove_button_clicked) {
866 TileArea ta(start_tile, end_tile);
868 Command<Commands::RemoveRoadStop>::Post(str, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, ta.w, ta.h, RoadStopType::Truck, IsCtrlPressed());
869 } else {
871 PlaceRoadStop(start_tile, end_tile, RoadStopType::Truck, IsCtrlPressed(), _cur_roadtype, str);
872 }
873 }
874 break;
875
877 Command<Commands::ConvertRoad>::Post(GetRoadTypeInfo(this->roadtype)->strings.err_convert_road, CcPlaySound_CONSTRUCTION_OTHER, end_tile, start_tile, _cur_roadtype, IsCtrlPressed());
878 break;
879 }
880 }
881 }
882
883 void OnPlacePresize([[maybe_unused]] Point pt, TileIndex tile) override
884 {
885 Command<Commands::BuildTunnel>::Do(DoCommandFlag::Auto, tile, TransportType::Road, INVALID_RAILTYPE, _cur_roadtype);
887 }
888
890 {
893 }
894
895 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
896 {
897 if (_game_mode == GameMode::Normal && this->IsWidgetLowered(WID_ROT_BUILD_WAYPOINT)) CheckRedrawRoadWaypointCoverage(this);
898 }
899
908 {
909 Window *w = nullptr;
910 switch (_game_mode) {
911 case GameMode::Normal:
912 w = ShowBuildRoadToolbar(last_build);
913 break;
914
915 case GameMode::Editor:
917 w = ShowBuildRoadScenToolbar(last_build);
918 break;
919
920 default:
921 break;
922 }
923
924 if (w == nullptr) return EventState::NotHandled;
925 return w->OnHotkey(hotkey);
926 }
927
928 static EventState RoadToolbarGlobalHotkeys(int hotkey)
929 {
931 }
932
933 static EventState TramToolbarGlobalHotkeys(int hotkey)
934 {
936 }
937
938 static inline HotkeyList road_hotkeys{"roadtoolbar", {
939 Hotkey('1', "build_x", WID_ROT_ROAD_X),
940 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
941 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
942 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
943 Hotkey('5', "depot", WID_ROT_DEPOT),
944 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
945 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
946 Hotkey('8', "oneway", WID_ROT_ONE_WAY),
947 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
948 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
949 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
950 Hotkey('R', "remove", WID_ROT_REMOVE),
951 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
954 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_roadtype", to_underlying(SpecialListHotkeys::FirstItem)),
955 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_roadtype", to_underlying(SpecialListHotkeys::LastItem)),
956 }, RoadToolbarGlobalHotkeys};
957
958 static inline HotkeyList tram_hotkeys{"tramtoolbar", {
959 Hotkey('1', "build_x", WID_ROT_ROAD_X),
960 Hotkey('2', "build_y", WID_ROT_ROAD_Y),
961 Hotkey('3', "autoroad", WID_ROT_AUTOROAD),
962 Hotkey('4', "demolish", WID_ROT_DEMOLISH),
963 Hotkey('5', "depot", WID_ROT_DEPOT),
964 Hotkey('6', "bus_station", WID_ROT_BUS_STATION),
965 Hotkey('7', "truck_station", WID_ROT_TRUCK_STATION),
966 Hotkey('9', "waypoint", WID_ROT_BUILD_WAYPOINT),
967 Hotkey('B', "bridge", WID_ROT_BUILD_BRIDGE),
968 Hotkey('T', "tunnel", WID_ROT_BUILD_TUNNEL),
969 Hotkey('R', "remove", WID_ROT_REMOVE),
970 Hotkey('C', "convert", WID_ROT_CONVERT_ROAD),
973 Hotkey(WKC_L_BRACKET | WKC_CTRL, "first_tramtype", to_underlying(SpecialListHotkeys::FirstItem)),
974 Hotkey(WKC_R_BRACKET | WKC_CTRL, "last_tramtype", to_underlying(SpecialListHotkeys::LastItem)),
975 }, TramToolbarGlobalHotkeys};
976};
977
978static constexpr std::initializer_list<NWidgetPart> _nested_build_road_widgets = {
983 EndContainer(),
986 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
988 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
990 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
992 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
994 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_VEHICLE_DEPOT),
996 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD_TO_WAYPOINT),
998 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_BUS_STATION),
1000 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRUCK_LOADING_BAY),
1001
1003
1005 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1007 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1009 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1011 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1013 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1014 EndContainer(),
1015};
1016
1019 WindowPosition::Manual, "toolbar_road", 0, 0,
1020 WindowClass::BuildToolbar, WindowClass::None,
1022 _nested_build_road_widgets,
1023 &BuildRoadToolbarWindow::road_hotkeys
1024);
1025
1026static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_widgets = {
1031 EndContainer(),
1034 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1036 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1038 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1040 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1042 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_DEPOT, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAM_VEHICLE_DEPOT),
1044 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_WAYPOINT, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM_TO_WAYPOINT),
1046 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_BUS_STATION, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_PASSENGER_TRAM_STATION),
1048 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRUCK_BAY, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_CARGO_TRAM_STATION),
1049
1051
1053 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1055 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1057 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1059 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1060 EndContainer(),
1061};
1062
1065 WindowPosition::Manual, "toolbar_tramway", 0, 0,
1066 WindowClass::BuildToolbar, WindowClass::None,
1068 _nested_build_tramway_widgets,
1069 &BuildRoadToolbarWindow::tram_hotkeys
1070);
1071
1081{
1082 if (!Company::IsValidID(_local_company)) return nullptr;
1083 if (!ValParamRoadType(roadtype)) return nullptr;
1084
1085 if (GetRoadTramType(roadtype) == GetRoadTramType(_cur_roadtype)) {
1086 Window *w = BringWindowToFrontById(WindowClass::BuildToolbar, TransportType::Road);
1087
1088 if (w != nullptr) {
1089 _cur_roadtype = roadtype;
1090 w->OnInvalidateData();
1091 return w;
1092 }
1093 }
1094
1095 _cur_roadtype = roadtype;
1096 CloseWindowByClass(WindowClass::BuildToolbar);
1098}
1099
1100static constexpr std::initializer_list<NWidgetPart> _nested_build_road_scen_widgets = {
1105 EndContainer(),
1108 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1110 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_SECTION),
1112 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOROAD, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOROAD),
1114 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1115
1117
1119 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_ONE_WAY, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_ONE_WAY_ROAD),
1121 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_BRIDGE),
1123 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_ROAD_TUNNEL),
1125 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_ROAD),
1127 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_ROAD),
1128 EndContainer(),
1129};
1130
1133 WindowPosition::Automatic, "toolbar_road_scen", 0, 0,
1134 WindowClass::ScenarioBuildToolbar, WindowClass::None,
1136 _nested_build_road_scen_widgets,
1137 &BuildRoadToolbarWindow::road_hotkeys
1138);
1139
1140static constexpr std::initializer_list<NWidgetPart> _nested_build_tramway_scen_widgets = {
1145 EndContainer(),
1148 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_X_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1150 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_TRAMWAY_Y_DIR, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_SECTION),
1152 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_AUTOTRAM, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_AUTOTRAM),
1154 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
1155
1157
1159 SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_BRIDGE, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_BRIDGE),
1161 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_ROAD_TUNNEL, STR_ROAD_TOOLBAR_TOOLTIP_BUILD_TRAMWAY_TUNNEL),
1163 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_REMOVE, STR_ROAD_TOOLBAR_TOOLTIP_TOGGLE_BUILD_REMOVE_FOR_TRAMWAYS),
1165 SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_CONVERT_ROAD, STR_ROAD_TOOLBAR_TOOLTIP_CONVERT_TRAM),
1166 EndContainer(),
1167};
1168
1171 WindowPosition::Automatic, "toolbar_tram_scen", 0, 0,
1172 WindowClass::ScenarioBuildToolbar, WindowClass::None,
1174 _nested_build_tramway_scen_widgets,
1175 &BuildRoadToolbarWindow::tram_hotkeys
1176);
1177
1184{
1185 CloseWindowById(WindowClass::ScenarioBuildToolbar, TransportType::Road);
1186 _cur_roadtype = roadtype;
1187
1189}
1190
1191struct BuildRoadDepotWindow : public PickerWindowBase {
1192 BuildRoadDepotWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
1193 {
1194 this->CreateNestedTree();
1195
1196 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1197 if (RoadTypeIsTram(_cur_roadtype)) {
1198 this->GetWidget<NWidgetCore>(WID_BROD_CAPTION)->SetString(STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION);
1199 for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) {
1200 this->GetWidget<NWidgetCore>(i)->SetToolTip(STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP);
1201 }
1202 }
1203
1205 }
1206
1207 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1208 {
1209 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1210
1211 size.width = ScaleGUITrad(64) + WidgetDimensions::scaled.fullbevel.Horizontal();
1212 size.height = ScaleGUITrad(48) + WidgetDimensions::scaled.fullbevel.Vertical();
1213 }
1214
1215 void DrawWidget(const Rect &r, WidgetID widget) const override
1216 {
1217 if (!IsInsideMM(widget, WID_BROD_DEPOT_NE, WID_BROD_DEPOT_NW + 1)) return;
1218
1219 DrawPixelInfo tmp_dpi;
1220 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1221 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1222 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1223 int x = (ir.Width() - ScaleSpriteTrad(64)) / 2 + ScaleSpriteTrad(31);
1224 int y = (ir.Height() + ScaleSpriteTrad(48)) / 2 - ScaleSpriteTrad(31);
1225 DrawRoadDepotSprite(x, y, static_cast<DiagDirection>(widget - WID_BROD_DEPOT_NE + to_underlying(DiagDirection::NE)), _cur_roadtype);
1226 }
1227 }
1228
1229 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1230 {
1231 switch (widget) {
1232 case WID_BROD_DEPOT_NW:
1233 case WID_BROD_DEPOT_NE:
1234 case WID_BROD_DEPOT_SW:
1235 case WID_BROD_DEPOT_SE:
1236 this->RaiseWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1237 _road_depot_orientation = (DiagDirection)(widget - WID_BROD_DEPOT_NE);
1238 this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation);
1239 SndClickBeep();
1240 this->SetDirty();
1241 break;
1242
1243 default:
1244 break;
1245 }
1246 }
1247};
1248
1249static constexpr std::initializer_list<NWidgetPart> _nested_build_road_depot_widgets = {
1252 NWidget(WWT_CAPTION, Colours::DarkGreen, WID_BROD_CAPTION), SetStringTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1253 EndContainer(),
1257 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_NW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1258 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_SW), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1259 EndContainer(),
1261 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_NE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1262 NWidget(WWT_TEXTBTN, Colours::Grey, WID_BROD_DEPOT_SE), SetFill(0, 0), SetToolTip(STR_BUILD_DEPOT_ROAD_ORIENTATION_SELECT_TOOLTIP),
1263 EndContainer(),
1264 EndContainer(),
1265 EndContainer(),
1266};
1267
1270 WindowPosition::Automatic, {}, 0, 0,
1271 WindowClass::BuildDepot, WindowClass::BuildToolbar,
1273 _nested_build_road_depot_widgets
1274);
1275
1276static void ShowRoadDepotPicker(Window *parent)
1277{
1279}
1280
1281template <RoadStopType roadstoptype>
1282class RoadStopPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1283public:
1284 RoadStopPickerCallbacks(const std::string &ini_group) : PickerCallbacksNewGRFClass<RoadStopClass>(ini_group) {}
1285
1287
1288 StringID GetClassTooltip() const override;
1289 StringID GetTypeTooltip() const override;
1291
1292 bool IsActive() const override
1293 {
1294 for (const auto &cls : RoadStopClass::Classes()) {
1295 if (IsWaypointClass(cls)) continue;
1296 for (const auto *spec : cls.Specs()) {
1297 if (spec == nullptr) continue;
1298 if (roadstoptype == RoadStopType::Truck && spec->stop_type != ROADSTOPTYPE_FREIGHT && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1299 if (roadstoptype == RoadStopType::Bus && spec->stop_type != ROADSTOPTYPE_PASSENGER && spec->stop_type != ROADSTOPTYPE_ALL) continue;
1300 return true;
1301 }
1302 }
1303 return false;
1304 }
1305
1306 static bool IsClassChoice(const RoadStopClass &cls)
1307 {
1308 return !IsWaypointClass(cls) && GetIfClassHasNewStopsByType(&cls, roadstoptype, _cur_roadtype);
1309 }
1310
1311 bool HasClassChoice() const override
1312 {
1313 return std::ranges::count_if(RoadStopClass::Classes(), IsClassChoice);
1314 }
1315
1316 int GetSelectedClass() const override { return _roadstop_gui.sel_class.base(); }
1317 void SetSelectedClass(int id) const override { _roadstop_gui.sel_class = this->GetClassIndex(id); }
1318
1319 StringID GetClassName(int id) const override
1320 {
1321 const auto *rsc = this->GetClass(id);
1322 if (!IsClassChoice(*rsc)) return INVALID_STRING_ID;
1323 return rsc->name;
1324 }
1325
1326 int GetSelectedType() const override { return _roadstop_gui.sel_type; }
1327 void SetSelectedType(int id) const override { _roadstop_gui.sel_type = id; }
1328
1329 StringID GetTypeName(int cls_id, int id) const override
1330 {
1331 const auto *spec = this->GetSpec(cls_id, id);
1332 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return INVALID_STRING_ID;
1333 return (spec == nullptr) ? STR_STATION_CLASS_DFLT_ROADSTOP : spec->name;
1334 }
1335
1336 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1337 {
1338 const auto *spec = this->GetSpec(cls_id, id);
1339 if (!IsRoadStopEverAvailable(spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck)) return {};
1340 if (spec == nullptr) return {};
1341 return spec->badges;
1342 }
1343
1344 bool IsTypeAvailable(int cls_id, int id) const override
1345 {
1346 const auto *spec = this->GetSpec(cls_id, id);
1348 }
1349
1350 void DrawType(int x, int y, int cls_id, int id) const override
1351 {
1352 const auto *spec = this->GetSpec(cls_id, id);
1353 if (spec == nullptr) {
1354 StationPickerDrawSprite(x, y, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, INVALID_RAILTYPE, _cur_roadtype, to_underlying(_roadstop_gui.orientation));
1355 } else {
1356 DiagDirection orientation = _roadstop_gui.orientation;
1357 if (orientation < DiagDirection::End && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) orientation = DiagDirection::End;
1358 DrawRoadStopTile(x, y, _cur_roadtype, spec, roadstoptype == RoadStopType::Bus ? StationType::Bus : StationType::Truck, to_underlying(orientation));
1359 }
1360 }
1361
1362 void FillUsedItems(std::set<PickerItem> &items) override
1363 {
1364 for (const Station *st : Station::Iterate()) {
1365 if (st->owner != _local_company) continue;
1366 if (roadstoptype == RoadStopType::Truck && !st->facilities.Test(StationFacility::TruckStop)) continue;
1367 if (roadstoptype == RoadStopType::Bus && !st->facilities.Test(StationFacility::BusStop)) continue;
1368 items.insert({GrfID{}, 0, ROADSTOP_CLASS_DFLT.base(), 0}); // We would need to scan the map to find out if default is used.
1369 for (const auto &sm : st->roadstop_speclist) {
1370 if (sm.spec == nullptr) continue;
1371 if (roadstoptype == RoadStopType::Truck && sm.spec->stop_type != ROADSTOPTYPE_FREIGHT && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1372 if (roadstoptype == RoadStopType::Bus && sm.spec->stop_type != ROADSTOPTYPE_PASSENGER && sm.spec->stop_type != ROADSTOPTYPE_ALL) continue;
1373 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1374 }
1375 }
1376 }
1377};
1378
1379template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_BUS_CLASS_TOOLTIP; }
1380template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_BUS_TYPE_TOOLTIP; }
1381template <> StringID RoadStopPickerCallbacks<RoadStopType::Bus>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_BUS_COLLECTION_TOOLTIP; }
1382
1383template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetClassTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_CLASS_TOOLTIP; }
1384template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetTypeTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_TYPE_TOOLTIP; }
1385template <> StringID RoadStopPickerCallbacks<RoadStopType::Truck>::GetCollectionTooltip() const { return STR_PICKER_ROADSTOP_TRUCK_COLLECTION_TOOLTIP; }
1386
1387static RoadStopPickerCallbacks<RoadStopType::Bus> _bus_callback_instance("fav_passenger_roadstops");
1388static RoadStopPickerCallbacks<RoadStopType::Truck> _truck_callback_instance("fav_freight_roadstops");
1389
1390static PickerCallbacks &GetRoadStopPickerCallbacks(RoadStopType rs)
1391{
1392 return rs == RoadStopType::Bus ? static_cast<PickerCallbacks &>(_bus_callback_instance) : static_cast<PickerCallbacks &>(_truck_callback_instance);
1393}
1394
1395struct BuildRoadStationWindow : public PickerWindow {
1396private:
1398
1399 void CheckOrientationValid()
1400 {
1401 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1402
1403 /* Raise and lower to ensure the correct widget is lowered after changing displayed orientation plane. */
1404 if (RoadTypeIsRoad(_cur_roadtype)) {
1405 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1406 this->GetWidget<NWidgetStacked>(WID_BROS_AVAILABLE_ORIENTATIONS)->SetDisplayedPlane((spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) ? 1 : 0);
1407 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1408 }
1409
1410 if (_roadstop_gui.orientation >= DiagDirection::End) return;
1411
1412 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) {
1413 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1414 _roadstop_gui.orientation = DiagDirection::End;
1415 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1416 this->SetDirty();
1417 CloseWindowById(WindowClass::JoinStation, 0);
1418 }
1419 }
1420
1421public:
1422 BuildRoadStationWindow(WindowDesc &desc, Window *parent, RoadStopType rs) : PickerWindow(desc, parent, TransportType::Road, GetRoadStopPickerCallbacks(rs))
1423 {
1424 this->coverage_height = 2 * GetCharacterHeight(FontSize::Normal) + WidgetDimensions::scaled.vsep_normal;
1425
1426 /* Trams don't have non-drivethrough stations */
1427 if (RoadTypeIsTram(_cur_roadtype) && _roadstop_gui.orientation < DiagDirection::End) {
1428 _roadstop_gui.orientation = DiagDirection::End;
1429 }
1430 this->ConstructWindow();
1431
1432 const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype);
1433 this->GetWidget<NWidgetCore>(WID_BROS_CAPTION)->SetString(rti->strings.picker_title[rs]);
1434
1435 for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) {
1436 this->GetWidget<NWidgetCore>(i)->SetToolTip(rti->strings.picker_tooltip[rs]);
1437 }
1438
1439 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1441
1442 this->window_class = (rs == RoadStopType::Bus) ? WindowClass::BuildBusStation : WindowClass::BuildTruckStation;
1443 }
1444
1445 void Close([[maybe_unused]] int data = 0) override
1446 {
1447 CloseWindowById(WindowClass::JoinStation, 0);
1448 this->PickerWindow::Close();
1449 }
1450
1451 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1452 {
1453 this->PickerWindow::OnInvalidateData(data, gui_scope);
1454
1455 if (gui_scope) {
1456 this->CheckOrientationValid();
1457 }
1458 }
1459
1460 void OnPaint() override
1461 {
1462 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1463
1464 this->DrawWidgets();
1465
1466 int rad = _settings_game.station.modified_catchment ? ((this->window_class == WindowClass::BuildBusStation) ? CA_BUS : CA_TRUCK) : CA_UNMODIFIED;
1467 if (_settings_client.gui.station_show_coverage) {
1468 SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
1469 } else {
1470 SetTileSelectSize(1, 1);
1471 }
1472
1473 if (this->IsShaded()) return;
1474
1475 /* 'Accepts' and 'Supplies' texts. */
1476 StationCoverageType sct = (this->window_class == WindowClass::BuildBusStation) ? SCT_PASSENGERS_ONLY : SCT_NON_PASSENGERS_ONLY;
1477 Rect r = this->GetWidget<NWidgetBase>(WID_BROS_ACCEPTANCE)->GetCurrentRect();
1478 const int bottom = r.bottom;
1479 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
1480 if (spec != nullptr) r.top = DrawBadgeNameList(r, spec->badges, GrfSpecFeature::RoadStops);
1481 r.top = DrawStationCoverageAreaText(r, sct, rad, false) + WidgetDimensions::scaled.vsep_normal;
1482 r.top = DrawStationCoverageAreaText(r, sct, rad, true);
1483 /* Resize background if the window is too small.
1484 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
1485 * (This is the case, if making the window bigger moves the mouse into the window.) */
1486 if (r.top > bottom) {
1487 this->coverage_height += r.top - bottom;
1488 this->ReInit();
1489 }
1490 }
1491
1492 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
1493 {
1494 switch (widget) {
1499 case WID_BROS_STATION_X:
1500 case WID_BROS_STATION_Y:
1501 size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal();
1502 size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical();
1503 break;
1504
1506 size.height = this->coverage_height;
1507 break;
1508
1509 default:
1510 this->PickerWindow::UpdateWidgetSize(widget, size, padding, fill, resize);
1511 break;
1512 }
1513 }
1514
1521 {
1522 switch (window_class) {
1523 case WindowClass::BuildBusStation: return StationType::Bus;
1524 case WindowClass::BuildTruckStation: return StationType::Truck;
1525 default: NOT_REACHED();
1526 }
1527 }
1528
1529 void DrawWidget(const Rect &r, WidgetID widget) const override
1530 {
1531 switch (widget) {
1536 case WID_BROS_STATION_X:
1537 case WID_BROS_STATION_Y: {
1539 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1540 DrawPixelInfo tmp_dpi;
1541 Rect ir = r.Shrink(WidgetDimensions::scaled.bevel);
1542 if (FillDrawPixelInfo(&tmp_dpi, ir)) {
1543 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
1546 if (spec == nullptr) {
1547 StationPickerDrawSprite(x, y, st, INVALID_RAILTYPE, _cur_roadtype, widget - WID_BROS_STATION_NE);
1548 } else {
1549 DrawRoadStopTile(x, y, _cur_roadtype, spec, st, widget - WID_BROS_STATION_NE);
1550 }
1551 }
1552 break;
1553 }
1554
1555 default:
1556 this->PickerWindow::DrawWidget(r, widget);
1557 break;
1558 }
1559 }
1560
1561 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1562 {
1563 switch (widget) {
1568 case WID_BROS_STATION_X:
1569 case WID_BROS_STATION_Y:
1570 if (widget < WID_BROS_STATION_X) {
1571 const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui.sel_class)->GetSpec(_roadstop_gui.sel_type);
1572 if (spec != nullptr && spec->flags.Test(RoadStopSpecFlag::DriveThroughOnly)) return;
1573 }
1574 this->RaiseWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1575 _roadstop_gui.orientation = (DiagDirection)(widget - WID_BROS_STATION_NE);
1576 this->LowerWidget(WID_BROS_STATION_NE + _roadstop_gui.orientation);
1577 SndClickBeep();
1578 this->SetDirty();
1579 CloseWindowById(WindowClass::JoinStation, 0);
1580 break;
1581
1582 case WID_BROS_LT_OFF:
1583 case WID_BROS_LT_ON:
1584 this->RaiseWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1585 _settings_client.gui.station_show_coverage = (widget != WID_BROS_LT_OFF);
1586 this->LowerWidget(_settings_client.gui.station_show_coverage + WID_BROS_LT_OFF);
1587 SndClickBeep();
1588 this->SetDirty();
1589 SetViewportCatchmentStation(nullptr, true);
1590 break;
1591
1592 default:
1593 this->PickerWindow::OnClick(pt, widget, click_count);
1594 break;
1595 }
1596 }
1597
1598 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
1599 {
1601 }
1602
1603 static inline HotkeyList road_hotkeys{"buildroadstop", {
1604 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1605 }};
1606
1607 static inline HotkeyList tram_hotkeys{"buildtramstop", {
1608 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1609 }};
1610};
1611
1613static constexpr std::initializer_list<NWidgetPart> _nested_road_station_picker_widgets = {
1619 EndContainer(),
1626 /* 6-orientation plane. */
1632 EndContainer(),
1634 EndContainer(),
1639 EndContainer(),
1641 EndContainer(),
1642 EndContainer(),
1643 /* 2-orientation plane. */
1648 EndContainer(),
1649 EndContainer(),
1650 EndContainer(),
1651 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1654 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1656 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1657 EndContainer(),
1659 EndContainer(),
1660 EndContainer(),
1661 EndContainer(),
1663 EndContainer(),
1664};
1665
1668 WindowPosition::Automatic, "build_station_road", 0, 0,
1669 WindowClass::BuildBusStation, WindowClass::BuildToolbar,
1672 &BuildRoadStationWindow::road_hotkeys
1673);
1674
1676static constexpr std::initializer_list<NWidgetPart> _nested_tram_station_picker_widgets = {
1682 EndContainer(),
1691 EndContainer(),
1692 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
1695 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
1697 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
1698 EndContainer(),
1700 EndContainer(),
1701 EndContainer(),
1702 EndContainer(),
1704 EndContainer(),
1705};
1706
1709 WindowPosition::Automatic, "build_station_tram", 0, 0,
1710 WindowClass::BuildBusStation, WindowClass::BuildToolbar,
1713 &BuildRoadStationWindow::tram_hotkeys
1714);
1715
1716static void ShowRVStationPicker(Window *parent, RoadStopType rs)
1717{
1718 new BuildRoadStationWindow(RoadTypeIsRoad(_cur_roadtype) ? _road_station_picker_desc : _tram_station_picker_desc, parent, rs);
1719}
1720
1721class RoadWaypointPickerCallbacks : public PickerCallbacksNewGRFClass<RoadStopClass> {
1722public:
1723 RoadWaypointPickerCallbacks() : PickerCallbacksNewGRFClass<RoadStopClass>("fav_road_waypoints") {}
1724
1726
1727 StringID GetClassTooltip() const override { return STR_PICKER_WAYPOINT_CLASS_TOOLTIP; }
1728 StringID GetTypeTooltip() const override { return STR_PICKER_WAYPOINT_TYPE_TOOLTIP; }
1729 StringID GetCollectionTooltip() const override { return STR_PICKER_WAYPOINT_COLLECTION_TOOLTIP; }
1730
1731 bool IsActive() const override
1732 {
1733 for (const auto &cls : RoadStopClass::Classes()) {
1734 if (!IsWaypointClass(cls)) continue;
1735 for (const auto *spec : cls.Specs()) {
1736 if (spec != nullptr) return true;
1737 }
1738 }
1739 return false;
1740 }
1741
1742 bool HasClassChoice() const override
1743 {
1744 return std::ranges::count_if(RoadStopClass::Classes(), [](const auto &cls) { return IsWaypointClass(cls); }) > 1;
1745 }
1746
1747 void Close(int) override { ResetObjectToPlace(); }
1748 int GetSelectedClass() const override { return _waypoint_gui.sel_class.base(); }
1749 void SetSelectedClass(int id) const override { _waypoint_gui.sel_class = this->GetClassIndex(id); }
1750
1751 StringID GetClassName(int id) const override
1752 {
1753 const auto *sc = GetClass(id);
1754 if (!IsWaypointClass(*sc)) return INVALID_STRING_ID;
1755 return sc->name;
1756 }
1757
1758 int GetSelectedType() const override { return _waypoint_gui.sel_type; }
1759 void SetSelectedType(int id) const override { _waypoint_gui.sel_type = id; }
1760
1761 StringID GetTypeName(int cls_id, int id) const override
1762 {
1763 const auto *spec = this->GetSpec(cls_id, id);
1764 return (spec == nullptr) ? STR_STATION_CLASS_WAYP_WAYPOINT : spec->name;
1765 }
1766
1767 std::span<const BadgeID> GetTypeBadges(int cls_id, int id) const override
1768 {
1769 const auto *spec = this->GetSpec(cls_id, id);
1770 if (spec == nullptr) return {};
1771 return spec->badges;
1772 }
1773
1774 bool IsTypeAvailable(int cls_id, int id) const override
1775 {
1776 return IsRoadStopAvailable(this->GetSpec(cls_id, id), StationType::RoadWaypoint);
1777 }
1778
1779 void DrawType(int x, int y, int cls_id, int id) const override
1780 {
1781 const auto *spec = this->GetSpec(cls_id, id);
1782 if (spec == nullptr) {
1783 StationPickerDrawSprite(x, y, StationType::RoadWaypoint, INVALID_RAILTYPE, _cur_roadtype, RSV_DRIVE_THROUGH_X);
1784 } else {
1786 }
1787 }
1788
1789 void FillUsedItems(std::set<PickerItem> &items) override
1790 {
1791 for (const Waypoint *wp : Waypoint::Iterate()) {
1792 if (wp->owner != _local_company || !HasBit(wp->waypoint_flags, WPF_ROAD)) continue;
1793 items.insert({GrfID{}, 0, ROADSTOP_CLASS_WAYP.base(), 0}); // We would need to scan the map to find out if default is used.
1794 for (const auto &sm : wp->roadstop_speclist) {
1795 if (sm.spec == nullptr) continue;
1796 items.insert({sm.grfid, sm.localidx, sm.spec->class_index.base(), sm.spec->index});
1797 }
1798 }
1799 }
1800
1801 static RoadWaypointPickerCallbacks instance;
1802};
1803/* static */ RoadWaypointPickerCallbacks RoadWaypointPickerCallbacks::instance;
1804
1805struct BuildRoadWaypointWindow : public PickerWindow {
1806 BuildRoadWaypointWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, TransportType::Road, RoadWaypointPickerCallbacks::instance)
1807 {
1808 this->ConstructWindow();
1809 }
1810
1811 static inline HotkeyList hotkeys{"buildroadwaypoint", {
1812 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1813 }};
1814};
1815
1829
1832 WindowPosition::Automatic, "build_road_waypoint", 0, 0,
1833 WindowClass::BuildWaypoint, WindowClass::BuildToolbar,
1836 &BuildRoadWaypointWindow::hotkeys
1837);
1838
1839static void ShowBuildRoadWaypointPicker(Window *parent)
1840{
1841 if (!RoadWaypointPickerCallbacks::instance.IsActive()) return;
1843}
1844
1845void InitializeRoadGui()
1846{
1847 _road_depot_orientation = DiagDirection::NW;
1848 _roadstop_gui.orientation = DiagDirection::NW;
1850 _waypoint_gui.sel_type = 0;
1851}
1852
1853DropDownList GetRoadTypeDropDownList(RoadTramTypes rtts, bool for_replacement, bool all_option)
1854{
1855 RoadTypes used_roadtypes;
1856 RoadTypes avail_roadtypes;
1857
1859
1860 /* Find the used roadtypes. */
1861 if (for_replacement) {
1862 avail_roadtypes = GetCompanyRoadTypes(c->index, false);
1863 used_roadtypes = GetRoadTypes(false);
1864 } else {
1865 avail_roadtypes = c->avail_roadtypes;
1866 used_roadtypes = GetRoadTypes(true);
1867 }
1868
1869 /* Filter listed road types */
1872
1873 DropDownList list;
1874
1875 if (all_option) {
1876 list.push_back(MakeDropDownListStringItem(STR_REPLACE_ALL_ROADTYPE, INVALID_ROADTYPE));
1877 }
1878
1879 Dimension d = { 0, 0 };
1880 /* Get largest icon size, to ensure text is aligned on each menu item. */
1881 if (!for_replacement) {
1882 used_roadtypes.Reset(_roadtypes_hidden_mask);
1883 for (const auto &rt : _sorted_roadtypes) {
1884 if (!used_roadtypes.Test(rt)) continue;
1885 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1887 }
1888 }
1889
1890 /* Shared list so that each item can take ownership. */
1891 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GrfSpecFeature::RoadTypes);
1892
1893 for (const auto &rt : _sorted_roadtypes) {
1894 /* If it's not used ever, don't show it to the user. */
1895 if (!used_roadtypes.Test(rt)) continue;
1896
1897 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1898
1899 if (for_replacement) {
1900 list.push_back(MakeDropDownListBadgeItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, GetString(rti->strings.replace_text), rt, !avail_roadtypes.Test(rt)));
1901 } else {
1902 std::string str = rti->max_speed > 0
1903 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1904 : GetString(rti->strings.menu_text);
1905 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1906 }
1907 }
1908
1909 if (list.empty()) {
1910 /* Empty dropdowns are not allowed */
1911 list.push_back(MakeDropDownListStringItem(STR_NONE, INVALID_ROADTYPE, true));
1912 }
1913
1914 return list;
1915}
1916
1917DropDownList GetScenRoadTypeDropDownList(RoadTramTypes rtts)
1918{
1919 RoadTypes avail_roadtypes = GetRoadTypes(false);
1920 avail_roadtypes = AddDateIntroducedRoadTypes(avail_roadtypes, TimerGameCalendar::date);
1921 RoadTypes used_roadtypes = GetRoadTypes(true);
1922
1923 /* Filter listed road types */
1924 used_roadtypes.Reset(_roadtypes_hidden_mask);
1927
1928 DropDownList list;
1929
1930 /* If it's not used ever, don't show it to the user. */
1931 Dimension d = { 0, 0 };
1932 for (const auto &rt : _sorted_roadtypes) {
1933 if (!used_roadtypes.Test(rt)) continue;
1934 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1936 }
1937
1938 /* Shared list so that each item can take ownership. */
1939 auto badge_class_list = std::make_shared<GUIBadgeClasses>(GrfSpecFeature::RoadTypes);
1940
1941 for (const auto &rt : _sorted_roadtypes) {
1942 if (!used_roadtypes.Test(rt)) continue;
1943
1944 const RoadTypeInfo *rti = GetRoadTypeInfo(rt);
1945
1946 std::string str = rti->max_speed > 0
1947 ? GetString(STR_TOOLBAR_ROADTYPE_VELOCITY, rti->strings.menu_text, rti->max_speed / 2)
1948 : GetString(rti->strings.menu_text);
1949 list.push_back(MakeDropDownListBadgeIconItem(badge_class_list, rti->badges, GrfSpecFeature::RoadTypes, rti->introduction_date, RoadBuildCost(rt), d, rti->gui_sprites.build_x_road, PAL_NONE, std::move(str), rt, !avail_roadtypes.Test(rt)));
1950 }
1951
1952 if (list.empty()) {
1953 /* Empty dropdowns are not allowed */
1954 list.push_back(MakeDropDownListStringItem(STR_NONE, -1, true));
1955 }
1956
1957 return list;
1958}
1959
1966{
1967 const auto find_available = [rtt]<typename It>(It begin, It end) {
1968 const RoadTypes mask = GetMaskForRoadTramType(rtt);
1969 auto it = std::find_if(begin, end, [&](RoadType r) {
1970 return HasRoadTypeAvail(_local_company, r) && mask.Test(r);
1971 });
1972 return it != end ? *it : ROADTYPE_BEGIN;
1973 };
1974
1975 switch (_settings_client.gui.default_rail_road_type) {
1978 std::array<uint, ROADTYPE_END> count{};
1979 for (RoadType rt : GetMaskForRoadTramType(rtt)) {
1980 count[rt] = c->infrastructure.road[rt];
1981 }
1982 auto best = static_cast<RoadType>(std::distance(std::begin(count), std::ranges::max_element(count)));
1983 if (c->infrastructure.road[best] > 0) return best;
1984
1985 /* No tile of this kind has been built yet, fall through to first available. */
1986 [[fallthrough]];
1987 }
1989 return find_available(_sorted_roadtypes.begin(), _sorted_roadtypes.end());
1991 return find_available(_sorted_roadtypes.rbegin(), _sorted_roadtypes.rend());
1992 default:
1993 NOT_REACHED();
1994 }
1995}
1996
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, RailType railtype, RoadType roadtype)
Prepare the data for the build a bridge window.
bool IsBridgeTile(Tile t)
checks if there is a bridge on this tile
Definition bridge_map.h:35
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Reset()
Reset all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
static std::span< NewGRFClass< RoadStopSpec, RoadStopClassID > const > Classes()
static NewGRFClass * Get(RoadStopClassID class_index)
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
uint16_t h
The height of the area.
RoadStopClass::index_type GetClassIndex(int cls_id) const
Definition picker_gui.h:242
const RoadStopClass * GetClass(int cls_id) const
Definition picker_gui.h:249
PickerCallbacksNewGRFClass(const std::string &ini_group)
Definition picker_gui.h:235
const RoadStopClass::spec_type * GetSpec(int cls_id, int id) const
Definition picker_gui.h:257
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:49
const std::string ini_group
Ini Group for saving favourites.
Definition picker_gui.h:214
static constexpr int PREVIEW_WIDTH
Width of each preview button.
Definition picker_gui.h:339
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static constexpr int PREVIEW_HEIGHT
Height of each preview button.
Definition picker_gui.h:340
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static constexpr int PREVIEW_LEFT
Offset from left edge to draw preview.
Definition picker_gui.h:341
static constexpr int PREVIEW_BOTTOM
Offset from bottom edge to draw preview.
Definition picker_gui.h:342
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:373
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void SetSelectedType(int id) const override
Set the selected type.
bool HasClassChoice() const override
Are there multiple classes to chose from?
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
StringID GetClassName(int id) const override
Get the name of a class.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
void SetSelectedClass(int id) const override
Set the selected class.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
int GetSelectedClass() const override
Get the index of the selected class.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item's badges of a type.
StringID GetTypeName(int cls_id, int id) const override
Get the item name of a type.
bool IsActive() const override
Should picker class/type selection be enabled?
GrfSpecFeature GetFeature() const override
NewGRF feature this picker is for.
int GetSelectedType() const override
Get the selected type.
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
StringID menu_text
Name of this rail type in the main toolbar dropdown.
Definition road.h:81
StringID replace_text
Text used in the autoreplace GUI.
Definition road.h:83
struct RoadTypeInfo::@040007041145073342004320043002073006000034160103 gui_sprites
struct containing the sprites for the road GUI.
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_build_station
Building a bus or truck station.
Definition road.h:89
struct RoadTypeInfo::@262365004142063215107272155332373126354130071373 cursor
Cursors associated with the road type.
CursorID autoroad
Cursor for autorail tool.
Definition road.h:72
TimerGameCalendar::Date introduction_date
Introduction date.
Definition road.h:142
StringID err_build_road
Building a normal piece of road.
Definition road.h:86
StringID err_remove_road
Removing a normal piece of road.
Definition road.h:87
CursorID depot
Cursor for building a depot.
Definition road.h:73
CursorID road_nwse
Cursor for building rail in Y direction.
Definition road.h:71
uint16_t max_speed
Maximum speed for vehicles travelling on this road type.
Definition road.h:118
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_title
Title for the station picker for bus or truck stations.
Definition road.h:93
struct RoadTypeInfo::@070000167274302256150317022075324310363002361255 strings
Strings associated with the rail type.
StringID toolbar_caption
Caption in the construction toolbar GUI for this rail type.
Definition road.h:80
SpriteID build_y_road
button for building single rail in Y direction
Definition road.h:62
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > picker_tooltip
Tooltip for the station picker for bus or truck stations.
Definition road.h:94
CursorID tunnel
Cursor for building a tunnel.
Definition road.h:74
SpriteID auto_road
button for the autoroad construction
Definition road.h:63
SpriteID convert_road
button for converting road types
Definition road.h:66
CursorID road_swne
Cursor for building rail in X direction.
Definition road.h:70
StringID err_convert_road
Converting a road type.
Definition road.h:91
StringID err_depot
Building a depot.
Definition road.h:88
SpriteID build_x_road
button for building single rail in X direction
Definition road.h:61
SpriteID build_depot
button for building depots
Definition road.h:64
SpriteID build_tunnel
button for building a tunnel
Definition road.h:65
EnumIndexArray< StringID, RoadStopType, RoadStopType::End > err_remove_station
Removing of a bus or truck station.
Definition road.h:90
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
int GetSelectedType() const override
Get the selected type.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item's badges of a type.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void DrawType(int x, int y, int cls_id, int id) const override
Draw preview image of an item.
bool IsActive() const override
Should picker class/type selection be enabled?
bool IsTypeAvailable(int cls_id, int id) const override
Test if an item is currently buildable.
void SetSelectedType(int id) const override
Set the selected type.
void Close(int) override
Hide the window and all its child windows, and mark them for a later deletion.
StringID GetCollectionTooltip() const override
Get the tooltip string for the collection list.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
StringID GetTypeName(int cls_id, int id) const override
Get the item name of a type.
StringID GetClassName(int id) const override
Get the name of a class.
void SetSelectedClass(int id) const override
Set the selected class.
int GetSelectedClass() const override
Get the index of the selected class.
GrfSpecFeature GetFeature() const override
NewGRF feature this picker is for.
bool HasClassChoice() const override
Are there multiple classes to chose from?
static Date date
Current date in days (day counter).
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Definition command.cpp:112
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
@ Auto
don't allow building on structures
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Axis
Enumeration for the two axis X and Y.
@ X
The X axis.
@ Invalid
Flag for an invalid Axis.
@ Y
The y axis.
DiagDirection
Enumeration for diagonal directions.
@ NW
Northwest.
@ End
Used for iterations.
@ NE
Northeast, upper right on your monitor.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
void SetCursor(CursorID icon, PaletteID pal)
Assign an animation or a non-animated sprite to the cursor.
Definition gfx.cpp:1732
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:1567
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
uint32_t CursorID
The number of the cursor (sprite).
Definition gfx_type.h:19
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ DarkGreen
Dark green.
Definition gfx_type.h:292
@ White
White colour.
Definition gfx_type.h:330
@ WKC_R_BRACKET
] Right square bracket
Definition gfx_type.h:102
@ WKC_L_BRACKET
[ Left square bracket
Definition gfx_type.h:100
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1694
static const CursorID SPR_CURSOR_BRIDGE
Definition sprites.h:1600
static const CursorID SPR_CURSOR_BUS_STATION
Definition sprites.h:1658
static const CursorID SPR_CURSOR_WAYPOINT
Definition sprites.h:1636
static const CursorID SPR_CURSOR_TRUCK_STATION
Definition sprites.h:1659
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
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:108
SpecialListHotkeys
Indexes for special hotkeys to navigate in lists.
Definition hotkeys.h:91
@ NextItem
Hotkey to select next item in the list.
Definition hotkeys.h:93
@ FirstItem
Hotkey to select first item in the list.
Definition hotkeys.h:94
@ LastItem
Hotkey to select last item in the list.
Definition hotkeys.h:95
@ PreviousItem
Hotkey to select previous item in the list.
Definition hotkeys.h:92
bool IsSpecialHotkey(const int &hotkey)
Checks if hotkey index is special or not.
Definition hotkeys.h:82
@ Road
Road livery schemes.
Definition livery.h:70
#define Point
Macro that prevents name conflicts between included headers.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:58
static TileIndex TileVirtXY(uint x, uint y)
Get a tile from the virtual XY-coordinate.
Definition map_func.h:407
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:574
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
GrfSpecFeature
Definition newgrf.h:81
@ RoadStops
Road stops feature.
Definition newgrf.h:102
@ RoadTypes
Road types feature.
Definition newgrf.h:100
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
@ CBID_STATION_AVAILABILITY
Determine whether a newstation should be made available to build.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ Avail
Availability of road stop in construction window.
bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
@ Any
Use first found.
bool GetIfClassHasNewStopsByType(const RoadStopClass *roadstopclass, RoadStopType rs, RoadType roadtype)
Checks if the given RoadStopClass has any specs assigned to it, compatible with the given RoadStopTyp...
void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
Draw representation of a road stop tile for GUI purposes.
NewGRF definitions and structures for road stops.
bool IsWaypointClass(const RoadStopClass &cls)
Test if a RoadStopClass is the waypoint class.
PoolID< uint16_t, struct RoadStopClassIDTag, UINT16_MAX, UINT16_MAX > RoadStopClassID
Class IDs for stations.
static constexpr RoadStopClassID ROADSTOP_CLASS_DFLT
Default road stop class.
static constexpr RoadStopClassID ROADSTOP_CLASS_WAYP
Waypoint class.
@ ROADSTOPTYPE_FREIGHT
This RoadStop is for freight (truck) stops.
@ ROADSTOPTYPE_ALL
This RoadStop is for both types of station road stops.
@ ROADSTOPTYPE_PASSENGER
This RoadStop is for passenger (bus) stops.
@ RSV_DRIVE_THROUGH_X
Drive through road stop, X axis.
@ NoAutoRoadConnection
No auto road connection.
@ RoadOnly
Only show in the road build menu (not tram).
@ TramOnly
Only show in the tram build menu (not road).
@ DriveThroughOnly
Stop is drive-through only.
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Definition newgrf_type.h:17
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Normal
Playing a game.
Definition openttd.h:20
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Functions/types etc.
static bool _remove_button_clicked
Flag whether 'remove' toggle-button is currently enabled.
Definition rail_gui.cpp:58
static WaypointPickerSelection _waypoint_gui
Settings of the waypoint picker.
Definition rail_gui.cpp:68
@ INVALID_RAILTYPE
Flag for invalid railtype.
Definition rail_type.h:33
RoadTypes GetCompanyRoadTypes(CompanyID company, bool introduces)
Get the road types the given company can build.
Definition road.cpp:209
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:237
bool ValParamRoadType(RoadType roadtype)
Validate functions for rail building.
Definition road.cpp:164
RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date date)
Add the road types that are to be introduced at the given date.
Definition road.cpp:176
bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
Finds out, whether given company has a given RoadType available for construction.
Definition road.cpp:122
RoadTypes _roadtypes_hidden_mask
Bitset of hidden roadtypes.
Definition road_cmd.cpp:57
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:185
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
Definition road.h:217
std::vector< RoadType > _sorted_roadtypes
Sorted list of road types.
Definition road_cmd.cpp:56
Money RoadBuildCost(RoadType roadtype)
Returns the cost of building the specified roadtype.
Definition road.h:242
void DrawRoadDepotSprite(int x, int y, DiagDirection dir, RoadType rt)
Draw the road depot sprite.
Road related functions.
void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
Command callback for building road stops.
Definition road_gui.cpp:198
RoadBits DiagDirToRoadBits(DiagDirection d)
Create the road-part which belongs to the given DiagDirection.
Definition road_func.h:78
static WindowDesc _build_road_scen_desc(WindowPosition::Automatic, "toolbar_road_scen", 0, 0, WindowClass::ScenarioBuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_road_scen_widgets, &BuildRoadToolbarWindow::road_hotkeys)
Window definition for the road toolbar of the scenario editor.
static WindowDesc _build_tramway_scen_desc(WindowPosition::Automatic, "toolbar_tram_scen", 0, 0, WindowClass::ScenarioBuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_tramway_scen_widgets, &BuildRoadToolbarWindow::tram_hotkeys)
Window definition for the tram toolbar of the scenario editor.
static constexpr std::initializer_list< NWidgetPart > _nested_build_road_waypoint_widgets
Nested widget definition for the build NewGRF road waypoint window.
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
void CcRoadStop(Commands, const CommandCost &result, TileIndex tile, uint8_t width, uint8_t length, RoadStopType, bool is_drive_through, DiagDirection dir, RoadType, RoadStopClassID spec_class, uint16_t spec_index, StationID, bool)
Command callback for building road stops.
Definition road_gui.cpp:198
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:232
static void PlaceRoad_TruckStation(TileIndex tile)
Callback for placing a truck station.
Definition road_gui.cpp:299
static constexpr std::initializer_list< NWidgetPart > _nested_tram_station_picker_widgets
Widget definition of the build tram station window.
static WindowDesc _build_road_depot_desc(WindowPosition::Automatic, {}, 0, 0, WindowClass::BuildDepot, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_road_depot_widgets)
Window definition for the build road depot window.
static bool IsRoadStopAvailable(const RoadStopSpec *spec, StationType type)
Check whether a road stop type can be built.
Definition road_gui.cpp:104
static RoadType GetDefaultRoadType(RoadTramType rtt)
Determine the default road type to use for a given RoadTramType.
static WindowDesc _build_road_waypoint_desc(WindowPosition::Automatic, "build_road_waypoint", 0, 0, WindowClass::BuildWaypoint, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_build_road_waypoint_widgets, &BuildRoadWaypointWindow::hotkeys)
Window definition for the build road waypoint window.
static void PlaceRoad_Bridge(TileIndex tile, Window *w)
Callback to start placing a bridge.
Definition road_gui.cpp:127
static WindowDesc _road_station_picker_desc(WindowPosition::Automatic, "build_station_road", 0, 0, WindowClass::BuildBusStation, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_road_station_picker_widgets, &BuildRoadStationWindow::road_hotkeys)
Window definition for the build road station window.
static constexpr std::initializer_list< NWidgetPart > _nested_road_station_picker_widgets
Widget definition of the build road station window.
static void PlaceRoad_BusStation(TileIndex tile)
Callback for placing a bus station.
Definition road_gui.cpp:281
static void PlaceRoad_Waypoint(TileIndex tile)
Place a road waypoint.
Definition road_gui.cpp:258
static void ToggleRoadButton_Remove(Window *w)
Toggles state of the Remove button of Build road toolbar.
Definition road_gui.cpp:319
void SetDefaultRoadGui()
Set the initial (default) road & tram type to use.
static WindowDesc _build_road_desc(WindowPosition::Manual, "toolbar_road", 0, 0, WindowClass::BuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_road_widgets, &BuildRoadToolbarWindow::road_hotkeys)
Window definition for the road toolbar.
static RoadWaypointPickerSelection _waypoint_gui
Settings of the road waypoint picker.
Definition road_gui.cpp:74
static bool RoadToolbar_CtrlChanged(Window *w)
Updates the Remove button because of Ctrl state change.
Definition road_gui.cpp:332
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
static WindowDesc _tram_station_picker_desc(WindowPosition::Automatic, "build_station_tram", 0, 0, WindowClass::BuildBusStation, WindowClass::BuildToolbar, WindowDefaultFlag::Construction, _nested_tram_station_picker_widgets, &BuildRoadStationWindow::tram_hotkeys)
Window definition for the build tram station window.
void CcBuildRoadTunnel(Commands, const CommandCost &result, TileIndex start_tile)
Callback executed after a build road tunnel command has been called.
Definition road_gui.cpp:144
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:166
static WindowDesc _build_tramway_desc(WindowPosition::Manual, "toolbar_tramway", 0, 0, WindowClass::BuildToolbar, WindowClass::None, WindowDefaultFlag::Construction, _nested_build_tramway_widgets, &BuildRoadToolbarWindow::tram_hotkeys)
Window definition for the tram toolbar.
Functions/types related to the road GUIs.
RoadBits GetRoadBits(Tile t, RoadTramType rtt)
Get the present road bits for a specific road type.
Definition road_map.h:112
static bool IsNormalRoadTile(Tile t)
Return whether a tile is a normal road tile.
Definition road_map.h:58
EnumBitSet< RoadTramType, uint8_t > RoadTramTypes
Bitset of RoadTramType elements.
Definition road_type.h:46
EnumBitSet< RoadType, uint64_t > RoadTypes
Bitset of RoadType elements.
Definition road_type.h:33
@ Northbound
All northbound traffic is disallowed.
Definition road_type.h:80
EnumBitSet< DisallowedRoadDirection, uint8_t > DisallowedRoadDirections
Bitset of DisallowedRoadDirection elements.
Definition road_type.h:85
RoadType
The different roadtypes we support.
Definition road_type.h:24
@ INVALID_ROADTYPE
flag for invalid roadtype
Definition road_type.h:29
@ ROADTYPE_BEGIN
Used for iterations.
Definition road_type.h:25
RoadTramType
The different types of road type.
Definition road_type.h:38
@ Tram
Tram type.
Definition road_type.h:40
@ Road
Road type.
Definition road_type.h:39
Types related to the road widgets.
@ WID_BROS_LT_ON
Turn on area highlight.
Definition road_widget.h:53
@ WID_BROS_ACCEPTANCE
Station acceptance info.
Definition road_widget.h:54
@ WID_BROS_STATION_SW
Terminal station with SW entry.
Definition road_widget.h:48
@ WID_BROS_STATION_X
Drive-through station in x-direction.
Definition road_widget.h:50
@ WID_BROS_STATION_NE
Terminal station with NE entry.
Definition road_widget.h:46
@ WID_BROS_STATION_SE
Terminal station with SE entry.
Definition road_widget.h:47
@ WID_BROS_CAPTION
Caption of the window.
Definition road_widget.h:45
@ WID_BROS_AVAILABLE_ORIENTATIONS
Selection for selecting 6 or 2 orientations.
Definition road_widget.h:55
@ WID_BROS_STATION_NW
Terminal station with NW entry.
Definition road_widget.h:49
@ WID_BROS_STATION_Y
Drive-through station in y-direction.
Definition road_widget.h:51
@ WID_BROS_LT_OFF
Turn off area highlight.
Definition road_widget.h:52
RoadToolbarWidgets
Widgets of the BuildRoadToolbarWindow class.
Definition road_widget.h:14
@ WID_ROT_BUILD_BRIDGE
Build bridge.
Definition road_widget.h:26
@ WID_ROT_BUS_STATION
Build bus station.
Definition road_widget.h:23
@ WID_ROT_DEPOT
Build depot.
Definition road_widget.h:21
@ WID_ROT_CAPTION
Caption of the window.
Definition road_widget.h:16
@ WID_ROT_BUILD_WAYPOINT
Build waypoint.
Definition road_widget.h:22
@ WID_ROT_ROAD_Y
Build road in y-direction.
Definition road_widget.h:18
@ WID_ROT_AUTOROAD
Autorail.
Definition road_widget.h:19
@ WID_ROT_DEMOLISH
Demolish.
Definition road_widget.h:20
@ WID_ROT_BUILD_TUNNEL
Build tunnel.
Definition road_widget.h:27
@ WID_ROT_TRUCK_STATION
Build truck station.
Definition road_widget.h:24
@ WID_ROT_CONVERT_ROAD
Convert road.
Definition road_widget.h:29
@ WID_ROT_REMOVE
Remove road.
Definition road_widget.h:28
@ WID_ROT_ONE_WAY
Build one-way road.
Definition road_widget.h:25
@ WID_ROT_ROAD_X
Build road in x-direction.
Definition road_widget.h:17
@ WID_BROD_DEPOT_SE
Depot with SE entry.
Definition road_widget.h:37
@ WID_BROD_DEPOT_NE
Depot with NE entry.
Definition road_widget.h:36
@ WID_BROD_CAPTION
Caption of the window.
Definition road_widget.h:35
@ WID_BROD_DEPOT_NW
Depot with NW entry.
Definition road_widget.h:39
@ WID_BROD_DEPOT_SW
Depot with SW entry.
Definition road_widget.h:38
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
@ LastAvailable
Use the latest available to the player.
@ FirstAvailable
Use the first available to the player.
@ MostUsed
Use the most used by the company controlled by the player.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:252
Functions related to sound.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:76
static const SpriteID SPR_IMG_ROAD_TUNNEL
Definition sprites.h:1485
static const SpriteID SPR_IMG_DYNAMITE
Definition sprites.h:1236
static const SpriteID SPR_IMG_AUTOTRAM
Definition sprites.h:1490
static const SpriteID SPR_IMG_REMOVE
Definition sprites.h:1486
static const SpriteID SPR_IMG_TRAMWAY_Y_DIR
Definition sprites.h:1488
static const SpriteID SPR_IMG_AUTOROAD
Definition sprites.h:1480
static const SpriteID SPR_IMG_TRUCK_BAY
Definition sprites.h:1483
static const SpriteID SPR_IMG_ROAD_ONE_WAY
Definition sprites.h:1487
static const SpriteID SPR_IMG_BUS_STATION
Definition sprites.h:1482
static const SpriteID SPR_IMG_CONVERT_ROAD
Definition sprites.h:1492
static const SpriteID SPR_IMG_ROAD_X_DIR
Definition sprites.h:1479
static const SpriteID SPR_IMG_ROAD_DEPOT
Definition sprites.h:1481
static const SpriteID SPR_IMG_ROAD_Y_DIR
Definition sprites.h:1478
static const SpriteID SPR_IMG_BRIDGE
Definition sprites.h:1484
static const SpriteID SPR_IMG_TRAMWAY_X_DIR
Definition sprites.h:1489
static const SpriteID SPR_IMG_WAYPOINT
Definition sprites.h:1509
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:20
@ SCT_NON_PASSENGERS_ONLY
Draw all non-passenger class cargoes.
Definition station_gui.h:22
@ SCT_PASSENGERS_ONLY
Draw only passenger class cargoes.
Definition station_gui.h:21
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:423
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.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
uint coverage_height
Height of the coverage texts.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
StationType GetRoadStationTypeByWindowClass(WindowClass window_class) const
Simply to have a easier way to get the StationType for bus, truck and trams from the WindowClass.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition road_gui.cpp:731
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition road_gui.cpp:463
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition road_gui.cpp:895
HighLightStyle GetHighLightStyleForWidget(WidgetID widget)
Returns corresponding high light style for provided button.
Definition road_gui.cpp:560
CursorID GetCursorForWidget(WidgetID widget)
Returns corresponding cursor for provided button.
Definition road_gui.cpp:537
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:752
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:367
static EventState RoadTramToolbarGlobalHotkeys(int hotkey, RoadType last_build, RoadTramType rtt)
Handler for global hotkeys of the BuildRoadToolbarWindow.
Definition road_gui.cpp:907
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:669
EventState ChangeRoadTypeOnHotkey(int hotkey)
Selects new RoadType based on SpecialHotkeys and order defined in _sorted_roadtypes.
Definition road_gui.cpp:638
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition road_gui.cpp:662
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:883
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition road_gui.cpp:435
RoadType roadtype
Road type to build.
Definition road_gui.cpp:349
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:796
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:578
void UpdateOptionWidgetStatus(RoadToolbarWidgets clicked_widget)
Update the remove button lowered state of the road toolbar.
Definition road_gui.cpp:482
EventState OnCTRLStateChange() override
The state of the control key has changed.
Definition road_gui.cpp:889
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:791
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition road_gui.cpp:379
bool ModifyRoadType(RoadType roadtype)
Switch to another road type.
Definition road_gui.cpp:454
WidgetID last_started_action
Last started user action.
Definition road_gui.cpp:350
GUISettings gui
settings related to the GUI
std::array< uint32_t, ROADTYPE_END > road
Count of company owned track bits for each road type.
CompanyInfrastructure infrastructure
NOSAVE: Counts of company owned infrastructure.
RoadTypes avail_roadtypes
Road types available to this company.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
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:44
All data for a single hotkey.
Definition hotkeys.h:20
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:77
DiagDirection orientation
Selected orientation of the road stop.
Definition road_gui.cpp:79
uint16_t sel_type
Selected road stop type within the class.
Definition road_gui.cpp:78
Road stop specification.
CargoGRFFileProps grf_prop
Link to NewGRF.
RoadStopClassID sel_class
Selected road waypoint class.
Definition road_gui.cpp:71
uint16_t sel_type
Selected road waypoint type within the class.
Definition road_gui.cpp:72
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Station data structure.
Representation of a waypoint.
High level window description.
Definition window_gui.h:171
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:818
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
Window * parent
Parent window.
Definition window_gui.h:327
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:468
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
WindowClass window_class
Window class.
Definition window_gui.h:300
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:409
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:539
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:561
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:869
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:579
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:449
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:100
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSetPresizeRange(TileIndex from, TileIndex to)
Highlights all tiles between a set of two tiles.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
void VpStartPlaceSizing(TileIndex tile, ViewportPlaceMethod method, ViewportDragDropSelectionProcess process)
Prepare state for highlighting tiles while dragging with the mouse.
HighLightStyle
Highlighting draw styles.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
@ HT_SPECIAL
special mode used for highlighting while dragging (and for tunnels/docks)
Definition of the game-calendar-timer.
RoadType _last_built_tramtype
The most recently used type of tram track.
RoadType _last_built_roadtype
The most recently used type of road.
Stuff related to the (main) toolbar.
TransportType
Available types of transport.
@ Road
Transport by road vehicle.
Header file for things common for tunnels and bridges.
TileIndex _build_tunnel_endtile
The end of a tunnel; as hidden return from the tunnel build command for GUI purposes.
Command definitions related to tunnels and bridges.
Functions that have tunnels and bridges in common.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
bool CanBuildVehicleInfrastructure(VehicleType type, RoadTramType subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1950
Functions related to vehicles.
@ Road
Road vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetRedErrorSquare(TileIndex tile)
Set a tile to display a red error square.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
@ VPM_FIX_Y
drag only in Y axis
@ VPM_Y_LIMITED
Drag only in Y axis with limited size.
@ VPM_X_AND_Y_LIMITED
area of land of limited size
@ VPM_X_LIMITED
Drag only in X axis with limited size.
@ VPM_X_AND_Y
area of land in X and Y directions
@ VPM_FIX_X
drag only in X axis
@ VPM_X_OR_Y
drag in X or Y direction
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_PLACE_ROAD_Y_DIR
Road placement (Y axis).
@ DDSP_BUILD_BUSSTOP
Road stop placement (buses).
@ DDSP_REMOVE_BUSSTOP
Road stop removal (buses).
@ DDSP_REMOVE_ROAD_WAYPOINT
Road stop removal (waypoint).
@ DDSP_DEMOLISH_AREA
Clear area.
@ DDSP_BUILD_TRUCKSTOP
Road stop placement (trucks).
@ DDSP_REMOVE_TRUCKSTOP
Road stop removal (trucks).
@ DDSP_PLACE_AUTOROAD
Road placement (auto).
@ DDSP_BUILD_ROAD_WAYPOINT
Road stop placement (waypoint).
@ DDSP_PLACE_ROAD_X_DIR
Road placement (X axis).
@ DDSP_BUILD_BRIDGE
Bridge placement.
@ DDSP_CONVERT_ROAD
Road conversion.
Base of waypoints.
@ WPF_ROAD
This is a road waypoint.
Axis GetAxisForNewRoadWaypoint(TileIndex tile)
Get the axis for a new road waypoint.
Command definitions related to waypoints.
Functions related to waypoints.
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:49
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX).
Definition widget_type.h:55
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ NWID_HORIZONTAL_LTR
Horizontal container that doesn't change the order of the widgets for RTL languages.
Definition widget_type.h:67
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1242
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1326
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1748
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting).
Definition window.cpp:3255
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:154
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:145
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:144
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24
WindowClass
Window classes.
Definition window_type.h:61
@ BuildTruckStation
Build truck station; Window numbers:
Functions related to zooming.
int ScaleSpriteTrad(int value)
Scale traditional pixel dimensions to GUI zoom level, for drawing sprites.
Definition zoom_func.h:107