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)
225 gui_set_label(time_l, goal ? _("Unlock Goal") : _("Best Times"));
229 for (j = 0; j < NSCORE + time_extrarow ; j++)
231 gui_set_clock(time_t2[j], -1);
232 gui_set_label(time_n[j], "");
233 gui_set_count(time_c[j], -1);
238 for (j = 0; j < NSCORE + time_extrarow; j++)
241 spe = is_special_name(name);
244 gui_set_color(time_n[j], 0, 0);
245 else if (j != hilight)
246 gui_set_color(time_n[j], gui_yel, gui_wht);
248 gui_set_color(time_n[j], gui_red, gui_red);
250 gui_set_color(time_n[j], gui_grn, gui_grn);
252 gui_set_clock(time_t2[j], s->timer[j]);
253 gui_set_label(time_n[j], spe ? _(name) : name);
254 gui_set_count(time_c[j], s->coins[j]);
259 /*---------------------------------------------------------------------------*/
262 static int keyd[127];
264 static void gui_fill(int id, char *line)
272 keyd[(int) *l] = gui_state(id, l, GUI_SML, *l, 0);
276 void gui_keyboard(int id)
282 if ((jd = gui_hstack(id)))
286 if ((kd = gui_vstack(jd)))
288 if ((ld = gui_harray(kd)))
291 gui_fill(ld, "9876543210");
294 if ((ld = gui_harray(kd)))
297 gui_fill(ld, "JIHGFEDCBA");
300 if ((ld = gui_harray(kd)))
303 gui_fill(ld, "TSRQPONMLK");
306 if ((ld = gui_harray(kd)))
309 gui_fill(ld, "!.-_ZYXWVU");
312 if ((ld = gui_harray(kd)))
315 gui_fill(ld, "jihgfedcba");
318 if ((ld = gui_harray(kd)))
321 gui_fill(ld, "tsrqponmlk");
324 if ((ld = gui_hstack(kd)))
327 gui_state(ld, _("del"), GUI_SML, GUI_BS, 0);
328 gui_fill(ld, "zyxwvu");
336 /*---------------------------------------------------------------------------*/
338 int gui_back_prev_next(int id, int prev, int next)
342 if ((jd = gui_hstack(id)))
346 gui_maybe(jd, _("Next"), GUI_NEXT, next);
347 gui_maybe(jd, _("Prev"), GUI_PREV, prev);
350 gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
355 int gui_maybe(int id, const char *label, int token, int enabled)
359 bd = gui_state(id, label, GUI_SML, token, 0);
362 bd = gui_state(id, label, GUI_SML, token >= 0 ? token | GUI_NULL_MASK : GUI_NULL, 0);
363 gui_set_color(bd, gui_gry, gui_gry);
368 /*---------------------------------------------------------------------------*/