Don't leak score board internals out to other code
[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 <string.h>
16
17 #include "gui.h"
18 #include "set.h"
19 #include "progress.h"
20 #include "audio.h"
21 #include "config.h"
22 #include "st_shared.h"
23
24 #include "game_server.h"
25 #include "game_client.h"
26
27 #include "st_level.h"
28 #include "st_play.h"
29 #include "st_start.h"
30 #include "st_over.h"
31
32 /*---------------------------------------------------------------------------*/
33
34 static int level_enter(void)
35 {
36     int id, jd, kd;
37
38     if ((id = gui_vstack(0)))
39     {
40         if ((jd = gui_hstack(id)))
41         {
42             gui_filler(jd);
43
44             if ((kd = gui_vstack(jd)))
45             {
46                 const char *ln = level_name (curr_level());
47                 int b          = level_bonus(curr_level());
48
49                 char setattr[MAXSTR], lvlattr[MAXSTR];
50
51                 if (b)
52                     sprintf(lvlattr, _("Bonus Level %s"), ln);
53                 else
54                     sprintf(lvlattr, _("Level %s"), ln);
55
56                 if (curr_mode() == MODE_CHALLENGE)
57                     sprintf(setattr, "%s: %s", set_name(curr_set()),
58                             mode_to_str(MODE_CHALLENGE, 1));
59                 else
60                     sprintf(setattr, "%s", set_name(curr_set()));
61
62                 gui_label(kd, lvlattr, b ? GUI_MED : GUI_LRG, GUI_TOP,
63                           b ? gui_wht : 0, b ? gui_grn : 0);
64                 gui_label(kd, setattr, GUI_SML,               GUI_BOT,
65                           gui_wht,         gui_wht);
66             }
67             gui_filler(jd);
68         }
69         gui_space(id);
70
71         gui_multi(id, level_msg(curr_level()),
72                   GUI_SML, GUI_ALL,
73                   gui_wht, gui_wht);
74
75         gui_layout(id, 0, 0);
76     }
77
78     game_set_fly(1.f, NULL);
79     game_client_step(NULL);
80
81     return id;
82 }
83
84 static void level_timer(int id, float dt)
85 {
86     game_step_fade(dt);
87 }
88
89 static int level_click(int b, int d)
90 {
91     return (b == SDL_BUTTON_LEFT && 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             progress_stop();
112             return goto_state(&st_over);
113         }
114     }
115     return 1;
116 }
117
118 /*---------------------------------------------------------------------------*/
119
120 static void poser_paint(int id, float t)
121 {
122     game_draw(1, t);
123 }
124
125 static int poser_buttn(int c, int d)
126 {
127     if (d && config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, c))
128         return goto_state(&st_level);
129
130     return 1;
131 }
132
133 /*---------------------------------------------------------------------------*/
134
135 struct state st_level = {
136     level_enter,
137     shared_leave,
138     shared_paint,
139     level_timer,
140     NULL,
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     NULL,
159     poser_buttn,
160     1, 0
161 };