OpenTTD
airport_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "window_gui.h"
14 #include "station_gui.h"
15 #include "terraform_gui.h"
16 #include "sound_func.h"
17 #include "window_func.h"
18 #include "strings_func.h"
19 #include "viewport_func.h"
20 #include "company_func.h"
21 #include "tilehighlight_func.h"
22 #include "company_base.h"
23 #include "station_type.h"
24 #include "newgrf_airport.h"
25 #include "newgrf_callbacks.h"
26 #include "widgets/dropdown_type.h"
27 #include "core/geometry_func.hpp"
28 #include "hotkeys.h"
29 #include "vehicle_func.h"
30 #include "gui.h"
31 
32 #include "widgets/airport_widget.h"
33 
34 #include "safeguards.h"
35 
36 
40 
41 static void ShowBuildAirportPicker(Window *parent);
42 
43 SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
44 
45 void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
46 {
47  if (result.Failed()) return;
48 
49  if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_SPLAT_OTHER, tile);
51 }
52 
57 static void PlaceAirport(TileIndex tile)
58 {
59  if (_selected_airport_index == -1) return;
60  uint32 p2 = _ctrl_pressed;
61  SB(p2, 16, 16, INVALID_STATION); // no station to join
62 
63  uint32 p1 = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex();
64  p1 |= _selected_airport_layout << 8;
65  CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
66  ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
67 }
68 
71  int last_user_action; // Last started user action.
72 
74  {
75  this->InitNested(window_number);
77  this->last_user_action = WIDGET_LIST_END;
78  }
79 
81  {
84  }
85 
91  void OnInvalidateData(int data = 0, bool gui_scope = true) override
92  {
93  if (!gui_scope) return;
94 
96  }
97 
98  void OnClick(Point pt, int widget, int click_count) override
99  {
100  switch (widget) {
101  case WID_AT_AIRPORT:
102  if (HandlePlacePushButton(this, WID_AT_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT)) {
103  ShowBuildAirportPicker(this);
104  this->last_user_action = widget;
105  }
106  break;
107 
108  case WID_AT_DEMOLISH:
110  this->last_user_action = widget;
111  break;
112 
113  default: break;
114  }
115  }
116 
117 
118  void OnPlaceObject(Point pt, TileIndex tile) override
119  {
120  switch (this->last_user_action) {
121  case WID_AT_AIRPORT:
122  PlaceAirport(tile);
123  break;
124 
125  case WID_AT_DEMOLISH:
127  break;
128 
129  default: NOT_REACHED();
130  }
131  }
132 
133  void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) override
134  {
135  VpSelectTilesWithMethod(pt.x, pt.y, select_method);
136  }
137 
138  void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) override
139  {
140  if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
141  GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
142  }
143  }
144 
145  void OnPlaceObjectAbort() override
146  {
148 
149  this->RaiseButtons();
150 
153  }
154 
155  static HotkeyList hotkeys;
156 };
157 
164 {
165  if (_game_mode != GM_NORMAL || !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
167  if (w == nullptr) return ES_NOT_HANDLED;
168  return w->OnHotkey(hotkey);
169 }
170 
171 static Hotkey airtoolbar_hotkeys[] = {
172  Hotkey('1', "airport", WID_AT_AIRPORT),
173  Hotkey('2', "demolish", WID_AT_DEMOLISH),
174  HOTKEY_LIST_END
175 };
176 HotkeyList BuildAirToolbarWindow::hotkeys("airtoolbar", airtoolbar_hotkeys, AirportToolbarGlobalHotkeys);
177 
178 static const NWidgetPart _nested_air_toolbar_widgets[] = {
180  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
181  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
182  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
183  EndContainer(),
185  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_AIRPORT), SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP),
186  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetFill(1, 1), EndContainer(),
187  NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_AT_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
188  EndContainer(),
189 };
190 
191 static WindowDesc _air_toolbar_desc(
192  WDP_ALIGN_TOOLBAR, "toolbar_air", 0, 0,
195  _nested_air_toolbar_widgets, lengthof(_nested_air_toolbar_widgets),
196  &BuildAirToolbarWindow::hotkeys
197 );
198 
207 {
208  if (!Company::IsValidID(_local_company)) return nullptr;
209 
211  return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
212 }
213 
216  int line_height;
217  Scrollbar *vscroll;
218 
221  {
222  DropDownList list;
223 
224  for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
225  list.emplace_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
226  }
227 
228  return list;
229  }
230 
231 public:
233  {
234  this->CreateNestedTree();
235 
236  this->vscroll = this->GetScrollbar(WID_AP_SCROLLBAR);
237  this->vscroll->SetCapacity(5);
238  this->vscroll->SetPosition(0);
239 
241 
244  this->OnInvalidateData();
245 
246  /* Ensure airport class is valid (changing NewGRFs). */
247  _selected_airport_class = Clamp(_selected_airport_class, APC_BEGIN, (AirportClassID)(AirportClass::GetClassCount() - 1));
249  this->vscroll->SetCount(ac->GetSpecCount());
250 
251  /* Ensure the airport index is valid for this class (changing NewGRFs). */
253 
254  /* Only when no valid airport was selected, we want to select the first airport. */
255  bool selectFirstAirport = true;
256  if (_selected_airport_index != -1) {
257  const AirportSpec *as = ac->GetSpec(_selected_airport_index);
258  if (as->IsAvailable()) {
259  /* Ensure the airport layout is valid. */
261  selectFirstAirport = false;
262  this->UpdateSelectSize();
263  }
264  }
265 
266  if (selectFirstAirport) this->SelectFirstAvailableAirport(true);
267  }
268 
269  virtual ~BuildAirportWindow()
270  {
272  }
273 
274  void SetStringParameters(int widget) const override
275  {
276  switch (widget) {
279  break;
280 
281  case WID_AP_LAYOUT_NUM:
282  SetDParam(0, STR_EMPTY);
283  if (_selected_airport_index != -1) {
286  if (string != STR_UNDEFINED) {
287  SetDParam(0, string);
288  } else if (as->num_table > 1) {
289  SetDParam(0, STR_STATION_BUILD_AIRPORT_LAYOUT_NAME);
291  }
292  }
293  break;
294 
295  default: break;
296  }
297  }
298 
299  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
300  {
301  switch (widget) {
302  case WID_AP_CLASS_DROPDOWN: {
303  Dimension d = {0, 0};
304  for (uint i = 0; i < AirportClass::GetClassCount(); i++) {
306  d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
307  }
308  d.width += padding.width;
309  d.height += padding.height;
310  *size = maxdim(*size, d);
311  break;
312  }
313 
314  case WID_AP_AIRPORT_LIST: {
315  for (int i = 0; i < NUM_AIRPORTS; i++) {
316  const AirportSpec *as = AirportSpec::Get(i);
317  if (!as->enabled) continue;
318 
319  size->width = max(size->width, GetStringBoundingBox(as->name).width);
320  }
321 
322  this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
323  size->height = 5 * this->line_height;
324  break;
325  }
326 
328  for (int i = 0; i < NUM_AIRPORTS; i++) {
329  const AirportSpec *as = AirportSpec::Get(i);
330  if (!as->enabled) continue;
331  for (byte layout = 0; layout < as->num_table; layout++) {
332  SpriteID sprite = GetCustomAirportSprite(as, layout);
333  if (sprite != 0) {
334  Dimension d = GetSpriteSize(sprite);
337  *size = maxdim(d, *size);
338  }
339  }
340  }
341  break;
342 
343  case WID_AP_EXTRA_TEXT:
344  for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
345  const AirportSpec *as = AirportSpec::Get(i);
346  if (!as->enabled) continue;
347  for (byte layout = 0; layout < as->num_table; layout++) {
349  if (string == STR_UNDEFINED) continue;
350 
351  /* STR_BLACK_STRING is used to start the string with {BLACK} */
352  SetDParam(0, string);
353  Dimension d = GetStringMultiLineBoundingBox(STR_BLACK_STRING, *size);
354  *size = maxdim(d, *size);
355  }
356  }
357  break;
358 
359  default: break;
360  }
361  }
362 
363  void DrawWidget(const Rect &r, int widget) const override
364  {
365  switch (widget) {
366  case WID_AP_AIRPORT_LIST: {
367  int y = r.top;
369  for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < apclass->GetSpecCount(); i++) {
370  const AirportSpec *as = apclass->GetSpec(i);
371  if (!as->IsAvailable()) {
372  GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER);
373  }
374  DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, as->name, ((int)i == _selected_airport_index) ? TC_WHITE : TC_BLACK);
375  y += this->line_height;
376  }
377  break;
378  }
379 
381  if (this->preview_sprite != 0) {
382  Dimension d = GetSpriteSize(this->preview_sprite);
383  DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), (r.left + r.right - d.width) / 2, (r.top + r.bottom - d.height) / 2);
384  }
385  break;
386 
387  case WID_AP_EXTRA_TEXT:
388  if (_selected_airport_index != -1) {
391  if (string != STR_UNDEFINED) {
392  SetDParam(0, string);
393  DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_BLACK_STRING);
394  }
395  }
396  break;
397  }
398  }
399 
400  void OnPaint() override
401  {
402  this->DrawWidgets();
403 
404  uint16 top = this->GetWidget<NWidgetBase>(WID_AP_BTN_DOHILIGHT)->pos_y + this->GetWidget<NWidgetBase>(WID_AP_BTN_DOHILIGHT)->current_y + WD_PAR_VSEP_NORMAL;
405  NWidgetBase *panel_nwi = this->GetWidget<NWidgetBase>(WID_AP_BOTTOMPANEL);
406 
407  int right = panel_nwi->pos_x + panel_nwi->current_x;
408  int bottom = panel_nwi->pos_y + panel_nwi->current_y;
409 
410  if (_selected_airport_index != -1) {
413 
414  /* only show the station (airport) noise, if the noise option is activated */
416  /* show the noise of the selected airport */
417  SetDParam(0, as->noise_level);
418  DrawString(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_STATION_BUILD_NOISE);
420  }
421 
422  /* strings such as 'Size' and 'Coverage Area' */
423  top = DrawStationCoverageAreaText(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
425  }
426 
427  /* Resize background if the window is too small.
428  * Never make the window smaller to avoid oscillating if the size change affects the acceptance.
429  * (This is the case, if making the window bigger moves the mouse into the window.) */
430  if (top > bottom) {
431  ResizeWindow(this, 0, top - bottom, false);
432  }
433  }
434 
435  void SelectOtherAirport(int airport_index)
436  {
437  _selected_airport_index = airport_index;
439 
440  this->UpdateSelectSize();
441  this->SetDirty();
442  }
443 
444  void UpdateSelectSize()
445  {
446  if (_selected_airport_index == -1) {
447  SetTileSelectSize(1, 1);
450  } else {
452  int w = as->size_x;
453  int h = as->size_y;
455  if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
456  SetTileSelectSize(w, h);
457 
458  this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
459 
462 
464  if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
465  }
466  }
467 
468  void OnClick(Point pt, int widget, int click_count) override
469  {
470  switch (widget) {
472  ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, WID_AP_CLASS_DROPDOWN);
473  break;
474 
475  case WID_AP_AIRPORT_LIST: {
476  int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
477  if (num_clicked >= this->vscroll->GetCount()) break;
478  const AirportSpec *as = AirportClass::Get(_selected_airport_class)->GetSpec(num_clicked);
479  if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
480  break;
481  }
482 
487  this->SetDirty();
488  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
489  this->UpdateSelectSize();
490  break;
491 
494  this->UpdateSelectSize();
495  this->SetDirty();
496  break;
497 
500  this->UpdateSelectSize();
501  this->SetDirty();
502  break;
503  }
504  }
505 
511  void SelectFirstAvailableAirport(bool change_class)
512  {
513  /* First try to select an airport in the selected class. */
515  for (uint i = 0; i < sel_apclass->GetSpecCount(); i++) {
516  const AirportSpec *as = sel_apclass->GetSpec(i);
517  if (as->IsAvailable()) {
518  this->SelectOtherAirport(i);
519  return;
520  }
521  }
522  if (change_class) {
523  /* If that fails, select the first available airport
524  * from a random class. */
525  for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
526  AirportClass *apclass = AirportClass::Get(j);
527  for (uint i = 0; i < apclass->GetSpecCount(); i++) {
528  const AirportSpec *as = apclass->GetSpec(i);
529  if (as->IsAvailable()) {
531  this->SelectOtherAirport(i);
532  return;
533  }
534  }
535  }
536  }
537  /* If all airports are unavailable, select nothing. */
538  this->SelectOtherAirport(-1);
539  }
540 
541  void OnDropdownSelect(int widget, int index) override
542  {
543  assert(widget == WID_AP_CLASS_DROPDOWN);
545  this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
546  this->SelectFirstAvailableAirport(false);
547  }
548 
549  void OnRealtimeTick(uint delta_ms) override
550  {
552  }
553 };
554 
555 static const NWidgetPart _nested_build_airport_widgets[] = {
557  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
558  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
559  EndContainer(),
560  NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 0), SetPIP(2, 0, 2),
561  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
562  NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_AP_CLASS_DROPDOWN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_STATION_BUILD_AIRPORT_TOOLTIP),
563  NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_AIRPORT_SPRITE), SetFill(1, 0),
565  NWidget(WWT_MATRIX, COLOUR_GREY, WID_AP_AIRPORT_LIST), SetFill(1, 0), SetMatrixDataTip(1, 5, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(WID_AP_SCROLLBAR),
567  EndContainer(),
570  NWidget(WWT_LABEL, COLOUR_GREY, WID_AP_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
572  EndContainer(),
573  NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, WID_AP_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
574  EndContainer(),
575  /* Bottom panel. */
576  NWidget(WWT_PANEL, COLOUR_DARK_GREEN, WID_AP_BOTTOMPANEL), SetPIP(2, 2, 2),
577  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
579  NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
581  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DONTHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
582  SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
583  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_AP_BTN_DOHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
584  SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
585  EndContainer(),
586  NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
587  EndContainer(),
588  NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1), SetFill(1, 0),
589  EndContainer(),
590 };
591 
592 static WindowDesc _build_airport_desc(
593  WDP_AUTO, "build_station_air", 0, 0,
596  _nested_build_airport_widgets, lengthof(_nested_build_airport_widgets)
597 );
598 
599 static void ShowBuildAirportPicker(Window *parent)
600 {
601  new BuildAirportWindow(&_build_airport_desc, parent);
602 }
603 
604 void InitializeAirportGui()
605 {
608 }
EventState
State of handling an event.
Definition: window_type.h:713
This callback is called from airport list.
Functions related to OTTD&#39;s strings.
ViewportDragDropSelectionProcess
Drag and drop selection process, or, what to do with an area of land when you&#39;ve selected it...
Definition: viewport_type.h:97
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
static void Swap(T &a, T &b)
Type safe swap operation.
Definition: math_func.hpp:277
Draw all cargoes.
Definition: station_gui.h:24
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
Definition of stuff that is very close to a company, like the company struct itself.
bool IsAvailable() const
Check whether this airport is available to build.
Select station (when joining stations); Window numbers:
Definition: window_type.h:237
Additional text about the airport.
bool link_terraform_toolbar
display terraform toolbar when displaying rail, road, water and airport toolbars
Definition: settings_type.h:96
ResizeInfo resize
Resize information.
Definition: window_gui.h:324
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Definition: window.cpp:594
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:930
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1851
AirportClassID
List of default airport classes.
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:112
void CheckRedrawStationCoverage(const Window *w)
Check whether we need to redraw the station coverage text.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:394
Offset at right of a matrix cell.
Definition: window_gui.h:79
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:455
byte size_y
size of airport in y direction
Window * parent
Parent window.
Definition: window_gui.h:339
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
static const CursorID ANIMCURSOR_DEMOLISH
704 - 707 - demolish dynamite
Definition: sprites.h:1487
Landscape generation (in Scenario Editor); Window numbers:
Definition: window_type.h:444
EconomySettings economy
settings to change the economy
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:604
bool station_show_coverage
whether to highlight coverage area
Hotkey related functions.
uint GetSpecCount() const
Get the number of allocated specs within the class.
Definition: newgrf_class.h:46
Centered label.
Definition: widget_type.h:57
Scrollbar data structure.
Definition: widget_type.h:589
West.
void ShowSelectStationIfNeeded(const CommandContainer &cmd, TileArea ta)
Show the station selection window when needed.
Contains enums and function declarations connected with stations GUI.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:139
Horizontal container.
Definition: widget_type.h:75
The passed event is not handled.
Definition: window_type.h:715
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition: viewport.cpp:2444
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:38
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:37
void OnPaint() override
The window must be repainted.
Point size
Size, in tile "units", of the white/red selection area.
Functions related to vehicles.
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 SetPosition(int position)
Sets the position of the first visible element.
Definition: widget_type.h:701
int top
y position of top edge of the window
Definition: window_gui.h:320
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
static AirportClassID _selected_airport_class
the currently visible airport class
Definition: airport_gui.cpp:37
Transport through air.
Close box (at top-left of a window)
Definition: widget_type.h:69
Offset at top of a matrix cell.
Definition: window_gui.h:80
Types related to the airport widgets.
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.
static byte _selected_airport_layout
selected airport layout number.
Definition: airport_gui.cpp:39
Decrease the layout number.
Lowest valid airport class id.
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:404
bool persistent_buildingtools
keep the building tools active after usage
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Common return value for all commands.
Definition: command_type.h:25
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:26
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: airport_gui.cpp:98
Common string list item.
Definition: dropdown_type.h:41
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1812
Callbacks that NewGRFs could implement.
List of airports.
StationSettings station
settings related to station management
static const uint TILE_SIZE
Tile size in world coordinates.
Definition: tile_type.h:15
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Functions, definitions and such used only by the GUI.
build an airport
Definition: command_type.h:207
NewGRF handling of airports.
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:686
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:670
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
Functions related to (drawing on) viewports.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Data structure for an opened window.
Definition: window_gui.h:278
Clear area.
Definition: viewport_type.h:98
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1828
static NWidgetPart SetMatrixDataTip(uint8 cols, uint8 rows, StringID tip)
Widget part function for setting the data and tooltip of WWT_MATRIX widgets.
Definition: widget_type.h:1032
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1841
byte catchment
catchment area of this airport
Panel at the bottom.
Maximal number of airports in total.
Definition: airport.h:43
byte noise_level
noise that this airport generates
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
Types related to stations.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:98
NWidgetBase ** nested_array
Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
Definition: window_gui.h:332
Invisible widget that takes some space.
Definition: widget_type.h:79
Offset at bottom of a matrix cell.
Definition: window_gui.h:81
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)
Definition: station_gui.cpp:56
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:495
SoundSettings sound
sound effect settings
Number of the first newgrf airport.
Definition: airport.h:41
Airport build toolbar window handler.
Definition: airport_gui.cpp:70
Build airport button.
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:175
East.
const Direction * rotation
the rotation of each tiletable
ViewportPlaceMethod
Viewport place method (type of highlighted area and placed objects)
Definition: viewport_type.h:78
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:557
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:477
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:178
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:80
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:947
maximum number of airport classes
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Current number of the layout.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
List of hotkeys for a window.
Definition: hotkeys.h:42
Direction
Defines the 8 directions on the map.
Geometry functions.
rectangle (stations, depots, ...)
static DropDownList BuildAirportClassDropDown()
Build a dropdown list of available airport classes.
Simple depressed panel.
Definition: widget_type.h:50
byte num_table
number of elements in the table
Called to determine text to show as airport layout name.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:311
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:177
Offset at left of a matrix cell.
Definition: window_gui.h:78
void SetViewportCatchmentStation(const Station *st, bool sel)
Select or deselect station for coverage area highlight.
Definition: viewport.cpp:3475
GUI stuff related to terraforming.
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1114
static const AirportSpec * Get(byte type)
Retrieve airport spec for the given airport.
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
void SelectFirstAvailableAirport(bool change_class)
Select the first available airport.
Baseclass for nested widgets.
Definition: widget_type.h:126
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:499
Build station; Window numbers:
Definition: window_type.h:392
Catchment for all stations with "modified catchment" disabled.
Definition: station_type.h:84
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
void PlaceProc_DemolishArea(TileIndex tile)
Start a drag for demolishing an area.
Grid of rows and columns.
Definition: widget_type.h:59
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
static EventState AirportToolbarGlobalHotkeys(int hotkey)
Handler for global hotkeys of the BuildAirToolbarWindow.
Also allow &#39;diagonal rectangles&#39;. Only usable in combination with HT_RECT or HT_POINT.
Functions related to sound.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
bool GUIPlaceProcDragXY(ViewportDragDropSelectionProcess proc, TileIndex start_tile, TileIndex end_tile)
A central place to handle all X_AND_Y dragged GUI functions.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1159
bool Failed() const
Did this command fail?
Definition: command_type.h:161
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:205
Scrollbar of the list.
Dropdown of airport classes.
void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method)
Selects tiles while dragging.
Definition: viewport.cpp:3099
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:22
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1760
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:968
bool IsVisible(uint16 item) const
Checks whether given current item is visible in the list.
Definition: widget_type.h:641
Build toolbar; Window numbers:
Definition: window_type.h:68
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:698
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:613
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:587
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:284
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1146
void OnRealtimeTick(uint delta_ms) override
Called periodically.
Functions related to companies.
GUISettings gui
settings related to the GUI
Align toward the toolbar.
Definition: window_gui.h:158
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:61
bool station_noise_level
build new airports when the town noise level is still within accepted limits
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition: main_gui.cpp:100
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: airport_gui.cpp:91
StringID name
name of this airport
bool modified_catchment
different-size catchment areas
Show the coverage button.
byte size_x
size of airport in x direction
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:999
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
Demolish button.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
bool confirm
Play sound effect on successful constructions or other actions.
Non-water non-rail construction.
Definition: sound_type.h:70
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:767
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:235
Drop down list.
Definition: widget_type.h:70
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:106
Aircraft vehicle type.
Definition: vehicle_type.h:29
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:66
bool enabled
Entity still available (by default true). Newgrf can disable it, though.
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:983
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:370
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:707
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3374
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:84
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:314
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
Defines the data structure for an airport.
Find a place automatically.
Definition: window_gui.h:156
(Toggle) Button with image
Definition: widget_type.h:52
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
GUI functions that shouldn&#39;t be here.
static void PlaceAirport(TileIndex tile)
Place an airport.
Definition: airport_gui.cpp:57
StringID GetAirportTextCallback(const AirportSpec *as, byte layout, uint16 callback)
Get a custom text for the airport.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2126
A visual display of the airport currently selected.
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1095
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
SpriteID preview_sprite
Cached airport preview sprite.
Dimensions (a width and height) of a rectangle in 2D.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:429
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
Increase the layout number.
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:832
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
Base class for windows opened from a toolbar.
Definition: window_gui.h:856
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:178
static int _selected_airport_index
the index of the selected airport in the current class or -1
Definition: airport_gui.cpp:38
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:620
(Toggle) Button with text
Definition: widget_type.h:55
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:631
Don&#39;t show the coverage button.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:201