2 * Copyright (C) 2003 Robert Kooima - 2006 Jean Privat
3 * Part of the Neverball Project http://icculus.org/neverball/
5 * NEVERBALL is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 2 of the License,
8 * or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
24 #include "st_shared.h"
28 /*---------------------------------------------------------------------------*/
30 extern struct state st_name;
32 static struct state * ok_state, * cancel_state;
33 static char player[MAXNAM];
35 void name_default(void)
37 char * login = getenv("LOGNAME");
38 if (login == NULL || login[0] == '\0')
41 strncpy(player, login, MAXNAM);
42 player[MAXNAM-1] = '\0';
43 player[0] = toupper(player[0]);
46 int goto_name(struct state * ok, struct state * cancel)
48 config_get_s(CONFIG_PLAYER, player, MAXNAM);
49 if (player[0] == '\0')
53 cancel_state = cancel;
54 return goto_state(&st_name);
63 static int name_action(int i)
67 audio_play(AUD_MENU, 1.0f);
76 config_set_s(CONFIG_PLAYER, player);
77 return goto_state(ok_state);
81 return goto_state(cancel_state);
87 gui_set_label(name_id, player);
94 player[l + 0] = (char) i;
96 gui_set_label(name_id, player);
102 static int name_enter(void)
106 if ((id = gui_vstack(0)))
108 gui_label(id, _("Player Name"), GUI_MED, GUI_ALL, 0, 0);
113 name_id = gui_label(id, player, GUI_MED, GUI_ALL, gui_yel, gui_yel);
118 if ((jd = gui_harray(id)))
120 gui_state(jd, _("Cancel"), GUI_SML, NAME_CANCEL, 0);
121 gui_start(jd, _("OK"), GUI_SML, NAME_OK, 0);
124 gui_layout(id, 0, 0);
127 SDL_EnableUNICODE(1);
132 static void name_leave(int id)
134 SDL_EnableUNICODE(0);
138 static int name_keybd(int c, int d)
141 if ((c & 0xFF80) == 0)
144 if (c == '\b' || c == 0x7F)
145 return name_action(GUI_BS);
147 return name_action(c);
152 static int name_buttn(int b, int d)
156 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
157 return name_action(gui_token(gui_click()));
158 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
159 name_action(NAME_BACK);
164 /*---------------------------------------------------------------------------*/
166 struct state st_name = {