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.
28 extern struct state st_save;
29 extern struct state st_clobber;
31 /*---------------------------------------------------------------------------*/
33 static struct state * next_state;
35 int goto_save(struct state * nextstate)
37 next_state = nextstate;
38 return goto_state(&st_save);
41 /*---------------------------------------------------------------------------*/
47 static char filename[MAXNAM];
49 static int save_action(int i)
51 size_t l = strlen(filename);
53 audio_play(AUD_MENU, 1.0f);
58 if (strcmp(filename, "") == 0)
60 if (demo_exists(filename))
61 return goto_state(&st_clobber);
64 demo_play_save(filename);
65 return goto_state(next_state);
69 return goto_state(next_state);
79 gui_set_label(file_id, filename);
86 filename[l + 0] = gui_keyboard_char((char) i);
88 gui_set_label(file_id, filename);
94 static int save_enter(void)
98 demo_unique(filename);
100 if ((id = gui_vstack(0)))
103 if ((jd = gui_hstack(id)))
106 if ((kd = gui_vstack(jd)))
108 if ((ld = gui_hstack(kd)))
110 gui_count(ld, curr_level(), GUI_LRG, GUI_NE);
111 gui_label(ld, _("Level "), GUI_LRG, GUI_NW, 0, 0);
113 gui_label(kd, _(set_name(set_curr())), GUI_SML, GUI_BOT, gui_wht, gui_wht);
120 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
123 if ((jd = gui_harray(id)))
125 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
126 gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
130 gui_layout(id, 0, 0);
136 static void save_leave(int id)
141 static void save_paint(int id, float st)
147 static void save_timer(int id, float dt)
153 static void save_point(int id, int x, int y, int dx, int dy)
155 gui_pulse(gui_point(id, x, y), 1.2f);
158 static void save_stick(int id, int a, int v)
160 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
161 gui_pulse(gui_stick(id, v, 0), 1.2f);
162 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
163 gui_pulse(gui_stick(id, 0, v), 1.2f);
166 static int save_click(int b, int d)
168 if (b <= 0 && d == 1)
169 return save_action(gui_token(gui_click()));
173 static int save_buttn(int b, int d)
177 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
178 return save_click(0, 1);
179 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
180 return save_action(SAVE_CANCEL);
185 /*---------------------------------------------------------------------------*/
187 static int clobber_action(int i)
189 audio_play(AUD_MENU, 1.0f);
193 demo_play_save(filename);
194 return goto_state(next_state);
196 return goto_state(&st_save);
199 static int clobber_enter(void)
203 if ((id = gui_vstack(0)))
205 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
207 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
209 if ((jd = gui_harray(id)))
211 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
212 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
216 gui_layout(id, 0, 0);
222 static void clobber_leave(int id)
227 static void clobber_paint(int id, float st)
233 static void clobber_timer(int id, float dt)
239 static void clobber_point(int id, int x, int y, int dx, int dy)
241 gui_pulse(gui_point(id, x, y), 1.2f);
244 static void clobber_stick(int id, int a, int v)
246 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
247 gui_pulse(gui_stick(id, v, 0), 1.2f);
248 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
249 gui_pulse(gui_stick(id, 0, v), 1.2f);
252 static int clobber_click(int b, int d)
255 return clobber_action(gui_token(gui_click()));
259 static int clobber_buttn(int b, int d)
263 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
264 return clobber_action(gui_token(gui_click()));
265 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
266 return clobber_action(SAVE_CANCEL);
271 /*---------------------------------------------------------------------------*/
273 struct state st_save = {
286 struct state st_clobber = {