running: tweaks
[neverball] / ball / st_conf.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
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.
8  *
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.
13  */
14
15 #include "gui.h"
16 #include "hud.h"
17 #include "back.h"
18 #include "geom.h"
19 #include "item.h"
20 #include "ball.h"
21 #include "part.h"
22 #include "game.h"
23 #include "audio.h"
24 #include "config.h"
25 #include "st_shared.h"
26
27 #include "st_conf.h"
28 #include "st_title.h"
29 #include "st_resol.h"
30 #include "st_name.h"
31
32 /*---------------------------------------------------------------------------*/
33
34 enum {
35     CONF_FULL = 1,
36     CONF_WIN,
37     CONF_TEXHI,
38     CONF_TEXLO,
39     CONF_GEOHI,
40     CONF_GEOLO,
41     CONF_REFON,
42     CONF_REFOF,
43     CONF_BACON,
44     CONF_BACOF,
45     CONF_SHDON,
46     CONF_SHDOF,
47     CONF_BACK,
48     CONF_RES,
49     CONF_PLAYER
50 };
51
52 static int music_id[11];
53 static int sound_id[11];
54
55 static int conf_action(int i)
56 {
57     int w = config_get_d(CONFIG_WIDTH);
58     int h = config_get_d(CONFIG_HEIGHT);
59     int s = config_get_d(CONFIG_SOUND_VOLUME);
60     int m = config_get_d(CONFIG_MUSIC_VOLUME);
61     int r = 1;
62
63     audio_play(AUD_MENU, 1.0f);
64
65     switch (i)
66     {
67     case CONF_FULL:
68         goto_state(&st_null);
69         r = config_mode(1, w, h);
70         goto_state(&st_conf);
71         break;
72
73     case CONF_WIN:
74         goto_state(&st_null);
75         r = config_mode(0, w, h);
76         goto_state(&st_conf);
77         break;
78
79     case CONF_TEXHI:
80         goto_state(&st_null);
81         config_set_d(CONFIG_TEXTURES, 1);
82         goto_state(&st_conf);
83         break;
84
85     case CONF_TEXLO:
86         goto_state(&st_null);
87         config_set_d(CONFIG_TEXTURES, 2);
88         goto_state(&st_conf);
89         break;
90
91     case CONF_GEOHI:
92         goto_state(&st_null);
93         config_set_d(CONFIG_GEOMETRY, 1);
94         goto_state(&st_conf);
95         break;
96
97     case CONF_GEOLO:
98         goto_state(&st_null);
99         config_set_d(CONFIG_GEOMETRY, 0);
100         goto_state(&st_conf);
101         break;
102
103     case CONF_REFON:
104         goto_state(&st_null);
105         config_set_d(CONFIG_REFLECTION, 1);
106         goto_state(&st_conf);
107         break;
108
109     case CONF_REFOF:
110         goto_state(&st_null);
111         config_set_d(CONFIG_REFLECTION, 0);
112         goto_state(&st_conf);
113         break;
114
115     case CONF_BACON:
116         goto_state(&st_null);
117         config_set_d(CONFIG_BACKGROUND, 1);
118         goto_state(&st_conf);
119         break;
120
121     case CONF_BACOF:
122         goto_state(&st_null);
123         config_set_d(CONFIG_BACKGROUND, 0);
124         goto_state(&st_conf);
125         break;
126
127     case CONF_SHDON:
128         goto_state(&st_null);
129         config_set_d(CONFIG_SHADOW, 1);
130         goto_state(&st_conf);
131         break;
132
133     case CONF_SHDOF:
134         goto_state(&st_null);
135         config_set_d(CONFIG_SHADOW, 0);
136         goto_state(&st_conf);
137         break;
138
139     case CONF_BACK:
140         goto_state(&st_title);
141         break;
142
143     case CONF_RES:
144         goto_state(&st_resol);
145         break;
146
147     case CONF_PLAYER:
148         goto_name(&st_conf, &st_conf, 1);
149         break;
150
151     default:
152         if (100 <= i && i <= 110)
153         {
154             int n = i - 100;
155
156             config_set_d(CONFIG_SOUND_VOLUME, n);
157             audio_volume(n, m);
158             audio_play(AUD_BUMPM, 1.f);
159
160             gui_toggle(sound_id[n]);
161             gui_toggle(sound_id[s]);
162         }
163         if (200 <= i && i <= 210)
164         {
165             int n = i - 200;
166
167             config_set_d(CONFIG_MUSIC_VOLUME, n);
168             audio_volume(s, n);
169             audio_play(AUD_BUMPM, 1.f);
170
171             gui_toggle(music_id[n]);
172             gui_toggle(music_id[m]);
173         }
174     }
175
176     return r;
177 }
178
179 static int conf_enter(void)
180 {
181     int id, jd, kd;
182
183     game_free();
184     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
185
186     /* Initialize the configuration GUI. */
187
188     if ((id = gui_vstack(0)))
189     {
190         int f = config_get_d(CONFIG_FULLSCREEN);
191         int t = config_get_d(CONFIG_TEXTURES);
192         int g = config_get_d(CONFIG_GEOMETRY);
193         int r = config_get_d(CONFIG_REFLECTION);
194         int b = config_get_d(CONFIG_BACKGROUND);
195         int h = config_get_d(CONFIG_SHADOW);
196         int s = config_get_d(CONFIG_SOUND_VOLUME);
197         int m = config_get_d(CONFIG_MUSIC_VOLUME);
198
199         char resolution[20], player[MAXNAM] = "";
200
201         sprintf(resolution, "%d x %d",
202                 config_get_d(CONFIG_WIDTH),
203                 config_get_d(CONFIG_HEIGHT));
204
205         config_get_s(CONFIG_PLAYER, player, MAXNAM - 1);
206
207         if ((jd = gui_harray(id)))
208         {
209             gui_label(jd, _("Options"), GUI_SML, GUI_ALL, 0, 0);
210             gui_space(jd);
211             gui_start(jd, _("Back"),    GUI_SML, CONF_BACK, 0);
212         }
213
214         gui_space(id);
215
216         if ((jd = gui_harray(id)) &&
217             (kd = gui_harray(jd)))
218         {
219             gui_state(kd, _("No"),  GUI_SML, CONF_WIN,  (f == 0));
220             gui_state(kd, _("Yes"), GUI_SML, CONF_FULL, (f == 1));
221
222             gui_label(jd, _("Fullscreen"), GUI_SML, GUI_ALL, 0, 0);
223         }
224
225         if ((jd = gui_harray(id)) &&
226             (kd = gui_harray(jd)))
227         {
228             gui_state(kd, resolution, GUI_SML, CONF_RES, 0);
229
230             gui_label(jd, _("Resolution"), GUI_SML, GUI_ALL, 0, 0);
231         }
232
233         gui_space(id);
234
235         if ((jd = gui_harray(id)) &&
236             (kd = gui_harray(jd)))
237         {
238             gui_state(kd, _("Low"),  GUI_SML, CONF_TEXLO, (t == 2));
239             gui_state(kd, _("High"), GUI_SML, CONF_TEXHI, (t == 1));
240
241             gui_label(jd, _("Textures"), GUI_SML, GUI_ALL, 0, 0);
242         }
243
244         if ((jd = gui_harray(id)) &&
245             (kd = gui_harray(jd)))
246         {
247             gui_state(kd, _("Low"),  GUI_SML, CONF_GEOLO, (g == 0));
248             gui_state(kd, _("High"), GUI_SML, CONF_GEOHI, (g == 1));
249
250             gui_label(jd, _("Geometry"), GUI_SML, GUI_ALL, 0, 0);
251         }
252
253         if ((jd = gui_harray(id)) &&
254             (kd = gui_harray(jd)))
255         {
256             gui_state(kd, _("Off"), GUI_SML, CONF_REFOF, (r == 0));
257             gui_state(kd, _("On"),  GUI_SML, CONF_REFON, (r == 1));
258
259             gui_label(jd, _("Reflection"), GUI_SML, GUI_ALL, 0, 0);
260         }
261
262         if ((jd = gui_harray(id)) &&
263             (kd = gui_harray(jd)))
264         {
265             gui_state(kd, _("Off"), GUI_SML, CONF_BACOF, (b == 0));
266             gui_state(kd, _("On"),  GUI_SML, CONF_BACON, (b == 1));
267
268             gui_label(jd, _("Background"), GUI_SML, GUI_ALL, 0, 0);
269         }
270
271         if ((jd = gui_harray(id)) &&
272             (kd = gui_harray(jd)))
273         {
274             gui_state(kd, _("Off"), GUI_SML, CONF_SHDOF, (h == 0));
275             gui_state(kd, _("On"),  GUI_SML, CONF_SHDON, (h == 1));
276
277             gui_label(jd, _("Shadow"), GUI_SML, GUI_ALL, 0, 0);
278         }
279
280         gui_space(id);
281
282         if ((jd = gui_harray(id)) &&
283             (kd = gui_harray(jd)))
284         {
285             /* A series of empty buttons forms the sound volume control. */
286
287             sound_id[10] = gui_state(kd, NULL, GUI_SML, 110, (s == 10));
288             sound_id[ 9] = gui_state(kd, NULL, GUI_SML, 109, (s ==  9));
289             sound_id[ 8] = gui_state(kd, NULL, GUI_SML, 108, (s ==  8));
290             sound_id[ 7] = gui_state(kd, NULL, GUI_SML, 107, (s ==  7));
291             sound_id[ 6] = gui_state(kd, NULL, GUI_SML, 106, (s ==  6));
292             sound_id[ 5] = gui_state(kd, NULL, GUI_SML, 105, (s ==  5));
293             sound_id[ 4] = gui_state(kd, NULL, GUI_SML, 104, (s ==  4));
294             sound_id[ 3] = gui_state(kd, NULL, GUI_SML, 103, (s ==  3));
295             sound_id[ 2] = gui_state(kd, NULL, GUI_SML, 102, (s ==  2));
296             sound_id[ 1] = gui_state(kd, NULL, GUI_SML, 101, (s ==  1));
297             sound_id[ 0] = gui_state(kd, NULL, GUI_SML, 100, (s ==  0));
298
299             gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
300         }
301
302         if ((jd = gui_harray(id)) &&
303             (kd = gui_harray(jd)))
304         {
305             /* A series of empty buttons forms the music volume control. */
306
307             music_id[10] = gui_state(kd, NULL, GUI_SML, 210, (m == 10));
308             music_id[ 9] = gui_state(kd, NULL, GUI_SML, 209, (m ==  9));
309             music_id[ 8] = gui_state(kd, NULL, GUI_SML, 208, (m ==  8));
310             music_id[ 7] = gui_state(kd, NULL, GUI_SML, 207, (m ==  7));
311             music_id[ 6] = gui_state(kd, NULL, GUI_SML, 206, (m ==  6));
312             music_id[ 5] = gui_state(kd, NULL, GUI_SML, 205, (m ==  5));
313             music_id[ 4] = gui_state(kd, NULL, GUI_SML, 204, (m ==  4));
314             music_id[ 3] = gui_state(kd, NULL, GUI_SML, 203, (m ==  3));
315             music_id[ 2] = gui_state(kd, NULL, GUI_SML, 202, (m ==  2));
316             music_id[ 1] = gui_state(kd, NULL, GUI_SML, 201, (m ==  1));
317             music_id[ 0] = gui_state(kd, NULL, GUI_SML, 200, (m ==  0));
318
319             gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
320         }
321
322         gui_space(id);
323
324         if ((jd = gui_harray(id)) &&
325             (kd = gui_harray(jd)))
326         {
327             gui_state(kd, player, GUI_SML, CONF_PLAYER, 0);
328
329             gui_label(jd, _("Player Name"), GUI_SML, GUI_ALL, 0, 0);
330         }
331
332         gui_layout(id, 0, 0);
333     }
334
335     audio_music_fade_to(0.5f, "bgm/inter.ogg");
336
337     return id;
338 }
339
340 static void conf_leave(int id)
341 {
342     back_free();
343     gui_delete(id);
344 }
345
346 static void conf_paint(int id, float t)
347 {
348     config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
349     {
350         back_draw(0);
351     }
352     config_pop_matrix();
353     gui_paint(id);
354 }
355
356 static int conf_buttn(int b, int d)
357 {
358     if (d)
359     {
360         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
361             return conf_action(gui_token(gui_click()));
362         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
363             return conf_action(CONF_BACK);
364     }
365     return 1;
366 }
367
368 /*---------------------------------------------------------------------------*/
369
370 static int null_enter(void)
371 {
372     hud_free();
373     gui_free();
374     swch_free();
375     jump_free();
376     goal_free();
377     item_free();
378     ball_free();
379     shad_free();
380     part_free();
381
382     return 0;
383 }
384
385 static void null_leave(int id)
386 {
387     int g = config_get_d(CONFIG_GEOMETRY);
388
389     part_init(GOAL_HEIGHT);
390     shad_init();
391     ball_init();
392     item_init();
393     goal_init(g);
394     jump_init(g);
395     swch_init(g);
396     gui_init();
397     hud_init();
398 }
399
400 /*---------------------------------------------------------------------------*/
401
402 struct state st_conf = {
403     conf_enter,
404     conf_leave,
405     conf_paint,
406     shared_timer,
407     shared_point,
408     shared_stick,
409     shared_angle,
410     shared_click,
411     NULL,
412     conf_buttn,
413     1, 0
414 };
415
416 struct state st_null = {
417     null_enter,
418     null_leave,
419     NULL,
420     NULL,
421     NULL,
422     NULL,
423     NULL,
424     NULL,
425     NULL,
426     NULL,
427     1, 0
428 };