global level and set loading at the begin of the game
[neverball] / ball / st_name.c
index e8ae001..2978210 100644 (file)
@@ -1,5 +1,6 @@
-/*   
- * Copyright (C) 2003 Robert Kooima
+/*
+ * Copyright (C) 2003 Robert Kooima - 2006 Jean Privat
+ * Part of the Neverball Project http://icculus.org/neverball/
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
  * it under the  terms of the GNU General  Public License as published
 
 extern struct state st_name;
 
-static struct state * ok_state, * cancel_state;
+static struct state *ok_state, *cancel_state;
 static char player[MAXNAM];
 
 void name_default(void)
 {
-    char * login = getenv("LOGNAME");
+    char *login = getenv("LOGNAME");
+
     if (login == NULL || login[0] == '\0')
-       login =  _("Player");
-    
+        login = _("Player");
+
     strncpy(player, login, MAXNAM);
     player[MAXNAM-1] = '\0';
     player[0] = toupper(player[0]);
 }
 
-int goto_name(struct state * ok, struct state * cancel)
+int goto_name(struct state *ok, struct state *cancel)
 {
     config_get_s(CONFIG_PLAYER, player, MAXNAM);
     if (player[0] == '\0')
-       name_default();
-    
+        name_default();
+
     ok_state     = ok;
     cancel_state = cancel;
     return goto_state(&st_name);
@@ -70,15 +72,15 @@ static int name_action(int i)
     switch (i)
     {
     case NAME_OK:
-       if (l == 0)
-          return 1;
+        if (l == 0)
+           return 1;
         config_set_s(CONFIG_PLAYER, player);
-       return goto_state(ok_state);
-       
+        return goto_state(ok_state);
+
     case NAME_BACK:
     case NAME_CANCEL:
-       return goto_state(cancel_state);
-       
+        return goto_state(cancel_state);
+
     case GUI_BS:
         if (l > 0)
         {
@@ -98,31 +100,33 @@ static int name_action(int i)
     return 1;
 }
 
+static int enter_id;
+
 static int name_enter(void)
 {
     int id, jd;
 
     if ((id = gui_vstack(0)))
     {
-       gui_label(id, _("Player Name"), GUI_MED, GUI_ALL, 0, 0);
+        gui_label(id, _("Player Name"), GUI_MED, GUI_ALL, 0, 0);
 
-       gui_space(id);
         gui_space(id);
-       
-       name_id = gui_label(id, player, GUI_MED, GUI_ALL, gui_yel, gui_yel);
+        gui_space(id);
+
+        name_id = gui_label(id, player, GUI_MED, GUI_ALL, gui_yel, gui_yel);
 
         gui_space(id);
 
-       gui_keyboard(id);
-       if ((jd = gui_harray(id)))
-       {
-           gui_state(jd, _("Cancel"), GUI_SML, NAME_CANCEL, 0);
-           gui_start(jd, _("OK"),     GUI_SML, NAME_OK,     0);
-       }
+        gui_keyboard(id);
+        if ((jd = gui_harray(id)))
+        {
+            enter_id = gui_start(jd, _("OK"), GUI_SML, NAME_OK, 0);
+            gui_state(jd, _("Cancel"), GUI_SML, NAME_CANCEL, 0);
+        }
 
-       gui_layout(id, 0, 0);
+        gui_layout(id, 0, 0);
     }
-    
+
     SDL_EnableUNICODE(1);
 
     return id;
@@ -137,14 +141,15 @@ static void name_leave(int id)
 static int name_keybd(int c, int d)
 {
     if (d)
-       if ((c & 0xFF80) == 0)
-       {
-           c &= 0x7F;
-           if (c == '\b')
-               return name_action(GUI_BS);
-           else if (c > ' ')
-               return name_action(c);
-       }
+        if ((c & 0xFF80) == 0)
+        {
+            gui_focus(enter_id);
+            c &= 0x7F;
+            if (c == '\b' || c == 0x7F)
+                return name_action(GUI_BS);
+            else if (c > ' ')
+                return name_action(c);
+        }
     return 1;
 }
 
@@ -155,7 +160,7 @@ static int name_buttn(int b, int d)
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
             return name_action(gui_token(gui_click()));
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-           name_action(NAME_BACK);
+            name_action(NAME_BACK);
     }
     return 1;
 }