2 * Copyright (C) 2003 Robert Kooima - 2006 Jean Privat
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.
25 #include "st_shared.h"
27 /*---------------------------------------------------------------------------*/
29 static char player[MAXNAM];
31 /*---------------------------------------------------------------------------*/
33 static struct state *ok_state, *cancel_state;
35 int goto_name(struct state *ok, struct state *cancel)
37 config_get_s(CONFIG_PLAYER, player, MAXNAM);
40 cancel_state = cancel;
42 return goto_state(&st_name);
45 /*---------------------------------------------------------------------------*/
52 static int name_action(int i)
54 size_t l = strlen(player);
56 audio_play(AUD_MENU, 1.0f);
64 config_set_s(CONFIG_PLAYER, player);
66 return goto_state(ok_state);
69 return goto_state(cancel_state);
79 gui_set_label(name_id, player);
86 player[l + 0] = (char) i;
89 gui_set_label(name_id, player);
97 static int name_enter(void)
101 if ((id = gui_vstack(0)))
103 gui_label(id, _("Player Name"), GUI_MED, GUI_ALL, 0, 0);
106 name_id = gui_label(id, strlen(player) == 0 ? " " : player,
107 GUI_MED, GUI_ALL, gui_yel, gui_yel);
112 if ((jd = gui_harray(id)))
114 enter_id = gui_start(jd, _("OK"), GUI_SML, NAME_OK, 0);
115 gui_state(jd, _("Cancel"), GUI_SML, NAME_CANCEL, 0);
118 gui_layout(id, 0, 0);
121 SDL_EnableUNICODE(1);
126 static void name_leave(int id)
128 SDL_EnableUNICODE(0);
132 static int name_keybd(int c, int d)
138 if (c == '\b' || c == 0x7F)
139 return name_action(GUI_BS);
141 return name_action(c);
146 static int name_buttn(int b, int d)
150 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
152 int c = gui_token(gui_click());
154 /* Ugh. This is such a hack. */
156 return name_action(isupper(c) ? gui_keyboard_char(c) : c);
158 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
159 name_action(NAME_CANCEL);
164 /*---------------------------------------------------------------------------*/
166 struct state st_name = {