1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 1995 Crack dot Com |
---|
4 | * |
---|
5 | * This software was released into the Public Domain. As with most public |
---|
6 | * domain software, no warranty is made or implied by Crack dot Com or |
---|
7 | * Jonathan Clark. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "config.h" |
---|
11 | |
---|
12 | #include <math.h> |
---|
13 | |
---|
14 | #include "menu.hpp" |
---|
15 | #include "lisp.hpp" |
---|
16 | #include "loader.hpp" |
---|
17 | #include "game.hpp" |
---|
18 | #include "timing.hpp" |
---|
19 | #include "game.hpp" |
---|
20 | #include "id.hpp" |
---|
21 | #include "pmenu.hpp" |
---|
22 | #include "gui.hpp" |
---|
23 | #include "property.hpp" |
---|
24 | #include "dev.hpp" |
---|
25 | #include "clisp.hpp" |
---|
26 | #include "gamma.hpp" |
---|
27 | #include "dprint.hpp" |
---|
28 | #include "demo.hpp" |
---|
29 | |
---|
30 | jwindow *volume_window=NULL; |
---|
31 | |
---|
32 | |
---|
33 | //percent is 0..256 |
---|
34 | void tint_area(int x1, int y1, int x2, int y2, int r_to, int g_to, int b_to, int percent) |
---|
35 | { |
---|
36 | int x,y; |
---|
37 | short cx1,cy1,cx2,cy2; |
---|
38 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
39 | if (x1<cx1) x1=cx1; |
---|
40 | if (y1<cy1) y1=cy1; |
---|
41 | if (x2>cx2) x2=cx2; |
---|
42 | if (y2>cy2) y2=cy2; |
---|
43 | if (x2<x1 || y2<y1) return ; |
---|
44 | |
---|
45 | percent=256-percent; |
---|
46 | |
---|
47 | for (y=y1;y<=y2;y++) |
---|
48 | { |
---|
49 | uint8_t *sl=screen->scan_line(y)+x1; |
---|
50 | for (x=x1;x<=x2;x++,sl++) |
---|
51 | { |
---|
52 | uint8_t *paddr=(uint8_t *)pal->addr()+(*sl)*3; |
---|
53 | uint8_t r=((*(paddr++))-r_to)*percent/256+r_to; |
---|
54 | uint8_t g=((*(paddr++))-g_to)*percent/256+g_to; |
---|
55 | uint8_t b=((*(paddr++))-b_to)*percent/256+b_to; |
---|
56 | *sl=color_table->lookup_color((r)>>3,(g)>>3,(b)>>3); |
---|
57 | } |
---|
58 | } |
---|
59 | screen->add_dirty(x1,y1,x2,y2); |
---|
60 | } |
---|
61 | |
---|
62 | void darken_area(int x1, int y1, int x2, int y2, int amount) |
---|
63 | { |
---|
64 | int x,y; |
---|
65 | short cx1,cy1,cx2,cy2; |
---|
66 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
67 | if (x1<cx1) x1=cx1; |
---|
68 | if (y1<cy1) y1=cy1; |
---|
69 | if (x2>cx2) x2=cx2; |
---|
70 | if (y2>cy2) y2=cy2; |
---|
71 | if (x2<x1 || y2<y1) return ; |
---|
72 | |
---|
73 | for (y=y1;y<=y2;y++) |
---|
74 | { |
---|
75 | uint8_t *sl=screen->scan_line(y)+x1; |
---|
76 | for (x=x1;x<=x2;x++,sl++) |
---|
77 | { |
---|
78 | uint8_t *paddr=(uint8_t *)pal->addr()+(*sl)*3; |
---|
79 | uint8_t r=(*(paddr++))*amount/256; |
---|
80 | uint8_t g=(*(paddr++))*amount/256; |
---|
81 | uint8_t b=(*(paddr++))*amount/256; |
---|
82 | *sl=color_table->lookup_color((r)>>3,(g)>>3,(b)>>3); |
---|
83 | } |
---|
84 | } |
---|
85 | screen->add_dirty(x1,y1,x2,y2); |
---|
86 | } |
---|
87 | |
---|
88 | void dark_wiget(int x1, int y1, int x2, int y2, int br, int dr, int amount) |
---|
89 | { |
---|
90 | screen->add_dirty(x1,y1,x2,y2); |
---|
91 | screen->line(x1,y1,x1,y2,br); |
---|
92 | screen->line(x1+1,y1,x2,y1,br); |
---|
93 | screen->line(x2,y1+1,x2,y2,dr); |
---|
94 | screen->line(x1+1,y2,x2,y2,dr); |
---|
95 | darken_area(x1+1,y1+1,x2-1,y2-1,amount); |
---|
96 | } |
---|
97 | |
---|
98 | char *men_str(void *arg) |
---|
99 | { |
---|
100 | switch (item_type(arg)) |
---|
101 | { |
---|
102 | case L_STRING : |
---|
103 | { return lstring_value(arg); } break; |
---|
104 | case L_CONS_CELL : |
---|
105 | { return lstring_value(CAR(arg)); } break; |
---|
106 | default : |
---|
107 | { |
---|
108 | lprint(arg); |
---|
109 | printf(" is not a valid menu option\n"); |
---|
110 | exit(0); |
---|
111 | } |
---|
112 | } |
---|
113 | return NULL; |
---|
114 | } |
---|
115 | |
---|
116 | void main_menu(); |
---|
117 | |
---|
118 | int menu(void *args, JCFont *font) // reurns -1 on esc |
---|
119 | { |
---|
120 | main_menu(); |
---|
121 | char *title=NULL; |
---|
122 | if (!NILP(CAR(args))) |
---|
123 | title=lstring_value(CAR(args)); |
---|
124 | Cell *def=lcar(lcdr(lcdr(args))); |
---|
125 | args=CAR(CDR(args)); |
---|
126 | |
---|
127 | int options=list_length(args); |
---|
128 | int mh=(font->height()+1)*options+10,maxw=0; |
---|
129 | |
---|
130 | Cell *c=(Cell *)args; |
---|
131 | for (;!NILP(c);c=CDR(c)) |
---|
132 | { |
---|
133 | if (strlen(men_str(CAR(c)))>maxw) |
---|
134 | maxw=strlen(men_str(CAR(c))); |
---|
135 | } |
---|
136 | |
---|
137 | int mw=(font->width())*maxw+20; |
---|
138 | int mx=screen->width()/2-mw/2, |
---|
139 | my=screen->height()/2-mh/2; |
---|
140 | |
---|
141 | |
---|
142 | screen->add_dirty(mx,my,mx+mw-1,my+mh-1); |
---|
143 | |
---|
144 | if (title) |
---|
145 | { |
---|
146 | int tl=strlen(title)*font->width(); |
---|
147 | int tx=screen->width()/2-tl/2; |
---|
148 | dark_wiget(tx-2,my-font->height()-4,tx+tl+2,my-2,eh->medium_color(),eh->dark_color(),180); |
---|
149 | font->put_string(screen,tx+1,my-font->height()-2,title,eh->bright_color()); |
---|
150 | } |
---|
151 | |
---|
152 | dark_wiget(mx,my,mx+mw-1,my+mh-1,eh->medium_color(),eh->dark_color(),200); |
---|
153 | |
---|
154 | |
---|
155 | int y=my+5; |
---|
156 | for (c=(Cell *)args;!NILP(c);c=CDR(c)) |
---|
157 | { |
---|
158 | char *ms=men_str(CAR(c)); |
---|
159 | font->put_string(screen,mx+10+1,y+1,ms,eh->black()); |
---|
160 | font->put_string(screen,mx+10,y,ms,eh->bright_color()); |
---|
161 | y+=font->height()+1; |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | eh->flush_screen(); |
---|
166 | event ev; |
---|
167 | int choice=0,done=0; |
---|
168 | int bh=font->height()+3; |
---|
169 | image *save=new image(mw-2,bh); |
---|
170 | int color=128,cdir=50; |
---|
171 | |
---|
172 | time_marker *last_color_time=NULL; |
---|
173 | if (!NILP(def)) |
---|
174 | choice=lnumber_value(def); |
---|
175 | do |
---|
176 | { |
---|
177 | |
---|
178 | if (eh->event_waiting()) |
---|
179 | { |
---|
180 | eh->get_event(ev); |
---|
181 | if (ev.type==EV_KEY) |
---|
182 | { |
---|
183 | switch (ev.key) |
---|
184 | { |
---|
185 | case JK_ESC : |
---|
186 | { choice=-1; done=1; } break; |
---|
187 | case JK_ENTER : |
---|
188 | { done=1; } break; |
---|
189 | case JK_DOWN : |
---|
190 | { if (choice<options-1) |
---|
191 | choice++; |
---|
192 | else choice=0; |
---|
193 | } break; |
---|
194 | case JK_UP : |
---|
195 | { |
---|
196 | if (choice>0) |
---|
197 | choice--; |
---|
198 | else choice=options-1; |
---|
199 | } break; |
---|
200 | } |
---|
201 | } else if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button) |
---|
202 | { |
---|
203 | if (ev.mouse_move.x>mx && ev.mouse_move.x<mx+mw && ev.mouse_move.y>my && |
---|
204 | ev.mouse_move.y<my+mh) |
---|
205 | { |
---|
206 | int msel=(ev.mouse_move.y-my)/(font->height()+1); |
---|
207 | if (msel>=options) msel=options-1; |
---|
208 | if (msel==choice) // clicked on already selected item, return it |
---|
209 | done=1; |
---|
210 | else choice=msel; // selects an item |
---|
211 | } |
---|
212 | } |
---|
213 | eh->flush_screen(); |
---|
214 | } |
---|
215 | |
---|
216 | time_marker cur_time; |
---|
217 | if (!last_color_time || (int)(cur_time.diff_time(last_color_time)*1000)>120) |
---|
218 | { |
---|
219 | if (last_color_time) |
---|
220 | delete last_color_time; |
---|
221 | last_color_time=new time_marker; |
---|
222 | |
---|
223 | int by1=(font->height()+1)*choice+my+5-2; |
---|
224 | int by2=by1+bh-1; |
---|
225 | |
---|
226 | screen->put_part(save,0,0,mx+1,by1,mx+mw-2,by2); |
---|
227 | tint_area(mx+1,by1,mx+mw-2,by2,63,63,63,color); |
---|
228 | |
---|
229 | char *cur=men_str(nth(choice,args)); |
---|
230 | font->put_string(screen,mx+10+1,by1+3,cur,eh->black()); |
---|
231 | font->put_string(screen,mx+10,by1+2,cur,eh->bright_color()); |
---|
232 | screen->rectangle(mx+1,by1,mx+mw-2,by2,eh->bright_color()); |
---|
233 | |
---|
234 | color+=cdir; |
---|
235 | |
---|
236 | if (color<12 || color>256) |
---|
237 | { |
---|
238 | cdir=-cdir; |
---|
239 | color+=cdir; |
---|
240 | } |
---|
241 | eh->flush_screen(); |
---|
242 | save->put_image(screen,mx+1,by1); |
---|
243 | } else milli_wait(10); |
---|
244 | |
---|
245 | } while (!done); |
---|
246 | if (last_color_time) |
---|
247 | delete last_color_time; |
---|
248 | delete save; |
---|
249 | the_game->draw(the_game->state==SCENE_STATE); |
---|
250 | |
---|
251 | if (choice!=-1) |
---|
252 | { |
---|
253 | void *val=nth(choice,args); |
---|
254 | if (item_type(val)==L_CONS_CELL) // is there another value that the user want us to return? |
---|
255 | return lnumber_value(lcdr(val)); |
---|
256 | } |
---|
257 | return choice; |
---|
258 | } |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | struct mask_line |
---|
263 | { |
---|
264 | int x,size; |
---|
265 | uint16_t *remap; |
---|
266 | } ; |
---|
267 | |
---|
268 | |
---|
269 | |
---|
270 | void scan_map(image *screen, int sx, int sy, image *im, image *clouds, mask_line *p, int mask_height, |
---|
271 | int xoff, int coff) |
---|
272 | { |
---|
273 | int x1=10000,x2=0; |
---|
274 | int iw=im->width(); |
---|
275 | uint16_t r,co,off,cc; |
---|
276 | int y=0; |
---|
277 | for (;y<mask_height;y++) |
---|
278 | { |
---|
279 | mask_line *n=p+y; |
---|
280 | uint8_t *sl=screen->scan_line(y+sy)+sx+n->x; |
---|
281 | uint8_t *sl2=im->scan_line(y); |
---|
282 | // uint8_t *sl3=clouds->scan_line(y); |
---|
283 | uint16_t *rem=n->remap; |
---|
284 | if (sx+n->x<x1) x1=sx+n->x; |
---|
285 | int x=0; |
---|
286 | for (;x<n->size;x++,sl++,rem++) |
---|
287 | { |
---|
288 | r=*rem; |
---|
289 | // co=(r+coff); |
---|
290 | // if (co>=iw) co-=iw; |
---|
291 | // cc=sl3[co]; |
---|
292 | |
---|
293 | off=(r+xoff); |
---|
294 | if (off>=iw) off-=iw; |
---|
295 | // if (cc) |
---|
296 | // *sl=*(white_light+(r/4+(x+y)%2)*256+*(white_light+((256-cc)/2-64)*256+sl2[off])); |
---|
297 | // *sl=*(white_light+(r/4+(x+y)%2)*256+*(white_light+(48+cc/16)*256+sl2[off])); |
---|
298 | // else |
---|
299 | *sl=*(white_light+(r/4+(x+y)%2)*256+sl2[off]); |
---|
300 | |
---|
301 | } |
---|
302 | if (sx+n->x+x>x2) x2=sx+n->x+x; |
---|
303 | |
---|
304 | } |
---|
305 | screen->add_dirty(x1,sy,x2,sy+mask_height-1); |
---|
306 | |
---|
307 | } |
---|
308 | |
---|
309 | mask_line *make_mask_lines(image *mask, int map_width) |
---|
310 | { |
---|
311 | mask_line *p=(mask_line *)jmalloc(mask->height()*sizeof(mask_line),"mask_line"); |
---|
312 | for (int y=0;y<mask->height();y++) |
---|
313 | { |
---|
314 | // find the start of the run.. |
---|
315 | uint8_t *sl=mask->scan_line(y); |
---|
316 | int x=0; |
---|
317 | while (*sl==0) { sl++; x++; } |
---|
318 | p[y].x=x; |
---|
319 | |
---|
320 | |
---|
321 | // find the length of the run |
---|
322 | int size=0; |
---|
323 | while (*sl!=0 && x<mask->width()) { sl++; x++; size++; } |
---|
324 | p[y].size=size; |
---|
325 | |
---|
326 | // now calculate remap for line |
---|
327 | p[y].remap=(uint16_t *)jmalloc(size*2,"mask remap"); |
---|
328 | uint16_t *rem=p[y].remap; |
---|
329 | for (x=0;x<size;x++,rem++) |
---|
330 | { |
---|
331 | if (x<=size/2) |
---|
332 | *rem=(int)(sqrt(x/(double)size)*map_width/2.0); |
---|
333 | else *rem=(int)(mask->width()-(sqrt((size-x)/(double)size)*map_width/2.0)+mask->width()/2); |
---|
334 | } |
---|
335 | } |
---|
336 | return p; |
---|
337 | } |
---|
338 | |
---|
339 | static void draw_vol(image *screen, int x1, int y1, int x2, int y2, int t, int max, int c1, int c2) |
---|
340 | { |
---|
341 | int dx=x1+t*(x2-x1)/max; |
---|
342 | if (t!=0) |
---|
343 | screen->bar(x1,y1,dx,y2,c1); |
---|
344 | else dx--; |
---|
345 | |
---|
346 | if (dx<x2) |
---|
347 | screen->bar(dx+1,y1,x2,y2,c2); |
---|
348 | } |
---|
349 | |
---|
350 | static void draw_sfx_vol() |
---|
351 | { |
---|
352 | draw_vol(volume_window->screen,5,17,34,23,sfx_volume,127,pal->find_closest(255,0,0), |
---|
353 | pal->find_closest(90,0,0)); |
---|
354 | } |
---|
355 | |
---|
356 | static void draw_music_vol() |
---|
357 | { |
---|
358 | draw_vol(volume_window->screen,5,72,34,78,music_volume,127,pal->find_closest(255,0,0), |
---|
359 | pal->find_closest(90,0,0)); |
---|
360 | } |
---|
361 | |
---|
362 | static void create_volume_window() |
---|
363 | { |
---|
364 | char *ff="art/frame.spe"; |
---|
365 | int t=SPEC_IMAGE; |
---|
366 | int u_u=cash.reg(ff,"u_u",t,1), |
---|
367 | u_d=cash.reg(ff,"u_u",t,1), |
---|
368 | u_ua=cash.reg(ff,"u_ua",t,1), |
---|
369 | u_da=cash.reg(ff,"u_da",t,1), |
---|
370 | |
---|
371 | d_u=cash.reg(ff,"d_u",t,1), |
---|
372 | d_d=cash.reg(ff,"d_u",t,1), |
---|
373 | d_ua=cash.reg(ff,"d_ua",t,1), |
---|
374 | d_da=cash.reg(ff,"d_da",t,1); |
---|
375 | |
---|
376 | volume_window=eh->new_window(prop->getd("volume_x",xres/2-20), |
---|
377 | prop->getd("volume_y",yres/2-50), |
---|
378 | 41-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT, |
---|
379 | 101-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM, |
---|
380 | new ico_button(10,27,ID_SFX_DOWN,d_u,d_d,d_ua,d_da, |
---|
381 | new ico_button(21,27,ID_SFX_UP,u_u,u_d,u_ua,u_da, |
---|
382 | |
---|
383 | new ico_button(10,63,ID_MUSIC_DOWN,d_u,d_d,d_ua,d_da, |
---|
384 | new ico_button(21,63,ID_MUSIC_UP,u_u,u_d,u_ua,u_da, |
---|
385 | NULL))))); |
---|
386 | cash.img(cash.reg(ff,"vcontrol",t,1))->put_image(volume_window->screen,0,0); |
---|
387 | draw_music_vol(); |
---|
388 | draw_sfx_vol(); |
---|
389 | volume_window->inm->redraw(); |
---|
390 | eh->grab_focus(volume_window); |
---|
391 | } |
---|
392 | |
---|
393 | |
---|
394 | #define MENU_TICONS 19 |
---|
395 | int menu_icons[MENU_TICONS*3]; |
---|
396 | int menu_icons_ids[MENU_TICONS]={ID_START_GAME,ID_VOLUME,ID_NULL,ID_NULL,ID_NULL,ID_NULL, |
---|
397 | ID_NULL,ID_NULL,ID_QUIT,ID_NULL,ID_EASY,ID_NULL, |
---|
398 | ID_MEDIUM,ID_NULL,ID_HARD,ID_NULL,ID_LIGHT_ON,ID_LIGHT_OFF, |
---|
399 | ID_EXTREME }; |
---|
400 | |
---|
401 | static jwindow *ico_win; |
---|
402 | |
---|
403 | void save_difficulty() |
---|
404 | { |
---|
405 | FILE *fp=fopen("hardness.lsp","wb"); |
---|
406 | if (!fp) |
---|
407 | dprintf("Unable to write to file hardness.lsp\n"); |
---|
408 | else |
---|
409 | { |
---|
410 | fprintf(fp,"(setf difficulty '"); |
---|
411 | if (DEFINEDP(l_difficulty)) |
---|
412 | { |
---|
413 | if (symbol_value(l_difficulty)==l_extreme) |
---|
414 | fprintf(fp,"extreme)\n"); |
---|
415 | else if (symbol_value(l_difficulty)==l_hard) |
---|
416 | fprintf(fp,"hard)\n"); |
---|
417 | else if (symbol_value(l_difficulty)==l_easy) |
---|
418 | fprintf(fp,"easy)\n"); |
---|
419 | else |
---|
420 | fprintf(fp,"medium)\n"); |
---|
421 | } else |
---|
422 | fprintf(fp,"medium)\n"); |
---|
423 | fclose(fp); |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | void menu_handler(event &ev, jwindow *ico_win) |
---|
428 | { |
---|
429 | switch (ev.type) |
---|
430 | { |
---|
431 | case EV_MESSAGE : |
---|
432 | { |
---|
433 | switch (ev.message.id) |
---|
434 | { |
---|
435 | case ID_LIGHT_OFF : |
---|
436 | { |
---|
437 | gamma_correct(pal,1); |
---|
438 | } break; |
---|
439 | case ID_START_GAME : |
---|
440 | { |
---|
441 | the_game->load_level(level_file); |
---|
442 | the_game->set_state(RUN_STATE); |
---|
443 | } break; |
---|
444 | |
---|
445 | case ID_VOLUME : |
---|
446 | { create_volume_window(); } break; |
---|
447 | case ID_SFX_UP : |
---|
448 | { if (volume_window) |
---|
449 | { |
---|
450 | sfx_volume+=16; |
---|
451 | if (sfx_volume>127) sfx_volume=127; |
---|
452 | draw_sfx_vol(); |
---|
453 | } |
---|
454 | } break; |
---|
455 | case ID_SFX_DOWN : |
---|
456 | { if (volume_window) |
---|
457 | { |
---|
458 | sfx_volume-=16; |
---|
459 | if (sfx_volume<0) sfx_volume=0; |
---|
460 | draw_sfx_vol(); |
---|
461 | } |
---|
462 | } break; |
---|
463 | |
---|
464 | case ID_MUSIC_UP : |
---|
465 | { if (volume_window) |
---|
466 | { |
---|
467 | music_volume+=16; |
---|
468 | if (music_volume>127) music_volume=127; |
---|
469 | draw_music_vol(); |
---|
470 | } |
---|
471 | } break; |
---|
472 | case ID_MUSIC_DOWN : |
---|
473 | { if (volume_window) |
---|
474 | { |
---|
475 | music_volume-=16; |
---|
476 | if (music_volume<0) music_volume=0; |
---|
477 | draw_music_vol(); |
---|
478 | } |
---|
479 | } break; |
---|
480 | case ID_MEDIUM : |
---|
481 | { |
---|
482 | set_symbol_value(l_difficulty,l_medium); |
---|
483 | save_difficulty(); |
---|
484 | } break; |
---|
485 | case ID_HARD : |
---|
486 | { |
---|
487 | set_symbol_value(l_difficulty,l_hard); |
---|
488 | save_difficulty(); |
---|
489 | } break; |
---|
490 | case ID_EXTREME : |
---|
491 | { |
---|
492 | set_symbol_value(l_difficulty,l_extreme); |
---|
493 | save_difficulty(); |
---|
494 | } break; |
---|
495 | case ID_EASY : |
---|
496 | { |
---|
497 | set_symbol_value(l_difficulty,l_easy); |
---|
498 | save_difficulty(); |
---|
499 | } break; |
---|
500 | |
---|
501 | |
---|
502 | } break; |
---|
503 | } break; |
---|
504 | case EV_CLOSE_WINDOW : |
---|
505 | { |
---|
506 | if (ev.window==volume_window) |
---|
507 | { eh->close_window(volume_window); volume_window=NULL; } |
---|
508 | } break; |
---|
509 | } |
---|
510 | } |
---|
511 | |
---|
512 | void *current_demo=NULL; |
---|
513 | |
---|
514 | void main_menu() |
---|
515 | { |
---|
516 | image *Earth=cash.img(earth); |
---|
517 | image *Emap=cash.img(earth_mask); |
---|
518 | |
---|
519 | char name[20]; |
---|
520 | ico_button *buts[MENU_TICONS]; |
---|
521 | |
---|
522 | int32_t maxx=0,maxy=0; |
---|
523 | int i=0; |
---|
524 | for (;i<MENU_TICONS;i++) |
---|
525 | { |
---|
526 | sprintf(name,"icon%04d.pcx",i*3+1); |
---|
527 | menu_icons[i*3]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
528 | sprintf(name,"icon%04d.pcx",i*3+2); |
---|
529 | menu_icons[i*3+1]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
530 | sprintf(name,"icon%04d.pcx",i*3+2); |
---|
531 | menu_icons[i*3+2]=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
532 | |
---|
533 | int32_t x=WINDOW_FRAME_LEFT+(i%9)*cash.img(menu_icons[0])->width(); |
---|
534 | int32_t y=WINDOW_FRAME_TOP+(i/9)*cash.img(menu_icons[0])->height(); |
---|
535 | if (x>maxx) maxx=x; |
---|
536 | if (y>maxy) maxy=y; |
---|
537 | buts[i]=new ico_button(x,y,menu_icons_ids[i], |
---|
538 | menu_icons[i*3],menu_icons[i*3], |
---|
539 | menu_icons[i*3+1],menu_icons[i*3+2],NULL); |
---|
540 | } |
---|
541 | |
---|
542 | buts[0]->next=buts[1]; |
---|
543 | |
---|
544 | int b1,b2,b3,b4; |
---|
545 | |
---|
546 | if (DEFINEDP(symbol_value)) |
---|
547 | { |
---|
548 | if (symbol_value(l_difficulty)==l_extreme) |
---|
549 | { b1=18; b2=10; b3=12; b4=14; } |
---|
550 | else if (symbol_value(l_difficulty)==l_hard) |
---|
551 | { b1=14; b2=18; b3=10; b4=12; } |
---|
552 | else if (symbol_value(l_difficulty)==l_easy) |
---|
553 | { b1=10; b2=12; b3=14; b4=18; } |
---|
554 | else |
---|
555 | { b1=12; b2=14; b3=18; b4=10; } |
---|
556 | } else |
---|
557 | { b1=12; b2=14; b3=18; b4=10; } |
---|
558 | |
---|
559 | |
---|
560 | buts[b1]->next=buts[b2]; |
---|
561 | buts[b2]->next=buts[b3]; |
---|
562 | buts[b3]->next=buts[b4]; |
---|
563 | |
---|
564 | |
---|
565 | buts[1]->next=new ico_switch_button(buts[0]->X(), |
---|
566 | buts[0]->Y()+cash.img(menu_icons[0])->height()*2, |
---|
567 | ID_NULL, |
---|
568 | buts[b1],buts[17]); |
---|
569 | |
---|
570 | |
---|
571 | |
---|
572 | |
---|
573 | buts[17]->next=buts[8]; |
---|
574 | |
---|
575 | buts[1]->set_xy(buts[0]->X(), |
---|
576 | buts[0]->Y()+cash.img(menu_icons[0])->height()*1); |
---|
577 | buts[12]->set_xy(buts[0]->X(), |
---|
578 | buts[0]->Y()+cash.img(menu_icons[0])->height()*2); |
---|
579 | buts[17]->set_xy(buts[0]->X(), |
---|
580 | buts[0]->Y()+cash.img(menu_icons[0])->height()*3); |
---|
581 | buts[8]->set_xy(buts[0]->X(), |
---|
582 | buts[0]->Y()+cash.img(menu_icons[0])->height()*4); |
---|
583 | |
---|
584 | |
---|
585 | |
---|
586 | ico_win=eh->new_window(-1,yres/2-80,-1,-1,buts[0],"Menu"); |
---|
587 | |
---|
588 | |
---|
589 | // pmenu *main_pm=new pmenu(0,0,game_sub,screen,eh); |
---|
590 | time_marker old_time; |
---|
591 | |
---|
592 | screen->add_dirty(0,0,319,199); |
---|
593 | |
---|
594 | |
---|
595 | // create sphere map |
---|
596 | mask_line *p=make_mask_lines(Emap,Earth->width()); |
---|
597 | |
---|
598 | int eoff=0,coff=0; |
---|
599 | event ev; |
---|
600 | // main_pm->draw(screen,eh,1); |
---|
601 | int32_t x=84,y=60; |
---|
602 | Cell *v=find_symbol("earth_x"); |
---|
603 | if (v && DEFINEDP(v)) x=lnumber_value(symbol_value(v)); |
---|
604 | |
---|
605 | v=find_symbol("earth_y"); |
---|
606 | if (v && DEFINEDP(v)) y=lnumber_value(symbol_value(v)); |
---|
607 | int state=0,stop_menu=0; |
---|
608 | time_marker start; |
---|
609 | do |
---|
610 | { |
---|
611 | time_marker new_time; |
---|
612 | if (state || new_time.diff_time(&old_time)>0.15) |
---|
613 | { |
---|
614 | old_time.get_time(); |
---|
615 | scan_map(screen,x,y,Earth,NULL,p,Emap->height(),eoff,coff); |
---|
616 | if (state) |
---|
617 | { eoff+=8; coff+=4; } |
---|
618 | else |
---|
619 | { |
---|
620 | eoff+=2; coff+=1; |
---|
621 | } |
---|
622 | |
---|
623 | if (eoff>=320) eoff-=320; |
---|
624 | if (coff>=320) coff-=320; |
---|
625 | eh->flush_screen(); |
---|
626 | } |
---|
627 | |
---|
628 | if (eh->event_waiting()) |
---|
629 | { |
---|
630 | eh->get_event(ev); |
---|
631 | start.get_time(); // reset time till demo starts up |
---|
632 | |
---|
633 | menu_handler(ev,ico_win); |
---|
634 | if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button && ev.mouse_move.x>=x && ev.mouse_move.y>=y && |
---|
635 | ev.mouse_move.x<=x+Emap->width() && ev.mouse_move.y<=y+Emap->height()) |
---|
636 | { |
---|
637 | state=1; |
---|
638 | } else if (ev.type==EV_MOUSE_BUTTON && !ev.mouse_button) state=0; |
---|
639 | |
---|
640 | |
---|
641 | |
---|
642 | eh->flush_screen(); |
---|
643 | } |
---|
644 | |
---|
645 | if (new_time.diff_time(&start)>10) |
---|
646 | { |
---|
647 | if (!current_demo) |
---|
648 | { |
---|
649 | void *d=make_find_symbol("demos"); |
---|
650 | if (DEFINEDP(d)) |
---|
651 | current_demo=symbol_value(d); |
---|
652 | } |
---|
653 | if (current_demo) |
---|
654 | { |
---|
655 | if (set_demo_mode(DEMO_PLAY,lstring_value(CAR(current_demo)),eh)) |
---|
656 | stop_menu=1; |
---|
657 | current_demo=CDR(current_demo); |
---|
658 | } |
---|
659 | } |
---|
660 | |
---|
661 | } while (!stop_menu && |
---|
662 | (ev.type!=EV_MESSAGE || (ev.message.id!=ID_START_GAME && ev.message.id!=ID_QUIT))); |
---|
663 | |
---|
664 | for (i=0;i<MENU_TICONS;i++) |
---|
665 | { |
---|
666 | ifield *ic=ico_win->inm->unlink(menu_icons_ids[i]); |
---|
667 | if (i) delete ic; |
---|
668 | else delete buts[i]; |
---|
669 | } |
---|
670 | |
---|
671 | eh->close_window(ico_win); |
---|
672 | for (int xx=0;xx<Emap->height();xx++) |
---|
673 | jfree(p[xx].remap); |
---|
674 | jfree(p); |
---|
675 | |
---|
676 | if (ev.message.id==ID_QUIT) // propogate the quit message |
---|
677 | the_game->end_session(); |
---|
678 | |
---|
679 | // delete main_pm; |
---|
680 | } |
---|
681 | |
---|
682 | |
---|
683 | |
---|
684 | |
---|
685 | |
---|
686 | /* pmenu_item *net_sub=new pmenu_item("Multiplayer", |
---|
687 | new psub_menu( |
---|
688 | new pmenu_item(ID_MODEM, "Modem",-1, |
---|
689 | new pmenu_item(ID_TCPIP, "TCP/IP (internet)",-1, |
---|
690 | new pmenu_item(ID_IPX, "IPX",-1, |
---|
691 | new pmenu_item(ID_SPLIT_SCREEN, "Split screen",-1, |
---|
692 | NULL)))),NULL),NULL,200); |
---|
693 | |
---|
694 | |
---|
695 | pmenu_item *graphics_sub=new pmenu_item("Options", |
---|
696 | new psub_menu( |
---|
697 | new pmenu_item(ID_KEY_SETUP, "Keyboard",-1, |
---|
698 | new pmenu_item(ID_MOUSE_SETUP, "Mouse",-1, |
---|
699 | new pmenu_item(CALB_JOY, "Joystick",-1, |
---|
700 | new pmenu_item(0, NULL, -1, |
---|
701 | new pmenu_item(ID_LIGHT_DETAIL, "Lighting detail",-1, |
---|
702 | new pmenu_item(ID_SCREEN_SIZE, "Screen Size",-1, |
---|
703 | new pmenu_item(ID_VOLUME, "Volume",-1, |
---|
704 | new pmenu_item(ID_SFX_CHANNELS, "Sfx Channels",-1, |
---|
705 | NULL)))))))),NULL),net_sub,100); |
---|
706 | |
---|
707 | |
---|
708 | pmenu_item *game_sub=new pmenu_item("Game", |
---|
709 | new psub_menu( |
---|
710 | new pmenu_item(ID_NEW_GAME, "New Game",-1, |
---|
711 | new pmenu_item(ID_DIFFICULTY,"Difficulty",-1, |
---|
712 | new pmenu_item(ID_LOAD_GAME, "Load Game",-1, |
---|
713 | new pmenu_item(ID_QUIT, "Quit",-1,NULL)))),NULL),graphics_sub,27); |
---|
714 | */ |
---|