1 | #include "menu.hpp" |
---|
2 | #include "lisp.hpp" |
---|
3 | #include "game.hpp" |
---|
4 | #include "timing.hpp" |
---|
5 | #include "game.hpp" |
---|
6 | #include "id.hpp" |
---|
7 | #include "pmenu.hpp" |
---|
8 | #include "gui.hpp" |
---|
9 | #include "property.hpp" |
---|
10 | #include "dev.hpp" |
---|
11 | #include "clisp.hpp" |
---|
12 | #include "gamma.hpp" |
---|
13 | #include "dprint.hpp" |
---|
14 | #include "demo.hpp" |
---|
15 | #include "loadgame.hpp" |
---|
16 | #include "scroller.hpp" |
---|
17 | #include "netcfg.hpp" |
---|
18 | #include <math.h> |
---|
19 | #include "sock.hpp" |
---|
20 | |
---|
21 | extern net_protocol *prot; |
---|
22 | jwindow *volume_window=NULL; |
---|
23 | extern int confirm_quit(); |
---|
24 | extern int registered; |
---|
25 | |
---|
26 | //percent is 0..256 |
---|
27 | void tint_area(int x1, int y1, int x2, int y2, int r_to, int g_to, int b_to, int percent) |
---|
28 | { |
---|
29 | int x,y; |
---|
30 | short cx1,cy1,cx2,cy2; |
---|
31 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
32 | if (x1<cx1) x1=cx1; |
---|
33 | if (y1<cy1) y1=cy1; |
---|
34 | if (x2>cx2) x2=cx2; |
---|
35 | if (y2>cy2) y2=cy2; |
---|
36 | if (x2<x1 || y2<y1) return ; |
---|
37 | |
---|
38 | percent=256-percent; |
---|
39 | |
---|
40 | for (y=y1;y<=y2;y++) |
---|
41 | { |
---|
42 | unsigned char *sl=screen->scan_line(y)+x1; |
---|
43 | for (x=x1;x<=x2;x++,sl++) |
---|
44 | { |
---|
45 | unsigned char *paddr=(unsigned char *)pal->addr()+(*sl)*3; |
---|
46 | unsigned char r=((*(paddr++))-r_to)*percent/256+r_to; |
---|
47 | unsigned char g=((*(paddr++))-g_to)*percent/256+g_to; |
---|
48 | unsigned char b=((*(paddr++))-b_to)*percent/256+b_to; |
---|
49 | *sl=color_table->lookup_color((r)>>3,(g)>>3,(b)>>3); |
---|
50 | } |
---|
51 | } |
---|
52 | screen->add_dirty(x1,y1,x2,y2); |
---|
53 | } |
---|
54 | |
---|
55 | void darken_area(int x1, int y1, int x2, int y2, int amount) |
---|
56 | { |
---|
57 | int x,y; |
---|
58 | short cx1,cy1,cx2,cy2; |
---|
59 | screen->get_clip(cx1,cy1,cx2,cy2); |
---|
60 | if (x1<cx1) x1=cx1; |
---|
61 | if (y1<cy1) y1=cy1; |
---|
62 | if (x2>cx2) x2=cx2; |
---|
63 | if (y2>cy2) y2=cy2; |
---|
64 | if (x2<x1 || y2<y1) return ; |
---|
65 | |
---|
66 | for (y=y1;y<=y2;y++) |
---|
67 | { |
---|
68 | unsigned char *sl=screen->scan_line(y)+x1; |
---|
69 | for (x=x1;x<=x2;x++,sl++) |
---|
70 | { |
---|
71 | unsigned char *paddr=(unsigned char *)pal->addr()+(*sl)*3; |
---|
72 | unsigned char r=(*(paddr++))*amount/256; |
---|
73 | unsigned char g=(*(paddr++))*amount/256; |
---|
74 | unsigned char b=(*(paddr++))*amount/256; |
---|
75 | *sl=color_table->lookup_color((r)>>3,(g)>>3,(b)>>3); |
---|
76 | } |
---|
77 | } |
---|
78 | screen->add_dirty(x1,y1,x2,y2); |
---|
79 | } |
---|
80 | |
---|
81 | void dark_wiget(int x1, int y1, int x2, int y2, int br, int dr, int amount) |
---|
82 | { |
---|
83 | screen->add_dirty(x1,y1,x2,y2); |
---|
84 | screen->line(x1,y1,x1,y2,br); |
---|
85 | screen->line(x1+1,y1,x2,y1,br); |
---|
86 | screen->line(x2,y1+1,x2,y2,dr); |
---|
87 | screen->line(x1+1,y2,x2,y2,dr); |
---|
88 | darken_area(x1+1,y1+1,x2-1,y2-1,amount); |
---|
89 | } |
---|
90 | |
---|
91 | char *men_str(void *arg) |
---|
92 | { |
---|
93 | switch (item_type(arg)) |
---|
94 | { |
---|
95 | case L_STRING : |
---|
96 | { return lstring_value(arg); } break; |
---|
97 | case L_CONS_CELL : |
---|
98 | { return lstring_value(CAR(arg)); } break; |
---|
99 | default : |
---|
100 | { |
---|
101 | lprint(arg); |
---|
102 | printf(" is not a valid menu option\n"); |
---|
103 | exit(0); |
---|
104 | } |
---|
105 | } |
---|
106 | return NULL; |
---|
107 | } |
---|
108 | |
---|
109 | void main_menu(); |
---|
110 | |
---|
111 | int menu(void *args, JCFont *font) // reurns -1 on esc |
---|
112 | { |
---|
113 | main_menu(); |
---|
114 | char *title=NULL; |
---|
115 | if (!NILP(CAR(args))) |
---|
116 | title=lstring_value(CAR(args)); |
---|
117 | Cell *def=lcar(lcdr(lcdr(args))); |
---|
118 | args=CAR(CDR(args)); |
---|
119 | |
---|
120 | int options=list_length(args); |
---|
121 | int mh=(font->height()+1)*options+10,maxw=0; |
---|
122 | |
---|
123 | Cell *c=(Cell *)args; |
---|
124 | for (;!NILP(c);c=CDR(c)) |
---|
125 | { |
---|
126 | if( strlen(men_str(CAR(c))) > (unsigned)maxw) |
---|
127 | maxw = strlen(men_str(CAR(c))); |
---|
128 | } |
---|
129 | |
---|
130 | int mw=(font->width())*maxw+20; |
---|
131 | int mx=screen->width()/2-mw/2, |
---|
132 | my=screen->height()/2-mh/2; |
---|
133 | |
---|
134 | |
---|
135 | screen->add_dirty(mx,my,mx+mw-1,my+mh-1); |
---|
136 | |
---|
137 | if (title) |
---|
138 | { |
---|
139 | int tl=strlen(title)*font->width(); |
---|
140 | int tx=screen->width()/2-tl/2; |
---|
141 | dark_wiget(tx-2,my-font->height()-4,tx+tl+2,my-2,eh->medium_color(),eh->dark_color(),180); |
---|
142 | font->put_string(screen,tx+1,my-font->height()-2,title,eh->bright_color()); |
---|
143 | } |
---|
144 | |
---|
145 | dark_wiget(mx,my,mx+mw-1,my+mh-1,eh->medium_color(),eh->dark_color(),200); |
---|
146 | |
---|
147 | |
---|
148 | int y=my+5; |
---|
149 | for (c=(Cell *)args;!NILP(c);c=CDR(c)) |
---|
150 | { |
---|
151 | char *ms=men_str(CAR(c)); |
---|
152 | font->put_string(screen,mx+10+1,y+1,ms,eh->black()); |
---|
153 | font->put_string(screen,mx+10,y,ms,eh->bright_color()); |
---|
154 | y+=font->height()+1; |
---|
155 | } |
---|
156 | |
---|
157 | eh->flush_screen(); |
---|
158 | event ev; |
---|
159 | int choice=0,done=0; |
---|
160 | int bh=font->height()+3; |
---|
161 | image *save=new image(mw-2,bh); |
---|
162 | int color=128,cdir=50; |
---|
163 | |
---|
164 | time_marker *last_color_time=NULL; |
---|
165 | if (!NILP(def)) |
---|
166 | choice=lnumber_value(def); |
---|
167 | do |
---|
168 | { |
---|
169 | eh->flush_screen(); |
---|
170 | if (eh->event_waiting()) |
---|
171 | { |
---|
172 | eh->get_event(ev); |
---|
173 | if (ev.type==EV_KEY) |
---|
174 | { |
---|
175 | switch (ev.key) |
---|
176 | { |
---|
177 | case JK_ESC : |
---|
178 | { choice=-1; done=1; } break; |
---|
179 | case JK_ENTER : |
---|
180 | { done=1; } break; |
---|
181 | case JK_DOWN : |
---|
182 | { if (choice<options-1) |
---|
183 | choice++; |
---|
184 | else choice=0; |
---|
185 | } break; |
---|
186 | case JK_UP : |
---|
187 | { |
---|
188 | if (choice>0) |
---|
189 | choice--; |
---|
190 | else choice=options-1; |
---|
191 | } break; |
---|
192 | } |
---|
193 | } else if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button) |
---|
194 | { |
---|
195 | if (ev.mouse_move.x>mx && ev.mouse_move.x<mx+mw && ev.mouse_move.y>my && |
---|
196 | ev.mouse_move.y<my+mh) |
---|
197 | { |
---|
198 | int msel=(ev.mouse_move.y-my)/(font->height()+1); |
---|
199 | if (msel>=options) msel=options-1; |
---|
200 | if (msel==choice) // clicked on already selected item, return it |
---|
201 | done=1; |
---|
202 | else choice=msel; // selects an item |
---|
203 | } |
---|
204 | } |
---|
205 | } |
---|
206 | |
---|
207 | time_marker cur_time; |
---|
208 | if (!last_color_time || (int)(cur_time.diff_time(last_color_time)*1000)>120) |
---|
209 | { |
---|
210 | if (last_color_time) |
---|
211 | delete last_color_time; |
---|
212 | last_color_time=new time_marker; |
---|
213 | |
---|
214 | int by1=(font->height()+1)*choice+my+5-2; |
---|
215 | int by2=by1+bh-1; |
---|
216 | |
---|
217 | screen->put_part(save,0,0,mx+1,by1,mx+mw-2,by2); |
---|
218 | tint_area(mx+1,by1,mx+mw-2,by2,63,63,63,color); |
---|
219 | |
---|
220 | char *cur=men_str(nth(choice,args)); |
---|
221 | font->put_string(screen,mx+10+1,by1+3,cur,eh->black()); |
---|
222 | font->put_string(screen,mx+10,by1+2,cur,eh->bright_color()); |
---|
223 | screen->rectangle(mx+1,by1,mx+mw-2,by2,eh->bright_color()); |
---|
224 | |
---|
225 | color+=cdir; |
---|
226 | |
---|
227 | if (color<12 || color>256) |
---|
228 | { |
---|
229 | cdir=-cdir; |
---|
230 | color+=cdir; |
---|
231 | } |
---|
232 | eh->flush_screen(); |
---|
233 | save->put_image(screen,mx+1,by1); |
---|
234 | } else milli_wait(10); |
---|
235 | |
---|
236 | } while (!done); |
---|
237 | if (last_color_time) |
---|
238 | delete last_color_time; |
---|
239 | delete save; |
---|
240 | the_game->draw(the_game->state==SCENE_STATE); |
---|
241 | |
---|
242 | if (choice!=-1) |
---|
243 | { |
---|
244 | void *val=nth(choice,args); |
---|
245 | if (item_type(val)==L_CONS_CELL) // is there another value that the user want us to return? |
---|
246 | return lnumber_value(lcdr(val)); |
---|
247 | } |
---|
248 | return choice; |
---|
249 | } |
---|
250 | |
---|
251 | |
---|
252 | static void draw_vol(image *screen, int x1, int y1, int x2, int y2, int t, int max, int c1, int c2, int slider) |
---|
253 | { |
---|
254 | int dx=x1+t*(x2-x1)/max; |
---|
255 | if (t!=0) |
---|
256 | { |
---|
257 | cash.img(slider)->put_image(screen,x1,y1); |
---|
258 | // screen->bar(x1,y1,dx,y2,c1); |
---|
259 | } |
---|
260 | else dx--; |
---|
261 | |
---|
262 | if (dx<x2) |
---|
263 | screen->bar(dx+1,y1,x2,y2,c2); |
---|
264 | } |
---|
265 | |
---|
266 | static void draw_sfx_vol(int slider) |
---|
267 | { |
---|
268 | draw_vol(volume_window->screen,6,16,34,22,sfx_volume,127,pal->find_closest(200,75,19), |
---|
269 | pal->find_closest(40,0,0),slider); |
---|
270 | } |
---|
271 | |
---|
272 | static void draw_music_vol(int slider) |
---|
273 | { |
---|
274 | draw_vol(volume_window->screen,6,61,34,67,music_volume,127,pal->find_closest(255,0,0), |
---|
275 | pal->find_closest(40,0,0),slider); |
---|
276 | } |
---|
277 | |
---|
278 | static void create_volume_window() |
---|
279 | { |
---|
280 | /* int vx=WINDOW_FRAME_LEFT,vy=WINDOW_FRAME_TOP+eh->font()->height()*2,scroller_height=130,bh=eh->font()->height()+5; |
---|
281 | |
---|
282 | volume_window=eh->new_window(prop->getd("volume_x",xres/2-20), |
---|
283 | prop->getd("volume_y",yres/2-50), |
---|
284 | -1, |
---|
285 | -1, |
---|
286 | new scroller(vx,vy,LOWER_SFX,0,scroller_height,0,127, |
---|
287 | new scroller(vx+30,vy,LOWER_MUSIC,0,scroller_height,0,127,NULL)),symbol_str("VOLUME")); |
---|
288 | event ev; |
---|
289 | int done=0; |
---|
290 | do |
---|
291 | { |
---|
292 | eh->flush_screen(); |
---|
293 | eh->get_event(ev); |
---|
294 | if (ev.type==EV_CLOSE_WINDOW && ev.window==volume_window) done=1; |
---|
295 | } while (!done); |
---|
296 | eh->close_window(volume_window); |
---|
297 | volume_window=NULL; */ |
---|
298 | |
---|
299 | |
---|
300 | char *ff="art/frame.spe"; |
---|
301 | int t=SPEC_IMAGE; |
---|
302 | int u_u=cash.reg(ff,"u_u",t,1), |
---|
303 | u_d=cash.reg(ff,"u_u",t,1), |
---|
304 | u_ua=cash.reg(ff,"u_ua",t,1), |
---|
305 | u_da=cash.reg(ff,"u_da",t,1), |
---|
306 | |
---|
307 | d_u=cash.reg(ff,"d_u",t,1), |
---|
308 | d_d=cash.reg(ff,"d_u",t,1), |
---|
309 | d_ua=cash.reg(ff,"d_ua",t,1), |
---|
310 | d_da=cash.reg(ff,"d_da",t,1), |
---|
311 | slider=cash.reg(ff,"volume_slide",t,1); |
---|
312 | |
---|
313 | volume_window=eh->new_window(prop->getd("volume_x",xres/2-20), |
---|
314 | prop->getd("volume_y",yres/2-50), |
---|
315 | 41-WINDOW_FRAME_LEFT-WINDOW_FRAME_RIGHT-2, |
---|
316 | 101-WINDOW_FRAME_TOP-WINDOW_FRAME_BOTTOM, |
---|
317 | new ico_button(10,27,ID_SFX_DOWN,d_u,d_d,d_ua,d_da, |
---|
318 | new ico_button(21,27,ID_SFX_UP,u_u,u_d,u_ua,u_da, |
---|
319 | new info_field(15,42,0,symbol_str("SFXv"), |
---|
320 | |
---|
321 | new ico_button(10,72,ID_MUSIC_DOWN,d_u,d_d,d_ua,d_da, |
---|
322 | new ico_button(21,72,ID_MUSIC_UP,u_u,u_d,u_ua,u_da, |
---|
323 | new info_field(10,86,0,symbol_str("MUSICv"), |
---|
324 | NULL))))))); |
---|
325 | |
---|
326 | cash.img(cash.reg(ff,"vcontrol",t,1))->put_image(volume_window->screen,0,0); |
---|
327 | draw_music_vol(slider); |
---|
328 | draw_sfx_vol(slider); |
---|
329 | volume_window->inm->redraw(); |
---|
330 | eh->grab_focus(volume_window); |
---|
331 | eh->flush_screen(); |
---|
332 | |
---|
333 | volume_window->inm->allow_no_selections(); |
---|
334 | volume_window->inm->clear_current(); |
---|
335 | |
---|
336 | event ev; |
---|
337 | do |
---|
338 | { |
---|
339 | do { eh->get_event(ev); } while (ev.type==EV_MOUSE_MOVE && eh->event_waiting()); |
---|
340 | eh->flush_screen(); |
---|
341 | if (ev.type==EV_MESSAGE) |
---|
342 | { |
---|
343 | switch (ev.message.id) |
---|
344 | { |
---|
345 | case ID_SFX_UP : |
---|
346 | { if (volume_window) |
---|
347 | { |
---|
348 | sfx_volume+=16; |
---|
349 | if (sfx_volume>127) sfx_volume=127; |
---|
350 | draw_sfx_vol(slider); |
---|
351 | char *s="sfx/ambtech1.wav"; |
---|
352 | if (sound_avail&SFX_INITIALIZED) |
---|
353 | cash.sfx(cash.reg(s,s,SPEC_EXTERN_SFX,1))->play(sfx_volume); |
---|
354 | } |
---|
355 | } break; |
---|
356 | case ID_SFX_DOWN : |
---|
357 | { if (volume_window) |
---|
358 | { |
---|
359 | sfx_volume-=16; |
---|
360 | if (sfx_volume<0) sfx_volume=0; |
---|
361 | draw_sfx_vol(slider); |
---|
362 | char *s="sfx/ambtech1.wav"; |
---|
363 | if (sound_avail&SFX_INITIALIZED) |
---|
364 | cash.sfx(cash.reg(s,s,SPEC_EXTERN_SFX,1))->play(sfx_volume); |
---|
365 | } |
---|
366 | } break; |
---|
367 | |
---|
368 | case ID_MUSIC_UP : |
---|
369 | { if (volume_window) |
---|
370 | { |
---|
371 | music_volume+=16; |
---|
372 | if (music_volume>127) music_volume=127; |
---|
373 | draw_music_vol(slider); |
---|
374 | if (current_song) current_song->set_volume(music_volume); |
---|
375 | } |
---|
376 | } break; |
---|
377 | case ID_MUSIC_DOWN : |
---|
378 | { if (volume_window) |
---|
379 | { |
---|
380 | music_volume-=16; |
---|
381 | if (music_volume<0) music_volume=0; |
---|
382 | draw_music_vol(slider); |
---|
383 | if (current_song) current_song->set_volume(music_volume); |
---|
384 | } |
---|
385 | } break; |
---|
386 | } |
---|
387 | } else if (ev.type==EV_CLOSE_WINDOW || (ev.type==EV_KEY && ev.key==JK_ESC)) |
---|
388 | { |
---|
389 | eh->close_window(volume_window); |
---|
390 | volume_window=NULL; |
---|
391 | } |
---|
392 | } while (volume_window); |
---|
393 | } |
---|
394 | |
---|
395 | |
---|
396 | FILE *open_FILE(char *filename, char *mode); |
---|
397 | |
---|
398 | void save_difficulty() |
---|
399 | { |
---|
400 | FILE *fp=open_FILE("hardness.lsp","wb"); |
---|
401 | if (!fp) |
---|
402 | dprintf("Unable to write to file hardness.lsp\n"); |
---|
403 | else |
---|
404 | { |
---|
405 | fprintf(fp,"(setf difficulty '"); |
---|
406 | if (DEFINEDP(symbol_value(l_difficulty))) |
---|
407 | { |
---|
408 | if (symbol_value(l_difficulty)==l_extreme) |
---|
409 | fprintf(fp,"extreme)\n"); |
---|
410 | else if (symbol_value(l_difficulty)==l_hard) |
---|
411 | fprintf(fp,"hard)\n"); |
---|
412 | else if (symbol_value(l_difficulty)==l_easy) |
---|
413 | fprintf(fp,"easy)\n"); |
---|
414 | else |
---|
415 | fprintf(fp,"medium)\n"); |
---|
416 | } else |
---|
417 | fprintf(fp,"medium)\n"); |
---|
418 | fclose(fp); |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | void fade_out(int steps); |
---|
423 | void fade_in(image *im, int steps); |
---|
424 | |
---|
425 | |
---|
426 | void show_sell(int abortable) |
---|
427 | { |
---|
428 | void *ss=make_find_symbol("sell_screens"); |
---|
429 | if (!DEFINEDP(symbol_value(ss))) |
---|
430 | { |
---|
431 | int sp=current_space; |
---|
432 | current_space=PERM_SPACE; |
---|
433 | // char *prog="((\"art/help.spe\" . \"sell2\")(\"art/help.spe\" . \"sell4\")(\"art/help.spe\" . \"sell3\")(\"art/endgame.spe\" . \"credit\"))"; |
---|
434 | // char *prog="((\"art/endgame.spe\" . \"credit\") (\"art/help.spe\" . \"sell6\"))"; |
---|
435 | char *prog="((\"art/endgame.spe\" . \"credit\"))"; |
---|
436 | set_symbol_value(ss,compile(prog)); |
---|
437 | current_space=sp; |
---|
438 | } |
---|
439 | |
---|
440 | if (DEFINEDP(symbol_value(ss))) |
---|
441 | { |
---|
442 | image blank(2,2); blank.clear(); |
---|
443 | eh->set_mouse_shape(blank.copy(),0,0); // don't show mouse |
---|
444 | |
---|
445 | ss=symbol_value(ss); |
---|
446 | int quit=0; |
---|
447 | while (ss && !quit) |
---|
448 | { |
---|
449 | int im=cash.reg_object("art/help.spe",CAR(ss),SPEC_IMAGE,1); |
---|
450 | fade_in(cash.img(im),16); |
---|
451 | |
---|
452 | event ev; |
---|
453 | do |
---|
454 | { eh->flush_screen(); |
---|
455 | eh->get_event(ev); |
---|
456 | } while (ev.type!=EV_KEY); |
---|
457 | if (ev.key==JK_ESC && abortable) |
---|
458 | quit=1; |
---|
459 | fade_out(16); |
---|
460 | ss=CDR(ss); |
---|
461 | } |
---|
462 | eh->set_mouse_shape(cash.img(c_normal)->copy(),1,1); |
---|
463 | } |
---|
464 | } |
---|
465 | |
---|
466 | |
---|
467 | void menu_handler(event &ev, input_manager *inm) |
---|
468 | { |
---|
469 | switch (ev.type) |
---|
470 | { |
---|
471 | case EV_MESSAGE : |
---|
472 | { |
---|
473 | switch (ev.message.id) |
---|
474 | { |
---|
475 | case ID_LIGHT_OFF : |
---|
476 | if (!volume_window) |
---|
477 | { |
---|
478 | gamma_correct(pal,1); |
---|
479 | } break; |
---|
480 | case ID_RETURN : |
---|
481 | if (!volume_window) |
---|
482 | { |
---|
483 | the_game->set_state(RUN_STATE); |
---|
484 | } break; |
---|
485 | case ID_START_GAME : |
---|
486 | if (!volume_window) |
---|
487 | { |
---|
488 | the_game->load_level(level_file); |
---|
489 | the_game->set_state(RUN_STATE); |
---|
490 | view *v; |
---|
491 | for (v=player_list;v;v=v->next) |
---|
492 | if (v->focus) |
---|
493 | v->reset_player(); |
---|
494 | |
---|
495 | } break; |
---|
496 | |
---|
497 | |
---|
498 | case ID_LOAD_PLAYER_GAME : |
---|
499 | if (!volume_window) |
---|
500 | { |
---|
501 | int got_level=load_game(0,symbol_str("LOAD")); |
---|
502 | the_game->reset_keymap(); |
---|
503 | if (got_level) |
---|
504 | { |
---|
505 | char name[255]; |
---|
506 | sprintf(name,"%ssave%04d.spe", get_save_filename_prefix(), got_level); |
---|
507 | |
---|
508 | the_game->load_level(name); |
---|
509 | the_game->set_state(RUN_STATE); |
---|
510 | } |
---|
511 | } break; |
---|
512 | |
---|
513 | |
---|
514 | case ID_VOLUME : |
---|
515 | if (!volume_window) |
---|
516 | { create_volume_window(); } break; |
---|
517 | |
---|
518 | case ID_MEDIUM : |
---|
519 | { |
---|
520 | set_symbol_value(l_difficulty,l_medium); |
---|
521 | save_difficulty(); |
---|
522 | } break; |
---|
523 | case ID_HARD : |
---|
524 | { |
---|
525 | set_symbol_value(l_difficulty,l_hard); |
---|
526 | save_difficulty(); |
---|
527 | } break; |
---|
528 | case ID_EXTREME : |
---|
529 | { |
---|
530 | set_symbol_value(l_difficulty,l_extreme); |
---|
531 | save_difficulty(); |
---|
532 | } break; |
---|
533 | case ID_EASY : |
---|
534 | { |
---|
535 | set_symbol_value(l_difficulty,l_easy); |
---|
536 | save_difficulty(); |
---|
537 | } break; |
---|
538 | |
---|
539 | case ID_NETWORKING : |
---|
540 | { |
---|
541 | if (!volume_window) |
---|
542 | { |
---|
543 | net_configuration *cfg=new net_configuration; |
---|
544 | if (cfg->input()) |
---|
545 | { |
---|
546 | if (main_net_cfg) delete main_net_cfg; |
---|
547 | main_net_cfg=cfg; |
---|
548 | } else delete cfg; |
---|
549 | the_game->draw(0); |
---|
550 | inm->redraw(); |
---|
551 | } |
---|
552 | } break; |
---|
553 | |
---|
554 | case ID_SHOW_SELL : |
---|
555 | if (!volume_window) |
---|
556 | { |
---|
557 | show_sell(1); |
---|
558 | screen->clear(); |
---|
559 | if (title_screen>=0) |
---|
560 | { |
---|
561 | image *tit=cash.img(title_screen); |
---|
562 | tit->put_image(screen,screen->width()/2-tit->width()/2, |
---|
563 | screen->height()/2-tit->height()/2); |
---|
564 | } |
---|
565 | inm->redraw(); |
---|
566 | fade_in(NULL,8); |
---|
567 | eh->flush_screen(); |
---|
568 | |
---|
569 | } break; |
---|
570 | } break; |
---|
571 | } break; |
---|
572 | case EV_CLOSE_WINDOW : |
---|
573 | { |
---|
574 | if (ev.window==volume_window) |
---|
575 | { eh->close_window(volume_window); volume_window=NULL; } |
---|
576 | } break; |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | void *current_demo=NULL; |
---|
581 | |
---|
582 | static ico_button *load_icon(int num, int id, int x, int y, int &h, ifield *next, char *key) |
---|
583 | { |
---|
584 | char name[20]; |
---|
585 | char *base="newi"; |
---|
586 | int a,b,c; |
---|
587 | sprintf(name,"%s%04d.pcx",base,num*3+1); |
---|
588 | a=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
589 | |
---|
590 | sprintf(name,"%s%04d.pcx",base,num*3+2); |
---|
591 | b=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
592 | |
---|
593 | sprintf(name,"%s%04d.pcx",base,num*3+3); |
---|
594 | c=cash.reg("art/icons.spe",name,SPEC_IMAGE,1); |
---|
595 | |
---|
596 | h=cash.img(a)->height(); |
---|
597 | |
---|
598 | return new ico_button(x,y,id,b,b,a,c,next,-1,key); |
---|
599 | } |
---|
600 | |
---|
601 | ico_button *make_default_buttons(int x,int &y, ico_button *append_list) |
---|
602 | { |
---|
603 | int h; |
---|
604 | int diff_on; |
---|
605 | |
---|
606 | if (DEFINEDP(symbol_value(l_difficulty))) |
---|
607 | { |
---|
608 | if (symbol_value(l_difficulty)==l_extreme) |
---|
609 | diff_on=3; |
---|
610 | else if (symbol_value(l_difficulty)==l_hard) |
---|
611 | diff_on=2; |
---|
612 | else if (symbol_value(l_difficulty)==l_easy) |
---|
613 | diff_on=0; |
---|
614 | else |
---|
615 | diff_on=1; |
---|
616 | } else diff_on=3; |
---|
617 | |
---|
618 | |
---|
619 | ico_button *start=load_icon(0,ID_START_GAME,x,y,h,NULL,"ic_start"); y+=h; |
---|
620 | |
---|
621 | ico_switch_button *set=NULL; |
---|
622 | if (!main_net_cfg || (main_net_cfg->state!=net_configuration::SERVER && main_net_cfg->state!=net_configuration::CLIENT)) |
---|
623 | { |
---|
624 | set=new ico_switch_button(x,y,ID_NULL,diff_on, |
---|
625 | load_icon(3,ID_EASY,x,y,h, |
---|
626 | load_icon(8,ID_MEDIUM,x,y,h, |
---|
627 | load_icon(9,ID_HARD,x,y,h, |
---|
628 | load_icon(10,ID_EXTREME,x,y,h,NULL,"ic_extreme"), |
---|
629 | "ic_hard"),"ic_medium"),"ic_easy"),NULL); y+=h; |
---|
630 | |
---|
631 | } |
---|
632 | |
---|
633 | ico_button *color=load_icon(4,ID_LIGHT_OFF,x,y,h,NULL,"ic_gamma"); y+=h; |
---|
634 | ico_button *volume=load_icon(5,ID_VOLUME,x,y,h,NULL,"ic_volume"); y+=h; |
---|
635 | ico_button *sell=NULL; |
---|
636 | |
---|
637 | if (registered && prot) |
---|
638 | { |
---|
639 | sell=load_icon(11,ID_NETWORKING,x,y,h,NULL,"ic_networking"); |
---|
640 | y+=h; |
---|
641 | } else |
---|
642 | { |
---|
643 | sell=load_icon(2,ID_SHOW_SELL,x,y,h,NULL,"ic_sell"); |
---|
644 | y+=h; |
---|
645 | } |
---|
646 | ico_button *quit=load_icon(6,ID_QUIT,x,y,h,NULL,"ic_quit"); y+=h; |
---|
647 | |
---|
648 | if (set) |
---|
649 | { |
---|
650 | start->next=set; |
---|
651 | set->next=color; |
---|
652 | } |
---|
653 | else start->next=color; |
---|
654 | |
---|
655 | |
---|
656 | color->next=volume; |
---|
657 | if (sell) |
---|
658 | { |
---|
659 | volume->next=sell; |
---|
660 | sell->next=quit; |
---|
661 | } else volume->next=quit; |
---|
662 | |
---|
663 | ico_button *list=append_list; |
---|
664 | |
---|
665 | if (append_list) |
---|
666 | { |
---|
667 | while (append_list->next) |
---|
668 | append_list=(ico_button *)append_list->next; |
---|
669 | append_list->next=start; |
---|
670 | } else list=start; |
---|
671 | |
---|
672 | return list; |
---|
673 | } |
---|
674 | |
---|
675 | |
---|
676 | ico_button *make_conditional_buttons(int x,int &y) |
---|
677 | { |
---|
678 | ico_button *start_list=NULL; |
---|
679 | int h; |
---|
680 | if (current_level) // should we include a return icon? |
---|
681 | { |
---|
682 | start_list=load_icon(7,ID_RETURN,x,y,h,NULL,"ic_return"); y+=h; |
---|
683 | } |
---|
684 | |
---|
685 | |
---|
686 | ico_button *load; |
---|
687 | if (show_load_icon()) |
---|
688 | { load= load_icon(1,ID_LOAD_PLAYER_GAME,x,y,h,NULL,"ic_load"); y+=h;} |
---|
689 | else load=NULL; |
---|
690 | |
---|
691 | if (start_list) start_list->next=load; |
---|
692 | else start_list=load; |
---|
693 | |
---|
694 | return start_list; |
---|
695 | } |
---|
696 | |
---|
697 | void main_menu() |
---|
698 | { |
---|
699 | int y=yres/2-100; |
---|
700 | ico_button *list=make_conditional_buttons(xres-33,y); |
---|
701 | list=make_default_buttons(xres-33,y,list); |
---|
702 | |
---|
703 | input_manager *inm=new input_manager(screen,eh,list); |
---|
704 | inm->allow_no_selections(); |
---|
705 | inm->clear_current(); |
---|
706 | |
---|
707 | screen->add_dirty(0,0,319,199); |
---|
708 | |
---|
709 | event ev; |
---|
710 | |
---|
711 | int stop_menu=0; |
---|
712 | time_marker start; |
---|
713 | eh->flush_screen(); |
---|
714 | do |
---|
715 | { |
---|
716 | time_marker new_time; |
---|
717 | |
---|
718 | if (eh->event_waiting()) |
---|
719 | { |
---|
720 | do |
---|
721 | { |
---|
722 | eh->get_event(ev); |
---|
723 | } while (ev.type==EV_MOUSE_MOVE && eh->event_waiting()); |
---|
724 | inm->handle_event(ev,NULL,eh); |
---|
725 | if (ev.type==EV_KEY && ev.key==JK_ESC) |
---|
726 | eh->push_event(new event(ID_QUIT,NULL)); |
---|
727 | |
---|
728 | menu_handler(ev,inm); |
---|
729 | start.get_time(); |
---|
730 | |
---|
731 | eh->flush_screen(); |
---|
732 | } |
---|
733 | else |
---|
734 | { |
---|
735 | // ECS - Added so that main menu doesn't grab 100% of CPU |
---|
736 | milli_wait(30); |
---|
737 | } |
---|
738 | |
---|
739 | if (new_time.diff_time(&start)>10) |
---|
740 | { |
---|
741 | if (volume_window) |
---|
742 | start.get_time(); |
---|
743 | else |
---|
744 | { |
---|
745 | if (!current_demo) |
---|
746 | { |
---|
747 | void *d=make_find_symbol("demos"); |
---|
748 | if (DEFINEDP(symbol_value(d))) |
---|
749 | current_demo=symbol_value(d); |
---|
750 | } |
---|
751 | if (current_demo) |
---|
752 | { |
---|
753 | demo_man.set_state(demo_manager::PLAYING,lstring_value(CAR(current_demo))); |
---|
754 | stop_menu=1; |
---|
755 | current_demo=CDR(current_demo); |
---|
756 | } |
---|
757 | } |
---|
758 | } |
---|
759 | |
---|
760 | if (volume_window) stop_menu=0; // can't exit with volume window open |
---|
761 | else if (main_net_cfg && main_net_cfg->restart_state()) stop_menu=1; |
---|
762 | else if (the_game->state==RUN_STATE) stop_menu=1; |
---|
763 | else if (ev.type==EV_MESSAGE) |
---|
764 | { |
---|
765 | if (ev.message.id==ID_START_GAME || ev.message.id==ID_RETURN) |
---|
766 | stop_menu=1; |
---|
767 | else if (ev.message.id==ID_QUIT) |
---|
768 | { |
---|
769 | if (confirm_quit()) |
---|
770 | stop_menu=1; |
---|
771 | else |
---|
772 | { |
---|
773 | ev.type=EV_SPURIOUS; |
---|
774 | start.get_time(); |
---|
775 | } |
---|
776 | } |
---|
777 | } |
---|
778 | } while (!stop_menu); |
---|
779 | |
---|
780 | delete inm; |
---|
781 | |
---|
782 | if (ev.type==EV_MESSAGE && ev.message.id==ID_QUIT) // propogate the quit message |
---|
783 | the_game->end_session(); |
---|
784 | } |
---|
785 | |
---|
786 | |
---|