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 extern struct state st_demo_play;
33 extern struct state st_demo_end;
34 extern struct state st_demo_del;
36 /*---------------------------------------------------------------------------*/
44 static float replay_time;
45 static float global_time;
47 /*---------------------------------------------------------------------------*/
49 static int demo_action(int i)
51 audio_play(AUD_MENU, 1.0f);
56 return goto_state(&st_title);
60 return goto_state(&st_demo);
65 return goto_state(&st_demo);
69 if (level_replay(get_demo(i)->filename))
70 return goto_demo_play(0);
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);
82 if ((jd = gui_vstack(id)))
86 gui_image(jd, get_demo(i)->shot, w / 6, h / 6);
87 nam[MAXNAM - 1] = '\0';
88 strncpy(nam, get_demo(i)->name, MAXNAM);
89 if (nam[MAXNAM - 1] != '\0')
91 nam[MAXNAM - 2] = '.';
92 nam[MAXNAM - 1] = '.';
93 nam[MAXNAM + 0] = '.';
94 nam[MAXNAM + 1] = '\0';
96 gui_state(jd, nam, GUI_SML, i, 0);
109 static int player_id;
111 static int gui_demo_status(int id, const struct demo *d)
112 /* Create a layout for some demo info, if d is NULL, try to reserve enough
116 const char *mode, *state;
122 /* Build a long name */
123 memset(noname, 'M', MAXNAM - 1);
124 noname[MAXNAM - 1] = '\0';
126 /* Get a long mode */
127 mode = mode_to_str(0);
129 for (i = 1; i <= MODE_SINGLE; i++)
131 k = strlen(mode_to_str(i));
135 mode = mode_to_str(i);
139 /* Get a long state */
140 state = state_to_str(0);
142 for (i = 1; i <= GAME_FALL; i++)
144 k = strlen(state_to_str(i));
148 state = state_to_str(i);
154 mode = mode_to_str(d->mode);
155 state = state_to_str(d->state);
158 if ((jd = gui_hstack(id)))
160 if ((kd = gui_vstack(jd)))
162 if ((ld = gui_harray(kd)))
164 if ((md = gui_vstack(ld)))
167 gui_label(md, (d ? d->player : noname), GUI_SML,
170 gui_count(md, (d ? d->coins : 100), GUI_SML, GUI_RGT);
172 gui_label(md, state, GUI_SML, GUI_RGT, gui_red,
175 if ((md = gui_vstack(ld)))
177 gui_label(md, _("Player"), GUI_SML, GUI_LFT, gui_wht,
179 gui_label(md, _("Coins"), GUI_SML, GUI_LFT, gui_wht,
181 gui_label(md, _("State"), GUI_SML, GUI_LFT, gui_wht,
184 if ((md = gui_vstack(ld)))
187 gui_label(md, (d ? d->name : noname), GUI_SML, GUI_RGT,
190 gui_clock(md, (d ? d->timer : 35000), GUI_SML, GUI_RGT);
191 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
195 gui_label(kd, (d ? d->file : "M"), GUI_SML, GUI_RGT, gui_wht,
198 gui_label(kd, (d ? date_to_str(d->date) : "M"), GUI_SML,
201 if ((kd = gui_vstack(jd)))
203 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
204 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
205 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
206 gui_label(kd, _("Level"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
207 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
209 if (d && (d->state == GAME_GOAL || d->state == GAME_SPEC))
210 gui_set_color(state_id, gui_grn, gui_grn);
215 static void gui_demo_update_status(int i)
217 const struct demo *d = get_demo(i);
219 gui_set_label(name_id, d->name);
220 gui_set_label(date_id, date_to_str(d->date));
221 gui_set_label(level_id, d->file);
222 gui_set_label(player_id, d->player);
223 gui_set_label(mode_id, mode_to_str(d->mode));
225 if (d->state == GAME_GOAL || d->state == GAME_SPEC)
226 gui_set_color(state_id, gui_grn, gui_grn);
228 gui_set_color(state_id, gui_red, gui_red);
230 gui_set_label(state_id, state_to_str(d->state));
231 gui_set_count(coin_id, d->coins);
232 gui_set_clock(time_id, d->timer);
235 static int demo_enter(void)
245 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
247 gui_multi(id, _("You can save replays of your games.\\"
248 "Currently, there are no replays saved."),
249 GUI_SML, GUI_ALL, gui_wht, gui_wht);
251 gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
252 gui_layout(id, 0, 0);
256 if ((jd = gui_hstack(id)))
259 ld = gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
261 gui_back_prev_next(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(0);
279 audio_music_fade_to(0.5f, "bgm/inter.ogg");
284 static void demo_point(int id, int x, int y, int dx, int dy)
286 int jd = shared_point_basic(id, x, y);
287 int i = gui_token(jd);
289 gui_demo_update_status(i);
292 static void demo_stick(int id, int a, int v)
294 int jd = shared_stick_basic(id, a, v);
295 int i = gui_token(jd);
297 gui_demo_update_status(i);
300 static int demo_buttn(int b, int d)
304 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
305 return demo_action(gui_token(gui_click()));
306 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
307 return demo_action(GUI_BACK);
312 /*---------------------------------------------------------------------------*/
314 static int simple_play;
316 int goto_demo_play(int simple)
318 simple_play = simple;
319 return goto_state(&st_demo_play);
322 static int demo_play_enter(void)
326 if ((id = gui_vstack(0)))
328 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
329 gui_layout(id, 0, 0);
343 static void demo_play_paint(int id, float st)
348 if (time_state() < 1.f)
352 static void demo_play_timer(int id, float dt)
363 /* Spin or skip depending on how fast the demo wants to run. */
365 while (replay_time < global_time)
366 if (demo_replay_step(&t))
372 goto_state(&st_demo_end);
377 static int demo_play_buttn(int b, int d)
381 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
382 return goto_state(&st_demo_end);
387 /*---------------------------------------------------------------------------*/
392 #define DEMO_REPLAY 3
394 static int demo_end_action(int i)
396 audio_play(AUD_MENU, 1.0f);
401 return goto_state(&st_demo_del);
404 return goto_state(&st_demo);
410 level_replay(curr_demo_replay()->filename);
411 return goto_state(&st_demo_play);
416 static int demo_end_enter(void)
420 if ((id = gui_vstack(0)))
422 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
424 if ((jd = gui_harray(id)))
426 gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
428 gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
431 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
432 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
438 if ((jd = gui_hstack(id)))
441 gui_demo_status(jd, curr_demo_replay());
446 gui_layout(id, 0, 0);
448 audio_music_fade_out(2.0f);
453 static void demo_end_timer(int id, float dt)
455 float gg[3] = { 0.0f, 9.8f, 0.0f };
456 float gf[3] = { 0.0f, -9.8f, 0.0f };
457 int state = curr_demo_replay()->state;
459 if (time_state() < 2.f && state != GAME_NONE)
460 game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf, dt, NULL);
466 static int demo_end_buttn(int b, int d)
470 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
471 return demo_end_action(gui_token(gui_click()));
472 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
473 return demo_end_action(simple_play ? DEMO_QUIT : DEMO_KEEP);
478 /*---------------------------------------------------------------------------*/
480 static int demo_del_action(int i)
482 audio_play(AUD_MENU, 1.0f);
484 demo_replay_stop(i == DEMO_DEL);
485 return goto_state(&st_demo);
488 static int demo_del_enter(void)
492 if ((id = gui_vstack(0)))
494 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
496 if ((jd = gui_harray(id)))
498 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
499 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
503 gui_layout(id, 0, 0);
505 audio_music_fade_out(2.0f);
510 static int demo_del_buttn(int b, int d)
514 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
515 return demo_del_action(gui_token(gui_click()));
516 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
517 return demo_del_action(DEMO_KEEP);
522 /*---------------------------------------------------------------------------*/
524 struct state st_demo = {
537 struct state st_demo_play = {
550 struct state st_demo_end = {
563 struct state st_demo_del = {