Save an player name chages:
[neverball] / ball / util.c
1 /*
2  * Copyright (C) 2003 Robert Kooima
3  *
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.
8  *
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.
13  */
14
15 #include <ctype.h>
16 #include <string.h>
17
18 #include "gui.h"
19 #include "util.h"
20 #include "level.h"
21 #include "config.h"
22
23 /*---------------------------------------------------------------------------*/
24
25 static int is_special_name(const char * n)
26 {
27     return (strcmp(n, N_("Hard"))==0 || strcmp(n, N_("Medium"))==0 || strcmp(n, N_("Easy"))==0);
28 }
29
30 /*---------------------------------------------------------------------------*/
31
32 static int coin_c[4];
33 static int coin_n[4];
34 static int coin_t[4];
35 static int coin_row;
36 static int coin_lastrow;
37
38 /* Build a Most Coins top three list with default values. */
39
40 void gui_most_coins(int id, int n, int n2)
41 {
42     const char *s = "1234567";
43
44     int j, jd, kd, ld, md;
45
46     coin_row = n;
47     coin_lastrow = n2;
48
49     if ((jd = gui_hstack(id)))
50     {
51         gui_filler(jd);
52
53         if ((kd = gui_vstack(jd)))
54         {
55             gui_label(kd, _("Most Coins"), GUI_SML, GUI_TOP, 0, 0);
56
57             if ((ld = gui_hstack(kd)))
58             {
59                 if ((md = gui_vstack(ld)))
60                 {
61                     for (j = 0; j < n - 1; j++)
62                         coin_c[j] = gui_count(md, 1000, GUI_SML, 0);
63
64                     coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SE);
65                     
66                     if (n2)
67                     {
68                        gui_space(md);
69                        coin_c[j++] = gui_count(md, 1000, GUI_SML, GUI_RGT);
70                     }
71                 }
72
73                 if ((md = gui_vstack(ld)))
74                 {
75                     for (j = 0; j < n; j++)
76                         coin_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
77                     
78                     if (n2)
79                     {
80                         gui_space(md);
81                         coin_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
82                     }
83                 }
84
85                 if ((md = gui_vstack(ld)))
86                 {
87                     for (j = 0; j < n - 1; j++)
88                         coin_t[j] = gui_clock(md, 359999, GUI_SML, 0);
89
90                     coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_SW);
91
92                     if (n2)
93                     {
94                        gui_space(md);
95                        coin_t[j++] = gui_clock(md, 359999,  GUI_SML, GUI_LFT);
96                     }
97                 }
98             }
99         }
100         gui_filler(jd);
101     }
102 }
103
104 /* Set the Most Coins top three list values for level i. */
105
106 void set_most_coins(int level, int hilight)
107 {
108     int j, spe;
109     const char * name;
110
111     for (j = 0; j < coin_row + coin_lastrow; j++)
112     {
113         name = level_coin_n(level, j);
114         spe = is_special_name(name);
115
116         if (spe)
117            gui_set_color(coin_n[j], 0, 0);
118         else if (j != hilight)
119            gui_set_color(coin_n[j], gui_yel, gui_wht);
120         else if (j>= coin_row)
121            gui_set_color(coin_n[j], gui_red, gui_red);
122         else
123            gui_set_color(coin_n[j], gui_grn, gui_grn);
124         
125         gui_set_count(coin_c[j], level_coin_c(level, j));
126         gui_set_label(coin_n[j], spe ? _(name) : name);
127         gui_set_clock(coin_t[j], level_coin_t(level, j));
128     }
129 }
130
131 /*---------------------------------------------------------------------------*/
132
133 static int time_c[4];
134 static int time_n[4];
135 static int time_t[4];
136 static int time_row;
137 static int time_lastrow;
138
139 /* Build a Best Times top three list with default values. */
140
141 void gui_best_times(int id, int n, int n2)
142 {
143     const char *s = "1234567";
144
145     int j, jd, kd, ld, md;
146
147     time_row = n;
148     time_lastrow = n2;
149
150     if ((jd = gui_hstack(id)))
151     {
152         gui_filler(jd);
153
154         if ((kd = gui_vstack(jd)))
155         {
156             gui_label(kd, _("Best Times"), GUI_SML, GUI_TOP, 0, 0);
157
158             if ((ld = gui_hstack(kd)))
159             {
160                 if ((md = gui_vstack(ld)))
161                 {
162                     for (j = 0; j < n - 1; j++)
163                         time_t[j] = gui_clock(md, 359999, GUI_SML, 0);
164
165                     time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_SE);
166                     
167                     if (n2)
168                     {
169                         gui_space(md);
170                         time_t[j++] = gui_clock(md, 359999, GUI_SML, GUI_RGT);
171                     }
172                 }
173
174                 if ((md = gui_vstack(ld)))
175                 {
176                     for (j = 0; j < n; j++)
177                         time_n[j] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
178
179                     if (n2)
180                     {
181                         gui_space(md);
182                         time_n[j++] = gui_label(md, s, GUI_SML, 0, gui_yel, gui_wht);
183                     }
184                 }
185
186                 if ((md = gui_vstack(ld)))
187                 {
188                     for (j = 0; j < n - 1; j++)
189                         time_c[j] = gui_count(md, 1000, GUI_SML, 0);
190
191                     time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_SW);
192                     
193                     if (n2)
194                     {
195                         gui_space(md);
196                         time_c[j++] = gui_count(md, 1000, GUI_SML, GUI_LFT);
197                     }
198                 }
199             }
200         }
201         gui_filler(jd);
202     }
203 }
204
205 /* Set the Best Times top three list values for level i. */
206
207 void set_best_times(int level, int hilight)
208 {
209     int j, spe;
210     const char * name;
211
212     for (j = 0; j < time_row + time_lastrow; j++)
213     {
214         name = level_time_n(level, j);
215         spe = is_special_name(name);
216         
217         if (spe)
218            gui_set_color(time_n[j], 0, 0);
219         else if (j != hilight)
220            gui_set_color(time_n[j], gui_yel, gui_wht);
221         else if (j>= time_row)
222            gui_set_color(time_n[j], gui_red, gui_red);
223         else
224            gui_set_color(time_n[j], gui_grn, gui_grn);
225         
226         gui_set_clock(time_t[j], level_time_t(level, j));
227         gui_set_label(time_n[j], spe ? _(name) : name);
228         gui_set_count(time_c[j], level_time_c(level, j));
229     }
230 }
231
232 /*---------------------------------------------------------------------------*/
233
234 static int lock = 1;
235 static int keyd[127]; 
236
237 static void gui_fill(int id, char * line)
238 {
239     char l[2];
240     l[1] = '\0';
241     while(*line)
242     {
243         *l = *(line++);
244         keyd[(int)*l] = gui_state(id, l, GUI_SML, *l, 0);
245     }
246 }
247
248 void gui_keyboard(int id)
249 {
250     int jd, kd, ld;
251
252     lock = 1;
253
254     if ((jd = gui_hstack(id)))
255     {
256         gui_filler(jd);
257
258         if ((kd = gui_vstack(jd)))
259         {
260             if ((ld = gui_harray(kd)))
261             {
262                 gui_filler(ld);
263                 gui_fill(ld, "9876543210");
264                 gui_filler(ld);
265             }
266             if ((ld = gui_harray(kd)))
267             {
268                 gui_filler(ld);
269                 gui_fill(ld, "JIHGFEDCBA");
270                 gui_filler(ld);
271             }
272             if ((ld = gui_harray(kd)))
273             {
274                 gui_filler(ld);
275                 gui_fill(ld, "TSRQPONMLK");
276                 gui_filler(ld);
277             }
278             if ((ld = gui_harray(kd)))
279             {
280                 gui_filler(ld);
281                 gui_fill(ld, "!.-_ZYXWVU");
282                 gui_filler(ld);
283             }
284             if ((ld = gui_harray(kd)))
285             {
286                 gui_filler(ld);
287                 gui_fill(ld, "jihgfedcba");
288                 gui_filler(ld);
289             }
290             if ((ld = gui_harray(kd)))
291             {
292                 gui_filler(ld);
293                 gui_fill(ld, "tsrqponmlk");
294                 gui_filler(ld);
295             }
296             if ((ld = gui_hstack(kd)))
297             {
298                 gui_filler(ld);
299                 gui_state(ld, _("del"), GUI_SML, GUI_BS, 0);
300                 gui_fill(ld, "zyxwvu");
301                 gui_filler(ld);
302             }
303         }
304         gui_filler(jd);
305     }
306 }
307
308 /*---------------------------------------------------------------------------*/