add infos in Modes and Secrets tabs
[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 "st_shared.h"
20
21 #include "st_title.h"
22 #include "st_help.h"
23
24 /*---------------------------------------------------------------------------*/
25
26 #define HELP_BACK   1
27 #define HELP_RULE   2
28 #define HELP_CONT   3
29 #define HELP_MODE   4
30 #define HELP_SECR   5
31
32 struct state st_help_rules;
33 struct state st_help_controls;
34 struct state st_help_modes;
35 struct state st_help_secrets;
36
37 static int help_action(int i)
38 {
39     audio_play(AUD_MENU, 1.0f);
40
41     switch (i)
42     {
43         case HELP_BACK: return goto_state(&st_title);
44         case HELP_RULE: return goto_state(&st_help_rules);
45         case HELP_CONT: return goto_state(&st_help_controls);
46         case HELP_MODE: return goto_state(&st_help_modes);
47         case HELP_SECR: return goto_state(&st_help_secrets);
48     }
49     return 1;
50 }
51
52 static int help_button(int id, const char *text, int token, int atoken)
53 {
54     int kd = gui_state(id, text, GUI_SML, token, token == atoken);
55
56     if (token == atoken)
57         gui_focus(kd);
58
59     return kd;
60 }
61
62 static int help_menu(int id, int i)
63 {
64     int jd;
65
66     gui_filler(id);
67     if ((jd = gui_harray(id)))
68     {
69         help_button(jd, _("Secrets"),  HELP_SECR, i);
70         help_button(jd, _("Modes"),    HELP_MODE, i);
71         help_button(jd, _("Controls"), HELP_CONT, i);
72         help_button(jd, _("Rules"),    HELP_RULE, i);
73         help_button(jd, _("Back"),     HELP_BACK, i);
74     }
75     gui_filler(id);
76     return jd;
77 }
78
79 static int help_enter(void)
80 {
81     goto_state(&st_help_rules);
82     return 0;
83 }
84
85 static int help_rules_enter(void)
86 {
87     const char *s0 = _(
88             "Move the mouse or joystick\\"
89             "or use keyboard arrows to\\"
90             "tilt the floor causing the\\"
91             "ball to roll.\\ ");
92     const char *s1 = _(
93             "Roll over coins to collect\\"
94             "them.  Collect coins to\\"
95             "unlock the goal and finish\\"
96             "the level.\\ ");
97
98     int w = config_get_d(CONFIG_WIDTH);
99     int h = config_get_d(CONFIG_HEIGHT);
100
101     int id, jd;
102
103     if ((id = gui_vstack(0)))
104     {
105         help_menu(id, HELP_RULE);
106
107         if ((jd = gui_hstack(id)))
108         {
109             gui_image(jd, "gui/help1.jpg", 6 * w / 16, 6 * h / 16);
110             gui_multi(jd, s0, GUI_SML, GUI_ALL, gui_wht, gui_wht);
111             gui_filler(jd);
112         }
113         gui_space(id);
114         if ((jd = gui_hstack(id)))
115         {
116             gui_filler(jd);
117             gui_multi(jd, s1, GUI_SML, GUI_ALL, gui_wht, gui_wht);
118             gui_image(jd, "gui/help2.jpg", 6 * w / 16, 6 * h / 16);
119         }
120         gui_layout(id, 0, +1);
121     }
122     return id;
123 }
124
125 static int help_controls_enter(void)
126 {
127     const char *s4 = _("Left and right mouse buttons rotate the view.");
128     const char *s5 = _("Hold Shift for faster view rotation.");
129     const char *s6 = _("Pause / Release Pointer");
130     const char *s7 = _("Exit / Cancel Menu");
131     const char *s8 = _("Chase View");
132     const char *s9 = _("Lazy View");
133     const char *sA = _("Manual View");
134     const char *sB = _("Show FPS");
135     const char *sC = _("Screenshot");
136     const char *sD = _("Toggle Fullscreen");
137
138     const char *k0 = _("Spacebar");
139     const char *k1 = _("Escape");
140     const char *k2 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_1));
141     const char *k3 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_2));
142     const char *k4 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_3));
143     const char *k5 = SDL_GetKeyName(SDLK_F9);
144     const char *k6 = SDL_GetKeyName(SDLK_F10);
145     const char *k7 = SDL_GetKeyName(SDLK_F11);
146
147     int id, jd;
148
149     if ((id = gui_vstack(0)))
150     {
151         help_menu(id, HELP_CONT);
152
153         if ((jd = gui_harray(id)))
154         {
155             gui_label(jd, s6, GUI_SML, GUI_NE, gui_wht, gui_wht);
156             gui_label(jd, k0, GUI_SML, GUI_NW, gui_yel, gui_yel);
157         }
158         if ((jd = gui_harray(id)))
159         {
160             gui_label(jd, s7, GUI_SML, 0,      gui_wht, gui_wht);
161             gui_label(jd, k1, GUI_SML, 0,      gui_yel, gui_yel);
162         }
163         if ((jd = gui_harray(id)))
164         {
165             gui_label(jd, s8, GUI_SML, 0,      gui_wht, gui_wht);
166             gui_label(jd, k2, GUI_SML, 0,      gui_yel, gui_yel);
167         }
168         if ((jd = gui_harray(id)))
169         {
170             gui_label(jd, s9, GUI_SML, 0,      gui_wht, gui_wht);
171             gui_label(jd, k3, GUI_SML, 0,      gui_yel, gui_yel);
172         }
173         if ((jd = gui_harray(id)))
174         {
175             gui_label(jd, sA, GUI_SML, GUI_SE, gui_wht, gui_wht);
176             gui_label(jd, k4, GUI_SML, GUI_SW, gui_yel, gui_yel);
177         }
178         if ((jd = gui_harray(id)))
179         {
180             gui_label(jd, sB, GUI_SML, GUI_SE, gui_wht, gui_wht);
181             gui_label(jd, k5, GUI_SML, GUI_SW, gui_yel, gui_yel);
182         }
183         if ((jd = gui_harray(id)))
184         {
185             gui_label(jd, sC, GUI_SML, GUI_SE, gui_wht, gui_wht);
186             gui_label(jd, k6, GUI_SML, GUI_SW, gui_yel, gui_yel);
187         }
188         if ((jd = gui_harray(id)))
189         {
190             gui_label(jd, sD, GUI_SML, GUI_SE, gui_wht, gui_wht);
191             gui_label(jd, k7, GUI_SML, GUI_SW, gui_yel, gui_yel);
192         }
193
194         gui_space(id);
195         gui_label(id, s4, GUI_SML, GUI_TOP, gui_wht, gui_wht);
196         gui_label(id, s5, GUI_SML, GUI_BOT, gui_wht, gui_wht);
197
198         gui_layout(id, 0, +1);
199     }
200     return id;
201 }
202
203 static int help_modes_enter(void)
204 {
205     int id;
206
207     if ((id = gui_vstack(0)))
208     {
209         help_menu(id, HELP_MODE);
210
211         gui_label(id, _("Normal"), GUI_SML, GUI_TOP, 0, 0);
212         gui_multi(id,
213                   "Finish a level before the time run out.\\"
214                   "You need to collect coins in order to open the goal.",
215                   GUI_SML, GUI_BOT, gui_wht, gui_wht);
216
217         gui_space(id);
218
219         gui_label(id, _("Practice"), GUI_SML, GUI_TOP, 0, 0);
220         gui_multi(id, "Play a level without time or coin constraint.\\"
221                         "Levels cannot be unlocked in this mode.",
222                   GUI_SML, GUI_BOT, gui_wht, gui_wht);
223
224         gui_space(id);
225
226         gui_label(id, _("Challenge"), GUI_SML, GUI_TOP, 0, 0);
227         gui_multi(id,
228                   "Start playing from the first level of the level set.\\"
229                   "You start with only four balls, do not lose them.\\"
230                   "Earn an extra ball for each 100 coins collected.",
231                   GUI_SML, GUI_BOT, gui_wht, gui_wht);
232
233         gui_layout(id, 0, +1);
234     }
235     return id;
236
237 }
238
239 static int help_secrets_enter(void)
240 {
241     const char *s0 = _(
242             "In challenge mode, such goals\\"
243             "will transport you to\\"
244             "somewhere... unusual.\\"
245             "You'll have to find them.\\");
246     const char *s1 = _(
247             "Angled acceleration works \\"
248             "in Neverball like in\\"
249             "some Doom-like games.\\"
250             "Best use with the manual view.\\ ");
251
252     int w = config_get_d(CONFIG_WIDTH);
253     int h = config_get_d(CONFIG_HEIGHT);
254
255     int id, jd;
256
257     if ((id = gui_vstack(0)))
258     {
259         help_menu(id, HELP_SECR);
260
261         if ((jd = gui_hstack(id)))
262         {
263             gui_filler(jd);
264             gui_multi(jd, s0, GUI_SML, GUI_ALL, gui_wht, gui_wht);
265             gui_image(jd, "gui/help3.jpg", 6 * w / 16, 6 * h / 16);
266         }
267         gui_space(id);
268         if ((jd = gui_hstack(id)))
269         {
270             gui_image(jd, "gui/help4.jpg", 6 * w / 16, 6 * h / 16);
271             gui_multi(jd, s1, GUI_SML, GUI_ALL, gui_wht, gui_wht);
272             gui_filler(jd);
273         }
274         gui_layout(id, 0, +1);
275     }
276     return id;
277 }
278
279 static int help_buttn(int b, int d)
280 {
281     if (d)
282     {
283         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
284             return help_action(gui_token(gui_click()));
285         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
286             return help_action(HELP_BACK);
287     }
288     return 1;
289 }
290
291 /*---------------------------------------------------------------------------*/
292
293 struct state st_help = {
294     help_enter,
295     NULL,
296     NULL,
297     NULL,
298     NULL,
299     NULL,
300     NULL,
301     NULL,
302     NULL,
303     1, 0
304 };
305
306 struct state st_help_rules = {
307     help_rules_enter,
308     shared_leave,
309     shared_paint,
310     shared_timer,
311     shared_point,
312     shared_stick,
313     shared_click,
314     NULL,
315     help_buttn,
316     1, 0
317 };
318
319 struct state st_help_controls = {
320     help_controls_enter,
321     shared_leave,
322     shared_paint,
323     shared_timer,
324     shared_point,
325     shared_stick,
326     shared_click,
327     NULL,
328     help_buttn,
329     1, 0
330 };
331
332 struct state st_help_modes = {
333     help_modes_enter,
334     shared_leave,
335     shared_paint,
336     shared_timer,
337     shared_point,
338     shared_stick,
339     shared_click,
340     NULL,
341     help_buttn,
342     1, 0
343 };
344
345 struct state st_help_secrets = {
346     help_secrets_enter,
347     shared_leave,
348     shared_paint,
349     shared_timer,
350     shared_point,
351     shared_stick,
352     shared_click,
353     NULL,
354     help_buttn,
355     1, 0
356 };
357