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.
26 /*---------------------------------------------------------------------------*/
51 static int music_id
[11];
52 static int sound_id
[11];
54 static int conf_action(int i
)
56 int f
= config_get_d(CONFIG_FULLSCREEN
);
57 int w
= config_get_d(CONFIG_WIDTH
);
58 int h
= config_get_d(CONFIG_HEIGHT
);
59 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
60 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
63 audio_play(AUD_MENU
, 1.0f
);
69 r
= config_mode(1, w
, h
);
75 r
= config_mode(0, w
, h
);
81 r
= config_mode(f
, 1600, 1200);
87 r
= config_mode(f
, 1280, 1024);
93 r
= config_mode(f
, 1024, 768);
99 r
= config_mode(f
, 800, 600);
100 goto_state(&st_conf
);
104 goto_state(&st_null
);
105 r
= config_mode(f
, 640, 480);
106 goto_state(&st_conf
);
110 goto_state(&st_null
);
111 config_set_d(CONFIG_TEXTURES
, 1);
112 goto_state(&st_conf
);
116 goto_state(&st_null
);
117 config_set_d(CONFIG_TEXTURES
, 2);
118 goto_state(&st_conf
);
122 goto_state(&st_null
);
123 config_set_d(CONFIG_GEOMETRY
, 1);
124 goto_state(&st_conf
);
128 goto_state(&st_null
);
129 config_set_d(CONFIG_GEOMETRY
, 0);
130 goto_state(&st_conf
);
134 goto_state(&st_null
);
135 config_set_d(CONFIG_REFLECTION
, 1);
136 goto_state(&st_conf
);
140 goto_state(&st_null
);
141 config_set_d(CONFIG_REFLECTION
, 0);
142 goto_state(&st_conf
);
146 goto_state(&st_null
);
147 config_set_d(CONFIG_BACKGROUND
, 1);
148 goto_state(&st_conf
);
152 goto_state(&st_null
);
153 config_set_d(CONFIG_BACKGROUND
, 0);
154 goto_state(&st_conf
);
158 goto_state(&st_null
);
159 config_set_d(CONFIG_SHADOW
, 1);
160 goto_state(&st_conf
);
164 goto_state(&st_null
);
165 config_set_d(CONFIG_SHADOW
, 0);
166 goto_state(&st_conf
);
171 config_set_d(CONFIG_AUDIO_RATE
, 44100);
172 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_HI
);
173 gui_toggle(audlo_id
);
174 gui_toggle(audhi_id
);
180 config_set_d(CONFIG_AUDIO_RATE
, 22050);
181 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_LO
);
182 gui_toggle(audlo_id
);
183 gui_toggle(audhi_id
);
188 goto_state(&st_title
);
192 if (100 <= i
&& i
<= 110)
196 config_set_d(CONFIG_SOUND_VOLUME
, n
);
198 audio_play(AUD_BUMP
, 1.f
);
200 gui_toggle(sound_id
[n
]);
201 gui_toggle(sound_id
[s
]);
203 if (200 <= i
&& i
<= 210)
207 config_set_d(CONFIG_MUSIC_VOLUME
, n
);
209 audio_play(AUD_BUMP
, 1.f
);
211 gui_toggle(music_id
[n
]);
212 gui_toggle(music_id
[m
]);
219 static int conf_enter(void)
223 /* Initialize the configuration GUI. */
225 if ((id
= gui_harray(0)))
227 if ((jd
= gui_varray(id
)))
229 int w
= config_get_d(CONFIG_WIDTH
);
230 int t
= config_get_d(CONFIG_TEXTURES
);
231 int g
= config_get_d(CONFIG_GEOMETRY
);
232 int r
= config_get_d(CONFIG_REFLECTION
);
233 int b
= config_get_d(CONFIG_BACKGROUND
);
234 int h
= config_get_d(CONFIG_SHADOW
);
235 int a
= config_get_d(CONFIG_AUDIO_RATE
);
236 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
237 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
239 if ((kd
= gui_harray(jd
)))
241 gui_label(kd
, "Options", GUI_SML
, GUI_ALL
, 0, 0);
245 /* Add mode selectors only for existing modes. */
247 if (SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE
))
248 gui_state(jd
, "1600 x 1200", GUI_SML
, CONF_16x12
, (w
== 1600));
249 if (SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE
))
250 gui_state(jd
, "1280 x 1024", GUI_SML
, CONF_12x10
, (w
== 1280));
251 if (SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE
))
252 gui_state(jd
, "1024 x 768", GUI_SML
, CONF_10x7
, (w
== 1024));
253 if (SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE
))
254 gui_state(jd
, "800 x 600", GUI_SML
, CONF_8x6
, (w
== 800));
255 if (SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE
))
256 gui_state(jd
, "640 x 480", GUI_SML
, CONF_6x4
, (w
== 640));
258 if ((kd
= gui_harray(jd
)))
260 gui_state(kd
, "Low", GUI_SML
, CONF_TEXLO
, (t
== 2));
261 gui_state(kd
, "High", GUI_SML
, CONF_TEXHI
, (t
== 1));
263 if ((kd
= gui_harray(jd
)))
265 gui_state(kd
, "Low", GUI_SML
, CONF_GEOLO
, (g
== 0));
266 gui_state(kd
, "High", GUI_SML
, CONF_GEOHI
, (g
== 1));
268 if ((kd
= gui_harray(jd
)))
270 gui_state(kd
, "Off", GUI_SML
, CONF_REFOF
, (r
== 0));
271 gui_state(kd
, "On", GUI_SML
, CONF_REFON
, (r
== 1));
273 if ((kd
= gui_harray(jd
)))
275 gui_state(kd
, "Off", GUI_SML
, CONF_BACOF
, (b
== 0));
276 gui_state(kd
, "On", GUI_SML
, CONF_BACON
, (b
== 1));
278 if ((kd
= gui_harray(jd
)))
280 gui_state(kd
, "Off", GUI_SML
, CONF_SHDOF
, (h
== 0));
281 gui_state(kd
, "On", GUI_SML
, CONF_SHDON
, (h
== 1));
283 if ((kd
= gui_harray(jd
)))
285 int lo
= (a
== 22050);
286 int hi
= (a
== 44100);
288 audlo_id
= gui_state(kd
, "Low", GUI_SML
, CONF_AUDLO
, lo
);
289 audhi_id
= gui_state(kd
, "High", GUI_SML
, CONF_AUDHI
, hi
);
291 if ((kd
= gui_harray(jd
)))
293 /* A series of empty buttons forms the sound volume control. */
295 sound_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 110, (s
== 10));
296 sound_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 109, (s
== 9));
297 sound_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 108, (s
== 8));
298 sound_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 107, (s
== 7));
299 sound_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 106, (s
== 6));
300 sound_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 105, (s
== 5));
301 sound_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 104, (s
== 4));
302 sound_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 103, (s
== 3));
303 sound_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 102, (s
== 2));
304 sound_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 101, (s
== 1));
305 sound_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 100, (s
== 0));
307 if ((kd
= gui_harray(jd
)))
309 /* A series of empty buttons forms the music volume control. */
311 music_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 210, (m
== 10));
312 music_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 209, (m
== 9));
313 music_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 208, (m
== 8));
314 music_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 207, (m
== 7));
315 music_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 206, (m
== 6));
316 music_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 205, (m
== 5));
317 music_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 204, (m
== 4));
318 music_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 203, (m
== 3));
319 music_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 202, (m
== 2));
320 music_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 201, (m
== 1));
321 music_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 200, (m
== 0));
324 if ((jd
= gui_vstack(id
)))
326 int f
= config_get_d(CONFIG_FULLSCREEN
);
328 if ((kd
= gui_harray(jd
)))
331 gui_start(kd
, "Back", GUI_SML
, CONF_BACK
, 0);
334 gui_state(jd
, "Fullscreen", GUI_SML
, CONF_FULL
, (f
== 1));
335 gui_state(jd
, "Window", GUI_SML
, CONF_WIN
, (f
== 0));
337 /* This filler expands to accomodate an unknown number of modes. */
340 gui_label(jd
, "Textures", GUI_SML
, GUI_ALL
, 0, 0);
341 gui_label(jd
, "Geometry", GUI_SML
, GUI_ALL
, 0, 0);
342 gui_label(jd
, "Reflection", GUI_SML
, GUI_ALL
, 0, 0);
343 gui_label(jd
, "Background", GUI_SML
, GUI_ALL
, 0, 0);
344 gui_label(jd
, "Shadow", GUI_SML
, GUI_ALL
, 0, 0);
345 gui_label(jd
, "Audio", GUI_SML
, GUI_ALL
, 0, 0);
346 gui_label(jd
, "Sound Volume", GUI_SML
, GUI_ALL
, 0, 0);
347 gui_label(jd
, "Music Volume", GUI_SML
, GUI_ALL
, 0, 0);
349 gui_layout(id
, 0, 0);
352 /* Initialize the background. */
354 back_init("png/blues.png", config_get_d(CONFIG_GEOMETRY
));
356 audio_music_fade_to(0.5f
, "bgm/inter.ogg");
361 static void conf_leave(int id
)
367 static void conf_paint(int id
, float st
)
369 config_push_persp((float) config_get_d(CONFIG_VIEW_FOV
), 0.1f
, FAR_DIST
);
377 static void conf_timer(int id
, float dt
)
383 static void conf_point(int id
, int x
, int y
, int dx
, int dy
)
385 gui_pulse(gui_point(id
, x
, y
), 1.2f
);
388 static void conf_stick(int id
, int a
, int v
)
390 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X
, a
))
391 gui_pulse(gui_stick(id
, v
, 0), 1.2f
);
392 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y
, a
))
393 gui_pulse(gui_stick(id
, 0, v
), 1.2f
);
396 static int conf_click(int b
, int d
)
399 return conf_action(gui_token(gui_click()));
403 static int conf_keybd(int c
, int d
)
405 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
408 static int conf_buttn(int b
, int d
)
412 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A
, b
))
413 return conf_action(gui_token(gui_click()));
414 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B
, b
))
415 return goto_state(&st_title
);
416 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
417 return goto_state(&st_title
);
422 /*---------------------------------------------------------------------------*/
424 static int null_enter(void)
439 static void null_leave(int id
)
441 int g
= config_get_d(CONFIG_GEOMETRY
);
443 part_init(GOAL_HEIGHT
);
454 /*---------------------------------------------------------------------------*/
456 struct state st_conf
= {
469 struct state st_null
= {