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 "geom.h"
18 #include "ball.h"
19 #include "part.h"
20 #include "game.h"
21 #include "audio.h"
22 #include "config.h"
23 #include "video.h"
24 
25 #include "st_conf.h"
26 #include "st_all.h"
27 #include "st_common.h"
28 
29 /*---------------------------------------------------------------------------*/
30 
31 enum
32 {
33     CONF_VIDEO = 1,
34     CONF_LANG,
35     CONF_BACK
36 };
37 
38 static int music_id[11];
39 static int sound_id[11];
40 
conf_action(int i)41 static int conf_action(int i)
42 {
43     int s = config_get_d(CONFIG_SOUND_VOLUME);
44     int m = config_get_d(CONFIG_MUSIC_VOLUME);
45     int r = 1;
46 
47     audio_play(AUD_MENU, 1.0f);
48 
49     switch (i)
50     {
51     case CONF_BACK:
52         goto_state(&st_title);
53         break;
54 
55     case CONF_VIDEO:
56         goto_state(&st_video);
57         break;
58 
59     case CONF_LANG:
60         goto_state(&st_lang);
61         break;
62 
63     default:
64         if (100 <= i && i <= 110)
65         {
66             int n = i - 100;
67 
68             config_set_d(CONFIG_SOUND_VOLUME, n);
69             audio_volume(n, m);
70             audio_play(AUD_BUMP, 1.f);
71 
72             gui_toggle(sound_id[n]);
73             gui_toggle(sound_id[s]);
74         }
75         if (200 <= i && i <= 210)
76         {
77             int n = i - 200;
78 
79             config_set_d(CONFIG_MUSIC_VOLUME, n);
80             audio_volume(s, n);
81             audio_play(AUD_BUMP, 1.f);
82 
83             gui_toggle(music_id[n]);
84             gui_toggle(music_id[m]);
85         }
86     }
87 
88     return r;
89 }
90 
conf_enter(struct state * st,struct state * prev)91 static int conf_enter(struct state *st, struct state *prev)
92 {
93     int id, jd, kd;
94     int i;
95 
96     back_init("back/gui.png");
97 
98     /* Initialize the configuration GUI. */
99 
100     if ((id = gui_vstack(0)))
101     {
102         if ((jd = gui_harray(id)))
103         {
104             gui_label(jd, _("Options"), GUI_SML, 0, 0);
105             gui_space(jd);
106             gui_start(jd, _("Back"),    GUI_SML, CONF_BACK, 0);
107         }
108 
109         gui_space(id);
110 
111         if ((jd = gui_harray(id)) &&
112             (kd = gui_harray(jd)))
113         {
114             gui_state(kd, _("Configure"), GUI_SML, CONF_VIDEO, 0);
115 
116             gui_label(jd, _("Graphics"),  GUI_SML, 0, 0);
117         }
118 
119         gui_space(id);
120 
121         if ((jd = gui_harray(id)) &&
122             (kd = gui_harray(jd)))
123         {
124             /* A series of empty buttons forms the sound volume control. */
125 
126             int s = config_get_d(CONFIG_SOUND_VOLUME);
127 
128             for (i = 10; i >= 0; i--)
129             {
130                 sound_id[i] = gui_state(kd, NULL, GUI_SML, 100 + i, 0);
131                 gui_set_hilite(sound_id[i], (s == i));
132             }
133 
134             gui_label(jd, _("Sound Volume"), GUI_SML, 0, 0);
135         }
136 
137         if ((jd = gui_harray(id)) &&
138             (kd = gui_harray(jd)))
139         {
140             /* A series of empty buttons forms the music volume control. */
141 
142             int m = config_get_d(CONFIG_MUSIC_VOLUME);
143 
144             for (i = 10; i >= 0; i--)
145             {
146                 music_id[i] = gui_state(kd, NULL, GUI_SML, 200 + i, 0);
147                 gui_set_hilite(music_id[i], (m == i));
148             }
149 
150             gui_label(jd, _("Music Volume"), GUI_SML, 0, 0);
151         }
152 
153         gui_space(id);
154 
155         if ((jd = gui_harray(id)) &&
156             (kd = gui_harray(jd)))
157         {
158             gui_state(kd, _("Select"), GUI_SML, CONF_LANG, 0);
159 
160             gui_label(jd, _("Language"),  GUI_SML, 0, 0);
161         }
162 
163         gui_layout(id, 0, 0);
164     }
165 
166     audio_music_fade_to(0.5f, "bgm/inter.ogg");
167 
168     return id;
169 }
170 
conf_leave(struct state * st,struct state * next,int id)171 static void conf_leave(struct state *st, struct state *next, int id)
172 {
173     back_free();
174     gui_delete(id);
175 }
176 
conf_paint(int id,float st)177 static void conf_paint(int id, float st)
178 {
179     video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
180     {
181         back_draw_easy();
182     }
183     video_pop_matrix();
184     gui_paint(id);
185 }
186 
conf_timer(int id,float dt)187 static void conf_timer(int id, float dt)
188 {
189     gui_timer(id, dt);
190 }
191 
conf_point(int id,int x,int y,int dx,int dy)192 static void conf_point(int id, int x, int y, int dx, int dy)
193 {
194     gui_pulse(gui_point(id, x, y), 1.2f);
195 }
196 
conf_stick(int id,int a,float v,int bump)197 static void conf_stick(int id, int a, float v, int bump)
198 {
199     gui_pulse(gui_stick(id, a, v, bump), 1.2f);
200 }
201 
conf_click(int b,int d)202 static int conf_click(int b, int d)
203 {
204     if (gui_click(b, d))
205         return conf_action(gui_token(gui_active()));
206 
207     return 1;
208 }
209 
conf_keybd(int c,int d)210 static int conf_keybd(int c, int d)
211 {
212     return (d && c == SDLK_ESCAPE) ? goto_state(&st_title) : 1;
213 }
214 
conf_buttn(int b,int d)215 static int conf_buttn(int b, int d)
216 {
217     if (d)
218     {
219         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
220             return conf_action(gui_token(gui_active()));
221         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
222             return goto_state(&st_title);
223     }
224     return 1;
225 }
226 
227 /*---------------------------------------------------------------------------*/
228 
null_enter(struct state * st,struct state * prev)229 static int null_enter(struct state *st, struct state *prev)
230 {
231     gui_free();
232     geom_free();
233     ball_free();
234     shad_free();
235     mtrl_free_objects();
236 
237     return 0;
238 }
239 
null_leave(struct state * st,struct state * next,int id)240 static void null_leave(struct state *st, struct state *next, int id)
241 {
242     mtrl_load_objects();
243     shad_init();
244     ball_init();
245     geom_init();
246     gui_init();
247 }
248 
249 /*---------------------------------------------------------------------------*/
250 
251 struct state st_conf = {
252     conf_enter,
253     conf_leave,
254     conf_paint,
255     conf_timer,
256     conf_point,
257     conf_stick,
258     NULL,
259     conf_click,
260     conf_keybd,
261     conf_buttn
262 };
263 
264 struct state st_null = {
265     null_enter,
266     null_leave,
267     NULL,
268     NULL,
269     NULL,
270     NULL,
271     NULL,
272     NULL,
273     NULL,
274     NULL
275 };
276