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 "command.h"
|
|
9 |
#include "engine.h"
|
|
10 |
|
|
11 |
static uint32 _dropdown_disabled;
|
|
12 |
static const StringID *_dropdown_items;
|
|
13 |
static int _dropdown_selindex;
|
|
14 |
static uint _dropdown_item_count;
|
|
15 |
static byte _dropdown_button;
|
|
16 |
static WindowClass _dropdown_windowclass;
|
|
17 |
static WindowNumber _dropdown_windownum;
|
|
18 |
static byte _dropdown_var1;
|
|
19 |
static byte _dropdown_var2;
|
|
20 |
|
|
21 |
static uint32 _difficulty_click_a;
|
|
22 |
static uint32 _difficulty_click_b;
|
|
23 |
static byte _difficulty_timeout;
|
|
24 |
|
|
25 |
static Widget _dropdown_menu_widgets[] = {
|
|
26 |
{ WWT_IMGBTN, 0, 0, 0, 0, 0, 0x0},
|
|
27 |
{ WWT_LAST},
|
|
28 |
};
|
|
29 |
|
|
30 |
static int GetDropdownItem(Window *w)
|
|
31 |
{
|
|
32 |
uint item;
|
|
33 |
int y;
|
|
34 |
|
|
35 |
if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
|
|
36 |
return -1;
|
|
37 |
|
|
38 |
y = _cursor.pos.y - w->top - 2;
|
|
39 |
|
|
40 |
if (y < 0)
|
|
41 |
return - 1;
|
|
42 |
|
|
43 |
item = y / 10;
|
|
44 |
if (item >= _dropdown_item_count || HASBIT(_dropdown_disabled,item) || _dropdown_items[item] == 0)
|
|
45 |
return - 1;
|
|
46 |
|
|
47 |
return item;
|
|
48 |
}
|
|
49 |
|
|
50 |
void DropdownMenuWndProc(Window *w, WindowEvent *e)
|
|
51 |
{
|
|
52 |
int item;
|
|
53 |
|
|
54 |
switch(e->event) {
|
|
55 |
case WE_PAINT: {
|
|
56 |
int x,y,i,sel;
|
|
57 |
uint32 dis;
|
|
58 |
|
|
59 |
DrawWindowWidgets(w);
|
|
60 |
|
|
61 |
x = 1;
|
|
62 |
y = 2;
|
|
63 |
sel = _dropdown_selindex;
|
|
64 |
dis = _dropdown_disabled;
|
|
65 |
|
|
66 |
for(i=0; _dropdown_items[i] != INVALID_STRING_ID; i++) {
|
|
67 |
if (_dropdown_items[i] != 0) {
|
|
68 |
if (sel == 0) {
|
|
69 |
GfxFillRect(x+1, y, x+w->width-4, y + 9, 0);
|
|
70 |
}
|
|
71 |
DrawString(x+2, y, _dropdown_items[i], sel==0 ? 12 : 16);
|
|
72 |
|
|
73 |
if (dis & 1) {
|
|
74 |
GfxFillRect(x, y, x+w->width-3, y + 9, 0x8000 +
|
|
75 |
_color_list[_dropdown_menu_widgets[0].color].window_color_bga);
|
|
76 |
}
|
|
77 |
} else {
|
|
78 |
int color_1 = _color_list[_dropdown_menu_widgets[0].color].window_color_1a;
|
|
79 |
int color_2 = _color_list[_dropdown_menu_widgets[0].color].window_color_2;
|
|
80 |
GfxFillRect(x+1, y+3, x+w->width-5, y+3, color_1);
|
|
81 |
GfxFillRect(x+1, y+4, x+w->width-5, y+4, color_2);
|
|
82 |
}
|
|
83 |
y += 10;
|
|
84 |
sel--;
|
|
85 |
dis>>=1;
|
|
86 |
}
|
|
87 |
} break;
|
|
88 |
|
|
89 |
case WE_CLICK: {
|
|
90 |
item = GetDropdownItem(w);
|
|
91 |
if (item >= 0) {
|
|
92 |
_dropdown_var1 = 4;
|
|
93 |
_dropdown_selindex = item;
|
|
94 |
SetWindowDirty(w);
|
|
95 |
}
|
|
96 |
} break;
|
|
97 |
|
|
98 |
case WE_MOUSELOOP: {
|
|
99 |
Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
|
|
100 |
if (w2 == NULL) {
|
|
101 |
DeleteWindow(w);
|
|
102 |
return;
|
|
103 |
}
|
|
104 |
|
|
105 |
if (_dropdown_var1 != 0 && --_dropdown_var1 == 0) {
|
|
106 |
WindowEvent e;
|
|
107 |
e.event = WE_DROPDOWN_SELECT;
|
|
108 |
e.dropdown.button = _dropdown_button;
|
|
109 |
e.dropdown.index = _dropdown_selindex;
|
|
110 |
w2->wndproc(w2, &e);
|
|
111 |
DeleteWindow(w);
|
|
112 |
return;
|
|
113 |
}
|
|
114 |
|
|
115 |
if (_dropdown_var2 != 0) {
|
|
116 |
item = GetDropdownItem(w);
|
|
117 |
|
|
118 |
if (!_left_button_clicked) {
|
|
119 |
_dropdown_var2 = 0;
|
|
120 |
if (item < 0)
|
|
121 |
return;
|
|
122 |
_dropdown_var1 = 2;
|
|
123 |
} else {
|
|
124 |
if (item < 0)
|
|
125 |
return;
|
|
126 |
}
|
|
127 |
|
|
128 |
_dropdown_selindex = item;
|
|
129 |
SetWindowDirty(w);
|
|
130 |
}
|
|
131 |
} break;
|
|
132 |
|
|
133 |
case WE_DESTROY: {
|
|
134 |
Window *w2 = FindWindowById(_dropdown_windowclass, _dropdown_windownum);
|
|
135 |
if (w2 != NULL) {
|
|
136 |
CLRBIT(w2->click_state, _dropdown_button);
|
|
137 |
InvalidateWidget(w2, _dropdown_button);
|
|
138 |
}
|
|
139 |
} break;
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask)
|
|
144 |
{
|
|
145 |
WindowNumber num;
|
|
146 |
WindowClass cls;
|
|
147 |
int i,t1,t2;
|
|
148 |
const Widget *wi;
|
|
149 |
Window *w2;
|
|
150 |
uint32 old_click_state = w->click_state;
|
|
151 |
|
|
152 |
_dropdown_disabled = disabled_mask;
|
|
153 |
|
|
154 |
cls = w->window_class;
|
|
155 |
num = w->window_number;
|
|
156 |
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
157 |
w = FindWindowById(cls, num);
|
|
158 |
|
|
159 |
if (HASBIT(old_click_state, button))
|
|
160 |
return;
|
|
161 |
|
|
162 |
SETBIT(w->click_state, button);
|
|
163 |
|
|
164 |
InvalidateWidget(w, button);
|
|
165 |
|
|
166 |
for(i=0;strings[i] != INVALID_STRING_ID;i++);
|
|
167 |
if (i == 0)
|
|
168 |
return;
|
|
169 |
|
|
170 |
_dropdown_items = strings;
|
|
171 |
_dropdown_item_count = i;
|
|
172 |
_dropdown_selindex = selected;
|
|
173 |
|
|
174 |
_dropdown_windowclass = w->window_class;
|
|
175 |
_dropdown_windownum = w->window_number;
|
|
176 |
_dropdown_button = button;
|
|
177 |
|
|
178 |
_dropdown_var1 = 0;
|
|
179 |
_dropdown_var2 = 1;
|
|
180 |
|
|
181 |
wi = &w->widget[button];
|
|
182 |
|
|
183 |
_dropdown_menu_widgets[0].color = wi->color;
|
|
184 |
|
|
185 |
w2 = AllocateWindow(
|
|
186 |
w->left + wi[-1].left + 1,
|
|
187 |
w->top + wi->bottom + 2,
|
|
188 |
(_dropdown_menu_widgets[0].right=t1=wi->right - wi[-1].left, t1 + 1),
|
|
189 |
(_dropdown_menu_widgets[0].bottom=t2=i*10+3, t2+1),
|
|
190 |
DropdownMenuWndProc,
|
|
191 |
0x3F,
|
|
192 |
_dropdown_menu_widgets);
|
|
193 |
|
|
194 |
|
|
195 |
w2->flags4 &= ~WF_WHITE_BORDER_MASK;
|
|
196 |
}
|
|
197 |
|
|
198 |
extern const StringID _currency_string_list[];
|
|
199 |
extern uint GetMaskOfAllowedCurrencies();
|
|
200 |
|
|
201 |
static const StringID _distances_dropdown[] = {
|
|
202 |
STR_0139_IMPERIAL_MILES,
|
|
203 |
STR_013A_METRIC_KILOMETERS,
|
|
204 |
INVALID_STRING_ID
|
|
205 |
};
|
|
206 |
|
|
207 |
static const StringID _driveside_dropdown[] = {
|
|
208 |
STR_02E9_DRIVE_ON_LEFT,
|
|
209 |
STR_02EA_DRIVE_ON_RIGHT,
|
|
210 |
INVALID_STRING_ID
|
|
211 |
};
|
|
212 |
|
|
213 |
static const StringID _autosave_dropdown[] = {
|
|
214 |
STR_02F7_OFF,
|
|
215 |
STR_AUTOSAVE_1_MONTH,
|
|
216 |
STR_02F8_EVERY_3_MONTHS,
|
|
217 |
STR_02F9_EVERY_6_MONTHS,
|
|
218 |
STR_02FA_EVERY_12_MONTHS,
|
|
219 |
INVALID_STRING_ID,
|
|
220 |
};
|
|
221 |
|
|
222 |
static const StringID _designnames_dropdown[] = {
|
|
223 |
STR_02BE_DEFAULT,
|
|
224 |
STR_02BF_CUSTOM,
|
|
225 |
INVALID_STRING_ID
|
|
226 |
};
|
|
227 |
|
|
228 |
static StringID *BuildDynamicDropdown(StringID base, int num)
|
|
229 |
{
|
|
230 |
static StringID buf[32 + 1];
|
|
231 |
StringID *p = buf;
|
|
232 |
while (--num>=0) *p++ = base++;
|
|
233 |
*p = INVALID_STRING_ID;
|
|
234 |
return buf;
|
|
235 |
}
|
|
236 |
|
|
237 |
static int GetCurRes()
|
|
238 |
{
|
|
239 |
int i;
|
|
240 |
for(i=0; i!=_num_resolutions; i++)
|
|
241 |
if (_resolutions[i][0] == _cur_resolution[0] && _resolutions[i][1] == _cur_resolution[1])
|
|
242 |
break;
|
|
243 |
return i;
|
|
244 |
}
|
|
245 |
|
|
246 |
static void GameOptionsWndProc(Window *w, WindowEvent *e)
|
|
247 |
{
|
|
248 |
int i;
|
|
249 |
|
|
250 |
switch(e->event) {
|
|
251 |
case WE_PAINT: {
|
|
252 |
StringID str = STR_02BE_DEFAULT;
|
|
253 |
w->disabled_state = (_vehicle_design_names & 1) ? (++str, 0) : (1 << 21);
|
|
254 |
SET_DPARAM16(0, str);
|
|
255 |
SET_DPARAM16(1, _currency_string_list[_opt_mod_ptr->currency]);
|
|
256 |
SET_DPARAM16(2, _opt_mod_ptr->kilometers + STR_0139_IMPERIAL_MILES);
|
|
257 |
SET_DPARAM16(3, STR_02E9_DRIVE_ON_LEFT + _opt_mod_ptr->road_side);
|
|
258 |
SET_DPARAM16(4, STR_TOWNNAME_ENGLISH + _opt_mod_ptr->town_name);
|
|
259 |
SET_DPARAM16(5, _autosave_dropdown[_opt_mod_ptr->autosave]);
|
|
260 |
SET_DPARAM16(6, SPECSTR_LANGUAGE_START + _dynlang.curr);
|
|
261 |
i = GetCurRes();
|
|
262 |
SET_DPARAM16(7, i == _num_resolutions ? STR_RES_OTHER : SPECSTR_RESOLUTION_START + i);
|
|
263 |
SET_DPARAM16(8, SPECSTR_SCREENSHOT_START + _cur_screenshot_format);
|
|
264 |
DrawWindowWidgets(w);
|
|
265 |
} break;
|
|
266 |
|
|
267 |
case WE_CLICK:
|
|
268 |
switch(e->click.widget) {
|
|
269 |
case 5:
|
|
270 |
ShowDropDownMenu(w, _currency_string_list, _opt_mod_ptr->currency, e->click.widget, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies());
|
|
271 |
return;
|
|
272 |
case 8:
|
|
273 |
ShowDropDownMenu(w, _distances_dropdown, _opt_mod_ptr->kilometers, e->click.widget, 0);
|
|
274 |
return;
|
|
275 |
case 11: {
|
|
276 |
int i = _opt_mod_ptr->road_side;
|
|
277 |
ShowDropDownMenu(w, _driveside_dropdown, i, e->click.widget, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i));
|
|
278 |
return;
|
|
279 |
}
|
|
280 |
case 14: {
|
|
281 |
int i = _opt_mod_ptr->town_name;
|
|
282 |
ShowDropDownMenu(w, BuildDynamicDropdown(STR_TOWNNAME_ENGLISH, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1), i, e->click.widget, (_game_mode == GM_MENU) ? 0 : (-1) ^ (1 << i));
|
|
283 |
return;
|
|
284 |
}
|
|
285 |
case 17:
|
|
286 |
ShowDropDownMenu(w, _autosave_dropdown, _opt_mod_ptr->autosave, e->click.widget, 0);
|
|
287 |
return;
|
|
288 |
case 20:
|
|
289 |
ShowDropDownMenu(w, _designnames_dropdown, (_vehicle_design_names&1)?1:0, e->click.widget, (_vehicle_design_names&2)?0:2);
|
|
290 |
return;
|
|
291 |
case 21:
|
|
292 |
return;
|
|
293 |
case 24:
|
|
294 |
ShowDropDownMenu(w, _dynlang.dropdown, _dynlang.curr, e->click.widget, 0);
|
|
295 |
return;
|
|
296 |
case 27:
|
|
297 |
// setup resolution dropdown
|
|
298 |
ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_RESOLUTION_START, _num_resolutions), GetCurRes(), e->click.widget, 0);
|
|
299 |
return;
|
|
300 |
case 30:
|
|
301 |
// setup screenshot format dropdown
|
|
302 |
ShowDropDownMenu(w, BuildDynamicDropdown(SPECSTR_SCREENSHOT_START, _num_screenshot_formats), _cur_screenshot_format, e->click.widget, 0);
|
|
303 |
return;
|
|
304 |
|
|
305 |
}
|
|
306 |
break;
|
|
307 |
|
|
308 |
case WE_DROPDOWN_SELECT:
|
|
309 |
switch(e->dropdown.button) {
|
|
310 |
case 20:
|
|
311 |
if (e->dropdown.index == 0) {
|
|
312 |
DeleteCustomEngineNames();
|
|
313 |
MarkWholeScreenDirty();
|
|
314 |
} else if (!(_vehicle_design_names&1)) {
|
|
315 |
LoadCustomEngineNames();
|
|
316 |
MarkWholeScreenDirty();
|
|
317 |
}
|
|
318 |
break;
|
|
319 |
case 5:
|
|
320 |
_opt_mod_ptr->currency = _opt.currency = e->dropdown.index;
|
|
321 |
MarkWholeScreenDirty();
|
|
322 |
break;
|
|
323 |
case 8:
|
|
324 |
_opt_mod_ptr->kilometers = e->dropdown.index;
|
|
325 |
MarkWholeScreenDirty();
|
|
326 |
break;
|
|
327 |
case 11:
|
|
328 |
if (_game_mode == GM_MENU)
|
|
329 |
DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_ROAD_DRIVE_SIDE | CMD_MSG(STR_EMPTY));
|
|
330 |
break;
|
|
331 |
case 14:
|
|
332 |
if (_game_mode == GM_MENU)
|
|
333 |
DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_TOWN_NAME_TYPE | CMD_MSG(STR_EMPTY));
|
|
334 |
break;
|
|
335 |
case 17:
|
|
336 |
_opt_mod_ptr->autosave = e->dropdown.index;
|
|
337 |
SetWindowDirty(w);
|
|
338 |
break;
|
|
339 |
|
|
340 |
// change interface language
|
|
341 |
case 24:
|
|
342 |
ReadLanguagePack(e->dropdown.index);
|
|
343 |
MarkWholeScreenDirty();
|
|
344 |
break;
|
|
345 |
|
|
346 |
// change resolution
|
|
347 |
case 27:
|
|
348 |
if (e->dropdown.index < _num_resolutions && ChangeResInGame(_resolutions[e->dropdown.index][0],_resolutions[e->dropdown.index][1]))
|
|
349 |
SetWindowDirty(w);
|
|
350 |
break;
|
|
351 |
|
|
352 |
// change screenshot format
|
|
353 |
case 30:
|
|
354 |
SetScreenshotFormat(e->dropdown.index);
|
|
355 |
SetWindowDirty(w);
|
|
356 |
break;
|
|
357 |
}
|
|
358 |
break;
|
|
359 |
}
|
|
360 |
}
|
|
361 |
|
|
362 |
int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
363 |
{
|
|
364 |
if (flags & DC_EXEC) {
|
|
365 |
_opt_mod_ptr->road_side = p1;
|
|
366 |
InvalidateWindow(WC_GAME_OPTIONS,0);
|
|
367 |
}
|
|
368 |
return 0;
|
|
369 |
}
|
|
370 |
|
|
371 |
int32 CmdSetTownNameType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|
372 |
{
|
|
373 |
if (flags & DC_EXEC) {
|
|
374 |
_opt_mod_ptr->town_name = p1;
|
|
375 |
InvalidateWindow(WC_GAME_OPTIONS,0);
|
|
376 |
}
|
|
377 |
return 0;
|
|
378 |
}
|
|
379 |
|
|
380 |
|
|
381 |
static const Widget _game_options_widgets[] = {
|
|
382 |
{ WWT_CLOSEBOX, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
383 |
{ WWT_CAPTION, 14, 11, 369, 0, 13, STR_00B1_GAME_OPTIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
384 |
{ WWT_PANEL, 14, 0, 369, 14, 233, 0x0},
|
|
385 |
{ WWT_FRAME, 14, 10, 179, 20, 55, STR_02E0_CURRENCY_UNITS},
|
|
386 |
{ WWT_6, 14, 20, 169, 34, 45, STR_02E1, STR_02E2_CURRENCY_UNITS_SELECTION},
|
|
387 |
{ WWT_CLOSEBOX, 14, 158, 168, 35, 44, STR_0225, STR_02E2_CURRENCY_UNITS_SELECTION},
|
|
388 |
{ WWT_FRAME, 14, 190, 359, 20, 55, STR_02E3_DISTANCE_UNITS},
|
|
389 |
{ WWT_6, 14, 200, 349, 34, 45, STR_02E4, STR_02E5_DISTANCE_UNITS_SELECTION},
|
|
390 |
{ WWT_CLOSEBOX, 14, 338, 348, 35, 44, STR_0225, STR_02E5_DISTANCE_UNITS_SELECTION},
|
|
391 |
{ WWT_FRAME, 14, 10, 179, 62, 97, STR_02E6_ROAD_VEHICLES},
|
|
392 |
{ WWT_6, 14, 20, 169, 76, 87, STR_02E7, STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
|
|
393 |
{ WWT_CLOSEBOX, 14, 158, 168, 77, 86, STR_0225, STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
|
|
394 |
{ WWT_FRAME, 14, 190, 359, 62, 97, STR_02EB_TOWN_NAMES},
|
|
395 |
{ WWT_6, 14, 200, 349, 76, 87, STR_02EC, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES},
|
|
396 |
{ WWT_CLOSEBOX, 14, 338, 348, 77, 86, STR_0225, STR_02ED_SELECT_STYLE_OF_TOWN_NAMES},
|
|
397 |
{ WWT_FRAME, 14, 10, 179, 104, 139, STR_02F4_AUTOSAVE},
|
|
398 |
{ WWT_6, 14, 20, 169, 118, 129, STR_02F5, STR_02F6_SELECT_INTERVAL_BETWEEN},
|
|
399 |
{ WWT_CLOSEBOX, 14, 158, 168, 119, 128, STR_0225, STR_02F6_SELECT_INTERVAL_BETWEEN},
|
|
400 |
|
|
401 |
{ WWT_FRAME, 14, 10, 359, 188, 223, STR_02BC_VEHICLE_DESIGN_NAMES},
|
|
402 |
{ WWT_6, 14, 20, 119, 202, 213, STR_02BD, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION},
|
|
403 |
{ WWT_CLOSEBOX, 14, 108, 118, 203, 212, STR_0225, STR_02C1_VEHICLE_DESIGN_NAMES_SELECTION},
|
|
404 |
{ WWT_CLOSEBOX, 14, 130, 349, 202, 213, STR_02C0_SAVE_CUSTOM_NAMES_TO_DISK, STR_02C2_SAVE_CUSTOMIZED_VEHICLE},
|
|
405 |
|
|
406 |
{ WWT_FRAME, 14, 190, 359, 104, 139, STR_OPTIONS_LANG},
|
|
407 |
{ WWT_6, 14, 200, 349, 118, 129, STR_OPTIONS_LANG_CBO, STR_OPTIONS_LANG_TIP},
|
|
408 |
{ WWT_CLOSEBOX, 14, 338, 348, 119, 128, STR_0225, STR_OPTIONS_LANG_TIP},
|
|
409 |
{ WWT_FRAME, 14, 10, 179, 146, 181, STR_OPTIONS_RES},
|
|
410 |
{ WWT_6, 14, 20, 169, 160, 171, STR_OPTIONS_RES_CBO, STR_OPTIONS_RES_TIP},
|
|
411 |
{ WWT_CLOSEBOX, 14, 158, 168, 161, 170, STR_0225, STR_OPTIONS_RES_TIP},
|
|
412 |
|
|
413 |
{ WWT_FRAME, 14, 190, 359, 146, 181, STR_OPTIONS_SCREENSHOT_FORMAT},
|
|
414 |
{ WWT_6, 14, 200, 349, 160, 171, STR_OPTIONS_SCREENSHOT_FORMAT_CBO, STR_OPTIONS_SCREENSHOT_FORMAT_TIP},
|
|
415 |
{ WWT_CLOSEBOX, 14, 338, 348, 161, 170, STR_0225, STR_OPTIONS_SCREENSHOT_FORMAT_TIP},
|
|
416 |
|
|
417 |
{ WWT_LAST},
|
|
418 |
};
|
|
419 |
|
|
420 |
static const WindowDesc _game_options_desc = {
|
|
421 |
WDP_CENTER, WDP_CENTER, 370, 234,
|
|
422 |
WC_GAME_OPTIONS,0,
|
|
423 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESTORE_DPARAM | WDF_UNCLICK_BUTTONS,
|
|
424 |
_game_options_widgets,
|
|
425 |
GameOptionsWndProc
|
|
426 |
};
|
|
427 |
|
|
428 |
|
|
429 |
void ShowGameOptions()
|
|
430 |
{
|
|
431 |
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
432 |
AllocateWindowDesc(&_game_options_desc);
|
|
433 |
}
|
|
434 |
|
|
435 |
typedef struct {
|
|
436 |
int16 min;
|
|
437 |
int16 max;
|
|
438 |
int16 step;
|
|
439 |
StringID str;
|
|
440 |
} GameSettingData;
|
|
441 |
|
|
442 |
static const GameSettingData _game_setting_info[] = {
|
|
443 |
{0,7,1,0},
|
|
444 |
{0,3,1,STR_6830_IMMEDIATE},
|
|
445 |
{0,2,1,STR_6816_LOW},
|
|
446 |
{0,2,1,STR_6816_LOW},
|
|
447 |
{100,500,50,0},
|
|
448 |
{2,4,1,0},
|
|
449 |
{0,2,1,STR_6820_LOW},
|
|
450 |
{0,4,1,STR_681B_VERY_SLOW},
|
|
451 |
{0,2,1,STR_6820_LOW},
|
|
452 |
{0,2,1,STR_6823_NONE},
|
|
453 |
{0,3,1,STR_6826_X1_5},
|
|
454 |
{0,2,1,STR_6820_LOW},
|
|
455 |
{0,3,1,STR_682A_VERY_FLAT},
|
|
456 |
{0,3,1,STR_VERY_LOW},
|
|
457 |
{0,1,1,STR_682E_STEADY},
|
|
458 |
{0,1,1,STR_6834_AT_END_OF_LINE_AND_AT_STATIONS},
|
|
459 |
{0,1,1,STR_6836_OFF},
|
|
460 |
{0,2,1,STR_6839_PERMISSIVE},
|
|
461 |
};
|
|
462 |
|
|
463 |
static bool FORCEINLINE GetBitAndShift(uint32 *b)
|
|
464 |
{
|
|
465 |
uint32 x = *b;
|
|
466 |
*b >>= 1;
|
|
467 |
return (x&1) != 0;
|
|
468 |
}
|
|
469 |
|
|
470 |
static GameOptions _opt_mod_temp;
|
|
471 |
|
|
472 |
static const int16 _default_game_diff[3][GAME_DIFFICULTY_NUM] = {
|
|
473 |
{2, 2, 1, 2, 300, 2, 0, 2, 0, 1, 2, 0, 1, 0, 0, 0, 0, 0},
|
|
474 |
{4, 1, 1, 1, 150, 3, 1, 3, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1},
|
|
475 |
{7, 0, 2, 1, 100, 4, 1, 3, 2, 2, 0, 2, 3, 2, 1, 1, 1, 2},
|
|
476 |
};
|
|
477 |
|
|
478 |
void SetDifficultyLevel(int mode, GameOptions *gm_opt)
|
|
479 |
{
|
|
480 |
int i;
|
|
481 |
assert(mode <= 3);
|
|
482 |
|
|
483 |
gm_opt->diff_level = mode;
|
|
484 |
if (mode != 3) { // not custom
|
|
485 |
for(i = 0; i != GAME_DIFFICULTY_NUM; i++)
|
|
486 |
((int*)&gm_opt->diff)[i] = _default_game_diff[mode][i];
|
|
487 |
}
|
|
488 |
}
|
|
489 |
|
|
490 |
static void GameDifficultyWndProc(Window *w, WindowEvent *e)
|
|
491 |
{
|
|
492 |
switch(e->event) {
|
|
493 |
case WE_PAINT: {
|
|
494 |
uint32 click_a, click_b, disabled;
|
|
495 |
int i;
|
|
496 |
int x,y,value;
|
|
497 |
|
|
498 |
w->click_state = (1 << 4) << _opt_mod_temp.diff_level;
|
|
499 |
w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7);
|
|
500 |
DrawWindowWidgets(w);
|
|
501 |
|
|
502 |
click_a = _difficulty_click_a;
|
|
503 |
click_b = _difficulty_click_b;
|
|
504 |
|
|
505 |
disabled = _game_mode == GM_NORMAL ? 0x383E : 0;
|
|
506 |
// XXX
|
|
507 |
|
|
508 |
x = 0;
|
|
509 |
y = 32;
|
|
510 |
for (i = 0; i != GAME_DIFFICULTY_NUM; i++) {
|
|
511 |
DrawFrameRect(x+5, y+1, x+5+9, y+9, 3, GetBitAndShift(&click_a)?0x20:0);
|
|
512 |
DrawFrameRect(x+15, y+1, x+15+9, y+9, 3, GetBitAndShift(&click_b)?0x20:0);
|
|
513 |
if (GetBitAndShift(&disabled)) {
|
|
514 |
int color = 0x8000 | _color_list[3].unk2;
|
|
515 |
GfxFillRect(x+6, y+2, x+6+8, y+9, color);
|
|
516 |
GfxFillRect(x+16, y+2, x+16+8, y+9, color);
|
|
517 |
}
|
|
518 |
|
|
519 |
DrawStringCentered(x+10, y+1, STR_6819, 0);
|
|
520 |
DrawStringCentered(x+20, y+1, STR_681A, 0);
|
|
521 |
|
|
522 |
|
|
523 |
value = _game_setting_info[i].str + ((int*)&_opt_mod_temp.diff)[i];
|
|
524 |
if (i == 4) value *= 1000; // handle currency option
|
|
525 |
SET_DPARAM32(0, value);
|
|
526 |
DrawString(x+30, y+1, STR_6805_MAXIMUM_NO_COMPETITORS + i, 0);
|
|
527 |
|
|
528 |
y += 11;
|
|
529 |
}
|
|
530 |
} break;
|
|
531 |
|
|
532 |
case WE_CLICK:
|
|
533 |
switch(e->click.widget) {
|
|
534 |
case 3: {
|
|
535 |
int x,y;
|
|
536 |
uint btn, dis;
|
|
537 |
int val;
|
|
538 |
const GameSettingData *info;
|
|
539 |
|
|
540 |
x = e->click.pt.x - 5;
|
|
541 |
if (!IS_INT_INSIDE(x, 0, 21))
|
|
542 |
return;
|
|
543 |
|
|
544 |
y = e->click.pt.y - 33;
|
|
545 |
if (y < 0)
|
|
546 |
return;
|
|
547 |
|
|
548 |
// Get button from Y coord.
|
|
549 |
btn = y / 11;
|
|
550 |
if (btn >= GAME_DIFFICULTY_NUM || y % 11 > 9)
|
|
551 |
return;
|
|
552 |
|
|
553 |
// Clicked disabled button?
|
|
554 |
dis = 0;
|
|
555 |
if (_game_mode == GM_NORMAL)
|
|
556 |
dis |= 0x383E;
|
|
557 |
if (HASBIT(dis, btn))
|
|
558 |
return;
|
|
559 |
|
|
560 |
_difficulty_timeout = 5;
|
|
561 |
|
|
562 |
val = ((int*)&_opt_mod_temp.diff)[btn];
|
|
563 |
|
|
564 |
info = &_game_setting_info[btn];
|
|
565 |
if (x >= 10) {
|
|
566 |
// Increase button clicked
|
|
567 |
val = min(val + info->step, info->max);
|
|
568 |
SETBIT(_difficulty_click_b, btn);
|
|
569 |
} else {
|
|
570 |
// Decrease button clicked
|
|
571 |
val = max(val - info->step, info->min);
|
|
572 |
SETBIT(_difficulty_click_a, btn);
|
|
573 |
}
|
|
574 |
|
|
575 |
// save value in temporary variable
|
|
576 |
((int*)&_opt_mod_temp.diff)[btn] = val;
|
|
577 |
SetDifficultyLevel(3, &_opt_mod_temp); // set difficulty level to custom
|
|
578 |
SetWindowDirty(w);
|
|
579 |
break;
|
|
580 |
}
|
|
581 |
case 4: case 5: case 6: case 7: // easy/medium/hard/custom
|
|
582 |
// temporarily change difficulty level
|
|
583 |
SetDifficultyLevel(e->click.widget - 4, &_opt_mod_temp);
|
|
584 |
SetWindowDirty(w);
|
|
585 |
break;
|
|
586 |
case 8:
|
|
587 |
ShowHighscoreTable(_opt_mod_ptr->diff_level);
|
|
588 |
break;
|
|
589 |
case 10: { // Save button - save changes
|
|
590 |
int btn, val;
|
|
591 |
for (btn = 0; btn != GAME_DIFFICULTY_NUM; btn++) {
|
|
592 |
val = ((int*)&_opt_mod_temp.diff)[btn];
|
|
593 |
// if setting has changed, change it
|
|
594 |
if (val != ((int*)&_opt_mod_ptr->diff)[btn])
|
|
595 |
DoCommandP(0, btn, val, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
|
596 |
}
|
|
597 |
DoCommandP(0, -1, _opt_mod_temp.diff_level, NULL, CMD_CHANGE_DIFFICULTY_LEVEL);
|
|
598 |
DeleteWindow(w);
|
|
599 |
break;
|
|
600 |
}
|
|
601 |
case 11: // Cancel button - close window
|
|
602 |
DeleteWindow(w);
|
|
603 |
break;
|
|
604 |
}
|
|
605 |
break;
|
|
606 |
|
|
607 |
case WE_MOUSELOOP:
|
|
608 |
if (_difficulty_timeout != 0 && !--_difficulty_timeout) {
|
|
609 |
_difficulty_click_a = 0;
|
|
610 |
_difficulty_click_b = 0;
|
|
611 |
SetWindowDirty(w);
|
|
612 |
}
|
|
613 |
break;
|
|
614 |
}
|
|
615 |
}
|
|
616 |
|
|
617 |
static const Widget _game_difficulty_widgets[] = {
|
|
618 |
{ WWT_CLOSEBOX, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
619 |
{ WWT_CAPTION, 10, 11, 369, 0, 13, STR_6800_DIFFICULTY_LEVEL, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
620 |
{ WWT_PANEL, 10, 0, 369, 14, 29, 0x0, 0},
|
|
621 |
{ WWT_PANEL, 10, 0, 369, 30, 276, 0x0, 0},
|
|
622 |
{ WWT_PUSHTXTBTN, 3, 10, 96, 16, 27, STR_6801_EASY, 0},
|
|
623 |
{ WWT_PUSHTXTBTN, 3, 97, 183, 16, 27, STR_6802_MEDIUM, 0},
|
|
624 |
{ WWT_PUSHTXTBTN, 3, 184, 270, 16, 27, STR_6803_HARD, 0},
|
|
625 |
{ WWT_PUSHTXTBTN, 3, 271, 357, 16, 27, STR_6804_CUSTOM, 0},
|
|
626 |
{ WWT_EMPTY, 10, 0, 369, 251, 262, 0x0, 0},
|
|
627 |
//{ WWT_CLOSEBOX, 10, 0, 369, 251, 262, STR_6838_SHOW_HI_SCORE_CHART, 0},
|
|
628 |
{ WWT_PANEL, 10, 0, 369, 263, 278, 0x0, 0},
|
|
629 |
{ WWT_PUSHTXTBTN, 3, 105, 185, 265, 276, STR_OPTIONS_SAVE_CHANGES, 0},
|
|
630 |
{ WWT_PUSHTXTBTN, 3, 186, 266, 265, 276, STR_012E_CANCEL, 0},
|
|
631 |
{ WWT_LAST},
|
|
632 |
};
|
|
633 |
|
|
634 |
static const WindowDesc _game_difficulty_desc = {
|
|
635 |
WDP_CENTER, WDP_CENTER, 370, 279,
|
|
636 |
WC_GAME_OPTIONS,0,
|
|
637 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
638 |
_game_difficulty_widgets,
|
|
639 |
GameDifficultyWndProc
|
|
640 |
};
|
|
641 |
|
|
642 |
void ShowGameDifficulty()
|
|
643 |
{
|
|
644 |
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
645 |
/* copy current settings to temporary holding place
|
|
646 |
* change that when setting stuff, copy back on clicking 'OK'
|
|
647 |
*/
|
|
648 |
memcpy(&_opt_mod_temp, _opt_mod_ptr, sizeof(GameOptions));
|
|
649 |
AllocateWindowDesc(&_game_difficulty_desc);
|
|
650 |
}
|
|
651 |
|
|
652 |
void ShowHighscoreTable(int tbl)
|
|
653 |
{
|
|
654 |
ShowInfoF("ShowHighscoreTable(%d) not implemented", tbl);
|
|
655 |
}
|
|
656 |
|
|
657 |
typedef struct PatchEntry {
|
|
658 |
byte type; // type of selector
|
|
659 |
byte flags; // selector flags
|
|
660 |
StringID str; // string with descriptive text
|
|
661 |
void *variable; // pointer to the variable
|
|
662 |
int16 min,max; // range for spinbox setting
|
|
663 |
uint16 step; // step for spinbox
|
|
664 |
} PatchEntry;
|
|
665 |
|
|
666 |
enum {
|
|
667 |
PE_BOOL = 0,
|
|
668 |
PE_UINT8 = 1,
|
|
669 |
PE_INT16 = 2,
|
|
670 |
PE_UINT16 = 3,
|
|
671 |
PE_INT32 = 4,
|
|
672 |
PE_BYTE = 5,
|
|
673 |
|
|
674 |
PF_0ISDIS = 1,
|
|
675 |
PF_NOCOMMA = 2,
|
|
676 |
};
|
|
677 |
|
|
678 |
static const PatchEntry _patches_ui[] = {
|
|
679 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_VEHICLESPEED, &_patches.vehicle_speed},
|
|
680 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_LONGDATE, &_patches.status_long_date},
|
|
681 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SHOWFINANCES, &_patches.show_finances},
|
|
682 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_AUTOSCROLL, &_patches.autoscroll},
|
|
683 |
|
|
684 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_ERRMSG_DURATION, &_patches.errmsg_duration, 0, 20, 1},
|
|
685 |
|
|
686 |
};
|
|
687 |
|
|
688 |
static const PatchEntry _patches_construction[] = {
|
|
689 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_BUILDONSLOPES, &_patches.build_on_slopes},
|
|
690 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_EXTRADYNAMITE, &_patches.extra_dynamite},
|
|
691 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_LONGBRIDGES, &_patches.longbridges},
|
|
692 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SIGNALSIDE, &_patches.signal_side},
|
|
693 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_BUILD_IN_PAUSE, &_patches.build_in_pause},
|
|
694 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SMALL_AIRPORTS, &_patches.always_small_airport},
|
|
695 |
|
|
696 |
};
|
|
697 |
|
|
698 |
static const PatchEntry _patches_vehicles[] = {
|
|
699 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_REALISTICACCEL, &_patches.realistic_acceleration},
|
|
700 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_MAMMOTHTRAINS, &_patches.mammoth_trains},
|
|
701 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NOTRAINSERVICE, &_patches.no_train_service},
|
|
702 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_GOTODEPOT, &_patches.gotodepot},
|
|
703 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_ROADVEH_QUEUE, &_patches.roadveh_queue},
|
|
704 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_DEPOT_FINDING, &_patches.new_depot_finding},
|
|
705 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_TRAIN_PATHFIND, &_patches.new_pathfinding},
|
|
706 |
|
|
707 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_WARN_INCOME_LESS, &_patches.train_income_warn},
|
|
708 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NEVER_EXPIRE_VEHICLES, &_patches.never_expire_vehicles},
|
|
709 |
|
|
710 |
{PE_UINT16, PF_0ISDIS, STR_CONFIG_PATCHES_LOST_TRAIN_DAYS, &_patches.lost_train_days, 180, 720, 60},
|
|
711 |
{PE_BOOL, 0, STR_CONFIG_AUTORENEW_VEHICLE, &_patches.autorenew},
|
|
712 |
|
|
713 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_TRAINS, &_patches.max_trains, 0, 240, 10},
|
|
714 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_ROADVEH, &_patches.max_roadveh, 0, 240, 10},
|
|
715 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_AIRCRAFT, &_patches.max_aircraft, 0, 240, 10},
|
|
716 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_MAX_SHIPS, &_patches.max_ships, 0, 240, 10},
|
|
717 |
|
|
718 |
{PE_UINT16, 0, STR_CONFIG_PATCHES_SERVINT_TRAINS, &_patches.servint_trains, 0, 1200, 10},
|
|
719 |
{PE_UINT16, 0, STR_CONFIG_PATCHES_SERVINT_ROADVEH, &_patches.servint_roadveh, 0, 1200, 10},
|
|
720 |
{PE_UINT16, 0, STR_CONFIG_PATCHES_SERVINT_AIRCRAFT, &_patches.servint_aircraft, 0, 1200, 10},
|
|
721 |
{PE_UINT16, 0, STR_CONFIG_PATCHES_SERVINT_SHIPS, &_patches.servint_ships, 0, 1200, 10},
|
|
722 |
|
|
723 |
{PE_BYTE, 0, STR_CONFIG_PATCHES_AI_BUILDS_TRAINS, &_patches.ai_disable_veh, 0x01},
|
|
724 |
{PE_BYTE, 0, STR_CONFIG_PATCHES_AI_BUILDS_ROADVEH, &_patches.ai_disable_veh, 0x02},
|
|
725 |
{PE_BYTE, 0, STR_CONFIG_PATCHES_AI_BUILDS_AIRCRAFT, &_patches.ai_disable_veh, 0x04},
|
|
726 |
{PE_BYTE, 0, STR_CONFIG_PATCHES_AI_BUILDS_SHIPS, &_patches.ai_disable_veh, 0x08},
|
|
727 |
};
|
|
728 |
|
|
729 |
static const PatchEntry _patches_stations[] = {
|
|
730 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_JOINSTATIONS, &_patches.join_stations},
|
|
731 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_FULLLOADANY, &_patches.full_load_any},
|
|
732 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SELECTGOODS, &_patches.selectgoods},
|
|
733 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NEW_NONSTOP, &_patches.new_nonstop},
|
|
734 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_NONUNIFORM_STATIONS, &_patches.nonuniform_stations},
|
|
735 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_STATION_SPREAD, &_patches.station_spread, 4, 64, 1},
|
|
736 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SERVICEATHELIPAD, &_patches.serviceathelipad},
|
|
737 |
};
|
|
738 |
|
|
739 |
static const PatchEntry _patches_economy[] = {
|
|
740 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_INFLATION, &_patches.inflation},
|
|
741 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_BUILDXTRAIND, &_patches.build_rawmaterial_ind},
|
|
742 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_MULTIPINDTOWN, &_patches.multiple_industry_per_town},
|
|
743 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SAMEINDCLOSE, &_patches.same_industry_close},
|
|
744 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_BRIBE, &_patches.bribe},
|
|
745 |
{PE_UINT8, 0, STR_CONFIG_PATCHES_SNOWLINE_HEIGHT, &_patches.snow_line_height, 2, 13, 1},
|
|
746 |
|
|
747 |
{PE_INT32, PF_NOCOMMA, STR_CONFIG_PATCHES_COLORED_NEWS_DATE, &_patches.colored_news_date, 1900, 2200, 5},
|
|
748 |
{PE_INT32, PF_NOCOMMA, STR_CONFIG_PATCHES_STARTING_DATE, &_patches.starting_date, 1920, 2100, 1},
|
|
749 |
|
|
750 |
{PE_BOOL, 0, STR_CONFIG_PATCHES_SMOOTH_ECONOMY, &_patches.smooth_economy},
|
|
751 |
};
|
|
752 |
|
|
753 |
typedef struct PatchPage {
|
|
754 |
const PatchEntry *entries;
|
|
755 |
uint num;
|
|
756 |
} PatchPage;
|
|
757 |
|
|
758 |
static const PatchPage _patches_page[] = {
|
|
759 |
{_patches_ui, lengthof(_patches_ui) },
|
|
760 |
{_patches_construction, lengthof(_patches_construction) },
|
|
761 |
{_patches_vehicles, lengthof(_patches_vehicles) },
|
|
762 |
{_patches_stations, lengthof(_patches_stations) },
|
|
763 |
{_patches_economy, lengthof(_patches_economy) },
|
|
764 |
};
|
|
765 |
|
|
766 |
static int32 ReadPE(const PatchEntry*pe)
|
|
767 |
{
|
|
768 |
switch(pe->type) {
|
|
769 |
case PE_BOOL: return *(bool*)pe->variable;
|
|
770 |
case PE_UINT8: return *(uint8*)pe->variable;
|
|
771 |
case PE_INT16: return *(int16*)pe->variable;
|
|
772 |
case PE_UINT16: return *(uint16*)pe->variable;
|
|
773 |
case PE_INT32: return *(int32*)pe->variable;
|
|
774 |
case PE_BYTE: return *(byte*)pe->variable;
|
|
775 |
default:
|
|
776 |
NOT_REACHED();
|
|
777 |
}
|
|
778 |
|
|
779 |
/* useless, but avoids compiler warning this way */
|
|
780 |
return 0;
|
|
781 |
}
|
|
782 |
|
|
783 |
static void WritePE(const PatchEntry *pe, int32 val)
|
|
784 |
{
|
|
785 |
switch(pe->type) {
|
|
786 |
case PE_BOOL: *(bool*)pe->variable = (bool)val; break;
|
|
787 |
case PE_BYTE: *(byte*)pe->variable = (byte)val; break;
|
|
788 |
case PE_UINT8: *(uint8*)pe->variable = (uint8)val; break;
|
|
789 |
case PE_INT16: *(int16*)pe->variable = (int16)val; break;
|
|
790 |
case PE_UINT16: *(uint16*)pe->variable = (uint16)val; break;
|
|
791 |
case PE_INT32: *(int32*)pe->variable = val; break;
|
|
792 |
default:
|
|
793 |
NOT_REACHED();
|
|
794 |
}
|
|
795 |
}
|
|
796 |
|
|
797 |
static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
|
|
798 |
{
|
|
799 |
uint i;
|
|
800 |
switch(e->event) {
|
|
801 |
case WE_PAINT: {
|
|
802 |
int x,y;
|
|
803 |
const PatchEntry *pe;
|
|
804 |
const PatchPage *page;
|
|
805 |
uint clk;
|
|
806 |
int32 val;
|
|
807 |
|
|
808 |
w->click_state = 1 << (WP(w,def_d).data_1 + 4);
|
|
809 |
|
|
810 |
DrawWindowWidgets(w);
|
|
811 |
|
|
812 |
x = 0;
|
|
813 |
y = 46;
|
|
814 |
clk = WP(w,def_d).data_2;
|
|
815 |
page = &_patches_page[WP(w,def_d).data_1];
|
|
816 |
for(i=0,pe=page->entries; i!=page->num; i++,pe++) {
|
|
817 |
if (pe->type == PE_BOOL) {
|
|
818 |
DrawFrameRect(x+5, y+1, x+15+9, y+9, (*(bool*)pe->variable)?6:4, (*(bool*)pe->variable)?0x20:0);
|
|
819 |
SET_DPARAM16(0, *(bool*)pe->variable ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
|
|
820 |
} else if (pe->type == PE_BYTE) {
|
|
821 |
bool enabled;
|
|
822 |
val = ReadPE(pe);
|
|
823 |
enabled = (byte)val & (byte)pe->min;
|
|
824 |
DrawFrameRect(x+5, y+1, x+15+9, y+9, enabled?6:4, enabled?0x20:0);
|
|
825 |
SET_DPARAM16(0, enabled ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
|
|
826 |
} else {
|
|
827 |
DrawFrameRect(x+5, y+1, x+5+9, y+9, 3, clk == i*2+1 ? 0x20 : 0);
|
|
828 |
DrawFrameRect(x+15, y+1, x+15+9, y+9, 3, clk == i*2+2 ? 0x20 : 0);
|
|
829 |
DrawStringCentered(x+10, y+1, STR_6819, 0);
|
|
830 |
DrawStringCentered(x+20, y+1, STR_681A, 0);
|
|
831 |
|
|
832 |
val = ReadPE(pe);
|
|
833 |
if (val == 0 && pe->flags & PF_0ISDIS) {
|
|
834 |
SET_DPARAM16(0, STR_CONFIG_PATCHES_DISABLED);
|
|
835 |
} else {
|
|
836 |
SET_DPARAM32(1, val);
|
|
837 |
SET_DPARAM16(0, pe->flags & PF_NOCOMMA ? STR_CONFIG_PATCHES_INT32 : STR_7024);
|
|
838 |
}
|
|
839 |
}
|
|
840 |
DrawString(30, y+1, pe->str, 0);
|
|
841 |
y += 11;
|
|
842 |
}
|
|
843 |
break;
|
|
844 |
}
|
|
845 |
|
|
846 |
case WE_CLICK:
|
|
847 |
switch(e->click.widget) {
|
|
848 |
case 3: {
|
|
849 |
int x,y;
|
|
850 |
uint btn;
|
|
851 |
const PatchPage *page;
|
|
852 |
const PatchEntry *pe;
|
|
853 |
|
|
854 |
y = e->click.pt.y - 46 - 1;
|
|
855 |
if (y < 0) return;
|
|
856 |
|
|
857 |
btn = y / 11;
|
|
858 |
if (y % 11 > 9) return;
|
|
859 |
|
|
860 |
page = &_patches_page[WP(w,def_d).data_1];
|
|
861 |
if (btn >= page->num) return;
|
|
862 |
pe = &page->entries[btn];
|
|
863 |
|
|
864 |
x = e->click.pt.x - 5;
|
|
865 |
if (x < 0) return;
|
|
866 |
|
|
867 |
if (x < 21) {
|
|
868 |
int32 val = ReadPE(pe), oval = val;
|
|
869 |
|
|
870 |
switch(pe->type) {
|
|
871 |
case PE_BOOL:
|
|
872 |
val ^= 1;
|
|
873 |
break;
|
|
874 |
case PE_BYTE:
|
|
875 |
val ^= pe->min;
|
|
876 |
break;
|
|
877 |
case PE_UINT8:
|
|
878 |
case PE_INT16:
|
|
879 |
case PE_UINT16:
|
|
880 |
case PE_INT32:
|
|
881 |
// don't allow too fast scrolling
|
|
882 |
if ((w->flags4 & WF_TIMEOUT_MASK) > 2 << WF_TIMEOUT_SHL) {
|
|
883 |
_left_button_clicked = false;
|
|
884 |
return;
|
|
885 |
}
|
|
886 |
|
|
887 |
if (x >= 10) {
|
|
888 |
//increase
|
|
889 |
if (pe->flags & PF_0ISDIS && val == 0)
|
|
890 |
val = pe->min;
|
|
891 |
else
|
|
892 |
val += pe->step;
|
|
893 |
if (val > pe->max) val = pe->max;
|
|
894 |
} else {
|
|
895 |
if (val <= pe->min && pe->flags & PF_0ISDIS) {
|
|
896 |
val = 0;
|
|
897 |
} else {
|
|
898 |
// decrease
|
|
899 |
val -= pe->step;
|
|
900 |
if (val < pe->min) val = pe->min;
|
|
901 |
}
|
|
902 |
}
|
|
903 |
|
|
904 |
if (val != oval) {
|
|
905 |
WP(w,def_d).data_2 = btn * 2 + 1 + ((x>=10) ? 1 : 0);
|
|
906 |
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
907 |
_left_button_clicked = false;
|
|
908 |
}
|
|
909 |
break;
|
|
910 |
}
|
|
911 |
if (val != oval) {
|
|
912 |
WritePE(pe, val);
|
|
913 |
SetWindowDirty(w);
|
|
914 |
}
|
|
915 |
} else {
|
|
916 |
if (pe->type != PE_BOOL) {
|
|
917 |
WP(w,def_d).data_3 = btn;
|
|
918 |
SET_DPARAM32(0, ReadPE(pe));
|
|
919 |
ShowQueryString(STR_CONFIG_PATCHES_INT32, STR_CONFIG_PATCHES_QUERY_CAPT, 10, 100, WC_GAME_OPTIONS, 0);
|
|
920 |
}
|
|
921 |
}
|
|
922 |
|
|
923 |
break;
|
|
924 |
}
|
|
925 |
case 4: case 5: case 6: case 7: case 8:
|
|
926 |
WP(w,def_d).data_1 = e->click.widget - 4;
|
|
927 |
DeleteWindowById(WC_QUERY_STRING, 0);
|
|
928 |
SetWindowDirty(w);
|
|
929 |
break;
|
|
930 |
}
|
|
931 |
break;
|
|
932 |
|
|
933 |
case WE_TIMEOUT:
|
|
934 |
WP(w,def_d).data_2 = 0;
|
|
935 |
SetWindowDirty(w);
|
|
936 |
break;
|
|
937 |
|
|
938 |
case WE_ON_EDIT_TEXT: {
|
|
939 |
if (*e->edittext.str) {
|
|
940 |
const PatchPage *page = &_patches_page[WP(w,def_d).data_1];
|
|
941 |
WritePE(&page->entries[WP(w,def_d).data_3], atoi(e->edittext.str));
|
|
942 |
SetWindowDirty(w);
|
|
943 |
}
|
|
944 |
break;
|
|
945 |
}
|
|
946 |
|
|
947 |
case WE_DESTROY:
|
|
948 |
DeleteWindowById(WC_QUERY_STRING, 0);
|
|
949 |
break;
|
|
950 |
}
|
|
951 |
}
|
|
952 |
|
|
953 |
static const Widget _patches_selection_widgets[] = {
|
|
954 |
{ WWT_CLOSEBOX, 10, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
955 |
{ WWT_CAPTION, 10, 11, 369, 0, 13, STR_CONFIG_PATCHES_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
956 |
{ WWT_PANEL, 10, 0, 369, 14, 41, 0x0, 0},
|
|
957 |
{ WWT_PANEL, 10, 0, 369, 42, 320, 0x0, 0},
|
|
958 |
|
|
959 |
{ WWT_CLOSEBOX, 3, 10, 96, 16, 27, STR_CONFIG_PATCHES_GUI, 0},
|
|
960 |
{ WWT_CLOSEBOX, 3, 97, 183, 16, 27, STR_CONFIG_PATCHES_CONSTRUCTION, 0},
|
|
961 |
{ WWT_CLOSEBOX, 3, 184, 270, 16, 27, STR_CONFIG_PATCHES_VEHICLES, 0},
|
|
962 |
{ WWT_CLOSEBOX, 3, 271, 357, 16, 27, STR_CONFIG_PATCHES_STATIONS, 0},
|
|
963 |
{ WWT_CLOSEBOX, 3, 10, 96, 28, 39, STR_CONFIG_PATCHES_ECONOMY, 0},
|
|
964 |
{ WWT_LAST},
|
|
965 |
};
|
|
966 |
|
|
967 |
static const WindowDesc _patches_selection_desc = {
|
|
968 |
WDP_CENTER, WDP_CENTER, 370, 321,
|
|
969 |
WC_GAME_OPTIONS,0,
|
|
970 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
971 |
_patches_selection_widgets,
|
|
972 |
PatchesSelectionWndProc,
|
|
973 |
};
|
|
974 |
|
|
975 |
void ShowPatchesSelection()
|
|
976 |
{
|
|
977 |
DeleteWindowById(WC_GAME_OPTIONS, 0);
|
|
978 |
AllocateWindowDesc(&_patches_selection_desc);
|
|
979 |
}
|