2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
22 /*---------------------------------------------------------------------------*/
24 static int is_special_name(const char *n)
26 return (strcmp(n, N_("Hard")) == 0 || strcmp(n, N_("Medium")) == 0
27 || strcmp(n, N_("Easy")) == 0);
30 /*---------------------------------------------------------------------------*/
35 static int coin_extrarow;
37 /* Build a Most Coins top three list with default values. */
39 void gui_most_coins(int id, int e)
41 const char *s = "1234567";
43 int j, jd, kd, ld, md;
47 if ((jd = gui_hstack(id)))
51 if ((kd = gui_vstack(jd)))
53 gui_label(kd, _("Most Coins"), GUI_SML, GUI_TOP, 0, 0);
55 if ((ld = gui_hstack(kd)))
57 if ((md = gui_vstack(ld)))
59 for (j = 0; j < NSCORE - 1; j++)
60 coin_c[j] = gui_count(md, 1000, GUI_SML, 0);
62 coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
67 coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
71 if ((md = gui_vstack(ld)))
73 for (j = 0; j < NSCORE ; j++)
74 coin_n[j] = gui_label(md, s, GUI_SML, 0,
80 coin_n[j++] = gui_label(md, s, GUI_SML, 0,
85 if ((md = gui_vstack(ld)))
87 for (j = 0; j < NSCORE - 1; j++)
88 coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
90 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW);
95 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_LFT);
104 /* Set the Most Coins top three list values for level i. */
106 void set_most_coins(const struct score *s, int hilight)
113 for (j = 0; j < NSCORE + coin_extrarow ; j++)
115 gui_set_count(coin_c[j], -1);
116 gui_set_label(coin_n[j], "");
117 gui_set_clock(coin_t[j], -1);
122 for (j = 0; j < NSCORE + coin_extrarow; j++)
125 spe = is_special_name(name);
128 gui_set_color(coin_n[j], 0, 0);
129 else if (j != hilight)
130 gui_set_color(coin_n[j], gui_yel, gui_wht);
132 gui_set_color(coin_n[j], gui_red, gui_red);
134 gui_set_color(coin_n[j], gui_grn, gui_grn);
136 gui_set_count(coin_c[j], s->coins[j]);
137 gui_set_label(coin_n[j], spe ? _(name) : name);
138 gui_set_clock(coin_t[j], s->timer[j]);
143 /*---------------------------------------------------------------------------*/
146 static int time_c[4];
147 static int time_n[4];
148 static int time_t2[4]; /* Renamed to time_t2 to avoid multiple declaration (in sys/types.h) */
149 static int time_extrarow;
151 /* Build a Best Times top three list with default values. */
153 void gui_best_times(int id, int e)
155 const char *s = "1234567";
157 int j, jd, kd, ld, md;
161 if ((jd = gui_hstack(id)))
165 if ((kd = gui_vstack(jd)))
167 time_l = gui_label(kd, "XXX", GUI_SML, GUI_TOP, 0, 0);
169 if ((ld = gui_hstack(kd)))
171 if ((md = gui_vstack(ld)))
173 for (j = 0; j < NSCORE - 1; j++)
174 time_t2[j] = gui_clock(md, 359999, GUI_SML, 0);
176 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
181 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
185 if ((md = gui_vstack(ld)))
187 for (j = 0; j < NSCORE; j++)
188 time_n[j] = gui_label(md, s, GUI_SML, 0,
194 time_n[j++] = gui_label(md, s, GUI_SML, 0,
199 if ((md = gui_vstack(ld)))
201 for (j = 0; j < NSCORE - 1; j++)
202 time_c[j] = gui_count(md, 1000, GUI_SML, 0);
204 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
209 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
218 /* Set the Best Times top three list values for level i. */
220 void set_best_times(const struct score *s, int hilight, int goal)
226 gui_set_label(time_l, _("Unlock Goal"));
228 gui_set_label(time_l, _("Best Times"));
232 for (j = 0; j < NSCORE + time_extrarow ; j++)
234 gui_set_clock(time_t2[j], -1);
235 gui_set_label(time_n[j], "");
236 gui_set_count(time_c[j], -1);
241 for (j = 0; j < NSCORE + time_extrarow; j++)
244 spe = is_special_name(name);
247 gui_set_color(time_n[j], 0, 0);
248 else if (j != hilight)
249 gui_set_color(time_n[j], gui_yel, gui_wht);
251 gui_set_color(time_n[j], gui_red, gui_red);
253 gui_set_color(time_n[j], gui_grn, gui_grn);
255 gui_set_clock(time_t2[j], s->timer[j]);
256 gui_set_label(time_n[j], spe ? _(name) : name);
257 gui_set_count(time_c[j], s->coins[j]);
262 /*---------------------------------------------------------------------------*/
265 static int keyd[127];
267 static void gui_fill(int id, char *line)
275 keyd[(int)*l] = gui_state(id, l, GUI_SML, *l, 0);
279 void gui_keyboard(int id)
285 if ((jd = gui_hstack(id)))
289 if ((kd = gui_vstack(jd)))
291 if ((ld = gui_harray(kd)))
294 gui_fill(ld, "9876543210");
297 if ((ld = gui_harray(kd)))
300 gui_fill(ld, "JIHGFEDCBA");
303 if ((ld = gui_harray(kd)))
306 gui_fill(ld, "TSRQPONMLK");
309 if ((ld = gui_harray(kd)))
312 gui_fill(ld, "!.-_ZYXWVU");
315 if ((ld = gui_harray(kd)))
318 gui_fill(ld, "jihgfedcba");
321 if ((ld = gui_harray(kd)))
324 gui_fill(ld, "tsrqponmlk");
327 if ((ld = gui_hstack(kd)))
330 gui_state(ld, _("del"), GUI_SML, GUI_BS, 0);
331 gui_fill(ld, "zyxwvu");
339 /*---------------------------------------------------------------------------*/
341 int gui_back_prev_next(int id, int prev, int next)
345 if ((jd = gui_hstack(id)))
349 gui_maybe(jd, _("Next"), GUI_NEXT, next);
350 gui_maybe(jd, _("Prev"), GUI_PREV, prev);
353 gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
358 int gui_maybe(int id, const char *label, int token, int enabled)
362 bd = gui_state(id, label, GUI_SML, token, 0);
365 bd = gui_state(id, label, GUI_SML, GUI_NULL, 0);
366 gui_set_color(bd, gui_gry, gui_gry);
371 /*---------------------------------------------------------------------------*/