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.
23 #include "st_shared.h"
27 extern struct state st_save;
28 extern struct state st_clobber;
29 static char filename[MAXNAM];
31 /*---------------------------------------------------------------------------*/
33 static struct state * ok_state;
34 static struct state * cancel_state;
36 int goto_save(struct state * ok, struct state * cancel)
38 demo_unique(filename);
40 cancel_state = cancel;
41 return goto_state(&st_save);
44 /*---------------------------------------------------------------------------*/
51 static int save_action(int i)
53 size_t l = strlen(filename);
55 audio_play(AUD_MENU, 1.0f);
60 if (strcmp(filename, "") == 0)
62 if (demo_exists(filename))
63 return goto_state(&st_clobber);
66 demo_play_save(filename);
67 return goto_state(ok_state);
71 return goto_state(cancel_state);
77 gui_set_label(file_id, filename);
84 filename[l + 0] = (char) i;
86 gui_set_label(file_id, filename);
92 static int save_enter(void)
96 if ((id = gui_vstack(0)))
98 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
103 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
108 if ((jd = gui_harray(id)))
110 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
111 gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
114 gui_layout(id, 0, 0);
117 SDL_EnableUNICODE(1);
122 static void save_leave(int id)
124 SDL_EnableUNICODE(0);
128 static int save_keybd(int c, int d)
131 if ((c & 0xFF80) == 0)
135 return save_action(GUI_BS);
137 return save_action(c);
142 static int save_buttn(int b, int d)
146 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
147 return save_action(gui_token(gui_click()));
148 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
149 return save_action(SAVE_CANCEL);
154 /*---------------------------------------------------------------------------*/
156 static int clobber_action(int i)
158 audio_play(AUD_MENU, 1.0f);
162 demo_play_save(filename);
163 return goto_state(ok_state);
165 return goto_state(&st_save);
168 static int clobber_enter(void)
172 if ((id = gui_vstack(0)))
174 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
176 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
178 if ((jd = gui_harray(id)))
180 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
181 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
185 gui_layout(id, 0, 0);
191 static int clobber_buttn(int b, int d)
195 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
196 return clobber_action(gui_token(gui_click()));
197 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
198 return clobber_action(SAVE_CANCEL);
203 /*---------------------------------------------------------------------------*/
205 struct state st_save = {
218 struct state st_clobber = {