47 static void ShowBuildAirportPicker(
Window *parent);
53 if (result.
Failed())
return;
71 auto proc = [=](
bool test, StationID to_join) ->
bool {
91 this->last_user_action = INVALID_WID_AT;
94 void Close([[maybe_unused]]
int data = 0)
override
106 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
108 if (!gui_scope)
return;
116 this->GetWidget<NWidgetCore>(
WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_DISABLED_NO_VEHICLE_AVAILABLE);
118 this->GetWidget<NWidgetCore>(
WID_AT_AIRPORT)->SetToolTip(STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP);
122 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
127 ShowBuildAirportPicker(
this);
128 this->last_user_action = widget;
134 this->last_user_action = widget;
142 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
144 switch (this->last_user_action) {
153 default: NOT_REACHED();
192 static inline HotkeyList hotkeys{
"airtoolbar", {
198 static constexpr
NWidgetPart _nested_air_toolbar_widgets[] = {
215 _nested_air_toolbar_widgets,
216 &BuildAirToolbarWindow::hotkeys
231 return AllocateWindowDescFront<BuildAirToolbarWindow>(_air_toolbar_desc,
TRANSPORT_AIR);
245 list.push_back(MakeDropDownListStringItem(cls.name, cls.Index()));
275 bool selectFirstAirport =
true;
281 selectFirstAirport =
false;
282 this->UpdateSelectSize();
289 void Close([[maybe_unused]]
int data = 0)
override
295 void SetStringParameters(
WidgetID widget)
const override
307 if (
string != STR_UNDEFINED) {
309 }
else if (as->
layouts.size() > 1) {
310 SetDParam(0, STR_STATION_BUILD_AIRPORT_LAYOUT_NAME);
328 d.width += padding.width;
329 d.height += padding.height;
343 size.height = 5 * this->line_height;
351 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->
layouts.size()); layout++) {
352 SpriteID sprite = GetCustomAirportSprite(as, layout);
367 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->
layouts.size()); layout++) {
369 if (
string == STR_UNDEFINED)
continue;
381 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
389 for (
auto it = first; it != last; ++it) {
395 row = row.
Translate(0, this->line_height);
396 text = text.
Translate(0, this->line_height);
402 if (this->preview_sprite != 0) {
412 if (
string != STR_UNDEFINED) {
454 if (
top > r.bottom) {
459 void SelectOtherAirport(
int airport_index)
464 this->UpdateSelectSize();
468 void UpdateSelectSize()
492 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
501 if (num_clicked == INT32_MAX)
break;
503 if (as->
IsAvailable()) this->SelectOtherAirport(num_clicked);
513 this->UpdateSelectSize();
519 this->UpdateSelectSize();
525 this->UpdateSelectSize();
542 this->SelectOtherAirport(as->
index);
550 for (
const auto &as : cls.Specs()) {
553 this->vscroll->
SetCount(cls.GetSpecCount());
554 this->SelectOtherAirport(as->
index);
561 this->SelectOtherAirport(-1);
564 void OnDropdownSelect(
WidgetID widget,
int index)
override
583 static constexpr
NWidgetPart _nested_build_airport_widgets[] = {
609 SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
611 SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
624 _nested_build_airport_widgets
627 static void ShowBuildAirportPicker(
Window *parent)
632 void InitializeAirportGui()
@ NUM_AIRPORTS
Maximal number of airports in total.
@ NEW_AIRPORT_OFFSET
Number of the first newgrf airport.
Command definitions related to airports.
static void PlaceAirport(TileIndex tile)
Place an airport.
static int _selected_airport_index
the index of the selected airport in the current class or -1
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
static AirportClassID _selected_airport_class
the currently visible airport class
static uint8_t _selected_airport_layout
selected airport layout number.
static DropDownList BuildAirportClassDropDown()
Build a dropdown list of available airport classes.
SpriteID preview_sprite
Cached airport preview sprite.
void OnPaint() override
The window must be repainted.
void OnRealtimeTick([[maybe_unused]] uint delta_ms) override
Called periodically.
void SelectFirstAvailableAirport(bool change_class)
Select the first available airport.
Common return value for all commands.
bool Failed() const
Did this command fail?
Struct containing information relating to NewGRF classes for stations and airports.
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
static std::span< NewGRFClass< Tspec, Tindex, Tmax > const > Classes()
Get read-only span of all classes of this type.
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.
void Close([[maybe_unused]] int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Functions related to commands.
static constexpr DoCommandFlag 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.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
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.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.
bool _ctrl_pressed
Is Ctrl pressed?
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.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
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.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
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.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
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.
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.
ClientSettings _settings_client
The current settings for this game.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Command definitions related to stations.
void ShowSelectStationIfNeeded(TileArea ta, StationPickerCmdProc proc)
Show the station selection window when needed.
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageType sct, int rad, bool supplies)
Calculates and draws the accepted or supplied cargo around the selected tile(s)
Contains enums and function declarations connected with stations GUI.
@ SCT_ALL
Draw all cargoes.
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.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Defines the data structure for an airport.
StringID name
name of this airport
std::vector< AirportTileLayout > layouts
List of layouts composing the airport.
uint8_t catchment
catchment area of this airport
uint16_t maintenance_cost
maintenance cost multiplier
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
uint8_t size_y
size of airport in y direction
uint8_t size_x
size of airport in x direction
static const AirportSpec * Get(uint8_t type)
Retrieve airport spec for the given airport.
bool IsAvailable() const
Check whether this airport is available to build.
uint8_t noise_level
noise that this airport generates
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.
All data for a single hotkey.
uint16_t index
Index within class of this spec, invalid until inserted into class.
Coordinates of a point in 2D.
static bool IsValidID(size_t 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.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Window * parent
Parent window.
ResizeInfo resize
Resize information.
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
int top
y position of top edge of the window
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
virtual void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true)
Some data on this window has become invalid.
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
WindowNumber window_number
Window number within the window class.
static const uint TILE_SIZE
Tile size in world coordinates.
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.
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.
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.
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
@ WDP_ALIGN_TOOLBAR
Align toward the toolbar.
int32_t WindowNumber
Number to differentiate different windows of the same class.
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:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ 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.