2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "gfx.h"
|
2004-11-05 23:12:33 +00:00
|
|
|
#include "sound.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "airport.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static byte _selected_airport_type;
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void ShowBuildAirportPicker(void);
|
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
|
|
|
{
|
|
|
|
DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE));
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
static void PlaceAir_DemolishArea(TileIndex tile)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
VpStartPlaceSizing(tile, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void BuildAirClick_Airport(Window *w)
|
|
|
|
{
|
2005-06-06 13:47:06 +00:00
|
|
|
if (HandlePlacePushButton(w, 3, SPR_CURSOR_AIRPORT, 1, PlaceAirport)) ShowBuildAirportPicker();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void BuildAirClick_Demolish(Window *w)
|
|
|
|
{
|
2004-12-22 00:18:40 +00:00
|
|
|
HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-12 17:42:04 +00:00
|
|
|
static void BuildAirClick_Landscaping(Window *w)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-12 17:42:04 +00:00
|
|
|
ShowTerraformToolbar();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef void OnButtonClick(Window *w);
|
|
|
|
static OnButtonClick * const _build_air_button_proc[] = {
|
|
|
|
BuildAirClick_Airport,
|
|
|
|
BuildAirClick_Demolish,
|
2004-12-12 17:42:04 +00:00
|
|
|
BuildAirClick_Landscaping,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
2004-12-22 00:18:40 +00:00
|
|
|
if (e->click.widget - 3 >= 0)
|
|
|
|
_build_air_button_proc[e->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: {
|
|
|
|
switch (e->keypress.keycode) {
|
|
|
|
case '1': BuildAirClick_Airport(w); break;
|
|
|
|
case '2': BuildAirClick_Demolish(w); break;
|
|
|
|
case 'l': BuildAirClick_Landscaping(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:
|
|
|
|
_place_proc(e->place.tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_PLACE_DRAG: {
|
|
|
|
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_PLACE_MOUSEUP:
|
|
|
|
if (e->place.pt.x != -1) {
|
|
|
|
DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ABORT_PLACE_OBJ:
|
2004-12-22 00:18:40 +00:00
|
|
|
UnclickWindowButtons(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
w = FindWindowById(WC_BUILD_STATION, 0);
|
|
|
|
if (w != 0)
|
|
|
|
WP(w,def_d).close = true;
|
|
|
|
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[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 73, 0, 13, STR_A000_AIRPORTS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 7, 74, 85, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 0, 41, 14, 35, 0x2E8, STR_A01E_BUILD_AIRPORT},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 42, 63, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 7, 64, 85, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _air_toolbar_desc = {
|
2004-12-12 17:42:04 +00:00
|
|
|
640-86, 22, 86, 36,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_BUILD_TOOLBAR,0,
|
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
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowBuildAirToolbar(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-08 20:55:21 +00:00
|
|
|
if (_current_player == OWNER_SPECTATOR) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
|
|
|
|
AllocateWindowDescFront(&_air_toolbar_desc, 0);
|
2005-11-09 07:25:55 +00:00
|
|
|
if (_patches.link_terraform_toolbar) ShowTerraformToolbar();
|
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) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
|
|
|
int sel;
|
2004-12-23 20:23:05 +00:00
|
|
|
int rad = 4; // default catchment radious
|
2005-05-09 22:33:00 +00:00
|
|
|
uint32 avail_airports;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-09 22:33:00 +00:00
|
|
|
if (WP(w,def_d).close) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
sel = _selected_airport_type;
|
2005-05-09 22:33:00 +00:00
|
|
|
avail_airports = GetValidAirports();
|
|
|
|
|
|
|
|
if (!HASBIT(avail_airports, 0) && sel == AT_SMALL) sel = AT_LARGE;
|
|
|
|
if (!HASBIT(avail_airports, 1) && sel == AT_LARGE) sel = AT_SMALL;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
/* 'Country Airport' starts at widget 3, and if its bit is set, it is
|
|
|
|
* available, so take its opposite value to set the disabled_state. There
|
|
|
|
* are only 5 available airports, so XOR with 0x1F (1 1111) */
|
2005-05-09 22:33:00 +00:00
|
|
|
w->disabled_state = (avail_airports ^ 0x1F) << 3;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_selected_airport_type = sel;
|
|
|
|
// select default the coverage area to 'Off' (8)
|
|
|
|
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage);
|
|
|
|
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]);
|
2004-12-08 15:46:13 +00:00
|
|
|
|
2005-11-13 14:54:09 +00:00
|
|
|
if (_patches.modified_catchment) {
|
|
|
|
switch (sel) {
|
|
|
|
case AT_OILRIG: rad = CA_AIR_OILPAD; break;
|
|
|
|
case AT_HELIPORT: rad = CA_AIR_HELIPORT; break;
|
|
|
|
case AT_SMALL: rad = CA_AIR_SMALL; break;
|
|
|
|
case AT_LARGE: rad = CA_AIR_LARGE; break;
|
|
|
|
case AT_METROPOLITAN: rad = CA_AIR_METRO; break;
|
|
|
|
case AT_INTERNATIONAL: rad = CA_AIR_INTER; break;
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
// strings such as 'Size' and 'Coverage Area'
|
|
|
|
DrawStringCentered(74, 16, STR_305B_SIZE, 0);
|
|
|
|
DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0);
|
2004-12-08 15:46:13 +00:00
|
|
|
DrawStationCoverageAreaText(2, 104, (uint)-1, rad);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 3: case 4: case 5: case 6: case 7:
|
|
|
|
_selected_airport_type = e->click.widget - 3;
|
2004-12-04 09:26:39 +00:00
|
|
|
SndPlayFx(SND_15_BEEP);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
case 8: case 9:
|
|
|
|
_station_show_coverage = e->click.widget - 8;
|
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: {
|
|
|
|
if (WP(w,def_d).close) {
|
|
|
|
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:
|
2005-11-14 19:48:04 +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[] = {
|
2005-01-03 19:45:18 +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, 130, 0x0, STR_NULL},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 73, 27, 38, STR_3059_SMALL, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 74, 145, 27, 38, STR_305A_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
|
|
|
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT},
|
2005-12-07 15:48:52 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _build_airport_desc = {
|
|
|
|
-1, -1, 148, 131, // height, 130+1
|
|
|
|
WC_BUILD_STATION,WC_BUILD_TOOLBAR,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
_build_airport_picker_widgets,
|
|
|
|
BuildAirportPickerWndProc
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void ShowBuildAirportPicker(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
AllocateWindowDesc(&_build_airport_desc);
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeAirportGui(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_selected_airport_type = AT_SMALL;
|
|
|
|
_last_built_aircraft_depot_tile = 0;
|
|
|
|
}
|