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"
33 /*---------------------------------------------------------------------------*/
41 static int last_viewed = 0;
43 /*---------------------------------------------------------------------------*/
45 static int demo_action(int i)
47 audio_play(AUD_MENU, 1.0f);
52 return goto_state(&st_title);
56 return goto_state(&st_demo);
61 return goto_state(&st_demo);
69 if (progress_replay(demo_get(i)->filename))
73 return goto_state(&st_demo_play);
80 /*---------------------------------------------------------------------------*/
82 static void demo_replay(int id, int i)
84 int w = config_get_d(CONFIG_WIDTH);
85 int h = config_get_d(CONFIG_HEIGHT);
90 if ((jd = gui_vstack(id)))
93 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
95 nam[MAXNAM - 1] = '\0';
96 strncpy(nam, demo_get(i)->name, MAXNAM);
97 if (nam[MAXNAM - 1] != '\0')
99 nam[MAXNAM - 2] = '.';
100 nam[MAXNAM - 1] = '.';
101 nam[MAXNAM + 0] = '.';
102 nam[MAXNAM + 1] = '\0';
104 gui_state(jd, nam, GUI_SML, i, 0);
106 gui_active(jd, i, 0);
114 static int status_id;
115 static int player_id;
117 static int gui_demo_status(int id, const struct demo *d)
126 /* Build a long name */
127 memset(noname, 'M', MAXNAM - 1);
128 noname[MAXNAM - 1] = '\0';
130 /* Get a long status */
131 status = status_to_str(0);
133 for (i = 1; i <= GAME_FALL; i++)
135 k = strlen(status_to_str(i));
139 status = status_to_str(i);
145 status = status_to_str(d->status);
148 if ((jd = gui_hstack(id)))
152 if ((kd = gui_hstack(jd)))
154 if ((ld = gui_vstack(kd)))
158 time_id = gui_clock(ld, (d ? d->timer : 35000),
160 coin_id = gui_count(ld, (d ? d->coins : 100),
162 status_id = gui_label(ld, status, GUI_SML, GUI_SE,
165 if (d && d->status == GAME_GOAL)
166 gui_set_color(status_id, gui_grn, gui_grn);
171 if ((ld = gui_vstack(kd)))
175 gui_label(ld, _("Time"), GUI_SML, GUI_NW,
177 gui_label(ld, _("Coins"), GUI_SML, 0,
179 gui_label(ld, _("Status"), GUI_SML, GUI_SW,
188 if ((kd = gui_vstack(jd)))
192 name_id = gui_label(kd, (d ? d->name : noname),
193 GUI_SML, GUI_NE, 0, 0);
194 player_id = gui_label(kd, (d ? d->player : noname),
196 date_id = gui_label(kd, (d ? date_to_str(d->date) :
197 date_to_str(time(NULL))),
198 GUI_SML, GUI_SE, 0, 0);
203 if ((kd = gui_vstack(jd)))
207 gui_label(kd, _("Replay"), GUI_SML, GUI_NW, gui_wht, gui_wht);
208 gui_label(kd, _("Player"), GUI_SML, 0, gui_wht, gui_wht);
209 gui_label(kd, _("Date"), GUI_SML, GUI_SW, gui_wht, gui_wht);
220 static void gui_demo_update_status(int i)
222 const struct demo *d;
224 if ((d = demo_get(i)) == NULL && (d = demo_get(0)) == NULL)
227 gui_set_label(name_id, d->name);
228 gui_set_label(date_id, date_to_str(d->date));
229 gui_set_label(player_id, d->player);
231 if (d->status == GAME_GOAL)
232 gui_set_color(status_id, gui_grn, gui_grn);
234 gui_set_color(status_id, gui_red, gui_red);
236 gui_set_label(status_id, status_to_str(d->status));
237 gui_set_count(coin_id, d->coins);
238 gui_set_clock(time_id, d->timer);
241 /*---------------------------------------------------------------------------*/
243 static int demo_enter(void)
250 if ((total = demo_scan()))
252 if ((jd = gui_hstack(id)))
255 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
257 gui_navig(jd, first > 0, first + DEMO_STEP < total);
260 if ((jd = gui_varray(id)))
261 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
262 if ((kd = gui_harray(jd)))
264 for (j = i + DEMO_LINE - 1; j >= i; j--)
271 gui_demo_status(id, NULL);
272 gui_layout(id, 0, 0);
273 gui_demo_update_status(last_viewed);
277 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
278 gui_layout(id, 0, 0);
281 audio_music_fade_to(0.5f, "bgm/inter.ogg");
286 static void demo_timer(int id, float dt)
288 if (total == 0 && time_state() > 4.0f)
289 goto_state(&st_title);
294 static void demo_point(int id, int x, int y, int dx, int dy)
296 int jd = shared_point_basic(id, x, y);
297 int i = gui_token(jd);
299 if (jd && i >= 0 && !GUI_ISMSK(i))
300 gui_demo_update_status(i);
303 static void demo_stick(int id, int a, int v)
305 int jd = shared_stick_basic(id, a, v);
306 int i = gui_token(jd);
308 if (jd && i >= 0 && !GUI_ISMSK(i))
309 gui_demo_update_status(i);
312 static int demo_buttn(int b, int d)
316 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
317 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
318 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
319 return demo_action(GUI_BACK);
324 /*---------------------------------------------------------------------------*/
326 static int standalone;
327 static int demo_paused;
330 void demo_play_goto(int s)
335 static int demo_play_enter(void)
342 audio_music_fade_in(0.5f);
346 if ((id = gui_vstack(0)))
348 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
349 gui_layout(id, 0, 0);
360 static void demo_play_paint(int id, float t)
367 if (time_state() < 1.f)
371 static void demo_play_timer(int id, float dt)
378 * Introduce a one-second pause at the start of replay playback. (One
379 * second is the time during which the "Replay" label is being displayed.)
380 * HACK ALERT! "id == 0" means we got here from the pause screen, so no
381 * label has been created and there's no need to wait.
384 if (id != 0 && time_state() < 1.0f)
387 /* Spin or skip depending on how fast the demo wants to run. */
389 if (!demo_replay_step(dt))
392 goto_state(&st_demo_end);
398 static int demo_play_keybd(int c, int d)
402 if (config_tst_d(CONFIG_KEY_PAUSE, c))
405 return goto_state(&st_demo_end);
409 show_hud = !show_hud;
414 static int demo_play_buttn(int b, int d)
418 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
420 if (config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
423 return goto_state(&st_demo_end);
429 /*---------------------------------------------------------------------------*/
434 #define DEMO_REPLAY 3
435 #define DEMO_CONTINUE 4
437 static int demo_end_action(int i)
439 audio_play(AUD_MENU, 1.0f);
445 return goto_state(&st_demo_del);
449 return goto_state(&st_demo);
455 progress_replay(curr_demo_replay()->filename);
456 return goto_state(&st_demo_play);
458 return goto_state(&st_demo_play);
463 static int demo_end_enter(void)
467 if ((id = gui_vstack(0)))
470 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
473 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
476 if ((jd = gui_harray(id)))
482 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
486 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
487 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
492 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
493 gui_toggle(start_id);
496 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
500 gui_layout(id, 0, 0);
503 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
508 static void demo_end_paint(int id, float t)
517 static int demo_end_keybd(int c, int d)
521 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
522 return demo_end_action(DEMO_CONTINUE);
527 static int demo_end_buttn(int b, int d)
531 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
532 return demo_end_action(gui_token(gui_click()));
534 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
537 return demo_end_action(DEMO_CONTINUE);
539 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
545 /*---------------------------------------------------------------------------*/
547 static int demo_del_action(int i)
549 audio_play(AUD_MENU, 1.0f);
551 demo_replay_stop(i == DEMO_DEL);
552 return goto_state(&st_demo);
555 static int demo_del_enter(void)
559 if ((id = gui_vstack(0)))
561 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
563 if ((jd = gui_harray(id)))
565 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
566 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
570 gui_layout(id, 0, 0);
572 audio_music_fade_out(2.0f);
577 static int demo_del_buttn(int b, int d)
581 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
582 return demo_del_action(gui_token(gui_click()));
583 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
584 return demo_del_action(DEMO_KEEP);
589 /*---------------------------------------------------------------------------*/
591 struct state st_demo = {
605 struct state st_demo_play = {
619 struct state st_demo_end = {
633 struct state st_demo_del = {