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, gui_yel, gui_wht);
79 coin_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
83 if ((md = gui_vstack(ld)))
85 for (j = 0; j < NSCORE - 1; j++)
86 coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
88 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SW);
93 coin_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_LFT);
102 /* Set the Most Coins top three list values for level i. */
104 void set_most_coins(const struct score *s, int hilight)
111 for (j = 0; j < NSCORE + coin_extrarow ; j++)
113 gui_set_count(coin_c[j], -1);
114 gui_set_label(coin_n[j], "");
115 gui_set_clock(coin_t[j], -1);
120 for (j = 0; j < NSCORE + coin_extrarow; j++)
123 spe = is_special_name(name);
126 gui_set_color(coin_n[j], 0, 0);
127 else if (j != hilight)
128 gui_set_color(coin_n[j], gui_yel, gui_wht);
130 gui_set_color(coin_n[j], gui_red, gui_red);
132 gui_set_color(coin_n[j], gui_grn, gui_grn);
134 gui_set_count(coin_c[j], s->coins[j]);
135 gui_set_label(coin_n[j], spe ? _(name) : name);
136 gui_set_clock(coin_t[j], s->timer[j]);
141 /*---------------------------------------------------------------------------*/
144 static int time_c[4];
145 static int time_n[4];
146 static int time_t2[4]; /* Renamed to time_t2 to avoid multiple declaration (in sys/types.h) */
147 static int time_extrarow;
149 /* Build a Best Times top three list with default values. */
151 void gui_best_times(int id, int e)
153 const char *s = "1234567";
155 int j, jd, kd, ld, md;
159 if ((jd = gui_hstack(id)))
163 if ((kd = gui_vstack(jd)))
165 time_l = gui_label(kd, "XXX", GUI_SML, GUI_TOP, 0, 0);
167 if ((ld = gui_hstack(kd)))
169 if ((md = gui_vstack(ld)))
171 for (j = 0; j < NSCORE - 1; j++)
172 time_t2[j] = gui_clock(md, 359999, GUI_SML, 0);
174 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
179 time_t2[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
183 if ((md = gui_vstack(ld)))
185 for (j = 0; j < NSCORE; j++)
186 time_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
191 time_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
195 if ((md = gui_vstack(ld)))
197 for (j = 0; j < NSCORE - 1; j++)
198 time_c[j] = gui_count(md, 1000, GUI_SML, 0);
200 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
205 time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
214 /* Set the Best Times top three list values for level i. */
216 void set_best_times(const struct score *s, int hilight, int goal)
222 gui_set_label(time_l, _("Unlock Goal"));
224 gui_set_label(time_l, _("Best Times"));
228 for (j = 0; j < NSCORE + time_extrarow ; j++)
230 gui_set_clock(time_t2[j], -1);
231 gui_set_label(time_n[j], "");
232 gui_set_count(time_c[j], -1);
237 for (j = 0; j < NSCORE + time_extrarow; j++)
240 spe = is_special_name(name);
243 gui_set_color(time_n[j], 0, 0);
244 else if (j != hilight)
245 gui_set_color(time_n[j], gui_yel, gui_wht);
247 gui_set_color(time_n[j], gui_red, gui_red);
249 gui_set_color(time_n[j], gui_grn, gui_grn);
251 gui_set_clock(time_t2[j], s->timer[j]);
252 gui_set_label(time_n[j], spe ? _(name) : name);
253 gui_set_count(time_c[j], s->coins[j]);
258 /*---------------------------------------------------------------------------*/
261 static int keyd[127];
263 static void gui_fill(int id, char *line)
271 keyd[(int)*l] = gui_state(id, l, GUI_SML, *l, 0);
275 void gui_keyboard(int id)
281 if ((jd = gui_hstack(id)))
285 if ((kd = gui_vstack(jd)))
287 if ((ld = gui_harray(kd)))
290 gui_fill(ld, "9876543210");
293 if ((ld = gui_harray(kd)))
296 gui_fill(ld, "JIHGFEDCBA");
299 if ((ld = gui_harray(kd)))
302 gui_fill(ld, "TSRQPONMLK");
305 if ((ld = gui_harray(kd)))
308 gui_fill(ld, "!.-_ZYXWVU");
311 if ((ld = gui_harray(kd)))
314 gui_fill(ld, "jihgfedcba");
317 if ((ld = gui_harray(kd)))
320 gui_fill(ld, "tsrqponmlk");
323 if ((ld = gui_hstack(kd)))
326 gui_state(ld, _("del"), GUI_SML, GUI_BS, 0);
327 gui_fill(ld, "zyxwvu");
335 /*---------------------------------------------------------------------------*/
337 int gui_back_prev_next(int id, int prev, int next)
340 if ((jd = gui_hstack(id)))
344 gui_maybe(jd, _("Next"), GUI_NEXT, next);
345 gui_maybe(jd, _("Prev"), GUI_PREV, prev);
348 gui_start(jd, _("Back"), GUI_SML, GUI_BACK, 0);
353 int gui_maybe(int id, const char *label, int token, int enabled)
357 bd = gui_state(id, label, GUI_SML, token, 0);
360 bd = gui_state(id, label, GUI_SML, GUI_NULL, 0);
361 gui_set_color(bd, gui_gry, gui_gry);
366 /*---------------------------------------------------------------------------*/