author | truelight |
Tue, 17 Aug 2004 08:40:09 +0000 | |
changeset 71 | 1b8e15a10515 |
parent 70 | 60216d94f7c1 |
child 74 | d23a80ef6361 |
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" |
|
8 |
#include "station.h" |
|
9 |
#include "command.h" |
|
10 |
#include "player.h" |
|
11 |
#include "town.h" |
|
12 |
||
13 |
#include "hal.h" // Fios items |
|
14 |
||
15 |
bool _query_string_active; |
|
16 |
static void SetFiosType(const byte fiostype); |
|
17 |
||
18 |
typedef struct LandInfoData { |
|
19 |
Town *town; |
|
20 |
int32 costclear; |
|
21 |
AcceptedCargo ac; |
|
22 |
uint tile; |
|
23 |
TileDesc td; |
|
24 |
} LandInfoData; |
|
25 |
||
26 |
||
27 |
static void LandInfoWndProc(Window *w, WindowEvent *e) |
|
28 |
{ |
|
29 |
LandInfoData *lid; |
|
30 |
StringID str; |
|
31 |
uint32 *b; |
|
32 |
||
33 |
if (e->event == WE_PAINT) { |
|
34 |
DrawWindowWidgets(w); |
|
35 |
||
36 |
lid = WP(w,void_d).data; |
|
37 |
||
38 |
SET_DPARAM32(0, lid->td.dparam[0]); |
|
39 |
DrawStringCentered(140, 16, lid->td.str, 13); |
|
40 |
||
41 |
SET_DPARAM16(0, STR_01A6_N_A); |
|
42 |
if (lid->td.owner != OWNER_NONE && lid->td.owner != OWNER_WATER) |
|
43 |
GetNameOfOwner(lid->td.owner, lid->tile); |
|
44 |
DrawStringCentered(140, 27, STR_01A7_OWNER, 0); |
|
45 |
||
46 |
str = STR_01A4_COST_TO_CLEAR_N_A; |
|
47 |
if (lid->costclear != CMD_ERROR) { |
|
48 |
SET_DPARAM32(0, lid->costclear); |
|
49 |
str = STR_01A5_COST_TO_CLEAR; |
|
50 |
} |
|
51 |
DrawStringCentered(140, 38, str, 0); |
|
52 |
||
53 |
sprintf(_userstring, "%.4X", lid->tile); |
|
54 |
SET_DPARAM16(0, GET_TILE_X(lid->tile)); |
|
55 |
SET_DPARAM16(1, GET_TILE_Y(lid->tile)); |
|
56 |
SET_DPARAM16(2, STR_SPEC_USERSTRING); |
|
57 |
DrawStringCentered(140, 49, STR_LANDINFO_COORDS, 0); |
|
58 |
||
59 |
SET_DPARAM16(0, STR_01A9_NONE); |
|
60 |
if (lid->town != NULL) { |
|
61 |
SET_DPARAM16(0, lid->town->townnametype); |
|
62 |
SET_DPARAM32(1, lid->town->townnameparts); |
|
63 |
} |
|
64 |
DrawStringCentered(140,60, STR_01A8_LOCAL_AUTHORITY, 0); |
|
65 |
||
66 |
b = &GET_DPARAM(0); |
|
67 |
||
68 |
str = STR_01CE_CARGO_ACCEPTED - 1; |
|
69 |
||
70 |
if (lid->ac.amount_1 != 0) { |
|
71 |
if (lid->ac.amount_1 < 8) { |
|
72 |
SET_DPARAMX16(b, 0, STR_01D1_8); |
|
73 |
SET_DPARAMX8(b, 1, lid->ac.amount_1); |
|
74 |
b += 2; |
|
75 |
} |
|
76 |
SET_DPARAMX16(b, 0, _cargoc.names_s[lid->ac.type_1]); |
|
77 |
b++; |
|
78 |
str++; |
|
79 |
} |
|
80 |
||
81 |
if (lid->ac.amount_2 != 0) { |
|
82 |
if (lid->ac.amount_2 < 8) { |
|
83 |
SET_DPARAMX16(b, 0, STR_01D1_8); |
|
84 |
SET_DPARAMX8(b, 1, lid->ac.amount_2); |
|
85 |
b += 2; |
|
86 |
} |
|
87 |
SET_DPARAMX16(b, 0, _cargoc.names_s[lid->ac.type_2]); |
|
88 |
b++; |
|
89 |
str++; |
|
90 |
} |
|
91 |
||
92 |
if (lid->ac.amount_3 != 0) { |
|
93 |
if (lid->ac.amount_3 < 8) { |
|
94 |
SET_DPARAMX16(b, 0, STR_01D1_8); |
|
95 |
SET_DPARAMX8(b, 1, lid->ac.amount_3); |
|
96 |
b += 2; |
|
97 |
} |
|
98 |
SET_DPARAMX16(b, 0, _cargoc.names_s[lid->ac.type_3]); |
|
99 |
b++; |
|
100 |
str++; |
|
101 |
} |
|
102 |
||
103 |
if (str != (STR_01CE_CARGO_ACCEPTED - 1)) |
|
104 |
DrawStringMultiCenter(140, 76, str, 276); |
|
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
105 |
|
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
106 |
if (lid->td.build_date != 0) { |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
107 |
SET_DPARAM16(0,lid->td.build_date); |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
108 |
DrawStringCentered(140,71, STR_BUILD_DATE, 0); |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
109 |
} |
0 | 110 |
} |
111 |
} |
|
112 |
||
113 |
static const Widget _land_info_widgets[] = { |
|
114 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
115 |
{ WWT_CAPTION, 14, 11, 279, 0, 13, STR_01A3_LAND_AREA_INFORMATION, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
116 |
{ WWT_IMGBTN, 14, 0, 279, 14, 92, 0x0, 0}, |
|
117 |
{ WWT_LAST}, |
|
118 |
}; |
|
119 |
||
120 |
static const WindowDesc _land_info_desc = { |
|
121 |
-1, -1, 280, 93, |
|
122 |
WC_LAND_INFO,0, |
|
123 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
124 |
_land_info_widgets, |
|
125 |
LandInfoWndProc |
|
126 |
}; |
|
127 |
||
128 |
static void Place_LandInfo(uint tile) |
|
129 |
{ |
|
130 |
Player *p; |
|
131 |
static LandInfoData lid; |
|
132 |
Window *w; |
|
133 |
int64 old_money; |
|
134 |
||
135 |
DeleteWindowById(WC_LAND_INFO, 0); |
|
136 |
||
137 |
w = AllocateWindowDesc(&_land_info_desc); |
|
138 |
WP(w,void_d).data = &lid; |
|
139 |
||
140 |
lid.tile = tile; |
|
141 |
lid.town = ClosestTownFromTile(tile, _patches.dist_local_authority); |
|
142 |
||
3
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
143 |
if (_local_player >= MAX_PLAYERS) |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
144 |
p = DEREF_PLAYER(0); |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
145 |
else |
0 | 146 |
p = DEREF_PLAYER(_local_player); |
3
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
147 |
|
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
148 |
old_money = p->money64; |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
149 |
p->money64 = p->player_money = 0x7fffffff; |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
150 |
lid.costclear = DoCommandByTile(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR); |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
151 |
p->money64 = old_money; |
27d9e9fa999a
(svn r4) -Fix [996025] _local_player fixes. Fixes wrong memory access (TrueLight)
darkvater
parents:
0
diff
changeset
|
152 |
UpdatePlayerMoney32(p); |
71
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
153 |
|
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
154 |
// Becuase build_date is not set yet in every TileDesc, we make sure it is empty |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
155 |
lid.td.build_date = 0; |
1b8e15a10515
(svn r72) -Add: build_date of station (viewable with Query tool)
truelight
parents:
70
diff
changeset
|
156 |
|
0 | 157 |
GetAcceptedCargo(tile, &lid.ac); |
158 |
GetTileDesc(tile, &lid.td); |
|
159 |
||
65
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
160 |
#if defined(_DEBUG) |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
161 |
DEBUG(misc, 0) ("TILE: %#x (%i,%i)", tile, GET_TILE_X(tile), GET_TILE_Y(tile)); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
162 |
DEBUG(misc, 0) ("_map_type_and_height=%#x", _map_type_and_height[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
163 |
DEBUG(misc, 0) ("_map2=%#x", _map2[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
164 |
DEBUG(misc, 0) ("_map3_lo=%#x", _map3_lo[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
165 |
DEBUG(misc, 0) ("_map3_hi=%#x", _map3_hi[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
166 |
DEBUG(misc, 0) ("_map5=%#x", _map5[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
167 |
DEBUG(misc, 0) ("_map_owner=%#x", _map_owner[tile]); |
f9f866bc609c
(svn r66) -Fix Station list updated on station deletion/station rename
darkvater
parents:
3
diff
changeset
|
168 |
#endif |
0 | 169 |
} |
170 |
||
171 |
void PlaceLandBlockInfo() |
|
172 |
{ |
|
173 |
if (_cursor.sprite == 0x2CF) { |
|
174 |
ResetObjectToPlace(); |
|
175 |
} else { |
|
176 |
_place_proc = Place_LandInfo; |
|
177 |
SetObjectToPlace(0x2CF, 1, 1, 0); |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
||
182 |
static void AboutWindowProc(Window *w, WindowEvent *e) |
|
183 |
{ |
|
184 |
switch(e->event) { |
|
185 |
case WE_PAINT: { |
|
186 |
int x,y; |
|
187 |
DrawWindowWidgets(w); |
|
188 |
||
189 |
x = 200; |
|
190 |
y = 0; |
|
191 |
DrawStringCentered(x, y+=17, STR_00B6_COPYRIGHT_1995_CHRIS_SAWYER, 0); |
|
192 |
DrawStringCentered(x, y+=10, STR_00B7_VERSION_3_02_011_11TH_OCTOBER, 0); |
|
193 |
DrawStringCentered(x, y+=15, STR_00B8_DESIGNED_PROGRAMMED_BY, 0); |
|
194 |
DrawStringCentered(x, y+=10, STR_00B9_GRAPHICS_BY_SIMON_FOSTER, 0); |
|
195 |
DrawStringMultiCenter(x, y+0x73, STR_00BA_WINDOWS_95_CONVERSION_BY, 0x18E); |
|
196 |
break; |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
static const Widget _about_widgets[] = { |
|
202 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5}, |
|
203 |
{ WWT_CAPTION, 14, 11, 399, 0, 13, STR_015B_TRANSPORT_TYCOON_DELUXE}, |
|
204 |
{ WWT_PANEL, 14, 0, 399, 14, 271, 0x0}, |
|
205 |
{ WWT_LAST}, |
|
206 |
}; |
|
207 |
||
208 |
static const WindowDesc _about_desc = { |
|
209 |
WDP_CENTER, WDP_CENTER, 400, 272, |
|
210 |
WC_GAME_OPTIONS,0, |
|
211 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
212 |
_about_widgets, |
|
213 |
AboutWindowProc |
|
214 |
}; |
|
215 |
||
216 |
||
217 |
void ShowAboutWindow() |
|
218 |
{ |
|
219 |
DeleteWindowById(WC_GAME_OPTIONS, 0); |
|
220 |
AllocateWindowDesc(&_about_desc); |
|
221 |
} |
|
222 |
||
223 |
static int _tree_to_plant; |
|
224 |
||
225 |
static const byte _tree_base_by_landscape[4] = {0, 12, 20, 32}; |
|
226 |
static const byte _tree_count_by_landscape[4] = {12, 8, 12, 9}; |
|
227 |
static const uint32 _tree_sprites[] = { |
|
228 |
0x655,0x663,0x678,0x62B,0x647,0x639,0x64E,0x632,0x67F,0x68D,0x69B,0x6A9, |
|
229 |
0x6AF,0x6D2,0x6D9,0x6C4,0x6CB,0x6B6,0x6BD,0x6E0, |
|
230 |
0x72E,0x734,0x74A,0x74F,0x76B,0x78F,0x788,0x77B,0x75F,0x774,0x720,0x797, |
|
231 |
0x79E,0x30D87A5,0x30B87AC,0x7B3,0x7BA,0x30B87C1,0x30887C8,0x30A87CF,0x30B87D6 |
|
232 |
}; |
|
233 |
||
234 |
static void BuildTreesWndProc(Window *w, WindowEvent *e) |
|
235 |
{ |
|
236 |
switch(e->event) { |
|
237 |
case WE_PAINT: { |
|
238 |
int x,y; |
|
239 |
int i, count; |
|
240 |
||
241 |
DrawWindowWidgets(w); |
|
242 |
||
243 |
WP(w,tree_d).base = i = _tree_base_by_landscape[_opt.landscape]; |
|
244 |
WP(w,tree_d).count = count = _tree_count_by_landscape[_opt.landscape]; |
|
245 |
||
246 |
x = 18; |
|
247 |
y = 54; |
|
248 |
do { |
|
249 |
DrawSprite(_tree_sprites[i], x, y); |
|
250 |
x += 35; |
|
251 |
if (!(++i & 3)) { |
|
252 |
x -= 35*4; |
|
253 |
y += 47; |
|
254 |
} |
|
255 |
} while (--count); |
|
256 |
} break; |
|
257 |
||
258 |
case WE_CLICK: { |
|
259 |
int wid; |
|
260 |
||
261 |
switch(wid=e->click.widget) { |
|
262 |
case 0: |
|
263 |
ResetObjectToPlace(); |
|
264 |
return; |
|
265 |
case 3: case 4: case 5: case 6: |
|
266 |
case 7: case 8: case 9: case 10: |
|
267 |
case 11:case 12: case 13: case 14: |
|
268 |
if ( (uint)(wid-3) >= (uint)WP(w,tree_d).count) |
|
269 |
return; |
|
270 |
||
271 |
if (HandlePlacePushButton(w, wid, 0x7DA, 1, NULL)) |
|
272 |
_tree_to_plant = WP(w,tree_d).base + wid - 3; |
|
273 |
break; |
|
274 |
||
275 |
case 15: // tree of random type. |
|
276 |
if (HandlePlacePushButton(w, 15, 0x7DA, 1, NULL)) |
|
277 |
_tree_to_plant = -1; |
|
278 |
break; |
|
279 |
||
280 |
case 16: /* place trees randomly over the landscape*/ |
|
281 |
w->click_state |= 1 << 16; |
|
282 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
283 |
SndPlayFx(0x13); |
|
284 |
PlaceTreesRandomly(); |
|
285 |
MarkWholeScreenDirty(); |
|
286 |
break; |
|
287 |
} |
|
288 |
} break; |
|
289 |
||
290 |
case WE_PLACE_OBJ: |
|
291 |
VpStartPlaceSizing(e->place.tile, VPM_X_AND_Y_LIMITED); |
|
292 |
VpSetPlaceSizingLimit(20); |
|
293 |
break; |
|
294 |
||
295 |
case WE_PLACE_DRAG: |
|
296 |
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata); |
|
297 |
return; |
|
298 |
||
299 |
case WE_PLACE_MOUSEUP: |
|
300 |
if (e->click.pt.x != -1) { |
|
301 |
DoCommandP(e->place.tile, _tree_to_plant, e->place.starttile, NULL, |
|
302 |
CMD_PLANT_TREE | CMD_AUTO | CMD_MSG(STR_2805_CAN_T_PLANT_TREE_HERE)); |
|
303 |
} |
|
304 |
break; |
|
305 |
||
306 |
case WE_TIMEOUT: |
|
307 |
UnclickSomeWindowButtons(w, 1<<16); |
|
308 |
break; |
|
309 |
||
310 |
case WE_ABORT_PLACE_OBJ: |
|
311 |
w->click_state = 0; |
|
312 |
SetWindowDirty(w); |
|
313 |
break; |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
static const Widget _build_trees_widgets[] = { |
|
318 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
319 |
{ WWT_CAPTION, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
320 |
{ WWT_PANEL, 7, 0, 142, 14, 170, 0x0, 0}, |
|
321 |
{ WWT_PANEL, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
322 |
{ WWT_PANEL, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
323 |
{ WWT_PANEL, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
324 |
{ WWT_PANEL, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
325 |
{ WWT_PANEL, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
326 |
{ WWT_PANEL, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
327 |
{ WWT_PANEL, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
328 |
{ WWT_PANEL, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
329 |
{ WWT_PANEL, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
330 |
{ WWT_PANEL, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
331 |
{ WWT_PANEL, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
332 |
{ WWT_PANEL, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
333 |
{ WWT_CLOSEBOX, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, |
|
334 |
{ WWT_LAST}, |
|
335 |
}; |
|
336 |
||
337 |
static const WindowDesc _build_trees_desc = { |
|
338 |
497, 22, 143, 171, |
|
339 |
WC_BUILD_TOOLBAR,0, |
|
340 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
341 |
_build_trees_widgets, |
|
342 |
BuildTreesWndProc |
|
343 |
}; |
|
344 |
||
345 |
static const Widget _build_trees_scen_widgets[] = { |
|
346 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
347 |
{ WWT_CAPTION, 7, 11, 142, 0, 13, STR_2802_TREES, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
348 |
{ WWT_PANEL, 7, 0, 142, 14, 183, 0x0, 0}, |
|
349 |
{ WWT_PANEL, 14, 2, 35, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
350 |
{ WWT_PANEL, 14, 37, 70, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
351 |
{ WWT_PANEL, 14, 72, 105, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
352 |
{ WWT_PANEL, 14, 107, 140, 16, 61, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
353 |
{ WWT_PANEL, 14, 2, 35, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
354 |
{ WWT_PANEL, 14, 37, 70, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
355 |
{ WWT_PANEL, 14, 72, 105, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
356 |
{ WWT_PANEL, 14, 107, 140, 63, 108, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
357 |
{ WWT_PANEL, 14, 2, 35, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
358 |
{ WWT_PANEL, 14, 37, 70, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
359 |
{ WWT_PANEL, 14, 72, 105, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
360 |
{ WWT_PANEL, 14, 107, 140, 110, 155, 0x0, STR_280D_SELECT_TREE_TYPE_TO_PLANT}, |
|
361 |
{ WWT_CLOSEBOX, 14, 2, 140, 157, 168, STR_TREES_RANDOM_TYPE, STR_TREES_RANDOM_TYPE_TIP}, |
|
362 |
{ WWT_CLOSEBOX, 14, 2, 140, 170, 181, STR_028A_RANDOM_TREES,STR_028B_PLANT_TREES_RANDOMLY_OVER}, |
|
363 |
{ WWT_LAST}, |
|
364 |
}; |
|
365 |
||
366 |
static const WindowDesc _build_trees_scen_desc = { |
|
367 |
-1, -1, 143, 184, |
|
368 |
WC_SCEN_BUILD_TREES,0, |
|
369 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
370 |
_build_trees_scen_widgets, |
|
371 |
BuildTreesWndProc |
|
372 |
}; |
|
373 |
||
374 |
||
375 |
void ShowBuildTreesToolbar() |
|
376 |
{ |
|
377 |
DeleteWindowById(WC_BUILD_TOOLBAR, 0); |
|
378 |
AllocateWindowDesc(&_build_trees_desc); |
|
379 |
} |
|
380 |
||
381 |
void ShowBuildTreesScenToolbar() |
|
382 |
{ |
|
383 |
AllocateWindowDescFront(&_build_trees_scen_desc, 0); |
|
384 |
} |
|
385 |
||
386 |
static uint32 _errmsg_decode_params[10]; |
|
387 |
static StringID _errmsg_message_1, _errmsg_message_2; |
|
388 |
static uint _errmsg_duration; |
|
389 |
||
390 |
||
391 |
static const Widget _errmsg_widgets[] = { |
|
392 |
{ WWT_CLOSEBOX, 4, 0, 10, 0, 13, STR_00C5}, |
|
393 |
{ WWT_CAPTION, 4, 11, 239, 0, 13, STR_00B2_MESSAGE}, |
|
394 |
{ WWT_PANEL, 4, 0, 239, 14, 45, 0x0}, |
|
395 |
{ WWT_LAST}, |
|
396 |
}; |
|
397 |
||
398 |
static const Widget _errmsg_face_widgets[] = { |
|
399 |
{ WWT_CLOSEBOX, 4, 0, 10, 0, 13, STR_00C5}, |
|
400 |
{ WWT_CAPTION, 4, 11, 333, 0, 13, STR_00B3_MESSAGE_FROM}, |
|
401 |
{ WWT_PANEL, 4, 0, 333, 14, 136, 0x0}, |
|
402 |
{ WWT_LAST}, |
|
403 |
}; |
|
404 |
||
405 |
static void ErrmsgWndProc(Window *w, WindowEvent *e) |
|
406 |
{ |
|
407 |
switch(e->event) { |
|
408 |
case WE_PAINT: |
|
409 |
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); |
|
410 |
DrawWindowWidgets(w); |
|
411 |
COPY_IN_DPARAM(0, _errmsg_decode_params, lengthof(_errmsg_decode_params)); |
|
412 |
if (w->widget != _errmsg_face_widgets) { |
|
413 |
DrawStringMultiCenter( |
|
414 |
120, |
|
415 |
(_errmsg_message_1 == INVALID_STRING_ID ? 25 : 15), |
|
416 |
_errmsg_message_2, |
|
417 |
238); |
|
418 |
if (_errmsg_message_1 != INVALID_STRING_ID) |
|
419 |
DrawStringMultiCenter( |
|
420 |
120, |
|
421 |
30, |
|
422 |
_errmsg_message_1, |
|
423 |
238); |
|
424 |
} else { |
|
425 |
Player *p = DEREF_PLAYER(_errmsg_decode_params[2]); |
|
426 |
DrawPlayerFace(p->face, p->player_color, 2, 16); |
|
427 |
||
428 |
DrawStringMultiCenter( |
|
429 |
214, |
|
430 |
(_errmsg_message_1 == INVALID_STRING_ID ? 65 : 45), |
|
431 |
_errmsg_message_2, |
|
432 |
238); |
|
433 |
if (_errmsg_message_1 != INVALID_STRING_ID) |
|
434 |
DrawStringMultiCenter( |
|
435 |
214, |
|
436 |
90, |
|
437 |
_errmsg_message_1, |
|
438 |
238); |
|
439 |
} |
|
440 |
break; |
|
441 |
||
442 |
case WE_MOUSELOOP: |
|
443 |
if (_right_button_down) |
|
444 |
DeleteWindow(w); |
|
445 |
break; |
|
446 |
case WE_4: |
|
447 |
if (!--_errmsg_duration) |
|
448 |
DeleteWindow(w); |
|
449 |
break; |
|
450 |
case WE_DESTROY: { |
|
451 |
TileHighlightData *thd = _thd_ptr; |
|
452 |
TileIndex tile = thd->redsq; |
|
453 |
thd->redsq = 0; |
|
454 |
if (tile != 0) |
|
455 |
MarkTileDirtyByTile(tile); |
|
456 |
break; |
|
457 |
} |
|
458 |
||
459 |
case WE_KEYPRESS: |
|
460 |
if (e->keypress.keycode == WKC_SPACE) { |
|
461 |
// Don't continue. |
|
462 |
e->keypress.cont = false; |
|
463 |
DeleteWindow(w); |
|
464 |
} |
|
465 |
break; |
|
466 |
} |
|
467 |
} |
|
468 |
||
469 |
void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y) |
|
470 |
{ |
|
471 |
Window *w; |
|
472 |
ViewPort *vp; |
|
473 |
Point pt; |
|
474 |
||
475 |
DeleteWindowById(WC_ERRMSG, 0); |
|
476 |
||
477 |
//assert(msg_2); |
|
478 |
if (msg_2 == 0) msg_2 = STR_EMPTY; |
|
479 |
||
480 |
_errmsg_message_1 = msg_1; |
|
481 |
_errmsg_message_2 = msg_2; |
|
482 |
COPY_OUT_DPARAM(_errmsg_decode_params, 0, lengthof(_errmsg_decode_params)); |
|
483 |
_errmsg_duration = _patches.errmsg_duration; |
|
484 |
if (!_errmsg_duration) |
|
485 |
return; |
|
486 |
||
487 |
if (_errmsg_message_1 != STR_013B_OWNED_BY || GET_DPARAMX8(_errmsg_decode_params,2) >= 8) { |
|
488 |
||
489 |
if ( (x|y) != 0) { |
|
490 |
pt = RemapCoords2(x, y); |
|
491 |
for(w=_windows; w->window_class != WC_MAIN_WINDOW; w++) {} |
|
492 |
vp = w->viewport; |
|
493 |
||
494 |
// move x pos to opposite corner |
|
495 |
pt.x = ((pt.x - vp->virtual_left) >> vp->zoom) + vp->left; |
|
496 |
pt.x = (pt.x < (_screen.width >> 1)) ? _screen.width - 260 : 20; |
|
497 |
||
498 |
// move y pos to opposite corner |
|
499 |
pt.y = ((pt.y - vp->virtual_top) >> vp->zoom) + vp->top; |
|
500 |
pt.y = (pt.y < (_screen.height >> 1)) ? _screen.height - 80 : 100; |
|
501 |
||
502 |
} else { |
|
503 |
pt.x = (_screen.width - 240) >> 1; |
|
504 |
pt.y = (_screen.height - 46) >> 1; |
|
505 |
} |
|
506 |
w = AllocateWindow(pt.x, pt.y, 240, 46, ErrmsgWndProc, WC_ERRMSG, _errmsg_widgets); |
|
507 |
} else { |
|
508 |
if ( (x|y) != 0) { |
|
509 |
pt = RemapCoords2(x, y); |
|
510 |
for(w=_windows; w->window_class != WC_MAIN_WINDOW; w++) {} |
|
511 |
vp = w->viewport; |
|
512 |
pt.x = clamp(((pt.x - vp->virtual_left) >> vp->zoom) + vp->left - (334/2), 0, _screen.width - 334); |
|
513 |
pt.y = clamp(((pt.y - vp->virtual_top) >> vp->zoom) + vp->top - (137/2), 22, _screen.height - 137); |
|
514 |
} else { |
|
515 |
pt.x = (_screen.width - 334) >> 1; |
|
516 |
pt.y = (_screen.height - 137) >> 1; |
|
517 |
} |
|
518 |
w = AllocateWindow(pt.x, pt.y, 334, 137, ErrmsgWndProc, WC_ERRMSG, _errmsg_face_widgets); |
|
519 |
} |
|
520 |
||
521 |
w->desc_flags = WDF_STD_BTN | WDF_DEF_WIDGET; |
|
522 |
} |
|
523 |
||
524 |
||
525 |
void ShowEstimatedCostOrIncome(int32 cost, int x, int y) |
|
526 |
{ |
|
527 |
int msg = STR_0805_ESTIMATED_COST; |
|
528 |
||
529 |
if (cost < 0) { |
|
530 |
cost = -cost; |
|
531 |
msg = STR_0807_ESTIMATED_INCOME; |
|
532 |
} |
|
533 |
SET_DPARAM32(0, cost); |
|
534 |
ShowErrorMessage(-1, msg, x, y); |
|
535 |
} |
|
536 |
||
537 |
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost) |
|
538 |
{ |
|
539 |
int msg; |
|
540 |
Point pt = RemapCoords(x,y,z); |
|
541 |
||
542 |
msg = STR_0801_COST; |
|
543 |
if (cost < 0) { |
|
544 |
cost = -cost; |
|
545 |
msg = STR_0803_INCOME; |
|
546 |
} |
|
547 |
SET_DPARAM32(0, cost); |
|
548 |
AddTextEffect(msg, pt.x, pt.y, 0x250); |
|
549 |
} |
|
550 |
||
551 |
static Widget _tooltips_widgets[] = { |
|
552 |
{ WWT_PANEL, 14, 0, 199, 0, 31, 0x0}, |
|
553 |
{ WWT_LAST}, |
|
554 |
}; |
|
555 |
||
556 |
||
557 |
static void TooltipsWndProc(Window *w, WindowEvent *e) |
|
558 |
{ |
|
559 |
||
560 |
switch(e->event) { |
|
561 |
case WE_PAINT: { |
|
562 |
GfxFillRect(0, 0, w->width - 1, w->height - 1, 0); |
|
563 |
GfxFillRect(1, 1, w->width - 2, w->height - 2, 0x44); |
|
564 |
DrawStringMultiCenter((w->width>>1), (w->height>>1)-5, WP(w,tooltips_d).string_id, 197); |
|
565 |
break; |
|
566 |
} |
|
567 |
case WE_MOUSELOOP: |
|
568 |
if (!_right_button_down) |
|
569 |
DeleteWindow(w); |
|
570 |
break; |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
void GuiShowTooltips(StringID string_id) |
|
575 |
{ |
|
576 |
Window *w; |
|
577 |
int right,bottom; |
|
578 |
int x,y; |
|
579 |
||
580 |
if (string_id == 0) |
|
581 |
return; |
|
582 |
||
583 |
w = FindWindowById(WC_TOOLTIPS, 0); |
|
584 |
if (w != NULL) { |
|
585 |
if (WP(w,tooltips_d).string_id == string_id) |
|
586 |
return; |
|
587 |
DeleteWindow(w); |
|
588 |
} |
|
589 |
||
590 |
GetString(str_buffr, string_id); |
|
591 |
assert(strlen(str_buffr) < sizeof(str_buffr) - 1); |
|
592 |
||
593 |
right = GetStringWidth(str_buffr) + 4; |
|
594 |
||
595 |
bottom = 14; |
|
596 |
if (right > 200) { |
|
597 |
bottom += ((right - 4) / 176) * 10; |
|
598 |
right = 200; |
|
599 |
} |
|
600 |
||
601 |
_tooltips_widgets[0].right = right; |
|
602 |
_tooltips_widgets[0].bottom = bottom; |
|
603 |
||
604 |
y = _cursor.pos.y + 30; |
|
605 |
if (y < 22) y = 22; |
|
606 |
||
607 |
if (y > (_screen.height - 44) && (y-=52) > (_screen.height - 44)) |
|
608 |
y = (_screen.height - 44); |
|
609 |
||
610 |
x = _cursor.pos.x - (right >> 1); |
|
611 |
if (x < 0) x = 0; |
|
612 |
if (x > (_screen.width - right)) x = _screen.width - right; |
|
613 |
||
614 |
w = AllocateWindow(x, y, right, bottom, TooltipsWndProc, WC_TOOLTIPS, _tooltips_widgets); |
|
615 |
WP(w,tooltips_d).string_id = string_id; |
|
616 |
w->flags4 &= ~WF_WHITE_BORDER_MASK; |
|
617 |
} |
|
618 |
||
619 |
||
620 |
static void DrawStationCoverageText(const uint *accepts, int str_x, int str_y, uint mask) |
|
621 |
{ |
|
622 |
int i; |
|
623 |
byte *b; |
|
624 |
||
625 |
b = _userstring; |
|
626 |
b[0] = 0x81; |
|
627 |
b[1] = STR_000D_ACCEPTS; |
|
628 |
b[2] = STR_000D_ACCEPTS >> 8; |
|
629 |
b += 3; |
|
630 |
||
631 |
for(i=0; i!=NUM_CARGO; i++,mask>>=1) { |
|
632 |
if (accepts[i] >= 8 && (mask&1) ) { |
|
633 |
StringID id = _cargoc.names_s[i]; |
|
634 |
b[0] = 0x81; |
|
635 |
b[1] = (byte)(id & 255); |
|
636 |
b[2] = (byte)(id >> 8); |
|
637 |
b[3] = ','; |
|
638 |
b[4] = ' '; |
|
639 |
b += 5; |
|
640 |
} |
|
641 |
} |
|
642 |
||
643 |
if (b == (byte*)&_userstring[3]) { |
|
644 |
b[0] = 0x81; |
|
645 |
b[1] = STR_00D0_NOTHING; |
|
646 |
b[2] = STR_00D0_NOTHING >> 8; |
|
647 |
b[3] = 0; |
|
648 |
} else { |
|
649 |
b[-2] = 0; |
|
650 |
} |
|
651 |
||
652 |
DrawStringMultiLine(str_x, str_y, STR_SPEC_USERSTRING, 144); |
|
653 |
} |
|
654 |
||
655 |
void DrawStationCoverageAreaText(int sx, int sy, uint mask) { |
|
656 |
int x = _thd.pos.x; |
|
657 |
int y = _thd.pos.y; |
|
658 |
uint accepts[NUM_CARGO]; |
|
659 |
if (x != -1) { |
|
660 |
GetAcceptanceAroundTiles(accepts, TILE_FROM_XY(x,y), _thd.new_size.x >> 4, _thd.new_size.y >> 4); |
|
661 |
DrawStationCoverageText(accepts, sx, sy, mask); |
|
662 |
} |
|
663 |
} |
|
664 |
||
665 |
void CheckRedrawStationCoverage(Window *w) |
|
666 |
{ |
|
667 |
if (_thd.dirty&1) { |
|
668 |
_thd.dirty&=~1; |
|
669 |
SetWindowDirty(w); |
|
670 |
} |
|
671 |
} |
|
672 |
||
673 |
||
674 |
void UnclickSomeWindowButtons(Window *w, uint32 mask) |
|
675 |
{ |
|
676 |
uint32 x = w->click_state & mask; |
|
677 |
int i = 0; |
|
678 |
w->click_state ^= x; |
|
679 |
do { |
|
680 |
if (x&1) InvalidateWidget(w,i); |
|
681 |
} while(i++,x>>=1); |
|
682 |
} |
|
683 |
||
684 |
||
685 |
void UnclickWindowButtons(Window *w) |
|
686 |
{ |
|
687 |
UnclickSomeWindowButtons(w, (uint32)-1); |
|
688 |
} |
|
689 |
||
690 |
||
691 |
void SetVScrollCount(Window *w, int num) |
|
692 |
{ |
|
693 |
w->vscroll.count = num; |
|
694 |
num -= w->vscroll.cap; |
|
695 |
if (num < 0) num = 0; |
|
696 |
if (num < w->vscroll.pos) w->vscroll.pos = num; |
|
697 |
} |
|
698 |
||
699 |
void SetHScrollCount(Window *w, int num) |
|
700 |
{ |
|
701 |
w->hscroll.count = num; |
|
702 |
num -= w->hscroll.cap; |
|
703 |
if (num < 0) num = 0; |
|
704 |
if (num < w->hscroll.pos) w->hscroll.pos = num; |
|
705 |
} |
|
706 |
||
707 |
||
708 |
int HandleEditBoxKey(Window *w, int wid, WindowEvent *we) |
|
709 |
{ |
|
710 |
byte *p; |
|
711 |
int width,count; |
|
712 |
int key = we->keypress.ascii; |
|
713 |
||
714 |
we->keypress.cont = false; |
|
715 |
||
716 |
if (we->keypress.keycode == WKC_ESC) { |
|
717 |
return 2; |
|
718 |
} else if (we->keypress.keycode == WKC_RETURN) { |
|
719 |
return 1; |
|
720 |
} else { |
|
721 |
width = -1; |
|
722 |
p = WP(w,querystr_d).buf - 1; |
|
723 |
count = 0; |
|
724 |
do { |
|
725 |
if (*++p == 0) |
|
726 |
break; |
|
727 |
count++; |
|
728 |
width += _stringwidth_table[*p - 32]; |
|
729 |
} while (1); |
|
730 |
||
731 |
if (we->keypress.keycode == WKC_BACKSPACE) { |
|
732 |
if (count != 0) { |
|
733 |
WP(w,querystr_d).buf[count-1] = 0; |
|
734 |
InvalidateWidget(w, wid); |
|
735 |
} |
|
736 |
} else if (IS_INT_INSIDE((key = we->keypress.ascii), 32, 256)) { |
|
737 |
if (count < WP(w,querystr_d).maxlen && width + _stringwidth_table[key-32] <= WP(w,querystr_d).maxwidth) { |
|
738 |
WP(w,querystr_d).buf[count] = key; |
|
739 |
WP(w,querystr_d).buf[count+1] = 0; |
|
740 |
InvalidateWidget(w, wid); |
|
741 |
} |
|
742 |
} else { |
|
743 |
// key wasn't caught |
|
744 |
we->keypress.cont = true; |
|
745 |
} |
|
746 |
} |
|
747 |
||
748 |
return 0; |
|
749 |
} |
|
750 |
||
751 |
void HandleEditBox(Window *w, int wid) |
|
752 |
{ |
|
753 |
bool b; |
|
754 |
||
755 |
/* caret changed? */ |
|
756 |
b = !!(_caret_timer & 0x20); |
|
757 |
if (b != WP(w,querystr_d).caret) { |
|
758 |
WP(w,querystr_d).caret = b; |
|
759 |
InvalidateWidget(w, wid); |
|
760 |
} |
|
761 |
} |
|
762 |
||
763 |
void DrawEditBox(Window *w, int wid) |
|
764 |
{ |
|
765 |
const Widget *wi = w->widget + wid; |
|
766 |
int x; |
|
767 |
||
768 |
GfxFillRect(wi->left+1, wi->top+1, wi->right-1, wi->bottom-1, 215); |
|
769 |
x = DoDrawString(WP(w,querystr_d).buf, wi->left+2, wi->top+1, 8); |
|
770 |
if (WP(w,querystr_d).caret) |
|
771 |
DoDrawString("_", x, wi->top+1, 12); |
|
772 |
} |
|
773 |
||
774 |
||
775 |
#define MAX_QUERYSTR_LEN 64 |
|
776 |
||
777 |
static void QueryStringWndProc(Window *w, WindowEvent *e) |
|
778 |
{ |
|
779 |
switch(e->event) { |
|
780 |
case WE_PAINT: { |
|
781 |
// int x; |
|
782 |
||
783 |
SET_DPARAM16(0, WP(w,querystr_d).caption); |
|
784 |
DrawWindowWidgets(w); |
|
785 |
||
786 |
DrawEditBox(w, 5); |
|
787 |
} break; |
|
788 |
||
789 |
case WE_CLICK: |
|
790 |
switch(e->click.widget) { |
|
791 |
case 3: DeleteWindow(w); break; |
|
792 |
case 4: |
|
793 |
press_ok:; |
|
794 |
if (str_eq(WP(w,querystr_d).buf, WP(w,querystr_d).buf + MAX_QUERYSTR_LEN)) { |
|
795 |
DeleteWindow(w); |
|
796 |
} else { |
|
797 |
Window *parent = FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num); |
|
798 |
byte *buf = WP(w,querystr_d).buf; |
|
799 |
DeleteWindow(w); |
|
800 |
if (parent != NULL) { |
|
801 |
WindowEvent e; |
|
802 |
e.event = WE_ON_EDIT_TEXT; |
|
803 |
e.edittext.str = buf; |
|
804 |
parent->wndproc(parent, &e); |
|
805 |
} |
|
806 |
} |
|
807 |
break; |
|
808 |
} |
|
809 |
break; |
|
810 |
||
811 |
case WE_MOUSELOOP: { |
|
812 |
if (!FindWindowById(WP(w,querystr_d).wnd_class, WP(w,querystr_d).wnd_num)) { |
|
813 |
DeleteWindow(w); |
|
814 |
return; |
|
815 |
} |
|
816 |
HandleEditBox(w, 5); |
|
817 |
} break; |
|
818 |
||
819 |
case WE_KEYPRESS: { |
|
820 |
switch(HandleEditBoxKey(w, 5, e)) { |
|
821 |
case 1: // Return |
|
822 |
goto press_ok; |
|
823 |
case 2: // Escape |
|
824 |
DeleteWindow(w); |
|
825 |
break; |
|
826 |
} |
|
827 |
} break; |
|
828 |
||
829 |
case WE_DESTROY: |
|
830 |
_query_string_active = false; |
|
831 |
break; |
|
832 |
} |
|
833 |
} |
|
834 |
||
835 |
static const Widget _query_string_widgets[] = { |
|
836 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5}, |
|
837 |
{ WWT_CAPTION, 14, 11, 259, 0, 13, STR_012D}, |
|
838 |
{ WWT_IMGBTN, 14, 0, 259, 14, 29, 0x0}, |
|
839 |
{ WWT_TEXTBTN, 14, 0, 129, 30, 41, STR_012E_CANCEL}, |
|
840 |
{ WWT_TEXTBTN, 14, 130, 259, 30, 41, STR_012F_OK}, |
|
841 |
{ WWT_IMGBTN, 14, 2, 257, 16, 27, 0x0}, |
|
842 |
{ WWT_LAST}, |
|
843 |
}; |
|
844 |
||
845 |
static const WindowDesc _query_string_desc = { |
|
846 |
190, 219, 260, 42, |
|
847 |
WC_QUERY_STRING,0, |
|
848 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
849 |
_query_string_widgets, |
|
850 |
QueryStringWndProc |
|
851 |
}; |
|
852 |
||
853 |
static byte _edit_str_buf[MAX_QUERYSTR_LEN*2]; |
|
854 |
||
855 |
void ShowQueryString(StringID str, StringID caption, int maxlen, int maxwidth, byte window_class, uint16 window_number) |
|
856 |
{ |
|
857 |
Window *w; |
|
858 |
||
859 |
#define _orig_edit_str_buf (_edit_str_buf+MAX_QUERYSTR_LEN) |
|
860 |
||
861 |
DeleteWindowById(WC_QUERY_STRING, 0); |
|
862 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
863 |
||
864 |
if (str == 0xFFFF) { |
|
865 |
memcpy(_orig_edit_str_buf, str_buffr, MAX_QUERYSTR_LEN); |
|
866 |
} else { |
|
867 |
GetString(_orig_edit_str_buf, str); |
|
868 |
} |
|
869 |
_orig_edit_str_buf[maxlen] = 0; |
|
870 |
||
871 |
memcpy(_edit_str_buf, _orig_edit_str_buf, MAX_QUERYSTR_LEN); |
|
872 |
||
873 |
w = AllocateWindowDesc(&_query_string_desc); |
|
874 |
||
875 |
w->click_state = 1 << 5; |
|
876 |
WP(w,querystr_d).caption = caption; |
|
877 |
WP(w,querystr_d).wnd_class = window_class; |
|
878 |
WP(w,querystr_d).wnd_num = window_number; |
|
879 |
WP(w,querystr_d).caret = 0; |
|
880 |
WP(w,querystr_d).maxlen = maxlen; |
|
881 |
WP(w,querystr_d).maxwidth = maxwidth; |
|
882 |
WP(w,querystr_d).buf = _edit_str_buf; |
|
883 |
||
884 |
_query_string_active = true; |
|
885 |
} |
|
886 |
||
887 |
static const Widget _load_dialog_1_widgets[] = { |
|
888 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
889 |
{ WWT_CAPTION, 14, 11, 256, 0, 13, STR_4001_LOAD_GAME, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
890 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
891 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 14, 25, STR_SORT_BY_DATE,STR_SORT_TIP}, |
|
892 |
{ WWT_IMGBTN, 14, 0, 256, 26, 47, 0x0}, |
|
893 |
{ WWT_IMGBTN, 14, 0, 256, 48, 293, 0x0}, |
|
894 |
{ WWT_6, 14, 2, 243, 50, 291, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
|
895 |
{ WWT_SCROLLBAR, 14, 246, 256, 48, 293, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
896 |
{ WWT_LAST}, |
|
897 |
}; |
|
898 |
||
899 |
static const Widget _load_dialog_2_widgets[] = { |
|
900 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
901 |
{ WWT_CAPTION, 14, 11, 256, 0, 13, STR_0298_LOAD_SCENARIO, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
902 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
903 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 14, 25, STR_SORT_BY_DATE,STR_SORT_TIP}, |
|
904 |
{ WWT_IMGBTN, 14, 0, 256, 26, 47, 0x0}, |
|
905 |
{ WWT_IMGBTN, 14, 0, 256, 48, 293, 0x0}, |
|
906 |
{ WWT_6, 14, 2, 243, 50, 291, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
|
907 |
{ WWT_SCROLLBAR, 14, 246, 256, 48, 293, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
908 |
{ WWT_LAST}, |
|
909 |
}; |
|
910 |
||
911 |
static const Widget _save_dialog_widgets[] = { |
|
912 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
913 |
{ WWT_CAPTION, 14, 11, 256, 0, 13, STR_4000_SAVE_GAME, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
914 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
915 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 14, 25, STR_SORT_BY_DATE,STR_SORT_TIP}, |
|
916 |
{ WWT_IMGBTN, 14, 0, 256, 26, 47, 0x0}, |
|
917 |
{ WWT_IMGBTN, 14, 0, 256, 48, 291, 0x0}, |
|
918 |
{ WWT_6, 14, 2, 243, 50, 289, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
|
919 |
{ WWT_SCROLLBAR, 14, 246, 256, 48, 291, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
920 |
{ WWT_IMGBTN, 14, 0, 256, 292, 307, 0x0}, |
|
921 |
{ WWT_IMGBTN, 14, 2, 254, 294, 305, 0x0, STR_400B_CURRENTLY_SELECTED_NAME}, |
|
922 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 308, 319, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED}, |
|
923 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 308, 319, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING}, |
|
924 |
{ WWT_LAST}, |
|
925 |
}; |
|
926 |
||
927 |
static const Widget _save_dialog_scen_widgets[] = { |
|
928 |
{ WWT_TEXTBTN, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
929 |
{ WWT_CAPTION, 14, 11, 256, 0, 13, STR_0299_SAVE_SCENARIO, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
930 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
931 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 14, 25, STR_SORT_BY_DATE,STR_SORT_TIP}, |
|
932 |
{ WWT_IMGBTN, 14, 0, 256, 26, 47, 0x0}, |
|
933 |
{ WWT_IMGBTN, 14, 0, 256, 48, 291, 0x0}, |
|
934 |
{ WWT_6, 14, 2, 243, 50, 289, 0x0, STR_400A_LIST_OF_DRIVES_DIRECTORIES}, |
|
935 |
{ WWT_SCROLLBAR, 14, 246, 256, 48, 291, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
936 |
{ WWT_IMGBTN, 14, 0, 256, 292, 307, 0x0}, |
|
937 |
{ WWT_IMGBTN, 14, 2, 254, 294, 305, 0x0, STR_400B_CURRENTLY_SELECTED_NAME}, |
|
938 |
{ WWT_PUSHTXTBTN, 14, 0, 127, 308, 319, STR_4003_DELETE, STR_400C_DELETE_THE_CURRENTLY_SELECTED}, |
|
939 |
{ WWT_PUSHTXTBTN, 14, 128, 256, 308, 319, STR_4002_SAVE, STR_400D_SAVE_THE_CURRENT_GAME_USING}, |
|
940 |
{ WWT_LAST}, |
|
941 |
}; |
|
942 |
||
943 |
||
944 |
static FiosItem *_fios_list; |
|
945 |
static int _fios_num; |
|
946 |
static int _saveload_mode; |
|
947 |
||
948 |
static void BuildFileList() |
|
949 |
{ |
|
950 |
FiosFreeSavegameList(); |
|
951 |
if(_saveload_mode==SLD_NEW_GAME || _saveload_mode==SLD_LOAD_SCENARIO || _saveload_mode==SLD_SAVE_SCENARIO) |
|
952 |
_fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode); |
|
953 |
else |
|
954 |
_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode); |
|
955 |
} |
|
956 |
||
957 |
static void DrawFiosTexts() |
|
958 |
{ |
|
959 |
char *path; |
|
960 |
StringID str; |
|
961 |
||
962 |
str = FiosGetDescText(&path); |
|
963 |
if (str != 0) |
|
964 |
DrawString(2, 37, str, 0); |
|
965 |
DoDrawString(path, 2, 27, 16); |
|
966 |
} |
|
967 |
||
968 |
/* FIOS_TYPE_FILE, FIOS_TYPE_OLDFILE etc. different colours */ |
|
969 |
static const byte _fios_colors[] = {13, 9, 9, 6, 5, 6, 5}; |
|
970 |
||
971 |
#if defined(_WIN32) |
|
972 |
extern int CDECL compare_FiosItems (const void *a, const void *b); |
|
973 |
#else |
|
974 |
extern int compare_FiosItems (const void *a, const void *b); |
|
975 |
#endif |
|
976 |
||
977 |
||
978 |
static void MakeSortedSaveGameList() |
|
979 |
{ |
|
980 |
/* Directories are always above the files (FIOS_TYPE_DIR) |
|
981 |
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE) |
|
982 |
* Only sort savegames/scenarios, not directories |
|
983 |
*/ |
|
984 |
||
985 |
int i, sort_start, sort_end, s_amount; |
|
986 |
i = sort_start = sort_end = 0; |
|
987 |
||
988 |
while (i < _fios_num) { |
|
989 |
if (_fios_list[i].type == FIOS_TYPE_DIR || _fios_list[i].type == FIOS_TYPE_PARENT) |
|
990 |
sort_start++; |
|
991 |
||
992 |
if (_fios_list[i].type == FIOS_TYPE_DRIVE) |
|
993 |
sort_end++; |
|
994 |
||
995 |
i++; |
|
996 |
} |
|
997 |
||
998 |
s_amount = _fios_num - sort_start - sort_end; |
|
999 |
if ((bool)s_amount) |
|
1000 |
qsort(_fios_list + sort_start, s_amount, sizeof(FiosItem), compare_FiosItems); |
|
1001 |
} |
|
1002 |
||
1003 |
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e) |
|
1004 |
{ |
|
1005 |
const int list_start = 51; |
|
1006 |
||
1007 |
switch(e->event) { |
|
1008 |
case WE_PAINT: { |
|
1009 |
int y,pos; |
|
1010 |
const FiosItem *item; |
|
1011 |
||
1012 |
SetVScrollCount(w, _fios_num); |
|
1013 |
DrawWindowWidgets(w); |
|
1014 |
DrawFiosTexts(); |
|
1015 |
||
1016 |
if (_savegame_sort_dirty) { |
|
1017 |
_savegame_sort_dirty = false; |
|
1018 |
MakeSortedSaveGameList(); |
|
1019 |
} |
|
1020 |
||
1021 |
GfxFillRect(3, list_start, 3+239, list_start+239, 0xD7); |
|
1022 |
DoDrawString(_savegame_sort_order & 1 ? "\xAA" : "\xA0", _savegame_sort_order <= 1 ? 248 : 118, 15, 0x10); |
|
1023 |
||
1024 |
y = list_start; |
|
1025 |
pos = w->vscroll.pos; |
|
1026 |
while (pos < _fios_num) { |
|
1027 |
item = _fios_list + pos; |
|
1028 |
DoDrawString(item->title[0] ? item->title : item->name, 4, y, _fios_colors[item->type] ); |
|
1029 |
pos++; |
|
1030 |
y+=10; |
|
1031 |
if (y >= w->vscroll.cap*10+list_start) |
|
1032 |
break; |
|
1033 |
} |
|
1034 |
||
1035 |
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) { |
|
1036 |
DrawEditBox(w, 9); |
|
1037 |
} |
|
1038 |
break; |
|
1039 |
} |
|
1040 |
case WE_CLICK: |
|
1041 |
switch(e->click.widget) { |
|
1042 |
case 2: /* Sort save names by name */ |
|
1043 |
_savegame_sort_order = (_savegame_sort_order == 2) ? 3 : 2; |
|
1044 |
_savegame_sort_dirty = true; |
|
1045 |
SetWindowDirty(w); |
|
1046 |
break; |
|
1047 |
||
1048 |
case 3: /* Sort save names by date */ |
|
1049 |
_savegame_sort_order = (_savegame_sort_order == 0) ? 1 : 0; |
|
1050 |
_savegame_sort_dirty = true; |
|
1051 |
SetWindowDirty(w); |
|
1052 |
break; |
|
1053 |
||
1054 |
case 6: { /* Click the listbox */ |
|
1055 |
int y = (e->click.pt.y - list_start) / 10; |
|
1056 |
char *name; |
|
1057 |
const FiosItem *file; |
|
1058 |
||
1059 |
if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) |
|
1060 |
return; |
|
1061 |
||
1062 |
file = _fios_list + y; |
|
1063 |
||
1064 |
if ((name = FiosBrowseTo(file)) != NULL) { |
|
1065 |
if (_saveload_mode == SLD_LOAD_GAME) { |
|
1066 |
_switch_mode = SM_LOAD; |
|
1067 |
SetFiosType(file->type); |
|
1068 |
strcpy(_file_to_saveload.name, name); |
|
1069 |
DeleteWindow(w); |
|
1070 |
} else if (_saveload_mode == SLD_LOAD_SCENARIO) { |
|
1071 |
_switch_mode = SM_LOAD_SCENARIO; |
|
1072 |
SetFiosType(file->type); |
|
1073 |
strcpy(_file_to_saveload.name, name); |
|
1074 |
DeleteWindow(w); |
|
1075 |
} else { |
|
1076 |
// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox |
|
1077 |
strcpy(WP(w,querystr_d).buf, file->title[0] ? file->title : file->name); |
|
1078 |
InvalidateWidget(w, 9); |
|
1079 |
} |
|
1080 |
} else { |
|
1081 |
// Changed directory, need repaint. |
|
1082 |
SetWindowDirty(w); |
|
1083 |
BuildFileList(); |
|
1084 |
} |
|
1085 |
break; |
|
1086 |
} |
|
1087 |
case 10: case 11: /* Delete, Save game */ |
|
1088 |
break; |
|
1089 |
} |
|
1090 |
break; |
|
1091 |
case WE_MOUSELOOP: |
|
1092 |
HandleEditBox(w, 9); |
|
1093 |
break; |
|
1094 |
case WE_KEYPRESS: |
|
1095 |
switch (HandleEditBoxKey(w, 9, e)) { |
|
1096 |
case 1: |
|
1097 |
HandleButtonClick(w, 11); |
|
1098 |
break; |
|
1099 |
} |
|
1100 |
break; |
|
1101 |
case WE_TIMEOUT: |
|
1102 |
if (HASBIT(w->click_state, 10)) { /* Delete button clicked */ |
|
1103 |
FiosDelete(WP(w,querystr_d).buf); |
|
1104 |
SetWindowDirty(w); |
|
1105 |
BuildFileList(); |
|
1106 |
} else if (HASBIT(w->click_state, 11)) { /* Save button clicked */ |
|
1107 |
_switch_mode = SM_SAVE; |
|
1108 |
FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).buf); |
|
1109 |
} |
|
1110 |
break; |
|
1111 |
case WE_DESTROY: |
|
1112 |
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); |
|
1113 |
_query_string_active = false; |
|
1114 |
FiosFreeSavegameList(); |
|
1115 |
break; |
|
1116 |
} |
|
1117 |
} |
|
1118 |
||
1119 |
static const WindowDesc _load_dialog_desc = { |
|
1120 |
WDP_CENTER, WDP_CENTER, 257, 294, |
|
1121 |
WC_SAVELOAD,0, |
|
1122 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
1123 |
_load_dialog_1_widgets, |
|
1124 |
SaveLoadDlgWndProc, |
|
1125 |
}; |
|
1126 |
||
1127 |
static const WindowDesc _load_dialog_scen_desc = { |
|
1128 |
WDP_CENTER, WDP_CENTER, 257, 294, |
|
1129 |
WC_SAVELOAD,0, |
|
1130 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
1131 |
_load_dialog_2_widgets, |
|
1132 |
SaveLoadDlgWndProc, |
|
1133 |
}; |
|
1134 |
||
1135 |
static const WindowDesc _save_dialog_desc = { |
|
1136 |
WDP_CENTER, WDP_CENTER, 257, 320, |
|
1137 |
WC_SAVELOAD,0, |
|
1138 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
1139 |
_save_dialog_widgets, |
|
1140 |
SaveLoadDlgWndProc, |
|
1141 |
}; |
|
1142 |
||
1143 |
static const WindowDesc _save_dialog_scen_desc = { |
|
1144 |
WDP_CENTER, WDP_CENTER, 257, 320, |
|
1145 |
WC_SAVELOAD,0, |
|
1146 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
1147 |
_save_dialog_scen_widgets, |
|
1148 |
SaveLoadDlgWndProc, |
|
1149 |
}; |
|
1150 |
||
1151 |
static const WindowDesc * const _saveload_dialogs[] = { |
|
1152 |
&_load_dialog_desc, |
|
1153 |
&_load_dialog_scen_desc, |
|
1154 |
&_save_dialog_desc, |
|
1155 |
&_save_dialog_scen_desc, |
|
1156 |
}; |
|
1157 |
||
1158 |
void ShowSaveLoadDialog(int mode) |
|
1159 |
{ |
|
1160 |
Window *w; |
|
1161 |
||
1162 |
SetObjectToPlace(1, 0, 0, 0); |
|
1163 |
DeleteWindowById(WC_QUERY_STRING, 0); |
|
1164 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
1165 |
||
1166 |
_saveload_mode = mode; |
|
1167 |
||
1168 |
w = AllocateWindowDesc(_saveload_dialogs[mode]); |
|
1169 |
w->vscroll.cap = 24; |
|
1170 |
w->click_state |= (1 << 6); |
|
1171 |
WP(w,querystr_d).caret = 0; |
|
1172 |
WP(w,querystr_d).maxlen = MAX_QUERYSTR_LEN; |
|
1173 |
WP(w,querystr_d).maxwidth = 240; |
|
1174 |
WP(w,querystr_d).buf = _edit_str_buf; |
|
1175 |
||
1176 |
if (mode == SLD_SAVE_GAME) { |
|
1177 |
Player *p = &_players[_local_player]; |
|
1178 |
SET_DPARAM16(0, p->name_1); |
|
1179 |
SET_DPARAM32(1, p->name_2); |
|
1180 |
SET_DPARAM16(2, _date); |
|
1181 |
GetString(_edit_str_buf, STR_4004); |
|
1182 |
} else if (mode == SLD_SAVE_SCENARIO) { |
|
1183 |
strcpy(_edit_str_buf, "UNNAMED"); |
|
1184 |
} |
|
1185 |
||
1186 |
if (_game_mode != GM_MENU) |
|
1187 |
DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
|
1188 |
||
1189 |
BuildFileList(); |
|
1190 |
||
1191 |
ResetObjectToPlace(); |
|
1192 |
} |
|
1193 |
||
1194 |
void RedrawAutosave() |
|
1195 |
{ |
|
1196 |
SetWindowDirty(FindWindowById(WC_STATUS_BAR, 0)); |
|
1197 |
} |
|
1198 |
||
1199 |
static const Widget _select_scenario_widgets[] = { |
|
1200 |
{ WWT_TEXTBTN, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
1201 |
{ WWT_CAPTION, 7, 11, 256, 0, 13, STR_400E_SELECT_NEW_GAME_TYPE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
1202 |
{ WWT_PUSHTXTBTN, 7, 0, 127, 14, 25, STR_SORT_BY_NAME, STR_SORT_TIP}, |
|
1203 |
{ WWT_PUSHTXTBTN, 7, 128, 256, 14, 25, STR_SORT_BY_DATE, STR_SORT_TIP}, |
|
1204 |
{ WWT_IMGBTN, 7, 0, 245, 26, 319, 0x0}, |
|
1205 |
{ WWT_6, 7, 2, 243, 28, 317, 0x0, STR_400F_SELECT_SCENARIO_GREEN_PRE}, |
|
1206 |
{ WWT_SCROLLBAR, 7, 246, 256, 26, 319, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
1207 |
{ WWT_LAST}, |
|
1208 |
}; |
|
1209 |
||
1210 |
static void SelectScenarioWndProc(Window *w, WindowEvent *e) { |
|
1211 |
const int list_start = 45; |
|
1212 |
switch(e->event) { |
|
1213 |
case WE_PAINT: |
|
1214 |
{ |
|
1215 |
int y,pos; |
|
1216 |
const FiosItem *item; |
|
1217 |
||
1218 |
if (_savegame_sort_dirty) { |
|
1219 |
_savegame_sort_dirty = false; |
|
1220 |
MakeSortedSaveGameList(); |
|
1221 |
} |
|
1222 |
||
1223 |
SetVScrollCount(w, _fios_num); |
|
1224 |
||
1225 |
DrawWindowWidgets(w); |
|
1226 |
DoDrawString(_savegame_sort_order & 1 ? "\xAA" : "\xA0", _savegame_sort_order <= 1 ? 248 : 118, 15, 0x10); |
|
1227 |
DrawString(4, 32, STR_4010_GENERATE_RANDOM_NEW_GAME, 9); |
|
1228 |
||
1229 |
y = list_start; |
|
1230 |
pos = w->vscroll.pos; |
|
1231 |
while (pos < _fios_num) { |
|
1232 |
item = _fios_list + pos; |
|
1233 |
DoDrawString(item->title[0] ? item->title : item->name, 4, y, _fios_colors[item->type] ); |
|
1234 |
pos++; |
|
1235 |
y+=10; |
|
1236 |
if (y >= w->vscroll.cap*10+list_start) |
|
1237 |
break; |
|
1238 |
} |
|
1239 |
} |
|
1240 |
break; |
|
1241 |
||
1242 |
case WE_CLICK: |
|
1243 |
switch(e->click.widget) { |
|
1244 |
case 2: /* Sort scenario names by name */ |
|
1245 |
_savegame_sort_order = (_savegame_sort_order == 2) ? 3 : 2; |
|
1246 |
_savegame_sort_dirty = true; |
|
1247 |
SetWindowDirty(w); |
|
1248 |
break; |
|
1249 |
||
1250 |
case 3: /* Sort scenario names by date */ |
|
1251 |
_savegame_sort_order = (_savegame_sort_order == 0) ? 1 : 0; |
|
1252 |
_savegame_sort_dirty = true; |
|
1253 |
SetWindowDirty(w); |
|
1254 |
break; |
|
1255 |
||
1256 |
case 5: /* Click the listbox */ |
|
1257 |
if(e->click.pt.y < list_start) |
|
1258 |
DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_GEN_RANDOM_NEW_GAME); |
|
1259 |
else { |
|
1260 |
char *name; |
|
1261 |
int y = (e->click.pt.y - list_start) / 10; |
|
1262 |
const FiosItem *file; |
|
1263 |
||
1264 |
if (y < 0 || (y += w->vscroll.pos) >= w->vscroll.count) |
|
1265 |
return; |
|
1266 |
||
1267 |
file = _fios_list + y; |
|
1268 |
||
1269 |
if ((name = FiosBrowseTo(file)) != NULL) { |
|
1270 |
SetFiosType(file->type); |
|
1271 |
strcpy(_file_to_saveload.name, name); |
|
1272 |
DeleteWindow(w); |
|
1273 |
DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_START_SCENARIO); |
|
1274 |
} |
|
1275 |
} |
|
1276 |
break; |
|
1277 |
} |
|
1278 |
case WE_DESTROY: |
|
1279 |
break; |
|
1280 |
} |
|
1281 |
} |
|
1282 |
||
1283 |
static void SetFiosType(const byte fiostype) |
|
1284 |
{ |
|
1285 |
switch (fiostype) { |
|
1286 |
case FIOS_TYPE_FILE: case FIOS_TYPE_SCENARIO: |
|
1287 |
_file_to_saveload.mode = SL_LOAD; |
|
1288 |
break; |
|
1289 |
case FIOS_TYPE_OLDFILE: case FIOS_TYPE_OLD_SCENARIO: |
|
1290 |
_file_to_saveload.mode = SL_OLD_LOAD; |
|
1291 |
break; |
|
1292 |
default: |
|
1293 |
_file_to_saveload.mode = SL_INVALID; |
|
1294 |
} |
|
1295 |
} |
|
1296 |
||
1297 |
static const WindowDesc _select_scenario_desc = { |
|
1298 |
WDP_CENTER, WDP_CENTER, 257, 320, |
|
1299 |
WC_SAVELOAD,0, |
|
1300 |
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS, |
|
1301 |
_select_scenario_widgets, |
|
1302 |
SelectScenarioWndProc |
|
1303 |
}; |
|
1304 |
||
1305 |
void AskForNewGameToStart() |
|
1306 |
{ |
|
1307 |
Window *w; |
|
1308 |
||
1309 |
DeleteWindowById(WC_QUERY_STRING, 0); |
|
1310 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
1311 |
||
1312 |
_saveload_mode = SLD_NEW_GAME; |
|
1313 |
BuildFileList(); |
|
1314 |
||
1315 |
w = AllocateWindowDesc(&_select_scenario_desc); |
|
1316 |
w->vscroll.cap = 27; |
|
1317 |
} |
|
1318 |
||
1319 |
||
1320 |
||
1321 |
||
1322 |
int32 ClickMoneyCheat(int32 p1, int32 p2) |
|
1323 |
{ |
|
1324 |
DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT); |
|
1325 |
return true; |
|
1326 |
} |
|
1327 |
||
1328 |
// p1 player to set to, p2 is -1 or +1 (down/up) |
|
1329 |
int32 ClickChangePlayerCheat(int32 p1, int32 p2) |
|
1330 |
{ |
|
1331 |
while(p1 >= 0 && p1 < MAX_PLAYERS) |
|
1332 |
{ |
|
1333 |
if (_players[p1].is_active) |
|
1334 |
{ |
|
1335 |
_local_player = p1; |
|
1336 |
return _local_player; |
|
1337 |
} |
|
1338 |
p1 += p2; |
|
1339 |
} |
|
1340 |
return _local_player; |
|
1341 |
} |
|
1342 |
||
1343 |
typedef int32 CheckButtonClick(int32, int32); |
|
1344 |
static CheckButtonClick * const _cheat_button_proc[] = { |
|
1345 |
ClickMoneyCheat, |
|
1346 |
ClickChangePlayerCheat, |
|
1347 |
}; |
|
1348 |
||
1349 |
||
1350 |
typedef struct CheatEntry { |
|
1351 |
byte type; // type of selector |
|
1352 |
byte flags; // selector flags |
|
1353 |
StringID str; // string with descriptive text |
|
1354 |
void *variable; // pointer to the variable |
|
1355 |
bool *been_used; // has this cheat been used before? |
|
1356 |
CheckButtonClick *click_proc; // procedure |
|
1357 |
int16 min,max; // range for spinbox setting |
|
1358 |
uint16 step; // step for spinbox |
|
1359 |
} CheatEntry; |
|
1360 |
||
1361 |
enum { |
|
1362 |
CE_BOOL = 0, |
|
1363 |
CE_UINT8 = 1, |
|
1364 |
CE_INT16 = 2, |
|
1365 |
CE_UINT16 = 3, |
|
1366 |
CE_INT32 = 4, |
|
1367 |
CE_BYTE = 5, |
|
1368 |
CE_CLICK = 6, |
|
1369 |
||
1370 |
CF_0ISDIS = 1, |
|
1371 |
CF_NOCOMMA = 2, |
|
1372 |
}; |
|
1373 |
||
1374 |
static int32 ReadCE(const CheatEntry*ce) |
|
1375 |
{ |
|
1376 |
switch(ce->type) { |
|
1377 |
case CE_BOOL: return *(bool*)ce->variable; |
|
1378 |
case CE_UINT8: return *(uint8*)ce->variable; |
|
1379 |
case CE_INT16: return *(int16*)ce->variable; |
|
1380 |
case CE_UINT16: return *(uint16*)ce->variable; |
|
1381 |
case CE_INT32: return *(int32*)ce->variable; |
|
1382 |
case CE_BYTE: return *(byte*)ce->variable; |
|
1383 |
case CE_CLICK: return 0; |
|
1384 |
default: |
|
1385 |
NOT_REACHED(); |
|
1386 |
} |
|
1387 |
||
1388 |
/* useless, but avoids compiler warning this way */ |
|
1389 |
return 0; |
|
1390 |
} |
|
1391 |
||
1392 |
static void WriteCE(const CheatEntry *ce, int32 val) |
|
1393 |
{ |
|
1394 |
switch(ce->type) { |
|
1395 |
case CE_BOOL: *(bool*)ce->variable = (bool)val; break; |
|
1396 |
case CE_BYTE: *(byte*)ce->variable = (byte)val; break; |
|
1397 |
case CE_UINT8: *(uint8*)ce->variable = (uint8)val; break; |
|
1398 |
case CE_INT16: *(int16*)ce->variable = (int16)val; break; |
|
1399 |
case CE_UINT16: *(uint16*)ce->variable = (uint16)val; break; |
|
1400 |
case CE_INT32: *(int32*)ce->variable = val; break; |
|
1401 |
case CE_CLICK: break; |
|
1402 |
default: |
|
1403 |
NOT_REACHED(); |
|
1404 |
} |
|
1405 |
} |
|
1406 |
||
1407 |
||
1408 |
static const CheatEntry _cheats_ui[] = { |
|
1409 |
{CE_CLICK, 0, STR_CHEAT_MONEY, &_cheats.money.value, &_cheats.money.been_used, &ClickMoneyCheat}, |
|
1410 |
{CE_UINT8, 0, STR_CHEAT_CHANGE_PLAYER, &_local_player, &_cheats.switch_player.been_used, &ClickChangePlayerCheat, 0, 11, 1}, |
|
1411 |
{CE_BOOL, 0, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used}, |
|
1412 |
{CE_BOOL, 0, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value,&_cheats.crossing_tunnels.been_used}, |
|
67
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
66
diff
changeset
|
1413 |
{CE_BOOL, 0, STR_CHEAT_BUILD_IN_PAUSE, &_cheats.build_in_pause.value, &_cheats.build_in_pause.been_used}, |
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
67
diff
changeset
|
1414 |
{CE_BOOL, 0, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used}, |
0 | 1415 |
}; |
1416 |
||
1417 |
||
1418 |
static const Widget _cheat_widgets[] = { |
|
1419 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
1420 |
{ WWT_CAPTION, 14, 11, 399, 0, 13, STR_CHEATS, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
1421 |
{ WWT_PANEL, 14, 0, 399, 14, 147, 0x0}, |
|
1422 |
||
1423 |
{ WWT_IMGBTN, 14, 0, 399, 14, 147, 0x0, STR_CHEATS_TIP}, |
|
1424 |
{ WWT_LAST}, |
|
1425 |
}; |
|
1426 |
||
1427 |
extern void DrawPlayerIcon(int p, int x, int y); |
|
1428 |
||
1429 |
static void CheatsWndProc(Window *w, WindowEvent *e) |
|
1430 |
{ |
|
1431 |
switch(e->event) { |
|
1432 |
case WE_PAINT: { |
|
1433 |
int clk = WP(w,def_d).data_1; |
|
1434 |
const CheatEntry *ce = &_cheats_ui[0]; |
|
1435 |
int32 val; |
|
1436 |
int x, y; |
|
1437 |
int i; |
|
1438 |
||
1439 |
DrawWindowWidgets(w); |
|
1440 |
||
1441 |
DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, 350); |
|
1442 |
||
1443 |
x=0; |
|
1444 |
y=45; |
|
1445 |
||
1446 |
for(i=0; i!=lengthof(_cheats_ui); i++,ce++) { |
|
1447 |
||
1448 |
DrawSprite((SPR_OPENTTD_BASE + ((*ce->been_used)?67:66)), x+5, y+2); |
|
1449 |
||
1450 |
if (ce->type == CE_BOOL) { |
|
1451 |
DrawFrameRect(x+20, y+1, x+30+9, y+9, (*(bool*)ce->variable)?6:4, (*(bool*)ce->variable)?0x20:0); |
|
1452 |
SET_DPARAM16(0, *(bool*)ce->variable ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF); |
|
1453 |
||
1454 |
} else if (ce->type == CE_CLICK) { |
|
1455 |
DrawFrameRect(x+20, y+1, x+30+9, y+9, 0, (WP(w,def_d).data_1==i*2+1)?0x20:0x00); |
|
1456 |
if(i==0) |
|
1457 |
SET_DPARAM64(0, (int64) 10000000); |
|
1458 |
else |
|
1459 |
SET_DPARAM16(0, false); |
|
1460 |
||
1461 |
} else { |
|
1462 |
DrawFrameRect(x+20, y+1, x+20+9, y+9, 3, clk == i*2+1 ? 0x20 : 0); |
|
1463 |
DrawFrameRect(x+30, y+1, x+30+9, y+9, 3, clk == i*2+2 ? 0x20 : 0); |
|
1464 |
DrawStringCentered(x+25, y+1, STR_6819, 0); |
|
1465 |
DrawStringCentered(x+35, y+1, STR_681A, 0); |
|
1466 |
||
1467 |
val = ReadCE(ce); |
|
1468 |
SET_DPARAM16(0, val); |
|
1469 |
||
1470 |
// draw colored flag for change player cheat |
|
1471 |
if(ce->str==STR_CHEAT_CHANGE_PLAYER) |
|
1472 |
DrawPlayerIcon(_current_player, 156, y+2); |
|
1473 |
||
1474 |
||
1475 |
} |
|
1476 |
||
1477 |
DrawString(50, y+1, ce->str, 0); |
|
1478 |
||
1479 |
y+=12; |
|
1480 |
} |
|
1481 |
break; |
|
1482 |
} |
|
1483 |
case WE_CLICK: { |
|
1484 |
const CheatEntry *ce; |
|
1485 |
uint btn = (e->click.pt.y - 46) / 12; |
|
1486 |
int32 val, oval; |
|
1487 |
uint x = e->click.pt.x; |
|
1488 |
||
1489 |
// not clicking a button? |
|
1490 |
if(!IS_INT_INSIDE(x, 20, 40) || btn>=lengthof(_cheats_ui)) |
|
1491 |
break; |
|
1492 |
||
1493 |
ce = &_cheats_ui[btn]; |
|
1494 |
oval = val = ReadCE(ce); |
|
1495 |
||
1496 |
*ce->been_used = true; |
|
1497 |
||
1498 |
switch(ce->type) { |
|
1499 |
case CE_BOOL: { |
|
1500 |
val ^= 1; |
|
1501 |
if (ce->click_proc != NULL) |
|
1502 |
ce->click_proc(val, 0); |
|
1503 |
break; |
|
1504 |
} |
|
1505 |
||
1506 |
case CE_CLICK: { |
|
1507 |
ce->click_proc(val, 0); |
|
1508 |
WP(w,def_d).data_1 = btn * 2 + 1; |
|
1509 |
break; |
|
1510 |
} |
|
1511 |
||
1512 |
default: { |
|
1513 |
if (x >= 30) { |
|
1514 |
//increase |
|
1515 |
val += ce->step; |
|
1516 |
if (val > ce->max) val = ce->max; |
|
1517 |
} else { |
|
1518 |
// decrease |
|
1519 |
val -= ce->step; |
|
1520 |
if (val < ce->min) val = ce->min; |
|
1521 |
} |
|
1522 |
||
1523 |
// take whatever the function returns |
|
1524 |
val = ce->click_proc(val, (x>=30) ? 1 : -1); |
|
1525 |
||
1526 |
if (val != oval) |
|
1527 |
WP(w,def_d).data_1 = btn * 2 + 1 + ((x>=30) ? 1 : 0); |
|
1528 |
||
1529 |
break; |
|
1530 |
} |
|
1531 |
} |
|
1532 |
||
1533 |
if (val != oval) { |
|
1534 |
WriteCE(ce, val); |
|
1535 |
SetWindowDirty(w); |
|
1536 |
} |
|
1537 |
||
1538 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
1539 |
||
1540 |
SetWindowDirty(w); |
|
1541 |
} |
|
1542 |
break; |
|
1543 |
case WE_TIMEOUT: |
|
1544 |
WP(w,def_d).data_1 = 0; |
|
1545 |
SetWindowDirty(w); |
|
1546 |
break; |
|
1547 |
} |
|
1548 |
} |
|
1549 |
static const WindowDesc _cheats_desc = { |
|
1550 |
240, 22, 400, 148, |
|
1551 |
WC_CHEATS,0, |
|
1552 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
1553 |
_cheat_widgets, |
|
1554 |
CheatsWndProc |
|
1555 |
}; |
|
1556 |
||
1557 |
||
1558 |
void ShowCheatWindow() |
|
1559 |
{ |
|
1560 |
Window *w; |
|
1561 |
||
1562 |
DeleteWindowById(WC_CHEATS, 0); |
|
1563 |
w = AllocateWindowDesc(&_cheats_desc); |
|
1564 |
||
1565 |
if (w) |
|
1566 |
SetWindowDirty(w); |
|
1567 |
} |