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 /*---------------------------------------------------------------------------*/
40 /*---------------------------------------------------------------------------*/
42 static int demo_action(int i)
44 audio_play(AUD_MENU, 1.0f);
49 return goto_state(&st_title);
53 return goto_state(&st_demo);
58 return goto_state(&st_demo);
66 if (level_replay(demo_get(i)->filename))
68 return goto_state(&st_demo_play);
73 /*---------------------------------------------------------------------------*/
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);
83 if ((jd = gui_vstack(id)))
86 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
88 nam[MAXNAM - 1] = '\0';
89 strncpy(nam, demo_get(i)->name, MAXNAM);
90 if (nam[MAXNAM - 1] != '\0')
92 nam[MAXNAM - 2] = '.';
93 nam[MAXNAM - 1] = '.';
94 nam[MAXNAM + 0] = '.';
95 nam[MAXNAM + 1] = '\0';
97 gui_state(jd, nam, GUI_SML, i, 0);
108 static int status_id;
109 static int player_id;
111 static int gui_demo_status(int id, const struct demo *d)
114 const char *mode, *status;
120 /* Build a long name */
121 memset(noname, 'M', MAXNAM - 1);
122 noname[MAXNAM - 1] = '\0';
124 /* Get a long mode */
125 mode = mode_to_str(0, 0);
128 for (i = 1; i <= MODE_COUNT; i++)
130 k = strlen(mode_to_str(i, 0));
135 mode = mode_to_str(i, 0);
139 /* Get a long status */
140 status = status_to_str(0);
142 for (i = 1; i <= GAME_FALL; i++)
144 k = strlen(status_to_str(i));
148 status = status_to_str(i);
154 mode = mode_to_str(d->mode, 0);
155 status = status_to_str(d->status);
158 if ((jd = gui_hstack(id)))
160 if ((kd = gui_vstack(jd)))
162 if ((ld = gui_harray(kd)))
164 if ((md = gui_vstack(ld)))
166 player_id = gui_label(md, (d ? d->player : noname),
167 GUI_SML, GUI_RGT, 0, 0);
168 coin_id = gui_count(md, (d ? d->coins : 100),
170 status_id = gui_label(md, status, GUI_SML, GUI_RGT,
173 if ((md = gui_vstack(ld)))
175 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
177 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
179 gui_label(md, _("State"), GUI_SML, GUI_LFT,
182 if ((md = gui_vstack(ld)))
184 name_id = gui_label(md, (d ? d->name : noname),
185 GUI_SML, GUI_RGT, 0, 0);
186 time_id = gui_clock(md, (d ? d->timer : 35000),
188 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
191 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
192 GUI_SML, GUI_RGT, 0, 0);
194 if ((kd = gui_vstack(jd)))
196 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
197 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
198 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
199 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
201 if (d && d->status == GAME_GOAL)
202 gui_set_color(status_id, gui_grn, gui_grn);
207 static void gui_demo_update_status(int i)
209 const struct demo *d = demo_get(i);
211 gui_set_label(name_id, d->name);
212 gui_set_label(date_id, date_to_str(d->date));
213 gui_set_label(player_id, d->player);
214 gui_set_label(mode_id, mode_to_str(d->mode, 0));
216 if (d->status == GAME_GOAL)
217 gui_set_color(status_id, gui_grn, gui_grn);
219 gui_set_color(status_id, gui_red, gui_red);
221 gui_set_label(status_id, status_to_str(d->status));
222 gui_set_count(coin_id, d->coins);
223 gui_set_clock(time_id, d->timer);
226 /*---------------------------------------------------------------------------*/
228 static int demo_enter(void)
235 if ((total = demo_scan()))
237 if ((jd = gui_hstack(id)))
240 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
242 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
245 if ((jd = gui_varray(id)))
246 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
247 if ((kd = gui_harray(jd)))
249 for (j = i + DEMO_LINE - 1; j >= i; j--)
256 gui_demo_status(id, NULL);
257 gui_layout(id, 0, 0);
258 gui_demo_update_status(0);
262 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
263 gui_layout(id, 0, 0);
266 audio_music_fade_to(0.5f, "bgm/inter.ogg");
271 static void demo_timer(int id, float dt)
273 if (total == 0 && time_state() > 4.0f)
274 goto_state(&st_title);
279 static void demo_point(int id, int x, int y, int dx, int dy)
281 int jd = shared_point_basic(id, x, y);
282 int i = gui_token(jd);
285 gui_demo_update_status(i);
288 static void demo_stick(int id, int a, int v)
290 int jd = shared_stick_basic(id, a, v);
291 int i = gui_token(jd);
294 gui_demo_update_status(i);
297 static int demo_buttn(int b, int d)
301 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
302 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
303 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
304 return demo_action(GUI_BACK);
309 /*---------------------------------------------------------------------------*/
311 static int standalone;
312 static int demo_paused;
314 void demo_play_goto(int s)
319 static int demo_play_enter(void)
326 audio_music_fade_in(0.5f);
330 if ((id = gui_vstack(0)))
332 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
333 gui_layout(id, 0, 0);
344 static void demo_play_paint(int id, float st)
349 if (time_state() < 1.f)
353 static void demo_play_timer(int id, float dt)
359 /* Spin or skip depending on how fast the demo wants to run. */
361 if (!demo_replay_step(dt))
364 goto_state(&st_demo_end);
368 static int demo_play_keybd(int c, int d)
372 if (config_tst_d(CONFIG_KEY_PAUSE, c))
375 return goto_state(&st_demo_end);
381 static int demo_play_buttn(int b, int d)
385 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
387 if (!(SDL_GetModState() & KMOD_SHIFT))
389 return goto_state(&st_demo_end);
395 /*---------------------------------------------------------------------------*/
400 #define DEMO_REPLAY 3
401 #define DEMO_CONTINUE 4
403 static int demo_end_action(int i)
405 audio_play(AUD_MENU, 1.0f);
411 return goto_state(&st_demo_del);
415 return goto_state(&st_demo);
421 level_replay(curr_demo_replay()->filename);
422 return goto_state(&st_demo_play);
424 return goto_state(&st_demo_play);
429 static int demo_end_enter(void)
433 if ((id = gui_vstack(0)))
436 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
439 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
442 if ((jd = gui_harray(id)))
448 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
452 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
453 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
458 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
459 gui_toggle(start_id);
462 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
466 gui_layout(id, 0, 0);
469 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
474 static void demo_end_paint(int id, float st)
483 static int demo_end_keybd(int c, int d)
487 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
488 return demo_end_action(DEMO_CONTINUE);
493 static int demo_end_buttn(int b, int d)
497 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
498 return demo_end_action(gui_token(gui_click()));
499 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
502 return demo_end_action(DEMO_CONTINUE);
504 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
510 /*---------------------------------------------------------------------------*/
512 static int demo_del_action(int i)
514 audio_play(AUD_MENU, 1.0f);
516 demo_replay_stop(i == DEMO_DEL);
517 return goto_state(&st_demo);
520 static int demo_del_enter(void)
524 if ((id = gui_vstack(0)))
526 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
528 if ((jd = gui_harray(id)))
530 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
531 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
535 gui_layout(id, 0, 0);
537 audio_music_fade_out(2.0f);
542 static int demo_del_buttn(int b, int d)
546 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
547 return demo_del_action(gui_token(gui_click()));
548 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
549 return demo_del_action(DEMO_KEEP);
554 /*---------------------------------------------------------------------------*/
556 struct state st_demo = {
570 struct state st_demo_play = {
584 struct state st_demo_end = {
598 struct state st_demo_del = {