T-int fixes
[neverball] / ball / st_help.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 "game.h"
17 #include "audio.h"
18 #include "config.h"
19 #include "demo.h"
20
21 #include "st_shared.h"
22 #include "st_title.h"
23 #include "st_help.h"
24
25 /*---------------------------------------------------------------------------*/
26
27 #define HELP_BACK   0
28 #define HELP_RULE   1
29 #define HELP_CONT   2
30 #define HELP_MODE   3
31 #define HELP_TECH   4
32 #define HELP_DEMO_1 6
33 #define HELP_DEMO_2 7
34
35 static int tab = HELP_RULE;
36
37 /*---------------------------------------------------------------------------*/
38
39 static int help_action(int t)
40 {
41     audio_play(AUD_MENU, 1.0f);
42
43     switch (t)
44     {
45     case HELP_BACK:
46         tab = HELP_RULE;
47         return goto_state(&st_title);
48         break;
49
50     case HELP_DEMO_1:
51         if (demo_replay_init(config_data("gui/demo1.nbr"), NULL))
52             return goto_state(&st_help_demo);
53         break;
54
55     case HELP_DEMO_2:
56         if (demo_replay_init(config_data("gui/demo2.nbr"), NULL))
57             return goto_state(&st_help_demo);
58         break;
59
60     default:
61         tab = t;
62         return goto_state(&st_help);
63         break;
64     }
65     return 1;
66 }
67
68 /* -------------------------------------------------------------------------- */
69
70 static int help_button(int id, const char *text, int token)
71 {
72     int jd = gui_state(id, text, GUI_SML, token, (token == tab));
73
74     if (token == tab)
75         gui_focus(jd);
76
77     return jd;
78 }
79
80 static int help_menu(int id)
81 {
82     int jd;
83
84     gui_space(id);
85
86     if ((jd = gui_harray(id)))
87     {
88         help_button(jd, _("Techniques"), HELP_TECH);
89         help_button(jd, _("Modes"),      HELP_MODE);
90         help_button(jd, _("Controls"),   HELP_CONT);
91         help_button(jd, _("Rules"),      HELP_RULE);
92         help_button(jd, _("Back"),       HELP_BACK);
93     }
94     return jd;
95 }
96
97 /* -------------------------------------------------------------------------- */
98
99 static int help_rules(int id)
100 {
101     const char *s0 = _(
102         "Move the mouse or joystick\\"
103         "or use keyboard arrows to\\"
104         "tilt the floor causing the\\"
105         "ball to roll.\\");
106     const char *s1 = _(
107         "Roll over coins to collect\\"
108         "them.  Collect coins to\\"
109         "unlock the goal and finish\\"
110         "the level.\\");
111
112     int w = config_get_d(CONFIG_WIDTH);
113     int h = config_get_d(CONFIG_HEIGHT);
114
115     int jd, kd, ld;
116
117     if ((jd = gui_hstack(id)))
118     {
119         gui_filler(jd);
120
121         if ((kd = gui_varray(jd)))
122         {
123             if ((ld = gui_vstack(kd)))
124             {
125                 gui_space(ld);
126                 gui_multi(ld, s0, GUI_SML, GUI_ALL, gui_wht, gui_wht);
127                 gui_filler(ld);
128             }
129
130             if ((ld = gui_vstack(kd)))
131             {
132                 gui_space(ld);
133                 gui_multi(ld, s1, GUI_SML, GUI_ALL, gui_wht, gui_wht);
134                 gui_filler(ld);
135             }
136         }
137
138         gui_space(jd);
139
140         if ((kd = gui_varray(jd)))
141         {
142             if ((ld = gui_vstack(kd)))
143             {
144                 gui_space(ld);
145                 gui_image(ld, "gui/help1.jpg", 5 * w / 16, 5 * h / 16);
146                 gui_filler(ld);
147             }
148
149             if ((ld = gui_vstack(kd)))
150             {
151                 gui_space(ld);
152                 gui_image(ld, "gui/help2.jpg", 5 * w / 16, 5 * h / 16);
153                 gui_filler(ld);
154             }
155         }
156
157         gui_filler(jd);
158     }
159     return id;
160 }
161
162 static int help_controls(int id)
163 {
164     const char *s4 = _("Left and right mouse buttons rotate the view.");
165     const char *s5 = _("Hold Shift for faster view rotation.");
166     const char *s6 = _("Pause / Release Pointer");
167     const char *s7 = _("Exit / Cancel Menu");
168     const char *s8 = _("Chase View");
169     const char *s9 = _("Lazy View");
170     const char *sA = _("Manual View");
171     const char *sC = _("Screenshot");
172     
173     const char *k0 = _(SDL_GetKeyName((SDLKey) config_get_d(CONFIG_KEY_PAUSE)));
174     const char *k1 = _("Escape");
175     const char *k2 = SDL_GetKeyName((SDLKey) config_get_d(CONFIG_KEY_CAMERA_1));
176     const char *k3 = SDL_GetKeyName((SDLKey) config_get_d(CONFIG_KEY_CAMERA_2));
177     const char *k4 = SDL_GetKeyName((SDLKey) config_get_d(CONFIG_KEY_CAMERA_3));
178     const char *k6 = SDL_GetKeyName(SDLK_F10);
179
180     int jd;
181
182     gui_space(id);
183
184     if ((jd = gui_harray(id)))
185     {
186         gui_label(jd, s6, GUI_SML, GUI_NE, gui_wht, gui_wht);
187         gui_label(jd, k0, GUI_SML, GUI_NW, gui_yel, gui_yel);
188     }
189     if ((jd = gui_harray(id)))
190     {
191         gui_label(jd, s7, GUI_SML, 0,      gui_wht, gui_wht);
192         gui_label(jd, k1, GUI_SML, 0,      gui_yel, gui_yel);
193     }
194     if ((jd = gui_harray(id)))
195     {
196         gui_label(jd, s8, GUI_SML, 0,      gui_wht, gui_wht);
197         gui_label(jd, k2, GUI_SML, 0,      gui_yel, gui_yel);
198     }
199     if ((jd = gui_harray(id)))
200     {
201         gui_label(jd, s9, GUI_SML, 0,      gui_wht, gui_wht);
202         gui_label(jd, k3, GUI_SML, 0,      gui_yel, gui_yel);
203     }
204     if ((jd = gui_harray(id)))
205     {
206         gui_label(jd, sA, GUI_SML, 0,      gui_wht, gui_wht);
207         gui_label(jd, k4, GUI_SML, 0,      gui_yel, gui_yel);
208     }
209     if ((jd = gui_harray(id)))
210     {
211         gui_label(jd, sC, GUI_SML, 0,      gui_wht, gui_wht);
212         gui_label(jd, k6, GUI_SML, 0,      gui_yel, gui_yel);
213     }
214
215     gui_space(id);
216
217     gui_label(id, s4, GUI_SML, GUI_TOP, gui_wht, gui_wht);
218     gui_label(id, s5, GUI_SML, GUI_BOT, gui_wht, gui_wht);
219
220     return id;
221 }
222
223 static int help_modes(int id)
224 {
225     int jd, kd;
226
227     gui_space(id);
228
229     if ((jd = gui_hstack(id)))
230     {
231         gui_filler(jd);
232
233         if ((kd = gui_vstack(jd)))
234         {
235             gui_label(kd, _("Normal Mode"), GUI_SML, GUI_TOP, 0, 0);
236             gui_multi(kd,
237                       _("Finish a level before the time runs out.\\"
238                         "You need to collect coins in order to open the goal."),
239                       GUI_SML, GUI_BOT, gui_wht, gui_wht);
240
241             gui_space(kd);
242
243             gui_label(kd, _("Practice Mode"), GUI_SML, GUI_TOP, 0, 0);
244             gui_multi(kd,
245                       _("Play without time limit or coin constraint.\\"
246                         "Levels cannot be unlocked in this mode."),
247                       GUI_SML, GUI_BOT, gui_wht, gui_wht);
248
249             gui_space(kd);
250
251             gui_label(kd, _("Challenge Mode"), GUI_SML, GUI_TOP, 0, 0);
252             gui_multi(kd,
253                       _("Start playing from the first level of the set.\\"
254                         "You start with only four balls, do not lose them.\\"
255                         "Earn an extra ball for each 100 coins collected."),
256                       GUI_SML, GUI_BOT, gui_wht, gui_wht);
257         }
258
259         gui_filler(jd);
260     }
261     return id;
262 }
263
264 static int help_techniques(int id)
265 {
266     const char *s0 = _(
267         "Corners can be used to jump.\\"
268         "Get rolling and take aim\\"
269         "at the angle. You may be able\\"
270         "to reach new places.\\");
271     const char *s1 = _(
272         "Tilting in 2 directions increases\\"
273         "the slope. Use the manual view\\"
274         "and turn the camera by 45\\"
275         "degrees for best results.\\");
276
277     int w = config_get_d(CONFIG_WIDTH);
278     int h = config_get_d(CONFIG_HEIGHT);
279
280     int jd, kd, ld;
281
282     if ((jd = gui_hstack(id)))
283     {
284         gui_filler(jd);
285
286         if ((kd = gui_varray(jd)))
287         {
288             if ((ld = gui_vstack(kd)))
289             {
290                 gui_space(ld);
291                 gui_image(ld, "gui/help3.jpg", w / 4, h / 4);
292                 gui_state(ld, _("Watch demo"), GUI_SML, 0, 0);
293                 gui_filler(ld);
294
295                 gui_active(ld, HELP_DEMO_1, 0);
296             }
297
298             if ((ld = gui_vstack(kd)))
299             {
300                 gui_space(ld);
301                 gui_image(ld, "gui/help4.jpg", w / 4, h / 4);
302                 gui_state(ld, _("Watch demo"), GUI_SML, 0, 0);
303                 gui_filler(ld);
304
305                 gui_active(ld, HELP_DEMO_2, 0);
306             }
307         }
308
309         gui_space(jd);
310
311         if ((kd = gui_varray(jd)))
312         {
313             if ((ld = gui_vstack(kd)))
314             {
315                 gui_space(ld);
316                 gui_multi(ld, s0, GUI_SML, GUI_ALL, gui_wht, gui_wht);
317                 gui_filler(ld);
318             }
319
320             if ((ld = gui_vstack(kd)))
321             {
322                 gui_space(ld);
323                 gui_multi(ld, s1, GUI_SML, GUI_ALL, gui_wht, gui_wht);
324                 gui_filler(ld);
325             }
326         }
327
328         gui_filler(jd);
329     }
330     return id;
331 }
332
333 /* -------------------------------------------------------------------------- */
334
335 static int help_enter(void)
336 {
337     int id;
338
339     if ((id = gui_vstack(0)))
340     {
341         help_menu(id);
342
343         switch (tab)
344         {
345         case HELP_RULE: help_rules(id);      break;
346         case HELP_CONT: help_controls(id);   break;
347         case HELP_MODE: help_modes(id);      break;
348         case HELP_TECH: help_techniques(id); break;
349
350         default:
351             break;
352         }
353
354         gui_layout(id, 0, +1);
355     }
356     return id;
357 }
358
359 static int help_buttn(int b, int d)
360 {
361     if (d)
362     {
363         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
364             return help_action(gui_token(gui_click()));
365         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
366             return help_action(HELP_BACK);
367     }
368     return 1;
369 }
370
371 /*---------------------------------------------------------------------------*/
372
373 static int help_demo_enter(void)
374 {
375     game_set_fly(0.f);
376
377     return 0;
378 }
379
380 static void help_demo_leave(int id)
381 {
382     demo_replay_stop(0);
383 }
384
385 static void help_demo_paint(int id, float t)
386 {
387     game_draw(0, t);
388 }
389
390 static void help_demo_timer(int id, float dt)
391 {
392     game_step_fade(dt);
393
394     if (!demo_replay_step(dt))
395         goto_state(&st_help);
396 }
397
398 static int help_demo_buttn(int b, int d)
399 {
400     if (d)
401     {
402         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
403             return goto_state(&st_help);
404     }
405     return 1;
406 }
407 /*---------------------------------------------------------------------------*/
408
409 struct state st_help = {
410     help_enter,
411     shared_leave,
412     shared_paint,
413     shared_timer,
414     shared_point,
415     shared_stick,
416     shared_angle,
417     shared_click,
418     NULL,
419     help_buttn,
420     1, 0
421 };
422
423 struct state st_help_demo = {
424     help_demo_enter,
425     help_demo_leave,
426     help_demo_paint,
427     help_demo_timer,
428     NULL,
429     NULL,
430     NULL,
431     NULL,
432     NULL,
433     help_demo_buttn,
434     1, 0
435 };