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