OpenTTD Source: src/road_gui.cpp Source File

OpenTTD Source 15.0-beta1

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