airport_gui.cpp

Go to the documentation of this file.
00001 /* $Id: airport_gui.cpp 12155 2008-02-16 00:10:03Z glx $ */
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 "station.h"
00013 #include "airport.h"
00014 #include "depot.h"
00015 #include "sound_func.h"
00016 #include "window_func.h"
00017 #include "settings_type.h"
00018 #include "viewport_func.h"
00019 #include "gfx_func.h"
00020 #include "player_func.h"
00021 
00022 #include "table/sprites.h"
00023 #include "table/strings.h"
00024 
00025 static byte _selected_airport_type;
00026 
00027 static void ShowBuildAirportPicker();
00028 
00029 
00030 void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
00031 {
00032   if (success) {
00033     SndPlayTileFx(SND_1F_SPLAT, tile);
00034     ResetObjectToPlace();
00035   }
00036 }
00037 
00038 static void PlaceAirport(TileIndex tile)
00039 {
00040   DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
00041 }
00042 
00043 static void PlaceAir_DemolishArea(TileIndex tile)
00044 {
00045   VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
00046 }
00047 
00048 
00049 enum {
00050   ATW_AIRPORT  = 3,
00051   ATW_DEMOLISH = 4
00052 };
00053 
00054 
00055 static void BuildAirClick_Airport(Window *w)
00056 {
00057   if (HandlePlacePushButton(w, ATW_AIRPORT, SPR_CURSOR_AIRPORT, VHM_RECT, PlaceAirport)) ShowBuildAirportPicker();
00058 }
00059 
00060 static void BuildAirClick_Demolish(Window *w)
00061 {
00062   HandlePlacePushButton(w, ATW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceAir_DemolishArea);
00063 }
00064 
00065 
00066 typedef void OnButtonClick(Window *w);
00067 static OnButtonClick * const _build_air_button_proc[] = {
00068   BuildAirClick_Airport,
00069   BuildAirClick_Demolish,
00070 };
00071 
00072 static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
00073 {
00074   switch (e->event) {
00075   case WE_PAINT:
00076     DrawWindowWidgets(w);
00077     break;
00078 
00079   case WE_CLICK:
00080     if (e->we.click.widget - 3 >= 0)
00081       _build_air_button_proc[e->we.click.widget - 3](w);
00082     break;
00083 
00084   case WE_KEYPRESS: {
00085     switch (e->we.keypress.keycode) {
00086       case '1': BuildAirClick_Airport(w); break;
00087       case '2': BuildAirClick_Demolish(w); break;
00088       default: return;
00089     }
00090   } break;
00091 
00092   case WE_PLACE_OBJ:
00093     _place_proc(e->we.place.tile);
00094     break;
00095 
00096   case WE_PLACE_DRAG:
00097     VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
00098     break;
00099 
00100   case WE_PLACE_MOUSEUP:
00101     if (e->we.place.pt.x != -1 && e->we.place.select_proc == DDSP_DEMOLISH_AREA) {
00102       DoCommandP(e->we.place.tile, e->we.place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
00103     }
00104     break;
00105 
00106   case WE_ABORT_PLACE_OBJ:
00107     w->RaiseButtons();
00108 
00109     w = FindWindowById(WC_BUILD_STATION, 0);
00110     if (w != 0)
00111       WP(w, def_d).close = true;
00112     break;
00113 
00114   case WE_DESTROY:
00115     if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
00116     break;
00117   }
00118 }
00119 
00120 static const Widget _air_toolbar_widgets[] = {
00121 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,            STR_018B_CLOSE_WINDOW },
00122 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,    51,     0,    13, STR_A000_AIRPORTS,   STR_018C_WINDOW_TITLE_DRAG_THIS },
00123 {  WWT_STICKYBOX,   RESIZE_NONE,     7,    52,    63,     0,    13, 0x0,                 STR_STICKY_BUTTON },
00124 {     WWT_IMGBTN,   RESIZE_NONE,     7,     0,    41,    14,    35, SPR_IMG_AIRPORT,     STR_A01E_BUILD_AIRPORT },
00125 {     WWT_IMGBTN,   RESIZE_NONE,     7,    42,    63,    14,    35, SPR_IMG_DYNAMITE,    STR_018D_DEMOLISH_BUILDINGS_ETC },
00126 {   WIDGETS_END},
00127 };
00128 
00129 
00130 static const WindowDesc _air_toolbar_desc = {
00131   WDP_ALIGN_TBR, 22, 64, 36, 64, 36,
00132   WC_BUILD_TOOLBAR, WC_NONE,
00133   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
00134   _air_toolbar_widgets,
00135   BuildAirToolbWndProc
00136 };
00137 
00138 void ShowBuildAirToolbar()
00139 {
00140   if (!IsValidPlayer(_current_player)) return;
00141 
00142   DeleteWindowById(WC_BUILD_TOOLBAR, 0);
00143   Window *w = AllocateWindowDescFront(&_air_toolbar_desc, 0);
00144   if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
00145 }
00146 
00147 static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
00148 {
00149   switch (e->event) {
00150   case WE_CREATE:
00151     w->SetWidgetLoweredState(16, !_station_show_coverage);
00152     w->SetWidgetLoweredState(17, _station_show_coverage);
00153     w->LowerWidget(_selected_airport_type + 7);
00154     break;
00155 
00156   case WE_PAINT: {
00157     int i; // airport enabling loop
00158     uint32 avail_airports;
00159     const AirportFTAClass *airport;
00160 
00161     if (WP(w, def_d).close) return;
00162 
00163     avail_airports = GetValidAirports();
00164 
00165     w->RaiseWidget(_selected_airport_type + 7);
00166     if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
00167     if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
00168     w->LowerWidget(_selected_airport_type + 7);
00169 
00170     /* 'Country Airport' starts at widget 7, and if its bit is set, it is
00171      * available, so take its opposite value to set the disabled state.
00172      * There are 9 buildable airports
00173      * XXX TODO : all airports should be held in arrays, with all relevant data.
00174      * This should be part of newgrf-airports, i suppose
00175      */
00176     for (i = 0; i < 9; i++) w->SetWidgetDisabledState(i + 7, !HasBit(avail_airports, i));
00177 
00178     // select default the coverage area to 'Off' (16)
00179     airport = GetAirport(_selected_airport_type);
00180     SetTileSelectSize(airport->size_x, airport->size_y);
00181 
00182     int rad = _patches.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
00183 
00184     if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
00185 
00186     DrawWindowWidgets(w);
00187     // strings such as 'Size' and 'Coverage Area'
00188     // 'Coverage Area'
00189     int text_end = DrawStationCoverageAreaText(2, 206, SCT_ALL, rad) + 4;
00190     if (text_end > w->widget[6].bottom) {
00191       SetWindowDirty(w);
00192       ResizeWindowForWidget(w, 6, 0, text_end - w->widget[6].bottom);
00193       SetWindowDirty(w);
00194     }
00195     break;
00196   }
00197 
00198   case WE_CLICK: {
00199     switch (e->we.click.widget) {
00200     case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
00201       w->RaiseWidget(_selected_airport_type + 7);
00202       _selected_airport_type = e->we.click.widget - 7;
00203       w->LowerWidget(_selected_airport_type + 7);
00204       SndPlayFx(SND_15_BEEP);
00205       SetWindowDirty(w);
00206       break;
00207     case 16: case 17:
00208       _station_show_coverage = (e->we.click.widget != 16);
00209       w->SetWidgetLoweredState(16, !_station_show_coverage);
00210       w->SetWidgetLoweredState(17, _station_show_coverage);
00211       SndPlayFx(SND_15_BEEP);
00212       SetWindowDirty(w);
00213       break;
00214     }
00215   } break;
00216 
00217   case WE_MOUSELOOP: {
00218     if (WP(w, def_d).close) {
00219       DeleteWindow(w);
00220       return;
00221     }
00222 
00223     CheckRedrawStationCoverage(w);
00224   } break;
00225 
00226   case WE_DESTROY:
00227     if (!WP(w, def_d).close) ResetObjectToPlace();
00228     break;
00229   }
00230 }
00231 
00232 static const Widget _build_airport_picker_widgets[] = {
00233 {   WWT_CLOSEBOX,   RESIZE_NONE,     7,     0,    10,     0,    13, STR_00C5,                         STR_018B_CLOSE_WINDOW},
00234 {    WWT_CAPTION,   RESIZE_NONE,     7,    11,   147,     0,    13, STR_3001_AIRPORT_SELECTION,       STR_018C_WINDOW_TITLE_DRAG_THIS},
00235 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,    14,    52, 0x0,                              STR_NULL},
00236 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,    53,    89, 0x0,                              STR_NULL},
00237 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,    90,   127, 0x0,                              STR_NULL},
00238 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,   128,   177, 0x0,                              STR_NULL},
00239 {      WWT_PANEL,   RESIZE_NONE,     7,     0,   147,   178,   239, 0x0,                              STR_NULL},
00240 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,    27,    38, STR_SMALL_AIRPORT,                STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00241 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,    65,    76, STR_CITY_AIRPORT,                 STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00242 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,   141,   152, STR_HELIPORT,                     STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00243 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,    77,    88, STR_METRO_AIRPORT ,               STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00244 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,   103,   114, STR_INTERNATIONAL_AIRPORT,        STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00245 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,    39,    50, STR_COMMUTER_AIRPORT,             STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00246 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,   165,   176, STR_HELIDEPOT,                    STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00247 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,   115,   126, STR_INTERCONTINENTAL_AIRPORT,     STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00248 {    WWT_TEXTBTN,   RESIZE_NONE,    14,     2,   145,   153,   164, STR_HELISTATION,                  STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00249 {    WWT_TEXTBTN,   RESIZE_NONE,    14,    14,    73,   191,   202, STR_02DB_OFF,                     STR_3065_DON_T_HIGHLIGHT_COVERAGE},
00250 {    WWT_TEXTBTN,   RESIZE_NONE,    14,    74,   133,   191,   202, STR_02DA_ON,                      STR_3064_HIGHLIGHT_COVERAGE_AREA},
00251 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,    14,    27, STR_SMALL_AIRPORTS,               STR_NULL},
00252 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,    52,    65, STR_LARGE_AIRPORTS,               STR_NULL},
00253 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,    90,   103, STR_HUB_AIRPORTS,                 STR_NULL},
00254 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,   128,   141, STR_HELIPORTS,                    STR_NULL},
00255 {      WWT_LABEL,   RESIZE_NONE,     7,     0,   147,   178,   191, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
00256 {   WIDGETS_END},
00257 };
00258 
00259 static const WindowDesc _build_airport_desc = {
00260   WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
00261   WC_BUILD_STATION, WC_BUILD_TOOLBAR,
00262   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
00263   _build_airport_picker_widgets,
00264   BuildAirportPickerWndProc
00265 };
00266 
00267 static void ShowBuildAirportPicker()
00268 {
00269   AllocateWindowDesc(&_build_airport_desc);
00270 }
00271 
00272 void InitializeAirportGui()
00273 {
00274   _selected_airport_type = AT_SMALL;
00275 }

Generated on Mon Sep 22 20:34:14 2008 for openttd by  doxygen 1.5.6