airport_gui.cpp

Go to the documentation of this file.
00001 /* $Id: airport_gui.cpp 14422 2008-09-30 20:51:04Z rubidium $ */
00002 
00005 #include "stdafx.h"
00006 #include "openttd.h"
00007 #include "window_gui.h"
00008 #include "gui.h"
00009 #include "station_gui.h"
00010 #include "terraform_gui.h"
00011 #include "command_func.h"
00012 #include "airport.h"
00013 #include "sound_func.h"
00014 #include "window_func.h"
00015 #include "strings_func.h"
00016 #include "settings_type.h"
00017 #include "viewport_func.h"
00018 #include "gfx_func.h"
00019 #include "company_func.h"
00020 #include "order_func.h"
00021 #include "station_type.h"
00022 #include "tilehighlight_func.h"
00023 #include "company_base.h"
00024 
00025 #include "table/sprites.h"
00026 #include "table/strings.h"
00027 
00028 static byte _selected_airport_type;
00029 
00030 static void ShowBuildAirportPicker(Window *parent);
00031 
00032 
00033 void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
00034 {
00035   if (success) {
00036     SndPlayTileFx(SND_1F_SPLAT, tile);
00037     ResetObjectToPlace();
00038   }
00039 }
00040 
00041 static void PlaceAirport(TileIndex tile)
00042 {
00043   DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
00044 }
00045 
00046 
00047 enum {
00048   ATW_AIRPORT  = 3,
00049   ATW_DEMOLISH = 4
00050 };
00051 
00052 
00053 static void BuildAirClick_Airport(Window *w)
00054 {
00055   if (HandlePlacePushButton(w, ATW_AIRPORT, SPR_CURSOR_AIRPORT, VHM_RECT, PlaceAirport)) ShowBuildAirportPicker(w);
00056 }
00057 
00058 static void BuildAirClick_Demolish(Window *w)
00059 {
00060   HandlePlacePushButton(w, ATW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceProc_DemolishArea);
00061 }
00062 
00063 
00064 typedef void OnButtonClick(Window *w);
00065 static OnButtonClick * const _build_air_button_proc[] = {
00066   BuildAirClick_Airport,
00067   BuildAirClick_Demolish,
00068 };
00069 
00070 struct BuildAirToolbarWindow : Window {
00071   BuildAirToolbarWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
00072   {
00073     this->FindWindowPlacementAndResize(desc);
00074     if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this);
00075   }
00076 
00077   ~BuildAirToolbarWindow()
00078   {
00079     if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
00080   }
00081 
00082   virtual void OnPaint()
00083   {
00084     this->DrawWidgets();
00085   }
00086 
00087   virtual void OnClick(Point pt, int widget)
00088   {
00089     if (widget - 3 >= 0) {
00090       _build_air_button_proc[widget - 3](this);
00091     }
00092   }
00093 
00094 
00095   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
00096   {
00097     switch (keycode) {
00098       case '1': BuildAirClick_Airport(this); break;
00099       case '2': BuildAirClick_Demolish(this); break;
00100       default: return ES_NOT_HANDLED;
00101     }
00102     return ES_HANDLED;
00103   }
00104 
00105   virtual void OnPlaceObject(Point pt, TileIndex tile)
00106   {
00107     _place_proc(tile);
00108   }
00109 
00110   virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
00111   {
00112     VpSelectTilesWithMethod(pt.x, pt.y, select_method);
00113   }
00114 
00115   virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
00116   {
00117     if (pt.x != -1 && select_proc == DDSP_DEMOLISH_AREA) {
00118       GUIPlaceProcDragXY(select_proc, start_tile, end_tile);
00119     }
00120   }
00121 
00122   virtual void OnPlaceObjectAbort()
00123   {
00124     this->RaiseButtons();
00125 
00126     delete FindWindowById(WC_BUILD_STATION, 0);
00127   }
00128 };
00129 
00130 static const Widget _air_toolbar_widgets[] = {
00131 {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_DARK_GREEN,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW },
00132 {    WWT_CAPTION,   RESIZE_NONE,   COLOUR_DARK_GREEN,    11,    51,     0,    13, STR_A000_AIRPORTS,   STR_018C_WINDOW_TITLE_DRAG_THIS },
00133 {  WWT_STICKYBOX,   RESIZE_NONE,   COLOUR_DARK_GREEN,    52,    63,     0,    13, 0x0,                 STR_STICKY_BUTTON },
00134 {     WWT_IMGBTN,   RESIZE_NONE,   COLOUR_DARK_GREEN,     0,    41,    14,    35, SPR_IMG_AIRPORT,     STR_A01E_BUILD_AIRPORT },
00135 {     WWT_IMGBTN,   RESIZE_NONE,   COLOUR_DARK_GREEN,    42,    63,    14,    35, SPR_IMG_DYNAMITE,    STR_018D_DEMOLISH_BUILDINGS_ETC },
00136 {   WIDGETS_END},
00137 };
00138 
00139 
00140 static const WindowDesc _air_toolbar_desc = {
00141   WDP_ALIGN_TBR, 22, 64, 36, 64, 36,
00142   WC_BUILD_TOOLBAR, WC_NONE,
00143   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
00144   _air_toolbar_widgets,
00145 };
00146 
00147 void ShowBuildAirToolbar()
00148 {
00149   if (!IsValidCompanyID(_current_company)) return;
00150 
00151   DeleteWindowByClass(WC_BUILD_TOOLBAR);
00152   AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
00153 }
00154 
00155 class AirportPickerWindow : public PickerWindowBase {
00156 
00157   enum {
00158     BAW_BOTTOMPANEL = 10,
00159     BAW_SMALL_AIRPORT,
00160     BAW_CITY_AIRPORT,
00161     BAW_HELIPORT,
00162     BAW_METRO_AIRPORT,
00163     BAW_STR_INTERNATIONAL_AIRPORT,
00164     BAW_COMMUTER_AIRPORT,
00165     BAW_HELIDEPOT,
00166     BAW_STR_INTERCONTINENTAL_AIRPORT,
00167     BAW_HELISTATION,
00168     BAW_LAST_AIRPORT = BAW_HELISTATION,
00169     BAW_AIRPORT_COUNT = BAW_LAST_AIRPORT - BAW_SMALL_AIRPORT + 1,
00170     BAW_BTN_DONTHILIGHT = BAW_LAST_AIRPORT + 1,
00171     BAW_BTN_DOHILIGHT,
00172   };
00173 
00174 public:
00175 
00176   AirportPickerWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
00177   {
00178     this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
00179     this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
00180     this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00181 
00182     if (_settings_game.economy.station_noise_level) {
00183       ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, 10);
00184     }
00185 
00186     this->FindWindowPlacementAndResize(desc);
00187   }
00188 
00189   virtual void OnPaint()
00190   {
00191     int i; // airport enabling loop
00192     uint16 y_noise_offset = 0;
00193     uint32 avail_airports;
00194     const AirportFTAClass *airport;
00195 
00196     avail_airports = GetValidAirports();
00197 
00198     this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00199     if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
00200     if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
00201     this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00202 
00203     /* 'Country Airport' starts at widget BAW_SMALL_AIRPORT, and if its bit is set, it is
00204      * available, so take its opposite value to set the disabled state.
00205      * There are 9 buildable airports
00206      * XXX TODO : all airports should be held in arrays, with all relevant data.
00207      * This should be part of newgrf-airports, i suppose
00208      */
00209     for (i = 0; i < BAW_AIRPORT_COUNT; i++) this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i));
00210 
00211     /* select default the coverage area to 'Off' (16) */
00212     airport = GetAirport(_selected_airport_type);
00213     SetTileSelectSize(airport->size_x, airport->size_y);
00214 
00215     int rad = _settings_game.station.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
00216 
00217     if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
00218 
00219     this->DrawWidgets();
00220 
00221     /* only show the station (airport) noise, if the noise option is activated */
00222     if (_settings_game.economy.station_noise_level) {
00223       /* show the noise of the selected airport */
00224       SetDParam(0, airport->noise_level);
00225       DrawString(2, 206, STR_STATION_NOISE, 0);
00226       y_noise_offset = 10;
00227     }
00228 
00229     /* strings such as 'Size' and 'Coverage Area' */
00230     int text_end = DrawStationCoverageAreaText(2, this->widget[BAW_BTN_DOHILIGHT].bottom + 4 + y_noise_offset, SCT_ALL, rad, false);
00231     text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
00232     if (text_end != this->widget[BAW_BOTTOMPANEL].bottom) {
00233       this->SetDirty();
00234       ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, text_end - this->widget[BAW_BOTTOMPANEL].bottom);
00235       this->SetDirty();
00236     }
00237   }
00238 
00239   virtual void OnClick(Point pt, int widget)
00240   {
00241     switch (widget) {
00242       case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT:
00243       case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT:
00244       case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION:
00245         this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00246         _selected_airport_type = widget - BAW_SMALL_AIRPORT;
00247         this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00248         SndPlayFx(SND_15_BEEP);
00249         this->SetDirty();
00250         break;
00251 
00252       case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT:
00253         _station_show_coverage = (widget != BAW_BTN_DONTHILIGHT);
00254         this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_station_show_coverage);
00255         this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _station_show_coverage);
00256         SndPlayFx(SND_15_BEEP);
00257         this->SetDirty();
00258         break;
00259     }
00260   }
00261 
00262   virtual void OnTick()
00263   {
00264     CheckRedrawStationCoverage(this);
00265   }
00266 };
00267 
00268 static const Widget _build_airport_picker_widgets[] = {
00269 {   WWT_CLOSEBOX,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW},
00270 {    WWT_CAPTION,   RESIZE_NONE,   COLOUR_DARK_GREEN,  11,   147,     0,    13, STR_3001_AIRPORT_SELECTION,       STR_018C_WINDOW_TITLE_DRAG_THIS},
00271 {      WWT_PANEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    14,    52, 0x0,                              STR_NULL},
00272 {      WWT_LABEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    14,    27, STR_SMALL_AIRPORTS,               STR_NULL},
00273 {      WWT_PANEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    53,    89, 0x0,                              STR_NULL},
00274 {      WWT_LABEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    52,    65, STR_LARGE_AIRPORTS,               STR_NULL},
00275 {      WWT_PANEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    90,   127, 0x0,                              STR_NULL},
00276 {      WWT_LABEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,    90,   103, STR_HUB_AIRPORTS,                 STR_NULL},
00277 {      WWT_PANEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,   128,   177, 0x0,                              STR_NULL},
00278 {      WWT_LABEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,   128,   141, STR_HELIPORTS,                    STR_NULL},
00279 {      WWT_PANEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,   178,   239, 0x0,                              STR_NULL}, // bottom general box
00280 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,    27,    38, STR_SMALL_AIRPORT,                STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00281 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,    65,    76, STR_CITY_AIRPORT,                 STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00282 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,   141,   152, STR_HELIPORT,                     STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00283 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,    77,    88, STR_METRO_AIRPORT ,               STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00284 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,   103,   114, STR_INTERNATIONAL_AIRPORT,        STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00285 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,    39,    50, STR_COMMUTER_AIRPORT,             STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00286 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,   165,   176, STR_HELIDEPOT,                    STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00287 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,   115,   126, STR_INTERCONTINENTAL_AIRPORT,     STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00288 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,         2,   145,   153,   164, STR_HELISTATION,                  STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00289 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,        14,    73,   191,   202, STR_02DB_OFF,                     STR_3065_DON_T_HIGHLIGHT_COVERAGE},
00290 {    WWT_TEXTBTN,   RESIZE_NONE,   COLOUR_GREY,        74,   133,   191,   202, STR_02DA_ON,                      STR_3064_HIGHLIGHT_COVERAGE_AREA},
00291 {      WWT_LABEL,   RESIZE_NONE,   COLOUR_DARK_GREEN,   0,   147,   178,   191, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
00292 {   WIDGETS_END},
00293 };
00294 
00295 static const WindowDesc _build_airport_desc = {
00296   WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
00297   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
00298   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
00299   _build_airport_picker_widgets,
00300 };
00301 
00302 static void ShowBuildAirportPicker(Window *parent)
00303 {
00304   new AirportPickerWindow(&_build_airport_desc, parent);
00305 }
00306 
00307 void InitializeAirportGui()
00308 {
00309   _selected_airport_type = AT_SMALL;
00310 }

Generated on Fri Nov 21 19:01:31 2008 for openttd by  doxygen 1.5.6