author | tron |
Fri, 05 Nov 2004 23:12:33 +0000 | |
changeset 337 | 66647f97e7c0 |
parent 193 | 0a7025304867 |
child 507 | 8aa8100b0b22 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
3 |
||
4 |
#include "window.h" |
|
5 |
#include "gui.h" |
|
6 |
#include "viewport.h" |
|
7 |
#include "gfx.h" |
|
337
66647f97e7c0
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
193
diff
changeset
|
8 |
#include "sound.h" |
0 | 9 |
#include "command.h" |
10 |
#include "vehicle.h" |
|
11 |
#include "station.h" |
|
12 |
#include "airport.h" |
|
13 |
||
14 |
static byte _selected_airport_type; |
|
15 |
||
16 |
static void ShowBuildAirportPicker(); |
|
17 |
||
18 |
||
19 |
static void CcBuildAirport(bool success, uint tile, uint32 p1, uint32 p2) |
|
20 |
{ |
|
21 |
if (success) { |
|
22 |
SndPlayTileFx(0x1D, tile); |
|
23 |
ResetObjectToPlace(); |
|
24 |
} |
|
25 |
} |
|
26 |
||
27 |
static void PlaceAirport(uint tile) |
|
28 |
{ |
|
29 |
DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE)); |
|
30 |
} |
|
31 |
||
32 |
static void PlaceAir_DemolishArea(uint tile) |
|
33 |
{ |
|
34 |
VpStartPlaceSizing(tile, 4); |
|
35 |
} |
|
36 |
||
37 |
||
38 |
static void BuildAirClick_Airport(Window *w) |
|
39 |
{ |
|
40 |
if (HandlePlacePushButton(w, 2, 0xAA4, 1, PlaceAirport)) ShowBuildAirportPicker(); |
|
41 |
} |
|
42 |
||
43 |
static void BuildAirClick_Demolish(Window *w) |
|
44 |
{ |
|
45 |
HandlePlacePushButton(w, 3, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea); |
|
46 |
} |
|
47 |
||
48 |
static void BuildAirClick_Lower(Window *w) |
|
49 |
{ |
|
50 |
HandlePlacePushButton(w, 4, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand); |
|
51 |
} |
|
52 |
||
53 |
static void BuildAirClick_Raise(Window *w) |
|
54 |
{ |
|
55 |
HandlePlacePushButton(w, 5, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand); |
|
56 |
} |
|
57 |
||
58 |
static void BuildAirClick_Purchase(Window *w) |
|
59 |
{ |
|
60 |
HandlePlacePushButton(w, 6, 0x12B8, 1, PlaceProc_BuyLand); |
|
61 |
} |
|
62 |
||
63 |
typedef void OnButtonClick(Window *w); |
|
64 |
static OnButtonClick * const _build_air_button_proc[] = { |
|
65 |
BuildAirClick_Airport, |
|
66 |
BuildAirClick_Demolish, |
|
67 |
BuildAirClick_Lower, |
|
68 |
BuildAirClick_Raise, |
|
69 |
BuildAirClick_Purchase, |
|
70 |
}; |
|
71 |
||
72 |
static void BuildAirToolbWndProc(Window *w, WindowEvent *e) |
|
73 |
{ |
|
74 |
switch(e->event) { |
|
75 |
case WE_PAINT: |
|
76 |
DrawWindowWidgets(w); |
|
77 |
break; |
|
78 |
||
79 |
case WE_CLICK: |
|
80 |
if (e->click.widget-2 >= 0) |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
81 |
_build_air_button_proc[e->click.widget - 2](w); |
0 | 82 |
break; |
83 |
||
84 |
case WE_PLACE_OBJ: |
|
85 |
_place_proc(e->place.tile); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
86 |
break; |
0 | 87 |
|
88 |
case WE_PLACE_DRAG: { |
|
89 |
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata); |
|
90 |
return; |
|
91 |
} |
|
92 |
||
93 |
case WE_PLACE_MOUSEUP: |
|
94 |
if (e->place.pt.x != -1) { |
|
95 |
DoCommandP(e->place.tile, e->place.starttile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA)); |
|
96 |
} |
|
97 |
break; |
|
98 |
||
99 |
case WE_ABORT_PLACE_OBJ: |
|
100 |
w->click_state = 0; |
|
101 |
SetWindowDirty(w); |
|
102 |
w = FindWindowById(WC_BUILD_STATION, 0); |
|
103 |
if (w != 0) |
|
104 |
WP(w,def_d).close = true; |
|
105 |
break; |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
static const Widget _air_toolbar_widgets[] = { |
|
110 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
111 |
{ WWT_CAPTION, 7, 11, 129, 0, 13, STR_A000_AIRPORT_CONSTRUCT, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
112 |
{ WWT_PANEL, 7, 0, 41, 14, 35, 0x2E8, STR_A01E_BUILD_AIRPORT}, |
|
113 |
{ WWT_PANEL, 7, 42, 63, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, |
|
114 |
{ WWT_PANEL, 7, 64, 85, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND}, |
|
115 |
{ WWT_PANEL, 7, 86, 107, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND}, |
|
116 |
{ WWT_PANEL, 7, 108, 129, 14, 35, 0x12B7, STR_0329_PURCHASE_LAND_FOR_FUTURE}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
117 |
{ WIDGETS_END}, |
0 | 118 |
}; |
119 |
||
120 |
||
121 |
static const WindowDesc _air_toolbar_desc = { |
|
122 |
510, 22, 130, 36, |
|
123 |
WC_BUILD_TOOLBAR,0, |
|
124 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
125 |
_air_toolbar_widgets, |
|
126 |
BuildAirToolbWndProc |
|
127 |
}; |
|
128 |
||
129 |
void ShowBuildAirToolbar() |
|
130 |
{ |
|
131 |
DeleteWindowById(WC_BUILD_TOOLBAR, 0); |
|
132 |
AllocateWindowDescFront(&_air_toolbar_desc, 0); |
|
133 |
} |
|
134 |
||
135 |
static void BuildAirportPickerWndProc(Window *w, WindowEvent *e) |
|
136 |
{ |
|
137 |
switch(e->event) { |
|
138 |
case WE_PAINT: { |
|
139 |
int sel; |
|
140 |
||
141 |
if (WP(w,def_d).close) |
|
142 |
return; |
|
143 |
w->disabled_state = 0; |
|
144 |
||
145 |
sel = _selected_airport_type; |
|
146 |
// FIXME -- BuildAirportPickerWndProc - set availability of airports by year, instead of airplane |
|
147 |
if (!(_avail_aircraft & 1)) { w->disabled_state |= (1<<3); if (sel == AT_SMALL) sel = AT_LARGE; } |
|
148 |
if (!(_avail_aircraft & 2)) { w->disabled_state |= (1<<4); if (sel == AT_LARGE) sel = AT_SMALL; } |
|
149 |
if (!(_avail_aircraft & 4)) { w->disabled_state |= (1<<5); } // heliport |
|
150 |
// 1980-1-1 is --> 21915 |
|
151 |
// 1990-1-1 is --> 25568 |
|
152 |
if (_date < 21915) {w->disabled_state |= (1<<6);} // metropilitan airport 1980 |
|
153 |
if (_date < 25568) {w->disabled_state |= (1<<7);} // international airport 1990 |
|
154 |
_selected_airport_type = sel; |
|
155 |
// select default the coverage area to 'Off' (8) |
|
156 |
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage); |
|
157 |
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]); |
|
158 |
if (_station_show_coverage) SetTileSelectBigSize(-4, -4, 8, 8); |
|
159 |
||
160 |
DrawWindowWidgets(w); |
|
161 |
// strings such as 'Size' and 'Coverage Area' |
|
162 |
DrawStringCentered(74, 16, STR_305B_SIZE, 0); |
|
163 |
DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
164 |
DrawStationCoverageAreaText(2, 104, (uint)-1); |
0 | 165 |
break; |
166 |
} |
|
167 |
||
168 |
case WE_CLICK: { |
|
169 |
switch(e->click.widget) { |
|
170 |
case 0: |
|
171 |
ResetObjectToPlace(); |
|
172 |
break; |
|
173 |
case 3: case 4: case 5: case 6: case 7: |
|
174 |
_selected_airport_type = e->click.widget - 3; |
|
175 |
SndPlayFx(0x13); |
|
176 |
SetWindowDirty(w); |
|
177 |
break; |
|
178 |
case 8: case 9: |
|
179 |
_station_show_coverage = e->click.widget - 8; |
|
180 |
SndPlayFx(0x13); |
|
181 |
SetWindowDirty(w); |
|
182 |
break; |
|
183 |
} |
|
184 |
} break; |
|
185 |
||
186 |
case WE_MOUSELOOP: { |
|
187 |
if (WP(w,def_d).close) { |
|
188 |
DeleteWindow(w); |
|
189 |
return; |
|
190 |
} |
|
191 |
||
192 |
CheckRedrawStationCoverage(w); |
|
193 |
} break; |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
static const Widget _build_airport_picker_widgets[] = { |
|
198 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
199 |
{ WWT_CAPTION, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
200 |
{ WWT_PANEL, 7, 0, 147, 14, 130, 0x0, STR_NULL}, |
0 | 201 |
{WWT_NODISTXTBTN, 14, 2, 73, 27, 38, STR_3059_SMALL, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
202 |
{WWT_NODISTXTBTN, 14, 74, 145, 27, 38, STR_305A_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
|
203 |
{WWT_NODISTXTBTN, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
|
204 |
{WWT_NODISTXTBTN, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
|
205 |
{WWT_NODISTXTBTN, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
|
206 |
{ WWT_CLOSEBOX, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, |
|
207 |
{ WWT_CLOSEBOX, 14, 74, 133, 88, 98, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
208 |
{ WIDGETS_END}, |
0 | 209 |
}; |
210 |
||
211 |
static const WindowDesc _build_airport_desc = { |
|
212 |
-1, -1, 148, 131, // height, 130+1 |
|
213 |
WC_BUILD_STATION,WC_BUILD_TOOLBAR, |
|
214 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
215 |
_build_airport_picker_widgets, |
|
216 |
BuildAirportPickerWndProc |
|
217 |
}; |
|
218 |
||
219 |
static void ShowBuildAirportPicker() |
|
220 |
{ |
|
221 |
AllocateWindowDesc(&_build_airport_desc); |
|
222 |
} |
|
223 |
||
224 |
void InitializeAirportGui() |
|
225 |
{ |
|
226 |
_selected_airport_type = AT_SMALL; |
|
227 |
_last_built_aircraft_depot_tile = 0; |
|
228 |
} |