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 /*---------------------------------------------------------------------------*/
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 /* Create a layout for some demo info. If d is NULL, try to reserve enough
117 static int gui_demo_status(int id, const struct demo *d)
120 const char *mode, *status;
126 /* Build a long name */
127 memset(noname, 'M', MAXNAM - 1);
128 noname[MAXNAM - 1] = '\0';
130 /* Get a long mode */
131 mode = mode_to_str(0, 0);
134 for (i = 1; i <= MODE_COUNT; i++)
136 k = strlen(mode_to_str(i, 0));
141 mode = mode_to_str(i, 0);
145 /* Get a long status */
146 status = status_to_str(0);
148 for (i = 1; i <= GAME_FALL; i++)
150 k = strlen(status_to_str(i));
154 status = status_to_str(i);
160 mode = mode_to_str(d->mode, 0);
161 status = status_to_str(d->status);
164 if ((jd = gui_hstack(id)))
166 if ((kd = gui_vstack(jd)))
168 if ((ld = gui_harray(kd)))
170 if ((md = gui_vstack(ld)))
172 player_id = gui_label(md, (d ? d->player : noname),
173 GUI_SML, GUI_RGT, 0, 0);
174 coin_id = gui_count(md, (d ? d->coins : 100),
176 status_id = gui_label(md, status, GUI_SML, GUI_RGT,
179 if ((md = gui_vstack(ld)))
181 gui_label(md, _("Player"), GUI_SML, GUI_LFT,
183 gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
185 gui_label(md, _("State"), GUI_SML, GUI_LFT,
188 if ((md = gui_vstack(ld)))
190 name_id = gui_label(md, (d ? d->name : noname),
191 GUI_SML, GUI_RGT, 0, 0);
192 time_id = gui_clock(md, (d ? d->timer : 35000),
194 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
197 date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
198 GUI_SML, GUI_RGT, 0, 0);
200 if ((kd = gui_vstack(jd)))
202 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
203 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
204 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
205 gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
207 if (d && d->status == GAME_GOAL)
208 gui_set_color(status_id, gui_grn, gui_grn);
213 static void gui_demo_update_status(int i)
215 const struct demo *d = demo_get(i);
217 gui_set_label(name_id, d->name);
218 gui_set_label(date_id, date_to_str(d->date));
219 gui_set_label(player_id, d->player);
220 gui_set_label(mode_id, mode_to_str(d->mode, 0));
222 if (d->status == GAME_GOAL)
223 gui_set_color(status_id, gui_grn, gui_grn);
225 gui_set_color(status_id, gui_red, gui_red);
227 gui_set_label(status_id, status_to_str(d->status));
228 gui_set_count(coin_id, d->coins);
229 gui_set_clock(time_id, d->timer);
232 /*---------------------------------------------------------------------------*/
234 static int demo_enter(void)
241 if ((total = demo_scan()))
243 if ((jd = gui_hstack(id)))
246 gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
248 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
251 if ((jd = gui_varray(id)))
252 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
253 if ((kd = gui_harray(jd)))
255 for (j = i + DEMO_LINE - 1; j >= i; j--)
262 gui_demo_status(id, NULL);
263 gui_layout(id, 0, 0);
264 gui_demo_update_status(0);
268 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0, 0);
269 gui_layout(id, 0, 0);
272 audio_music_fade_to(0.5f, "bgm/inter.ogg");
277 static void demo_timer(int id, float dt)
279 if (total == 0 && time_state() > 4.0f)
280 goto_state(&st_title);
286 static void demo_point(int id, int x, int y, int dx, int dy)
288 int jd = shared_point_basic(id, x, y);
289 int i = gui_token(jd);
292 gui_demo_update_status(i);
295 static void demo_stick(int id, int a, int v)
297 int jd = shared_stick_basic(id, a, v);
298 int i = gui_token(jd);
301 gui_demo_update_status(i);
304 static int demo_buttn(int b, int d)
308 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
309 return demo_action(total ? gui_token(gui_click()) : GUI_BACK);
310 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
311 return demo_action(GUI_BACK);
316 /*---------------------------------------------------------------------------*/
318 /* Play demo from command line. */
319 static int simple_play;
321 static int demo_paused;
323 void demo_play_goto(int simple)
325 simple_play = simple;
328 static int demo_play_enter(void)
335 audio_music_fade_in(0.5f);
339 if ((id = gui_vstack(0)))
341 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
342 gui_layout(id, 0, 0);
356 static void demo_play_paint(int id, float st)
361 if (time_state() < 1.f)
365 static void demo_play_timer(int id, float dt)
376 /* Spin or skip depending on how fast the demo wants to run. */
378 while (replay_time < global_time)
379 if (demo_replay_step(&t))
386 goto_state(&st_demo_end);
391 static int demo_play_keybd(int c, int d)
395 if (config_tst_d(CONFIG_KEY_PAUSE, c))
398 return goto_state(&st_demo_end);
404 static int demo_play_buttn(int b, int d)
408 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
410 if (! (SDL_GetModState() & (KMOD_SHIFT | KMOD_CTRL | KMOD_ALT | KMOD_META)))
412 return goto_state(&st_demo_end);
418 /*---------------------------------------------------------------------------*/
423 #define DEMO_REPLAY 3
424 #define DEMO_CONTINUE 4
426 static int demo_end_action(int i)
428 audio_play(AUD_MENU, 1.0f);
433 return goto_state(&st_demo_del);
436 return goto_state(&st_demo);
442 level_replay(curr_demo_replay()->filename);
443 return goto_state(&st_demo_play);
445 return goto_state(&st_demo_play);
450 static int demo_end_enter(void)
454 if ((id = gui_vstack(0)))
457 kd = gui_label(id, _("Replay Paused"), GUI_LRG, GUI_ALL,
460 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL,
463 if ((jd = gui_harray(id)))
466 gui_start(jd, _("Continue"), GUI_SML, DEMO_CONTINUE, 0);
468 gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
471 gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
474 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
475 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
481 if ((jd = gui_hstack(id)))
484 gui_demo_status(jd, curr_demo_replay());
489 gui_layout(id, 0, 0);
492 audio_music_fade_out(demo_paused ? 0.2f : 2.0f);
497 static void demo_end_paint(int id, float st)
506 static int demo_end_keybd(int c, int d)
510 if (demo_paused && config_tst_d(CONFIG_KEY_PAUSE, c))
511 return demo_end_action(DEMO_CONTINUE);
516 static int demo_end_buttn(int b, int d)
520 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
521 return demo_end_action(gui_token(gui_click()));
522 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
523 return demo_end_action(demo_paused
525 : (simple_play ? DEMO_QUIT : DEMO_KEEP));
530 /*---------------------------------------------------------------------------*/
532 static int demo_del_action(int i)
534 audio_play(AUD_MENU, 1.0f);
536 demo_replay_stop(i == DEMO_DEL);
537 return goto_state(&st_demo);
540 static int demo_del_enter(void)
544 if ((id = gui_vstack(0)))
546 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
548 if ((jd = gui_harray(id)))
550 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
551 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
555 gui_layout(id, 0, 0);
557 audio_music_fade_out(2.0f);
562 static int demo_del_buttn(int b, int d)
566 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
567 return demo_del_action(gui_token(gui_click()));
568 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
569 return demo_del_action(DEMO_KEEP);
574 /*---------------------------------------------------------------------------*/
576 struct state st_demo = {
589 struct state st_demo_play = {
602 struct state st_demo_end = {
615 struct state st_demo_del = {