Reworked mapc+no SDL+no i18n and neverball/neverputt+SDL+i18n distinction.
[neverball] / putt / st_conf.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
4  * NEVERPUTT 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 "part.h"
20 #include "game.h"
21 #include "audio.h"
22 #include "config.h"
23
24 #include "st_conf.h"
25 #include "st_all.h"
26 #include "st_resol.h"
27
28 /*---------------------------------------------------------------------------*/
29
30 enum {
31     CONF_FULL = 1,
32     CONF_WIN,
33     CONF_TEXHI,
34     CONF_TEXLO,
35     CONF_GEOHI,
36     CONF_GEOLO,
37     CONF_SHDON,
38     CONF_SHDOF,
39     CONF_BACK,
40     CONF_RESOL
41 };
42
43 static int music_id[11];
44 static int sound_id[11];
45
46 static int conf_action(int i)
47 {
48     int w = config_get_d(CONFIG_WIDTH);
49     int h = config_get_d(CONFIG_HEIGHT);
50     int s = config_get_d(CONFIG_SOUND_VOLUME);
51     int m = config_get_d(CONFIG_MUSIC_VOLUME);
52     int r = 1;
53
54     audio_play(AUD_MENU, 1.0f);
55
56     switch (i)
57     {
58     case CONF_FULL:
59         goto_state(&st_null);
60         r = config_mode(1, w, h);
61         goto_state(&st_conf);
62         break;
63
64     case CONF_WIN:
65         goto_state(&st_null);
66         r = config_mode(0, w, h);
67         goto_state(&st_conf);
68         break;
69
70     case CONF_TEXHI:
71         goto_state(&st_null);
72         config_set_d(CONFIG_TEXTURES, 1);
73         goto_state(&st_conf);
74         break;
75
76     case CONF_TEXLO:
77         goto_state(&st_null);
78         config_set_d(CONFIG_TEXTURES, 2);
79         goto_state(&st_conf);
80         break;
81
82     case CONF_GEOHI:
83         goto_state(&st_null);
84         config_set_d(CONFIG_GEOMETRY, 1);
85         goto_state(&st_conf);
86         break;
87
88     case CONF_GEOLO:
89         goto_state(&st_null);
90         config_set_d(CONFIG_GEOMETRY, 0);
91         goto_state(&st_conf);
92         break;
93
94     case CONF_SHDON:
95         goto_state(&st_null);
96         config_set_d(CONFIG_SHADOW, 1);
97         goto_state(&st_conf);
98         break;
99
100     case CONF_SHDOF:
101         goto_state(&st_null);
102         config_set_d(CONFIG_SHADOW, 0);
103         goto_state(&st_conf);
104         break;
105
106     case CONF_BACK:
107         goto_state(&st_title);
108         break;
109
110     case CONF_RESOL:
111         goto_state(&st_resol);
112         break;
113
114     default:
115         if (100 <= i && i <= 110)
116         {
117             int n = i - 100;
118
119             config_set_d(CONFIG_SOUND_VOLUME, n);
120             audio_volume(n, m);
121             audio_play(AUD_BUMP, 1.f);
122
123             gui_toggle(sound_id[n]);
124             gui_toggle(sound_id[s]);
125         }
126         if (200 <= i && i <= 210)
127         {
128             int n = i - 200;
129
130             config_set_d(CONFIG_MUSIC_VOLUME, n);
131             audio_volume(s, n);
132             audio_play(AUD_BUMP, 1.f);
133
134             gui_toggle(music_id[n]);
135             gui_toggle(music_id[m]);
136         }
137     }
138
139     return r;
140 }
141
142 static int conf_enter(void)
143 {
144     int id, jd, kd;
145
146     back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
147
148     /* Initialize the configuration GUI. */
149
150     if ((id = gui_harray(0)))
151     {
152         if ((jd = gui_varray(id)))
153         {
154             int f = config_get_d(CONFIG_FULLSCREEN);
155             int t = config_get_d(CONFIG_TEXTURES);
156             int g = config_get_d(CONFIG_GEOMETRY);
157             int h = config_get_d(CONFIG_SHADOW);
158             int s = config_get_d(CONFIG_SOUND_VOLUME);
159             int m = config_get_d(CONFIG_MUSIC_VOLUME);
160
161             if ((kd = gui_harray(jd)))
162             {
163                 gui_label(kd, _("Options"), GUI_SML, GUI_ALL, 0, 0);
164                 gui_filler(kd);
165             }
166
167             /* Add mode selectors only for existing modes. */
168
169             if ((kd = gui_harray(jd)))
170             {
171                 gui_state(kd, _("No"), GUI_SML, CONF_WIN, (f == 0));
172                 gui_state(kd, _("Yes"),  GUI_SML, CONF_FULL, (f == 1));
173             }
174
175             {
176                 static char msg[20];
177                 sprintf(msg, "%d x %d", config_get_d(CONFIG_WIDTH),
178                         config_get_d(CONFIG_HEIGHT));
179                 gui_state(jd, msg, GUI_SML, CONF_RESOL, 0);
180             }
181
182             if ((kd = gui_harray(jd)))
183             {
184                 gui_state(kd, _("Low"),  GUI_SML, CONF_TEXLO, (t == 2));
185                 gui_state(kd, _("High"), GUI_SML, CONF_TEXHI, (t == 1));
186             }
187             if ((kd = gui_harray(jd)))
188             {
189                 gui_state(kd, _("Low"),  GUI_SML, CONF_GEOLO, (g == 0));
190                 gui_state(kd, _("High"), GUI_SML, CONF_GEOHI, (g == 1));
191             }
192             if ((kd = gui_harray(jd)))
193             {
194                 gui_state(kd, _("Off"),  GUI_SML, CONF_SHDOF, (h == 0));
195                 gui_state(kd, _("On"),   GUI_SML, CONF_SHDON, (h == 1));
196             }
197             if ((kd = gui_harray(jd)))
198             {
199                 /* A series of empty buttons forms the sound volume control. */
200
201                 sound_id[10] = gui_state(kd, NULL, GUI_SML, 110, (s == 10));
202                 sound_id[ 9] = gui_state(kd, NULL, GUI_SML, 109, (s ==  9));
203                 sound_id[ 8] = gui_state(kd, NULL, GUI_SML, 108, (s ==  8));
204                 sound_id[ 7] = gui_state(kd, NULL, GUI_SML, 107, (s ==  7));
205                 sound_id[ 6] = gui_state(kd, NULL, GUI_SML, 106, (s ==  6));
206                 sound_id[ 5] = gui_state(kd, NULL, GUI_SML, 105, (s ==  5));
207                 sound_id[ 4] = gui_state(kd, NULL, GUI_SML, 104, (s ==  4));
208                 sound_id[ 3] = gui_state(kd, NULL, GUI_SML, 103, (s ==  3));
209                 sound_id[ 2] = gui_state(kd, NULL, GUI_SML, 102, (s ==  2));
210                 sound_id[ 1] = gui_state(kd, NULL, GUI_SML, 101, (s ==  1));
211                 sound_id[ 0] = gui_state(kd, NULL, GUI_SML, 100, (s ==  0));
212             }
213             if ((kd = gui_harray(jd)))
214             {
215                 /* A series of empty buttons forms the music volume control. */
216
217                 music_id[10] = gui_state(kd, NULL, GUI_SML, 210, (m == 10));
218                 music_id[ 9] = gui_state(kd, NULL, GUI_SML, 209, (m ==  9));
219                 music_id[ 8] = gui_state(kd, NULL, GUI_SML, 208, (m ==  8));
220                 music_id[ 7] = gui_state(kd, NULL, GUI_SML, 207, (m ==  7));
221                 music_id[ 6] = gui_state(kd, NULL, GUI_SML, 206, (m ==  6));
222                 music_id[ 5] = gui_state(kd, NULL, GUI_SML, 205, (m ==  5));
223                 music_id[ 4] = gui_state(kd, NULL, GUI_SML, 204, (m ==  4));
224                 music_id[ 3] = gui_state(kd, NULL, GUI_SML, 203, (m ==  3));
225                 music_id[ 2] = gui_state(kd, NULL, GUI_SML, 202, (m ==  2));
226                 music_id[ 1] = gui_state(kd, NULL, GUI_SML, 201, (m ==  1));
227                 music_id[ 0] = gui_state(kd, NULL, GUI_SML, 200, (m ==  0));
228             }
229         }
230         if ((jd = gui_vstack(id)))
231         {
232             if ((kd = gui_harray(jd)))
233             {
234                 gui_filler(kd);
235                 gui_start(kd, _("Back"), GUI_SML, CONF_BACK, 0);
236             }
237
238             gui_label(jd, _("Fullscreen"),   GUI_SML, GUI_ALL, 0, 0);
239             gui_label(jd, _("Resolution"),   GUI_SML, GUI_ALL, 0, 0);
240
241             gui_label(jd, _("Textures"),     GUI_SML, GUI_ALL, 0, 0);
242             gui_label(jd, _("Geometry"),     GUI_SML, GUI_ALL, 0, 0);
243             gui_label(jd, _("Shadow"),       GUI_SML, GUI_ALL, 0, 0);
244             gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
245             gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
246         }
247         gui_layout(id, 0, 0);
248     }
249
250     audio_music_fade_to(0.5f, "bgm/inter.ogg");
251
252     return id;
253 }
254
255 static void conf_leave(int id)
256 {
257     gui_delete(id);
258 }
259
260 static void conf_paint(int id, float st)
261 {
262     config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
263     {
264         back_draw(0);
265     }
266     config_pop_matrix();
267     gui_paint(id);
268 }
269
270 static void conf_timer(int id, float dt)
271 {
272     gui_timer(id, dt);
273 }
274
275 static void conf_point(int id, int x, int y, int dx, int dy)
276 {
277     gui_pulse(gui_point(id, x, y), 1.2f);
278 }
279
280 static void conf_stick(int id, int a, int v)
281 {
282     if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
283         gui_pulse(gui_stick(id, v, 0), 1.2f);
284     if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
285         gui_pulse(gui_stick(id, 0, v), 1.2f);
286 }
287
288 static int conf_click(int b, int d)
289 {
290     if (b < 0 && d == 1)
291         return conf_action(gui_token(gui_click()));
292     return 1;
293 }
294
295 static int conf_keybd(int c, int d)
296 {
297     return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
298 }
299
300 static int conf_buttn(int b, int d)
301 {
302     if (d)
303     {
304         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
305             return conf_action(gui_token(gui_click()));
306         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
307             return goto_state(&st_title);
308         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
309             return goto_state(&st_title);
310     }
311     return 1;
312 }
313
314 /*---------------------------------------------------------------------------*/
315
316 static int null_enter(void)
317 {
318     gui_free();
319     swch_free();
320     jump_free();
321     flag_free();
322     mark_free();
323     ball_free();
324     shad_free();
325
326     return 0;
327 }
328
329 static void null_leave(int id)
330 {
331     int g = config_get_d(CONFIG_GEOMETRY);
332
333     shad_init();
334     ball_init(g);
335     mark_init(g);
336     flag_init(g);
337     jump_init(g);
338     swch_init(g);
339     gui_init();
340 }
341
342 /*---------------------------------------------------------------------------*/
343
344 struct state st_conf = {
345     conf_enter,
346     conf_leave,
347     conf_paint,
348     conf_timer,
349     conf_point,
350     conf_stick,
351     conf_click,
352     conf_keybd,
353     conf_buttn,
354     1, 0
355 };
356
357 struct state st_null = {
358     null_enter,
359     null_leave,
360     NULL,
361     NULL,
362     NULL,
363     NULL,
364     NULL,
365     NULL,
366     NULL,
367     1, 0
368 };