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 static void conf_header(int id, const char *text, int token)
92 if ((jd = gui_harray(id)))
94 gui_label(jd, text, GUI_SML, GUI_ALL, 0, 0);
96 gui_start(jd, _("Back"), GUI_SML, token, 0);
102 /*---------------------------------------------------------------------------*/
104 #define CONF_SHARED_BACK 1 /* Shared GUI token. */
106 static int (*conf_shared_action)(int i);
108 static void conf_shared_init(int (*action_fn)(int))
110 conf_shared_action = action_fn;
112 game_client_free(NULL);
113 back_init("back/gui.png");
114 audio_music_fade_to(0.5f, "bgm/inter.ogg");
117 static void conf_shared_leave(struct state *st, struct state *next, int id)
123 static void conf_shared_paint(int id, float t)
125 video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
133 static int conf_shared_buttn(int b, int d)
137 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
138 return conf_shared_action(gui_token(gui_click()));
139 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
140 return conf_shared_action(CONF_SHARED_BACK);
145 /*---------------------------------------------------------------------------*/
149 CONF_BACK = CONF_SHARED_BACK,
155 static int music_id[11];
156 static int sound_id[11];
158 static int conf_action(int i)
160 int s = config_get_d(CONFIG_SOUND_VOLUME);
161 int m = config_get_d(CONFIG_MUSIC_VOLUME);
164 audio_play(AUD_MENU, 1.0f);
169 goto_state(&st_title);
173 goto_state(&st_conf_video);
177 goto_name(&st_conf, &st_conf, 1);
181 goto_state(&st_ball);
185 if (100 <= i && i <= 110)
189 config_set_d(CONFIG_SOUND_VOLUME, n);
191 audio_play(AUD_BUMPM, 1.f);
193 gui_toggle(sound_id[n]);
194 gui_toggle(sound_id[s]);
196 if (200 <= i && i <= 210)
200 config_set_d(CONFIG_MUSIC_VOLUME, n);
202 audio_play(AUD_BUMPM, 1.f);
204 gui_toggle(music_id[n]);
205 gui_toggle(music_id[m]);
212 static int conf_gui(void)
216 /* Initialize the configuration GUI. */
218 if ((id = gui_vstack(0)))
220 int s = config_get_d(CONFIG_SOUND_VOLUME);
221 int m = config_get_d(CONFIG_MUSIC_VOLUME);
223 const char *player = config_get_s(CONFIG_PLAYER);
224 const char *ball = config_get_s(CONFIG_BALL_FILE);
226 int name_id = 0, ball_id = 0;
228 conf_header(id, _("Options"), CONF_BACK);
230 conf_state(id, _("Video"), _("Configure"), CONF_VIDEO);
234 conf_slider(id, _("Sound Volume"), 100, s,
235 sound_id, ARRAYSIZE(sound_id));
236 conf_slider(id, _("Music Volume"), 200, m,
237 music_id, ARRAYSIZE(music_id));
241 name_id = conf_state(id, _("Player Name"), " ", CONF_PLAYER);
242 ball_id = conf_state(id, _("Ball Model"), " ", CONF_BALL);
244 gui_layout(id, 0, 0);
246 gui_set_trunc(name_id, TRUNC_TAIL);
247 gui_set_trunc(ball_id, TRUNC_TAIL);
249 gui_set_label(name_id, player);
250 gui_set_label(ball_id, base_name(ball));
256 static int conf_enter(struct state *st, struct state *prev)
258 conf_shared_init(conf_action);
262 /*---------------------------------------------------------------------------*/
266 CONF_VIDEO_BACK = CONF_SHARED_BACK,
280 static int conf_video_action(int i)
282 int w = config_get_d(CONFIG_WIDTH);
283 int h = config_get_d(CONFIG_HEIGHT);
286 audio_play(AUD_MENU, 1.0f);
290 case CONF_VIDEO_FULL:
291 goto_state(&st_null);
292 r = video_mode(1, w, h);
293 goto_state(&st_conf_video);
297 goto_state(&st_null);
298 r = video_mode(0, w, h);
299 goto_state(&st_conf_video);
302 case CONF_VIDEO_TEXHI:
303 goto_state(&st_null);
304 config_set_d(CONFIG_TEXTURES, 1);
305 goto_state(&st_conf_video);
308 case CONF_VIDEO_TEXLO:
309 goto_state(&st_null);
310 config_set_d(CONFIG_TEXTURES, 2);
311 goto_state(&st_conf_video);
314 case CONF_VIDEO_REFON:
315 goto_state(&st_null);
316 config_set_d(CONFIG_REFLECTION, 1);
317 r = video_init(TITLE, ICON);
318 goto_state(&st_conf_video);
321 case CONF_VIDEO_REFOF:
322 goto_state(&st_null);
323 config_set_d(CONFIG_REFLECTION, 0);
324 goto_state(&st_conf_video);
327 case CONF_VIDEO_BACON:
328 goto_state(&st_null);
329 config_set_d(CONFIG_BACKGROUND, 1);
330 goto_state(&st_conf_video);
333 case CONF_VIDEO_BACOF:
334 goto_state(&st_null);
335 config_set_d(CONFIG_BACKGROUND, 0);
336 goto_state(&st_conf_video);
339 case CONF_VIDEO_SHDON:
340 goto_state(&st_null);
341 config_set_d(CONFIG_SHADOW, 1);
342 goto_state(&st_conf_video);
345 case CONF_VIDEO_SHDOF:
346 goto_state(&st_null);
347 config_set_d(CONFIG_SHADOW, 0);
348 goto_state(&st_conf_video);
351 case CONF_VIDEO_BACK:
352 goto_state(&st_conf);
356 goto_state(&st_resol);
363 static int conf_video_gui(void)
367 if ((id = gui_vstack(0)))
369 int f = config_get_d(CONFIG_FULLSCREEN);
370 int t = config_get_d(CONFIG_TEXTURES);
371 int r = config_get_d(CONFIG_REFLECTION);
372 int b = config_get_d(CONFIG_BACKGROUND);
373 int s = config_get_d(CONFIG_SHADOW);
375 char resolution[sizeof ("12345678 x 12345678")];
377 sprintf(resolution, "%d x %d",
378 config_get_d(CONFIG_WIDTH),
379 config_get_d(CONFIG_HEIGHT));
381 conf_header(id, _("Video Options"), CONF_VIDEO_BACK);
383 conf_toggle(id, _("Fullscreen"), f,
384 _("Yes"), CONF_VIDEO_FULL, 1,
385 _("No"), CONF_VIDEO_WIN, 0);
387 conf_state(id, _("Resolution"), resolution, CONF_VIDEO_RES);
391 conf_toggle(id, _("Textures"), t,
392 _("High"), CONF_VIDEO_TEXHI, 1,
393 _("Low"), CONF_VIDEO_TEXLO, 2);
395 conf_toggle(id, _("Reflection"), r,
396 _("On"), CONF_VIDEO_REFON, 1,
397 _("Off"), CONF_VIDEO_REFOF, 0);
399 conf_toggle(id, _("Background"), b,
400 _("On"), CONF_VIDEO_BACON, 1,
401 _("Off"), CONF_VIDEO_BACOF, 0);
403 conf_toggle(id, _("Shadow"), s,
404 _("On"), CONF_VIDEO_SHDON, 1,
405 _("Off"), CONF_VIDEO_SHDOF, 0);
407 gui_layout(id, 0, 0);
413 static int conf_video_enter(struct state *st, struct state *prev)
415 conf_shared_init(conf_video_action);
416 return conf_video_gui();
419 /*---------------------------------------------------------------------------*/
421 static int null_enter(struct state *st, struct state *prev)
436 static void null_leave(struct state *st, struct state *next, int id)
438 part_init(GOAL_HEIGHT, JUMP_HEIGHT);
449 /*---------------------------------------------------------------------------*/
451 struct state st_conf = {
464 struct state st_conf_video = {
477 struct state st_null = {