forked from fesh0r/newkind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.c
366 lines (285 loc) · 6.42 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/*
* Elite - The New Kind.
*
* Reverse engineered from the BBC disk version of Elite.
* Additional material by C.J.Pinder.
*
* The original Elite code is (C) I.Bell & D.Braben 1984.
* This version re-engineered in C by C.J.Pinder 1999-2001.
*
* email: <christian@newkind.co.uk>
*
*
*/
/*
* Options.c
*/
#include <stdlib.h>
#include <string.h>
#include "elite.h"
#include "config.h"
#include "gfx.h"
#include "options.h"
#include "main.h"
#include "docked.h"
#include "file.h"
static int hilite_item;
#define NUM_OPTIONS 4
#define NUM_SETTINGS 6
#define OPTION_BAR_WIDTH (400)
#define OPTION_BAR_HEIGHT (15)
struct option
{
char *text;
int docked_only;
};
static struct option option_list[NUM_OPTIONS] =
{
{"Save Commander", 1},
{"Load Commander", 1},
{"Game Settings", 0},
{"Quit", 0}
};
struct setting
{
char *name;
char *value[5];
};
static struct setting setting_list[NUM_SETTINGS] =
{
{"Graphics:", {"Solid", "Wireframe", "", "", ""}},
{"Anti Alias:", {"Off", "On", "", "", ""}},
{"Planet Style:", {"Wireframe", "Green", "SNES", "Fractal", ""}},
{"Planet Desc.:", {"BBC", "MSX", "", "", ""}},
{"Instant Dock:", {"Off", "On", "", "", ""}},
{"Save Settings", {"", "", "", "", ""}}
};
void quit_screen (void)
{
current_screen = SCR_QUIT;
gfx_clear_display();
gfx_display_centre_text (10, "GAME OPTIONS", 140, GFX_COL_GOLD);
gfx_draw_line (0, 36, 511, 36);
gfx_display_centre_text (175, "QUIT GAME (Y/N)?", 140, GFX_COL_GOLD);
}
void display_setting_item (int item)
{
int x,y;
int v;
if (item == (NUM_SETTINGS - 1))
{
y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
gfx_display_centre_text (y, setting_list[item].name, 120, GFX_COL_WHITE);
return;
}
switch (item)
{
case 0:
v = wireframe;
break;
case 1:
v = anti_alias_gfx;
break;
case 2:
v = planet_render_style;
break;
case 3:
v = hoopy_casinos;
break;
case 4:
v = instant_dock;
break;
default:
v = 0;
break;
}
x = (item & 1) * 250 + 32;
y = (item / 2) * 30 + 96;
gfx_display_colour_text (x, y, setting_list[item].name, GFX_COL_WHITE);
gfx_display_colour_text (x + 120, y, setting_list[item].value[v], GFX_COL_WHITE);
}
void highlight_setting (int item)
{
int x,y;
int width;
if ((hilite_item != -1) && (hilite_item != item))
{
if (hilite_item == (NUM_SETTINGS - 1))
{
x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
width = OPTION_BAR_WIDTH;
}
else
{
x = (hilite_item & 1) * 250 + 32 + 120;
y = (hilite_item / 2) * 30 + 96;
width = 100;
}
gfx_clear_area (x, y, x + width, y + OPTION_BAR_HEIGHT);
display_setting_item (hilite_item);
}
if (item == (NUM_SETTINGS - 1))
{
x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
width = OPTION_BAR_WIDTH;
}
else
{
x = (item & 1) * 250 + 32 + 120;
y = (item / 2) * 30 + 96;
width = 100;
}
gfx_draw_rectangle (x, y, x + width, y + OPTION_BAR_HEIGHT, GFX_COL_DARK_RED);
display_setting_item (item);
hilite_item = item;
}
void select_left_setting (void)
{
if ((hilite_item & 1) != 0)
highlight_setting (hilite_item - 1);
}
void select_right_setting (void)
{
if (((hilite_item & 1) == 0) && (hilite_item < (NUM_SETTINGS - 1)))
highlight_setting (hilite_item + 1);
}
void select_up_setting (void)
{
if (hilite_item == (NUM_SETTINGS - 1))
{
highlight_setting (NUM_SETTINGS - 2);
return;
}
if (hilite_item > 1)
highlight_setting (hilite_item - 2);
}
void select_down_setting (void)
{
if (hilite_item == (NUM_SETTINGS - 2))
{
highlight_setting (NUM_SETTINGS - 1);
return;
}
if (hilite_item < (NUM_SETTINGS - 2))
highlight_setting (hilite_item + 2);
}
void toggle_setting (void)
{
if (hilite_item == (NUM_SETTINGS - 1))
{
write_config_file();
display_options();
return;
}
switch (hilite_item)
{
case 0:
wireframe ^= 1;
break;
case 1:
anti_alias_gfx ^= 1;
break;
case 2:
planet_render_style = (planet_render_style + 1) % 4;
break;
case 3:
hoopy_casinos ^= 1;
break;
case 4:
instant_dock ^= 1;
break;
}
highlight_setting (hilite_item);
}
void game_settings_screen (void)
{
int i;
current_screen = SCR_SETTINGS;
gfx_clear_display();
gfx_display_centre_text (10, "GAME SETTINGS", 140, GFX_COL_GOLD);
gfx_draw_line (0, 36, 511, 36);
for (i = 0; i < NUM_SETTINGS; i++)
{
display_setting_item (i);
}
hilite_item = -1;
highlight_setting (0);
}
void display_option_item (int i)
{
int y;
int col;
y = (384 - (30 * NUM_OPTIONS)) / 2;
y += i * 30;
col = ((!docked) && option_list[i].docked_only) ? GFX_COL_GREY_1 : GFX_COL_WHITE;
gfx_display_centre_text (y, option_list[i].text, 120, col);
}
void highlight_option (int i)
{
int y;
int x;
if ((hilite_item != -1) && (hilite_item != i))
{
x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
y = (384 - (30 * NUM_OPTIONS)) / 2;
y += hilite_item * 30;
gfx_clear_area (x, y, x + OPTION_BAR_WIDTH, y + OPTION_BAR_HEIGHT);
display_option_item (hilite_item);
}
x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
y = (384 - (30 * NUM_OPTIONS)) / 2;
y += i * 30;
gfx_draw_rectangle (x, y, x + OPTION_BAR_WIDTH, y + OPTION_BAR_HEIGHT,
GFX_COL_DARK_RED);
display_option_item (i);
hilite_item = i;
}
void select_previous_option (void)
{
if (hilite_item > 0)
highlight_option (hilite_item - 1);
}
void select_next_option (void)
{
if (hilite_item < (NUM_OPTIONS - 1))
highlight_option (hilite_item + 1);
}
void do_option (void)
{
if ((!docked) && option_list[hilite_item].docked_only)
return;
switch (hilite_item)
{
case 0:
save_commander_screen();
break;
case 1:
load_commander_screen();
display_commander_status();
break;
case 2:
game_settings_screen();
break;
case 3:
quit_screen();
break;
}
}
void display_options (void)
{
int i;
current_screen = SCR_OPTIONS;
gfx_clear_display();
gfx_display_centre_text (10, "GAME OPTIONS", 140, GFX_COL_GOLD);
gfx_draw_line (0, 36, 511, 36);
gfx_display_centre_text (300, "Version: Release 1.0", 120, GFX_COL_WHITE);
gfx_display_centre_text (320, "www.newkind.co.uk", 120, GFX_COL_WHITE);
gfx_display_centre_text (340, "Written by Christian Pinder 1999-2001", 120, GFX_COL_WHITE);
gfx_display_centre_text (360, "Based on original code by Ian Bell & David Braben", 120, GFX_COL_WHITE);
for (i = 0; i < NUM_OPTIONS; i++)
display_option_item (i);
hilite_item = -1;
highlight_option (0);
}