Those sets haven't been merged.
[neverball] / ball / util.c
index 39ed8f0..d439438 100644 (file)
  */
 
 #include <ctype.h>
+#include <string.h>
 
 #include "gui.h"
 #include "util.h"
-#include "level.h"
+#include "config.h"
 
 /*---------------------------------------------------------------------------*/
 
-static int coin_c[4];
-static int coin_n[4];
-static int coin_t[4];
+static int is_special_name(const char *n)
+{
+    return (strcmp(n, N_("Hard"))   == 0 ||
+            strcmp(n, N_("Medium")) == 0 ||
+            strcmp(n, N_("Easy"))   == 0);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static int coin_coin[4];
+static int coin_name[4];
+static int coin_time[4];
+
+static int coin_extra_row;
 
 /* Build a Most Coins top three list with default values. */
 
-void gui_most_coins(int id, int n, int i)
+void gui_most_coins(int id, int e)
 {
     const char *s = "1234567";
 
-    const float *c0 = gui_yel;
-    const float *c1 = gui_grn;
-    const float *c2 = gui_wht;
-    const float *c3 = gui_red;
-
     int j, jd, kd, ld, md;
 
+    coin_extra_row = e;
+
     if ((jd = gui_hstack(id)))
     {
         gui_filler(jd);
 
         if ((kd = gui_vstack(jd)))
         {
-            gui_label(kd, "Most Coins", GUI_SML, GUI_TOP, 0, 0);
+            gui_label(kd, _("Most Coins"), GUI_SML, GUI_TOP, 0, 0);
 
             if ((ld = gui_hstack(kd)))
             {
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 2; j++)
-                        coin_c[j] = gui_count(md, 1000, GUI_SML, 0);
+                    for (j = 0; j < NSCORE - 1; j++)
+                        coin_coin[j] = gui_count(md, 1000, GUI_SML, 0);
+
+                    coin_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
 
-                    coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
-                    gui_space(md);
-                    coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
+                    if (e)
+                    {
+                        gui_space(md);
+                        coin_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
+                    }
                 }
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n; j++)
-                        if      (i == j && i < n - 1)
-                            coin_n[j] = gui_label(md, s, GUI_SML, 0, c1, c1);
-                        else if (i == j)
-                        {
-                            if (j == n - 1) gui_space(md);
-                            coin_n[j] = gui_label(md, s, GUI_SML, 0, c3, c3);
-                        }
-                        else
-                        {
-                            if (j == n - 1) gui_space(md);
-                            coin_n[j] = gui_label(md, s, GUI_SML, 0, c0, c2);
-                        }
+                    for (j = 0; j < NSCORE ; j++)
+                        coin_name[j] = gui_label(md, s, GUI_SML, 0,
+                                                 gui_yel, gui_wht);
+
+                    if (e)
+                    {
+                        gui_space(md);
+                        coin_name[j++] = gui_label(md, s, GUI_SML, 0,
+                                                   gui_yel, gui_wht);
+                    }
                 }
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 2; j++)
-                        coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
+                    for (j = 0; j < NSCORE - 1; j++)
+                        coin_time[j] = gui_clock(md, 359999, GUI_SML, 0);
+
+                    coin_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW);
 
-                    coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_SW);
-                    gui_space(md);
-                    coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_LFT);
+                    if (e)
+                    {
+                        gui_space(md);
+                        coin_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_LFT);
+                    }
                 }
             }
         }
@@ -91,82 +105,113 @@ void gui_most_coins(int id, int n, int i)
 
 /* Set the Most Coins top three list values for level i. */
 
