Merged branch utf8.
[neverball] / ball / st_title.c
index bfc0719..49cb73a 100644 (file)
@@ -1,4 +1,4 @@
-/*   
+/*
  * Copyright (C) 2003 Robert Kooima
  *
  * NEVERBALL is  free software; you can redistribute  it and/or modify
@@ -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,21 +43,68 @@ 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)
     {
-    case TITLE_PLAY: 
-       config_get_s(CONFIG_PLAYER, player, MAXNAM);
-       if (player[0] == '\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;
+    case TITLE_PLAY:
+        config_get_s(CONFIG_PLAYER, player, MAXNAM);
+
+        if (strlen(player) == 0)
+            return goto_name(&st_set, &st_title);
+        else
+            return goto_state(&st_set);
+
+        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;
 }
@@ -71,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)))
@@ -79,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);
@@ -95,19 +151,22 @@ static int title_enter(void)
 
     audio_music_fade_to(0.5f, "bgm/title.ogg");
 
-    /* Initialize the first level of the first set for display. */
-    level_load(config_data("map-rlk/title.sol"), &title_level);
+    /* Initialize the title level for display. */
+    level_load("map-medium/title.sol", &title_level);
     game_init(&title_level, 0, 0);
 
     real_time = 0.0f;
     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);
 }
@@ -159,7 +218,7 @@ static void title_timer(int id, float dt)
             if (demo_replay_step(&t))
                 demo_time += t;
             else
-            { 
+            {
                 demo_replay_stop(0);
                 game_fade(+1.0f);
                 real_time = 0.0f;
@@ -185,11 +244,11 @@ 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);
-    return 1; 
+    if (d && (c & 0xFF80) == 0 && c > ' ')
+        return title_action(c);
+    return 1;
 }
-       
+
 static int title_buttn(int b, int d)
 {
     if (d)