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);
55 return goto_state(&st_done);
59 if (level_exit(NULL, 1))
60 return goto_state(&st_level);
62 return goto_state(&st_done);
72 gui_set_label(file_id, filename);
79 filename[l + 0] = gui_keyboard_char((char) i);
81 gui_set_label(file_id, filename);
87 static int save_enter(void)
91 demo_unique(filename);
93 if ((id = gui_vstack(0)))
96 if ((jd = gui_hstack(id)))
99 gui_count(jd, curr_level(), GUI_LRG, GUI_NE | GUI_SE);
100 gui_label(jd, _("Level "), GUI_LRG, GUI_NW | GUI_SW, 0, 0);
106 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
109 if ((jd = gui_harray(id)))
111 gui_start(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_keybd(int c, int d)
161 if (d && c == SDLK_ESCAPE)
162 goto_state(&st_over);
166 static int save_buttn(int b, int d)
170 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
171 return save_click(0, 1);
172 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
173 return goto_state(&st_over);
178 /*---------------------------------------------------------------------------*/
180 static int clobber_action(int i)
182 audio_play(AUD_MENU, 1.0f);
186 if (level_exit(filename, 1))
187 return goto_state(&st_level);
189 return goto_state(&st_title);
191 return goto_state(&st_save);
194 static int clobber_enter(void)
198 if ((id = gui_vstack(0)))
200 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
202 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
204 if ((jd = gui_harray(id)))
206 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
207 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
211 gui_layout(id, 0, 0);
217 static void clobber_leave(int id)
222 static void clobber_paint(int id, float st)
228 static void clobber_timer(int id, float dt)
234 static int clobber_keybd(int c, int d)
236 return (d && c == SDLK_ESCAPE) ? clobber_action(SAVE_CANCEL) : 1;
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 = {