-void set_most_coins(int level, int n)
+void set_most_coins(const struct score *s, int hilight)
 {
-    int j;
+    int j, spe;
+    const char *name;
 
-    for (j = 0; j < n; j++)
+    if (s == NULL)
+    {
+        for (j = 0; j < NSCORE + coin_extra_row ; j++)
+        {
+            gui_set_count(coin_coin[j], -1);
+            gui_set_label(coin_name[j], "");
+            gui_set_clock(coin_time[j], -1);
+        }
+    }
+    else
     {
-        gui_set_count(coin_c[j], level_coin_c(level, j));
-        gui_set_label(coin_n[j], level_coin_n(level, j));
-        gui_set_clock(coin_t[j], level_coin_t(level, j));
+        for (j = 0; j < NSCORE + coin_extra_row; j++)
+        {
+            name = s->player[j];
+            spe = is_special_name(name);
+
+            if (spe)
+                gui_set_color(coin_name[j], 0, 0);
+            else if (j != hilight)
+                gui_set_color(coin_name[j], gui_yel, gui_wht);
+            else if (j>= NSCORE)
+                gui_set_color(coin_name[j], gui_red, gui_red);
+            else
+                gui_set_color(coin_name[j], gui_grn, gui_grn);
+
+            gui_set_count(coin_coin[j], s->coins[j]);
+            gui_set_label(coin_name[j], spe ? _(name) : name);
+            gui_set_clock(coin_time[j], s->timer[j]);
+        }
     }
 }
 
 /*---------------------------------------------------------------------------*/
 
-static int time_c[4];
-static int time_n[4];
-static int time_t[4];
+static int time_label;
+
+static int time_coin[4];
+static int time_name[4];
+static int time_time[4];
+
+static int time_extra_row;
 
 /* Build a Best Times top three list with default values. */
 
-void gui_best_times(int id, int n, int i)
+void gui_best_times(int id, int e)
 {
     const char *s = "1234567";
 
-    const float *c0 = gui_yel;
-    const float *c1 = gui_grn;
-    const float *c2 = gui_wht;
-    const float *c3 = gui_red;
-
     int j, jd, kd, ld, md;
 
+    time_extra_row = e;
+
     if ((jd = gui_hstack(id)))
     {
         gui_filler(jd);
 
         if ((kd = gui_vstack(jd)))
         {
-            gui_label(kd, "Best Times", GUI_SML, GUI_TOP, 0, 0);
+            time_label = gui_label(kd, "XXX", GUI_SML, GUI_TOP, 0, 0);
 
             if ((ld = gui_hstack(kd)))
             {
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 2; j++)
-                        time_t[j] = gui_clock(md, 359999, GUI_SML, 0);
+                    for (j = 0; j < NSCORE - 1; j++)
+                        time_time[j] = gui_clock(md, 359999, GUI_SML, 0);
 
-                    time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
-                    gui_space(md);
-                    time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
+                    time_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
+
+                    if (e)
+                    {
+                        gui_space(md);
+                        time_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
+                    }
                 }
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n; j++)
-                        if      (i == j && i < n - 1)
-                            time_n[j] = gui_label(md, s, GUI_SML, 0, c1, c1);
-                        else if (i == j)
-                        {
-                            if (j == n - 1) gui_space(md);
-                            time_n[j] = gui_label(md, s, GUI_SML, 0, c3, c3);
-                        }
-                        else
-                        {
-                            if (j == n - 1) gui_space(md);
-                            time_n[j] = gui_label(md, s, GUI_SML, 0, c0, c2);
-                        }
+                    for (j = 0; j < NSCORE; j++)
+                        time_name[j] = gui_label(md, s, GUI_SML, 0,
+                                                 gui_yel, gui_wht);
+
+                    if (e)
+                    {
+                        gui_space(md);
+                        time_name[j++] = gui_label(md, s, GUI_SML, 0,
+                                                   gui_yel, gui_wht);
+                    }
                 }
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 2; j++)
-                        time_c[j] = gui_count(md, 1000, GUI_SML, 0);
+                    for (j = 0; j < NSCORE - 1; j++)
+                        time_coin[j] = gui_count(md, 1000, GUI_SML, 0);
+
+                    time_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
 
