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 extern struct state st_save;
27 extern struct state st_clobber;
29 /*---------------------------------------------------------------------------*/
31 static struct state * next_state;
33 int goto_save(struct state * nextstate)
35 next_state = nextstate;
36 return goto_state(&st_save);
39 /*---------------------------------------------------------------------------*/
45 static char filename[MAXNAM];
47 static int save_action(int i)
49 size_t l = strlen(filename);
51 audio_play(AUD_MENU, 1.0f);
56 if (strcmp(filename, "") == 0)
58 if (demo_exists(filename))
59 return goto_state(&st_clobber);
62 demo_play_save(filename);
63 return goto_state(next_state);
67 return goto_state(next_state);
77 gui_set_label(file_id, filename);
84 filename[l + 0] = gui_keyboard_char((char) i);
86 gui_set_label(file_id, filename);
92 static int save_enter(void)
96 demo_unique(filename);
98 if ((id = gui_vstack(0)))
100 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
105 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
109 if ((jd = gui_harray(id)))
111 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
112 gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
116 gui_layout(id, 0, 0);
122 static void save_leave(int id)
127 static void save_paint(int id, float st)
133 static void save_timer(int id, float dt)
139 static void save_point(int id, int x, int y, int dx, int dy)
141 gui_pulse(gui_point(id, x, y), 1.2f);
144 static void save_stick(int id, int a, int v)
146 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
147 gui_pulse(gui_stick(id, v, 0), 1.2f);
148 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
149 gui_pulse(gui_stick(id, 0, v), 1.2f);
152 static int save_click(int b, int d)
154 if (b <= 0 && d == 1)
155 return save_action(gui_token(gui_click()));
159 static int save_buttn(int b, int d)
163 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
164 return save_click(0, 1);
165 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
166 return save_action(SAVE_CANCEL);
171 /*---------------------------------------------------------------------------*/
173 static int clobber_action(int i)
175 audio_play(AUD_MENU, 1.0f);
179 demo_play_save(filename);
180 return goto_state(next_state);
182 return goto_state(&st_save);
185 static int clobber_enter(void)
189 if ((id = gui_vstack(0)))
191 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
193 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
195 if ((jd = gui_harray(id)))
197 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
198 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
202 gui_layout(id, 0, 0);
208 static void clobber_leave(int id)
213 static void clobber_paint(int id, float st)
219 static void clobber_timer(int id, float dt)
225 static void clobber_point(int id, int x, int y, int dx, int dy)
227 gui_pulse(gui_point(id, x, y), 1.2f);
230 static void clobber_stick(int id, int a, int v)
232 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
233 gui_pulse(gui_stick(id, v, 0), 1.2f);
234 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
235 gui_pulse(gui_stick(id, 0, v), 1.2f);
238 static int clobber_click(int b, int d)
241 return clobber_action(gui_token(gui_click()));
245 static int clobber_buttn(int b, int d)
249 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
250 return clobber_action(gui_token(gui_click()));
251 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
252 return clobber_action(SAVE_CANCEL);
257 /*---------------------------------------------------------------------------*/
259 struct state st_save = {
272 struct state st_clobber = {