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