A new inline help system.
[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_CRED   5
31
32 extern struct state st_help2;
33 extern struct state st_help3;
34 extern struct state st_help4;
35
36 static int help_action(int i)
37 {
38     audio_play(AUD_MENU, 1.0f);
39     
40     switch(i)
41     {
42         case HELP_BACK: return goto_state(&st_title);
43         case HELP_RULE: return goto_state(&st_help);
44         case HELP_CONT: return goto_state(&st_help2);
45         case HELP_MODE: return goto_state(&st_help3);
46         case HELP_CRED: return goto_state(&st_help4);
47     }
48     return 1;
49 }
50
51 static int help_button(int id, const char *text, int token, int atoken)
52 {
53     int kd = gui_state(id, text, GUI_SML, token, token == atoken);
54     return kd;
55 }
56
57 static int help_menu(int id, int i)
58 {
59     int jd, kd;
60     gui_filler(id);
61     if ((jd = gui_harray(id)))
62     {
63         help_button(jd, _("Credits"),     HELP_CRED, i);
64         help_button(jd, _("Modes"),       HELP_MODE, i);
65         help_button(jd, _("Controls"),   HELP_CONT, i);
66         help_button(jd, _("Rules"),       HELP_RULE, i);
67         kd = help_button(jd, _("Back"),   HELP_BACK, i);
68         gui_focus(kd);
69     }
70     gui_filler(id);
71     return jd;
72 }
73
74 static int help1_enter(void)
75 {
76     const char *s0 = _(
77             "Move the mouse or joystick\\"
78             "or use keyboard arrows to\\"
79             "tilt the floor causing the\\"
80             "ball to roll.");
81     const char *s1 = _(
82             "Roll over coins to collect\\"
83             "them.  Collect coins to\\"
84             "unlock the goal and finish\\"
85             "the level.");
86
87     
88     int w = config_get_d(CONFIG_WIDTH);
89     int h = config_get_d(CONFIG_HEIGHT);
90     
91     int id, jd;
92
93     if ((id = gui_vstack(0)))
94     {
95         help_menu(id, HELP_RULE);
96         
97         if ((jd = gui_hstack(id)))
98         {
99             gui_image(jd, "", 6 * w / 16, 6 * h / 16);
100             gui_filler(jd);
101             gui_multi(jd, s0, GUI_SML, GUI_ALL, gui_wht, gui_wht);
102         }
103         if ((jd = gui_hstack(id)))
104         {
105             gui_multi(jd, s1, GUI_SML, GUI_ALL, gui_wht, gui_wht);
106             gui_filler(jd);
107             gui_image(jd, "", 6 * w / 16, 6 * h / 16);
108         }
109         gui_layout(id, 0, +1);
110     }
111     return id;
112 }
113
114 static int help2_enter(void)
115 {
116     const char *s4 = _("Left and right mouse buttons rotate the view.");
117     const char *s5 = _("Hold Shift for faster view rotation.");
118     const char *s6 = _("Pause / Release Pointer");
119     const char *s7 = _("Exit / Cancel Menu");
120     const char *s8 = _("Chase View");
121     const char *s9 = _("Lazy View");
122     const char *sA = _("Manual View");
123     const char *sB = _("Show FPS");
124     const char *sC = _("Screenshot");
125     const char *sD = _("Toggle Fullscreen");
126
127     const char *k0 = _("Spacebar");
128     const char *k1 = _("Escape");
129     const char *k2 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_1));
130     const char *k3 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_2));
131     const char *k4 = SDL_GetKeyName(config_get_d(CONFIG_KEY_CAMERA_3));
132     const char *k5 = SDL_GetKeyName(SDLK_F9);
133     const char *k6 = SDL_GetKeyName(SDLK_F10);
134     const char *k7 = SDL_GetKeyName(SDLK_F11);
135
136     int id, jd;
137     
138     if ((id = gui_vstack(0)))
139     {
140         help_menu(id, HELP_CONT);
141         
142         if ((jd = gui_harray(id)))
143         {
144             gui_label(jd, s6, GUI_SML, GUI_NE, gui_wht, gui_wht);
145             gui_label(jd, k0, GUI_SML, GUI_NW, gui_yel, gui_yel);
146         }
147         if ((jd = gui_harray(id)))
148         {
149             gui_label(jd, s7, GUI_SML, 0,      gui_wht, gui_wht);
150             gui_label(jd, k1, GUI_SML, 0,      gui_yel, gui_yel);
151         }
152         if ((jd = gui_harray(id)))
153         {
154             gui_label(jd, s8, GUI_SML, 0,      gui_wht, gui_wht);
155             gui_label(jd, k2, GUI_SML, 0,      gui_yel, gui_yel);
156         }
157         if ((jd = gui_harray(id)))
158         {
159             gui_label(jd, s9, GUI_SML, 0,      gui_wht, gui_wht);
160             gui_label(jd, k3, GUI_SML, 0,      gui_yel, gui_yel);
161         }
162         if ((jd = gui_harray(id)))
163         {
164             gui_label(jd, sA, GUI_SML, GUI_SE, gui_wht, gui_wht);
165             gui_label(jd, k4, GUI_SML, GUI_SW, gui_yel, gui_yel);
166         }
167         if ((jd = gui_harray(id)))
168         {
169             gui_label(jd, sB, GUI_SML, GUI_SE, gui_wht, gui_wht);
170             gui_label(jd, k5, GUI_SML, GUI_SW, gui_yel, gui_yel);
171         }
172         if ((jd = gui_harray(id)))
173         {
174             gui_label(jd, sC, GUI_SML, GUI_SE, gui_wht, gui_wht);
175             gui_label(jd, k6, GUI_SML, GUI_SW, gui_yel, gui_yel);
176         }
177         if ((jd = gui_harray(id)))
178         {
179             gui_label(jd, sD, GUI_SML, GUI_SE, gui_wht, gui_wht);
180             gui_label(jd, k7, GUI_SML, GUI_SW, gui_yel, gui_yel);
181         }
182
183         gui_space(id);
184         gui_label(id, s4, GUI_SML, GUI_TOP, gui_wht, gui_wht);
185         gui_label(id, s5, GUI_SML, GUI_BOT, gui_wht, gui_wht);
186
187         gui_layout(id, 0, +1);
188     }
189     return id;
190 }
191
192 static int help3_enter(void)
193 {
194     int id, jd;
195     
196     if ((id = gui_vstack(0)))
197     {
198         help_menu(id, HELP_MODE);
199         
200         if ((jd = gui_hstack(id)))
201             gui_label(jd, _("Normal"), GUI_SML, GUI_TOP, 0, 0);
202         gui_multi(id, 
203         "Finish a level before the time run out.\\"
204         "You need to collect coins in order to open the goal.",
205         GUI_SML, GUI_BOT | GUI_RGT, gui_wht, gui_wht);
206         
207         gui_space(id);
208         
209         if ((jd = gui_hstack(id)))
210         {
211             gui_label(jd, _("Practice"), GUI_SML, GUI_TOP, 0, 0);
212             gui_filler(jd);
213         }
214         gui_multi(id, 
215         "Play a level without time or coin constraint.",
216         GUI_SML, GUI_BOT | GUI_LFT, gui_wht, gui_wht);
217         
218         gui_space(id);
219         
220         if ((jd = gui_hstack(id)))
221             gui_label(jd, _("Challenge"), GUI_SML, GUI_TOP, 0, 0);
222         gui_multi(id, 
223         "Start playing from the first level of the level set.\\"
224         "You start with only four balls, do not lose them.\\"
225         "Earn an extra ball for each 100 coins collected.",
226         GUI_SML, GUI_BOT | GUI_RGT, gui_wht, gui_wht);
227
228         gui_layout(id, 0, +1);
229     }
230     return id;
231     
232 }
233
234 static int help4_enter(void)
235 {
236     int id;
237     
238     if ((id = gui_vstack(0)))
239     {
240         help_menu(id, HELP_CRED);
241         
242         gui_label(id, _("LEAD MAINTAINER"), GUI_SML, GUI_TOP, 0, 0);
243         gui_label(id, "Robert Kooima <robert.kooima@gmail.com>", GUI_SML, GUI_BOT , gui_wht, gui_wht);
244         
245         gui_space(id);
246         
247         gui_label(id, _("DEVELOPERS"), GUI_SML, GUI_TOP, 0, 0);
248         gui_label(id, "Robert Kooima - Jean Privat", GUI_SML, GUI_BOT , gui_wht, gui_wht);
249         
250         gui_space(id);
251         
252         gui_label(id, _("LEVEL CONTRIBUTION"), GUI_SML, GUI_TOP, 0, 0);
253         gui_multi(id, "Pasi Kallinen - Robert Kooima\\Michael Middleton - Jānis Rūcis\\Paul Tompkins - Mehdi Yousfi-Monod", GUI_SML, GUI_BOT , gui_wht, gui_wht);
254         
255         gui_space(id);
256         
257         gui_label(id, _("TRANSLATION"), GUI_SML, GUI_TOP, 0, 0);
258         gui_multi(id, "French: Jean Privat - Mehdi Yousfi-Monod\\"
259                 "German: Georg Wachter\\"
260                 "Latavian: Jānis Rūcis", GUI_SML, GUI_BOT , gui_wht, gui_wht);
261         
262         gui_layout(id, 0, +1);
263     }
264     return id;
265     
266 }
267
268 static int help_buttn(int b, int d)
269 {
270     if (d)
271     {
272         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
273             return help_action(gui_token(gui_click()));
274         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
275             return help_action(HELP_BACK);
276     }
277     return 1;
278 }
279
280 /*---------------------------------------------------------------------------*/
281
282 struct state st_help = {
283     help1_enter,
284     shared_leave,
285     shared_paint,
286     shared_timer,
287     shared_point,
288     shared_stick,
289     shared_click,
290     NULL,
291     help_buttn,
292     1, 0
293 };
294
295 struct state st_help2 = {
296     help2_enter,
297     shared_leave,
298     shared_paint,
299     shared_timer,
300     shared_point,
301     shared_stick,
302     shared_click,
303     NULL,
304     help_buttn,
305     1, 0
306 };
307
308 struct state st_help3 = {
309     help3_enter,
310     shared_leave,
311     shared_paint,
312     shared_timer,
313     shared_point,
314     shared_stick,
315     shared_click,
316     NULL,
317     help_buttn,
318     1, 0
319 };
320
321 struct state st_help4 = {
322     help4_enter,
323     shared_leave,
324     shared_paint,
325     shared_timer,
326     shared_point,
327     shared_stick,
328     shared_click,
329     NULL,
330     help_buttn,
331     1, 0
332 };