Merged branch utf8.
[neverball] / ball / st_title.c
index 3f0836b..49cb73a 100644 (file)
@@ -33,6 +33,8 @@ static float real_time = 0.0f;
 static float demo_time = 0.0f;
 static int   mode      = 0;
 
+static int play_id = 0;
+
 #define TITLE_PLAY 1
 #define TITLE_HELP 2
 #define TITLE_DEMO 3
@@ -41,7 +43,13 @@ static int   mode      = 0;
 
 static int title_action(int i)
 {
+    static const char keyphrase[] = "CHEAT";
+    static char queue[sizeof (keyphrase)] = "";
+
+    size_t queue_len = strlen(queue);
+
     char player[MAXNAM];
+
     audio_play(AUD_MENU, 1.0f);
 
     switch (i)
@@ -49,15 +57,54 @@ static int title_action(int i)
     case TITLE_PLAY:
         config_get_s(CONFIG_PLAYER, player, MAXNAM);
 
-        if (player[0] == '\0')
+        if (strlen(player) == 0)
             return goto_name(&st_set, &st_title);
         else
             return goto_state(&st_set);
 
-    case TITLE_HELP: return goto_state(&st_help);
-    case TITLE_DEMO: return goto_state(&st_demo);
-    case TITLE_CONF: return goto_state(&st_conf);
-    case TITLE_EXIT: return 0;
+        break;
+
+    case TITLE_HELP: return goto_state(&st_help); break;
+    case TITLE_DEMO: return goto_state(&st_demo); break;
+    case TITLE_CONF: return goto_state(&st_conf); break;
+    case TITLE_EXIT: return 0;                    break;
+
+    default:
+
+        /* Let the queue fill up. */
+
+        if (queue_len < sizeof (queue) - 1)
+        {
+            queue[queue_len]     = (char) i;
+            queue[queue_len + 1] = '\0';
+        }
+
+        /* Advance the queue before adding the new element. */
+
+        else
+        {
+            int k;
+
+            for (k = 1; k < queue_len; k++)
+                queue[k - 1] = queue[k];
+
+            queue[queue_len - 1] = (char) i;
+        }
+
+        if (strcmp(queue, keyphrase) == 0)
+        {
+            config_set_cheat();
+            gui_set_label(play_id, sgettext("menu^Cheat"));
+            gui_pulse(play_id, 1.2f);
+        }
+        else if (config_cheat())
+        {
+            config_clr_cheat();
+            gui_set_label(play_id, sgettext("menu^Play"));
+            gui_pulse(play_id, 1.2f);
+        }
+
+        break;
     }
     return 1;
 }
@@ -73,6 +120,7 @@ static int title_enter(void)
     if ((id = gui_vstack(0)))
     {
         gui_label(id, "Neverball", GUI_LRG, GUI_ALL, 0, 0);
+
         gui_space(id);
 
         if ((jd = gui_harray(id)))
@@ -81,7 +129,13 @@ static int title_enter(void)
 
             if ((kd = gui_varray(jd)))
             {
-                gui_start(kd, sgettext("menu^Play"),    GUI_MED, TITLE_PLAY, 1);
+                if (config_cheat())
+                    play_id = gui_start(kd, sgettext("menu^Cheat"),
+                                        GUI_MED, TITLE_PLAY, 1);
+                else
+                    play_id = gui_start(kd, sgettext("menu^Play"),
+                                        GUI_MED, TITLE_PLAY, 1);
+
                 gui_state(kd, sgettext("menu^Replay"),  GUI_MED, TITLE_DEMO, 0);
                 gui_state(kd, sgettext("menu^Help"),    GUI_MED, TITLE_HELP, 0);
                 gui_state(kd, sgettext("menu^Options"), GUI_MED, TITLE_CONF, 0);
@@ -105,11 +159,14 @@ static int title_enter(void)
     demo_time = 0.0f;
     mode = 0;
 
+    SDL_EnableUNICODE(1);
+
     return id;
 }
 
 static void title_leave(int id)
 {
+    SDL_EnableUNICODE(0);
     demo_replay_stop(0);
     gui_delete(id);
 }
@@ -187,8 +244,8 @@ static void title_timer(int id, float dt)
 
 static int title_keybd(int c, int d)
 {
-    if (d && c == SDLK_c && ALLOW_CHEAT)
-        config_tgl_d(CONFIG_CHEAT);
+    if (d && (c & 0xFF80) == 0 && c > ' ')
+        return title_action(c);
     return 1;
 }