X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=ball%2Futil.c;h=4eaba6acdbc5824539dfb5ed46c37f697b85c9a7;hb=9a5b5f027b27b45b4926604f48cf00904b37ec64;hp=863157bd55a39b7088537467fe2250e33058ceb7;hpb=bd4d4ade7c9e15d8838458c3114b323488c1d3dc;p=neverball diff --git a/ball/util.c b/ball/util.c index 863157b..4eaba6a 100644 --- a/ball/util.c +++ b/ball/util.c @@ -17,34 +17,34 @@ #include "gui.h" #include "util.h" -#include "level.h" #include "config.h" /*---------------------------------------------------------------------------*/ -static int is_special_name(const char * n) +static int is_special_name(const char *n) { - return (strcmp(n, N_("Hard"))==0 || strcmp(n, N_("Medium"))==0 || strcmp(n, N_("Easy"))==0); + return (strcmp(n, N_("Hard")) == 0 || + strcmp(n, N_("Medium")) == 0 || + strcmp(n, N_("Easy")) == 0); } /*---------------------------------------------------------------------------*/ -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_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 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_extra_row = e; if ((jd = gui_hstack(id))) { @@ -58,42 +58,44 @@ void gui_most_coins(int id, int n, int n2) { if ((md = gui_vstack(ld))) { - for (j = 0; j < n - 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) - { - gui_space(md); - coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT); - } + 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); + + 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++) - coin_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht); - - if (n2) - { - gui_space(md); - coin_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht); - } + 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 - 1; 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_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW); + coin_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW); - if (n2) - { - 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); + } } } } @@ -103,49 +105,62 @@ 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; + 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_extra_row ; j++) + { + gui_set_count(coin_coin[j], -1); + gui_set_label(coin_name[j], ""); + gui_set_clock(coin_time[j], -1); + } + } + else + { + 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_row; -static int time_lastrow; +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 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_extra_row = e; if ((jd = gui_hstack(id))) { @@ -153,48 +168,50 @@ 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_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 - 1; 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_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE); - time_t[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_time[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT); + } } if ((md = gui_vstack(ld))) { - for (j = 0; j < n; j++) - time_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht); - - if (n2) - { - gui_space(md); - time_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht); - } + 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 - 1; 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_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW); - - if (n2) - { + time_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_SW); + + if (e) + { gui_space(md); - time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT); - } + time_coin[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT); + } } } } @@ -204,35 +221,49 @@ 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; + const char *name; + + gui_set_label(time_label, goal ? _("Unlock Goal") : _("Best Times")); - for (j = 0; j < time_row + time_lastrow; 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 { - 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_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) { @@ -348,3 +379,61 @@ 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 displayContrib) +{ + int jd; + int kd; + int ld; + + if ((jd = gui_vstack(id))) + { + if ((ld = gui_hstack(jd))) + { + if(displayContrib) + { + gui_maybe(ld, _("Contributions"), GUI_CONTRIB, !config_get_d(CONFIG_SHOW_CONTRIBUTIONS)); + gui_maybe(ld, _("Official Sets"), GUI_OFFIC, config_get_d(CONFIG_SHOW_CONTRIBUTIONS)); + } + } + + if ((kd = gui_hstack(jd))) + { + if (next || prev) + { + gui_maybe(kd, _("Next"), GUI_NEXT, next); + gui_maybe(kd, _("Prev"), GUI_PREV, prev); + } + + gui_start(kd, _("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; +} + +/*---------------------------------------------------------------------------*/