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