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 #include "st_shared.h"
29 extern struct state st_save;
30 extern struct state st_clobber;
32 static char filename[MAXNAM];
34 /*---------------------------------------------------------------------------*/
36 static struct state *ok_state;
37 static struct state *cancel_state;
39 int goto_save(struct state *ok, struct state *cancel)
41 demo_unique(filename);
44 cancel_state = cancel;
46 return goto_state(&st_save);
49 /*---------------------------------------------------------------------------*/
56 static int save_action(int i)
58 size_t l = strlen(filename);
60 audio_play(AUD_MENU, 1.0f);
65 if (strlen(filename) == 0)
68 if (demo_exists(filename))
69 return goto_state(&st_clobber);
72 demo_rename(filename);
73 return goto_state(ok_state);
77 return goto_state(cancel_state);
87 gui_set_label(file_id, filename);
94 filename[l + 0] = (char) i;
96 gui_set_label(file_id, filename);
104 static int save_enter(void)
108 if ((id = gui_vstack(0)))
110 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
114 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
120 if ((jd = gui_harray(id)))
122 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
123 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
126 gui_layout(id, 0, 0);
129 SDL_EnableUNICODE(1);
134 static void save_leave(int id)
136 SDL_EnableUNICODE(0);
140 static int save_keybd(int c, int d)
142 if (d && (c & 0xFF80) == 0)
146 if (c == '\b' || c == 0x7F)
147 return save_action(GUI_BS);
149 return save_action(c);
154 static int save_buttn(int b, int d)
158 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
160 int c = gui_token(gui_click());
162 /* Ugh. This is such a hack. */
164 return save_action(isupper(c) ? gui_keyboard_char(c) : c);
166 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
167 return save_action(SAVE_CANCEL);
172 /*---------------------------------------------------------------------------*/
174 static int clobber_action(int i)
176 audio_play(AUD_MENU, 1.0f);
180 demo_rename(filename);
181 return goto_state(ok_state);
183 return goto_state(&st_save);
186 static int clobber_enter(void)
190 if ((id = gui_vstack(0)))
192 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
194 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
196 if ((jd = gui_harray(id)))
198 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
199 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
203 gui_layout(id, 0, 0);
209 static int clobber_buttn(int b, int d)
213 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
214 return clobber_action(gui_token(gui_click()));
215 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
216 return clobber_action(SAVE_CANCEL);
221 /*---------------------------------------------------------------------------*/
223 struct state st_save = {
236 struct state st_clobber = {