#include <ctype.h>
#include <string.h>
+#include <assert.h>
#include "gui.h"
#include "util.h"
/* Build a Most Coins top three list with default values. */
-void gui_most_coins(int id, int e)
+static void gui_most_coins(int id, int e)
{
const char *s = "1234567";
}
}
-/* Set the Most Coins top three list values for level i. */
+/* Set the Most Coins top three list values. */
-void set_most_coins(const struct score *s, int hilight)
+static void set_most_coins(const struct score *s, int hilight)
{
- int j, spe;
const char *name;
+ int j;
if (s == NULL)
{
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);
+ if (j == hilight)
+ {
+ if (j < NSCORE)
+ gui_set_color(coin_name[j], gui_grn, gui_grn);
+ else
+ gui_set_color(coin_name[j], gui_red, gui_red);
+ }
else
- gui_set_color(coin_name[j], gui_grn, gui_grn);
+ gui_set_color(coin_name[j], gui_yel, gui_wht);
gui_set_count(coin_coin[j], s->coins[j]);
- gui_set_label(coin_name[j], spe ? _(name) : name);
+ gui_set_label(coin_name[j], is_special_name(name) ? _(name) : name);
gui_set_clock(coin_time[j], s->timer[j]);
}
}
/* Build a Best Times top three list with default values. */
-void gui_best_times(int id, int e)
+static void gui_best_times(int id, int e)
{
const char *s = "1234567";
}
}
-/* Set the Best Times top three list values for level i. */
+/* Set the Best Times top three list values. */
-void set_best_times(const struct score *s, int hilight, int goal)
+static void set_best_times(const struct score *s, int hilight, int goal)
{
- int j, spe;
const char *name;
+ int j;
gui_set_label(time_label, goal ? _("Unlock Goal") : _("Best Times"));
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);
+ if (j == hilight)
+ {
+ if (j < NSCORE)
+ gui_set_color(time_name[j], gui_grn, gui_grn);
+ else
+ gui_set_color(time_name[j], gui_red, gui_red);
+ }
else
- gui_set_color(time_name[j], gui_grn, gui_grn);
+ gui_set_color(time_name[j], gui_yel, gui_wht);
gui_set_clock(time_time[j], s->timer[j]);
- gui_set_label(time_name[j], spe ? _(name) : name);
+ gui_set_label(time_name[j], is_special_name(name) ? _(name) : name);
gui_set_count(time_coin[j], s->coins[j]);
}
}
/*---------------------------------------------------------------------------*/
+static int score_type = GUI_MOST_COINS;
+
+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)))
+ {
+ gui_filler(jd);
+
+ if ((kd = gui_vstack(jd)))
+ {
+ gui_filler(kd);
+
+ 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)
+ {
+ gui_space(kd);
+
+ if ((ld = gui_hstack(kd)))
+ {
+ gui_filler(ld);
+ gui_state(ld, _("Change Name"), GUI_SML, GUI_NAME, 0);
+ gui_filler(ld);
+ }
+ }
+
+ gui_filler(kd);
+ }
+
+ gui_filler(jd);
+ }
+
+ gui_filler(id);
+
+ switch (score_type)
+ {
+ case GUI_MOST_COINS:
+ gui_most_coins(id, e);
+ break;
+
+ case GUI_BEST_TIMES:
+ gui_best_times(id, e);
+ break;
+
+ case GUI_UNLOCK_GOAL:
+ gui_best_times(id, e);
+ break;
+ }
+
+ gui_filler(id);
+}
+
+void set_score_board(const struct score *smc, int hmc,
+ const struct score *sbt, int hbt,
+ const struct score *sug, int hug)
+{
+ switch (score_type)
+ {
+ case GUI_MOST_COINS:
+ set_most_coins(smc, hmc);
+ break;
+
+ case GUI_BEST_TIMES:
+ set_best_times(sbt, hbt, 0);
+ break;
+
+ case GUI_UNLOCK_GOAL:
+ set_best_times(sug, hug, 1);
+ break;
+ }
+}
+
+void gui_score_set(int t)
+{
+ score_type = t;
+}
+
+int gui_score_get(void)
+{
+ return score_type;
+}
+
+int gui_score_next(int t)
+{
+ switch (t)
+ {
+ case GUI_MOST_COINS: return GUI_BEST_TIMES;
+ case GUI_BEST_TIMES: return GUI_UNLOCK_GOAL;
+ case GUI_UNLOCK_GOAL: return GUI_MOST_COINS;
+
+ default:
+ return GUI_MOST_COINS;
+ }
+}
+
+/*---------------------------------------------------------------------------*/
+
static int lock = 1;
static int keyd[127];
* two as labels for a switch with a default label.
*/
-int gui_back_prev_next(int id, int prev, int next)
+int gui_navig(int id, int prev, int next)
{
int jd;
{
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);
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;
}