OpenTTD Source: src/airport_gui.cpp Source File

OpenTTD Source 15.3

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
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"
28#include "core/geometry_func.hpp"
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"
37#include "timer/timer_game_calendar.h"
38
39#include "widgets/airport_widget.h"
40
41#include "table/strings.h"
42
43#include "safeguards.h"
44
45
46 static AirportClassID _selected_airport_class;
47 static int _selected_airport_index;
48 static uint8_t _selected_airport_layout;
49
50static void ShowBuildAirportPicker(Window *parent);
51
52 SpriteID 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
66 static void PlaceAirport(TileIndex tile)
67{
68 if (_selected_airport_index == -1) return;
69
70 uint8_t airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
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<CMD_BUILD_AIRPORT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_AIRPORT>()), tile, airport_type, layout, StationID::Invalid(), adjacent).Succeeded();
77 } else {
78 return Command<CMD_BUILD_AIRPORT>::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
86 struct BuildAirToolbarWindow : Window {
87 WidgetID last_user_action = INVALID_WIDGET; // Last started user action.
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 {
98 if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true);
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
112 bool can_build = CanBuildVehicleInfrastructure(VEH_AIRCRAFT);
113 this->SetWidgetDisabledState(WID_AT_AIRPORT, !can_build);
114 if (!can_build) {
115 CloseWindowById(WC_BUILD_STATION, TRANSPORT_AIR);
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:
135 HandlePlacePushButton(this, WID_AT_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
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:
152 PlaceProc_DemolishArea(tile);
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
176 void OnPlaceObjectAbort() override
177 {
178 if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true);
179
180 this->RaiseButtons();
181
182 CloseWindowById(WC_BUILD_STATION, TRANSPORT_AIR);
183 CloseWindowById(WC_SELECT_STATION, 0);
184 }
185
191 static EventState AirportToolbarGlobalHotkeys(int hotkey)
192 {
193 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
194 Window *w = ShowBuildAirToolbar();
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),
202 }, AirportToolbarGlobalHotkeys};
203};
204
205static constexpr std::initializer_list<NWidgetPart> _nested_air_toolbar_widgets = {
206 NWidget(NWID_HORIZONTAL),
207 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
208 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
209 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
210 EndContainer(),
211 NWidget(NWID_HORIZONTAL),
212 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_AIRPORT), SetFill(0, 1), SetToolbarMinimalSize(2), SetSpriteTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP),
213 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetToolbarSpacerMinimalSize(), SetFill(1, 1), EndContainer(),
214 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_DEMOLISH), SetFill(0, 1), SetToolbarMinimalSize(1), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
215 EndContainer(),
216};
217
218static WindowDesc _air_toolbar_desc(
219 WDP_MANUAL, "toolbar_air", 0, 0,
220 WC_BUILD_TOOLBAR, WC_NONE,
221 WindowDefaultFlag::Construction,
222 _nested_air_toolbar_widgets,
223 &BuildAirToolbarWindow::hotkeys
224);
225
233 Window *ShowBuildAirToolbar()
234{
235 if (!Company::IsValidID(_local_company)) return nullptr;
236
237 CloseWindowByClass(WC_BUILD_TOOLBAR);
238 return AllocateWindowDescFront<BuildAirToolbarWindow>(_air_toolbar_desc, TRANSPORT_AIR);
239}
240
241 class BuildAirportWindow : public PickerWindowBase {
242 SpriteID preview_sprite{};
243 int line_height = 0;
244 Scrollbar *vscroll = nullptr;
245
247 static DropDownList BuildAirportClassDropDown()
248 {
249 DropDownList list;
250
251 for (const auto &cls : AirportClass::Classes()) {
252 list.push_back(MakeDropDownListStringItem(cls.name, cls.Index()));
253 }
254
255 return list;
256 }
257
258public:
259 BuildAirportWindow(WindowDesc &desc, Window *parent) : PickerWindowBase(desc, parent)
260 {
261 this->CreateNestedTree();
262
263 this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR);
264 this->vscroll->SetCapacity(5);
265 this->vscroll->SetPosition(0);
266
267 this->FinishInitNested(TRANSPORT_AIR);
268
269 this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
270 this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
271 this->OnInvalidateData();
272
273 /* Ensure airport class is valid (changing NewGRFs). */
274 _selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1));
275 const AirportClass *ac = AirportClass::Get(_selected_airport_class);
276 this->vscroll->SetCount(ac->GetSpecCount());
277
278 /* Ensure the airport index is valid for this class (changing NewGRFs). */
279 _selected_airport_index = Clamp(_selected_airport_index, -1, ac->GetSpecCount() - 1);
280
281 /* Only when no valid airport was selected, we want to select the first airport. */
282 bool select_first_airport = true;
283 if (_selected_airport_index != -1) {
284 const AirportSpec *as = ac->GetSpec(_selected_airport_index);
285 if (as->IsAvailable()) {
286 /* Ensure the airport layout is valid. */
287 _selected_airport_layout = Clamp(_selected_airport_layout, 0, static_cast<uint8_t>(as->layouts.size() - 1));
288 select_first_airport = false;
289 this->UpdateSelectSize();
290 }
291 }
292
293 if (select_first_airport) this->SelectFirstAvailableAirport(true);
294 }
295
296 void Close([[maybe_unused]] int data = 0) override
297 {
298 CloseWindowById(WC_SELECT_STATION, 0);
299 this->PickerWindowBase::Close();
300 }
301
302 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
303 {
304 switch (widget) {
305 case WID_AP_CLASS_DROPDOWN:
306 return GetString(AirportClass::Get(_selected_airport_class)->name);
307
308 case WID_AP_LAYOUT_NUM:
309 if (_selected_airport_index != -1) {
310 const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
311 StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_LAYOUT_NAME);
312 if (string != STR_UNDEFINED) {
313 return GetString(string);
314 } else if (as->layouts.size() > 1) {
315 return GetString(STR_STATION_BUILD_AIRPORT_LAYOUT_NAME, _selected_airport_layout + 1);
316 }
317 }
318 return {};
319
320 default:
321 return this->Window::GetWidgetString(widget, stringid);
322 }
323 }
324
325 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
326 {
327 switch (widget) {
328 case WID_AP_CLASS_DROPDOWN: {
329 Dimension d = {0, 0};
330 for (const auto &cls : AirportClass::Classes()) {
331 d = maxdim(d, GetStringBoundingBox(cls.name));
332 }
333 d.width += padding.width;
334 d.height += padding.height;
335 size = maxdim(size, d);
336 break;
337 }
338
339 case WID_AP_AIRPORT_LIST: {
340 for (int i = 0; i < NUM_AIRPORTS; i++) {
341 const AirportSpec *as = AirportSpec::Get(i);
342 if (!as->enabled) continue;
343
344 size.width = std::max(size.width, GetStringBoundingBox(as->name).width + padding.width);
345 }
346
347 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
348 size.height = 5 * this->line_height;
349 break;
350 }
351
352 case WID_AP_AIRPORT_SPRITE:
353 for (int i = 0; i < NUM_AIRPORTS; i++) {
354 const AirportSpec *as = AirportSpec::Get(i);
355 if (!as->enabled) continue;
356 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
357 SpriteID sprite = GetCustomAirportSprite(as, layout);
358 if (sprite != 0) {
359 Dimension d = GetSpriteSize(sprite);
360 d.width += WidgetDimensions::scaled.framerect.Horizontal();
361 d.height += WidgetDimensions::scaled.framerect.Vertical();
362 size = maxdim(d, size);
363 }
364 }
365 }
366 break;
367
368 case WID_AP_EXTRA_TEXT:
369 for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
370 const AirportSpec *as = AirportSpec::Get(i);
371 if (!as->enabled) continue;
372 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
373 StringID string = GetAirportTextCallback(as, layout, CBID_AIRPORT_ADDITIONAL_TEXT);
374 if (string == STR_UNDEFINED) continue;
375
376 Dimension d = GetStringMultiLineBoundingBox(string, size);
377 size = maxdim(d, size);
378 }
379 }
380 break;
381
382 default: break;
383 }
384 }
385
386 void DrawWidget(const Rect &r, WidgetID widget) const override
387 {
388 switch (widget) {
389 case WID_AP_AIRPORT_LIST: {
390 Rect row = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.bevel);
391 Rect text = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.matrix);
392 const auto specs = AirportClass::Get(_selected_airport_class)->Specs();
393 auto [first, last] = this->vscroll->GetVisibleRangeIterators(specs);
394 for (auto it = first; it != last; ++it) {
395 const AirportSpec *as = *it;
396 if (!as->IsAvailable()) {
397 GfxFillRect(row, PC_BLACK, FILLRECT_CHECKER);
398 }
399 DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK);
400 row = row.Translate(0, this->line_height);
401 text = text.Translate(0, this->line_height);
402 }
403 break;
404 }
405
406 case WID_AP_AIRPORT_SPRITE:
407 if (this->preview_sprite != 0) {
408 Dimension d = GetSpriteSize(this->preview_sprite);
409 DrawSprite(this->preview_sprite, GetCompanyPalette(_local_company), CentreBounds(r.left, r.right, d.width), CentreBounds(r.top, r.bottom, d.height));
410 }
411 break;
412
413 case WID_AP_EXTRA_TEXT:
414 if (_selected_airport_index != -1) {
415 const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
416 StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
417 if (string != STR_UNDEFINED) {
418 DrawStringMultiLine(r, string, TC_BLACK);
419 }
420 }
421 break;
422 }
423 }
424
425 void OnPaint() override
426 {
427 this->DrawWidgets();
428
429 Rect r = this->GetWidget<NWidgetBase>(WID_AP_ACCEPTANCE)->GetCurrentRect();
430 const int bottom = r.bottom;
431 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
432
433 if (_selected_airport_index != -1) {
434 const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
435 int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
436
437 /* only show the station (airport) noise, if the noise option is activated */
438 if (_settings_game.economy.station_noise_level) {
439 /* show the noise of the selected airport */
440 DrawString(r, GetString(STR_STATION_BUILD_NOISE, as->noise_level));
441 r.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
442 }
443
444 if (_settings_game.economy.infrastructure_maintenance) {
445 Money monthly = _price[PR_INFRASTRUCTURE_AIRPORT] * as->maintenance_cost >> 3;
446 DrawString(r, GetString(TimerGameEconomy::UsingWallclockUnits() ? STR_STATION_BUILD_INFRASTRUCTURE_COST_PERIOD : STR_STATION_BUILD_INFRASTRUCTURE_COST_YEAR, monthly * 12));
447 r.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
448 }
449
450 /* strings such as 'Size' and 'Coverage Area' */
451 r.top = DrawBadgeNameList(r, as->badges, GSF_AIRPORTS) + WidgetDimensions::scaled.vsep_normal;
452 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, false) + WidgetDimensions::scaled.vsep_normal;
453 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
454 }
455
456 /* Resize background if the window is too small.
457 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
458 * (This is the case, if making the window bigger moves the mouse into the window.) */
459 if (r.top > bottom) {
460 ResizeWindow(this, 0, r.top - bottom, false);
461 }
462 }
463
464 void SelectOtherAirport(int airport_index)
465 {
466 _selected_airport_index = airport_index;
467 _selected_airport_layout = 0;
468
469 this->UpdateSelectSize();
470 this->SetDirty();
471 }
472
473 void UpdateSelectSize()
474 {
475 if (_selected_airport_index == -1) {
476 SetTileSelectSize(1, 1);
477 this->DisableWidget(WID_AP_LAYOUT_DECREASE);
478 this->DisableWidget(WID_AP_LAYOUT_INCREASE);
479 } else {
480 const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index);
481 int w = as->size_x;
482 int h = as->size_y;
483 Direction rotation = as->layouts[_selected_airport_layout].rotation;
484 if (rotation == DIR_E || rotation == DIR_W) std::swap(w, h);
485 SetTileSelectSize(w, h);
486
487 this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
488
489 this->SetWidgetDisabledState(WID_AP_LAYOUT_DECREASE, _selected_airport_layout == 0);
490 this->SetWidgetDisabledState(WID_AP_LAYOUT_INCREASE, _selected_airport_layout + 1U >= as->layouts.size());
491
492 int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
493 if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
494 }
495 }
496
497 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
498 {
499 switch (widget) {
500 case WID_AP_CLASS_DROPDOWN:
501 ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN);
502 break;
503
504 case WID_AP_AIRPORT_LIST: {
505 int32_t num_clicked = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
506 if (num_clicked == INT32_MAX) break;
507 const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked);
508 if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
509 break;
510 }
511
512 case WID_AP_BTN_DONTHILIGHT: case WID_AP_BTN_DOHILIGHT:
513 _settings_client.gui.station_show_coverage = (widget != WID_AP_BTN_DONTHILIGHT);
514 this->SetWidgetLoweredState(WID_AP_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
515 this->SetWidgetLoweredState(WID_AP_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
516 this->SetDirty();
517 SndClickBeep();
518 this->UpdateSelectSize();
519 SetViewportCatchmentStation(nullptr, true);
520 break;
521
522 case WID_AP_LAYOUT_DECREASE:
523 _selected_airport_layout--;
524 this->UpdateSelectSize();
525 this->SetDirty();
526 break;
527
528 case WID_AP_LAYOUT_INCREASE:
529 _selected_airport_layout++;
530 this->UpdateSelectSize();
531 this->SetDirty();
532 break;
533 }
534 }
535
541 void SelectFirstAvailableAirport(bool change_class)
542 {
543 /* First try to select an airport in the selected class. */
544 AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class);
545 for (const AirportSpec *as : sel_apclass->Specs()) {
546 if (as->IsAvailable()) {
547 this->SelectOtherAirport(as->index);
548 return;
549 }
550 }
551 if (change_class) {
552 /* If that fails, select the first available airport
553 * from the first class where airports are available. */
554 for (const auto &cls : AirportClass::Classes()) {
555 for (const auto &as : cls.Specs()) {
556 if (as->IsAvailable()) {
557 _selected_airport_class = cls.Index();
558 this->vscroll->SetCount(cls.GetSpecCount());
559 this->SelectOtherAirport(as->index);
560 return;
561 }
562 }
563 }
564 }
565 /* If all airports are unavailable, select nothing. */
566 this->SelectOtherAirport(-1);
567 }
568
569 void OnDropdownSelect(WidgetID widget, int index, int) override
570 {
571 if (widget == WID_AP_CLASS_DROPDOWN) {
572 _selected_airport_class = (AirportClassID)index;
573 this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
574 this->SelectFirstAvailableAirport(false);
575 }
576 }
577
578 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
579 {
580 CheckRedrawStationCoverage(this);
581 }
582
583 const IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
584 this->InvalidateData();
585 }};
586};
587
588static constexpr std::initializer_list<NWidgetPart> _nested_build_airport_widgets = {
589 NWidget(NWID_HORIZONTAL),
590 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
591 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
592 EndContainer(),
593 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
594 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(WidgetDimensions::unscaled.picker),
595 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0),
596 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL), SetFill(1, 0),
597 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetToolTip(STR_STATION_BUILD_AIRPORT_TOOLTIP),
598 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
599 NWidget(NWID_HORIZONTAL),
600 NWidget(WWT_MATRIX, COLOUR_GREY, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetMatrixDataTip(1, 5, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
601 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_AP_SCROLLBAR),
602 EndContainer(),
603 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
604 NWidget(NWID_HORIZONTAL),
605 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_DECREASE), SetMinimalSize(12, 0), SetArrowWidgetTypeTip(AWV_DECREASE),
606 NWidget(WWT_LABEL, INVALID_COLOUR, WID_AP_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0),
607 NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_AP_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetArrowWidgetTypeTip(AWV_INCREASE),
608 EndContainer(),
609 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_AP_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
610 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
611 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14), SetPIPRatio(1, 0, 1),
612 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
613 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DONTHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
614 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
615 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DOHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
616 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
617 EndContainer(),
618 EndContainer(),
619 EndContainer(),
620 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_AP_ACCEPTANCE), SetResize(0, 1), SetFill(1, 0), SetMinimalTextLines(2, WidgetDimensions::unscaled.vsep_normal),
621 EndContainer(),
622 EndContainer(),
623};
624
625static WindowDesc _build_airport_desc(
626 WDP_AUTO, {}, 0, 0,
627 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
628 WindowDefaultFlag::Construction,
629 _nested_build_airport_widgets
630);
631
632static void ShowBuildAirportPicker(Window *parent)
633{
634 new BuildAirportWindow(_build_airport_desc, parent);
635}
636
637void InitializeAirportGui()
638{
639 _selected_airport_class = APC_BEGIN;
640 _selected_airport_index = -1;
641}
NUM_AIRPORTS
@ NUM_AIRPORTS
Maximal number of airports in total.
Definition airport.h:41
NEW_AIRPORT_OFFSET
@ NEW_AIRPORT_OFFSET
Number of the first newgrf airport.
Definition airport.h:39
airport_cmd.h
Command definitions related to airports.
PlaceAirport
static void PlaceAirport(TileIndex tile)
Place an airport.
Definition airport_gui.cpp:66
ShowBuildAirToolbar
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
Definition airport_gui.cpp:233
_selected_airport_index
static int _selected_airport_index
the index of the selected airport in the current class or -1
Definition airport_gui.cpp:47
_selected_airport_class
static AirportClassID _selected_airport_class
the currently visible airport class
Definition airport_gui.cpp:46
_selected_airport_layout
static uint8_t _selected_airport_layout
selected airport layout number.
Definition airport_gui.cpp:48
airport_widget.h
Types related to the airport widgets.
WID_AT_DEMOLISH
@ WID_AT_DEMOLISH
Demolish button.
Definition airport_widget.h:16
WID_AT_AIRPORT
@ WID_AT_AIRPORT
Build airport button.
Definition airport_widget.h:15
WID_AP_AIRPORT_LIST
@ WID_AP_AIRPORT_LIST
List of airports.
Definition airport_widget.h:22
WID_AP_ACCEPTANCE
@ WID_AP_ACCEPTANCE
Acceptance info.
Definition airport_widget.h:32
WID_AP_LAYOUT_DECREASE
@ WID_AP_LAYOUT_DECREASE
Decrease the layout number.
Definition airport_widget.h:25
WID_AP_LAYOUT_INCREASE
@ WID_AP_LAYOUT_INCREASE
Increase the layout number.
Definition airport_widget.h:26
WID_AP_CLASS_DROPDOWN
@ WID_AP_CLASS_DROPDOWN
Dropdown of airport classes.
Definition airport_widget.h:21
WID_AP_BTN_DOHILIGHT
@ WID_AP_BTN_DOHILIGHT
Show the coverage button.
Definition airport_widget.h:31
WID_AP_AIRPORT_SPRITE
@ WID_AP_AIRPORT_SPRITE
A visual display of the airport currently selected.
Definition airport_widget.h:27
WID_AP_SCROLLBAR
@ WID_AP_SCROLLBAR
Scrollbar of the list.
Definition airport_widget.h:23
WID_AP_BTN_DONTHILIGHT
@ WID_AP_BTN_DONTHILIGHT
Don't show the coverage button.
Definition airport_widget.h:30
WID_AP_LAYOUT_NUM
@ WID_AP_LAYOUT_NUM
Current number of the layout.
Definition airport_widget.h:24
WID_AP_EXTRA_TEXT
@ WID_AP_EXTRA_TEXT
Additional text about the airport.
Definition airport_widget.h:28
BuildAirportWindow
Definition airport_gui.cpp:241
BuildAirportWindow::BuildAirportClassDropDown
static DropDownList BuildAirportClassDropDown()
Build a dropdown list of available airport classes.
Definition airport_gui.cpp:247
BuildAirportWindow::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 airport_gui.cpp:497
BuildAirportWindow::OnRealtimeTick
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Definition airport_gui.cpp:578
BuildAirportWindow::preview_sprite
SpriteID preview_sprite
Cached airport preview sprite.
Definition airport_gui.cpp:242
BuildAirportWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
Definition airport_gui.cpp:569
BuildAirportWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition airport_gui.cpp:425
BuildAirportWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition airport_gui.cpp:386
BuildAirportWindow::GetWidgetString
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition airport_gui.cpp:302
BuildAirportWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition airport_gui.cpp:296
BuildAirportWindow::SelectFirstAvailableAirport
void SelectFirstAvailableAirport(bool change_class)
Select the first available airport.
Definition airport_gui.cpp:541
BuildAirportWindow::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 airport_gui.cpp:325
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:177
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
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::Specs
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
Definition newgrf_class.h:58
NewGRFClass::Get
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Definition newgrf_class_func.h:82
NewGRFClass::GetSpecCount
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition newgrf_class.h:70
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
OverflowSafeInt< int64_t >
PickerWindowBase
Base class for windows opened from a toolbar.
Definition window_gui.h:992
PickerWindowBase::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3602
Scrollbar
Scrollbar data structure.
Definition widget_type.h:711
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:795
Scrollbar::SetCapacity
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
Definition widget_type.h:809
Scrollbar::GetScrolledRowFromWidget
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:2453
Scrollbar::SetPosition
bool SetPosition(size_type position)
Sets the position of the first visible element.
Definition widget_type.h:825
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:875
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:98
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
command_func.h
Functions related to commands.
CommandFlagsToDCFlags
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition command_func.h:49
Commands
Commands
List of commands.
Definition command_type.h:196
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
company_func.h
Functions related to companies.
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
DIR_W
@ DIR_W
West.
Definition direction_type.h:32
DIR_E
@ DIR_E
East.
Definition direction_type.h:28
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
Show a drop down list.
Definition dropdown.cpp:418
dropdown_func.h
Functions related to the drop down widget.
dropdown_type.h
Types related to the drop down widget.
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition dropdown_type.h:56
economy_func.h
Functions related to the economy.
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
CentreBounds
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Definition geometry_type.hpp:26
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:968
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:897
DrawString
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:668
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawSprite
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:1034
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:751
DrawStringMultiLine
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:785
GfxFillRect
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:115
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:346
SetMatrixDataTip
constexpr NWidgetPart SetMatrixDataTip(uint32_t cols, uint32_t rows, StringID tip={})
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition widget_type.h:1311
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1222
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1254
SetToolbarMinimalSize
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
Definition widget_type.h:1178
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1378
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1402
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1335
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1243
SetToolbarSpacerMinimalSize
constexpr NWidgetPart SetToolbarSpacerMinimalSize()
Widget part function to setting the minimal size for a toolbar spacer.
Definition widget_type.h:1168
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1159
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1321
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1232
SetArrowWidgetTypeTip
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
Definition widget_type.h:1277
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1427
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1190
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1148
SetPIPRatio
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
Definition widget_type.h:1390
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:968
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
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
GetAirportTextCallback
StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback)
Get a custom text for the airport.
Definition newgrf_airport.cpp:280
newgrf_airport.h
NewGRF handling of airports.
AirportClassID
AirportClassID
List of default airport classes.
Definition newgrf_airport.h:74
APC_BEGIN
@ APC_BEGIN
Lowest valid airport class id.
Definition newgrf_airport.h:75
newgrf_badge_gui.h
GUI functions related to NewGRF badges.
newgrf_callbacks.h
Callbacks that NewGRFs could implement.
CBID_AIRPORT_ADDITIONAL_TEXT
@ CBID_AIRPORT_ADDITIONAL_TEXT
This callback is called from airport list.
Definition newgrf_callbacks.h:250
CBID_AIRPORT_LAYOUT_NAME
@ CBID_AIRPORT_LAYOUT_NAME
Called to determine text to show as airport layout name.
Definition newgrf_callbacks.h:253
PC_BLACK
static constexpr PixelColour PC_BLACK
Black palette colour.
Definition palette_func.h:96
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
SndClickBeep
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
sound_func.h
Functions related to sound.
SND_1F_CONSTRUCTION_OTHER
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:76
ANIMCURSOR_DEMOLISH
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1522
station_cmd.h
Command definitions related to stations.
ShowSelectStationIfNeeded
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
Definition station_gui.cpp:2475
DrawStationCoverageAreaText
int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
Definition station_gui.cpp:77
CheckRedrawStationCoverage
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
Definition station_gui.cpp:159
station_gui.h
Contains enums and function declarations connected with stations GUI.
SCT_ALL
@ SCT_ALL
Draw all cargoes.
Definition station_gui.h:24
station_type.h
Types related to stations.
CA_UNMODIFIED
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition station_type.h:120
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
AirportSpec
Defines the data structure for an airport.
Definition newgrf_airport.h:109
AirportSpec::name
StringID name
name of this airport
Definition newgrf_airport.h:119
AirportSpec::layouts
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
Definition newgrf_airport.h:111
AirportSpec::catchment
uint8_t catchment
catchment area of this airport
Definition newgrf_airport.h:116
AirportSpec::maintenance_cost
uint16_t maintenance_cost
maintenance cost multiplier
Definition newgrf_airport.h:122
AirportSpec::enabled
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
Definition newgrf_airport.h:124
AirportSpec::size_y
uint8_t size_y
size of airport in y direction
Definition newgrf_airport.h:114
AirportSpec::size_x
uint8_t size_x
size of airport in x direction
Definition newgrf_airport.h:113
AirportSpec::Get
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
Definition newgrf_airport.cpp:59
AirportSpec::IsAvailable
bool IsAvailable() const
Check whether this airport is available to build.
Definition newgrf_airport.cpp:86
AirportSpec::noise_level
uint8_t noise_level
noise that this airport generates
Definition newgrf_airport.h:115
BuildAirToolbarWindow
Airport build toolbar window handler.
Definition airport_gui.cpp:86
BuildAirToolbarWindow::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 airport_gui.cpp:159
BuildAirToolbarWindow::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 airport_gui.cpp:169
BuildAirToolbarWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition airport_gui.cpp:96
BuildAirToolbarWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition airport_gui.cpp:176
BuildAirToolbarWindow::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 airport_gui.cpp:144
BuildAirToolbarWindow::AirportToolbarGlobalHotkeys
static EventState AirportToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildAirToolbarWindow.
Definition airport_gui.cpp:191
BuildAirToolbarWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition airport_gui.cpp:108
BuildAirToolbarWindow::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 airport_gui.cpp:124
BuildAirToolbarWindow::OnInitialPosition
Point OnInitialPosition(int16_t sm_width, int16_t sm_height, int window_number) override
Compute the initial position of the window.
Definition airport_gui.cpp:164
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:653
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:84
Coord2D< int >
Coord2D::y
T y
Y coordinate.
Definition geometry_type.hpp:35
Coord2D::x
T x
X coordinate.
Definition geometry_type.hpp:34
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
EconomySettings::station_noise_level
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Definition settings_type.h:560
EconomySettings::infrastructure_maintenance
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
Definition settings_type.h:563
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition settings_type.h:225
GUISettings::station_show_coverage
bool station_show_coverage
whether to highlight coverage area
Definition settings_type.h:224
GUISettings::link_terraform_toolbar
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
Definition settings_type.h:176
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition settings_type.h:642
GameSettings::station
StationSettings station
settings related to station management
Definition settings_type.h:644
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
NewGRFSpecBase::index
uint16_t index
Index within class of this spec, invalid until inserted into class.
Definition newgrf_class.h:19
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition geometry_type.hpp:89
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition geometry_type.hpp:237
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition settings_type.h:275
StationSettings::modified_catchment
bool modified_catchment
different-size catchment areas
Definition settings_type.h:593
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
WindowDesc
High level window description.
Definition window_gui.h:168
WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:760
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1104
Window::OnInvalidateData
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:793
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1809
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:784
Window::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:3237
Window::parent
Window * parent
Parent window.
Definition window_gui.h:329
Window::GetWidgetString
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:506
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::DisableWidget
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1799
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:532
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1823
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:315
Window::OnHotkey
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:572
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
GUIPlaceProcDragXY
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
Definition terraform_gui.cpp:112
PlaceProc_DemolishArea
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Definition terraform_gui.cpp:151
ShowTerraformToolbar
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
Definition terraform_gui.cpp:364
terraform_gui.h
GUI stuff related to terraforming.
TILE_SIZE
static constexpr uint TILE_SIZE
Tile size in world coordinates.
Definition tile_type.h:15
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition tilearea_type.h:102
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3573
VpSelectTilesWithMethod
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition viewport.cpp:3291
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
timer.h
Definition of Interval and OneShot timers.
timer_game_calendar.h
Definition of the game-calendar-timer.
TRANSPORT_AIR
@ TRANSPORT_AIR
Transport through air.
Definition transport_type.h:28
CanBuildVehicleInfrastructure
bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1903
vehicle_func.h
Functions related to vehicles.
VEH_AIRCRAFT
@ VEH_AIRCRAFT
Aircraft vehicle type.
Definition vehicle_type.h:28
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition viewport.cpp:2619
SetViewportCatchmentStation
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition viewport.cpp:3713
viewport_func.h
Functions related to (drawing on) viewports.
ViewportPlaceMethod
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition viewport_type.h:96
ViewportDragDropSelectionProcess
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you've selected it.
Definition viewport_type.h:115
DDSP_DEMOLISH_AREA
@ DDSP_DEMOLISH_AREA
Clear area.
Definition viewport_type.h:116
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition widget_type.h:107
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:57
WWT_MATRIX
@ WWT_MATRIX
Grid of rows and columns.
Definition widget_type.h:50
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:544
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1195
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2099
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1207
AlignInitialConstructionToolbar
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
Definition window.cpp:1701
window_func.h
Window functions not directly related to making/drawing windows.
window_gui.h
Functions, definitions and such used only by the GUI.
WindowDefaultFlag::Construction
@ Construction
This window is used for construction; close it whenever changing company.
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:144
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
INVALID_WIDGET
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
Definition window_type.h:23
WC_BUILD_STATION
@ WC_BUILD_STATION
Build station; Window numbers:
Definition window_type.h:408
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:78
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_SCEN_LAND_GEN
@ WC_SCEN_LAND_GEN
Landscape generation (in Scenario Editor); Window numbers:
Definition window_type.h:460
WC_SELECT_STATION
@ WC_SELECT_STATION
Select station (when joining stations); Window numbers:
Definition window_type.h:247
zoom_func.h
Functions related to zooming.