airport_gui.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "window_gui.h"
00014 #include "station_gui.h"
00015 #include "terraform_gui.h"
00016 #include "sound_func.h"
00017 #include "window_func.h"
00018 #include "strings_func.h"
00019 #include "viewport_func.h"
00020 #include "company_func.h"
00021 #include "tilehighlight_func.h"
00022 #include "company_base.h"
00023 #include "station_type.h"
00024 #include "newgrf_airport.h"
00025 #include "newgrf_callbacks.h"
00026 #include "widgets/dropdown_type.h"
00027 #include "core/geometry_func.hpp"
00028 #include "hotkeys.h"
00029 #include "vehicle_func.h"
00030 #include "sprite.h"
00031 
00032 #include "table/strings.h"
00033 
00034 static AirportClassID _selected_airport_class; 
00035 static int _selected_airport_index;            
00036 static byte _selected_airport_layout;          
00037 
00038 static void ShowBuildAirportPicker(Window *parent);
00039 
00040 SpriteID GetCustomAirportSprite(const AirportSpec *as, byte layout);
00041 
00042 void CcBuildAirport(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00043 {
00044   if (result.Failed()) return;
00045 
00046   SndPlayTileFx(SND_1F_SPLAT, tile);
00047   if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
00048 }
00049 
00054 static void PlaceAirport(TileIndex tile)
00055 {
00056   if (_selected_airport_index == -1) return;
00057   uint32 p2 = _ctrl_pressed;
00058   SB(p2, 16, 16, INVALID_STATION); // no station to join
00059 
00060   uint32 p1 = AirportClass::Get(_selected_airport_class, _selected_airport_index)->GetIndex();
00061   p1 |= _selected_airport_layout << 8;
00062   CommandContainer cmdcont = { tile, p1, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
00063   ShowSelectStationIfNeeded(cmdcont, TileArea(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE));
00064 }
00065 
00067 enum AirportToolbarWidgets {
00068   ATW_AIRPORT,
00069   ATW_DEMOLISH,
00070 };
00071 
00072 
00074 struct BuildAirToolbarWindow : Window {
00075   int last_user_action; // Last started user action.
00076 
00077   BuildAirToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
00078   {
00079     this->InitNested(desc, window_number);
00080     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
00081     this->last_user_action = WIDGET_LIST_END;
00082   }
00083 
00084   ~BuildAirToolbarWindow()
00085   {
00086     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false);
00087   }
00088 
00089   virtual void OnClick(Point pt, int widget, int click_count)
00090   {
00091     switch (widget) {
00092       case ATW_AIRPORT:
00093         if (HandlePlacePushButton(this, ATW_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT)) {
00094           ShowBuildAirportPicker(this);
00095           this->last_user_action = widget;
00096         }
00097         break;
00098 
00099       case ATW_DEMOLISH:
00100         HandlePlacePushButton(this, ATW_DEMOLISH, ANIMCURSOR_DEMOLISH, HT_RECT | HT_DIAGONAL);
00101         this->last_user_action = widget;
00102         break;
00103 
00104       default: break;
00105     }
00106   }
00107 
00108 
00109   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00110   {
00111     int num = CheckHotkeyMatch(airtoolbar_hotkeys, keycode, this);
00112     if (num == -1) return ES_NOT_HANDLED;
00113     this->OnClick(Point(), num, 1);
00114     return ES_HANDLED;
00115   }
00116 
00117   virtual void OnPlaceObject(Point pt, TileIndex tile)
00118   {
00119     switch (this->last_user_action) {
00120       case ATW_AIRPORT:
00121         PlaceAirport(tile);
00122         break;
00123 
00124       case ATW_DEMOLISH:
00125         PlaceProc_DemolishArea(tile);
00126         break;
00127 
00128       default: NOT_REACHED();
00129     }
00130   }
00131 
00132   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
00133   {
00134     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
00135   }
00136 
00137   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
00138   {
00139     if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
00140       GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
00141     }
00142   }
00143 
00144   virtual void OnPlaceObjectAbort()
00145   {
00146     this->RaiseButtons();
00147 
00148     DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR);
00149     DeleteWindowById(WC_SELECT_STATION, 0);
00150   }
00151 
00152   static Hotkey<BuildAirToolbarWindow> airtoolbar_hotkeys[];
00153 };
00154 
00155 Hotkey<BuildAirToolbarWindow> BuildAirToolbarWindow::airtoolbar_hotkeys[] = {
00156   Hotkey<BuildAirToolbarWindow>('1', "airport", ATW_AIRPORT),
00157   Hotkey<BuildAirToolbarWindow>('2', "demolish", ATW_DEMOLISH),
00158   HOTKEY_LIST_END(BuildAirToolbarWindow)
00159 };
00160 Hotkey<BuildAirToolbarWindow> *_airtoolbar_hotkeys = BuildAirToolbarWindow::airtoolbar_hotkeys;
00161 
00162 static const NWidgetPart _nested_air_toolbar_widgets[] = {
00163   NWidget(NWID_HORIZONTAL),
00164     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00165     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_TOOLBAR_AIRCRAFT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00166     NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
00167   EndContainer(),
00168   NWidget(NWID_HORIZONTAL),
00169     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, ATW_AIRPORT), SetFill(0, 1), SetMinimalSize(42, 22), SetDataTip(SPR_IMG_AIRPORT, STR_TOOLBAR_AIRCRAFT_BUILD_AIRPORT_TOOLTIP),
00170     NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetMinimalSize(4, 22), SetFill(1, 1), EndContainer(),
00171     NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, ATW_DEMOLISH), SetFill(0, 1), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_DYNAMITE, STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC),
00172   EndContainer(),
00173 };
00174 
00175 static const WindowDesc _air_toolbar_desc(
00176   WDP_ALIGN_TOOLBAR, 0, 0,
00177   WC_BUILD_TOOLBAR, WC_NONE,
00178   WDF_CONSTRUCTION,
00179   _nested_air_toolbar_widgets, lengthof(_nested_air_toolbar_widgets)
00180 );
00181 
00189 Window *ShowBuildAirToolbar()
00190 {
00191   if (!Company::IsValidID(_local_company)) return NULL;
00192 
00193   DeleteWindowByClass(WC_BUILD_TOOLBAR);
00194   return AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
00195 }
00196 
00197 EventState AirportToolbarGlobalHotkeys(uint16 key, uint16 keycode)
00198 {
00199   if (!CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) return ES_NOT_HANDLED;
00200   int num = CheckHotkeyMatch<BuildAirToolbarWindow>(_airtoolbar_hotkeys, keycode, NULL, true);
00201   if (num == -1) return ES_NOT_HANDLED;
00202   Window *w = ShowBuildAirToolbar();
00203   if (w == NULL) return ES_NOT_HANDLED;
00204   return w->OnKeyPress(key, keycode);
00205 }
00206 
00208 enum AirportPickerWidgets {
00209   BAIRW_CLASS_DROPDOWN,
00210   BAIRW_AIRPORT_LIST,
00211   BAIRW_SCROLLBAR,
00212   BAIRW_LAYOUT_NUM,
00213   BAIRW_LAYOUT_DECREASE,
00214   BAIRW_LAYOUT_INCREASE,
00215   BAIRW_AIRPORT_SPRITE,
00216   BAIRW_EXTRA_TEXT,
00217   BAIRW_BOTTOMPANEL,
00218   BAIRW_COVERAGE_LABEL,
00219   BAIRW_BTN_DONTHILIGHT,
00220   BAIRW_BTN_DOHILIGHT,
00221 };
00222 
00223 class BuildAirportWindow : public PickerWindowBase {
00224   SpriteID preview_sprite; 
00225   int line_height;
00226   Scrollbar *vscroll;
00227 
00229   static DropDownList *BuildAirportClassDropDown()
00230   {
00231     DropDownList *list = new DropDownList();
00232 
00233     for (uint i = 0; i < AirportClass::GetCount(); i++) {
00234       list->push_back(new DropDownListStringItem(AirportClass::GetName((AirportClassID)i), i, false));
00235     }
00236 
00237     return list;
00238   }
00239 
00240 public:
00241   BuildAirportWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(parent)
00242   {
00243     this->CreateNestedTree(desc);
00244 
00245     this->vscroll = this->GetScrollbar(BAIRW_SCROLLBAR);
00246     this->vscroll->SetCapacity(5);
00247     this->vscroll->SetPosition(0);
00248 
00249     this->FinishInitNested(desc, TRANSPORT_AIR);
00250 
00251     this->SetWidgetLoweredState(BAIRW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
00252     this->SetWidgetLoweredState(BAIRW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
00253     this->OnInvalidateData();
00254 
00255     this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
00256     this->SelectFirstAvailableAirport(true);
00257   }
00258 
00259   virtual ~BuildAirportWindow()
00260   {
00261     DeleteWindowById(WC_SELECT_STATION, 0);
00262   }
00263 
00264   virtual void SetStringParameters(int widget) const
00265   {
00266     switch (widget) {
00267       case BAIRW_CLASS_DROPDOWN:
00268         SetDParam(0, AirportClass::GetName(_selected_airport_class));
00269         break;
00270 
00271       case BAIRW_LAYOUT_NUM:
00272         SetDParam(0, STR_EMPTY);
00273         if (_selected_airport_index != -1) {
00274           const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
00275           StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_LAYOUT_NAME);
00276           if (string != STR_UNDEFINED) {
00277             SetDParam(0, string);
00278           } else if (as->num_table > 1) {
00279             SetDParam(0, STR_STATION_BUILD_AIRPORT_LAYOUT_NAME);
00280             SetDParam(1, _selected_airport_layout + 1);
00281           }
00282         }
00283         break;
00284 
00285       default: break;
00286     }
00287   }
00288 
00289   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00290   {
00291     switch (widget) {
00292       case BAIRW_CLASS_DROPDOWN: {
00293         Dimension d = {0, 0};
00294         for (uint i = 0; i < AirportClass::GetCount(); i++) {
00295           SetDParam(0, AirportClass::GetName((AirportClassID)i));
00296           d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
00297         }
00298         d.width += padding.width;
00299         d.height += padding.height;
00300         *size = maxdim(*size, d);
00301         break;
00302       }
00303 
00304       case BAIRW_AIRPORT_LIST: {
00305         for (int i = 0; i < NUM_AIRPORTS; i++) {
00306           const AirportSpec *as = AirportSpec::Get(i);
00307           if (!as->enabled) continue;
00308 
00309           size->width = max(size->width, GetStringBoundingBox(as->name).width);
00310         }
00311 
00312         this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
00313         size->height = this->vscroll->GetCapacity() * this->line_height;
00314         break;
00315       }
00316 
00317       case BAIRW_AIRPORT_SPRITE:
00318         for (int i = 0; i < NUM_AIRPORTS; i++) {
00319           const AirportSpec *as = AirportSpec::Get(i);
00320           if (!as->enabled) continue;
00321           for (byte layout = 0; layout < as->num_table; layout++) {
00322             SpriteID sprite = GetCustomAirportSprite(as, layout);
00323             if (sprite != 0) {
00324               Dimension d = GetSpriteSize(sprite);
00325               d.width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
00326               d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
00327               *size = maxdim(d, *size);
00328             }
00329           }
00330         }
00331         break;
00332 
00333       case BAIRW_EXTRA_TEXT:
00334         for (int i = NEW_AIRPORT_OFFSET; i < NUM_AIRPORTS; i++) {
00335           const AirportSpec *as = AirportSpec::Get(i);
00336           if (!as->enabled) continue;
00337           for (byte layout = 0; layout < as->num_table; layout++) {
00338             StringID string = GetAirportTextCallback(as, layout, CBID_AIRPORT_ADDITIONAL_TEXT);
00339             if (string == STR_UNDEFINED) continue;
00340 
00341             /* STR_BLACK_STRING is used to start the string with {BLACK} */
00342             SetDParam(0, string);
00343             Dimension d = GetStringMultiLineBoundingBox(STR_BLACK_STRING, *size);
00344             *size = maxdim(d, *size);
00345           }
00346         }
00347         break;
00348 
00349       default: break;
00350     }
00351   }
00352 
00353   virtual void DrawWidget(const Rect &r, int widget) const
00354   {
00355     switch (widget) {
00356       case BAIRW_AIRPORT_LIST: {
00357         int y = r.top;
00358         for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < AirportClass::GetCount(_selected_airport_class); i++) {
00359           const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
00360           if (!as->IsAvailable()) {
00361             GfxFillRect(r.left + 1, y + 1, r.right - 1, y + this->line_height - 2, PC_BLACK, FILLRECT_CHECKER);
00362           }
00363           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);
00364           y += this->line_height;
00365         }
00366         break;
00367       }
00368 
00369       case BAIRW_AIRPORT_SPRITE:
00370         if (this->preview_sprite != 0) {
00371           Dimension d = GetSpriteSize(this->preview_sprite);
00372           DrawSprite(this->preview_sprite, COMPANY_SPRITE_COLOUR(_local_company), (r.left + r.right - d.width) / 2, (r.top + r.bottom - d.height) / 2);
00373         }
00374         break;
00375 
00376       case BAIRW_EXTRA_TEXT:
00377         if (_selected_airport_index != -1) {
00378           const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
00379           StringID string = GetAirportTextCallback(as, _selected_airport_layout, CBID_AIRPORT_ADDITIONAL_TEXT);
00380           if (string != STR_UNDEFINED) {
00381             SetDParam(0, string);
00382             DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_BLACK_STRING);
00383           }
00384         }
00385         break;
00386     }
00387   }
00388 
00389   virtual void OnPaint()
00390   {
00391     this->DrawWidgets();
00392 
00393     uint16 top = this->GetWidget<NWidgetBase>(BAIRW_BTN_DOHILIGHT)->pos_y + this->GetWidget<NWidgetBase>(BAIRW_BTN_DOHILIGHT)->current_y + WD_PAR_VSEP_NORMAL;
00394     NWidgetBase *panel_nwi = this->GetWidget<NWidgetBase>(BAIRW_BOTTOMPANEL);
00395 
00396     int right = panel_nwi->pos_x +  panel_nwi->current_x;
00397     int bottom = panel_nwi->pos_y +  panel_nwi->current_y;
00398 
00399     if (_selected_airport_index != -1) {
00400       const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
00401       int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
00402 
00403       /* only show the station (airport) noise, if the noise option is activated */
00404       if (_settings_game.economy.station_noise_level) {
00405         /* show the noise of the selected airport */
00406         SetDParam(0, as->noise_level);
00407         DrawString(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_STATION_BUILD_NOISE);
00408         top += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
00409       }
00410 
00411       /* strings such as 'Size' and 'Coverage Area' */
00412       top = DrawStationCoverageAreaText(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, false) + WD_PAR_VSEP_NORMAL;
00413       top = DrawStationCoverageAreaText(panel_nwi->pos_x + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, SCT_ALL, rad, true) + WD_PAR_VSEP_NORMAL;
00414     }
00415 
00416     /* Resize background if the text is not equally long as the window. */
00417     if (top > bottom || (top < bottom && panel_nwi->current_y > panel_nwi->smallest_y)) {
00418       ResizeWindow(this, 0, top - bottom);
00419     }
00420   }
00421 
00422   void SelectOtherAirport(int airport_index)
00423   {
00424     _selected_airport_index = airport_index;
00425     _selected_airport_layout = 0;
00426 
00427     this->UpdateSelectSize();
00428     this->SetDirty();
00429   }
00430 
00431   void UpdateSelectSize()
00432   {
00433     if (_selected_airport_index == -1) {
00434       SetTileSelectSize(1, 1);
00435       this->DisableWidget(BAIRW_LAYOUT_DECREASE);
00436       this->DisableWidget(BAIRW_LAYOUT_INCREASE);
00437     } else {
00438       const AirportSpec *as = AirportClass::Get(_selected_airport_class, _selected_airport_index);
00439       int w = as->size_x;
00440       int h = as->size_y;
00441       Direction rotation = as->rotation[_selected_airport_layout];
00442       if (rotation == DIR_E || rotation == DIR_W) Swap(w, h);
00443       SetTileSelectSize(w, h);
00444 
00445       this->preview_sprite = GetCustomAirportSprite(as, _selected_airport_layout);
00446 
00447       this->SetWidgetDisabledState(BAIRW_LAYOUT_DECREASE, _selected_airport_layout == 0);
00448       this->SetWidgetDisabledState(BAIRW_LAYOUT_INCREASE, _selected_airport_layout + 1 >= as->num_table);
00449 
00450       int rad = _settings_game.station.modified_catchment ? as->catchment : (uint)CA_UNMODIFIED;
00451       if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
00452     }
00453   }
00454 
00455   virtual void OnClick(Point pt, int widget, int click_count)
00456   {
00457     switch (widget) {
00458       case BAIRW_CLASS_DROPDOWN:
00459         ShowDropDownList(this, BuildAirportClassDropDown(), _selected_airport_class, BAIRW_CLASS_DROPDOWN);
00460         break;
00461 
00462       case BAIRW_AIRPORT_LIST: {
00463         int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
00464         if (num_clicked >= this->vscroll->GetCount()) break;
00465         const AirportSpec *as = AirportClass::Get(_selected_airport_class, num_clicked);
00466         if (as->IsAvailable()) this->SelectOtherAirport(num_clicked);
00467         break;
00468       }
00469 
00470       case BAIRW_BTN_DONTHILIGHT: case BAIRW_BTN_DOHILIGHT:
00471         _settings_client.gui.station_show_coverage = (widget != BAIRW_BTN_DONTHILIGHT);
00472         this->SetWidgetLoweredState(BAIRW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
00473         this->SetWidgetLoweredState(BAIRW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
00474         this->SetDirty();
00475         SndPlayFx(SND_15_BEEP);
00476         this->UpdateSelectSize();
00477         break;
00478 
00479       case BAIRW_LAYOUT_DECREASE:
00480         _selected_airport_layout--;
00481         this->UpdateSelectSize();
00482         this->SetDirty();
00483         break;
00484 
00485       case BAIRW_LAYOUT_INCREASE:
00486         _selected_airport_layout++;
00487         this->UpdateSelectSize();
00488         this->SetDirty();
00489         break;
00490     }
00491   }
00492 
00498   void SelectFirstAvailableAirport(bool change_class)
00499   {
00500     /* First try to select an airport in the selected class. */
00501     for (uint i = 0; i < AirportClass::GetCount(_selected_airport_class); i++) {
00502       const AirportSpec *as = AirportClass::Get(_selected_airport_class, i);
00503       if (as->IsAvailable()) {
00504         this->SelectOtherAirport(i);
00505         return;
00506       }
00507     }
00508     if (change_class) {
00509       /* If that fails, select the first available airport
00510        * from a random class. */
00511       for (AirportClassID j = APC_BEGIN; j < APC_MAX; j++) {
00512         for (uint i = 0; i < AirportClass::GetCount(j); i++) {
00513           const AirportSpec *as = AirportClass::Get(j, i);
00514           if (as->IsAvailable()) {
00515             _selected_airport_class = j;
00516             this->SelectOtherAirport(i);
00517             return;
00518           }
00519         }
00520       }
00521     }
00522     /* If all airports are unavailable, select nothing. */
00523     this->SelectOtherAirport(-1);
00524   }
00525 
00526   virtual void OnDropdownSelect(int widget, int index)
00527   {
00528     assert(widget == BAIRW_CLASS_DROPDOWN);
00529     _selected_airport_class = (AirportClassID)index;
00530     this->vscroll->SetCount(AirportClass::GetCount(_selected_airport_class));
00531     this->SelectFirstAvailableAirport(false);
00532   }
00533 
00534   virtual void OnTick()
00535   {
00536     CheckRedrawStationCoverage(this);
00537   }
00538 };
00539 
00540 static const NWidgetPart _nested_build_airport_widgets[] = {
00541   NWidget(NWID_HORIZONTAL),
00542     NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
00543     NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00544   EndContainer(),
00545   NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetFill(1, 0), SetPIP(2, 0, 2),
00546     NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_AIRPORT_CLASS_LABEL, STR_NULL), SetFill(1, 0),
00547     NWidget(WWT_DROPDOWN, COLOUR_GREY, BAIRW_CLASS_DROPDOWN), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_STATION_BUILD_AIRPORT_TOOLTIP),
00548     NWidget(NWID_HORIZONTAL),
00549       NWidget(WWT_MATRIX, COLOUR_GREY, BAIRW_AIRPORT_LIST), SetFill(1, 0), SetDataTip(0x501, STR_STATION_BUILD_AIRPORT_TOOLTIP), SetScrollbar(BAIRW_SCROLLBAR),
00550       NWidget(NWID_VSCROLLBAR, COLOUR_GREY, BAIRW_SCROLLBAR),
00551     EndContainer(),
00552     NWidget(NWID_HORIZONTAL),
00553       NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, BAIRW_LAYOUT_DECREASE), SetMinimalSize(12, 0), SetDataTip(AWV_DECREASE, STR_NULL),
00554       NWidget(WWT_LABEL, COLOUR_GREY, BAIRW_LAYOUT_NUM), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_BLACK_STRING, STR_NULL),
00555       NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, BAIRW_LAYOUT_INCREASE), SetMinimalSize(12, 0), SetDataTip(AWV_INCREASE, STR_NULL),
00556     EndContainer(),
00557     NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, BAIRW_AIRPORT_SPRITE), SetFill(1, 0),
00558     NWidget(WWT_EMPTY, COLOUR_DARK_GREEN, BAIRW_EXTRA_TEXT), SetFill(1, 0), SetMinimalSize(150, 0),
00559   EndContainer(),
00560   /* Bottom panel. */
00561   NWidget(WWT_PANEL, COLOUR_DARK_GREEN, BAIRW_BOTTOMPANEL), SetPIP(2, 2, 2),
00562     NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_STATION_BUILD_COVERAGE_AREA_TITLE, STR_NULL), SetFill(1, 0),
00563     NWidget(NWID_HORIZONTAL),
00564       NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
00565       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00566         NWidget(WWT_TEXTBTN, COLOUR_GREY, BAIRW_BTN_DONTHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
00567                       SetDataTip(STR_STATION_BUILD_COVERAGE_OFF, STR_STATION_BUILD_COVERAGE_AREA_OFF_TOOLTIP),
00568         NWidget(WWT_TEXTBTN, COLOUR_GREY, BAIRW_BTN_DOHILIGHT), SetMinimalSize(60, 12), SetFill(1, 0),
00569                       SetDataTip(STR_STATION_BUILD_COVERAGE_ON, STR_STATION_BUILD_COVERAGE_AREA_ON_TOOLTIP),
00570       EndContainer(),
00571       NWidget(NWID_SPACER), SetMinimalSize(14, 0), SetFill(1, 0),
00572     EndContainer(),
00573     NWidget(NWID_SPACER), SetMinimalSize(0, 10), SetResize(0, 1), SetFill(1, 0),
00574   EndContainer(),
00575 };
00576 
00577 static const WindowDesc _build_airport_desc(
00578   WDP_AUTO, 0, 0,
00579   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
00580   WDF_CONSTRUCTION | WDF_UNCLICK_BUTTONS,
00581   _nested_build_airport_widgets, lengthof(_nested_build_airport_widgets)
00582 );
00583 
00584 static void ShowBuildAirportPicker(Window *parent)
00585 {
00586   new BuildAirportWindow(&_build_airport_desc, parent);
00587 }
00588 
00589 void InitializeAirportGui()
00590 {
00591   _selected_airport_class = APC_BEGIN;
00592   _selected_airport_index = -1;
00593 }