OpenTTD Source 20260512-master-g20b387b91f
airport_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "economy_func.h"
12#include "window_gui.h"
13#include "station_gui.h"
14#include "terraform_gui.h"
15#include "sound_func.h"
16#include "window_func.h"
17#include "strings_func.h"
18#include "viewport_func.h"
19#include "company_func.h"
20#include "tilehighlight_func.h"
21#include "company_base.h"
22#include "station_type.h"
23#include "newgrf_airport.h"
24#include "newgrf_badge_gui.h"
25#include "newgrf_callbacks.h"
26#include "dropdown_type.h"
27#include "dropdown_func.h"
29#include "hotkeys.h"
30#include "vehicle_func.h"
31#include "gui.h"
32#include "command_func.h"
33#include "airport_cmd.h"
34#include "station_cmd.h"
35#include "zoom_func.h"
36#include "timer/timer.h"
38
40
41#include "table/strings.h"
42
43#include "safeguards.h"
44
45
49
50static void ShowBuildAirportPicker(Window *parent);
51
52SpriteID GetCustomAirportSprite(const AirportSpec *as, uint8_t layout);
53
54void CcBuildAirport(Commands, const CommandCost &result, TileIndex tile)
55{
56 if (result.Failed()) return;
57
58 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
59 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
60}
61
66static void PlaceAirport(TileIndex tile)
67{
68 if (_selected_airport_index == -1) return;
69
71 uint8_t layout = _selected_airport_layout;
72 bool adjacent = _ctrl_pressed;
73
74 auto proc = [=](bool test, StationID to_join) -> bool {
75 if (test) {
76 return Command<Commands::BuildAirport>::Do(CommandFlagsToDCFlags(GetCommandFlags<Commands::BuildAirport>()), tile, airport_type, layout, StationID::Invalid(), adjacent).Succeeded();
77 } else {
78 return Command<Commands::BuildAirport>::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, airport_type, layout, to_join, adjacent);
79 }
80 };
81
82 ShowSelectStationIfNeeded(TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE), proc);
83}
84
86struct BuildAirToolbarWindow : Window {
88
89 BuildAirToolbarWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
90 {
91 this->InitNested(window_number);
92 this->OnInvalidateData();
93 if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
94 }
95
96 void Close([[maybe_unused]] int data = 0) override
97 {
99 if (_settings_client.gui.link_terraform_toolbar) CloseWindowById(WC_SCEN_LAND_GEN, 0, false);
100 this->Window::Close();
101 }
102
108 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
109 {
110 if (!gui_scope) return;
111
113 this->SetWidgetDisabledState(WID_AT_AIRPORT, !can_build);
114 if (!can_build) {
116
117 /* Show in the tooltip why this button is disabled. */
118 this->GetWidget<NWidgetCore>(WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
119 } else {
120 this->GetWidget<NWidgetCore>(WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP);
121 }
122 }
123
124 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
125 {
126 switch (widget) {
127 case WID_AT_AIRPORT:
128 if (HandlePlacePushButton(this, WID_AT_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT)) {
129 ShowBuildAirportPicker(this);
130 this->last_user_action = widget;
131 }
132 break;
133
134 case WID_AT_DEMOLISH:
136 this->last_user_action = widget;
137 break;
138
139 default: break;
140 }
141 }
142
143
144 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
145 {
146 switch (this->last_user_action) {
147 case WID_AT_AIRPORT:
148 PlaceAirport(tile);
149 break;
150
151 case WID_AT_DEMOLISH:
153 break;
154
155 default: NOT_REACHED();
156 }
157 }
158
159 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
160 {
161 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
162 }
163
164 Point OnInitialPosition(int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
165 {
166 return AlignInitialConstructionToolbar(sm_width);
167 }
168
169 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
170 {
171 if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
172 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
173 }
174 }
175
185
192 {
193 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
195 if (w == nullptr) return ES_NOT_HANDLED;
196 return w->OnHotkey(hotkey);
197 }
198
199 static inline HotkeyList hotkeys{"airtoolbar", {
200 Hotkey('1', "airport", WID_AT_AIRPORT),
201 Hotkey('2', "demolish", WID_AT_DEMOLISH),
203};
204
205static constexpr std::initializer_list<NWidgetPart> _nested_air_toolbar_widgets = {
208 NWidget(WWT_CAPTION, Colours::DarkGreen), SetStringTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
210 EndContainer(),
212 NWidget(WWT_IMGBTN, Colours::DarkGreen, WID_AT_AIRPORT), SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP),
214 NWidget(WWT_IMGBTN, Colours::DarkGreen, WID_AT_DEMOLISH), SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
215 EndContainer(),
216};
217
220 WindowPosition::Manual, "toolbar_air", 0, 0,
223 _nested_air_toolbar_widgets,
224 &BuildAirToolbarWindow::hotkeys
225);
226
241
242class BuildAirportWindow : public PickerWindowBase {
244 int line_height = 0;
245 Scrollbar *vscroll = nullptr;
246
252 {
253 DropDownList list;
254
255 for (const auto &cls : AirportClass::Classes()) {
256 list.push_back(MakeDropDownListStringItem(cls.name, cls.Index().base()));
257 }
258
259 return list;
260 }
261
262public:
264 {
265 this->CreateNestedTree();
266
267 this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR);
268 this->vscroll->SetCapacity(5);
269 this->vscroll->SetPosition(0);
270
272
273 this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
274 this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
275 this->OnInvalidateData();
276
277 /* Ensure airport class is valid (changing NewGRFs). */
278 _selected_airport_class = Clamp(_selected_airport_class, AirportClassID::Begin(), static_cast<AirportClassID>(AirportClass::GetClassCount() - 1));
280 this->vscroll->SetCount(ac->GetSpecCount());
281
282 /* Ensure the airport index is valid for this class (changing NewGRFs). */
284
285 /* Only when no valid airport was selected, we want to select the first airport. */
286 bool select_first_airport = true;
287 if (_selected_airport_index != -1) {
289 if (as->IsAvailable()) {
290 /* Ensure the airport layout is valid. */
291 _selected_airport_layout = Clamp(_selected_airport_layout, 0, static_cast<uint8_t>(as->layouts.size() - 1));
292 select_first_airport = false;
293 this->UpdateSelectSize();
294 }
295 }
296
297 if (select_first_airport) this->SelectFirstAvailableAirport(true);
298 }
299
300 void Close([[maybe_unused]] int data = 0) override
301 {
304 }
305
306 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
307 {
308 switch (widget) {
311
313 if (_selected_airport_index != -1) {
316 if (string != STR_UNDEFINED) {
317 return GetString(string);
318 } else if (as->layouts.size() > 1) {
319 return GetString(STR_STATION_BUILD_AIRPORT_LAYOUT_NAME, _selected_airport_layout + 1);
320 }
321 }
322 return {};
323
324 default:
325 return this->Window::GetWidgetString(widget, stringid);
326 }
327 }
328
329 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
330 {
331 switch (widget) {
333 Dimension d = {0, 0};
334 for (const auto &cls : AirportClass::Classes()) {
335 d = maxdim(d, GetStringBoundingBox(cls.name));
336 }
337 d.width += padding.width;
338 d.height += padding.height;
339 size = maxdim(size, d);
340 break;
341 }
342
343 case WID_AP_AIRPORT_LIST: {
344 for (int i = 0; i < NUM_AIRPORTS; i++) {
345 const AirportSpec *as = AirportSpec::Get(i);
346 if (!as->enabled) continue;
347
348 size.width = std::max(size.width, GetStringBoundingBox(as->name).width + padding.width);
349 }
350
351 this->line_height = GetCharacterHeight(FontSize::Normal) + padding.height;
352 size.height = 5 * this->line_height;
353 break;
354 }
355
357 for (int i = 0; i < NUM_AIRPORTS; i++) {
358 const AirportSpec *as = AirportSpec::Get(i);
359 if (!as->enabled) continue;
360 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
361 SpriteID sprite = GetCustomAirportSprite(as, layout);
362 if (sprite != 0) {
363 Dimension d = GetSpriteSize(sprite);
364 d.width += WidgetDimensions::scaled.framerect.Horizontal();
365 d.height += WidgetDimensions::scaled.framerect.Vertical();
366 size = maxdim(d, size);
367 }
368 }
369 }
370 break;
371
373 for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
374 const AirportSpec *as = AirportSpec::Get(i);
375 if (!as->enabled) continue;
376 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
378 if (string == STR_UNDEFINED) continue;
379
381 size = maxdim(d, size);
382 }
383 }
384 break;
385
386 default: break;
387 }
388 }
389
390 void DrawWidget(const Rect &r, WidgetID widget) const override
391 {
392 switch (widget) {
393 case WID_AP_AIRPORT_LIST: {
394 Rect row = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.bevel);
395 Rect text = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.matrix);
396 const auto specs = AirportClass::Get(_selected_airport_class)->Specs();
397 auto [first, last] = this->vscroll->GetVisibleRangeIterators(specs);
398 for (auto it = first; it != last; ++it) {
399 const AirportSpec *as = *it;
400 if (!as->IsAvailable()) {
402 }
403 DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK);
404 row = row.Translate(0, this->line_height);
405 text = text.Translate(0, this->line_height);
406 }
407 break;
408 }
409
411 if (this->preview_sprite != 0) {
412 Dimension d = GetSpriteSize(this->preview_sprite);
413 DrawSprite(this->preview_sprite, GetCompanyPalette(_local_company), CentreBounds(r.left, r.right, d.width), CentreBounds(r.top, r.bottom, d.height));
414 }
415 break;
416
418 if (_selected_airport_index != -1) {
421 if (string != STR_UNDEFINED) {
422 DrawStringMultiLine(r, string, TC_BLACK);
423 }
424 }
425 break;
426 }
427 }
428
429 void OnPaint() override
430 {
431 this->DrawWidgets();
432
433 Rect r = this->GetWidget<NWidgetBase>(WID_AP_ACCEPTANCE)->GetCurrentRect();
434 const int bottom = r.bottom;
435 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
436
437 if (_selected_airport_index != -1) {
439 int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
440
441 /* only show the station (airport) noise, if the noise option is activated */
442 if (_settings_game.economy.station_noise_level) {
443 /* show the noise of the selected airport */
444 DrawString(r, GetString(STR_STATION_BUILD_NOISE, as->noise_level));
446 }
447
448 if (_settings_game.economy.infrastructure_maintenance) {
449 Money monthly = _price[Price::InfrastructureAirport] * as->maintenance_cost >> 3;
450 DrawString(r, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_BUILD_INFRASTRUCTURE_COST_PERIOD : STR_STATION_BUILD_INFRASTRUCTURE_COST_YEAR, monthly * 12));
452 }
453
454 /* strings such as 'Size' and 'Coverage Area' */
455 r.top = DrawBadgeNameList(r, as->badges, GrfSpecFeature::Airports) + WidgetDimensions::scaled.vsep_normal;
456 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
457 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
458 }
459
460 /* Resize background if the window is too small.
461 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
462 * (This is the case, if making the window bigger moves the mouse into the window.) */
463 if (r.top > bottom) {
464 ResizeWindow(this, 0, r.top - bottom, false);
465 }
466 }
467
468 void SelectOtherAirport(int airport_index)
469 {
470 _selected_airport_index = airport_index;
472
473 this->UpdateSelectSize();
474 this->SetDirty();
475 }
476
477 void UpdateSelectSize()
478 {
479 if (_selected_airport_index == -1) {
480 SetTileSelectSize(1, 1);
483 } else {
485 int w = as->size_x;
486 int h = as->size_y;
487 Direction rotation = as->layouts[_selected_airport_layout].rotation;
488 if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h);
489 SetTileSelectSize(w, h);
490
491 this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
492
495
497 if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
498 }
499 }
500
501 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
502 {
503 switch (widget) {
506 break;
507
508 case WID_AP_AIRPORT_LIST: {
509 int32_t num_clicked = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
510 if (num_clicked == INT32_MAX) break;
512 if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
513 break;
514 }
515
517 _settings_client.gui.station_show_coverage = (widget != WID_AP_BTN_DONTHILIGHT);
518 this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
519 this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
520 this->SetDirty();
521 SndClickBeep();
522 this->UpdateSelectSize();
523 SetViewportCatchmentStation(nullptr, true);
524 break;
525
528 this->UpdateSelectSize();
529 this->SetDirty();
530 break;
531
534 this->UpdateSelectSize();
535 this->SetDirty();
536 break;
537 }
538 }
539
545 void SelectFirstAvailableAirport(bool change_class)
546 {
547 /* First try to select an airport in the selected class. */
549 for (const AirportSpec *as : sel_apclass->Specs()) {
550 if (as->IsAvailable()) {
551 this->SelectOtherAirport(as->index);
552 return;
553 }
554 }
555 if (change_class) {
556 /* If that fails, select the first available airport
557 * from the first class where airports are available. */
558 for (const auto &cls : AirportClass::Classes()) {
559 for (const auto &as : cls.Specs()) {
560 if (as->IsAvailable()) {
561 _selected_airport_class = cls.Index();
562 this->vscroll->SetCount(cls.GetSpecCount());
563 this->SelectOtherAirport(as->index);
564 return;
565 }
566 }
567 }
568 }
569 /* If all airports are unavailable, select nothing. */
570 this->SelectOtherAirport(-1);
571 }
572
573 void OnDropdownSelect(WidgetID widget, int index, int) override
574 {
575 if (widget == WID_AP_CLASS_DROPDOWN) {
577 this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
578 this->SelectFirstAvailableAirport(false);
579 }
580 }
581
582 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
583 {
585 }
586
587 const IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::Trigger::Year, TimerGameCalendar::Priority::None}, [this](auto) {
588 this->InvalidateData();
589 }};
590};
591
592static constexpr std::initializer_list<NWidgetPart> _nested_build_airport_widgets = {
595 NWidget(WWT_CAPTION, Colours::DarkGreen), SetStringTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
596 EndContainer(),
600 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL), SetFill(1, 0),
601 NWidget(WWT_DROPDOWN, Colours::Grey, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetToolTip(STR_STATION_BUILD_AIRPORT_TOOLTIP),
604 NWidget(WWT_MATRIX, Colours::Grey, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetMatrixDataTip(1, 5, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
606 EndContainer(),
607 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
612 EndContainer(),
614 NWidget(WWT_LABEL, Colours::Invalid), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
615 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14), SetPIPRatio(1, 0, 1),
618 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
620 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
621 EndContainer(),
622 EndContainer(),
623 EndContainer(),
625 EndContainer(),
626 EndContainer(),
627};
628
634 _nested_build_airport_widgets
635);
636
637static void ShowBuildAirportPicker(Window *parent)
638{
640}
641
642void InitializeAirportGui()
643{
644 _selected_airport_class = AirportClassID::Begin();
646}
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition airport.h:41
@ NEW_AIRPORT_OFFSET
Number of the first newgrf airport.
Definition airport.h:39
Command definitions related to airports.
static void PlaceAirport(TileIndex tile)
Place an airport.
static WindowDesc _build_airport_desc(WindowPosition::Automatic, {}, 0, 0, WC_BUILD_STATION, WC_BUILD_TOOLBAR, WindowDefaultFlag::Construction, _nested_build_airport_widgets)
Window definition for the airport build window.
static WindowDesc _air_toolbar_desc(WindowPosition::Manual, "toolbar_air", 0, 0, WC_BUILD_TOOLBAR, WC_NONE, WindowDefaultFlag::Construction, _nested_air_toolbar_widgets, &BuildAirToolbarWindow::hotkeys)
Window definition for the air toolbar.
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
static int _selected_airport_index
the index of the selected airport in the current class or -1
static AirportClassID _selected_airport_class
the currently visible airport class
static uint8_t _selected_airport_layout
selected airport layout number.
Types related to the airport widgets.
@ WID_AT_DEMOLISH
Demolish button.
@ WID_AT_AIRPORT
Build airport button.
@ WID_AP_AIRPORT_LIST
List of airports.
@ WID_AP_ACCEPTANCE
Acceptance info.
@ WID_AP_LAYOUT_DECREASE
Decrease the layout number.
@ WID_AP_LAYOUT_INCREASE
Increase the layout number.
@ WID_AP_CLASS_DROPDOWN
Dropdown of airport classes.
@ WID_AP_BTN_DOHILIGHT
Show the coverage button.
@ WID_AP_AIRPORT_SPRITE
A visual display of the airport currently selected.
@ WID_AP_SCROLLBAR
Scrollbar of the list.
@ WID_AP_BTN_DONTHILIGHT
Don't show the coverage button.
@ WID_AP_LAYOUT_NUM
Current number of the layout.
@ WID_AP_EXTRA_TEXT
Additional text about the airport.
static DropDownList BuildAirportClassDropDown()
Build a dropdown list of available airport classes.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
SpriteID preview_sprite
Cached airport preview sprite.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnPaint() override
The window must be repainted.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void SelectFirstAvailableAirport(bool change_class)
Select the first available airport.
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.
Common return value for all commands.
bool Failed() const
Did this command fail?
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
uint GetSpecCount() const
Get the number of allocated specs within the class.
static std::span< NewGRFClass< AirportSpec, AirportClassID > const > Classes()
static NewGRFClass * Get(AirportClassID class_index)
Base class for windows opened from a toolbar.
Definition window_gui.h:999
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3629
Scrollbar data structure.
void SetCount(size_t num)
Sets the number of elements in the list.
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2458
bool SetPosition(size_type position)
Sets the position of the first visible element.
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Definition command.cpp:113
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
Direction
Defines the 8 directions on the map.
@ DIR_W
West.
@ DIR_E
East.
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:587
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Prices _price
Prices and also the fractional part.
Definition economy.cpp:106
Functions related to the economy.
@ InfrastructureAirport
Airports maintenance cost.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:972
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:900
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:669
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:1038
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:753
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:788
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:116
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ DarkGreen
Dark green.
Definition gfx_type.h:292
@ Checker
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:346
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetToolbarSpacerMinimalSize()
Widget part function to setting the minimal size for a toolbar spacer.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetType widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:980
GUI functions that shouldn't be here.
Hotkey related functions.
#define Point
Macro that prevents name conflicts between included headers.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:63
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
@ Airports
Airports feature.
Definition newgrf.h:86
StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback)
Get a custom text for the airport.
NewGRF handling of airports.
PoolID< uint8_t, struct AirportClassIDTag, 16, UINT8_MAX > AirportClassID
Class IDs for airports.
NewGRFClass< AirportSpec, AirportClassID > AirportClass
Information related to airport classes.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
Callbacks that NewGRFs could implement.
@ CBID_AIRPORT_ADDITIONAL_TEXT
This callback is called from airport list.
@ CBID_AIRPORT_LAYOUT_NAME
Called to determine text to show as airport layout name.
static constexpr PixelColour PC_BLACK
Black palette colour.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:77
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1522
Command definitions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s).
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Contains enums and function declarations connected with stations GUI.
@ SCT_ALL
Draw all cargoes.
Definition station_gui.h:24
Types related to stations.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Defines the data structure for an airport.
StringID name
name of this airport
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
uint8_t catchment
catchment area of this airport
uint16_t maintenance_cost
maintenance cost multiplier
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
uint8_t size_y
size of airport in y direction
uint8_t size_x
size of airport in x direction
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
bool IsAvailable() const
Check whether this airport is available to build.
uint8_t noise_level
noise that this airport generates
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.
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.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
static EventState AirportToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildAirToolbarWindow.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
WidgetID last_user_action
Last started user action.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool station_show_coverage
whether to highlight coverage area
StationSettings station
settings related to station management
List of hotkeys for a window.
Definition hotkeys.h:46
All data for a single hotkey.
Definition hotkeys.h:22
uint16_t index
Index within class of this spec, invalid until inserted into class.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool modified_catchment
different-size catchment areas
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1117
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:799
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1822
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:786
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3262
Window * parent
Parent window.
Definition window_gui.h:329
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:518
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1812
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:544
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1846
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:990
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1836
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:327
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:584
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
@ TRANSPORT_AIR
Transport through air.
bool CanBuildVehicleInfrastructure(VehicleType type, RoadTramType subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1941
Functions related to vehicles.
@ Aircraft
Aircraft vehicle type.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Functions related to (drawing on) viewports.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects).
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
@ DDSP_DEMOLISH_AREA
Clear area.
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX).
Definition widget_type.h:57
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ Decrease
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
@ Increase
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
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:1209
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2113
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1222
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1715
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ Construction
This window is used for construction; close it whenever changing company.
Definition window_gui.h:153
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ Automatic
Find a place automatically.
Definition window_gui.h:144
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:143
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:24
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:79
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:51
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Functions related to zooming.