-                    time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
-                    gui_space(md);
-                    time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
+                    if (e)
+                    {
+                        gui_space(md);
+                        time_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
+                    }
                 }
             }
         }
@@ -176,22 +221,49 @@ void gui_best_times(int id, int n, int i)
 
 /* Set the Best Times top three list values for level i. */
 
-void set_best_times(int level, int n)
+void set_best_times(const struct score *s, int hilight, int goal)
 {
-    int j;
+    int j, spe;
+    const char *name;
+
+    gui_set_label(time_label, goal ? _("Unlock Goal") : _("Best Times"));
 
-    for (j = 0; j < n; j++)
+    if (s == NULL)
+    {
+        for (j = 0; j < NSCORE + time_extra_row ; j++)
+        {
+            gui_set_clock(time_time[j], -1);
+            gui_set_label(time_name[j], "");
+            gui_set_count(time_coin[j], -1);
+        }
+    }
+    else
     {
-        gui_set_clock(time_t[j], level_time_t(level, j));
-        gui_set_label(time_n[j], level_time_n(level, j));
-        gui_set_count(time_c[j], level_time_c(level, j));
+        for (j = 0; j < NSCORE + time_extra_row; j++)
+        {
+            name = s->player[j];
+            spe = is_special_name(name);
+
+            if (spe)
+                gui_set_color(time_name[j], 0, 0);
+            else if (j != hilight)
+                gui_set_color(time_name[j], gui_yel, gui_wht);
+            else if (j>= NSCORE)
+                gui_set_color(time_name[j], gui_red, gui_red);
+            else
+                gui_set_color(time_name[j], gui_grn, gui_grn);
+
+            gui_set_clock(time_time[j], s->timer[j]);
+            gui_set_label(time_name[j], spe ? _(name) : name);
+            gui_set_count(time_coin[j], s->coins[j]);
+        }
     }
 }
 
 /*---------------------------------------------------------------------------*/
 
 static int lock = 1;
-static int keyd[127]; 
+static int keyd[127];
 
 void gui_keyboard(int id)
 {
@@ -261,7 +333,7 @@ void gui_keyboard(int id)
                 keyd['W'] = gui_state(ld, "W", GUI_SML, 'W', 0);
                 keyd['V'] = gui_state(ld, "V", GUI_SML, 'V', 0);
                 keyd['U'] = gui_state(ld, "U", GUI_SML, 'U', 0);
-                gui_state(ld, "caps", GUI_SML, GUI_CL, 0);
+                gui_state(ld, _("caps"), GUI_SML, GUI_CL, 0);
                 gui_filler(ld);
             }
         }
@@ -307,3 +379,47 @@ char gui_keyboard_char(char c)
 }
 
 /*---------------------------------------------------------------------------*/
+
+/*
+ * XXX Watch  out when  using these  functions. Be  sure to  check for
+ * GUI_NULL in addition to GUI_NEXT and GUI_PREV when using the latter
+ * two as labels for a switch with a default label.
+ */
+
+int gui_back_prev_next(int id, int prev, int next)
+{
+    int jd;
+
+    if ((jd = gui_hstack(id)))
+    {
+        if (next || prev)
+        {
+            gui_maybe(jd, _("Next"), GUI_NEXT, next);
+            gui_maybe(jd, _("Prev"), GUI_PREV, prev);
+        }
+
+        gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
+    }
+    return jd;
+}
+
+int gui_maybe(int id, const char *label, int token, int enabled)
+{
+    int bd;
+
+    if (!enabled)
+    {
+        bd = gui_state(id,
+                       label,
+                       GUI_SML,
+                       token >= 0 ? token | GUI_NULL_MASK : GUI_NULL,
+                       0);
+
+        gui_set_color(bd, gui_gry, gui_gry);
+    }
+    else bd = gui_state(id, label, GUI_SML, token, 0);
+
+    return bd;
+}
+
+/*---------------------------------------------------------------------------*/