00001
00002
00005 #include "stdafx.h"
00006 #include "window_gui.h"
00007 #include "station_gui.h"
00008 #include "terraform_gui.h"
00009 #include "airport.h"
00010 #include "sound_func.h"
00011 #include "window_func.h"
00012 #include "strings_func.h"
00013 #include "settings_type.h"
00014 #include "viewport_func.h"
00015 #include "gfx_func.h"
00016 #include "company_func.h"
00017 #include "station_type.h"
00018 #include "tilehighlight_func.h"
00019 #include "company_base.h"
00020
00021 #include "table/sprites.h"
00022 #include "table/strings.h"
00023
00024 static byte _selected_airport_type;
00025
00026 static void ShowBuildAirportPicker(Window *parent);
00027
00028
00029 void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
00030 {
00031 if (success) {
00032 SndPlayTileFx(SND_1F_SPLAT, tile);
00033 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
00034 }
00035 }
00036
00037 static void PlaceAirport(TileIndex tile)
00038 {
00039 uint32 p2 = _ctrl_pressed;
00040 SB(p2, 16, 16, INVALID_STATION);
00041
00042 CommandContainer cmdcont = { tile, _selected_airport_type, p2, CMD_BUILD_AIRPORT | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE), CcBuildAirport, "" };
00043 ShowSelectStationIfNeeded(cmdcont, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE);
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, false);
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 DeleteWindowById(WC_BUILD_STATION, 0);
00127 DeleteWindowById(WC_SELECT_STATION, 0);
00128 }
00129 };
00130
00131 static const Widget _air_toolbar_widgets[] = {
00132 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
00133 { WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 51, 0, 13, STR_A000_AIRPORTS, STR_018C_WINDOW_TITLE_DRAG_THIS },
00134 { WWT_STICKYBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 52, 63, 0, 13, 0x0, STR_STICKY_BUTTON },
00135 { WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 41, 14, 35, SPR_IMG_AIRPORT, STR_A01E_BUILD_AIRPORT },
00136 { WWT_IMGBTN, RESIZE_NONE, COLOUR_DARK_GREEN, 42, 63, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC },
00137 { WIDGETS_END},
00138 };
00139
00140
00141 static const WindowDesc _air_toolbar_desc(
00142 WDP_ALIGN_TBR, 22, 64, 36, 64, 36,
00143 WC_BUILD_TOOLBAR, WC_NONE,
00144 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_CONSTRUCTION,
00145 _air_toolbar_widgets
00146 );
00147
00148 void ShowBuildAirToolbar()
00149 {
00150 if (!IsValidCompanyID(_local_company)) return;
00151
00152 DeleteWindowByClass(WC_BUILD_TOOLBAR);
00153 AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
00154 }
00155
00156 class AirportPickerWindow : public PickerWindowBase {
00157
00158 enum {
00159 BAW_BOTTOMPANEL = 10,
00160 BAW_SMALL_AIRPORT,
00161 BAW_CITY_AIRPORT,
00162 BAW_HELIPORT,
00163 BAW_METRO_AIRPORT,
00164 BAW_STR_INTERNATIONAL_AIRPORT,
00165 BAW_COMMUTER_AIRPORT,
00166 BAW_HELIDEPOT,
00167 BAW_STR_INTERCONTINENTAL_AIRPORT,
00168 BAW_HELISTATION,
00169 BAW_LAST_AIRPORT = BAW_HELISTATION,
00170 BAW_AIRPORT_COUNT = BAW_LAST_AIRPORT - BAW_SMALL_AIRPORT + 1,
00171 BAW_BTN_DONTHILIGHT = BAW_LAST_AIRPORT + 1,
00172 BAW_BTN_DOHILIGHT,
00173 };
00174
00175 public:
00176
00177 AirportPickerWindow(const WindowDesc *desc, Window *parent) : PickerWindowBase(desc, parent)
00178 {
00179 this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
00180 this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
00181 this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00182
00183 if (_settings_game.economy.station_noise_level) {
00184 ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, 10);
00185 }
00186
00187 this->FindWindowPlacementAndResize(desc);
00188 }
00189
00190 virtual ~AirportPickerWindow()
00191 {
00192 DeleteWindowById(WC_SELECT_STATION, 0);
00193 }
00194
00195 virtual void OnPaint()
00196 {
00197 int i;
00198 uint16 y_noise_offset = 0;
00199 uint32 avail_airports;
00200 const AirportFTAClass *airport;
00201
00202 avail_airports = GetValidAirports();
00203
00204 this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00205 if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
00206 if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
00207 this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00208
00209
00210
00211
00212
00213
00214
00215 for (i = 0; i < BAW_AIRPORT_COUNT; i++) this->SetWidgetDisabledState(i + BAW_SMALL_AIRPORT, !HasBit(avail_airports, i));
00216
00217
00218 airport = GetAirport(_selected_airport_type);
00219 SetTileSelectSize(airport->size_x, airport->size_y);
00220
00221 int rad = _settings_game.station.modified_catchment ? airport->catchment : (uint)CA_UNMODIFIED;
00222
00223 if (_settings_client.gui.station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
00224
00225 this->DrawWidgets();
00226
00227
00228 if (_settings_game.economy.station_noise_level) {
00229
00230 SetDParam(0, airport->noise_level);
00231 DrawString(2, 206, STR_STATION_NOISE, TC_FROMSTRING);
00232 y_noise_offset = 10;
00233 }
00234
00235
00236 int text_end = DrawStationCoverageAreaText(2, this->widget[BAW_BTN_DOHILIGHT].bottom + 4 + y_noise_offset, SCT_ALL, rad, false);
00237 text_end = DrawStationCoverageAreaText(2, text_end + 4, SCT_ALL, rad, true) + 4;
00238 if (text_end != this->widget[BAW_BOTTOMPANEL].bottom) {
00239 this->SetDirty();
00240 ResizeWindowForWidget(this, BAW_BOTTOMPANEL, 0, text_end - this->widget[BAW_BOTTOMPANEL].bottom);
00241 this->SetDirty();
00242 }
00243 }
00244
00245 virtual void OnClick(Point pt, int widget)
00246 {
00247 switch (widget) {
00248 case BAW_SMALL_AIRPORT: case BAW_CITY_AIRPORT: case BAW_HELIPORT: case BAW_METRO_AIRPORT:
00249 case BAW_STR_INTERNATIONAL_AIRPORT: case BAW_COMMUTER_AIRPORT: case BAW_HELIDEPOT:
00250 case BAW_STR_INTERCONTINENTAL_AIRPORT: case BAW_HELISTATION:
00251 this->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00252 _selected_airport_type = widget - BAW_SMALL_AIRPORT;
00253 this->LowerWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
00254 SndPlayFx(SND_15_BEEP);
00255 this->SetDirty();
00256 DeleteWindowById(WC_SELECT_STATION, 0);
00257 break;
00258
00259 case BAW_BTN_DONTHILIGHT: case BAW_BTN_DOHILIGHT:
00260 _settings_client.gui.station_show_coverage = (widget != BAW_BTN_DONTHILIGHT);
00261 this->SetWidgetLoweredState(BAW_BTN_DONTHILIGHT, !_settings_client.gui.station_show_coverage);
00262 this->SetWidgetLoweredState(BAW_BTN_DOHILIGHT, _settings_client.gui.station_show_coverage);
00263 SndPlayFx(SND_15_BEEP);
00264 this->SetDirty();
00265 break;
00266 }
00267 }
00268
00269 virtual void OnTick()
00270 {
00271 CheckRedrawStationCoverage(this);
00272 }
00273 };
00274
00275 static const Widget _build_airport_picker_widgets[] = {
00276 { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
00277 { WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
00278 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 14, 52, 0x0, STR_NULL},
00279 { WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 14, 27, STR_SMALL_AIRPORTS, STR_NULL},
00280 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 53, 89, 0x0, STR_NULL},
00281 { WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 52, 65, STR_LARGE_AIRPORTS, STR_NULL},
00282 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 90, 127, 0x0, STR_NULL},
00283 { WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 90, 103, STR_HUB_AIRPORTS, STR_NULL},
00284 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 128, 177, 0x0, STR_NULL},
00285 { WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 128, 141, STR_HELIPORTS, STR_NULL},
00286 { WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 178, 239, 0x0, STR_NULL},
00287 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 27, 38, STR_SMALL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00288 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 65, 76, STR_CITY_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00289 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 141, 152, STR_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00290 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 77, 88, STR_METRO_AIRPORT , STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00291 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 103, 114, STR_INTERNATIONAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00292 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 39, 50, STR_COMMUTER_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00293 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 165, 176, STR_HELIDEPOT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00294 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 115, 126, STR_INTERCONTINENTAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00295 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 145, 153, 164, STR_HELISTATION, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
00296 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 14, 73, 191, 202, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
00297 { WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 74, 133, 191, 202, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
00298 { WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 178, 191, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
00299 { WIDGETS_END},
00300 };
00301
00302 static const WindowDesc _build_airport_desc(
00303 WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
00304 WC_BUILD_STATION, WC_BUILD_TOOLBAR,
00305 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_CONSTRUCTION,
00306 _build_airport_picker_widgets
00307 );
00308
00309 static void ShowBuildAirportPicker(Window *parent)
00310 {
00311 new AirportPickerWindow(&_build_airport_desc, parent);
00312 }
00313
00314 void InitializeAirportGui()
00315 {
00316 _selected_airport_type = AT_SMALL;
00317 }