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.
25 /*---------------------------------------------------------------------------*/
46 static int music_id
[11];
47 static int sound_id
[11];
49 static int conf_action(int i
)
51 int f
= config_get(CONFIG_FULLSCREEN
);
52 int w
= config_get(CONFIG_WIDTH
);
53 int h
= config_get(CONFIG_HEIGHT
);
54 int s
= config_get(CONFIG_SOUND_VOLUME
);
55 int m
= config_get(CONFIG_MUSIC_VOLUME
);
62 r
= config_mode(1, w
, h
);
68 r
= config_mode(0, w
, h
);
74 r
= config_mode(f
, 1600, 1200);
80 r
= config_mode(f
, 1280, 1024);
86 r
= config_mode(f
, 1024, 768);
92 r
= config_mode(f
, 800, 600);
98 r
= config_mode(f
, 640, 480);
103 goto_state(&st_null
);
104 config_set(CONFIG_TEXTURES
, 1);
105 goto_state(&st_conf
);
109 goto_state(&st_null
);
110 config_set(CONFIG_TEXTURES
, 2);
111 goto_state(&st_conf
);
115 goto_state(&st_null
);
116 config_set(CONFIG_GEOMETRY
, 1);
117 goto_state(&st_conf
);
121 goto_state(&st_null
);
122 config_set(CONFIG_GEOMETRY
, 0);
123 goto_state(&st_conf
);
127 goto_state(&st_null
);
128 config_set(CONFIG_REFLECTION
, 1);
129 goto_state(&st_conf
);
133 goto_state(&st_null
);
134 config_set(CONFIG_REFLECTION
, 0);
135 goto_state(&st_conf
);
140 config_set(CONFIG_AUDIO_RATE
, 44100);
141 config_set(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_HI
);
142 gui_toggle(audlo_id
);
143 gui_toggle(audhi_id
);
149 config_set(CONFIG_AUDIO_RATE
, 22050);
150 config_set(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_LO
);
151 gui_toggle(audlo_id
);
152 gui_toggle(audhi_id
);
157 goto_state(&st_title
);
161 if (100 <= i
&& i
<= 110)
165 config_set(CONFIG_SOUND_VOLUME
, n
);
167 audio_play(AUD_BUMP
, 1.f
);
169 gui_toggle(sound_id
[n
]);
170 gui_toggle(sound_id
[s
]);
172 if (200 <= i
&& i
<= 210)
176 config_set(CONFIG_MUSIC_VOLUME
, n
);
178 audio_play(AUD_BUMP
, 1.f
);
180 gui_toggle(music_id
[n
]);
181 gui_toggle(music_id
[m
]);
188 static int conf_enter(void)
192 /* Initialize the configuration GUI. */
194 if ((id
= gui_harray(0)))
196 if ((jd
= gui_varray(id
)))
198 int w
= config_get(CONFIG_WIDTH
);
199 int t
= config_get(CONFIG_TEXTURES
);
200 int g
= config_get(CONFIG_GEOMETRY
);
201 int r
= config_get(CONFIG_REFLECTION
);
202 int a
= config_get(CONFIG_AUDIO_RATE
);
203 int s
= config_get(CONFIG_SOUND_VOLUME
);
204 int m
= config_get(CONFIG_MUSIC_VOLUME
);
206 if ((kd
= gui_harray(jd
)))
208 gui_label(kd
, "Options", GUI_SML
, GUI_ALL
, 0, 0);
212 /* Add mode selectors only for existing modes. */
214 if (SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE
))
215 gui_state(jd
, "1600 x 1200", GUI_SML
, CONF_16x12
, (w
== 1600));
216 if (SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE
))
217 gui_state(jd
, "1280 x 1024", GUI_SML
, CONF_12x10
, (w
== 1280));
218 if (SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE
))
219 gui_state(jd
, "1024 x 768", GUI_SML
, CONF_10x7
, (w
== 1024));
220 if (SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE
))
221 gui_state(jd
, "800 x 600", GUI_SML
, CONF_8x6
, (w
== 800));
222 if (SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE
))
223 gui_state(jd
, "640 x 480", GUI_SML
, CONF_6x4
, (w
== 640));
225 if ((kd
= gui_harray(jd
)))
227 gui_state(kd
, "Low", GUI_SML
, CONF_TEXLO
, (t
== 2));
228 gui_state(kd
, "High", GUI_SML
, CONF_TEXHI
, (t
== 1));
230 if ((kd
= gui_harray(jd
)))
232 gui_state(kd
, "Low", GUI_SML
, CONF_GEOLO
, (g
== 0));
233 gui_state(kd
, "High", GUI_SML
, CONF_GEOHI
, (g
== 1));
235 if ((kd
= gui_harray(jd
)))
237 gui_state(kd
, "Off", GUI_SML
, CONF_REFOF
, (r
== 0));
238 gui_state(kd
, "On", GUI_SML
, CONF_REFON
, (r
== 1));
240 if ((kd
= gui_harray(jd
)))
242 int lo
= (a
== 22050);
243 int hi
= (a
== 44100);
245 audlo_id
= gui_state(kd
, "Low", GUI_SML
, CONF_AUDLO
, lo
);
246 audhi_id
= gui_state(kd
, "High", GUI_SML
, CONF_AUDHI
, hi
);
248 if ((kd
= gui_harray(jd
)))
250 /* A series of empty buttons forms the sound volume control. */
252 sound_id
[10] = gui_state(kd
, " ", GUI_SML
, 110, (s
== 10));
253 sound_id
[ 9] = gui_state(kd
, " ", GUI_SML
, 109, (s
== 9));
254 sound_id
[ 8] = gui_state(kd
, " ", GUI_SML
, 108, (s
== 8));
255 sound_id
[ 7] = gui_state(kd
, " ", GUI_SML
, 107, (s
== 7));
256 sound_id
[ 6] = gui_state(kd
, " ", GUI_SML
, 106, (s
== 6));
257 sound_id
[ 5] = gui_state(kd
, " ", GUI_SML
, 105, (s
== 5));
258 sound_id
[ 4] = gui_state(kd
, " ", GUI_SML
, 104, (s
== 4));
259 sound_id
[ 3] = gui_state(kd
, " ", GUI_SML
, 103, (s
== 3));
260 sound_id
[ 2] = gui_state(kd
, " ", GUI_SML
, 102, (s
== 2));
261 sound_id
[ 1] = gui_state(kd
, " ", GUI_SML
, 101, (s
== 1));
262 sound_id
[ 0] = gui_state(kd
, " ", GUI_SML
, 100, (s
== 0));
264 if ((kd
= gui_harray(jd
)))
266 /* A series of empty buttons forms the music volume control. */
268 music_id
[10] = gui_state(kd
, " ", GUI_SML
, 210, (m
== 10));
269 music_id
[ 9] = gui_state(kd
, " ", GUI_SML
, 209, (m
== 9));
270 music_id
[ 8] = gui_state(kd
, " ", GUI_SML
, 208, (m
== 8));
271 music_id
[ 7] = gui_state(kd
, " ", GUI_SML
, 207, (m
== 7));
272 music_id
[ 6] = gui_state(kd
, " ", GUI_SML
, 206, (m
== 6));
273 music_id
[ 5] = gui_state(kd
, " ", GUI_SML
, 205, (m
== 5));
274 music_id
[ 4] = gui_state(kd
, " ", GUI_SML
, 204, (m
== 4));
275 music_id
[ 3] = gui_state(kd
, " ", GUI_SML
, 203, (m
== 3));
276 music_id
[ 2] = gui_state(kd
, " ", GUI_SML
, 202, (m
== 2));
277 music_id
[ 1] = gui_state(kd
, " ", GUI_SML
, 201, (m
== 1));
278 music_id
[ 0] = gui_state(kd
, " ", GUI_SML
, 200, (m
== 0));
281 if ((jd
= gui_vstack(id
)))
283 int f
= config_get(CONFIG_FULLSCREEN
);
285 if ((kd
= gui_harray(jd
)))
288 gui_start(kd
, "Back", GUI_SML
, CONF_BACK
, 0);
291 gui_state(jd
, "Fullscreen", GUI_SML
, CONF_FULL
, (f
== 1));
292 gui_state(jd
, "Window", GUI_SML
, CONF_WIN
, (f
== 0));
294 /* This filler expands to accomodate an unknown number of modes. */
297 gui_label(jd
, "Textures", GUI_SML
, GUI_ALL
, 0, 0);
298 gui_label(jd
, "Geometry", GUI_SML
, GUI_ALL
, 0, 0);
299 gui_label(jd
, "Reflection", GUI_SML
, GUI_ALL
, 0, 0);
300 gui_label(jd
, "Audio", GUI_SML
, GUI_ALL
, 0, 0);
301 gui_label(jd
, "Sound Volume", GUI_SML
, GUI_ALL
, 0, 0);
302 gui_label(jd
, "Music Volume", GUI_SML
, GUI_ALL
, 0, 0);
304 gui_layout(id
, 0, 0);
307 /* Initialize the background. */
309 back_init("png/blues.png", config_get(CONFIG_GEOMETRY
));
311 /* Start the title screen music. */
313 audio_music_play("bgm/title.ogg");
318 static void conf_leave(int id
)
324 static void conf_paint(int id
, float st
)
326 config_push_persp((float) config_get(CONFIG_VIEW_FOV
), 0.1f
, FAR_DIST
);
328 back_draw(time_state());
334 static void conf_timer(int id
, float dt
)
339 static void conf_point(int id
, int x
, int y
, int dx
, int dy
)
341 gui_pulse(gui_point(id
, x
, y
), 1.2f
);
344 static void conf_stick(int id
, int a
, int v
)
346 if (config_tst(CONFIG_JOYSTICK_AXIS_X
, a
))
347 gui_pulse(gui_stick(id
, v
, 0), 1.2f
);
348 if (config_tst(CONFIG_JOYSTICK_AXIS_Y
, a
))
349 gui_pulse(gui_stick(id
, 0, v
), 1.2f
);
352 static int conf_click(int b
, int d
)
355 return conf_action(gui_token(gui_click()));
359 static int conf_keybd(int c
, int d
)
361 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
364 static int conf_buttn(int b
, int d
)
368 if (config_tst(CONFIG_JOYSTICK_BUTTON_A
, b
))
369 return conf_action(gui_token(gui_click()));
370 if (config_tst(CONFIG_JOYSTICK_BUTTON_B
, b
))
371 return goto_state(&st_title
);
372 if (config_tst(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
373 return goto_state(&st_title
);
378 /*---------------------------------------------------------------------------*/
380 static int null_enter(void)
393 static void null_leave(int id
)
395 int g
= config_get(CONFIG_GEOMETRY
);
406 /*---------------------------------------------------------------------------*/
408 struct state st_conf
= {
421 struct state st_null
= {