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