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 || strcmp(n, N_("Easy"))==0);
29 /*---------------------------------------------------------------------------*/
34 static int coin_extrarow;
36 /* Build a Most Coins top three list with default values. */
38 void gui_most_coins(int id, int e)
40 const char *s = "1234567";
42 int j, jd, kd, ld, md;
46 if ((jd = gui_hstack(id)))
50 if ((kd = gui_vstack(jd)))
52 gui_label(kd, _("Most Coins"), GUI_SML, GUI_TOP, 0, 0);
54 if ((ld = gui_hstack(kd)))
56 if ((md = gui_vstack(ld)))
58 for (j = 0; j < NSCORE - 1; j++)
59 coin_c[j] = gui_count(md, 1000, GUI_SML, 0);
61 coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
66 coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
70 if ((md = gui_vstack(ld)))
72 for (j = 0; j < NSCORE ; j++)
73 coin_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
78 coin_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
82 if ((md = gui_vstack(ld)))
84 for (j = 0; j < NSCORE - 1; j++)
85 coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
87 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW);
92 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_LFT);
101 /* Set the Most Coins top three list values for level i. */
103 void set_most_coins(const struct score *s, int hilight)
110 for (j = 0; j < NSCORE + coin_extrarow ; j++)
112 gui_set_count(coin_c[j], -1);
113 gui_set_label(coin_n[j], "");
114 gui_set_clock(coin_t[j], -1);
119 for (j = 0; j < NSCORE + coin_extrarow; j++)
122 spe = is_special_name(name);
125 gui_set_color(coin_n[j], 0, 0);
126 else if (j != hilight)
127 gui_set_color(coin_n[j], gui_yel, gui_wht);
129 gui_set_color(coin_n[j], gui_red, gui_red);
131 gui_set_color(coin_n[j], gui_grn, gui_grn);
133 gui_set_count(coin_c[j], s->coins[j]);
134 gui_set_label(coin_n[j], spe ? _(name) : name);
135 gui_set_clock(coin_t[j], s->timer[j]);
140 /*---------------------------------------------------------------------------*/
143 static int time_c[4];
144 static int time_n[4];
145 static int time_t2[4]; /* Renamed to time_t2 to avoid multiple declaration (in sys/types.h) */
146 static int time_extrarow;
148 /* Build a Best Times top three list with default values. */
150 void gui_best_times(int id, int e)
152 const char *s = "1234567";
154 int j, jd, kd, ld, md;
158 if ((jd = gui_hstack(id)))
162 if ((kd = gui_vstack(jd)))
164 time_l = gui_label(kd, "XXX", GUI_SML, GUI_TOP, 0, 0);
166 if ((ld = gui_hstack(kd)))
168 if ((md = gui_vstack(ld)))
170 for (j = 0; j < NSCORE - 1; j++)
171 time_t2[j] = gui_clock(md, 359999, GUI_SML, 0);
173 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
178 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
182 if ((md = gui_vstack(ld)))
184 for (j = 0; j < NSCORE; j++)
185 time_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
190 time_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
194 if ((md = gui_vstack(ld)))
196 for (j = 0; j < NSCORE - 1; j++)
197 time_c[j] = gui_count(md, 1000, GUI_SML, 0);
199 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
204 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
213 /* Set the Best Times top three list values for level i. */
215 void set_best_times(const struct score *s, int hilight, int goal)
221 gui_set_label(time_l, _("Unlock Goal"));
223 gui_set_label(time_l, _("Best Times"));
227 for (j = 0; j < NSCORE + time_extrarow ; j++)
229 gui_set_clock(time_t2[j], -1);
230 gui_set_label(time_n[j], "");
231 gui_set_count(time_c[j], -1);
236 for (j = 0; j < NSCORE + time_extrarow ; j++)
239 spe = is_special_name(name);
242 gui_set_color(time_n[j], 0, 0);
243 else if (j != hilight)
244 gui_set_color(time_n[j], gui_yel, gui_wht);
246 gui_set_color(time_n[j], gui_red, gui_red);
248 gui_set_color(time_n[j], gui_grn, gui_grn);
250 gui_set_clock(time_t2[j], s->timer[j]);
251 gui_set_label(time_n[j], spe ? _(name) : name);
252 gui_set_count(time_c[j], s->coins[j]);
257 /*---------------------------------------------------------------------------*/
260 static int keyd[127];
262 static void gui_fill(int id, char * line)
269 keyd[(int)*l] = gui_state(id, l, GUI_SML, *l, 0);
273 void gui_keyboard(int id)
279 if ((jd = gui_hstack(id)))
283 if ((kd = gui_vstack(jd)))
285 if ((ld = gui_harray(kd)))
288 gui_fill(ld, "9876543210");
291 if ((ld = gui_harray(kd)))
294 gui_fill(ld, "JIHGFEDCBA");
297 if ((ld = gui_harray(kd)))
300 gui_fill(ld, "TSRQPONMLK");
303 if ((ld = gui_harray(kd)))
306 gui_fill(ld, "!.-_ZYXWVU");
309 if ((ld = gui_harray(kd)))
312 gui_fill(ld, "jihgfedcba");
315 if ((ld = gui_harray(kd)))
318 gui_fill(ld, "tsrqponmlk");
321 if ((ld = gui_hstack(kd)))
324 gui_state(ld, _("del"), GUI_SML, GUI_BS, 0);
325 gui_fill(ld, "zyxwvu");
333 /*---------------------------------------------------------------------------*/
335 int gui_back_prev_next(int id, int prev, int next)
338 if ((jd = gui_hstack(id)))
342 gui_maybe(jd, _("Next"), GUI_NEXT, next);
343 gui_maybe(jd, _("Prev"), GUI_PREV, prev);
346 gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
351 int gui_maybe(int id, const char *label, int token, int enabled)
355 bd = gui_state(id, label, GUI_SML, token, 0);
358 bd = gui_state(id, label, GUI_SML, GUI_NULL, 0);
359 gui_set_color(bd, gui_gry, gui_gry);
364 /*---------------------------------------------------------------------------*/