OpenTTD Source 20250218-master-g53dd1258a7
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 <http://www.gnu.org/licenses/>.
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.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 "safeguards.h"
42
43
47
48static void ShowBuildAirportPicker(Window *parent);
49
50SpriteID GetCustomAirportSprite(const AirportSpec *as, uint8_t layout);
51
52void CcBuildAirport(Commands, const CommandCost &result, TileIndex tile)
53{
54 if (result.Failed()) return;
55
58}
59
64static void PlaceAirport(TileIndex tile)
65{
66 if (_selected_airport_index == -1) return;
67
69 uint8_t layout = _selected_airport_layout;
70 bool adjacent = _ctrl_pressed;
71
72 auto proc = [=](bool test, StationID to_join) -> bool {
73 if (test) {
74 return Command<CMD_BUILD_AIRPORT>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_AIRPORT>()), tile, airport_type, layout, StationID::Invalid(), adjacent).Succeeded();
75 } else {
76 return Command<CMD_BUILD_AIRPORT>::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, airport_type, layout, to_join, adjacent);
77 }
78 };
79
80 ShowSelectStationIfNeeded(TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE), proc);
81}
82
85 int last_user_action; // Last started user action.
86
88 {
89 this->InitNested(window_number);
90 this->OnInvalidateData();
92 this->last_user_action = INVALID_WID_AT;
93 }
94
95 void Close([[maybe_unused]] int data = 0) override
96 {
99 this->Window::Close();
100 }
101
107 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
108 {
109 if (!gui_scope) return;
110
112 this->SetWidgetDisabledState(WID_AT_AIRPORT, !can_build);
113 if (!can_build) {
115
116 /* Show in the tooltip why this button is disabled. */
118 } else {
120 }
121 }
122
123 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
124 {
125 switch (widget) {
126 case WID_AT_AIRPORT:
127 if (HandlePlacePushButton(this, WID_AT_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT)) {
128 ShowBuildAirportPicker(this);
129 this->last_user_action = widget;
130 }
131 break;
132
133 case WID_AT_DEMOLISH:
135 this->last_user_action = widget;
136 break;
137
138 default: break;
139 }
140 }
141
142
143 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
144 {
145 switch (this->last_user_action) {
146 case WID_AT_AIRPORT:
147 PlaceAirport(tile);
148 break;
149
150 case WID_AT_DEMOLISH:
152 break;
153
154 default: NOT_REACHED();
155 }
156 }
157
159 {
160 VpSelectTilesWithMethod(pt.x, pt.y, select_method);
161 }
162
163 void OnPlaceMouseUp([[maybe_unused]] ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt, TileIndex start_tile, TileIndex end_tile) override
164 {
165 if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
166 GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
167 }
168 }
169
179
186 {
187 if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED;
189 if (w == nullptr) return ES_NOT_HANDLED;
190 return w->OnHotkey(hotkey);
191 }
192
193 static inline HotkeyList hotkeys{"airtoolbar", {
194 Hotkey('1', "airport", WID_AT_AIRPORT),
195 Hotkey('2', "demolish", WID_AT_DEMOLISH),
197};
198
199static constexpr NWidgetPart _nested_air_toolbar_widgets[] = {
201 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
202 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
203 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
204 EndContainer(),
206 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_AIRPORT), SetFill(0, 1), SetMinimalSize(42, 22), SetSpriteTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP),
207 NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetFill(1, 1), EndContainer(),
208 NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetSpriteTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
209 EndContainer(),
210};
211
212static WindowDesc _air_toolbar_desc(
213 WDP_ALIGN_TOOLBAR, "toolbar_air", 0, 0,
216 _nested_air_toolbar_widgets,
217 &BuildAirToolbarWindow::hotkeys
218);
219
228{
229 if (!Company::IsValidID(_local_company)) return nullptr;
230
232 return AllocateWindowDescFront<BuildAirToolbarWindow>(_air_toolbar_desc, TRANSPORT_AIR);
233}
234
237 int line_height;
238 Scrollbar *vscroll;
239
242 {
243 DropDownList list;
244
245 for (const auto &cls : AirportClass::Classes()) {
246 list.push_back(MakeDropDownListStringItem(cls.name, cls.Index()));
247 }
248
249 return list;
250 }
251
252public:
254 {
255 this->CreateNestedTree();
256
257 this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR);
258 this->vscroll->SetCapacity(5);
259 this->vscroll->SetPosition(0);
260
262
265 this->OnInvalidateData();
266
267 /* Ensure airport class is valid (changing NewGRFs). */
270 this->vscroll->SetCount(ac->GetSpecCount());
271
272 /* Ensure the airport index is valid for this class (changing NewGRFs). */
273 _selected_airport_index = Clamp(_selected_airport_index, -1, ac->GetSpecCount() - 1);
274
275 /* Only when no valid airport was selected, we want to select the first airport. */
276 bool selectFirstAirport = true;
277 if (_selected_airport_index != -1) {
278 const AirportSpec *as = ac->GetSpec(_selected_airport_index);
279 if (as->IsAvailable()) {
280 /* Ensure the airport layout is valid. */
281 _selected_airport_layout = Clamp(_selected_airport_layout, 0, static_cast<uint8_t>(as->layouts.size() - 1));
282 selectFirstAirport = false;
283 this->UpdateSelectSize();
284 }
285 }
286
288 }
289
290 void Close([[maybe_unused]] int data = 0) override
291 {
294 }
295
296 void SetStringParameters(WidgetID widget) const override
297 {
298 switch (widget) {
301 break;
302
305 if (_selected_airport_index != -1) {
308 if (string != STR_UNDEFINED) {
309 SetDParam(0, string);
310 } else if (as->layouts.size() > 1) {
313 }
314 }
315 break;
316
317 default: break;
318 }
319 }
320
322 {
323 switch (widget) {
325 Dimension d = {0, 0};
326 for (const auto &cls : AirportClass::Classes()) {
327 d = maxdim(d, GetStringBoundingBox(cls.name));
328 }
329 d.width += padding.width;
330 d.height += padding.height;
331 size = maxdim(size, d);
332 break;
333 }
334
335 case WID_AP_AIRPORT_LIST: {
336 for (int i = 0; i < NUM_AIRPORTS; i++) {
337 const AirportSpec *as = AirportSpec::Get(i);
338 if (!as->enabled) continue;
339
340 size.width = std::max(size.width, GetStringBoundingBox(as->name).width + padding.width);
341 }
342
343 this->line_height = GetCharacterHeight(FS_NORMAL) + padding.height;
344 size.height = 5 * this->line_height;
345 break;
346 }
347
349 for (int i = 0; i < NUM_AIRPORTS; i++) {
350 const AirportSpec *as = AirportSpec::Get(i);
351 if (!as->enabled) continue;
352 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
353 SpriteID sprite = GetCustomAirportSprite(as, layout);
354 if (sprite != 0) {
355 Dimension d = GetSpriteSize(sprite);
358 size = maxdim(d, size);
359 }
360 }
361 }
362 break;
363
365 for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
366 const AirportSpec *as = AirportSpec::Get(i);
367 if (!as->enabled) continue;
368 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->layouts.size()); layout++) {
370 if (string == STR_UNDEFINED) continue;
371
373 size = maxdim(d, size);
374 }
375 }
376 break;
377
378 default: break;
379 }
380 }
381
382 void DrawWidget(const Rect &r, WidgetID widget) const override
383 {
384 switch (widget) {
385 case WID_AP_AIRPORT_LIST: {
386 Rect row = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.bevel);
387 Rect text = r.WithHeight(this->line_height).Shrink(WidgetDimensions::scaled.matrix);
388 const auto specs = AirportClass::Get(_selected_airport_class)->Specs();
389 auto [first, last] = this->vscroll->GetVisibleRangeIterators(specs);
390 for (auto it = first; it != last; ++it) {
391 const AirportSpec *as = *it;
392 if (!as->IsAvailable()) {
394 }
395 DrawString(text, as->name, (static_cast<int>(as->index) == _selected_airport_index) ? TC_WHITE : TC_BLACK);
396 row = row.Translate(0, this->line_height);
397 text = text.Translate(0, this->line_height);
398 }
399 break;
400 }
401
403 if (this->preview_sprite != 0) {
404 Dimension d = GetSpriteSize(this->preview_sprite);
405 DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), CenterBounds(r.left, r.right, d.width), CenterBounds(r.top, r.bottom, d.height));
406 }
407 break;
408
410 if (_selected_airport_index != -1) {
413 if (string != STR_UNDEFINED) {
414 DrawStringMultiLine(r.left, r.right, r.top, r.bottom, string, TC_BLACK);
415 }
416 }
417 break;
418 }
419 }
420
421 void OnPaint() override
422 {
423 this->DrawWidgets();
424
425 Rect r = this->GetWidget<NWidgetBase>(WID_AP_ACCEPTANCE)->GetCurrentRect();
426 const int bottom = r.bottom;
427 r.bottom = INT_MAX; // Allow overflow as we want to know the required height.
428
429 if (_selected_airport_index != -1) {
431 int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
432
433 /* only show the station (airport) noise, if the noise option is activated */
435 /* show the noise of the selected airport */
436 SetDParam(0, as->noise_level);
439 }
440
442 Money monthly = _price[PR_INFRASTRUCTURE_AIRPORT] * as->maintenance_cost >> 3;
443 SetDParam(0, monthly * 12);
446 }
447
448 /* strings such as 'Size' and 'Coverage Area' */
449 r.top = DrawBadgeNameList(r, as->badges, GSF_AIRPORTS) + WidgetDimensions::scaled.vsep_normal;
451 r.top = DrawStationCoverageAreaText(r, SCT_ALL, rad, true);
452 }
453
454 /* Resize background if the window is too small.
455 * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
456 * (This is the case, if making the window bigger moves the mouse into the window.) */
457 if (r.top > bottom) {
458 ResizeWindow(this, 0, r.top - bottom, false);
459 }
460 }
461
462 void SelectOtherAirport(int airport_index)
463 {
466
467 this->UpdateSelectSize();
468 this->SetDirty();
469 }
470
471 void UpdateSelectSize()
472 {
473 if (_selected_airport_index == -1) {
474 SetTileSelectSize(1, 1);
477 } else {
479 int w = as->size_x;
480 int h = as->size_y;
481 Direction rotation = as->layouts[_selected_airport_layout].rotation;
482 if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
483 SetTileSelectSize(w, h);
484
485 this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
486
489
490 int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
491 if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
492 }
493 }
494
495 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
496 {
497 switch (widget) {
500 break;
501
502 case WID_AP_AIRPORT_LIST: {
503 int32_t num_clicked = this->vscroll->GetScrolledRowFromWidget(pt.y, this, widget, 0, this->line_height);
504 if (num_clicked == INT32_MAX) break;
506 if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
507 break;
508 }
509
514 this->SetDirty();
516 this->UpdateSelectSize();
517 SetViewportCatchmentStation(nullptr, true);
518 break;
519
522 this->UpdateSelectSize();
523 this->SetDirty();
524 break;
525
528 this->UpdateSelectSize();
529 this->SetDirty();
530 break;
531 }
532 }
533
540 {
541 /* First try to select an airport in the selected class. */
543 for (const AirportSpec *as : sel_apclass->Specs()) {
544 if (as->IsAvailable()) {
545 this->SelectOtherAirport(as->index);
546 return;
547 }
548 }
549 if (change_class) {
550 /* If that fails, select the first available airport
551 * from the first class where airports are available. */
552 for (const auto &cls : AirportClass::Classes()) {
553 for (const auto &as : cls.Specs()) {
554 if (as->IsAvailable()) {
555 _selected_airport_class = cls.Index();
556 this->vscroll->SetCount(cls.GetSpecCount());
557 this->SelectOtherAirport(as->index);
558 return;
559 }
560 }
561 }
562 }
563 /* If all airports are unavailable, select nothing. */
564 this->SelectOtherAirport(-1);
565 }
566
567 void OnDropdownSelect(WidgetID widget, int index) override
568 {
569 if (widget == WID_AP_CLASS_DROPDOWN) {
572 this->SelectFirstAvailableAirport(false);
573 }
574 }
575
576 void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
577 {
579 }
580
581 IntervalTimer<TimerGameCalendar> yearly_interval = {{TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE}, [this](auto) {
582 this->InvalidateData();
583 }};
584};
585
586static constexpr NWidgetPart _nested_build_airport_widgets[] = {
588 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
589 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetStringTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
590 EndContainer(),
591 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
594 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL), SetFill(1, 0),
595 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetStringTip(STR_JUST_STRING, STR_STATION_BUILD_AIRPORT_TOOLTIP),
596 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
598 NWidget(WWT_MATRIX, COLOUR_GREY, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetMatrixDataTip(1, 5, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
600 EndContainer(),
601 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_ORIENTATION), SetFill(1, 0),
604 NWidget(WWT_LABEL, INVALID_COLOUR, WID_AP_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_JUST_STRING1),
606 EndContainer(),
607 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_AP_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
608 NWidget(WWT_LABEL, INVALID_COLOUR), SetStringTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE), SetFill(1, 0),
609 NWidget(NWID_HORIZONTAL), SetPIP(14, 0, 14), SetPIPRatio(1, 0, 1),
611 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DONTHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
612 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
613 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DOHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
614 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
615 EndContainer(),
616 EndContainer(),
617 EndContainer(),
619 EndContainer(),
620 EndContainer(),
621};
622
623static WindowDesc _build_airport_desc(
624 WDP_AUTO, nullptr, 0, 0,
627 _nested_build_airport_widgets
628);
629
630static void ShowBuildAirportPicker(Window *parent)
631{
632 new BuildAirportWindow(_build_airport_desc, parent);
633}
634
635void InitializeAirportGui()
636{
639}
@ 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.
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 OnPaint() override
The window must be repainted.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
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.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
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
Struct containing information relating to NewGRF classes for stations and airports.
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
uint GetSpecCount() const
Get the number of allocated specs within the class.
static uint GetClassCount()
Get the number of allocated classes.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Base class for windows opened from a toolbar.
Definition window_gui.h:978
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:3522
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:2459
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.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
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.
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.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:404
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.
Functions related to the economy.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:922
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
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:657
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:114
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:988
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:740
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:774
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:333
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 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 SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetValues widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
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:937
GUI functions that shouldn't be here.
Hotkey related functions.
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
constexpr void Swap(T &a, T &b)
Type safe swap operation.
StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback)
Get a custom text for the airport.
NewGRF handling of airports.
AirportClassID
List of default airport classes.
@ APC_BEGIN
Lowest valid airport class id.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
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 const uint8_t 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:58
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:57
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:76
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition sprites.h:1508
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.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:163
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.
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
Airport build toolbar window handler.
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.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool station_noise_level
build new airports when the town noise level is still within accepted limits
bool infrastructure_maintenance
enable monthly maintenance fee for owner infrastructure
bool persistent_buildingtools
keep the building tools active after usage
bool station_show_coverage
whether to highlight coverage area
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
EconomySettings economy
settings to change the economy
StationSettings station
settings related to station management
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
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 click_beep
Beep on a random selection of buttons.
bool confirm
Play sound effect on successful constructions or other actions.
bool modified_catchment
different-size catchment areas
Point size
Size, in tile "units", of the white/red selection area.
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:272
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1044
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
Definition window_gui.h:779
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1730
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:731
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3157
Window * parent
Parent window.
Definition window_gui.h:327
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1720
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:522
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:969
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1743
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:311
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition window.cpp:562
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:301
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
static const 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, uint8_t subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition vehicle.cpp:1919
Functions related to vehicles.
@ VEH_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:43
@ 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:46
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:41
@ 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:39
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:22
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:23
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:1137
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2019
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1149
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.
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:145
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
Definition window_gui.h:147
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_BUILD_STATION
Build station; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:75
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ 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.