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 "game_common.h"
30 #include "st_shared.h"
32 static char filename[MAXSTR];
34 /*---------------------------------------------------------------------------*/
36 static struct state *ok_state;
37 static struct state *cancel_state;
39 int goto_save(struct state *ok, struct state *cancel)
43 name = demo_format_name(config_get_s(CONFIG_REPLAY_NAME),
45 level_name(curr_level()));
47 SAFECPY(filename, name);
50 cancel_state = cancel;
52 return goto_state(&st_save);
55 /*---------------------------------------------------------------------------*/
60 #define SAVE_CANCEL -2
62 static int save_action(int i)
66 audio_play(AUD_MENU, 1.0f);
77 return goto_state(&st_clobber);
81 return goto_state(ok_state);
85 return goto_state(cancel_state);
92 if (text_del_char(filename))
93 gui_set_label(file_id, filename);
97 if (!path_is_sep(i) && text_add_char(i, filename, sizeof (filename)))
98 gui_set_label(file_id, filename);
105 static int save_gui(void)
109 if ((id = gui_vstack(0)))
111 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
114 file_id = gui_label(id, " ", GUI_MED, GUI_ALL, gui_yel, gui_yel);
120 if ((jd = gui_harray(id)))
122 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
124 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
127 gui_layout(id, 0, 0);
129 gui_set_trunc(file_id, TRUNC_HEAD);
130 gui_set_label(file_id, filename);
136 static int save_enter(struct state *st, struct state *prev)
138 SDL_EnableUNICODE(1);
143 static void save_leave(struct state *st, struct state *next, int id)
145 SDL_EnableUNICODE(0);
149 static int save_keybd(int c, int d)
155 if (c == '\b' || c == 0x7F)
156 return save_action(GUI_BS);
158 return save_action(c);
163 static int save_buttn(int b, int d)
167 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
169 int c = gui_token(gui_click());
171 if (c >= 0 && !GUI_ISMSK(c))
172 return save_action(gui_keyboard_char(c));
174 return save_action(c);
176 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
177 return save_action(SAVE_CANCEL);
182 /*---------------------------------------------------------------------------*/
184 static int clobber_action(int i)
186 audio_play(AUD_MENU, 1.0f);
190 demo_rename(filename);
191 return goto_state(ok_state);
193 return goto_state(&st_save);
196 static int clobber_gui(void)
201 if ((id = gui_vstack(0)))
203 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
205 file_id = gui_label(id, "MMMMMMMM", GUI_MED, GUI_ALL, gui_yel, gui_yel);
207 if ((jd = gui_harray(id)))
209 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
210 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
214 gui_layout(id, 0, 0);
216 gui_set_trunc(file_id, TRUNC_TAIL);
217 gui_set_label(file_id, filename);
223 static int clobber_enter(struct state *st, struct state *prev)
225 return clobber_gui();
228 static int clobber_buttn(int b, int d)
232 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
233 return clobber_action(gui_token(gui_click()));
234 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
235 return clobber_action(SAVE_CANCEL);
240 /*---------------------------------------------------------------------------*/
242 struct state st_save = {
255 struct state st_clobber = {