Those sets haven't been merged.
[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                     else
65                     {
66                         gui_label(ld, ln,                GUI_MED, GUI_NE,
67                                   textcol1, textcol2);
68                         gui_label(ld, _("Bonus Level "), GUI_MED, GUI_NW,
69                                   textcol1, textcol2);
70                     }
71                 }
72
73                 gui_label(kd, mode_to_str(lg->mode, 1), GUI_SML, GUI_BOT,
74                           gui_wht, gui_wht);
75
76             }
77             gui_filler(jd);
78         }
79         gui_space(id);
80
81         if (strlen(lg->level->message) != 0)
82             gui_multi(id, _(lg->level->message), GUI_SML, GUI_ALL, gui_wht,
83                       gui_wht);
84
85         gui_layout(id, 0, 0);
86     }
87
88     game_set_fly(1.f);
89
90     return id;
91 }
92
93 static void level_timer(int id, float dt)
94 {
95     game_step_fade(dt);
96 }
97
98 static int level_click(int b, int d)
99 {
100     return (b < 0 && d == 1) ? goto_state(&st_play_ready) : 1;
101 }
102
103 static int level_keybd(int c, int d)
104 {
105     if (d && c == SDLK_F12)
106         return goto_state(&st_poser);
107     return 1;
108 }
109
110 static int level_buttn(int b, int d)
111 {
112     if (d)
113     {
114         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
115         {
116             return goto_state(&st_play_ready);
117         }
118         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
119         {
120             level_stat(GAME_NONE, curr_clock(), curr_coins());
121             level_stop();
122             return goto_state(&st_over);
123         }
124     }
125     return 1;
126 }
127
128 /*---------------------------------------------------------------------------*/
129
130 static void poser_paint(int id, float st)
131 {
132     game_draw(1, st);
133 }
134
135 static int poser_buttn(int c, int d)
136 {
137     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
138         return goto_state(&st_level);
139
140     return 1;
141 }
142
143 /*---------------------------------------------------------------------------*/
144
145 struct state st_level = {
146     level_enter,
147     shared_leave,
148     shared_paint,
149     level_timer,
150     NULL,
151     NULL,
152     NULL,
153     level_click,
154     level_keybd,
155     level_buttn,
156     1, 0
157 };
158
159 struct state st_poser = {
160     NULL,
161     NULL,
162     poser_paint,
163     NULL,
164     NULL,
165     NULL,
166     NULL,
167     NULL,
168     NULL,
169     poser_buttn,
170     1, 0
171 };