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.
25 #include "st_shared.h"
29 #include "game_common.h"
30 #include "game_server.h"
31 #include "game_client.h"
36 /*---------------------------------------------------------------------------*/
44 static int last_viewed = 0;
46 /*---------------------------------------------------------------------------*/
48 static int demo_action(int i)
50 audio_play(AUD_MENU, 1.0f);
55 return goto_state(&st_title);
59 return goto_state(&st_demo);
64 return goto_state(&st_demo);
72 if (progress_replay(demo_get(i)->filename))
76 return goto_state(&st_demo_play);
83 /*---------------------------------------------------------------------------*/
85 static void demo_replay(int id, int i)
87 int w = config_get_d(CONFIG_WIDTH);
88 int h = config_get_d(CONFIG_HEIGHT);
93 if ((jd = gui_vstack(id)))
96 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
98 nam[MAXNAM - 1] = '\0';
99 strncpy(nam, demo_get(i)->name, MAXNAM);
100 if (nam[MAXNAM - 1] != '\0')
102 nam[MAXNAM - 2] = '.';
103 nam[MAXNAM - 1] = '.';
104 nam[MAXNAM + 0] = '.';
105 nam[MAXNAM + 1] = '\0';
107 gui_state(jd, nam, GUI_SML, i, 0);
109 gui_active(jd, i, 0);
117 static int status_id;
118 static int player_id;
120 static int gui_demo_status(int id, const struct demo *d)
129 /* Build a long name */
130 memset(noname, 'M', MAXNAM - 1);
131 noname[MAXNAM - 1] = '\0';
133 /* Get a long status */
134 status = status_to_str(0);
136 for (i = 1; i <= GAME_FALL; i++)
138 k = strlen(status_to_str(i));
142 status = status_to_str(i);
148 status = status_to_str(d->status);
151 if ((jd = gui_hstack(id)))
155 if ((kd = gui_hstack(jd)))
157 if ((ld = gui_vstack(kd)))
161 time_id = gui_clock(ld, (d ? d->timer : 35000),
163 coin_id = gui_count(ld, (d ? d->coins : 100),
165 status_id = gui_label(ld, status, GUI_SML, GUI_SE,
168 if (d && d->status == GAME_GOAL)
169 gui_set_color(status_id, gui_grn, gui_grn);
174 if ((ld = gui_vstack(kd)))
178 gui_label(ld, _("Time"), GUI_SML, GUI_NW,
180 gui_label(ld, _("Coins"), GUI_SML, 0,
182 gui_label(ld, _("Status"), GUI_SML, GUI_SW,
191 if ((kd = gui_vstack(jd)))
195 name_id = gui_label(kd, (d ? d->name : noname),
196 GUI_SML, GUI_NE, 0, 0);
197 player_id = gui_label(kd, (d ? d->player : noname),
199 date_id = gui_label(kd, (d ? date_to_str(d->date) :
200 date_to_str(time(NULL))),
201 GUI_SML, GUI_SE, 0, 0);
206 if ((kd = gui_vstack(jd)))
210 gui_label(kd, _("Replay"), GUI_SML, GUI_NW, gui_wht, gui_wht);
211 gui_label(kd, _("Player"), GUI_SML, 0, gui_wht, gui_wht);
212 gui_label(kd, _("Date"), GUI_SML, GUI_SW, gui_wht, gui_wht);
223 static void gui_demo_update_status(int i)
225 const struct demo *d;
227 if ((d = demo_get(i)) == NULL && (d = demo_get(0)) == NULL)
230 gui_set_label(name_id, d->name);
231 gui_set_label(date_id, date_to_str(d->date));
232 gui_set_label(player_id, d->player);
234 if (d->status == GAME_GOAL)
235 gui_set_color(status_id, gui_grn, gui_grn);
237 gui_set_color(status_id, gui_red, gui_red);
239 gui_set_label(status_id, status_to_str(d->status));
240 gui_set_count(coin_id, d->coins);
241 gui_set_clock(time_id, d->timer);
244 /*---------------------------------------------------------------------------*/
246 static int demo_enter(void)
253 if ((total = demo_scan()))
255 if ((jd = gui_hstack(id)))
258 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
260 gui_navig(jd, first > 0, first + DEMO_STEP < total);
263 if ((jd = gui_varray(id)))
264 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
265 if ((kd = gui_harray(jd)))
267 for (j = i + DEMO_LINE - 1; j >= i; j--)
274 gui_demo_status(id, NULL);
275 gui_layout(id, 0, 0);
276 gui_demo_update_status(last_viewed);
280 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
281 gui_layout(id, 0, 0);
284 audio_music_fade_to(0.5f, "bgm/inter.ogg");
289 static void demo_timer(int id, float dt)
291 if (total == 0 && time_state() > 4.0f)
292 goto_state(&st_title);
297 static void demo_point(int id, int x, int y, int dx, int dy)
299 int jd = shared_point_basic(id, x, y);
300 int i = gui_token(jd);
302 if (jd && i >= 0 && !GUI_ISMSK(i))
303 gui_demo_update_status(i);
306 static void demo_stick(int id, int a, int v)
308 int jd = shared_stick_basic(id, a, v);
309 int i = gui_token(jd);
311 if (jd && i >= 0 && !GUI_ISMSK(i))
312 gui_demo_update_status(i);
315 static int demo_buttn(int b, int d)
319 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
320 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
321 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
322 return demo_action(GUI_BACK);
327 /*---------------------------------------------------------------------------*/
329 static int standalone;
330 static int demo_paused;
333 void demo_play_goto(int s)
338 static int demo_play_enter(void)
345 audio_music_fade_in(0.5f);
349 if ((id = gui_vstack(0)))
351 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
352 gui_layout(id, 0, 0);
358 game_set_fly(0.f, game_client_file());
359 game_client_step(NULL);
364 static void demo_play_paint(int id, float t)
371 if (time_state() < 1.f)
375 static void demo_play_timer(int id, float dt)
382 * Introduce a one-second pause at the start of replay playback. (One
383 * second is the time during which the "Replay" label is being displayed.)
384 * HACK ALERT! "id == 0" means we got here from the pause screen, so no
385 * label has been created and there's no need to wait.
388 if (id != 0 && time_state() < 1.0f)
391 /* Spin or skip depending on how fast the demo wants to run. */
393 if (!demo_replay_step(dt))
396 goto_state(&st_demo_end);
402 static int demo_play_keybd(int c, int d)
406 if (config_tst_d(CONFIG_KEY_PAUSE, c))
409 return goto_state(&st_demo_end);
413 show_hud = !show_hud;
418 static int demo_play_buttn(int b, int d)
422 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
424 if (config_tst_d(CONFIG_KEY_PAUSE, SDLK_ESCAPE))
427 return goto_state(&st_demo_end);
433 /*---------------------------------------------------------------------------*/
438 #define DEMO_REPLAY 3
439 #define DEMO_CONTINUE 4
441 static int demo_end_action(int i)
443 audio_play(AUD_MENU, 1.0f);
449 return goto_state(&st_demo_del);
453 return goto_state(&st_demo);
459 progress_replay(curr_demo_replay()->filename);
460 return goto_state(&st_demo_play);
462 return goto_state(&st_demo_play);
467 static int demo_end_enter(void)
471 if ((id = gui_vstack(0)))
474 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
477 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
480 if ((jd = gui_harray(id)))
486 start_id = gui_start(jd, _("Quit"), GUI_SML, DEMO_QUIT, 1);
490 start_id = gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
491 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
496 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 1);
497 gui_toggle(start_id);
500 gui_state(jd, _("Repeat"), GUI_SML, DEMO_REPLAY, 0);
504 gui_layout(id, 0, 0);
507 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
512 static void demo_end_paint(int id, float t)
521 static int demo_end_keybd(int c, int d)
525 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
526 return demo_end_action(DEMO_CONTINUE);
531 static int demo_end_buttn(int b, int d)
535 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
536 return demo_end_action(gui_token(gui_click()));
538 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
541 return demo_end_action(DEMO_CONTINUE);
543 return demo_end_action(standalone ? DEMO_QUIT : DEMO_KEEP);
549 /*---------------------------------------------------------------------------*/
551 static int demo_del_action(int i)
553 audio_play(AUD_MENU, 1.0f);
555 demo_replay_stop(i == DEMO_DEL);
556 return goto_state(&st_demo);
559 static int demo_del_enter(void)
563 if ((id = gui_vstack(0)))
565 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
567 if ((jd = gui_harray(id)))
569 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
570 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
574 gui_layout(id, 0, 0);
576 audio_music_fade_out(2.0f);
581 static int demo_del_buttn(int b, int d)
585 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
586 return demo_del_action(gui_token(gui_click()));
587 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
588 return demo_del_action(DEMO_KEEP);
593 /*---------------------------------------------------------------------------*/
595 struct state st_demo = {
609 struct state st_demo_play = {
623 struct state st_demo_end = {
637 struct state st_demo_del = {