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 static float replay_time;
41 static float global_time;
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 static void demo_replay(int id, int i)
78 int w = config_get_d(CONFIG_WIDTH);
79 int h = config_get_d(CONFIG_HEIGHT);
84 if ((jd = gui_vstack(id)))
87 gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
89 nam[MAXNAM - 1] = '\0';
90 strncpy(nam, demo_get(i)->name, MAXNAM);
91 if (nam[MAXNAM - 1] != '\0')
93 nam[MAXNAM - 2] = '.';
94 nam[MAXNAM - 1] = '.';
95 nam[MAXNAM + 0] = '.';
96 nam[MAXNAM + 1] = '\0';
98 gui_state(jd, nam, GUI_SML, i, 0);
100 gui_active(jd, i, 0);
110 static int player_id;
112 /* Create a layout for some demo info. If d is NULL, try to reserve enough
115 static int gui_demo_status(int id, const struct demo *d)
118 const char *mode, *state;
124 /* Build a long name */
125 memset(noname, 'M', MAXNAM - 1);
126 noname[MAXNAM - 1] = '\0';
128 /* Get a long mode */
129 mode = mode_to_str(0, 0);
134 * This stuff should not require changes each time a mode is
138 for (i = 1; i <= MODE_PRACTICE; i++)
140 k = strlen(mode_to_str(i, 0));
144 mode = mode_to_str(i, 0);
148 /* Get a long state */
149 state = state_to_str(0);
151 for (i = 1; i <= GAME_FALL; i++)
153 k = strlen(state_to_str(i));
157 state = state_to_str(i);
163 mode = mode_to_str(d->mode, 0);
164 state = state_to_str(d->state);
167 if ((jd = gui_hstack(id)))
169 if ((kd = gui_vstack(jd)))
171 if ((ld = gui_harray(kd)))
173 if ((md = gui_vstack(ld)))
175 player_id = gui_label(md, (d ? d->player : noname),
176 GUI_SML, GUI_RGT, 0, 0);
177 coin_id = gui_count(md, (d ? d->coins : 100),
179 state_id = gui_label(md, state, GUI_SML, GUI_RGT,
182 if ((md = gui_vstack(ld)))
184 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
186 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
188 gui_label(md, _("State"), GUI_SML, GUI_LFT,
191 if ((md = gui_vstack(ld)))
193 name_id = gui_label(md, (d ? d->name : noname),
194 GUI_SML, GUI_RGT, 0, 0);
195 time_id = gui_clock(md, (d ? d->timer : 35000),
197 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
200 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
201 GUI_SML, GUI_RGT, 0, 0);
203 if ((kd = gui_vstack(jd)))
205 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
206 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
207 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
208 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
210 if (d && (d->state == GAME_GOAL || d->state == GAME_SPEC))
211 gui_set_color(state_id, gui_grn, gui_grn);
216 static void gui_demo_update_status(int i)
218 const struct demo *d = demo_get(i);
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->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)
242 if ((total = demo_scan()))
244 if ((jd = gui_hstack(id)))
247 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
249 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
252 if ((jd = gui_varray(id)))
253 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
254 if ((kd = gui_harray(jd)))
256 for (j = i + DEMO_LINE - 1; j >= i; j--)
263 gui_demo_status(id, NULL);
264 gui_layout(id, 0, 0);
265 gui_demo_update_status(0);
269 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
271 gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
272 gui_layout(id, 0, 0);
275 audio_music_fade_to(0.5f, "bgm/inter.ogg");
280 static void demo_point(int id, int x, int y, int dx, int dy)
282 int jd = shared_point_basic(id, x, y);
283 int i = gui_token(jd);
286 gui_demo_update_status(i);
289 static void demo_stick(int id, int a, int v)
291 int jd = shared_stick_basic(id, a, v);
292 int i = gui_token(jd);
295 gui_demo_update_status(i);
298 static int demo_buttn(int b, int d)
302 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
303 return demo_action(gui_token(gui_click()));
304 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
305 return demo_action(GUI_BACK);
310 /*---------------------------------------------------------------------------*/
312 static int simple_play; /* play demo from command line */
314 static int demo_paused;
316 void demo_play_goto(int simple)
318 simple_play = simple;
321 static int demo_play_enter(void)
328 audio_music_fade_in(0.5f);
332 if ((id = gui_vstack(0)))
334 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
335 gui_layout(id, 0, 0);
349 static void demo_play_paint(int id, float st)
354 if (time_state() < 1.f)
358 static void demo_play_timer(int id, float dt)
369 /* Spin or skip depending on how fast the demo wants to run. */
371 while (replay_time < global_time)
372 if (demo_replay_step(&t))
379 goto_state(&st_demo_end);
384 static int demo_play_keybd(int c, int d)
388 if (config_tst_d(CONFIG_KEY_PAUSE, c))
391 return goto_state(&st_demo_end);
397 static int demo_play_buttn(int b, int d)
401 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
403 if (! (SDL_GetModState() & (KMOD_SHIFT | KMOD_CTRL | KMOD_ALT | KMOD_META)))
405 return goto_state(&st_demo_end);
411 /*---------------------------------------------------------------------------*/
416 #define DEMO_REPLAY 3
417 #define DEMO_CONTINUE 4
419 static int demo_end_action(int i)
421 audio_play(AUD_MENU, 1.0f);
426 return goto_state(&st_demo_del);
429 return goto_state(&st_demo);
435 level_replay(curr_demo_replay()->filename);
436 return goto_state(&st_demo_play);
438 return goto_state(&st_demo_play);
443 static int demo_end_enter(void)
447 if ((id = gui_vstack(0)))
450 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
453 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
456 if ((jd = gui_harray(id)))
459 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 0);
461 gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
464 gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
467 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
468 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
474 if ((jd = gui_hstack(id)))
477 gui_demo_status(jd, curr_demo_replay());
482 gui_layout(id, 0, 0);
485 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
490 void demo_end_paint(int id, float st)
499 static void demo_end_timer(int id, float dt)
501 float gg[3] = { 0.0f, 9.8f, 0.0f };
502 float gf[3] = { 0.0f, -9.8f, 0.0f };
503 int state = curr_demo_replay()->state;
505 if (time_state() < 2.f)
507 if (replay_time < global_time)
509 if (state != GAME_NONE && state != GAME_TIME)
510 game_step(state == GAME_GOAL ? gg : gf, dt, NULL);
518 static int demo_end_keybd(int c, int d)
522 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
523 return demo_end_action(DEMO_CONTINUE);
528 static int demo_end_buttn(int b, int d)
532 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
533 return demo_end_action(gui_token(gui_click()));
534 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
535 return demo_end_action(demo_paused
537 : (simple_play ? DEMO_QUIT : DEMO_KEEP));
542 /*---------------------------------------------------------------------------*/
544 static int demo_del_action(int i)
546 audio_play(AUD_MENU, 1.0f);
548 demo_replay_stop(i == DEMO_DEL);
549 return goto_state(&st_demo);
552 static int demo_del_enter(void)
556 if ((id = gui_vstack(0)))
558 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
560 if ((jd = gui_harray(id)))
562 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
563 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
567 gui_layout(id, 0, 0);
569 audio_music_fade_out(2.0f);
574 static int demo_del_buttn(int b, int d)
578 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
579 return demo_del_action(gui_token(gui_click()));
580 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
581 return demo_del_action(DEMO_KEEP);
586 /*---------------------------------------------------------------------------*/
588 struct state st_demo = {
601 struct state st_demo_play = {
614 struct state st_demo_end = {
627 struct state st_demo_del = {