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 /*---------------------------------------------------------------------------*/
37 static char filename[MAXNAM];
39 static int save_action(int i)
41 size_t l = strlen(filename);
43 audio_play(AUD_MENU, 1.0f);
48 if (demo_exists(filename))
49 return goto_state(&st_clobber);
52 if (level_exit(filename, 1))
53 return goto_state(&st_level);
54 else if (level_dead())
55 return goto_state(&st_title);
57 return goto_state(&st_done);
61 if (level_exit(NULL, 1))
62 return goto_state(&st_level);
63 else if (level_dead())
64 return goto_state(&st_title);
66 return goto_state(&st_done);
76 gui_set_label(file_id, filename);
83 filename[l + 0] = gui_keyboard_char((char) i);
85 gui_set_label(file_id, filename);
91 static int save_enter(void)
95 demo_unique(filename);
97 if ((id = gui_vstack(0)))
100 if ((jd = gui_hstack(id)))
103 gui_count(jd, curr_level(), GUI_LRG, GUI_NE | GUI_SE);
104 gui_label(jd, _("Level "), GUI_LRG, GUI_NW | GUI_SW, 0, 0);
110 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
113 if ((jd = gui_harray(id)))
115 gui_start(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
116 gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
120 gui_layout(id, 0, 0);
126 static void save_leave(int id)
131 static void save_paint(int id, float st)
137 static void save_timer(int id, float dt)
143 static void save_point(int id, int x, int y, int dx, int dy)
145 gui_pulse(gui_point(id, x, y), 1.2f);
148 static void save_stick(int id, int a, int v)
150 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
151 gui_pulse(gui_stick(id, v, 0), 1.2f);
152 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
153 gui_pulse(gui_stick(id, 0, v), 1.2f);
156 static int save_click(int b, int d)
158 if (b <= 0 && d == 1)
159 return save_action(gui_token(gui_click()));
163 static int save_keybd(int c, int d)
165 if (d && c == SDLK_ESCAPE)
166 goto_state(&st_over);
170 static int save_buttn(int b, int d)
174 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
175 return save_click(0, 1);
176 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
177 return goto_state(&st_over);
182 /*---------------------------------------------------------------------------*/
184 static int clobber_action(int i)
186 audio_play(AUD_MENU, 1.0f);
190 if (level_exit(filename, 1))
191 return goto_state(&st_level);
193 return goto_state(&st_title);
195 return goto_state(&st_save);
198 static int clobber_enter(void)
202 if ((id = gui_vstack(0)))
204 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
206 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
208 if ((jd = gui_harray(id)))
210 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
211 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
215 gui_layout(id, 0, 0);
221 static void clobber_leave(int id)
226 static void clobber_paint(int id, float st)
232 static void clobber_timer(int id, float dt)
238 static int clobber_keybd(int c, int d)
240 return (d && c == SDLK_ESCAPE) ? clobber_action(SAVE_CANCEL) : 1;
243 static void clobber_point(int id, int x, int y, int dx, int dy)
245 gui_pulse(gui_point(id, x, y), 1.2f);
248 static void clobber_stick(int id, int a, int v)
250 if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
251 gui_pulse(gui_stick(id, v, 0), 1.2f);
252 if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
253 gui_pulse(gui_stick(id, 0, v), 1.2f);
256 static int clobber_click(int b, int d)
259 return clobber_action(gui_token(gui_click()));
263 static int clobber_buttn(int b, int d)
267 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
268 return clobber_action(gui_token(gui_click()));
269 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
270 return clobber_action(SAVE_CANCEL);
275 /*---------------------------------------------------------------------------*/
277 struct state st_save = {
290 struct state st_clobber = {