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 /*---------------------------------------------------------------------------*/
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))
71 return goto_state(&st_demo_play);
76 /*---------------------------------------------------------------------------*/
78 static void demo_replay(int id, int i)
80 int w = config_get_d(CONFIG_WIDTH);
81 int h = config_get_d(CONFIG_HEIGHT);
86 if ((jd = gui_vstack(id)))
89 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
91 nam[MAXNAM - 1] = '\0';
92 strncpy(nam, demo_get(i)->name, MAXNAM);
93 if (nam[MAXNAM - 1] != '\0')
95 nam[MAXNAM - 2] = '.';
96 nam[MAXNAM - 1] = '.';
97 nam[MAXNAM + 0] = '.';
98 nam[MAXNAM + 1] = '\0';
100 gui_state(jd, nam, GUI_SML, i, 0);
102 gui_active(jd, i, 0);
111 static int status_id;
112 static int player_id;
114 static int gui_demo_status(int id, const struct demo *d)
117 const char *mode, *status;
123 /* Build a long name */
124 memset(noname, 'M', MAXNAM - 1);
125 noname[MAXNAM - 1] = '\0';
127 /* Get a long mode */
128 mode = mode_to_str(0, 0);
131 for (i = 1; i <= MODE_COUNT; i++)
133 k = strlen(mode_to_str(i, 0));
138 mode = mode_to_str(i, 0);
142 /* Get a long status */
143 status = status_to_str(0);
145 for (i = 1; i <= GAME_FALL; i++)
147 k = strlen(status_to_str(i));
151 status = status_to_str(i);
157 mode = mode_to_str(d->mode, 0);
158 status = status_to_str(d->status);
161 if ((jd = gui_hstack(id)))
163 if ((kd = gui_vstack(jd)))
165 if ((ld = gui_harray(kd)))
167 if ((md = gui_vstack(ld)))
169 player_id = gui_label(md, (d ? d->player : noname),
170 GUI_SML, GUI_RGT, 0, 0);
171 coin_id = gui_count(md, (d ? d->coins : 100),
173 status_id = gui_label(md, status, GUI_SML, GUI_RGT,
176 if ((md = gui_vstack(ld)))
178 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
180 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
182 gui_label(md, _("State"), GUI_SML, GUI_LFT,
185 if ((md = gui_vstack(ld)))
187 name_id = gui_label(md, (d ? d->name : noname),
188 GUI_SML, GUI_RGT, 0, 0);
189 time_id = gui_clock(md, (d ? d->timer : 35000),
191 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
194 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
195 GUI_SML, GUI_RGT, 0, 0);
197 if ((kd = gui_vstack(jd)))
199 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
200 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
201 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
202 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
204 if (d && d->status == GAME_GOAL)
205 gui_set_color(status_id, gui_grn, gui_grn);
210 static void gui_demo_update_status(int i)
212 const struct demo *d = demo_get(i);
214 gui_set_label(name_id, d->name);
215 gui_set_label(date_id, date_to_str(d->date));
216 gui_set_label(player_id, d->player);
217 gui_set_label(mode_id, mode_to_str(d->mode, 0));
219 if (d->status == GAME_GOAL)
220 gui_set_color(status_id, gui_grn, gui_grn);
222 gui_set_color(status_id, gui_red, gui_red);
224 gui_set_label(status_id, status_to_str(d->status));
225 gui_set_count(coin_id, d->coins);
226 gui_set_clock(time_id, d->timer);
229 /*---------------------------------------------------------------------------*/
231 static int demo_enter(void)
238 if ((total = demo_scan()))
240 if ((jd = gui_hstack(id)))
243 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
245 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
248 if ((jd = gui_varray(id)))
249 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
250 if ((kd = gui_harray(jd)))
252 for (j = i + DEMO_LINE - 1; j >= i; j--)
259 gui_demo_status(id, NULL);
260 gui_layout(id, 0, 0);
261 gui_demo_update_status(lastv);
265 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
266 gui_layout(id, 0, 0);
269 audio_music_fade_to(0.5f, "bgm/inter.ogg");
274 static void demo_timer(int id, float dt)
276 if (total == 0 && time_state() > 4.0f)
277 goto_state(&st_title);
282 static void demo_point(int id, int x, int y, int dx, int dy)
284 int jd = shared_point_basic(id, x, y);
285 int i = gui_token(jd);
290 gui_demo_update_status(i);
294 static void demo_stick(int id, int a, int v)
296 int jd = shared_stick_basic(id, a, v);
297 int i = gui_token(jd);
300 gui_demo_update_status(i);
303 static int demo_buttn(int b, int d)
307 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
308 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
309 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
310 return demo_action(GUI_BACK);
315 /*---------------------------------------------------------------------------*/
317 static int standalone;
318 static int demo_paused;
321 void demo_play_goto(int s)
326 static int demo_play_enter(void)
333 audio_music_fade_in(0.5f);
337 if ((id = gui_vstack(0)))
339 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
340 gui_layout(id, 0, 0);
351 static void demo_play_paint(int id, float t)
358 if (time_state() < 1.f)
362 static void demo_play_timer(int id, float dt)
368 /* Spin or skip depending on how fast the demo wants to run. */
370 if (!demo_replay_step(dt))
373 goto_state(&st_demo_end);
377 static int demo_play_keybd(int c, int d)
381 if (config_tst_d(CONFIG_KEY_PAUSE, c))
384 return goto_state(&st_demo_end);
388 show_hud = !show_hud;
393 static int demo_play_buttn(int b, int d)
397 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
399 if (!(SDL_GetModState() & KMOD_SHIFT))
401 return goto_state(&st_demo_end);
407 /*---------------------------------------------------------------------------*/
412 #define DEMO_REPLAY 3
413 #define DEMO_CONTINUE 4
415 static int demo_end_action(int i)
417 audio_play(AUD_MENU, 1.0f);
423 return goto_state(&st_demo_del);
427 return goto_state(&st_demo);
433 level_replay(curr_demo_replay()->filename);
434 return goto_state(&st_demo_play);
436 return goto_state(&st_demo_play);
441 static int demo_end_enter(void)
445 if ((id = gui_vstack(0)))
448 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
451 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
454 if ((jd = gui_harray(id)))
460 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
464 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
465 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
470 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
471 gui_toggle(start_id);
474 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
478 gui_layout(id, 0, 0);
481 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
486 static void demo_end_paint(int id, float t)
495 static int demo_end_keybd(int c, int d)
499 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
500 return demo_end_action(DEMO_CONTINUE);
505 static int demo_end_buttn(int b, int d)
509 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
510 return demo_end_action(gui_token(gui_click()));
511 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
514 return demo_end_action(DEMO_CONTINUE);
516 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
522 /*---------------------------------------------------------------------------*/
524 static int demo_del_action(int i)
526 audio_play(AUD_MENU, 1.0f);
528 demo_replay_stop(i == DEMO_DEL);
529 return goto_state(&st_demo);
532 static int demo_del_enter(void)
536 if ((id = gui_vstack(0)))
538 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
540 if ((jd = gui_harray(id)))
542 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
543 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
547 gui_layout(id, 0, 0);
549 audio_music_fade_out(2.0f);
554 static int demo_del_buttn(int b, int d)
558 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
559 return demo_del_action(gui_token(gui_click()));
560 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
561 return demo_del_action(DEMO_KEEP);
566 /*---------------------------------------------------------------------------*/
568 struct state st_demo = {
582 struct state st_demo_play = {
596 struct state st_demo_end = {
610 struct state st_demo_del = {