Rolled back ball/set to a less exposed implementation.
[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, set_name(curr_set()), GUI_SML, GUI_ALL,
52                           gui_wht, gui_wht);
53
54                 gui_space(kd);
55
56                 if ((ld = gui_hstack(kd)))
57                 {
58                     if (b == 0)
59                     {
60                         gui_label(ld, ln,          GUI_LRG, GUI_NE,
61                                   textcol1, textcol2);
62                         gui_label(ld, _("Level "), GUI_LRG, GUI_NW,
63                                   textcol1, textcol2);
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                 gui_label(kd, mode_to_str(lg->mode, 1), GUI_SML, GUI_BOT,
75                           gui_wht, gui_wht);
76
77             }
78             gui_filler(jd);
79         }
80         gui_space(id);
81
82         if (strlen(lg->level->message) != 0)
83             gui_multi(id, _(lg->level->message), GUI_SML, GUI_ALL, gui_wht,
84                       gui_wht);
85
86         gui_layout(id, 0, 0);
87     }
88
89     game_set_fly(1.f);
90
91     return id;
92 }
93
94 static void level_timer(int id, float dt)
95 {
96     game_step_fade(dt);
97 }
98
99 static int level_click(int b, int d)
100 {
101     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
102 }
103
104 static int level_keybd(int c, int d)
105 {
106     if (d && c == SDLK_F12)
107         return goto_state(&st_poser);
108     return 1;
109 }
110
111 static int level_buttn(int b, int d)
112 {
113     if (d)
114     {
115         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
116         {
117             return goto_state(&st_play_ready);
118         }
119         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
120         {
121             level_stat(GAME_NONE, curr_clock(), curr_coins());
122             level_stop();
123             return goto_state(&st_over);
124         }
125     }
126     return 1;
127 }
128
129 /*---------------------------------------------------------------------------*/
130
131 static void poser_paint(int id, float st)
132 {
133     game_draw(1, st);
134 }
135
136 static int poser_buttn(int c, int d)
137 {
138     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
139         return goto_state(&st_level);
140
141     return 1;
142 }
143
144 /*---------------------------------------------------------------------------*/
145
146 struct state st_level = {
147     level_enter,
148     shared_leave,
149     shared_paint,
150     level_timer,
151     NULL,
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     NULL,
170     poser_buttn,
171     1, 0
172 };