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 #include "game_common.h"
27 #include "game_client.h"
28 #include "game_server.h"
35 #include "st_shared.h"
37 extern const char TITLE[];
38 extern const char ICON[];
40 /*---------------------------------------------------------------------------*/
42 static void conf_slider(int id, const char *text,
48 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
50 /* A series of empty buttons forms a "slider". */
52 for (i = num - 1; i >= 0; i--)
53 ids[i] = gui_state(kd, NULL, GUI_SML, token + i, (i == value));
55 gui_label(jd, text, GUI_SML, GUI_ALL, 0, 0);
59 static int conf_state(int id, const char *label, const char *text, int token)
63 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
65 rd = gui_state(kd, text, GUI_SML, token, 0);
66 gui_label(jd, label, GUI_SML, GUI_ALL, 0, 0);
72 static void conf_toggle(int id, const char *label, int value,
73 const char *text1, int token1, int value1,
74 const char *text0, int token0, int value0)
78 if ((jd = gui_harray(id)) && (kd = gui_harray(jd)))
80 gui_state(kd, text0, GUI_SML, token0, (value == value0));
81 gui_state(kd, text1, GUI_SML, token1, (value == value1));
83 gui_label(jd, label, GUI_SML, GUI_ALL, 0, 0);
87 static void conf_header(int id, const char *text, int token)
91 if ((jd = gui_harray(id)))
93 gui_label(jd, text, GUI_SML, GUI_ALL, 0, 0);
95 gui_start(jd, _("Back"), GUI_SML, token, 0);
101 /*---------------------------------------------------------------------------*/
103 #define CONF_SHARED_BACK 1 /* Shared GUI token. */
105 static int (*conf_shared_action)(int i);
107 static void conf_shared_init(int (*action_fn)(int))
109 conf_shared_action = action_fn;
111 game_client_free(NULL);
112 back_init("back/gui.png");
113 audio_music_fade_to(0.5f, "bgm/inter.ogg");
116 static void conf_shared_leave(struct state *st, struct state *next, int id)
122 static void conf_shared_paint(int id, float t)
124 video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
132 static int conf_shared_buttn(int b, int d)
136 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
137 return conf_shared_action(gui_token(gui_click()));
138 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
139 return conf_shared_action(CONF_SHARED_BACK);
144 /*---------------------------------------------------------------------------*/
148 CONF_BACK = CONF_SHARED_BACK,
154 static int music_id[11];
155 static int sound_id[11];
157 static int conf_action(int i)
159 int s = config_get_d(CONFIG_SOUND_VOLUME);
160 int m = config_get_d(CONFIG_MUSIC_VOLUME);
163 audio_play(AUD_MENU, 1.0f);
168 goto_state(&st_title);
172 goto_state(&st_conf_video);
176 goto_name(&st_conf, &st_conf, 1);
180 goto_state(&st_ball);
184 if (100 <= i && i <= 110)
188 config_set_d(CONFIG_SOUND_VOLUME, n);
190 audio_play(AUD_BUMPM, 1.f);
192 gui_toggle(sound_id[n]);
193 gui_toggle(sound_id[s]);
195 if (200 <= i && i <= 210)
199 config_set_d(CONFIG_MUSIC_VOLUME, n);
201 audio_play(AUD_BUMPM, 1.f);
203 gui_toggle(music_id[n]);
204 gui_toggle(music_id[m]);
211 static int conf_gui(void)
215 /* Initialize the configuration GUI. */
217 if ((id = gui_vstack(0)))
219 int s = config_get_d(CONFIG_SOUND_VOLUME);
220 int m = config_get_d(CONFIG_MUSIC_VOLUME);
222 const char *player = config_get_s(CONFIG_PLAYER);
223 const char *ball = config_get_s(CONFIG_BALL_FILE);
225 int name_id = 0, ball_id = 0;
227 conf_header(id, _("Options"), CONF_BACK);
229 conf_state(id, _("Video"), _("Configure"), CONF_VIDEO);
233 conf_slider(id, _("Sound Volume"), 100, s,
234 sound_id, ARRAYSIZE(sound_id));
235 conf_slider(id, _("Music Volume"), 200, m,
236 music_id, ARRAYSIZE(music_id));
240 name_id = conf_state(id, _("Player Name"), " ", CONF_PLAYER);
241 ball_id = conf_state(id, _("Ball Model"), " ", CONF_BALL);
243 gui_layout(id, 0, 0);
245 gui_set_trunc(name_id, TRUNC_TAIL);
246 gui_set_trunc(ball_id, TRUNC_TAIL);
248 gui_set_label(name_id, player);
249 gui_set_label(ball_id, base_name(ball));
255 static int conf_enter(struct state *st, struct state *prev)
257 conf_shared_init(conf_action);
261 /*---------------------------------------------------------------------------*/
265 CONF_VIDEO_BACK = CONF_SHARED_BACK,
279 static int conf_video_action(int i)
281 int w = config_get_d(CONFIG_WIDTH);
282 int h = config_get_d(CONFIG_HEIGHT);
285 audio_play(AUD_MENU, 1.0f);
289 case CONF_VIDEO_FULL:
290 goto_state(&st_null);
291 r = video_mode(1, w, h);
292 goto_state(&st_conf_video);
296 goto_state(&st_null);
297 r = video_mode(0, w, h);
298 goto_state(&st_conf_video);
301 case CONF_VIDEO_TEXHI:
302 goto_state(&st_null);
303 config_set_d(CONFIG_TEXTURES, 1);
304 goto_state(&st_conf_video);
307 case CONF_VIDEO_TEXLO:
308 goto_state(&st_null);
309 config_set_d(CONFIG_TEXTURES, 2);
310 goto_state(&st_conf_video);
313 case CONF_VIDEO_REFON:
314 goto_state(&st_null);
315 config_set_d(CONFIG_REFLECTION, 1);
316 r = video_init(TITLE, ICON);
317 goto_state(&st_conf_video);
320 case CONF_VIDEO_REFOF:
321 goto_state(&st_null);
322 config_set_d(CONFIG_REFLECTION, 0);
323 goto_state(&st_conf_video);
326 case CONF_VIDEO_BACON:
327 goto_state(&st_null);
328 config_set_d(CONFIG_BACKGROUND, 1);
329 goto_state(&st_conf_video);
332 case CONF_VIDEO_BACOF:
333 goto_state(&st_null);
334 config_set_d(CONFIG_BACKGROUND, 0);
335 goto_state(&st_conf_video);
338 case CONF_VIDEO_SHDON:
339 goto_state(&st_null);
340 config_set_d(CONFIG_SHADOW, 1);
341 goto_state(&st_conf_video);
344 case CONF_VIDEO_SHDOF:
345 goto_state(&st_null);
346 config_set_d(CONFIG_SHADOW, 0);
347 goto_state(&st_conf_video);
350 case CONF_VIDEO_BACK:
351 goto_state(&st_conf);
355 goto_state(&st_resol);
362 static int conf_video_gui(void)
366 if ((id = gui_vstack(0)))
368 int f = config_get_d(CONFIG_FULLSCREEN);
369 int t = config_get_d(CONFIG_TEXTURES);
370 int r = config_get_d(CONFIG_REFLECTION);
371 int b = config_get_d(CONFIG_BACKGROUND);
372 int s = config_get_d(CONFIG_SHADOW);
374 char resolution[sizeof ("12345678 x 12345678")];
376 sprintf(resolution, "%d x %d",
377 config_get_d(CONFIG_WIDTH),
378 config_get_d(CONFIG_HEIGHT));
380 conf_header(id, _("Video Options"), CONF_VIDEO_BACK);
382 conf_toggle(id, _("Fullscreen"), f,
383 _("Yes"), CONF_VIDEO_FULL, 1,
384 _("No"), CONF_VIDEO_WIN, 0);
386 conf_state(id, _("Resolution"), resolution, CONF_VIDEO_RES);
390 conf_toggle(id, _("Textures"), t,
391 _("High"), CONF_VIDEO_TEXHI, 1,
392 _("Low"), CONF_VIDEO_TEXLO, 2);
394 conf_toggle(id, _("Reflection"), r,
395 _("On"), CONF_VIDEO_REFON, 1,
396 _("Off"), CONF_VIDEO_REFOF, 0);
398 conf_toggle(id, _("Background"), b,
399 _("On"), CONF_VIDEO_BACON, 1,
400 _("Off"), CONF_VIDEO_BACOF, 0);
402 conf_toggle(id, _("Shadow"), s,
403 _("On"), CONF_VIDEO_SHDON, 1,
404 _("Off"), CONF_VIDEO_SHDOF, 0);
406 gui_layout(id, 0, 0);
412 static int conf_video_enter(struct state *st, struct state *prev)
414 conf_shared_init(conf_video_action);
415 return conf_video_gui();
418 /*---------------------------------------------------------------------------*/
420 static int null_enter(struct state *st, struct state *prev)
433 static void null_leave(struct state *st, struct state *next, int id)
444 /*---------------------------------------------------------------------------*/
446 struct state st_conf = {
460 struct state st_conf_video = {
474 struct state st_null = {