truelight@0: #include "stdafx.h" truelight@0: #include "ttd.h" tron@507: #include "table/strings.h" tron@679: #include "map.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "viewport.h" truelight@0: #include "gfx.h" tron@337: #include "sound.h" truelight@0: #include "command.h" truelight@0: #include "vehicle.h" truelight@0: #include "station.h" truelight@0: #include "airport.h" truelight@1313: #include "depot.h" truelight@0: truelight@0: static byte _selected_airport_type; truelight@0: tron@1093: static void ShowBuildAirportPicker(void); truelight@0: truelight@0: truelight@543: void CcBuildAirport(bool success, uint tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: if (success) { tron@541: SndPlayTileFx(SND_1F_SPLAT, tile); truelight@0: ResetObjectToPlace(); truelight@0: } truelight@0: } truelight@0: truelight@0: static void PlaceAirport(uint tile) truelight@0: { truelight@0: DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE)); truelight@0: } truelight@0: truelight@0: static void PlaceAir_DemolishArea(uint tile) truelight@0: { truelight@0: VpStartPlaceSizing(tile, 4); truelight@0: } truelight@0: truelight@0: truelight@0: static void BuildAirClick_Airport(Window *w) truelight@0: { darkvater@756: if (HandlePlacePushButton(w, 3, 0xAA4, 1, PlaceAirport)) ShowBuildAirportPicker(); truelight@0: } truelight@0: truelight@0: static void BuildAirClick_Demolish(Window *w) truelight@0: { darkvater@756: HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea); truelight@0: } truelight@0: dominik@606: static void BuildAirClick_Landscaping(Window *w) truelight@0: { dominik@606: ShowTerraformToolbar(); truelight@0: } truelight@0: truelight@0: typedef void OnButtonClick(Window *w); truelight@0: static OnButtonClick * const _build_air_button_proc[] = { truelight@0: BuildAirClick_Airport, truelight@0: BuildAirClick_Demolish, dominik@606: BuildAirClick_Landscaping, truelight@0: }; truelight@0: truelight@0: static void BuildAirToolbWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawWindowWidgets(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: darkvater@756: if (e->click.widget - 3 >= 0) darkvater@756: _build_air_button_proc[e->click.widget - 3](w); truelight@0: break; tron@1019: celestar@937: case WE_KEYPRESS: { celestar@937: switch (e->keypress.keycode) { celestar@937: case '1': BuildAirClick_Airport(w); break; celestar@937: case '2': BuildAirClick_Demolish(w); break; celestar@937: case 'l': BuildAirClick_Landscaping(w); break; celestar@937: default: celestar@937: return; celestar@937: } celestar@937: } break; truelight@0: truelight@0: case WE_PLACE_OBJ: truelight@0: _place_proc(e->place.tile); truelight@193: break; truelight@0: truelight@0: case WE_PLACE_DRAG: { truelight@0: VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata); truelight@0: return; truelight@0: } truelight@0: truelight@0: case WE_PLACE_MOUSEUP: truelight@0: if (e->place.pt.x != -1) { truelight@0: DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_ABORT_PLACE_OBJ: darkvater@756: UnclickWindowButtons(w); truelight@0: SetWindowDirty(w); truelight@0: w = FindWindowById(WC_BUILD_STATION, 0); truelight@0: if (w != 0) truelight@0: WP(w,def_d).close = true; truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _air_toolbar_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 73, 0, 13, STR_A000_AIRPORTS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_NONE, 7, 74, 85, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 41, 14, 35, 0x2E8, STR_A01E_BUILD_AIRPORT}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 42, 63, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 64, 85, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const WindowDesc _air_toolbar_desc = { dominik@606: 640-86, 22, 86, 36, truelight@0: WC_BUILD_TOOLBAR,0, darkvater@756: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, truelight@0: _air_toolbar_widgets, truelight@0: BuildAirToolbWndProc truelight@0: }; truelight@0: tron@1093: void ShowBuildAirToolbar(void) truelight@0: { dominik@946: if (_current_player == OWNER_SPECTATOR) return; truelight@0: DeleteWindowById(WC_BUILD_TOOLBAR, 0); truelight@0: AllocateWindowDescFront(&_air_toolbar_desc, 0); truelight@0: } truelight@0: truelight@0: static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: { truelight@0: int sel; darkvater@792: int rad = 4; // default catchment radious truelight@0: truelight@0: if (WP(w,def_d).close) truelight@0: return; truelight@0: w->disabled_state = 0; truelight@0: truelight@0: sel = _selected_airport_type; truelight@0: // FIXME -- BuildAirportPickerWndProc - set availability of airports by year, instead of airplane truelight@0: if (!(_avail_aircraft & 1)) { w->disabled_state |= (1<<3); if (sel == AT_SMALL) sel = AT_LARGE; } truelight@0: if (!(_avail_aircraft & 2)) { w->disabled_state |= (1<<4); if (sel == AT_LARGE) sel = AT_SMALL; } truelight@0: if (!(_avail_aircraft & 4)) { w->disabled_state |= (1<<5); } // heliport truelight@0: // 1980-1-1 is --> 21915 truelight@0: // 1990-1-1 is --> 25568 truelight@0: if (_date < 21915) {w->disabled_state |= (1<<6);} // metropilitan airport 1980 truelight@0: if (_date < 25568) {w->disabled_state |= (1<<7);} // international airport 1990 truelight@0: _selected_airport_type = sel; truelight@0: // select default the coverage area to 'Off' (8) truelight@0: w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage); truelight@0: SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]); Celestar@568: Celestar@568: if (_patches.modified_catchment) { Celestar@568: switch (sel) { Celestar@568: case AT_OILRIG: rad = CA_AIR_OILPAD; break; Celestar@568: case AT_HELIPORT: rad = CA_AIR_HELIPORT; break; Celestar@568: case AT_SMALL: rad = CA_AIR_SMALL; break; Celestar@568: case AT_LARGE: rad = CA_AIR_LARGE; break; Celestar@568: case AT_METROPOLITAN: rad = CA_AIR_METRO; break; Celestar@568: case AT_INTERNATIONAL: rad = CA_AIR_INTER; break; Celestar@568: } darkvater@792: } truelight@867: Celestar@568: if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); truelight@0: truelight@0: DrawWindowWidgets(w); truelight@0: // strings such as 'Size' and 'Coverage Area' truelight@0: DrawStringCentered(74, 16, STR_305B_SIZE, 0); truelight@0: DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); Celestar@568: DrawStationCoverageAreaText(2, 104, (uint)-1, rad); truelight@0: break; truelight@0: } truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@0: case 3: case 4: case 5: case 6: case 7: truelight@0: _selected_airport_type = e->click.widget - 3; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: case 8: case 9: truelight@0: _station_show_coverage = e->click.widget - 8; tron@541: SndPlayFx(SND_15_BEEP); truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_MOUSELOOP: { truelight@0: if (WP(w,def_d).close) { truelight@0: DeleteWindow(w); truelight@0: return; truelight@0: } truelight@0: truelight@0: CheckRedrawStationCoverage(w); truelight@0: } break; tron@1109: celestar@1072: case WE_DESTROY: darkvater@1116: if (!WP(w,def_d).close) darkvater@1116: ResetObjectToPlace(); celestar@1072: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _build_airport_picker_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 130, 0x0, STR_NULL}, truelight@867: {WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 73, 27, 38, STR_3059_SMALL, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, truelight@867: {WWT_NODISTXTBTN, RESIZE_NONE, 14, 74, 145, 27, 38, STR_305A_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, truelight@867: {WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, truelight@867: {WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, truelight@867: {WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _build_airport_desc = { truelight@0: -1, -1, 148, 131, // height, 130+1 truelight@0: WC_BUILD_STATION,WC_BUILD_TOOLBAR, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, truelight@0: _build_airport_picker_widgets, truelight@0: BuildAirportPickerWndProc truelight@0: }; truelight@0: tron@1093: static void ShowBuildAirportPicker(void) truelight@0: { truelight@0: AllocateWindowDesc(&_build_airport_desc); truelight@0: } truelight@0: tron@1093: void InitializeAirportGui(void) truelight@0: { truelight@0: _selected_airport_type = AT_SMALL; truelight@0: _last_built_aircraft_depot_tile = 0; truelight@0: }