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 #include "game_common.h"
28 #include "game_client.h"
29 #include "game_server.h"
36 #include "st_shared.h"
38 extern const char TITLE[];
39 extern const char ICON[];
41 /*---------------------------------------------------------------------------*/
43 static void conf_slider(int id, const char *text,
49 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
51 /* A series of empty buttons forms a "slider". */
53 for (i = num - 1; i >= 0; i--)
54 ids[i] = gui_state(kd, NULL, GUI_SML, token + i, (i == value));
56 gui_label(jd, text, GUI_SML, GUI_ALL, 0, 0);
60 static int conf_state(int id, const char *label, const char *text, int token)
64 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
66 rd = gui_state(kd, text, GUI_SML, token, 0);
67 gui_label(jd, label, GUI_SML, GUI_ALL, 0, 0);
73 static void conf_toggle(int id, const char *label, int value,
74 const char *text1, int token1, int value1,
75 const char *text0, int token0, int value0)
79 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
81 gui_state(kd, text0, GUI_SML, token0, (value == value0));
82 gui_state(kd, text1, GUI_SML, token1, (value == value1));
84 gui_label(jd, label, GUI_SML, GUI_ALL, 0, 0);
88 /*---------------------------------------------------------------------------*/
98 static int music_id[11];
99 static int sound_id[11];
101 static int conf_action(int i)
103 int s = config_get_d(CONFIG_SOUND_VOLUME);
104 int m = config_get_d(CONFIG_MUSIC_VOLUME);
107 audio_play(AUD_MENU, 1.0f);
112 goto_state(&st_title);
116 goto_state(&st_conf_video);
120 goto_name(&st_conf, &st_conf, 1);
124 goto_state(&st_ball);
128 if (100 <= i && i <= 110)
132 config_set_d(CONFIG_SOUND_VOLUME, n);
134 audio_play(AUD_BUMPM, 1.f);
136 gui_toggle(sound_id[n]);
137 gui_toggle(sound_id[s]);
139 if (200 <= i && i <= 210)
143 config_set_d(CONFIG_MUSIC_VOLUME, n);
145 audio_play(AUD_BUMPM, 1.f);
147 gui_toggle(music_id[n]);
148 gui_toggle(music_id[m]);
155 static int conf_gui(void)
159 /* Initialize the configuration GUI. */
161 if ((id = gui_vstack(0)))
163 int s = config_get_d(CONFIG_SOUND_VOLUME);
164 int m = config_get_d(CONFIG_MUSIC_VOLUME);
166 const char *player = config_get_s(CONFIG_PLAYER);
167 const char *ball = config_get_s(CONFIG_BALL_FILE);
169 int name_id = 0, ball_id = 0;
171 if ((jd = gui_harray(id)))
173 gui_label(jd, _("Options"), GUI_SML, GUI_ALL, 0, 0);
175 gui_start(jd, _("Back"), GUI_SML, CONF_BACK, 0);
180 conf_state(id, _("Video"), _("Configure"), CONF_VIDEO);
184 conf_slider(id, _("Sound Volume"), 100, s,
185 sound_id, ARRAYSIZE(sound_id));
186 conf_slider(id, _("Music Volume"), 200, m,
187 music_id, ARRAYSIZE(music_id));
191 name_id = conf_state(id, _("Player Name"), " ", CONF_PLAYER);
192 ball_id = conf_state(id, _("Ball Model"), " ", CONF_BALL);
194 gui_layout(id, 0, 0);
196 gui_set_trunc(name_id, TRUNC_TAIL);
197 gui_set_trunc(ball_id, TRUNC_TAIL);
199 gui_set_label(name_id, player);
200 gui_set_label(ball_id, base_name(ball));
206 static int conf_enter(struct state *st, struct state *prev)
209 back_init("back/gui.png");
210 audio_music_fade_to(0.5f, "bgm/inter.ogg");
215 static void conf_leave(struct state *st, struct state *next, int id)
221 static void conf_paint(int id, float t)
223 video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
231 static int conf_buttn(int b, int d)
235 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
236 return conf_action(gui_token(gui_click()));
237 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
238 return conf_action(CONF_BACK);
243 /*---------------------------------------------------------------------------*/
261 static int conf_video_action(int i)
263 int w = config_get_d(CONFIG_WIDTH);
264 int h = config_get_d(CONFIG_HEIGHT);
267 audio_play(AUD_MENU, 1.0f);
271 case CONF_VIDEO_FULL:
272 goto_state(&st_null);
273 r = video_mode(1, w, h);
274 goto_state(&st_conf_video);
278 goto_state(&st_null);
279 r = video_mode(0, w, h);
280 goto_state(&st_conf_video);
283 case CONF_VIDEO_TEXHI:
284 goto_state(&st_null);
285 config_set_d(CONFIG_TEXTURES, 1);
286 goto_state(&st_conf_video);
289 case CONF_VIDEO_TEXLO:
290 goto_state(&st_null);
291 config_set_d(CONFIG_TEXTURES, 2);
292 goto_state(&st_conf_video);
295 case CONF_VIDEO_REFON:
296 goto_state(&st_null);
297 config_set_d(CONFIG_REFLECTION, 1);
298 r = video_init(TITLE, ICON);
299 goto_state(&st_conf_video);
302 case CONF_VIDEO_REFOF:
303 goto_state(&st_null);
304 config_set_d(CONFIG_REFLECTION, 0);
305 goto_state(&st_conf_video);
308 case CONF_VIDEO_BACON:
309 goto_state(&st_null);
310 config_set_d(CONFIG_BACKGROUND, 1);
311 goto_state(&st_conf_video);
314 case CONF_VIDEO_BACOF:
315 goto_state(&st_null);
316 config_set_d(CONFIG_BACKGROUND, 0);
317 goto_state(&st_conf_video);
320 case CONF_VIDEO_SHDON:
321 goto_state(&st_null);
322 config_set_d(CONFIG_SHADOW, 1);
323 goto_state(&st_conf_video);
326 case CONF_VIDEO_SHDOF:
327 goto_state(&st_null);
328 config_set_d(CONFIG_SHADOW, 0);
329 goto_state(&st_conf_video);
332 case CONF_VIDEO_BACK:
333 goto_state(&st_conf);
337 goto_state(&st_resol);
344 static int conf_video_gui(void)
348 if ((id = gui_vstack(0)))
350 int f = config_get_d(CONFIG_FULLSCREEN);
351 int t = config_get_d(CONFIG_TEXTURES);
352 int r = config_get_d(CONFIG_REFLECTION);
353 int b = config_get_d(CONFIG_BACKGROUND);
354 int s = config_get_d(CONFIG_SHADOW);
356 char resolution[sizeof ("12345678 x 12345678")];
358 sprintf(resolution, "%d x %d",
359 config_get_d(CONFIG_WIDTH),
360 config_get_d(CONFIG_HEIGHT));
362 if ((jd = gui_harray(id)))
364 gui_label(jd, _("Video Options"), GUI_SML, GUI_ALL, 0, 0);
366 gui_start(jd, _("Back"), GUI_SML, CONF_VIDEO_BACK, 0);
371 conf_toggle(id, _("Fullscreen"), f,
372 _("Yes"), CONF_VIDEO_FULL, 1,
373 _("No"), CONF_VIDEO_WIN, 0);
375 conf_state(id, _("Resolution"), resolution, CONF_VIDEO_RES);
379 conf_toggle(id, _("Textures"), t,
380 _("High"), CONF_VIDEO_TEXHI, 1,
381 _("Low"), CONF_VIDEO_TEXLO, 2);
383 conf_toggle(id, _("Reflection"), r,
384 _("On"), CONF_VIDEO_REFON, 1,
385 _("Off"), CONF_VIDEO_REFOF, 0);
387 conf_toggle(id, _("Background"), b,
388 _("On"), CONF_VIDEO_BACON, 1,
389 _("Off"), CONF_VIDEO_BACOF, 0);
391 conf_toggle(id, _("Shadow"), s,
392 _("On"), CONF_VIDEO_SHDON, 1,
393 _("Off"), CONF_VIDEO_SHDOF, 0);
395 gui_layout(id, 0, 0);
401 static int conf_video_enter(struct state *st, struct state *prev)
404 back_init("back/gui.png");
405 audio_music_fade_to(0.5f, "bgm/inter.ogg");
407 return conf_video_gui();
410 static void conf_video_leave(struct state *st, struct state *next, int id)
416 static void conf_video_paint(int id, float t)
418 video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
426 static int conf_video_buttn(int b, int d)
430 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
431 return conf_video_action(gui_token(gui_click()));
432 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
433 return conf_video_action(CONF_BACK);
438 /*---------------------------------------------------------------------------*/
440 static int null_enter(struct state *st, struct state *prev)
455 static void null_leave(struct state *st, struct state *next, int id)
457 part_init(GOAL_HEIGHT, JUMP_HEIGHT);
468 /*---------------------------------------------------------------------------*/
470 struct state st_conf = {
483 struct state st_conf_video = {
496 struct state st_null = {