Merge branch 'gles'
[neverball] / ball / st_name.c
index bbe05e5..44051c8 100644 (file)
 #include <string.h>
 #include <ctype.h>
 
+#include "common.h"
 #include "gui.h"
 #include "util.h"
 #include "audio.h"
 #include "config.h"
-#include "game.h"
+#include "video.h"
 #include "text.h"
-#include "back.h"
+#include "geom.h"
+
+#include "game_common.h"
+#include "game_server.h"
+#include "game_client.h"
 
 #include "st_name.h"
 #include "st_shared.h"
@@ -37,7 +42,7 @@ static unsigned int draw_back;
 
 int goto_name(struct state *ok, struct state *cancel, unsigned int back)
 {
-    config_get_s(CONFIG_PLAYER, player, MAXNAM);
+    SAFECPY(player, config_get_s(CONFIG_PLAYER));
 
     ok_state     = ok;
     cancel_state = cancel;
@@ -48,8 +53,8 @@ int goto_name(struct state *ok, struct state *cancel, unsigned int back)
 
 /*---------------------------------------------------------------------------*/
 
-#define NAME_OK     1
-#define NAME_CANCEL 2
+#define NAME_OK     -1
+#define NAME_CANCEL -2
 
 static int name_id;
 
@@ -80,7 +85,7 @@ static int name_action(int i)
         break;
 
     default:
-        if (text_add_char(i, player, MAXNAM, 17))
+        if (text_add_char(i, player, sizeof (player)))
             gui_set_label(name_id, player);
     }
     return 1;
@@ -88,23 +93,16 @@ static int name_action(int i)
 
 static int enter_id;
 
-static int name_enter(void)
+static int name_gui(void)
 {
     int id, jd;
 
-    if (draw_back)
-    {
-        game_free();
-        back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
-    }
-
     if ((id = gui_vstack(0)))
     {
         gui_label(id, _("Player Name"), GUI_MED, GUI_ALL, 0, 0);
         gui_space(id);
 
-        name_id = gui_label(id, strlen(player) == 0 ? " " : player,
-                            GUI_MED, GUI_ALL, gui_yel, gui_yel);
+        name_id = gui_label(id, " ", GUI_MED, GUI_ALL, gui_yel, gui_yel);
 
         gui_space(id);
         gui_keyboard(id);
@@ -118,14 +116,28 @@ static int name_enter(void)
         }
 
         gui_layout(id, 0, 0);
+
+        gui_set_trunc(name_id, TRUNC_HEAD);
+        gui_set_label(name_id, player);
+    }
+
+    return id;
+}
+
+static int name_enter(struct state *st, struct state *prev)
+{
+    if (draw_back)
+    {
+        game_client_free(NULL);
+        back_init("back/gui.png");
     }
 
     SDL_EnableUNICODE(1);
 
-    return id;
+    return name_gui();
 }
 
-static void name_leave(int id)
+static void name_leave(struct state *st, struct state *next, int id)
 {
     if (draw_back)
         back_free();
@@ -138,14 +150,14 @@ static void name_paint(int id, float t)
 {
     if (draw_back)
     {
-        config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
+        video_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
         {
-            back_draw(0);
+            back_draw_easy();
         }
-        config_pop_matrix();
+        video_pop_matrix();
     }
     else
-        game_draw(0, t);
+        game_client_draw(0, t);
 
     gui_paint(id);
 }
@@ -158,7 +170,7 @@ static int name_keybd(int c, int d)
 
         if (c == '\b' || c == 0x7F)
             return name_action(GUI_BS);
-        if (c > ' ')
+        if (c >= ' ')
             return name_action(c);
     }
     return 1;
@@ -172,9 +184,10 @@ static int name_buttn(int b, int d)
         {
             int c = gui_token(gui_click());
 
-            /* Ugh.  This is such a hack. */
-
-            return name_action(isupper(c) ? gui_keyboard_char(c) : c);
+            if (c >= 0 && !GUI_ISMSK(c))
+                return name_action(gui_keyboard_char(c));
+            else
+                return name_action(c);
         }
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
             name_action(NAME_CANCEL);
@@ -194,7 +207,6 @@ struct state st_name = {
     shared_angle,
     shared_click,
     name_keybd,
-    name_buttn,
-    1, 0
+    name_buttn
 };