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.
31 extern struct state st_save;
32 extern struct state st_clobber;
34 /*---------------------------------------------------------------------------*/
36 static struct state * next_state;
38 int goto_save(struct state * nextstate)
40 next_state = nextstate;
41 return goto_state(&st_save);
44 /*---------------------------------------------------------------------------*/
50 static char filename[MAXNAM];
52 static int save_action(int i)
54 size_t l = strlen(filename);
56 audio_play(AUD_MENU, 1.0f);
61 if (strcmp(filename, "") == 0)
63 if (demo_exists(filename))
64 return goto_state(&st_clobber);
67 demo_play_save(filename);
68 return goto_state(next_state);
72 return goto_state(next_state);
82 gui_set_label(file_id, filename);
89 filename[l + 0] = gui_keyboard_char((char) i);
91 gui_set_label(file_id, filename);
97 static int save_enter(void)
101 demo_unique(filename);
103 if ((id = gui_vstack(0)))
106 if ((jd = gui_hstack(id)))
109 if ((kd = gui_vstack(jd)))
111 if ((ld = gui_hstack(kd)))
113 gui_count(ld, curr_level(), GUI_LRG, GUI_NE);
114 gui_label(ld, _("Level "), GUI_LRG, GUI_NW, 0, 0);
116 gui_label(kd, _(set_name(set_curr())), GUI_SML, GUI_BOT, gui_wht, gui_wht);
123 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
126 if ((jd = gui_harray(id)))
128 gui_start(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
129 gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
133 gui_layout(id, 0, 0);
139 static void save_leave(int id)
144 static void save_paint(int id, float st)
150 static void save_timer(int id, float dt)
156 static void save_point(int id, int x, int y, int dx, int dy)
158 gui_pulse(gui_point(id, x, y), 1.2f);
161 static void save_stick(int id, int a, int v)
163 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
164 gui_pulse(gui_stick(id, v, 0), 1.2f);
165 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
166 gui_pulse(gui_stick(id, 0, v), 1.2f);
169 static int save_click(int b, int d)
171 if (b <= 0 && d == 1)
172 return save_action(gui_token(gui_click()));
176 static int save_buttn(int b, int d)
180 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
181 return save_click(0, 1);
182 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
183 return save_action(SAVE_CANCEL);
188 /*---------------------------------------------------------------------------*/
190 static int clobber_action(int i)
192 audio_play(AUD_MENU, 1.0f);
196 demo_play_save(filename);
197 return goto_state(next_state);
199 return goto_state(&st_save);
202 static int clobber_enter(void)
206 if ((id = gui_vstack(0)))
208 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
210 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
212 if ((jd = gui_harray(id)))
214 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
215 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
219 gui_layout(id, 0, 0);
225 static void clobber_leave(int id)
230 static void clobber_paint(int id, float st)
236 static void clobber_timer(int id, float dt)
242 static void clobber_point(int id, int x, int y, int dx, int dy)
244 gui_pulse(gui_point(id, x, y), 1.2f);
247 static void clobber_stick(int id, int a, int v)
249 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
250 gui_pulse(gui_stick(id, v, 0), 1.2f);
251 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
252 gui_pulse(gui_stick(id, 0, v), 1.2f);
255 static int clobber_click(int b, int d)
258 return clobber_action(gui_token(gui_click()));
262 static int clobber_buttn(int b, int d)
266 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
267 return clobber_action(gui_token(gui_click()));
268 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
269 return clobber_action(SAVE_CANCEL);
274 /*---------------------------------------------------------------------------*/
276 struct state st_save = {
289 struct state st_clobber = {