author | truelight |
Sun, 06 Feb 2005 10:18:47 +0000 | |
changeset 1313 | bba6afb8a995 |
parent 1116 | a38aed715c95 |
child 1363 | 01d3de5d8039 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
337
diff
changeset
|
3 |
#include "table/strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
606
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "window.h" |
6 |
#include "gui.h" |
|
7 |
#include "viewport.h" |
|
8 |
#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
|
9 |
#include "sound.h" |
0 | 10 |
#include "command.h" |
11 |
#include "vehicle.h" |
|
12 |
#include "station.h" |
|
13 |
#include "airport.h" |
|
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1116
diff
changeset
|
14 |
#include "depot.h" |
0 | 15 |
|
16 |
static byte _selected_airport_type; |
|
17 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1072
diff
changeset
|
18 |
static void ShowBuildAirportPicker(void); |
0 | 19 |
|
20 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
21 |
void CcBuildAirport(bool success, uint tile, uint32 p1, uint32 p2) |
0 | 22 |
{ |
23 |
if (success) { |
|
541 | 24 |
SndPlayTileFx(SND_1F_SPLAT, tile); |
0 | 25 |
ResetObjectToPlace(); |
26 |
} |
|
27 |
} |
|
28 |
||
29 |
static void PlaceAirport(uint tile) |
|
30 |
{ |
|
31 |
DoCommandP(tile, _selected_airport_type, 0, CcBuildAirport, CMD_BUILD_AIRPORT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_A001_CAN_T_BUILD_AIRPORT_HERE)); |
|
32 |
} |
|
33 |
||
34 |
static void PlaceAir_DemolishArea(uint tile) |
|
35 |
{ |
|
36 |
VpStartPlaceSizing(tile, 4); |
|
37 |
} |
|
38 |
||
39 |
||
40 |
static void BuildAirClick_Airport(Window *w) |
|
41 |
{ |
|
756
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
42 |
if (HandlePlacePushButton(w, 3, 0xAA4, 1, PlaceAirport)) ShowBuildAirportPicker(); |
0 | 43 |
} |
44 |
||
45 |
static void BuildAirClick_Demolish(Window *w) |
|
46 |
{ |
|
756
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
47 |
HandlePlacePushButton(w, 4, ANIMCURSOR_DEMOLISH, 1, PlaceAir_DemolishArea); |
0 | 48 |
} |
49 |
||
606
0e507bb0f63a
(svn r1030) Some toolbar icons are arranged differently:
dominik
parents:
568
diff
changeset
|
50 |
static void BuildAirClick_Landscaping(Window *w) |
0 | 51 |
{ |
606
0e507bb0f63a
(svn r1030) Some toolbar icons are arranged differently:
dominik
parents:
568
diff
changeset
|
52 |
ShowTerraformToolbar(); |
0 | 53 |
} |
54 |
||
55 |
typedef void OnButtonClick(Window *w); |
|
56 |
static OnButtonClick * const _build_air_button_proc[] = { |
|
57 |
BuildAirClick_Airport, |
|
58 |
BuildAirClick_Demolish, |
|
606
0e507bb0f63a
(svn r1030) Some toolbar icons are arranged differently:
dominik
parents:
568
diff
changeset
|
59 |
BuildAirClick_Landscaping, |
0 | 60 |
}; |
61 |
||
62 |
static void BuildAirToolbWndProc(Window *w, WindowEvent *e) |
|
63 |
{ |
|
64 |
switch(e->event) { |
|
65 |
case WE_PAINT: |
|
66 |
DrawWindowWidgets(w); |
|
67 |
break; |
|
68 |
||
69 |
case WE_CLICK: |
|
756
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
70 |
if (e->click.widget - 3 >= 0) |
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
71 |
_build_air_button_proc[e->click.widget - 3](w); |
0 | 72 |
break; |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
946
diff
changeset
|
73 |
|
937
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
74 |
case WE_KEYPRESS: { |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
75 |
switch (e->keypress.keycode) { |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
76 |
case '1': BuildAirClick_Airport(w); break; |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
77 |
case '2': BuildAirClick_Demolish(w); break; |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
78 |
case 'l': BuildAirClick_Landscaping(w); break; |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
79 |
default: |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
80 |
return; |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
81 |
} |
a8dfd3eb406f
(svn r1425) Added hotkeys for dock and airport toolbar
celestar
parents:
867
diff
changeset
|
82 |
} break; |
0 | 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: |
|
756
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
100 |
UnclickWindowButtons(w); |
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[] = { |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
110 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
111 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 73, 0, 13, STR_A000_AIRPORTS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
112 |
{ WWT_STICKYBOX, RESIZE_NONE, 7, 74, 85, 0, 13, 0x0, STR_STICKY_BUTTON}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
113 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 41, 14, 35, 0x2E8, STR_A01E_BUILD_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
114 |
{ WWT_PANEL, RESIZE_NONE, 7, 42, 63, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
115 |
{ WWT_PANEL, RESIZE_NONE, 7, 64, 85, 14, 35, SPR_IMG_LANDSCAPING, STR_LANDSCAPING_TOOLBAR_TIP}, |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
116 |
{ WIDGETS_END}, |
0 | 117 |
}; |
118 |
||
119 |
||
120 |
static const WindowDesc _air_toolbar_desc = { |
|
606
0e507bb0f63a
(svn r1030) Some toolbar icons are arranged differently:
dominik
parents:
568
diff
changeset
|
121 |
640-86, 22, 86, 36, |
0 | 122 |
WC_BUILD_TOOLBAR,0, |
756
d1f1dc31b6f4
(svn r1212) -Feature: sticky windows all build-toolbars
darkvater
parents:
751
diff
changeset
|
123 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON, |
0 | 124 |
_air_toolbar_widgets, |
125 |
BuildAirToolbWndProc |
|
126 |
}; |
|
127 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1072
diff
changeset
|
128 |
void ShowBuildAirToolbar(void) |
0 | 129 |
{ |
946
81cf624bbdc5
(svn r1435) Fix: [ 1094092 ] Toolbars accessible via keyboard in spectator mode
dominik
parents:
937
diff
changeset
|
130 |
if (_current_player == OWNER_SPECTATOR) return; |
0 | 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; |
|
792
d8a4164fdb14
(svn r1262) -Fix: [1088996] kill some warnings for MinGW (luzi82)
darkvater
parents:
787
diff
changeset
|
140 |
int rad = 4; // default catchment radious |
0 | 141 |
|
142 |
if (WP(w,def_d).close) |
|
143 |
return; |
|
144 |
w->disabled_state = 0; |
|
145 |
||
146 |
sel = _selected_airport_type; |
|
147 |
// FIXME -- BuildAirportPickerWndProc - set availability of airports by year, instead of airplane |
|
148 |
if (!(_avail_aircraft & 1)) { w->disabled_state |= (1<<3); if (sel == AT_SMALL) sel = AT_LARGE; } |
|
149 |
if (!(_avail_aircraft & 2)) { w->disabled_state |= (1<<4); if (sel == AT_LARGE) sel = AT_SMALL; } |
|
150 |
if (!(_avail_aircraft & 4)) { w->disabled_state |= (1<<5); } // heliport |
|
151 |
// 1980-1-1 is --> 21915 |
|
152 |
// 1990-1-1 is --> 25568 |
|
153 |
if (_date < 21915) {w->disabled_state |= (1<<6);} // metropilitan airport 1980 |
|
154 |
if (_date < 25568) {w->disabled_state |= (1<<7);} // international airport 1990 |
|
155 |
_selected_airport_type = sel; |
|
156 |
// select default the coverage area to 'Off' (8) |
|
157 |
w->click_state = ((1<<3) << sel) | ((1<<8) << _station_show_coverage); |
|
158 |
SetTileSelectSize(_airport_size_x[sel],_airport_size_y[sel]); |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
159 |
|
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
160 |
if (_patches.modified_catchment) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
161 |
switch (sel) { |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
162 |
case AT_OILRIG: rad = CA_AIR_OILPAD; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
163 |
case AT_HELIPORT: rad = CA_AIR_HELIPORT; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
164 |
case AT_SMALL: rad = CA_AIR_SMALL; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
165 |
case AT_LARGE: rad = CA_AIR_LARGE; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
166 |
case AT_METROPOLITAN: rad = CA_AIR_METRO; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
167 |
case AT_INTERNATIONAL: rad = CA_AIR_INTER; break; |
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
168 |
} |
792
d8a4164fdb14
(svn r1262) -Fix: [1088996] kill some warnings for MinGW (luzi82)
darkvater
parents:
787
diff
changeset
|
169 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
170 |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
171 |
if (_station_show_coverage) SetTileSelectBigSize(-rad, -rad, 2 * rad, 2 * rad); |
0 | 172 |
|
173 |
DrawWindowWidgets(w); |
|
174 |
// strings such as 'Size' and 'Coverage Area' |
|
175 |
DrawStringCentered(74, 16, STR_305B_SIZE, 0); |
|
176 |
DrawStringCentered(74, 78, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0); |
|
568
6eb7d394fb35
(svn r979) Allow more realistically sized catchment areas
Celestar
parents:
543
diff
changeset
|
177 |
DrawStationCoverageAreaText(2, 104, (uint)-1, rad); |
0 | 178 |
break; |
179 |
} |
|
180 |
||
181 |
case WE_CLICK: { |
|
182 |
switch(e->click.widget) { |
|
183 |
case 3: case 4: case 5: case 6: case 7: |
|
184 |
_selected_airport_type = e->click.widget - 3; |
|
541 | 185 |
SndPlayFx(SND_15_BEEP); |
0 | 186 |
SetWindowDirty(w); |
187 |
break; |
|
188 |
case 8: case 9: |
|
189 |
_station_show_coverage = e->click.widget - 8; |
|
541 | 190 |
SndPlayFx(SND_15_BEEP); |
0 | 191 |
SetWindowDirty(w); |
192 |
break; |
|
193 |
} |
|
194 |
} break; |
|
195 |
||
196 |
case WE_MOUSELOOP: { |
|
197 |
if (WP(w,def_d).close) { |
|
198 |
DeleteWindow(w); |
|
199 |
return; |
|
200 |
} |
|
201 |
||
202 |
CheckRedrawStationCoverage(w); |
|
203 |
} break; |
|
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1093
diff
changeset
|
204 |
|
1072
01bf9fc64236
(svn r1573) -Fix: Station and depot building mode is now terminated if the
celestar
parents:
1019
diff
changeset
|
205 |
case WE_DESTROY: |
1116
a38aed715c95
(svn r1617) -Fix: Ugly hack to only call ResetObjectToPlaceon childwindows of build-toolbar if the window is closed manually (with 'X'); if not checked ResetObjectToPlace is called twice resulting in undesired actions (eg. clicked button is unclicked immediately).
darkvater
parents:
1109
diff
changeset
|
206 |
if (!WP(w,def_d).close) |
a38aed715c95
(svn r1617) -Fix: Ugly hack to only call ResetObjectToPlaceon childwindows of build-toolbar if the window is closed manually (with 'X'); if not checked ResetObjectToPlace is called twice resulting in undesired actions (eg. clicked button is unclicked immediately).
darkvater
parents:
1109
diff
changeset
|
207 |
ResetObjectToPlace(); |
1072
01bf9fc64236
(svn r1573) -Fix: Station and depot building mode is now terminated if the
celestar
parents:
1019
diff
changeset
|
208 |
break; |
0 | 209 |
} |
210 |
} |
|
211 |
||
212 |
static const Widget _build_airport_picker_widgets[] = { |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
213 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
214 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 147, 0, 13, STR_3001_AIRPORT_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
215 |
{ WWT_PANEL, RESIZE_NONE, 7, 0, 147, 14, 130, 0x0, STR_NULL}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
216 |
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 73, 27, 38, STR_3059_SMALL, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
217 |
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 74, 145, 27, 38, STR_305A_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
218 |
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 63, 74, STR_306B_HELIPORT, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
219 |
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 39, 50, STR_305AA_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
220 |
{WWT_NODISTXTBTN, RESIZE_NONE, 14, 2, 145, 51, 62, STR_305AB_LARGE, STR_3058_SELECT_SIZE_TYPE_OF_AIRPORT}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
221 |
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 14, 73, 88, 98, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE}, |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
792
diff
changeset
|
222 |
{ WWT_CLOSEBOX, RESIZE_NONE, 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
|
223 |
{ WIDGETS_END}, |
0 | 224 |
}; |
225 |
||
226 |
static const WindowDesc _build_airport_desc = { |
|
227 |
-1, -1, 148, 131, // height, 130+1 |
|
228 |
WC_BUILD_STATION,WC_BUILD_TOOLBAR, |
|
229 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
230 |
_build_airport_picker_widgets, |
|
231 |
BuildAirportPickerWndProc |
|
232 |
}; |
|
233 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1072
diff
changeset
|
234 |
static void ShowBuildAirportPicker(void) |
0 | 235 |
{ |
236 |
AllocateWindowDesc(&_build_airport_desc); |
|
237 |
} |
|
238 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1072
diff
changeset
|
239 |
void InitializeAirportGui(void) |
0 | 240 |
{ |
241 |
_selected_airport_type = AT_SMALL; |
|
242 |
_last_built_aircraft_depot_tile = 0; |
|
243 |
} |