Formatting stuff. Convert tabs to spaces, shorten lines to 80, etc. First
[neverball] / ball / util.c
index 88a39c7..d2e83f6 100644 (file)
@@ -17,7 +17,6 @@
 
 #include "gui.h"
 #include "util.h"
-#include "levels.h"
 #include "config.h"
 
 /*---------------------------------------------------------------------------*/
@@ -32,19 +31,17 @@ static int is_special_name(const char * n)
 static int coin_c[4];
 static int coin_n[4];
 static int coin_t[4];
-static int coin_row;
-static int coin_lastrow;
+static int coin_extrarow;
 
 /* Build a Most Coins top three list with default values. */
 
-void gui_most_coins(int id, int n, int n2)
+void gui_most_coins(int id, int e)
 {
     const char *s = "1234567";
 
     int j, jd, kd, ld, md;
 
-    coin_row = n;
-    coin_lastrow = n2;
+    coin_extrarow = e;
 
     if ((jd = gui_hstack(id)))
     {
@@ -58,12 +55,12 @@ void gui_most_coins(int id, int n, int n2)
             {
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 1; j++)
+                    for (j = 0; j < NSCORE - 1; j++)
                         coin_c[j] = gui_count(md, 1000, GUI_SML, 0);
 
                     coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
                    
-                   if (n2)
+                   if (e)
                    {
                        gui_space(md);
                        coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
@@ -72,10 +69,10 @@ void gui_most_coins(int id, int n, int n2)
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n; j++)
+                    for (j = 0; j < NSCORE ; j++)
                        coin_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
                    
-                   if (n2)
+                   if (e)
                    {
                        gui_space(md);
                        coin_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
@@ -84,12 +81,12 @@ void gui_most_coins(int id, int n, int n2)
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 1; j++)
+                    for (j = 0; j < NSCORE - 1; j++)
                         coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
 
                     coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_SW);
 
-                   if (n2)
+                   if (e)
                    {
                        gui_space(md);
                        coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_LFT);
@@ -103,49 +100,60 @@ void gui_most_coins(int id, int n, int n2)
 
 /* Set the Most Coins top three list values for level i. */
 
-void set_most_coins(int level, int hilight)
+void set_most_coins(const struct score *s, int hilight)
 {
     int j, spe;
     const char * name;
 
-    for (j = 0; j < coin_row + coin_lastrow; j++)
+    if (s == NULL)
     {
-       name = level_coin_n(level, j);
-       spe = is_special_name(name);
-
-       if (spe)
-          gui_set_color(coin_n[j], 0, 0);
-       else if (j != hilight)
-          gui_set_color(coin_n[j], gui_yel, gui_wht);
-       else if (j>= coin_row)
-          gui_set_color(coin_n[j], gui_red, gui_red);
-       else
-          gui_set_color(coin_n[j], gui_grn, gui_grn);
-       
-        gui_set_count(coin_c[j], level_coin_c(level, j));
-        gui_set_label(coin_n[j], spe ? _(name) : name);
-        gui_set_clock(coin_t[j], level_coin_t(level, j));
+       for (j = 0; j < NSCORE + coin_extrarow ; j++)
+       {
+           gui_set_count(coin_c[j], -1);
+           gui_set_label(coin_n[j], "");
+           gui_set_clock(coin_t[j], -1);
+       }
+    }
+    else
+    {
+       for (j = 0; j < NSCORE + coin_extrarow; j++)
+       {
+           name = s->player[j];
+           spe = is_special_name(name);
+
+           if (spe)
+               gui_set_color(coin_n[j], 0, 0);
+           else if (j != hilight)
+               gui_set_color(coin_n[j], gui_yel, gui_wht);
+           else if (j>= NSCORE)
+               gui_set_color(coin_n[j], gui_red, gui_red);
+           else
+               gui_set_color(coin_n[j], gui_grn, gui_grn);
+
+           gui_set_count(coin_c[j], s->coins[j]);
+           gui_set_label(coin_n[j], spe ? _(name) : name);
+           gui_set_clock(coin_t[j], s->timer[j]);
+       }
     }
 }
 
 /*---------------------------------------------------------------------------*/
 
+static int time_l;
 static int time_c[4];
 static int time_n[4];
-static int time_t[4];
-static int time_row;
-static int time_lastrow;
+static int time_t2[4]; /* Renamed to time_t2 to avoid multiple declaration (in sys/types.h) */
+static int time_extrarow;
 
 /* Build a Best Times top three list with default values. */
 
-void gui_best_times(int id, int n, int n2)
+void gui_best_times(int id, int e)
 {
     const char *s = "1234567";
 
     int j, jd, kd, ld, md;
 
-    time_row = n;
-    time_lastrow = n2;
+    time_extrarow = e;
 
     if ((jd = gui_hstack(id)))
     {
@@ -153,30 +161,30 @@ void gui_best_times(int id, int n, int n2)
 
         if ((kd = gui_vstack(jd)))
         {
-            gui_label(kd, _("Best Times"), GUI_SML, GUI_TOP, 0, 0);
+            time_l = 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 - 1; j++)
-                        time_t[j] = gui_clock(md, 359999, GUI_SML, 0);
+                    for (j = 0; j < NSCORE - 1; j++)
+                        time_t2[j] = gui_clock(md, 359999, GUI_SML, 0);
 
-                    time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
+                    time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
                    
-                   if (n2)
+                   if (e)
                    {
                         gui_space(md);
-                       time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
+                       time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
                    }
                 }
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n; j++)
+                    for (j = 0; j < NSCORE; j++)
                         time_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
 
-                   if (n2)
+                   if (e)
                    {
                        gui_space(md);
                         time_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
@@ -185,12 +193,12 @@ void gui_best_times(int id, int n, int n2)
 
                 if ((md = gui_vstack(ld)))
                 {
-                    for (j = 0; j < n - 1; j++)
+                    for (j = 0; j < NSCORE - 1; j++)
                         time_c[j] = gui_count(md, 1000, GUI_SML, 0);
 
                     time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
                    
-                   if (n2)
+                   if (e)
                    {
                         gui_space(md);
                        time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
@@ -204,28 +212,45 @@ void gui_best_times(int id, int n, int n2)
 
 /* Set the Best Times top three list values for level i. */
 
-void set_best_times(int level, int hilight)
+void set_best_times(const struct score *s, int hilight, int goal)
 {
     int j, spe;
     const char * name;
 
-    for (j = 0; j < time_row + time_lastrow; j++)
+    if (goal)
+       gui_set_label(time_l, _("Unlock Goal"));
+    else
+       gui_set_label(time_l, _("Best Times"));
+
+    if (s == NULL)
     {
-       name = level_time_n(level, j);
-       spe = is_special_name(name);
-       
-       if (spe)
-          gui_set_color(time_n[j], 0, 0);
-       else if (j != hilight)
-          gui_set_color(time_n[j], gui_yel, gui_wht);
-       else if (j>= time_row)
-          gui_set_color(time_n[j], gui_red, gui_red);
-       else
-          gui_set_color(time_n[j], gui_grn, gui_grn);
-       
-        gui_set_clock(time_t[j], level_time_t(level, j));
-        gui_set_label(time_n[j], spe ? _(name) : name);
-        gui_set_count(time_c[j], level_time_c(level, j));
+       for (j = 0; j < NSCORE + time_extrarow ; j++)
+       {
+           gui_set_clock(time_t2[j], -1);
+           gui_set_label(time_n[j], "");
+           gui_set_count(time_c[j], -1);
+       }
+    }
+    else
+    {
+       for (j = 0; j < NSCORE + time_extrarow ; j++)
+       {
+           name = s->player[j];
+           spe = is_special_name(name);
+
+           if (spe)
+               gui_set_color(time_n[j], 0, 0);
+           else if (j != hilight)
+               gui_set_color(time_n[j], gui_yel, gui_wht);
+           else if (j>= NSCORE)
+               gui_set_color(time_n[j], gui_red, gui_red);
+           else
+               gui_set_color(time_n[j], gui_grn, gui_grn);
+
+           gui_set_clock(time_t2[j], s->timer[j]);
+           gui_set_label(time_n[j], spe ? _(name) : name);
+           gui_set_count(time_c[j], s->coins[j]);
+       }
     }
 }
 
@@ -306,3 +331,34 @@ void gui_keyboard(int id)
 }
 
 /*---------------------------------------------------------------------------*/
+
+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);
+    else
+    {
+       bd = gui_state(id, label, GUI_SML, GUI_NULL, 0);
+       gui_set_color(bd, gui_gry, gui_gry);
+    }
+    return bd;
+}
+
+/*---------------------------------------------------------------------------*/