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.
22 #include "st_shared.h"
30 /*---------------------------------------------------------------------------*/
33 #define START_CHALLENGE -2
34 #define START_OPEN_GOALS -3
35 #define START_LOCK_GOALS -4
39 static int challenge_id;
41 /*---------------------------------------------------------------------------*/
43 /* Create a level selector button based upon its existence and status. */
45 static void gui_level(int id, int i)
47 const GLfloat *fore = 0, *back = 0;
53 gui_label(id, " ", GUI_SML, GUI_ALL, gui_blk, gui_blk);
59 fore = level_bonus(i) ? gui_grn : gui_wht;
60 back = level_completed(i) ? fore : gui_yel;
63 jd = gui_label(id, level_name(i), GUI_SML, GUI_ALL, back, fore);
65 if (level_opened(i) || config_cheat())
69 static void start_over_level(int i)
71 if (level_opened(i) || config_cheat())
73 gui_set_image(shot_id, level_shot(i));
75 set_score_board(&get_level(i)->score.most_coins, -1,
76 &get_level(i)->score.best_times, -1,
77 &get_level(i)->score.unlock_goal, -1);
80 gui_set_label(file_id, level_file(i));
84 static void start_over(int id, int pulse)
96 if (i == START_CHALLENGE || i == START_BACK)
98 gui_set_image(shot_id, set_shot(curr_set()));
100 set_score_board(set_coin_score(curr_set()), -1,
101 set_time_score(curr_set()), -1,
102 set_time_score(curr_set()), -1);
105 if (i >= 0 && !GUI_ISMSK(i))
109 /*---------------------------------------------------------------------------*/
111 static int start_action(int i)
113 audio_play(AUD_MENU, 1.0f);
118 return goto_state(&st_set);
120 case START_CHALLENGE:
123 progress_init(curr_mode() == MODE_CHALLENGE ?
124 MODE_NORMAL : MODE_CHALLENGE);
125 gui_toggle(challenge_id);
130 progress_init(MODE_CHALLENGE);
131 return start_action(0);
137 case GUI_UNLOCK_GOAL:
139 return goto_state(&st_start);
141 case START_OPEN_GOALS:
142 config_set_d(CONFIG_LOCK_GOALS, 0);
143 return goto_state(&st_start);
145 case START_LOCK_GOALS:
146 config_set_d(CONFIG_LOCK_GOALS, 1);
147 return goto_state(&st_start);
150 if (progress_play(i))
151 return goto_state(&st_level);
158 static int start_enter(void)
160 int w = config_get_d(CONFIG_WIDTH);
161 int h = config_get_d(CONFIG_HEIGHT);
166 progress_init(MODE_NORMAL);
168 if ((id = gui_vstack(0)))
170 if ((jd = gui_hstack(id)))
173 gui_label(jd, set_name(curr_set()), GUI_SML, GUI_ALL,
176 gui_start(jd, _("Back"), GUI_SML, START_BACK, 0);
179 if ((jd = gui_harray(id)))
183 if ((kd = gui_vstack(jd)))
185 shot_id = gui_image(kd, set_shot(curr_set()),
186 7 * w / 16, 7 * h / 16);
187 file_id = gui_label(kd, " ", GUI_SML, GUI_ALL,
193 shot_id = gui_image(jd, set_shot(curr_set()),
194 7 * w / 16, 7 * h / 16);
197 if ((kd = gui_varray(jd)))
199 for (i = 0; i < 5; i++)
200 if ((ld = gui_harray(kd)))
201 for (j = 4; j >= 0; j--)
202 gui_level(ld, i * 5 + j);
204 challenge_id = gui_state(kd, _("Challenge"),
205 GUI_SML, START_CHALLENGE,
206 curr_mode() == MODE_CHALLENGE);
211 if ((jd = gui_hstack(id)))
212 gui_score_board(jd, GUI_MOST_COINS |
214 GUI_UNLOCK_GOAL, 0, 0);
218 if ((jd = gui_hstack(id)))
222 if ((kd = gui_harray(jd)))
224 /* TODO, replace the whitespace hack with something sane. */
227 /* Translators: adjust the amount of whitespace here
228 * as necessary for the buttons to look good. */
229 _(" No "), GUI_SML, START_OPEN_GOALS,
230 config_get_d(CONFIG_LOCK_GOALS) == 0);
232 gui_state(kd, _("Yes"), GUI_SML, START_LOCK_GOALS,
233 config_get_d(CONFIG_LOCK_GOALS) == 1);
238 gui_label(jd, _("Lock Goals of Completed Levels?"),
239 GUI_SML, GUI_ALL, 0, 0);
244 gui_layout(id, 0, 0);
246 set_score_board(NULL, -1, NULL, -1, NULL, -1);
249 audio_music_fade_to(0.5f, "bgm/inter.ogg");
254 static void start_point(int id, int x, int y, int dx, int dy)
256 start_over(gui_point(id, x, y), 1);
259 static void start_stick(int id, int a, int v)
261 int x = (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a)) ? v : 0;
262 int y = (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a)) ? v : 0;
264 start_over(gui_stick(id, x, y), 1);
267 static int start_keybd(int c, int d)
271 if (c == SDLK_c && config_cheat())
274 return goto_state(&st_start);
276 else if (c == SDLK_F12 && config_cheat())
280 /* Iterate over all levels, taking a screenshot of each. */
282 for (i = 0; i < MAXLVL; i++)
286 else if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
288 int active = gui_click();
290 if (start_action(gui_score_next(gui_score_get())))
294 * This assumes that 'active' is a valid widget ID even after
295 * the above start_action has recreated the entire widget
296 * hierarchy. Maybe it is. Maybe it isn't.
299 start_over(active, 0);
311 static int start_buttn(int b, int d)
315 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
316 return start_action(gui_token(gui_click()));
317 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
318 return start_action(START_BACK);
323 /*---------------------------------------------------------------------------*/
325 struct state st_start = {