Import from neverball-1.3.1.tar.gz
[neverball-archive.git] / ball / st_done.c
blob6c4d6d572270fa5eff92bd5c0493afbae1918247
1 /*
2 * Copyright (C) 2003 Robert Kooima
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.
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.
15 #include <string.h>
17 #include "gui.h"
18 #include "set.h"
19 #include "game.h"
20 #include "util.h"
21 #include "demo.h"
22 #include "level.h"
23 #include "audio.h"
24 #include "config.h"
26 #include "st_done.h"
27 #include "st_title.h"
29 /*---------------------------------------------------------------------------*/
31 #define DONE_OK 2
33 static int high;
34 static int time_i;
35 static int coin_i;
37 static int done_action(int i)
39 char player[MAXNAM];
40 size_t l;
42 audio_play(AUD_MENU, 1.0f);
44 config_get_s(CONFIG_PLAYER, player, MAXNAM);
45 l = strlen(player);
47 switch (i)
49 case DONE_OK:
50 level_free();
51 return goto_state(&st_title);
53 case GUI_CL:
54 gui_keyboard_lock();
55 break;
57 case GUI_BS:
58 if (l > 0)
60 player[l - 1] = 0;
62 config_set_s(CONFIG_PLAYER, player);
63 level_name(0, player, time_i, coin_i);
64 set_most_coins(0, 4);
65 set_best_times(0, 4);
67 break;
69 default:
70 if (l < MAXNAM - 1)
72 player[l + 0] = gui_keyboard_char((char) i);
73 player[l + 1] = 0;
75 config_set_s(CONFIG_PLAYER, player);
76 level_name(0, player, time_i, coin_i);
77 set_most_coins(0, 4);
78 set_best_times(0, 4);
81 return 1;
84 static int done_enter(void)
86 const char *s1 = "New Set Record";
87 const char *s2 = "Set Complete";
89 int id, jd;
91 time_i = 3;
92 coin_i = 3;
93 high = level_done(&time_i, &coin_i);
95 if ((id = gui_vstack(0)))
97 int gid;
99 if (high)
100 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
101 else
102 gid = gui_label(id, s2, GUI_MED, GUI_ALL, gui_blu, gui_grn);
104 gui_space(id);
106 if ((jd = gui_harray(id)))
108 gui_most_coins(jd, 4, coin_i);
109 gui_best_times(jd, 4, time_i);
112 gui_space(id);
113 gui_state(id, "Main Menu", GUI_SML, DONE_OK, 0);
115 if (high) gui_keyboard(id);
117 gui_layout(id, 0, 0);
118 gui_pulse(gid, 1.2f);
121 set_most_coins(0, 4);
122 set_best_times(0, 4);
124 return id;
127 static void done_leave(int id)
129 gui_delete(id);
132 static void done_paint(int id, float st)
134 game_draw(0, st);
135 gui_paint(id);
138 static void done_timer(int id, float dt)
140 gui_timer(id, dt);
141 audio_timer(dt);
144 static void done_point(int id, int x, int y, int dx, int dy)
146 gui_pulse(gui_point(id, x, y), 1.2f);
149 static void done_stick(int id, int a, int v)
151 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
152 gui_pulse(gui_stick(id, v, 0), 1.2f);
153 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
154 gui_pulse(gui_stick(id, 0, v), 1.2f);
157 static int done_click(int b, int d)
159 if (b <= 0 && d == 1)
160 return done_action(gui_token(gui_click()));
161 return 1;
164 static int done_keybd(int c, int d)
166 if (d && c == SDLK_ESCAPE)
167 goto_state(&st_title);
168 return 1;
171 static int done_buttn(int b, int d)
173 if (d)
175 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
176 return done_click(0, 1);
177 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
178 return goto_state(&st_title);
180 return 1;
183 /*---------------------------------------------------------------------------*/
185 struct state st_done = {
186 done_enter,
187 done_leave,
188 done_paint,
189 done_timer,
190 done_point,
191 done_stick,
192 done_click,
193 done_keybd,
194 done_buttn,
195 1, 0