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