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 "game_common.h"
28 #include "st_shared.h"
31 extern struct state st_save;
32 extern struct state st_clobber;
34 static char filename[MAXSTR];
36 /*---------------------------------------------------------------------------*/
38 static struct state *ok_state;
39 static struct state *cancel_state;
41 int goto_save(struct state *ok, struct state *cancel)
43 char fmt[MAXSTR] = "";
46 config_get_s(CONFIG_REPLAY_NAME, fmt, sizeof (fmt) - 1);
47 name = demo_format_name(fmt, set_id(curr_set()), level_name(curr_level()));
49 strncpy(filename, name, sizeof (filename) - 1);
52 cancel_state = cancel;
54 return goto_state(&st_save);
57 /*---------------------------------------------------------------------------*/
62 #define SAVE_CANCEL -2
64 static int save_action(int i)
68 audio_play(AUD_MENU, 1.0f);
73 n = text_to_locale(filename);
79 return goto_state(&st_clobber);
83 return goto_state(ok_state);
87 return goto_state(cancel_state);
94 if (text_del_char(filename))
95 gui_set_label(file_id, filename);
99 if (text_add_char(i, filename, sizeof (filename) - 1,
100 sizeof (filename) - 1))
101 gui_set_label(file_id, filename);
108 static int save_enter(void)
112 if ((id = gui_vstack(0)))
114 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
117 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
123 if ((jd = gui_harray(id)))
125 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
127 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
130 gui_layout(id, 0, 0);
133 SDL_EnableUNICODE(1);
138 static void save_leave(int id)
140 SDL_EnableUNICODE(0);
144 static int save_keybd(int c, int d)
150 if (c == '\b' || c == 0x7F)
151 return save_action(GUI_BS);
153 return save_action(c);
158 static int save_buttn(int b, int d)
162 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
164 int c = gui_token(gui_click());
166 if (c >= 0 && !GUI_ISMSK(c))
167 return save_action(gui_keyboard_char(c));
169 return save_action(c);
171 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
172 return save_action(SAVE_CANCEL);
177 /*---------------------------------------------------------------------------*/
179 static int clobber_action(int i)
181 audio_play(AUD_MENU, 1.0f);
185 demo_rename(text_to_locale(filename));
186 return goto_state(ok_state);
188 return goto_state(&st_save);
191 static int clobber_enter(void)
195 if ((id = gui_vstack(0)))
197 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
199 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
201 if ((jd = gui_harray(id)))
203 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
204 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
208 gui_layout(id, 0, 0);
214 static int clobber_buttn(int b, int d)
218 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
219 return clobber_action(gui_token(gui_click()));
220 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
221 return clobber_action(SAVE_CANCEL);
226 /*---------------------------------------------------------------------------*/
228 struct state st_save = {
242 struct state st_clobber = {