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 (level_replay(demo_get(i)->filename))
73 return goto_state(&st_demo_play);
79 /*---------------------------------------------------------------------------*/
81 static void demo_replay(int id, int i)
83 int w = config_get_d(CONFIG_WIDTH);
84 int h = config_get_d(CONFIG_HEIGHT);
89 if ((jd = gui_vstack(id)))
92 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
94 nam[MAXNAM - 1] = '\0';
95 strncpy(nam, demo_get(i)->name, MAXNAM);
96 if (nam[MAXNAM - 1] != '\0')
98 nam[MAXNAM - 2] = '.';
99 nam[MAXNAM - 1] = '.';
100 nam[MAXNAM + 0] = '.';
101 nam[MAXNAM + 1] = '\0';
103 gui_state(jd, nam, GUI_SML, i, 0);
105 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)
120 const char *mode, *status;
126 /* Build a long name */
127 memset(noname, 'M', MAXNAM - 1);
128 noname[MAXNAM - 1] = '\0';
130 /* Get a long mode */
131 mode = mode_to_str(0, 0);
134 for (i = 1; i <= MODE_COUNT; i++)
136 k = strlen(mode_to_str(i, 0));
141 mode = mode_to_str(i, 0);
145 /* Get a long status */
146 status = status_to_str(0);
148 for (i = 1; i <= GAME_FALL; i++)
150 k = strlen(status_to_str(i));
154 status = status_to_str(i);
160 mode = mode_to_str(d->mode, 0);
161 status = status_to_str(d->status);
164 if ((jd = gui_hstack(id)))
166 if ((kd = gui_vstack(jd)))
168 if ((ld = gui_harray(kd)))
170 if ((md = gui_vstack(ld)))
172 player_id = gui_label(md, (d ? d->player : noname),
173 GUI_SML, GUI_RGT, 0, 0);
174 coin_id = gui_count(md, (d ? d->coins : 100),
176 status_id = gui_label(md, status, GUI_SML, GUI_RGT,
179 if ((md = gui_vstack(ld)))
181 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
183 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
185 gui_label(md, _("State"), GUI_SML, GUI_LFT,
188 if ((md = gui_vstack(ld)))
190 name_id = gui_label(md, (d ? d->name : noname),
191 GUI_SML, GUI_RGT, 0, 0);
192 time_id = gui_clock(md, (d ? d->timer : 35000),
194 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
197 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
198 GUI_SML, GUI_RGT, 0, 0);
200 if ((kd = gui_vstack(jd)))
202 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
203 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
204 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
205 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
207 if (d && d->status == GAME_GOAL)
208 gui_set_color(status_id, gui_grn, gui_grn);
213 static void gui_demo_update_status(int i)
215 const struct demo *d;
217 if ((d = demo_get(i)) == NULL && (d = demo_get(0)) == NULL)
220 gui_set_label(name_id, d->name);
221 gui_set_label(date_id, date_to_str(d->date));
222 gui_set_label(player_id, d->player);
223 gui_set_label(mode_id, mode_to_str(d->mode, 0));
225 if (d->status == GAME_GOAL)
226 gui_set_color(status_id, gui_grn, gui_grn);
228 gui_set_color(status_id, gui_red, gui_red);
230 gui_set_label(status_id, status_to_str(d->status));
231 gui_set_count(coin_id, d->coins);
232 gui_set_clock(time_id, d->timer);
235 /*---------------------------------------------------------------------------*/
237 static int demo_enter(void)
244 if ((total = demo_scan()))
246 if ((jd = gui_hstack(id)))
249 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
251 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
254 if ((jd = gui_varray(id)))
255 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
256 if ((kd = gui_harray(jd)))
258 for (j = i + DEMO_LINE - 1; j >= i; j--)
265 gui_demo_status(id, NULL);
266 gui_layout(id, 0, 0);
267 gui_demo_update_status(last_viewed);
271 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
272 gui_layout(id, 0, 0);
275 audio_music_fade_to(0.5f, "bgm/inter.ogg");
280 static void demo_timer(int id, float dt)
282 if (total == 0 && time_state() > 4.0f)
283 goto_state(&st_title);
288 static void demo_point(int id, int x, int y, int dx, int dy)
290 int jd = shared_point_basic(id, x, y);
291 int i = gui_token(jd);
294 gui_demo_update_status(i);
297 static void demo_stick(int id, int a, int v)
299 int jd = shared_stick_basic(id, a, v);
300 int i = gui_token(jd);
303 gui_demo_update_status(i);
306 static int demo_buttn(int b, int d)
310 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
311 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
312 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
313 return demo_action(GUI_BACK);
318 /*---------------------------------------------------------------------------*/
320 static int standalone;
321 static int demo_paused;
324 void demo_play_goto(int s)
329 static int demo_play_enter(void)
336 audio_music_fade_in(0.5f);
340 if ((id = gui_vstack(0)))
342 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
343 gui_layout(id, 0, 0);
354 static void demo_play_paint(int id, float t)
361 if (time_state() < 1.f)
365 static void demo_play_timer(int id, float dt)
371 /* Spin or skip depending on how fast the demo wants to run. */
373 if (!demo_replay_step(dt))
376 goto_state(&st_demo_end);
380 static int demo_play_keybd(int c, int d)
384 if (config_tst_d(CONFIG_KEY_PAUSE, c))
387 return goto_state(&st_demo_end);
391 show_hud = !show_hud;
396 static int demo_play_buttn(int b, int d)
400 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
402 if (!(SDL_GetModState() & KMOD_SHIFT))
404 return goto_state(&st_demo_end);
410 /*---------------------------------------------------------------------------*/
415 #define DEMO_REPLAY 3
416 #define DEMO_CONTINUE 4
418 static int demo_end_action(int i)
420 audio_play(AUD_MENU, 1.0f);
426 return goto_state(&st_demo_del);
430 return goto_state(&st_demo);
436 level_replay(curr_demo_replay()->filename);
437 return goto_state(&st_demo_play);
439 return goto_state(&st_demo_play);
444 static int demo_end_enter(void)
448 if ((id = gui_vstack(0)))
451 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
454 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
457 if ((jd = gui_harray(id)))
463 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
467 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
468 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
473 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
474 gui_toggle(start_id);
477 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
481 gui_layout(id, 0, 0);
484 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
489 static void demo_end_paint(int id, float t)
498 static int demo_end_keybd(int c, int d)
502 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
503 return demo_end_action(DEMO_CONTINUE);
508 static int demo_end_buttn(int b, int d)
512 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
513 return demo_end_action(gui_token(gui_click()));
514 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
517 return demo_end_action(DEMO_CONTINUE);
519 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
525 /*---------------------------------------------------------------------------*/
527 static int demo_del_action(int i)
529 audio_play(AUD_MENU, 1.0f);
531 demo_replay_stop(i == DEMO_DEL);
532 return goto_state(&st_demo);
535 static int demo_del_enter(void)
539 if ((id = gui_vstack(0)))
541 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
543 if ((jd = gui_harray(id)))
545 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
546 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
550 gui_layout(id, 0, 0);
552 audio_music_fade_out(2.0f);
557 static int demo_del_buttn(int b, int d)
561 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
562 return demo_del_action(gui_token(gui_click()));
563 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
564 return demo_del_action(DEMO_KEEP);
569 /*---------------------------------------------------------------------------*/
571 struct state st_demo = {
585 struct state st_demo_play = {
599 struct state st_demo_end = {
613 struct state st_demo_del = {