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.
26 #include "st_shared.h"
32 extern struct state st_demo_play;
33 extern struct state st_demo_end;
34 extern struct state st_demo_del;
36 /*---------------------------------------------------------------------------*/
44 static float replay_time;
45 static float global_time;
47 /*---------------------------------------------------------------------------*/
49 static int demo_action(int i)
51 audio_play(AUD_MENU, 1.0f);
56 return goto_state(&st_title);
60 return goto_state(&st_demo);
65 return goto_state(&st_demo);
69 if (level_replay(get_demo(i)->filename))
70 return goto_demo_play(0);
75 static void demo_replay(int id, int i)
77 int w = config_get_d(CONFIG_WIDTH);
78 int h = config_get_d(CONFIG_HEIGHT);
81 if ((jd = gui_vstack(id)))
85 gui_image(jd, get_demo(i)->shot, w / 6, h / 6);
86 gui_state(jd, get_demo(i)->name, GUI_SML, i, 0);
101 static int gui_demo_status(int id, const struct demo * d)
102 /* Create a layout for some demo info, if d is NULL, try to reserve enought space */
105 const char *mode, *state;
111 /* Build a long name */
112 memset(noname, 'M', MAXNAM-1);
113 noname[MAXNAM-1] = '\0';
115 /* Get a long mode */
116 mode = mode_to_str(0);
118 for(i=1; i<=MODE_SINGLE; i++)
120 k = strlen(mode_to_str(i));
124 mode = mode_to_str(i);
128 /* Get a long state */
129 state = state_to_str(0);
131 for(i=1; i<=GAME_FALL; i++)
133 k = strlen(state_to_str(i));
137 state = state_to_str(i);
143 mode = mode_to_str(d->mode);
144 state = state_to_str(d->state);
147 if ((jd = gui_hstack(id)))
149 if((kd = gui_vstack(jd)))
151 if ((ld = gui_harray(kd)))
153 if ((md = gui_vstack(ld)))
155 player_id = gui_label(md, (d?d->player:noname), GUI_SML, GUI_RGT, 0, 0);
156 coin_id = gui_count(md, (d?d->coins:100), GUI_SML, GUI_RGT);
157 state_id = gui_label(md, state, GUI_SML, GUI_RGT, gui_red, gui_red);
159 if ((md = gui_vstack(ld)))
161 gui_label(md, _("Player"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
162 gui_label(md, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
163 gui_label(md, _("State"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
165 if ((md = gui_vstack(ld)))
167 name_id = gui_label(md, (d?d->name:noname), GUI_SML, GUI_RGT, 0, 0);
168 time_id = gui_clock(md, (d?d->timer:35000), GUI_SML, GUI_RGT);
169 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
172 level_id = gui_label(kd, (d?d->file:"M"), GUI_SML, GUI_RGT, gui_wht, gui_wht);
173 date_id = gui_label(kd, (d?date_to_str(d->date):"M"), GUI_SML, GUI_RGT, 0, 0);
175 if((kd = gui_vstack(jd)))
177 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
178 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
179 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
180 gui_label(kd, _("Level"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
181 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
183 if(d && d->state == GAME_GOAL)
184 gui_set_color(state_id, gui_grn, gui_grn);
189 static void gui_demo_update_status(int i)
191 const struct demo * d = get_demo(i);
193 gui_set_label(name_id, d->name);
194 gui_set_label(date_id, date_to_str(d->date));
195 gui_set_label(level_id, d->file);
196 gui_set_label(player_id, d->player);
197 gui_set_label(mode_id, mode_to_str(d->mode));
198 if (d->state == GAME_GOAL)
199 gui_set_color(state_id, gui_grn, gui_grn);
201 gui_set_color(state_id, gui_red, gui_red);
202 gui_set_label(state_id, state_to_str(d->state));
203 gui_set_count(coin_id, d->coins);
204 gui_set_clock(time_id, d->timer);
207 static int demo_enter(void)
217 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
219 gui_multi(id, _("You can save replays of your games.\\"
220 "Currently, there are no replays saved."),
221 GUI_SML, GUI_ALL, gui_wht, gui_wht);
223 gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
224 gui_layout(id, 0, 0);
228 if ((jd = gui_hstack(id)))
231 ld = gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
233 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
235 if ((jd = gui_varray(id)))
236 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
237 if ((kd = gui_harray(jd)))
239 for (j = i + DEMO_LINE - 1; j >= i; j--)
246 gui_demo_status(id, NULL);
247 gui_layout(id, 0, 0);
248 gui_demo_update_status(0);
251 audio_music_fade_to(0.5f, "bgm/inter.ogg");
256 static void demo_point(int id, int x, int y, int dx, int dy)
258 int jd = shared_point_basic(id, x, y);
259 int i = gui_token(jd);
261 gui_demo_update_status(i);
264 static void demo_stick(int id, int a, int v)
266 int jd = shared_stick_basic(id, a, v);
267 int i = gui_token(jd);
269 gui_demo_update_status(i);
272 static int demo_buttn(int b, int d)
276 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
277 return demo_action(gui_token(gui_click()));
278 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
279 return demo_action(GUI_BACK);
284 /*---------------------------------------------------------------------------*/
286 static int simple_play;
287 int goto_demo_play(int simple)
289 simple_play = simple;
290 return goto_state(&st_demo_play);
293 static int demo_play_enter(void)
297 if ((id = gui_vstack(0)))
299 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
300 gui_layout(id, 0, 0);
314 static void demo_play_paint(int id, float st)
319 if (time_state() < 1.f)
323 static void demo_play_timer(int id, float dt)
334 /* Spin or skip depending on how fast the demo wants to run. */
336 while (replay_time < global_time)
337 if (demo_replay_step(&t))
343 goto_state(&st_demo_end);
348 static int demo_play_buttn(int b, int d)
352 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
353 return goto_state(&st_demo_end);
358 /*---------------------------------------------------------------------------*/
363 #define DEMO_REPLAY 3
365 static int demo_end_action(int i)
367 audio_play(AUD_MENU, 1.0f);
372 return goto_state(&st_demo_del);
375 return goto_state(&st_demo);
381 level_replay(curr_demo_replay()->filename);
382 return goto_state(&st_demo_play);
387 static int demo_end_enter(void)
391 if ((id = gui_vstack(0)))
393 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
395 if ((jd = gui_harray(id)))
397 gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
399 gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
402 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
403 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
409 if ((jd = gui_hstack(id)))
412 gui_demo_status(jd, curr_demo_replay());
417 gui_layout(id, 0, 0);
419 audio_music_fade_out(2.0f);
424 static void demo_end_timer(int id, float dt)
426 float g[3] = { 0.0f, -9.8f, 0.0f };
428 if (time_state() < 2.f)
429 game_step(g, dt, NULL);
435 static int demo_end_buttn(int b, int d)
439 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
440 return demo_end_action(gui_token(gui_click()));
441 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
442 return demo_end_action(simple_play ? DEMO_QUIT : DEMO_KEEP);
447 /*---------------------------------------------------------------------------*/
449 static int demo_del_action(int i)
451 audio_play(AUD_MENU, 1.0f);
453 demo_replay_stop(i == DEMO_DEL);
454 return goto_state(&st_demo);
457 static int demo_del_enter(void)
461 if ((id = gui_vstack(0)))
463 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
465 if ((jd = gui_harray(id)))
467 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
468 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
472 gui_layout(id, 0, 0);
474 audio_music_fade_out(2.0f);
479 static int demo_del_buttn(int b, int d)
483 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
484 return demo_del_action(gui_token(gui_click()));
485 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
486 return demo_del_action(DEMO_KEEP);
491 /*---------------------------------------------------------------------------*/
493 struct state st_demo = {
506 struct state st_demo_play = {
519 struct state st_demo_end = {
532 struct state st_demo_del = {