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[MAXNAM];
35 /*---------------------------------------------------------------------------*/
37 static struct state *ok_state;
38 static struct state *cancel_state;
40 int goto_save(struct state *ok, struct state *cancel)
42 demo_unique(filename);
45 cancel_state = cancel;
47 return goto_state(&st_save);
50 /*---------------------------------------------------------------------------*/
57 static int save_action(int i)
61 audio_play(AUD_MENU, 1.0f);
66 n = text_to_locale(filename);
72 return goto_state(&st_clobber);
76 return goto_state(ok_state);
80 return goto_state(cancel_state);
87 if (text_del_char(filename))
88 gui_set_label(file_id, filename);
92 if (text_add_char(i, filename, MAXNAM, 17))
93 gui_set_label(file_id, filename);
100 static int save_enter(void)
104 if ((id = gui_vstack(0)))
106 gui_label(id, _("Replay Name"), GUI_MED, GUI_ALL, 0, 0);
110 file_id = gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
116 if ((jd = gui_harray(id)))
118 enter_id = gui_start(jd, _("Save"), GUI_SML, SAVE_SAVE, 0);
119 gui_state(jd, _("Cancel"), GUI_SML, SAVE_CANCEL, 0);
122 gui_layout(id, 0, 0);
125 SDL_EnableUNICODE(1);
130 static void save_leave(int id)
132 SDL_EnableUNICODE(0);
136 static int save_keybd(int c, int d)
142 if (c == '\b' || c == 0x7F)
143 return save_action(GUI_BS);
145 return save_action(c);
150 static int save_buttn(int b, int d)
154 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
156 int c = gui_token(gui_click());
158 /* Ugh. This is such a hack. */
160 return save_action(isupper(c) ? gui_keyboard_char(c) : c);
162 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
163 return save_action(SAVE_CANCEL);
168 /*---------------------------------------------------------------------------*/
170 static int clobber_action(int i)
172 audio_play(AUD_MENU, 1.0f);
176 demo_rename(text_to_locale(filename));
177 return goto_state(ok_state);
179 return goto_state(&st_save);
182 static int clobber_enter(void)
186 if ((id = gui_vstack(0)))
188 kd = gui_label(id, _("Overwrite?"), GUI_MED, GUI_ALL, gui_red, gui_red);
190 gui_label(id, filename, GUI_MED, GUI_ALL, gui_yel, gui_yel);
192 if ((jd = gui_harray(id)))
194 gui_start(jd, _("No"), GUI_SML, SAVE_CANCEL, 1);
195 gui_state(jd, _("Yes"), GUI_SML, SAVE_SAVE, 0);
199 gui_layout(id, 0, 0);
205 static int clobber_buttn(int b, int d)
209 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
210 return clobber_action(gui_token(gui_click()));
211 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
212 return clobber_action(SAVE_CANCEL);
217 /*---------------------------------------------------------------------------*/
219 struct state st_save = {
233 struct state st_clobber = {