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