Correct logic of BSP back/front tests
[neverball] / ball / util.c
index 772f62f..33bafce 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <ctype.h>
 #include <string.h>
+#include <assert.h>
 
 #include "gui.h"
 #include "util.h"
@@ -264,10 +265,19 @@ static void set_best_times(const struct score *s, int hilight, int goal)
 
 static int score_type = GUI_MOST_COINS;
 
-void gui_score_board(int id, int e, int h)
+void gui_score_board(int id, unsigned int types, int e, int h)
 {
     int jd, kd, ld;
 
+    assert((types & GUI_MOST_COINS)  == GUI_MOST_COINS ||
+           (types & GUI_BEST_TIMES)  == GUI_BEST_TIMES ||
+           (types & GUI_UNLOCK_GOAL) == GUI_UNLOCK_GOAL );
+
+    /* Make sure current score type matches the spec. */
+
+    while ((types & score_type) != score_type)
+        score_type = gui_score_next(score_type);
+
     gui_filler(id);
 
     if ((jd = gui_hstack(id)))
@@ -278,12 +288,15 @@ void gui_score_board(int id, int e, int h)
         {
             gui_filler(kd);
 
-            gui_state(kd, _("Most Coins"),  GUI_SML, GUI_MOST_COINS,
-                      score_type == GUI_MOST_COINS);
-            gui_state(kd, _("Best Times"),  GUI_SML, GUI_BEST_TIMES,
-                      score_type == GUI_BEST_TIMES);
-            gui_state(kd, _("Unlock Goal"), GUI_SML, GUI_UNLOCK_GOAL,
-                      score_type == GUI_UNLOCK_GOAL);
+            if ((types & GUI_MOST_COINS) == GUI_MOST_COINS)
+                gui_state(kd, _("Most Coins"),  GUI_SML, GUI_MOST_COINS,
+                          score_type == GUI_MOST_COINS);
+            if ((types & GUI_BEST_TIMES) == GUI_BEST_TIMES)
+                gui_state(kd, _("Best Times"),  GUI_SML, GUI_BEST_TIMES,
+                          score_type == GUI_BEST_TIMES);
+            if ((types & GUI_UNLOCK_GOAL) == GUI_UNLOCK_GOAL)
+                gui_state(kd, _("Unlock Goal"), GUI_SML, GUI_UNLOCK_GOAL,
+                          score_type == GUI_UNLOCK_GOAL);
 
             if (h)
             {
@@ -500,8 +513,8 @@ int gui_navig(int id, int prev, int next)
     {
         if (next || prev)
         {
-            gui_maybe(jd, _("Next"), GUI_NEXT, next);
-            gui_maybe(jd, _("Prev"), GUI_PREV, prev);
+            gui_maybe(jd, _("Next"), GUI_NEXT, GUI_NULL, next);
+            gui_maybe(jd, _("Prev"), GUI_PREV, GUI_NULL, prev);
         }
 
         gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
@@ -509,21 +522,17 @@ int gui_navig(int id, int prev, int next)
     return jd;
 }
 
-int gui_maybe(int id, const char *label, int token, int enabled)
+int gui_maybe(int id, const char *label, int etoken, int dtoken, int enabled)
 {
     int bd;
 
     if (!enabled)
     {
-        bd = gui_state(id,
-                       label,
-                       GUI_SML,
-                       token >= 0 ? token | GUI_NULL_MASK : GUI_NULL,
-                       0);
-
+        bd = gui_state(id, label, GUI_SML, dtoken, 0);
         gui_set_color(bd, gui_gry, gui_gry);
     }
-    else bd = gui_state(id, label, GUI_SML, token, 0);
+    else
+        bd = gui_state(id, label, GUI_SML, etoken, 0);
 
     return bd;
 }