diff options
Diffstat (limited to 'apps/plugins/xrick/scr_getname.c')
-rw-r--r-- | apps/plugins/xrick/scr_getname.c | 290 |
1 files changed, 290 insertions, 0 deletions
diff --git a/apps/plugins/xrick/scr_getname.c b/apps/plugins/xrick/scr_getname.c new file mode 100644 index 0000000000..eb1afffde9 --- /dev/null +++ b/apps/plugins/xrick/scr_getname.c | |||
@@ -0,0 +1,290 @@ | |||
1 | /* | ||
2 | * xrick/scr_getname.c | ||
3 | * | ||
4 | * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). | ||
5 | * Copyright (C) 2008-2014 Pierluigi Vicinanza. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * The use and distribution terms for this software are contained in the file | ||
9 | * named README, which can be found in the root of this distribution. By | ||
10 | * using this software in any fashion, you are agreeing to be bound by the | ||
11 | * terms of this license. | ||
12 | * | ||
13 | * You must not remove this notice, or any other, from this software. | ||
14 | */ | ||
15 | |||
16 | #include "xrick/screens.h" | ||
17 | |||
18 | #include "xrick/game.h" | ||
19 | #include "xrick/draw.h" | ||
20 | #include "xrick/control.h" | ||
21 | #include "xrick/data/pics.h" | ||
22 | #include "xrick/system/system.h" | ||
23 | |||
24 | /* | ||
25 | * local vars | ||
26 | */ | ||
27 | static U8 seq = 0; | ||
28 | static U8 x, y, p; | ||
29 | static U8 player_name[HISCORE_NAME_SIZE]; | ||
30 | |||
31 | #define TILE_POINTER '\072' | ||
32 | #define TILE_CURSOR '\073' | ||
33 | #define TOPLEFT_X 116 | ||
34 | #define TOPLEFT_Y 64 | ||
35 | #define NAMEPOS_X 120 | ||
36 | #define NAMEPOS_Y 160 | ||
37 | #define AUTOREPEAT_TMOUT 100 | ||
38 | |||
39 | |||
40 | /* | ||
41 | * prototypes | ||
42 | */ | ||
43 | static void pointer_show(bool); | ||
44 | static void name_update(void); | ||
45 | static void name_draw(void); | ||
46 | |||
47 | |||
48 | /* | ||
49 | * Get name | ||
50 | * | ||
51 | * return: 0 while running, 1 when finished. | ||
52 | */ | ||
53 | U8 | ||
54 | screen_getname(void) | ||
55 | { | ||
56 | static U32 tm = 0; | ||
57 | U8 i, j; | ||
58 | |||
59 | if (seq == 0) | ||
60 | { | ||
61 | /* figure out if this is a high score */ | ||
62 | if (game_score < screen_highScores[screen_nbr_hiscores - 1].score) | ||
63 | return SCREEN_DONE; | ||
64 | |||
65 | /* prepare */ | ||
66 | draw_tilesBank = 0; | ||
67 | #ifdef GFXPC | ||
68 | draw_filter = 0xffff; | ||
69 | #endif | ||
70 | for (i = 0; i < HISCORE_NAME_SIZE; i++) | ||
71 | { | ||
72 | player_name[i] = '@'; | ||
73 | } | ||
74 | x = 5, y = 4, p = 0; | ||
75 | game_rects = &draw_SCREENRECT; | ||
76 | seq = 1; | ||
77 | } | ||
78 | |||
79 | switch (seq) | ||
80 | { | ||
81 | case 1: /* prepare screen */ | ||
82 | { | ||
83 | sysvid_clear(); | ||
84 | #ifdef GFXPC | ||
85 | draw_setfb(32, 8); | ||
86 | draw_filter = 0xaaaa; /* red */ | ||
87 | draw_tilesListImm(screen_congrats); | ||
88 | #endif | ||
89 | #ifdef GFXST | ||
90 | draw_pic(pic_congrats); | ||
91 | #endif | ||
92 | draw_setfb(72, 40); | ||
93 | #ifdef GFXPC | ||
94 | draw_filter = 0xffff; /* yellow */ | ||
95 | #endif | ||
96 | draw_tilesListImm((U8 *)"PLEASE@ENTER@YOUR@NAME\376"); | ||
97 | #ifdef GFXPC | ||
98 | draw_filter = 0x5555; /* green */ | ||
99 | #endif | ||
100 | for (i = 0; i < 6; i++) | ||
101 | { | ||
102 | for (j = 0; j < 4; j++) | ||
103 | { | ||
104 | draw_setfb(TOPLEFT_X + i * 8 * 2, TOPLEFT_Y + j * 8 * 2); | ||
105 | draw_tile('A' + i + j * 6); | ||
106 | } | ||
107 | } | ||
108 | draw_setfb(TOPLEFT_X, TOPLEFT_Y + 64); | ||
109 | #ifdef GFXST | ||
110 | draw_tilesListImm((U8 *)"Y@Z@.@@@\074\373\374\375\376"); | ||
111 | #endif | ||
112 | #ifdef GFXPC | ||
113 | draw_tilesListImm((U8 *)"Y@Z@.@@@\074@\075@\376"); | ||
114 | #endif | ||
115 | name_draw(); | ||
116 | pointer_show(true); | ||
117 | seq = 2; | ||
118 | break; | ||
119 | } | ||
120 | case 2: /* wait for key pressed */ | ||
121 | { | ||
122 | if (control_test(Control_FIRE)) | ||
123 | seq = 3; | ||
124 | if (control_test(Control_UP)) { | ||
125 | if (y > 0) { | ||
126 | pointer_show(false); | ||
127 | y--; | ||
128 | pointer_show(true); | ||
129 | tm = sys_gettime(); | ||
130 | } | ||
131 | seq = 4; | ||
132 | } | ||
133 | if (control_test(Control_DOWN)) { | ||
134 | if (y < 4) { | ||
135 | pointer_show(false); | ||
136 | y++; | ||
137 | pointer_show(true); | ||
138 | tm = sys_gettime(); | ||
139 | } | ||
140 | seq = 5; | ||
141 | } | ||
142 | if (control_test(Control_LEFT)) { | ||
143 | if (x > 0) { | ||
144 | pointer_show(false); | ||
145 | x--; | ||
146 | pointer_show(true); | ||
147 | tm = sys_gettime(); | ||
148 | } | ||
149 | seq = 6; | ||
150 | } | ||
151 | if (control_test(Control_RIGHT)) { | ||
152 | if (x < 5) { | ||
153 | pointer_show(false); | ||
154 | x++; | ||
155 | pointer_show(true); | ||
156 | tm = sys_gettime(); | ||
157 | } | ||
158 | seq = 7; | ||
159 | } | ||
160 | break; | ||
161 | } | ||
162 | case 3: /* wait for FIRE released */ | ||
163 | { | ||
164 | if (!(control_test(Control_FIRE))) | ||
165 | { | ||
166 | if (x == 5 && y == 4) | ||
167 | { /* end */ | ||
168 | i = 0; | ||
169 | while (game_score < screen_highScores[i].score) i++; | ||
170 | j = 7; | ||
171 | while (j > i) | ||
172 | { | ||
173 | screen_highScores[j].score = screen_highScores[j - 1].score; | ||
174 | for (x = 0; x < HISCORE_NAME_SIZE; x++) | ||
175 | { | ||
176 | screen_highScores[j].name[x] = screen_highScores[j - 1].name[x]; | ||
177 | } | ||
178 | j--; | ||
179 | } | ||
180 | screen_highScores[i].score = game_score; | ||
181 | for (x = 0; x < HISCORE_NAME_SIZE; x++) | ||
182 | { | ||
183 | screen_highScores[i].name[x] = player_name[x]; | ||
184 | } | ||
185 | seq = 99; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | name_update(); | ||
190 | name_draw(); | ||
191 | seq = 2; | ||
192 | } | ||
193 | } | ||
194 | break; | ||
195 | } | ||
196 | case 4: /* wait for UP released */ | ||
197 | { | ||
198 | if (!(control_test(Control_UP)) || | ||
199 | sys_gettime() - tm > AUTOREPEAT_TMOUT) | ||
200 | seq = 2; | ||
201 | break; | ||
202 | } | ||
203 | case 5: /* wait for DOWN released */ | ||
204 | { | ||
205 | if (!(control_test(Control_DOWN)) || | ||
206 | sys_gettime() - tm > AUTOREPEAT_TMOUT) | ||
207 | seq = 2; | ||
208 | break; | ||
209 | } | ||
210 | case 6: /* wait for LEFT released */ | ||
211 | { | ||
212 | if (!(control_test(Control_LEFT)) || | ||
213 | sys_gettime() - tm > AUTOREPEAT_TMOUT) | ||
214 | seq = 2; | ||
215 | break; | ||
216 | } | ||
217 | case 7: /* wait for RIGHT released */ | ||
218 | { | ||
219 | if (!(control_test(Control_RIGHT)) || | ||
220 | sys_gettime() - tm > AUTOREPEAT_TMOUT) | ||
221 | seq = 2; | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | if (control_test(Control_EXIT)) /* check for exit request */ | ||
227 | return SCREEN_EXIT; | ||
228 | |||
229 | if (seq == 99) { /* seq 99, we're done */ | ||
230 | sysvid_clear(); | ||
231 | seq = 0; | ||
232 | return SCREEN_DONE; | ||
233 | } | ||
234 | else | ||
235 | return SCREEN_RUNNING; | ||
236 | } | ||
237 | |||
238 | |||
239 | static void | ||
240 | pointer_show(bool show) | ||
241 | { | ||
242 | draw_setfb(TOPLEFT_X + x * 8 * 2, TOPLEFT_Y + y * 8 * 2 + 8); | ||
243 | #ifdef GFXPC | ||
244 | draw_filter = 0xaaaa; /* red */ | ||
245 | #endif | ||
246 | draw_tile(show? TILE_POINTER:'@'); | ||
247 | } | ||
248 | |||
249 | static void | ||
250 | name_update(void) | ||
251 | { | ||
252 | U8 i; | ||
253 | |||
254 | i = x + y * 6; | ||
255 | if (i < 26 && p < 10) | ||
256 | player_name[p++] = 'A' + i; | ||
257 | if (i == 26 && p < 10) | ||
258 | player_name[p++] = '.'; | ||
259 | if (i == 27 && p < 10) | ||
260 | player_name[p++] = '@'; | ||
261 | if (i == 28 && p > 0) { | ||
262 | p--; | ||
263 | } | ||
264 | } | ||
265 | |||
266 | static void | ||
267 | name_draw(void) | ||
268 | { | ||
269 | U8 i; | ||
270 | |||
271 | draw_setfb(NAMEPOS_X, NAMEPOS_Y); | ||
272 | #ifdef GFXPC | ||
273 | draw_filter = 0xaaaa; /* red */ | ||
274 | #endif | ||
275 | for (i = 0; i < p; i++) | ||
276 | draw_tile(player_name[i]); | ||
277 | for (i = p; i < 10; i++) | ||
278 | draw_tile(TILE_CURSOR); | ||
279 | |||
280 | #ifdef GFXST | ||
281 | draw_setfb(NAMEPOS_X, NAMEPOS_Y + 8); | ||
282 | for (i = 0; i < 10; i++) | ||
283 | draw_tile('@'); | ||
284 | draw_setfb(NAMEPOS_X + 8 * (p < 9 ? p : 9), NAMEPOS_Y + 8); | ||
285 | draw_tile(TILE_POINTER); | ||
286 | #endif | ||
287 | } | ||
288 | |||
289 | |||
290 | /* eof */ | ||