2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
27 /*---------------------------------------------------------------------------*/
52 static int music_id
[11];
53 static int sound_id
[11];
55 static int conf_action(int i
)
57 int f
= config_get_d(CONFIG_FULLSCREEN
);
58 int w
= config_get_d(CONFIG_WIDTH
);
59 int h
= config_get_d(CONFIG_HEIGHT
);
60 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
61 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
64 audio_play(AUD_MENU
, 1.0f
);
70 r
= config_mode(1, w
, h
);
76 r
= config_mode(0, w
, h
);
82 r
= config_mode(f
, 1600, 1200);
88 r
= config_mode(f
, 1280, 1024);
94 r
= config_mode(f
, 1024, 768);
100 r
= config_mode(f
, 800, 600);
101 goto_state(&st_conf
);
105 goto_state(&st_null
);
106 r
= config_mode(f
, 640, 480);
107 goto_state(&st_conf
);
111 goto_state(&st_null
);
112 config_set_d(CONFIG_TEXTURES
, 1);
113 goto_state(&st_conf
);
117 goto_state(&st_null
);
118 config_set_d(CONFIG_TEXTURES
, 2);
119 goto_state(&st_conf
);
123 goto_state(&st_null
);
124 config_set_d(CONFIG_GEOMETRY
, 1);
125 goto_state(&st_conf
);
129 goto_state(&st_null
);
130 config_set_d(CONFIG_GEOMETRY
, 0);
131 goto_state(&st_conf
);
135 goto_state(&st_null
);
136 config_set_d(CONFIG_REFLECTION
, 1);
137 goto_state(&st_conf
);
141 goto_state(&st_null
);
142 config_set_d(CONFIG_REFLECTION
, 0);
143 goto_state(&st_conf
);
147 goto_state(&st_null
);
148 config_set_d(CONFIG_BACKGROUND
, 1);
149 goto_state(&st_conf
);
153 goto_state(&st_null
);
154 config_set_d(CONFIG_BACKGROUND
, 0);
155 goto_state(&st_conf
);
159 goto_state(&st_null
);
160 config_set_d(CONFIG_SHADOW
, 1);
161 goto_state(&st_conf
);
165 goto_state(&st_null
);
166 config_set_d(CONFIG_SHADOW
, 0);
167 goto_state(&st_conf
);
172 config_set_d(CONFIG_AUDIO_RATE
, 44100);
173 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_HI
);
174 gui_toggle(audlo_id
);
175 gui_toggle(audhi_id
);
181 config_set_d(CONFIG_AUDIO_RATE
, 22050);
182 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_LO
);
183 gui_toggle(audlo_id
);
184 gui_toggle(audhi_id
);
189 goto_state(&st_title
);
193 if (100 <= i
&& i
<= 110)
197 config_set_d(CONFIG_SOUND_VOLUME
, n
);
199 audio_play(AUD_BUMP
, 1.f
);
201 gui_toggle(sound_id
[n
]);
202 gui_toggle(sound_id
[s
]);
204 if (200 <= i
&& i
<= 210)
208 config_set_d(CONFIG_MUSIC_VOLUME
, n
);
210 audio_play(AUD_BUMP
, 1.f
);
212 gui_toggle(music_id
[n
]);
213 gui_toggle(music_id
[m
]);
220 static int conf_enter(void)
224 back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY
));
226 /* Initialize the configuration GUI. */
228 if ((id
= gui_harray(0)))
230 if ((jd
= gui_varray(id
)))
232 int w
= config_get_d(CONFIG_WIDTH
);
233 int t
= config_get_d(CONFIG_TEXTURES
);
234 int g
= config_get_d(CONFIG_GEOMETRY
);
235 int r
= config_get_d(CONFIG_REFLECTION
);
236 int b
= config_get_d(CONFIG_BACKGROUND
);
237 int h
= config_get_d(CONFIG_SHADOW
);
238 int a
= config_get_d(CONFIG_AUDIO_RATE
);
239 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
240 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
242 if ((kd
= gui_harray(jd
)))
244 gui_label(kd
, "Options", GUI_SML
, GUI_ALL
, 0, 0);
248 /* Add mode selectors only for existing modes. */
250 if (SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE
))
251 gui_state(jd
, "1600 x 1200", GUI_SML
, CONF_16x12
, (w
== 1600));
252 if (SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE
))
253 gui_state(jd
, "1280 x 1024", GUI_SML
, CONF_12x10
, (w
== 1280));
254 if (SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE
))
255 gui_state(jd
, "1024 x 768", GUI_SML
, CONF_10x7
, (w
== 1024));
256 if (SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE
))
257 gui_state(jd
, "800 x 600", GUI_SML
, CONF_8x6
, (w
== 800));
258 if (SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE
))
259 gui_state(jd
, "640 x 480", GUI_SML
, CONF_6x4
, (w
== 640));
261 if ((kd
= gui_harray(jd
)))
263 gui_state(kd
, "Low", GUI_SML
, CONF_TEXLO
, (t
== 2));
264 gui_state(kd
, "High", GUI_SML
, CONF_TEXHI
, (t
== 1));
266 if ((kd
= gui_harray(jd
)))
268 gui_state(kd
, "Low", GUI_SML
, CONF_GEOLO
, (g
== 0));
269 gui_state(kd
, "High", GUI_SML
, CONF_GEOHI
, (g
== 1));
271 if ((kd
= gui_harray(jd
)))
273 gui_state(kd
, "Off", GUI_SML
, CONF_REFOF
, (r
== 0));
274 gui_state(kd
, "On", GUI_SML
, CONF_REFON
, (r
== 1));
276 if ((kd
= gui_harray(jd
)))
278 gui_state(kd
, "Off", GUI_SML
, CONF_BACOF
, (b
== 0));
279 gui_state(kd
, "On", GUI_SML
, CONF_BACON
, (b
== 1));
281 if ((kd
= gui_harray(jd
)))
283 gui_state(kd
, "Off", GUI_SML
, CONF_SHDOF
, (h
== 0));
284 gui_state(kd
, "On", GUI_SML
, CONF_SHDON
, (h
== 1));
286 if ((kd
= gui_harray(jd
)))
288 int lo
= (a
== 22050);
289 int hi
= (a
== 44100);
291 audlo_id
= gui_state(kd
, "Low", GUI_SML
, CONF_AUDLO
, lo
);
292 audhi_id
= gui_state(kd
, "High", GUI_SML
, CONF_AUDHI
, hi
);
294 if ((kd
= gui_harray(jd
)))
296 /* A series of empty buttons forms the sound volume control. */
298 sound_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 110, (s
== 10));
299 sound_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 109, (s
== 9));
300 sound_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 108, (s
== 8));
301 sound_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 107, (s
== 7));
302 sound_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 106, (s
== 6));
303 sound_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 105, (s
== 5));
304 sound_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 104, (s
== 4));
305 sound_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 103, (s
== 3));
306 sound_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 102, (s
== 2));
307 sound_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 101, (s
== 1));
308 sound_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 100, (s
== 0));
310 if ((kd
= gui_harray(jd
)))
312 /* A series of empty buttons forms the music volume control. */
314 music_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 210, (m
== 10));
315 music_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 209, (m
== 9));
316 music_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 208, (m
== 8));
317 music_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 207, (m
== 7));
318 music_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 206, (m
== 6));
319 music_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 205, (m
== 5));
320 music_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 204, (m
== 4));
321 music_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 203, (m
== 3));
322 music_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 202, (m
== 2));
323 music_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 201, (m
== 1));
324 music_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 200, (m
== 0));
327 if ((jd
= gui_vstack(id
)))
329 int f
= config_get_d(CONFIG_FULLSCREEN
);
331 if ((kd
= gui_harray(jd
)))
334 gui_start(kd
, "Back", GUI_SML
, CONF_BACK
, 0);
337 gui_state(jd
, "Fullscreen", GUI_SML
, CONF_FULL
, (f
== 1));
338 gui_state(jd
, "Window", GUI_SML
, CONF_WIN
, (f
== 0));
340 /* This filler expands to accomodate an unknown number of modes. */
343 gui_label(jd
, "Textures", GUI_SML
, GUI_ALL
, 0, 0);
344 gui_label(jd
, "Geometry", GUI_SML
, GUI_ALL
, 0, 0);
345 gui_label(jd
, "Reflection", GUI_SML
, GUI_ALL
, 0, 0);
346 gui_label(jd
, "Background", GUI_SML
, GUI_ALL
, 0, 0);
347 gui_label(jd
, "Shadow", GUI_SML
, GUI_ALL
, 0, 0);
348 gui_label(jd
, "Audio", GUI_SML
, GUI_ALL
, 0, 0);
349 gui_label(jd
, "Sound Volume", GUI_SML
, GUI_ALL
, 0, 0);
350 gui_label(jd
, "Music Volume", GUI_SML
, GUI_ALL
, 0, 0);
352 gui_layout(id
, 0, 0);
355 audio_music_fade_to(0.5f
, "bgm/inter.ogg");
360 static void conf_leave(int id
)
366 static void conf_paint(int id
, float st
)
368 config_push_persp((float) config_get_d(CONFIG_VIEW_FOV
), 0.1f
, FAR_DIST
);
376 static void conf_timer(int id
, float dt
)
382 static void conf_point(int id
, int x
, int y
, int dx
, int dy
)
384 gui_pulse(gui_point(id
, x
, y
), 1.2f
);
387 static void conf_stick(int id
, int a
, int v
)
389 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X
, a
))
390 gui_pulse(gui_stick(id
, v
, 0), 1.2f
);
391 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y
, a
))
392 gui_pulse(gui_stick(id
, 0, v
), 1.2f
);
395 static int conf_click(int b
, int d
)
398 return conf_action(gui_token(gui_click()));
402 static int conf_keybd(int c
, int d
)
404 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
407 static int conf_buttn(int b
, int d
)
411 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A
, b
))
412 return conf_action(gui_token(gui_click()));
413 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B
, b
))
414 return goto_state(&st_title
);
415 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
416 return goto_state(&st_title
);
421 /*---------------------------------------------------------------------------*/
423 static int null_enter(void)
438 static void null_leave(int id
)
440 int g
= config_get_d(CONFIG_GEOMETRY
);
442 part_init(GOAL_HEIGHT
);
453 /*---------------------------------------------------------------------------*/
455 struct state st_conf
= {
468 struct state st_null
= {