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.
27 #include "st_shared.h"
30 extern struct state st_save;
31 extern struct state st_clobber;
33 static char filename[MAXSTR];
35 /*---------------------------------------------------------------------------*/
37 static struct state *ok_state;
38 static struct state *cancel_state;
40 int goto_save(struct state *ok, struct state *cancel)
42 char fmt[MAXSTR] = "";
45 config_get_s(CONFIG_REPLAY_NAME, fmt, sizeof (fmt) - 1);
46 name = demo_format_name(fmt, set_id(curr_set()), level_name(curr_level()));
48 strncpy(filename, name, sizeof (filename) - 1);
51 cancel_state = cancel;
53 return goto_state(&st_save);
56 /*---------------------------------------------------------------------------*/
61 #define SAVE_CANCEL -2
63 static int save_action(int i)
67 audio_play(AUD_MENU, 1.0f);
72 n = text_to_locale(filename);
78 return goto_state(&st_clobber);
82 return goto_state(ok_state);
86 return goto_state(cancel_state);
93 if (text_del_char(filename))
94 gui_set_label(file_id, filename);
98 if (text_add_char(i, filename, sizeof (filename) - 1,
99 sizeof (filename) - 1))
100 gui_set_label(file_id, filename);
107 static int save_enter(void)
111 if ((id = gui_vstack(0)))
113 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
116 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
122 if ((jd = gui_harray(id)))
124 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
126 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
129 gui_layout(id, 0, 0);
132 SDL_EnableUNICODE(1);
137 static void save_leave(int id)
139 SDL_EnableUNICODE(0);
143 static int save_keybd(int c, int d)
149 if (c == '\b' || c == 0x7F)
150 return save_action(GUI_BS);
152 return save_action(c);
157 static int save_buttn(int b, int d)
161 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
163 int c = gui_token(gui_click());
165 if (c >= 0 && !GUI_ISMSK(c))
166 return save_action(gui_keyboard_char(c));
168 return save_action(c);
170 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
171 return save_action(SAVE_CANCEL);
176 /*---------------------------------------------------------------------------*/
178 static int clobber_action(int i)
180 audio_play(AUD_MENU, 1.0f);
184 demo_rename(text_to_locale(filename));
185 return goto_state(ok_state);
187 return goto_state(&st_save);
190 static int clobber_enter(void)
194 if ((id = gui_vstack(0)))
196 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
198 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
200 if ((jd = gui_harray(id)))
202 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
203 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
207 gui_layout(id, 0, 0);
213 static int clobber_buttn(int b, int d)
217 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
218 return clobber_action(gui_token(gui_click()));
219 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
220 return clobber_action(SAVE_CANCEL);
225 /*---------------------------------------------------------------------------*/
227 struct state st_save = {
241 struct state st_clobber = {