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