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);
94 static int save_enter(void)
98 if ((id = gui_vstack(0)))
100 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
105 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
110 if ((jd = gui_harray(id)))
112 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
113 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
116 gui_layout(id, 0, 0);
119 SDL_EnableUNICODE(1);
124 static void save_leave(int id)
126 SDL_EnableUNICODE(0);
130 static int save_keybd(int c, int d)
133 if ((c & 0xFF80) == 0)
138 return save_action(GUI_BS);
140 return save_action(c);
145 static int save_buttn(int b, int d)
149 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
150 return save_action(gui_token(gui_click()));
151 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
152 return save_action(SAVE_CANCEL);
157 /*---------------------------------------------------------------------------*/
159 static int clobber_action(int i)
161 audio_play(AUD_MENU, 1.0f);
165 demo_play_save(filename);
166 return goto_state(ok_state);
168 return goto_state(&st_save);
171 static int clobber_enter(void)
175 if ((id = gui_vstack(0)))
177 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
179 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
181 if ((jd = gui_harray(id)))
183 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
184 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
188 gui_layout(id, 0, 0);
194 static int clobber_buttn(int b, int d)
198 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
199 return clobber_action(gui_token(gui_click()));
200 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
201 return clobber_action(SAVE_CANCEL);
206 /*---------------------------------------------------------------------------*/
208 struct state st_save = {
221 struct state st_clobber = {