0109c7202e0ed5899b4ad8069d979853a8492bd6
[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 "gui.h"
16 #include "game.h"
17 #include "set.h"
18 #include "levels.h"
19 #include "audio.h"
20 #include "config.h"
21 #include "st_shared.h"
22
23 #include "st_level.h"
24 #include "st_play.h"
25 #include "st_start.h"
26 #include "st_over.h"
27
28 /*---------------------------------------------------------------------------*/
29
30 static int level_enter(void)
31 {
32     int id, jd, kd, ld;
33     const char *ln;
34     const struct level_game *lg = curr_lg();
35     int b;
36     const float *textcol1, *textcol2;
37
38     if ((id = gui_vstack(0)))
39     {
40         if ((jd = gui_hstack(id)))
41         {
42             ln = lg->level->repr;
43             b = lg->level->is_bonus;
44             textcol1 = b ? gui_wht : 0;
45             textcol2 = b ? gui_grn : 0;
46
47             gui_filler(jd);
48
49             if ((kd = gui_vstack(jd)))
50             {
51                 gui_label(kd, _(curr_set()->name), GUI_SML,
52                           GUI_ALL, gui_wht, gui_wht);
53                 gui_space(kd);
54
55                 if ((ld = gui_hstack(kd)))
56                 {
57                     if(b == 0)
58                     {
59                         gui_label(ld, ln,          GUI_LRG, GUI_NE,
60                                   textcol1, textcol2);
61                         gui_label(ld, _("Level "), GUI_LRG, GUI_NW,
62                                   textcol1, textcol2);
63                     }
64
65                     else
66                     {
67                         gui_label(ld, ln,          GUI_MED, GUI_NE,
68                                   textcol1, textcol2);
69                         gui_label(ld, _("Bonus Level "), GUI_MED, GUI_NW,
70                                   textcol1, textcol2);
71                     }
72
73                 }
74
75                 gui_label(kd, mode_to_str(lg->mode, 1), GUI_SML, GUI_BOT,
76                           gui_wht, gui_wht);
77
78             }
79             gui_filler(jd);
80         }
81         gui_space(id);
82
83         if (strlen(lg->level->message) != 0)
84             gui_multi(id, _(lg->level->message), GUI_SML, GUI_ALL, gui_wht,
85                       gui_wht);
86
87         gui_layout(id, 0, 0);
88     }
89
90     game_set_fly(1.f);
91
92     return id;
93 }
94
95 static void level_timer(int id, float dt)
96 {
97     game_step_fade(dt);
98 }
99
100 static int level_click(int b, int d)
101 {
102     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
103 }
104
105 static int level_keybd(int c, int d)
106 {
107     if (d && c == SDLK_F12)
108         return goto_state(&st_poser);
109     return 1;
110 }
111
112 static int level_buttn(int b, int d)
113 {
114     if (d)
115     {
116         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
117         {
118             return goto_state(&st_play_ready);
119         }
120         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
121         {
122             level_stat(GAME_NONE, curr_clock(), curr_coins());
123             level_stop();
124             return goto_state(&st_over);
125         }
126     }
127     return 1;
128 }
129
130 /*---------------------------------------------------------------------------*/
131
132 static void poser_paint(int id, float st)
133 {
134     game_draw(1, st);
135 }
136
137 static int poser_buttn(int c, int d)
138 {
139     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
140         return goto_state(&st_level);
141
142     return 1;
143 }
144
145 /*---------------------------------------------------------------------------*/
146
147 struct state st_level = {
148     level_enter,
149     shared_leave,
150     shared_paint,
151     level_timer,
152     NULL,
153     NULL,
154     level_click,
155     level_keybd,
156     level_buttn,
157     1, 0
158 };
159
160 struct state st_poser = {
161     NULL,
162     NULL,
163     poser_paint,
164     NULL,
165     NULL,
166     NULL,
167     NULL,
168     NULL,
169     poser_buttn,
170     1, 0
171 };