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