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 /*---------------------------------------------------------------------------*/
43 static int demo_action(int i)
45 audio_play(AUD_MENU, 1.0f);
50 return goto_state(&st_title);
54 return goto_state(&st_demo);
59 return goto_state(&st_demo);
67 if (level_replay(demo_get(i)->filename))
69 return goto_state(&st_demo_play);
74 /*---------------------------------------------------------------------------*/
76 static void demo_replay(int id, int i)
78 int w = config_get_d(CONFIG_WIDTH);
79 int h = config_get_d(CONFIG_HEIGHT);
84 if ((jd = gui_vstack(id)))
87 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
89 nam[MAXNAM - 1] = '\0';
90 strncpy(nam, demo_get(i)->name, MAXNAM);
91 if (nam[MAXNAM - 1] != '\0')
93 nam[MAXNAM - 2] = '.';
94 nam[MAXNAM - 1] = '.';
95 nam[MAXNAM + 0] = '.';
96 nam[MAXNAM + 1] = '\0';
98 gui_state(jd, nam, GUI_SML, i, 0);
100 gui_active(jd, i, 0);
109 static int status_id;
110 static int player_id;
112 static int gui_demo_status(int id, const struct demo *d)
115 const char *mode, *status;
121 /* Build a long name */
122 memset(noname, 'M', MAXNAM - 1);
123 noname[MAXNAM - 1] = '\0';
125 /* Get a long mode */
126 mode = mode_to_str(0, 0);
129 for (i = 1; i <= MODE_COUNT; i++)
131 k = strlen(mode_to_str(i, 0));
136 mode = mode_to_str(i, 0);
140 /* Get a long status */
141 status = status_to_str(0);
143 for (i = 1; i <= GAME_FALL; i++)
145 k = strlen(status_to_str(i));
149 status = status_to_str(i);
155 mode = mode_to_str(d->mode, 0);
156 status = status_to_str(d->status);
159 if ((jd = gui_hstack(id)))
161 if ((kd = gui_vstack(jd)))
163 if ((ld = gui_harray(kd)))
165 if ((md = gui_vstack(ld)))
167 player_id = gui_label(md, (d ? d->player : noname),
168 GUI_SML, GUI_RGT, 0, 0);
169 coin_id = gui_count(md, (d ? d->coins : 100),
171 status_id = gui_label(md, status, GUI_SML, GUI_RGT,
174 if ((md = gui_vstack(ld)))
176 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
178 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
180 gui_label(md, _("State"), GUI_SML, GUI_LFT,
183 if ((md = gui_vstack(ld)))
185 name_id = gui_label(md, (d ? d->name : noname),
186 GUI_SML, GUI_RGT, 0, 0);
187 time_id = gui_clock(md, (d ? d->timer : 35000),
189 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
192 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
193 GUI_SML, GUI_RGT, 0, 0);
195 if ((kd = gui_vstack(jd)))
197 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
198 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
199 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
200 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
202 if (d && d->status == GAME_GOAL)
203 gui_set_color(status_id, gui_grn, gui_grn);
208 static void gui_demo_update_status(int i)
210 const struct demo *d = demo_get(i);
212 gui_set_label(name_id, d->name);
213 gui_set_label(date_id, date_to_str(d->date));
214 gui_set_label(player_id, d->player);
215 gui_set_label(mode_id, mode_to_str(d->mode, 0));
217 if (d->status == GAME_GOAL)
218 gui_set_color(status_id, gui_grn, gui_grn);
220 gui_set_color(status_id, gui_red, gui_red);
222 gui_set_label(status_id, status_to_str(d->status));
223 gui_set_count(coin_id, d->coins);
224 gui_set_clock(time_id, d->timer);
227 /*---------------------------------------------------------------------------*/
229 static int demo_enter(void)
236 if ((total = demo_scan()))
238 if ((jd = gui_hstack(id)))
241 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
243 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total, 0);
246 if ((jd = gui_varray(id)))
247 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
248 if ((kd = gui_harray(jd)))
250 for (j = i + DEMO_LINE - 1; j >= i; j--)
257 gui_demo_status(id, NULL);
258 gui_layout(id, 0, 0);
259 gui_demo_update_status(0);
263 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
264 gui_layout(id, 0, 0);
267 audio_music_fade_to(0.5f, "bgm/inter.ogg");
272 static void demo_timer(int id, float dt)
274 if (total == 0 && time_state() > 4.0f)
275 goto_state(&st_title);
280 static void demo_point(int id, int x, int y, int dx, int dy)
282 int jd = shared_point_basic(id, x, y);
283 int i = gui_token(jd);
286 gui_demo_update_status(i);
289 static void demo_stick(int id, int a, int v)
291 int jd = shared_stick_basic(id, a, v);
292 int i = gui_token(jd);
295 gui_demo_update_status(i);
298 static int demo_buttn(int b, int d)
302 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
303 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
304 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
305 return demo_action(GUI_BACK);
310 /*---------------------------------------------------------------------------*/
312 static int standalone;
313 static int demo_paused;
316 void demo_play_goto(int s)
321 static int demo_play_enter(void)
328 audio_music_fade_in(0.5f);
332 if ((id = gui_vstack(0)))
334 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
335 gui_layout(id, 0, 0);
346 static void demo_play_paint(int id, float st)
353 if (time_state() < 1.f)
357 static void demo_play_timer(int id, float dt)
363 /* Spin or skip depending on how fast the demo wants to run. */
365 if (!demo_replay_step(dt))
368 goto_state(&st_demo_end);
372 static int demo_play_keybd(int c, int d)
376 if (config_tst_d(CONFIG_KEY_PAUSE, c))
379 return goto_state(&st_demo_end);
383 show_hud = !show_hud;
388 static int demo_play_buttn(int b, int d)
392 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
394 if (!(SDL_GetModState() & KMOD_SHIFT))
396 return goto_state(&st_demo_end);
402 /*---------------------------------------------------------------------------*/
407 #define DEMO_REPLAY 3
408 #define DEMO_CONTINUE 4
410 static int demo_end_action(int i)
412 audio_play(AUD_MENU, 1.0f);
418 return goto_state(&st_demo_del);
422 return goto_state(&st_demo);
428 level_replay(curr_demo_replay()->filename);
429 return goto_state(&st_demo_play);
431 return goto_state(&st_demo_play);
436 static int demo_end_enter(void)
440 if ((id = gui_vstack(0)))
443 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
446 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
449 if ((jd = gui_harray(id)))
455 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
459 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
460 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
465 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
466 gui_toggle(start_id);
469 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
473 gui_layout(id, 0, 0);
476 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
481 static void demo_end_paint(int id, float st)
490 static int demo_end_keybd(int c, int d)
494 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
495 return demo_end_action(DEMO_CONTINUE);
500 static int demo_end_buttn(int b, int d)
504 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
505 return demo_end_action(gui_token(gui_click()));
506 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
509 return demo_end_action(DEMO_CONTINUE);
511 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
517 /*---------------------------------------------------------------------------*/
519 static int demo_del_action(int i)
521 audio_play(AUD_MENU, 1.0f);
523 demo_replay_stop(i == DEMO_DEL);
524 return goto_state(&st_demo);
527 static int demo_del_enter(void)
531 if ((id = gui_vstack(0)))
533 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
535 if ((jd = gui_harray(id)))
537 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
538 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
542 gui_layout(id, 0, 0);
544 audio_music_fade_out(2.0f);
549 static int demo_del_buttn(int b, int d)
553 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
554 return demo_del_action(gui_token(gui_click()));
555 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
556 return demo_del_action(DEMO_KEEP);
561 /*---------------------------------------------------------------------------*/
563 struct state st_demo = {
577 struct state st_demo_play = {
591 struct state st_demo_end = {
605 struct state st_demo_del = {