41#include "table/strings.h"
50static void ShowBuildAirportPicker(
Window *parent);
56 if (result.
Failed())
return;
74 auto proc = [=](
bool test, StationID to_join) ->
bool {
78 return Command<Commands::BuildAirport>::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, airport_type, layout, to_join, adjacent);
86struct BuildAirToolbarWindow :
Window {
96 void Close([[maybe_unused]]
int data = 0)
override
108 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
110 if (!gui_scope)
return;
129 ShowBuildAirportPicker(
this);
130 this->last_user_action = widget;
136 this->last_user_action = widget;
146 switch (this->last_user_action) {
155 default: NOT_REACHED();
199 static inline HotkeyList hotkeys{
"airtoolbar", {
205static constexpr std::initializer_list<NWidgetPart> _nested_air_toolbar_widgets = {
222 _nested_air_toolbar_widgets,
223 &BuildAirToolbarWindow::hotkeys
241class BuildAirportWindow :
public PickerWindowBase {
252 list.push_back(MakeDropDownListStringItem(cls.name, cls.Index()));
282 bool select_first_airport =
true;
288 select_first_airport =
false;
289 this->UpdateSelectSize();
296 void Close([[maybe_unused]]
int data = 0)
override
312 if (
string != STR_UNDEFINED) {
314 }
else if (as->
layouts.size() > 1) {
333 d.width += padding.width;
334 d.height += padding.height;
348 size.height = 5 * this->line_height;
356 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->
layouts.size()); layout++) {
357 SpriteID sprite = GetCustomAirportSprite(as, layout);
372 for (uint8_t layout = 0; layout < static_cast<uint8_t>(as->
layouts.size()); layout++) {
374 if (
string == STR_UNDEFINED)
continue;
394 for (
auto it = first; it != last; ++it) {
400 row = row.
Translate(0, this->line_height);
401 text = text.
Translate(0, this->line_height);
407 if (this->preview_sprite != 0) {
417 if (
string != STR_UNDEFINED) {
430 const int bottom = r.bottom;
459 if (r.top > bottom) {
464 void SelectOtherAirport(
int airport_index)
469 this->UpdateSelectSize();
473 void UpdateSelectSize()
484 if (rotation ==
DIR_E || rotation ==
DIR_W) std::swap(w, h);
506 if (num_clicked == INT32_MAX)
break;
508 if (as->
IsAvailable()) this->SelectOtherAirport(num_clicked);
518 this->UpdateSelectSize();
524 this->UpdateSelectSize();
530 this->UpdateSelectSize();
547 this->SelectOtherAirport(as->
index);
555 for (
const auto &as : cls.Specs()) {
558 this->vscroll->
SetCount(cls.GetSpecCount());
559 this->SelectOtherAirport(as->
index);
566 this->SelectOtherAirport(-1);
588static constexpr std::initializer_list<NWidgetPart> _nested_build_airport_widgets = {
614 SetStringTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
616 SetStringTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
629 _nested_build_airport_widgets
632static void ShowBuildAirportPicker(
Window *parent)
637void 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.
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.
static DropDownList BuildAirportClassDropDown()
Build a dropdown list of available airport classes.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
SpriteID preview_sprite
Cached airport preview sprite.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnPaint() override
The window must be repainted.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void SelectFirstAvailableAirport(bool change_class)
Select the first available airport.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Common return value for all commands.
bool Failed() const
Did this command fail?
An interval timer will fire every interval, and will continue to fire until it is deleted.
static std::span< NewGRFClass< AirportSpec, AirportClassID, Tmax > const > Classes()
std::span< Tspec *const > Specs() const
Get read-only span of specs of this class.
static NewGRFClass * Get(AirportClassID class_index)
uint GetSpecCount() const
Get the number of allocated specs within the class.
static uint GetClassCount()
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(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.
CommandFlags GetCommandFlags(Commands cmd)
Get the command flags associated with the given command.
Functions related to commands.
static constexpr DoCommandFlags CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
Direction
Defines the 8 directions on the map.
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options)
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.
@ InfrastructureAirport
Airports maintenance cost.
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.
int CentreBounds(int min, int max, int size)
Determine where to position a centred object.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
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 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.
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.
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.
#define Point
Macro that prevents name conflicts between included headers.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
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.
NewGRFClass< AirportSpec, AirportClassID, APC_MAX > AirportClass
Information related to airport classes.
int DrawBadgeNameList(Rect r, std::span< const BadgeID > badges, GrfSpecFeature)
Draw names for a list of badge labels.
GUI functions related to NewGRF badges.
Callbacks that NewGRFs could implement.
@ CBID_AIRPORT_ADDITIONAL_TEXT
This callback is called from airport list.
@ CBID_AIRPORT_LAYOUT_NAME
Called to determine text to show as airport layout name.
static constexpr PixelColour PC_BLACK
Black palette colour.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Functions related to sound.
@ 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.
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.
Types related to stations.
static constexpr uint CA_UNMODIFIED
Catchment for all stations with "modified catchment" disabled.
Definition of base types and functions in a cross-platform compatible way.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
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
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
bool station_show_coverage
whether to highlight coverage area
StationSettings station
settings related to station management
List of hotkeys for a window.
All data for a single hotkey.
uint16_t index
Index within class of this spec, invalid until inserted into class.
static bool IsValidID(auto index)
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool modified_catchment
different-size catchment areas
High level window description.
Number to differentiate different windows of the same class.
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
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.
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
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 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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
static constexpr 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.
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.
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.
Point AlignInitialConstructionToolbar(int window_width)
Compute the position of the construction toolbars.
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.
Twindow * AllocateWindowDescFront(WindowDesc &desc, WindowNumber window_number, Targs... extra_arguments)
Open a new window.
@ WDP_AUTO
Find a place automatically.
@ WDP_MANUAL
Manually align the window (so no automatic location finding).
EventState
State of handling an event.
@ ES_NOT_HANDLED
The passed event is not handled.
static constexpr WidgetID INVALID_WIDGET
An invalid widget index.
@ 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.