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