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.
21 #include "st_shared.h"
24 #include "game_common.h"
32 /*---------------------------------------------------------------------------*/
35 #define START_CHALLENGE -2
36 #define START_OPEN_GOALS -3
37 #define START_LOCK_GOALS -4
41 static int challenge_id;
43 /*---------------------------------------------------------------------------*/
45 /* Create a level selector button based upon its existence and status. */
47 static void gui_level(int id, int i)
49 const GLfloat *fore = 0, *back = 0;
55 gui_label(id, " ", GUI_SML, GUI_ALL, gui_blk, gui_blk);
61 fore = level_bonus(i) ? gui_grn : gui_wht;
62 back = level_completed(i) ? fore : gui_yel;
65 jd = gui_label(id, level_name(i), GUI_SML, GUI_ALL, back, fore);
67 if (level_opened(i) || config_cheat())
71 static void start_over_level(int i)
73 if (level_opened(i) || config_cheat())
75 gui_set_image(shot_id, level_shot(i));
77 set_score_board(&get_level(i)->score.most_coins, -1,
78 &get_level(i)->score.best_times, -1,
79 &get_level(i)->score.fast_unlock, -1);
82 gui_set_label(file_id, level_file(i));
86 static void start_over(int id, int pulse)
98 if (i == START_CHALLENGE || i == START_BACK)
100 gui_set_image(shot_id, set_shot(curr_set()));
102 set_score_board(set_coin_score(curr_set()), -1,
103 set_time_score(curr_set()), -1,
107 if (i >= 0 && !GUI_ISMSK(i))
111 /*---------------------------------------------------------------------------*/
113 static int start_action(int i)
115 audio_play(AUD_MENU, 1.0f);
120 return goto_state(&st_set);
122 case START_CHALLENGE:
125 progress_init(curr_mode() == MODE_CHALLENGE ?
126 MODE_NORMAL : MODE_CHALLENGE);
127 gui_toggle(challenge_id);
132 progress_init(MODE_CHALLENGE);
133 return start_action(0);
139 case GUI_FAST_UNLOCK:
141 return goto_state(&st_start);
143 case START_OPEN_GOALS:
144 config_set_d(CONFIG_LOCK_GOALS, 0);
145 return goto_state(&st_start);
147 case START_LOCK_GOALS:
148 config_set_d(CONFIG_LOCK_GOALS, 1);
149 return goto_state(&st_start);
152 if (progress_play(i))
153 return goto_state(&st_level);
160 static int start_enter(void)
162 int w = config_get_d(CONFIG_WIDTH);
163 int h = config_get_d(CONFIG_HEIGHT);
168 progress_init(MODE_NORMAL);
170 if ((id = gui_vstack(0)))
172 if ((jd = gui_hstack(id)))
175 gui_label(jd, set_name(curr_set()), GUI_SML, GUI_ALL,
178 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
183 if ((jd = gui_harray(id)))
187 if ((kd = gui_vstack(jd)))
189 shot_id = gui_image(kd, set_shot(curr_set()),
190 6 * w / 16, 6 * h / 16);
191 file_id = gui_label(kd, " ", GUI_SML, GUI_ALL,
197 shot_id = gui_image(jd, set_shot(curr_set()),
198 7 * w / 16, 7 * h / 16);
201 if ((kd = gui_varray(jd)))
203 for (i = 0; i < 5; i++)
204 if ((ld = gui_harray(kd)))
205 for (j = 4; j >= 0; j--)
206 gui_level(ld, i * 5 + j);
208 challenge_id = gui_state(kd, _("Challenge"),
209 GUI_SML, START_CHALLENGE,
210 curr_mode() == MODE_CHALLENGE);
214 gui_score_board(id, (GUI_MOST_COINS |
216 GUI_FAST_UNLOCK), 0, 0);
219 if ((jd = gui_hstack(id)))
223 if ((kd = gui_harray(jd)))
225 /* TODO, replace the whitespace hack with something sane. */
228 /* Translators: adjust the amount of whitespace here
229 * as necessary for the buttons to look good. */
230 _(" No "), GUI_SML, START_OPEN_GOALS,
231 config_get_d(CONFIG_LOCK_GOALS) == 0);
233 gui_state(kd, _("Yes"), GUI_SML, START_LOCK_GOALS,
234 config_get_d(CONFIG_LOCK_GOALS) == 1);
239 gui_label(jd, _("Lock Goals of Completed Levels?"),
240 GUI_SML, GUI_ALL, 0, 0);
245 gui_layout(id, 0, 0);
247 set_score_board(NULL, -1, NULL, -1, NULL, -1);
250 audio_music_fade_to(0.5f, "bgm/inter.ogg");
255 static void start_point(int id, int x, int y, int dx, int dy)
257 start_over(gui_point(id, x, y), 1);
260 static void start_stick(int id, int a, int v)
262 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
263 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
265 start_over(gui_stick(id, x, y), 1);
268 static int start_keybd(int c, int d)
272 if (c == SDLK_c && config_cheat())
275 return goto_state(&st_start);
277 else if (c == SDLK_F12 && config_cheat())
279 char *dir = concat_string("Screenshots/shot-",
280 set_id(curr_set()), NULL);
285 /* Iterate over all levels, taking a screenshot of each. */
287 for (i = 0; i < MAXLVL; i++)
293 else if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
295 int active = gui_click();
297 if (start_action(gui_score_next(gui_score_get())))
301 * This assumes that 'active' is a valid widget ID even after
302 * the above start_action has recreated the entire widget
303 * hierarchy. Maybe it is. Maybe it isn't.
306 start_over(active, 0);
318 static int start_buttn(int b, int d)
322 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
323 return start_action(gui_token(gui_click()));
324 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
325 return start_action(START_BACK);
330 /*---------------------------------------------------------------------------*/
332 struct state st_start = {