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.
25 #include "st_shared.h"
28 extern struct state st_save;
29 extern struct state st_clobber;
31 static char filename[MAXNAM];
33 /*---------------------------------------------------------------------------*/
35 static struct state *ok_state;
36 static struct state *cancel_state;
38 int goto_save(struct state *ok, struct state *cancel)
40 demo_unique(filename);
43 cancel_state = cancel;
45 return goto_state(&st_save);
48 /*---------------------------------------------------------------------------*/
55 static int save_action(int i)
57 size_t l = strlen(filename);
59 audio_play(AUD_MENU, 1.0f);
64 if (strlen(filename) == 0)
66 if (demo_exists(filename))
67 return goto_state(&st_clobber);
70 demo_play_save(filename);
71 return goto_state(ok_state);
75 return goto_state(cancel_state);
85 gui_set_label(file_id, filename);
92 filename[l + 0] = (char) i;
94 gui_set_label(file_id, filename);
102 static int save_enter(void)
106 if ((id = gui_vstack(0)))
108 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
112 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
118 if ((jd = gui_harray(id)))
120 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
121 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
124 gui_layout(id, 0, 0);
127 SDL_EnableUNICODE(1);
132 static void save_leave(int id)
134 SDL_EnableUNICODE(0);
138 static int save_keybd(int c, int d)
140 if (d && (c & 0xFF80) == 0)
144 if (c == '\b' || c == 0x7F)
145 return save_action(GUI_BS);
147 return save_action(c);
152 static int save_buttn(int b, int d)
156 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
158 int c = gui_token(gui_click());
160 /* Ugh. This is such a hack. */
162 return save_action(isupper(c) ? gui_keyboard_char(c) : c);
164 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
165 return save_action(SAVE_CANCEL);
170 /*---------------------------------------------------------------------------*/
172 static int clobber_action(int i)
174 audio_play(AUD_MENU, 1.0f);
178 demo_play_save(filename);
179 return goto_state(ok_state);
181 return goto_state(&st_save);
184 static int clobber_enter(void)
188 if ((id = gui_vstack(0)))
190 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
192 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
194 if ((jd = gui_harray(id)))
196 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
197 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
201 gui_layout(id, 0, 0);
207 static int clobber_buttn(int b, int d)
211 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
212 return clobber_action(gui_token(gui_click()));
213 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
214 return clobber_action(SAVE_CANCEL);
219 /*---------------------------------------------------------------------------*/
221 struct state st_save = {
234 struct state st_clobber = {