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 /*---------------------------------------------------------------------------*/
49 static int music_id
[11];
50 static int sound_id
[11];
52 static int conf_action(int i
)
54 int f
= config_get_d(CONFIG_FULLSCREEN
);
55 int w
= config_get_d(CONFIG_WIDTH
);
56 int h
= config_get_d(CONFIG_HEIGHT
);
57 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
58 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
61 audio_play(AUD_MENU
, 1.0f
);
67 r
= config_mode(1, w
, h
);
73 r
= config_mode(0, w
, h
);
79 r
= config_mode(f
, 1600, 1200);
85 r
= config_mode(f
, 1280, 1024);
91 r
= config_mode(f
, 1024, 768);
97 r
= config_mode(f
, 800, 600);
102 goto_state(&st_null
);
103 r
= config_mode(f
, 640, 480);
104 goto_state(&st_conf
);
108 goto_state(&st_null
);
109 config_set_d(CONFIG_TEXTURES
, 1);
110 goto_state(&st_conf
);
114 goto_state(&st_null
);
115 config_set_d(CONFIG_TEXTURES
, 2);
116 goto_state(&st_conf
);
120 goto_state(&st_null
);
121 config_set_d(CONFIG_GEOMETRY
, 1);
122 goto_state(&st_conf
);
126 goto_state(&st_null
);
127 config_set_d(CONFIG_GEOMETRY
, 0);
128 goto_state(&st_conf
);
132 goto_state(&st_null
);
133 config_set_d(CONFIG_REFLECTION
, 1);
134 goto_state(&st_conf
);
138 goto_state(&st_null
);
139 config_set_d(CONFIG_REFLECTION
, 0);
140 goto_state(&st_conf
);
144 goto_state(&st_null
);
145 config_set_d(CONFIG_BACKGROUND
, 1);
146 goto_state(&st_conf
);
150 goto_state(&st_null
);
151 config_set_d(CONFIG_BACKGROUND
, 0);
152 goto_state(&st_conf
);
157 config_set_d(CONFIG_AUDIO_RATE
, 44100);
158 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_HI
);
159 gui_toggle(audlo_id
);
160 gui_toggle(audhi_id
);
166 config_set_d(CONFIG_AUDIO_RATE
, 22050);
167 config_set_d(CONFIG_AUDIO_BUFF
, AUDIO_BUFF_LO
);
168 gui_toggle(audlo_id
);
169 gui_toggle(audhi_id
);
174 goto_state(&st_title
);
178 if (100 <= i
&& i
<= 110)
182 config_set_d(CONFIG_SOUND_VOLUME
, n
);
184 audio_play(AUD_BUMP
, 1.f
);
186 gui_toggle(sound_id
[n
]);
187 gui_toggle(sound_id
[s
]);
189 if (200 <= i
&& i
<= 210)
193 config_set_d(CONFIG_MUSIC_VOLUME
, n
);
195 audio_play(AUD_BUMP
, 1.f
);
197 gui_toggle(music_id
[n
]);
198 gui_toggle(music_id
[m
]);
205 static int conf_enter(void)
209 /* Initialize the configuration GUI. */
211 if ((id
= gui_harray(0)))
213 if ((jd
= gui_varray(id
)))
215 int w
= config_get_d(CONFIG_WIDTH
);
216 int t
= config_get_d(CONFIG_TEXTURES
);
217 int g
= config_get_d(CONFIG_GEOMETRY
);
218 int r
= config_get_d(CONFIG_REFLECTION
);
219 int b
= config_get_d(CONFIG_BACKGROUND
);
220 int a
= config_get_d(CONFIG_AUDIO_RATE
);
221 int s
= config_get_d(CONFIG_SOUND_VOLUME
);
222 int m
= config_get_d(CONFIG_MUSIC_VOLUME
);
224 if ((kd
= gui_harray(jd
)))
226 gui_label(kd
, "Options", GUI_SML
, GUI_ALL
, 0, 0);
230 /* Add mode selectors only for existing modes. */
232 if (SDL_VideoModeOK(1600, 1200, 16, SDL_HWSURFACE
))
233 gui_state(jd
, "1600 x 1200", GUI_SML
, CONF_16x12
, (w
== 1600));
234 if (SDL_VideoModeOK(1280, 1024, 16, SDL_HWSURFACE
))
235 gui_state(jd
, "1280 x 1024", GUI_SML
, CONF_12x10
, (w
== 1280));
236 if (SDL_VideoModeOK(1024, 768, 16, SDL_HWSURFACE
))
237 gui_state(jd
, "1024 x 768", GUI_SML
, CONF_10x7
, (w
== 1024));
238 if (SDL_VideoModeOK(800, 600, 16, SDL_HWSURFACE
))
239 gui_state(jd
, "800 x 600", GUI_SML
, CONF_8x6
, (w
== 800));
240 if (SDL_VideoModeOK(640, 480, 16, SDL_HWSURFACE
))
241 gui_state(jd
, "640 x 480", GUI_SML
, CONF_6x4
, (w
== 640));
243 if ((kd
= gui_harray(jd
)))
245 gui_state(kd
, "Low", GUI_SML
, CONF_TEXLO
, (t
== 2));
246 gui_state(kd
, "High", GUI_SML
, CONF_TEXHI
, (t
== 1));
248 if ((kd
= gui_harray(jd
)))
250 gui_state(kd
, "Low", GUI_SML
, CONF_GEOLO
, (g
== 0));
251 gui_state(kd
, "High", GUI_SML
, CONF_GEOHI
, (g
== 1));
253 if ((kd
= gui_harray(jd
)))
255 gui_state(kd
, "Off", GUI_SML
, CONF_REFOF
, (r
== 0));
256 gui_state(kd
, "On", GUI_SML
, CONF_REFON
, (r
== 1));
258 if ((kd
= gui_harray(jd
)))
260 gui_state(kd
, "Off", GUI_SML
, CONF_BACOF
, (b
== 0));
261 gui_state(kd
, "On", GUI_SML
, CONF_BACON
, (b
== 1));
263 if ((kd
= gui_harray(jd
)))
265 int lo
= (a
== 22050);
266 int hi
= (a
== 44100);
268 audlo_id
= gui_state(kd
, "Low", GUI_SML
, CONF_AUDLO
, lo
);
269 audhi_id
= gui_state(kd
, "High", GUI_SML
, CONF_AUDHI
, hi
);
271 if ((kd
= gui_harray(jd
)))
273 /* A series of empty buttons forms the sound volume control. */
275 sound_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 110, (s
== 10));
276 sound_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 109, (s
== 9));
277 sound_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 108, (s
== 8));
278 sound_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 107, (s
== 7));
279 sound_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 106, (s
== 6));
280 sound_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 105, (s
== 5));
281 sound_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 104, (s
== 4));
282 sound_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 103, (s
== 3));
283 sound_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 102, (s
== 2));
284 sound_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 101, (s
== 1));
285 sound_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 100, (s
== 0));
287 if ((kd
= gui_harray(jd
)))
289 /* A series of empty buttons forms the music volume control. */
291 music_id
[10] = gui_state(kd
, NULL
, GUI_SML
, 210, (m
== 10));
292 music_id
[ 9] = gui_state(kd
, NULL
, GUI_SML
, 209, (m
== 9));
293 music_id
[ 8] = gui_state(kd
, NULL
, GUI_SML
, 208, (m
== 8));
294 music_id
[ 7] = gui_state(kd
, NULL
, GUI_SML
, 207, (m
== 7));
295 music_id
[ 6] = gui_state(kd
, NULL
, GUI_SML
, 206, (m
== 6));
296 music_id
[ 5] = gui_state(kd
, NULL
, GUI_SML
, 205, (m
== 5));
297 music_id
[ 4] = gui_state(kd
, NULL
, GUI_SML
, 204, (m
== 4));
298 music_id
[ 3] = gui_state(kd
, NULL
, GUI_SML
, 203, (m
== 3));
299 music_id
[ 2] = gui_state(kd
, NULL
, GUI_SML
, 202, (m
== 2));
300 music_id
[ 1] = gui_state(kd
, NULL
, GUI_SML
, 201, (m
== 1));
301 music_id
[ 0] = gui_state(kd
, NULL
, GUI_SML
, 200, (m
== 0));
304 if ((jd
= gui_vstack(id
)))
306 int f
= config_get_d(CONFIG_FULLSCREEN
);
308 if ((kd
= gui_harray(jd
)))
311 gui_start(kd
, "Back", GUI_SML
, CONF_BACK
, 0);
314 gui_state(jd
, "Fullscreen", GUI_SML
, CONF_FULL
, (f
== 1));
315 gui_state(jd
, "Window", GUI_SML
, CONF_WIN
, (f
== 0));
317 /* This filler expands to accomodate an unknown number of modes. */
320 gui_label(jd
, "Textures", GUI_SML
, GUI_ALL
, 0, 0);
321 gui_label(jd
, "Geometry", GUI_SML
, GUI_ALL
, 0, 0);
322 gui_label(jd
, "Reflection", GUI_SML
, GUI_ALL
, 0, 0);
323 gui_label(jd
, "Background", GUI_SML
, GUI_ALL
, 0, 0);
324 gui_label(jd
, "Audio", GUI_SML
, GUI_ALL
, 0, 0);
325 gui_label(jd
, "Sound Volume", GUI_SML
, GUI_ALL
, 0, 0);
326 gui_label(jd
, "Music Volume", GUI_SML
, GUI_ALL
, 0, 0);
328 gui_layout(id
, 0, 0);
331 /* Initialize the background. */
333 back_init("png/blues.png", config_get_d(CONFIG_GEOMETRY
));
335 audio_music_fade_to(0.5f
, "bgm/inter.ogg");
340 static void conf_leave(int id
)
346 static void conf_paint(int id
, float st
)
348 config_push_persp((float) config_get_d(CONFIG_VIEW_FOV
), 0.1f
, FAR_DIST
);
356 static void conf_timer(int id
, float dt
)
362 static void conf_point(int id
, int x
, int y
, int dx
, int dy
)
364 gui_pulse(gui_point(id
, x
, y
), 1.2f
);
367 static void conf_stick(int id
, int a
, int v
)
369 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X
, a
))
370 gui_pulse(gui_stick(id
, v
, 0), 1.2f
);
371 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y
, a
))
372 gui_pulse(gui_stick(id
, 0, v
), 1.2f
);
375 static int conf_click(int b
, int d
)
378 return conf_action(gui_token(gui_click()));
382 static int conf_keybd(int c
, int d
)
384 return (d
&& c
== SDLK_ESCAPE
) ? goto_state(&st_title
) : 1;
387 static int conf_buttn(int b
, int d
)
391 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A
, b
))
392 return conf_action(gui_token(gui_click()));
393 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B
, b
))
394 return goto_state(&st_title
);
395 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT
, b
))
396 return goto_state(&st_title
);
401 /*---------------------------------------------------------------------------*/
403 static int null_enter(void)
418 static void null_leave(int id
)
420 int g
= config_get_d(CONFIG_GEOMETRY
);
422 part_init(GOAL_HEIGHT
);
433 /*---------------------------------------------------------------------------*/
435 struct state st_conf
= {
448 struct state st_null
= {