OpenTTD Source: src/road_gui.cpp Source File

OpenTTD Source 15.3

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