2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 01:48:53 +00:00
|
|
|
/** @file airport_gui.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-13 11:18:02 +00:00
|
|
|
#include "table/sprites.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "station_gui.h"
|
2008-01-06 18:56:43 +00:00
|
|
|
#include "terraform_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "viewport.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "station.h"
|
|
|
|
#include "airport.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2007-12-29 09:24:26 +00:00
|
|
|
#include "sound_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "window_func.h"
|
2008-01-07 00:57:19 +00:00
|
|
|
#include "variables.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static byte _selected_airport_type;
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ShowBuildAirportPicker();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
void CcBuildAirport(bool success, TileIndex tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (success) {
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayTileFx(SND_1F_SPLAT, tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
ResetObjectToPlace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void PlaceAirport(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-09-04 11:58:27 +00:00
|
|
|
DoCommandP(tile, _selected_airport_type, _ctrl_pressed, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void PlaceAir_DemolishArea(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-05-23 13:52:10 +00:00
|
|
|
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_DEMOLISH_AREA);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-22 16:08:01 +00:00
|
|
|
enum {
|
|
|
|
ATW_AIRPORT = 3,
|
|
|
|
ATW_DEMOLISH = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void BuildAirClick_Airport(Window *w)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
if (HandlePlacePushButton(w, ATW_AIRPORT, SPR_CURSOR_AIRPORT, VHM_RECT, PlaceAirport)) ShowBuildAirportPicker();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BuildAirClick_Demolish(Window *w)
|
|
|
|
{
|
2007-11-15 18:28:00 +00:00
|
|
|
HandlePlacePushButton(w, ATW_DEMOLISH, ANIMCURSOR_DEMOLISH, VHM_RECT, PlaceAir_DemolishArea);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w);
|
|
|
|
static OnButtonClick * const _build_air_button_proc[] = {
|
|
|
|
BuildAirClick_Airport,
|
|
|
|
BuildAirClick_Demolish,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.click.widget - 3 >= 0)
|
|
|
|
_build_air_button_proc[e->we.click.widget - 3](w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-08 09:40:22 +00:00
|
|
|
case WE_KEYPRESS: {
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.keypress.keycode) {
|
2005-01-08 09:40:22 +00:00
|
|
|
case '1': BuildAirClick_Airport(w); break;
|
|
|
|
case '2': BuildAirClick_Demolish(w); break;
|
2005-11-13 14:54:09 +00:00
|
|
|
default: return;
|
2005-01-08 09:40:22 +00:00
|
|
|
}
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_PLACE_OBJ:
|
2006-09-23 02:39:24 +00:00
|
|
|
_place_proc(e->we.place.tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-27 21:25:53 +00:00
|
|
|
case WE_PLACE_DRAG:
|
2007-05-23 12:45:56 +00:00
|
|
|
VpSelectTilesWithMethod(e->we.place.pt.x, e->we.place.pt.y, e->we.place.select_method);
|
2006-06-27 21:25:53 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_PLACE_MOUSEUP:
|
2007-05-23 13:52:10 +00:00
|
|
|
if (e->we.place.pt.x != -1 && e->we.place.select_proc == DDSP_DEMOLISH_AREA) {
|
2006-09-23 02:39:24 +00:00
|
|
|
DoCommandP(e->we.place.tile, e->we.place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2007-12-08 01:20:47 +00:00
|
|
|
w->RaiseButtons();
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
w = FindWindowById(WC_BUILD_STATION, 0);
|
|
|
|
if (w != 0)
|
2007-04-18 22:10:36 +00:00
|
|
|
WP(w, def_d).close = true;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-11-09 07:25:55 +00:00
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _air_toolbar_widgets[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
2007-01-15 07:38:36 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 51, 0, 13, STR_A000_AIRPORTS, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 7, 52, 63, 0, 13, 0x0, STR_STICKY_BUTTON },
|
2006-10-24 13:20:54 +00:00
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 0, 41, 14, 35, SPR_IMG_AIRPORT, STR_A01E_BUILD_AIRPORT },
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 7, 42, 63, 14, 35, SPR_IMG_DYNAMITE, STR_018D_DEMOLISH_BUILDINGS_ETC },
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _air_toolbar_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_ALIGN_TBR, 22, 64, 36, 64, 36,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_BUILD_TOOLBAR, WC_NONE,
|
2004-12-22 00:18:40 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_air_toolbar_widgets,
|
|
|
|
BuildAirToolbWndProc
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ShowBuildAirToolbar()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(_current_player)) return;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
|
2007-01-28 10:09:40 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_air_toolbar_desc, 0);
|
|
|
|
if (_patches.link_terraform_toolbar) ShowTerraformToolbar(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-09 22:33:00 +00:00
|
|
|
switch (e->event) {
|
2006-10-03 20:16:20 +00:00
|
|
|
case WE_CREATE:
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetLoweredState(16, !_station_show_coverage);
|
|
|
|
w->SetWidgetLoweredState(17, _station_show_coverage);
|
|
|
|
w->LowerWidget(_selected_airport_type + 7);
|
2006-10-03 20:16:20 +00:00
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2006-10-03 02:08:15 +00:00
|
|
|
int i; // airport enabling loop
|
2005-05-09 22:33:00 +00:00
|
|
|
uint32 avail_airports;
|
2006-07-26 03:33:12 +00:00
|
|
|
const AirportFTAClass *airport;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
if (WP(w, def_d).close) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
avail_airports = GetValidAirports();
|
|
|
|
|
2007-12-02 14:29:48 +00:00
|
|
|
w->RaiseWidget(_selected_airport_type + 7);
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(avail_airports, 0) && _selected_airport_type == AT_SMALL) _selected_airport_type = AT_LARGE;
|
|
|
|
if (!HasBit(avail_airports, 1) && _selected_airport_type == AT_LARGE) _selected_airport_type = AT_SMALL;
|
2007-12-02 14:29:48 +00:00
|
|
|
w->LowerWidget(_selected_airport_type + 7);
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
/* 'Country Airport' starts at widget 7, and if its bit is set, it is
|
|
|
|
* available, so take its opposite value to set the disabled state.
|
|
|
|
* There are 9 buildable airports
|
|
|
|
* XXX TODO : all airports should be held in arrays, with all relevant data.
|
|
|
|
* This should be part of newgrf-airports, i suppose
|
|
|
|
*/
|
2007-12-02 14:29:48 +00:00
|
|
|
for (i = 0; i < 9; i++) w->SetWidgetDisabledState(i + 7, !HasBit(avail_airports, i));
|
2005-05-09 22:33:00 +00:00
|
|
|
|
2006-06-23 22:05:40 +00:00
|
|
|
// select default the coverage area to 'Off' (16)
|
2006-10-03 20:16:20 +00:00
|
|
|
airport = GetAirport(_selected_airport_type);
|
2006-05-20 15:13:27 +00:00
|
|
|
SetTileSelectSize(airport->size_x, airport->size_y);
|
2004-12-08 15:46:13 +00:00
|
|
|
|
2007-02-17 10:21:48 +00:00
|
|
|
int rad = _patches.modified_catchment ? airport->catchment : 4;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DrawWindowWidgets(w);
|
2006-06-27 21:25:53 +00:00
|
|
|
// strings such as 'Size' and 'Coverage Area'
|
2006-08-22 15:23:25 +00:00
|
|
|
// 'Coverage Area'
|
2007-07-12 13:40:24 +00:00
|
|
|
DrawStationCoverageAreaText(2, 206, SCT_ALL, rad);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2006-06-23 22:05:40 +00:00
|
|
|
case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
|
2007-12-02 14:29:48 +00:00
|
|
|
w->RaiseWidget(_selected_airport_type + 7);
|
2006-09-23 02:39:24 +00:00
|
|
|
_selected_airport_type = e->we.click.widget - 7;
|
2007-12-02 14:29:48 +00:00
|
|
|
w->LowerWidget(_selected_airport_type + 7);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayFx(SND_15_BEEP);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-06-23 22:05:40 +00:00
|
|
|
case 16: case 17:
|
2007-01-10 18:56:51 +00:00
|
|
|
_station_show_coverage = (e->we.click.widget != 16);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->SetWidgetLoweredState(16, !_station_show_coverage);
|
|
|
|
w->SetWidgetLoweredState(17, _station_show_coverage);
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayFx(SND_15_BEEP);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP: {
|
2007-04-18 22:10:36 +00:00
|
|
|
if (WP(w, def_d).close) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindow(w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckRedrawStationCoverage(w);
|
|
|
|
} break;
|
2005-01-23 13:09:35 +00:00
|
|
|
|
2005-01-20 08:36:15 +00:00
|
|
|
case WE_DESTROY:
|
2007-04-18 22:10:36 +00:00
|
|
|
if (!WP(w, def_d).close) ResetObjectToPlace();
|
2005-01-20 08:36:15 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _build_airport_picker_widgets[] = {
|
2006-08-22 15:23:25 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 52, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 53, 89, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 90, 127, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 128, 177, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 178, 239, 0x0, STR_NULL},
|
2006-10-27 20:39:58 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 27, 38, STR_SMALL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 65, 76, STR_CITY_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 141, 152, STR_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 77, 88, STR_METRO_AIRPORT , STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 103, 114, STR_INTERNATIONAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 39, 50, STR_COMMUTER_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 165, 176, STR_HELIDEPOT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 115, 126, STR_INTERCONTINENTAL_AIRPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 2, 145, 153, 164, STR_HELISTATION, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
2006-08-22 15:23:25 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 191, 202, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 191, 202, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 14, 27, STR_SMALL_AIRPORTS, STR_NULL},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 52, 65, STR_LARGE_AIRPORTS, STR_NULL},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 90, 103, STR_HUB_AIRPORTS, STR_NULL},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 128, 141, STR_HELIPORTS, STR_NULL},
|
|
|
|
{ WWT_LABEL, RESIZE_NONE, 7, 0, 147, 178, 191, STR_3066_COVERAGE_AREA_HIGHLIGHT, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_airport_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 148, 240, 148, 240,
|
2006-11-10 19:24:14 +00:00
|
|
|
WC_BUILD_STATION, WC_BUILD_TOOLBAR,
|
2004-08-09 17:04:08 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_airport_picker_widgets,
|
|
|
|
BuildAirportPickerWndProc
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ShowBuildAirportPicker()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
AllocateWindowDesc(&_build_airport_desc);
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeAirportGui()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_selected_airport_type = AT_SMALL;
|
|
|
|
}
|