locales: Improved words-fr.png texture
[neverball] / ball / st_level.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 <string.h>
16
17 #include "gui.h"
18 #include "game.h"
19 #include "set.h"
20 #include "progress.h"
21 #include "audio.h"
22 #include "config.h"
23 #include "st_shared.h"
24
25 #include "st_level.h"
26 #include "st_play.h"
27 #include "st_start.h"
28 #include "st_over.h"
29
30 /*---------------------------------------------------------------------------*/
31
32 static int level_enter(void)
33 {
34     int id, jd, kd;
35
36     if ((id = gui_vstack(0)))
37     {
38         if ((jd = gui_hstack(id)))
39         {
40             gui_filler(jd);
41
42             if ((kd = gui_vstack(jd)))
43             {
44                 const char *ln = level_name (curr_level());
45                 int b          = level_bonus(curr_level());
46
47                 char setattr[MAXSTR], lvlattr[MAXSTR];
48
49                 if (b)
50                     sprintf(lvlattr, _("Bonus Level %s"), ln);
51                 else
52                     sprintf(lvlattr, _("Level %s"), ln);
53
54                 if (curr_mode() == MODE_CHALLENGE)
55                     sprintf(setattr, "%s: %s", set_name(curr_set()),
56                             mode_to_str(MODE_CHALLENGE, 1));
57                 else
58                     sprintf(setattr, "%s", set_name(curr_set()));
59
60                 gui_label(kd, lvlattr, b ? GUI_MED : GUI_LRG, GUI_TOP,
61                           b ? gui_wht : 0, b ? gui_grn : 0);
62                 gui_label(kd, setattr, GUI_SML,               GUI_BOT,
63                           gui_wht,         gui_wht);
64             }
65             gui_filler(jd);
66         }
67         gui_space(id);
68
69         gui_multi(id, level_msg(curr_level()),
70                   GUI_SML, GUI_ALL,
71                   gui_wht, gui_wht);
72
73         gui_layout(id, 0, 0);
74     }
75
76     game_set_fly(1.f);
77
78     return id;
79 }
80
81 static void level_timer(int id, float dt)
82 {
83     game_step_fade(dt);
84 }
85
86 static int level_click(int b, int d)
87 {
88     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
89 }
90
91 static int level_keybd(int c, int d)
92 {
93     if (d && c == SDLK_F12)
94         return goto_state(&st_poser);
95     return 1;
96 }
97
98 static int level_buttn(int b, int d)
99 {
100     if (d)
101     {
102         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
103         {
104             return goto_state(&st_play_ready);
105         }
106         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
107         {
108             progress_stop();
109             return goto_state(&st_over);
110         }
111     }
112     return 1;
113 }
114
115 /*---------------------------------------------------------------------------*/
116
117 static void poser_paint(int id, float t)
118 {
119     game_draw(1, t);
120 }
121
122 static int poser_buttn(int c, int d)
123 {
124     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
125         return goto_state(&st_level);
126
127     return 1;
128 }
129
130 /*---------------------------------------------------------------------------*/
131
132 struct state st_level = {
133     level_enter,
134     shared_leave,
135     shared_paint,
136     level_timer,
137     NULL,
138     NULL,
139     NULL,
140     level_click,
141     level_keybd,
142     level_buttn,
143     1, 0
144 };
145
146 struct state st_poser = {
147     NULL,
148     NULL,
149     poser_paint,
150     NULL,
151     NULL,
152     NULL,
153     NULL,
154     NULL,
155     NULL,
156     poser_buttn,
157     1, 0
158 };