-/*
+/*
* Copyright (C) 2003 Robert Kooima
*
* NEVERBALL is free software; you can redistribute it and/or modify
* General Public License for more details.
*/
+#include <string.h>
+
#include "gui.h"
#include "hud.h"
#include "set.h"
#include "st_demo.h"
#include "st_title.h"
-extern struct state st_demo_play;
-extern struct state st_demo_end;
-extern struct state st_demo_del;
-
/*---------------------------------------------------------------------------*/
#define DEMO_LINE 4
break;
default:
- if (level_replay(demo_filename(i)))
- return goto_demo_play(0);
+ if (level_replay(demo_get(i)->filename))
+ demo_play_goto(0);
+ return goto_state(&st_demo_play);
}
return 1;
}
int h = config_get_d(CONFIG_HEIGHT);
int jd;
+ char nam[MAXNAM + 3];
+
if ((jd = gui_vstack(id)))
{
gui_space(jd);
+ gui_image(jd, demo_get(i)->shot, w / 6, h / 6);
- gui_image(jd, demo_shot(i), w / 6, h / 6);
- gui_state(jd, demo_name(i), GUI_SML, i, 0);
+ nam[MAXNAM - 1] = '\0';
+ strncpy(nam, demo_get(i)->name, MAXNAM);
+ if (nam[MAXNAM - 1] != '\0')
+ {
+ nam[MAXNAM - 2] = '.';
+ nam[MAXNAM - 1] = '.';
+ nam[MAXNAM + 0] = '.';
+ nam[MAXNAM + 1] = '\0';
+ }
+ gui_state(jd, nam, GUI_SML, i, 0);
gui_active(jd, i, 0);
}
static int coin_id;
static int date_id;
static int mode_id;
+static int state_id;
static int player_id;
-static void demo_status(int i)
+/* Create a layout for some demo info. If d is NULL, try to reserve enough
+ * space. */
+
+static int gui_demo_status(int id, const struct demo *d)
{
- char ds[MAXSTR];
- demo_str_date(i, ds, MAXSTR);
- gui_set_label(name_id, demo_name(i));
- gui_set_label(date_id, ds);
- gui_set_label(player_id, demo_player(i));
- gui_set_label(mode_id, mode_to_str(demo_mode(i)));
- gui_set_count(coin_id, demo_coins(i));
- gui_set_clock(time_id, demo_clock(i));
+ char noname[MAXNAM];
+ const char *mode, *state;
+ int i, j, k;
+ int jd, kd, ld, md;
+
+ if (d == NULL)
+ {
+ /* Build a long name */
+ memset(noname, 'M', MAXNAM - 1);
+ noname[MAXNAM - 1] = '\0';
+
+ /* Get a long mode */
+ mode = mode_to_str(0);
+ j = strlen(mode);
+ for (i = 1; i <= MODE_SINGLE; i++)
+ {
+ k = strlen(mode_to_str(i));
+ if (k > j)
+ {
+ j = k;
+ mode = mode_to_str(i);
+ }
+ }
+
+ /* Get a long state */
+ state = state_to_str(0);
+ j = strlen(state);
+ for (i = 1; i <= GAME_FALL; i++)
+ {
+ k = strlen(state_to_str(i));
+ if (k > j)
+ {
+ j = k;
+ state = state_to_str(i);
+ }
+ }
+ }
+ else
+ {
+ mode = mode_to_str(d->mode);
+ state = state_to_str(d->state);
+ }
+
+ if ((jd = gui_hstack(id)))
+ {
+ if ((kd = gui_vstack(jd)))
+ {
+ if ((ld = gui_harray(kd)))
+ {
+ if ((md = gui_vstack(ld)))
+ {
+ player_id = gui_label(md, (d ? d->player : noname),
+ GUI_SML, GUI_RGT, 0, 0);
+ coin_id = gui_count(md, (d ? d->coins : 100),
+ GUI_SML, GUI_RGT);
+ state_id = gui_label(md, state, GUI_SML, GUI_RGT,
+ gui_red, gui_red);
+ }
+ if ((md = gui_vstack(ld)))
+ {
+ gui_label(md, _("Player"), GUI_SML, GUI_LFT,
+ gui_wht, gui_wht);
+ gui_label(md, _("Coins"), GUI_SML, GUI_LFT,
+ gui_wht, gui_wht);
+ gui_label(md, _("State"), GUI_SML, GUI_LFT,
+ gui_wht, gui_wht);
+ }
+ if ((md = gui_vstack(ld)))
+ {
+ name_id = gui_label(md, (d ? d->name : noname),
+ GUI_SML, GUI_RGT, 0, 0);
+ time_id = gui_clock(md, (d ? d->timer : 35000),
+ GUI_SML, GUI_RGT);
+ mode_id = gui_label(md, mode, GUI_SML, GUI_RGT, 0, 0);
+ }
+ }
+ date_id = gui_label(kd, (d ? date_to_str(d->date) : "M"),
+ GUI_SML, GUI_RGT, 0, 0);
+ }
+ if ((kd = gui_vstack(jd)))
+ {
+ gui_label(kd, _("Replay"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
+ gui_label(kd, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
+ gui_label(kd, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
+ gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
+ }
+ if (d && (d->state == GAME_GOAL || d->state == GAME_SPEC))
+ gui_set_color(state_id, gui_grn, gui_grn);
+ }
+ return jd;
+}
+
+static void gui_demo_update_status(int i)
+{
+ const struct demo *d = demo_get(i);
+
+ gui_set_label(name_id, d->name);
+ gui_set_label(date_id, date_to_str(d->date));
+ gui_set_label(player_id, d->player);
+ gui_set_label(mode_id, mode_to_str(d->mode));
+
+ if (d->state == GAME_GOAL || d->state == GAME_SPEC)
+ gui_set_color(state_id, gui_grn, gui_grn);
+ else
+ gui_set_color(state_id, gui_red, gui_red);
+
+ gui_set_label(state_id, state_to_str(d->state));
+ gui_set_count(coin_id, d->coins);
+ gui_set_clock(time_id, d->timer);
}
static int demo_enter(void)
{
int i, j;
- int id, jd, kd, ld;
-
- total = demo_scan();
+ int id, jd, kd;
id = gui_vstack(0);
- if (total == 0)
- {
- gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
- gui_filler(id);
- gui_multi(id, _("You can save replays of your games.\\"
- "Currently, there are no replays saved."),
- GUI_SML, GUI_ALL, gui_wht, gui_wht);
- gui_filler(id);
- gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
- gui_layout(id, 0, 0);
- }
- else
+
+ if ((total = demo_scan()))
{
- if ((jd = gui_hstack(id)))
+ if ((jd = gui_hstack(id)))
{
- ld = gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
+ gui_label(jd, _("Select Replay"), GUI_SML, GUI_ALL, 0,0);
gui_filler(jd);
- gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
+ gui_back_prev_next(jd, first > 0, first + DEMO_STEP < total);
}
+
if ((jd = gui_varray(id)))
for (i = first; i < first + DEMO_STEP ; i += DEMO_LINE)
if ((kd = gui_harray(jd)))
else
gui_space(kd);
}
- gui_filler(id);
- if ((jd = gui_hstack(id)))
- {
- if((kd = gui_vstack(jd)))
- {
- if ((ld = gui_harray(kd)))
- {
- coin_id = gui_count(ld, 100, GUI_SML, GUI_RGT);
- gui_label(ld, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- time_id = gui_clock(ld, 35000, GUI_SML, GUI_RGT);
- gui_label(ld, _("Time"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- name_id = gui_label(ld, demo_name(0), GUI_SML, GUI_RGT, 0, 0);
- }
- if ((ld = gui_harray(kd)))
- {
- mode_id = gui_label(ld, "..............", GUI_SML, GUI_RGT, 0, 0);
- gui_label(ld, _("Mode"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- player_id = gui_label(ld, demo_player(0), GUI_SML, GUI_RGT, 0, 0);
- }
- date_id = gui_label(kd, "X", GUI_SML, GUI_RGT, 0, 0);
- }
- if((kd = gui_vstack(jd)))
- {
- gui_label(kd, _("Name"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- gui_label(kd, _("Player"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- gui_label(kd, _("Date"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- }
- }
- gui_layout(id, 0, 0);
- demo_status(0);
+ gui_filler(id);
+ gui_demo_status(id, NULL);
+ gui_layout(id, 0, 0);
+ gui_demo_update_status(0);
+ }
+ else
+ {
+ gui_label(id, _("No Replays"), GUI_MED, GUI_ALL, 0,0);
+ gui_filler(id);
+ gui_start(id, _("Back"), GUI_SML, GUI_BACK, 0);
+ gui_layout(id, 0, 0);
}
audio_music_fade_to(0.5f, "bgm/inter.ogg");
{
int jd = shared_point_basic(id, x, y);
int i = gui_token(jd);
- if (jd && i>=0)
- demo_status(i);
+
+ if (jd && i >= 0)
+ gui_demo_update_status(i);
}
static void demo_stick(int id, int a, int v)
{
int jd = shared_stick_basic(id, a, v);
int i = gui_token(jd);
- if (jd && i>=0)
- demo_status(i);
+
+ if (jd && i >= 0)
+ gui_demo_update_status(i);
}
static int demo_buttn(int b, int d)
/*---------------------------------------------------------------------------*/
-static int simple_play;
-int goto_demo_play(int simple)
+static int simple_play; /* play demo from command line */
+
+void demo_play_goto(int simple)
{
simple_play = simple;
- return goto_state(&st_demo_play);
}
static int demo_play_enter(void)
{
int id;
- if ((id = gui_label(0, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn)))
+ if ((id = gui_vstack(0)))
{
+ gui_label(id, _("Replay"), GUI_LRG, GUI_ALL, gui_blu, gui_grn);
gui_layout(id, 0, 0);
gui_pulse(id, 1.2f);
}
{
replay_time += t;
}
- else
+ else
{
goto_state(&st_demo_end);
break;
/*---------------------------------------------------------------------------*/
-#define DEMO_KEEP 0
-#define DEMO_DEL 1
-#define DEMO_QUIT 2
+#define DEMO_KEEP 0
+#define DEMO_DEL 1
+#define DEMO_QUIT 2
+#define DEMO_REPLAY 3
static int demo_end_action(int i)
{
switch (i)
{
- case DEMO_DEL:
- return goto_state(&st_demo_del);
+ case DEMO_DEL:
+ return goto_state(&st_demo_del);
case DEMO_KEEP:
demo_replay_stop(0);
return goto_state(&st_demo);
case DEMO_QUIT:
- demo_replay_stop(0);
- return 0;
+ demo_replay_stop(0);
+ return 0;
+ case DEMO_REPLAY:
+ demo_replay_stop(0);
+ level_replay(curr_demo_replay()->filename);
+ return goto_state(&st_demo_play);
}
return 1;
}
if ((id = gui_vstack(0)))
{
- kd = gui_label(id, _("Replay Ends"), GUI_MED, GUI_ALL, gui_gry, gui_red);
+ kd = gui_label(id, _("Replay Ends"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
if ((jd = gui_harray(id)))
{
- if (simple_play)
- gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
- else
- {
- gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
- gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
- }
+ gui_start(jd, _("Replay Again"), GUI_SML, DEMO_REPLAY, 0);
+
+ if (simple_play)
+ gui_start(jd, _("OK"), GUI_SML, DEMO_QUIT, 1);
+ else
+ {
+ gui_start(jd, _("Keep"), GUI_SML, DEMO_KEEP, 1);
+ gui_state(jd, _("Delete"), GUI_SML, DEMO_DEL, 0);
+ }
+ }
+
+ gui_filler(id);
+
+ if ((jd = gui_hstack(id)))
+ {
+ gui_filler(jd);
+ gui_demo_status(jd, curr_demo_replay());
+ gui_filler(jd);
}
gui_pulse(kd, 1.2f);
static void demo_end_timer(int id, float dt)
{
- float g[3] = { 0.0f, -9.8f, 0.0f };
+ float t;
+ float gg[3] = { 0.0f, 9.8f, 0.0f };
+ float gf[3] = { 0.0f, -9.8f, 0.0f };
+ int state = curr_demo_replay()->state;
if (time_state() < 2.f)
- game_step(g, dt, 0);
-
+ {
+ /* Continue demo in background for 2 seconds */
+ if (replay_time < global_time)
+ {
+ /* The demo is finished, let the ball go */
+ if (state != GAME_NONE)
+ game_step((state == GAME_GOAL || state == GAME_SPEC) ? gg : gf,
+ dt, NULL);
+ }
+ else
+ {
+ /* The demo is not finished, play it */
+ global_time += dt;
+
+ while (replay_time < global_time)
+ if (demo_replay_step(&t))
+ replay_time += t;
+ else
+ break;
+ }
+ }
+
gui_timer(id, dt);
audio_timer(dt);
}
if ((jd = gui_harray(id)))
{
- gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
gui_start(jd, _("No"), GUI_SML, DEMO_KEEP, 1);
+ gui_state(jd, _("Yes"), GUI_SML, DEMO_DEL, 0);
}
gui_pulse(kd, 1.2f);