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);
65 if (level_replay(get_demo(i)->filename))
67 return goto_state(&st_demo_play);
72 static void demo_replay(int id, int i)
74 int w = config_get_d(CONFIG_WIDTH);
75 int h = config_get_d(CONFIG_HEIGHT);
80 if ((jd = gui_vstack(id)))
84 gui_image(jd, get_demo(i)->shot, w / 6, h / 6);
85 nam[MAXNAM - 1] = '\0';
86 strncpy(nam, get_demo(i)->name, MAXNAM);
87 if (nam[MAXNAM - 1] != '\0')
89 nam[MAXNAM - 2] = '.';
90 nam[MAXNAM - 1] = '.';
91 nam[MAXNAM + 0] = '.';
92 nam[MAXNAM + 1] = '\0';
94 gui_state(jd, nam, GUI_SML, i, 0);
107 static int player_id;
109 static int gui_demo_status(int id, const struct demo *d)
110 /* Create a layout for some demo info, if d is NULL, try to reserve enough
114 const char *mode, *state;
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);
127 for (i = 1; i <= MODE_SINGLE; i++)
129 k = strlen(mode_to_str(i));
133 mode = mode_to_str(i);
137 /* Get a long state */
138 state = state_to_str(0);
140 for (i = 1; i <= GAME_FALL; i++)
142 k = strlen(state_to_str(i));
146 state = state_to_str(i);
152 mode = mode_to_str(d->mode);
153 state = state_to_str(d->state);
156 if ((jd = gui_hstack(id)))
158 if ((kd = gui_vstack(jd)))
160 if ((ld = gui_harray(kd)))
162 if ((md = gui_vstack(ld)))
165 gui_label(md, (d ? d->player : noname), GUI_SML,
168 gui_count(md, (d ? d->coins : 100), GUI_SML, GUI_RGT);
170 gui_label(md, state, GUI_SML, GUI_RGT, gui_red,
173 if ((md = gui_vstack(ld)))
175 gui_label(md, _("Player"), GUI_SML, GUI_LFT, gui_wht,
177 gui_label(md, _("Coins"), GUI_SML, GUI_LFT, gui_wht,
179 gui_label(md, _("State"), GUI_SML, GUI_LFT, gui_wht,
182 if ((md = gui_vstack(ld)))
185 gui_label(md, (d ? d->name : noname), GUI_SML, GUI_RGT,
188 gui_clock(md, (d ? d->timer : 35000), GUI_SML, GUI_RGT);
189 mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
193 gui_label(kd, (d ? d->file : "M"), GUI_SML, GUI_RGT, gui_wht,
196 gui_label(kd, (d ? date_to_str(d->date) : "M"), GUI_SML,
199 if ((kd = gui_vstack(jd)))
201 gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
202 gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
203 gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
204 gui_label(kd, _("Level"), 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->state == GAME_GOAL || d->state == GAME_SPEC))
208 gui_set_color(state_id, gui_grn, gui_grn);
213 static void gui_demo_update_status(int i)
215 const struct demo *d = get_demo(i);
217 gui_set_label(name_id, d->name);
218 gui_set_label(date_id, date_to_str(d->date));
219 gui_set_label(level_id, d->file);
220 gui_set_label(player_id, d->player);
221 gui_set_label(mode_id, mode_to_str(d->mode));
223 if (d->state == GAME_GOAL || d->state == GAME_SPEC)
224 gui_set_color(state_id, gui_grn, gui_grn);
226 gui_set_color(state_id, gui_red, gui_red);
228 gui_set_label(state_id, state_to_str(d->state));
229 gui_set_count(coin_id, d->coins);
230 gui_set_clock(time_id, d->timer);
233 static int demo_enter(void)
243 gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
245 gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
246 gui_layout(id, 0, 0);
250 if ((jd = gui_hstack(id)))
253 ld = gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
255 gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
257 if ((jd = gui_varray(id)))
258 for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
259 if ((kd = gui_harray(jd)))
261 for (j = i + DEMO_LINE - 1; j >= i; j--)
268 gui_demo_status(id, NULL);
269 gui_layout(id, 0, 0);
270 gui_demo_update_status(0);
273 audio_music_fade_to(0.5f, "bgm/inter.ogg");
278 static void demo_point(int id, int x, int y, int dx, int dy)
280 int jd = shared_point_basic(id, x, y);
281 int i = gui_token(jd);
283 gui_demo_update_status(i);
286 static void demo_stick(int id, int a, int v)
288 int jd = shared_stick_basic(id, a, v);
289 int i = gui_token(jd);
291 gui_demo_update_status(i);
294 static int demo_buttn(int b, int d)
298 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
299 return demo_action(gui_token(gui_click()));
300 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
301 return demo_action(GUI_BACK);
306 /*---------------------------------------------------------------------------*/
308 static int simple_play;
310 void demo_play_goto(int simple)
312 simple_play = simple;
315 static int demo_play_enter(void)
319 if ((id = gui_vstack(0)))
321 gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
322 gui_layout(id, 0, 0);
336 static void demo_play_paint(int id, float st)
341 if (time_state() < 1.f)
345 static void demo_play_timer(int id, float dt)
356 /* Spin or skip depending on how fast the demo wants to run. */
358 while (replay_time < global_time)
359 if (demo_replay_step(&t))
365 goto_state(&st_demo_end);
370 static int demo_play_buttn(int b, int d)
374 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
375 return goto_state(&st_demo_end);
380 /*---------------------------------------------------------------------------*/
385 #define DEMO_REPLAY 3
387 static int demo_end_action(int i)
389 audio_play(AUD_MENU, 1.0f);
394 return goto_state(&st_demo_del);
397 return goto_state(&st_demo);
403 level_replay(curr_demo_replay()->filename);
404 return goto_state(&st_demo_play);
409 static int demo_end_enter(void)
413 if ((id = gui_vstack(0)))
415 kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
417 if ((jd = gui_harray(id)))
419 gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
422 gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
425 gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
426 gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
432 if ((jd = gui_hstack(id)))
435 gui_demo_status(jd, curr_demo_replay());
440 gui_layout(id, 0, 0);
442 audio_music_fade_out(2.0f);
447 static void demo_end_timer(int id, float dt)
449 float gg[3] = { 0.0f, 9.8f, 0.0f };
450 float gf[3] = { 0.0f, -9.8f, 0.0f };
451 int state = curr_demo_replay()->state;
453 if (time_state() < 2.f && state != GAME_NONE)
454 game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf, dt, NULL);
460 static int demo_end_buttn(int b, int d)
464 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
465 return demo_end_action(gui_token(gui_click()));
466 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
467 return demo_end_action(simple_play ? DEMO_QUIT : DEMO_KEEP);
472 /*---------------------------------------------------------------------------*/
474 static int demo_del_action(int i)
476 audio_play(AUD_MENU, 1.0f);
478 demo_replay_stop(i == DEMO_DEL);
479 return goto_state(&st_demo);
482 static int demo_del_enter(void)
486 if ((id = gui_vstack(0)))
488 kd = gui_label(id, _("Delete Replay?"), GUI_MED, GUI_ALL, gui_red, gui_red);
490 if ((jd = gui_harray(id)))
492 gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
493 gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
497 gui_layout(id, 0, 0);
499 audio_music_fade_out(2.0f);
504 static int demo_del_buttn(int b, int d)
508 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
509 return demo_del_action(gui_token(gui_click()));
510 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
511 return demo_del_action(DEMO_KEEP);
516 /*---------------------------------------------------------------------------*/
518 struct state st_demo = {
531 struct state st_demo_play = {
544 struct state st_demo_end = {
557 struct state st_demo_del = {