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