home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / skyscrap / build / menu.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-04  |  3.1 KB  |  140 lines

  1. #include "menu.h"
  2. #include "help.h"
  3. #include "alpha.h"
  4.  
  5. MenuItem::MenuItem( Director* d, int X, int Y, int Image ) : Performer( d )
  6. {
  7.   x=X, y=Y, image=Image;
  8. }
  9.  
  10. void MenuItem::display()
  11. {
  12.   show_image( x, y, image );
  13. }
  14.  
  15. void MenuItem::initialize()
  16. {
  17.   load_gfxlib( "menu.gfx" );
  18.   load_sfxlib( "menu.sfx" );
  19. }
  20.  
  21. void MenuItem::playSwitchSound()
  22. {
  23.   play_sound_clip( SWITCH );
  24. }
  25.  
  26. //---------------------------------------------- MENU -----------
  27. Menu::Menu()
  28. {
  29.   item[1]=new MenuItem( this, 95, 20, PLAY );
  30.   item[2]=new MenuItem( this, 95, 20, PLAYSEL );
  31.   item[3]=new MenuItem( this, 95, 70, HELP );
  32.   item[4]=new MenuItem( this, 95, 70, HELPSEL );
  33.   item[5]=new MenuItem( this, 95, 115, QUIT );
  34.   item[6]=new MenuItem( this, 95, 115, QUITSEL );
  35. }
  36.  
  37. Menu::~Menu()
  38. {
  39.   stop_keystroke_cue( UP,        (callback)&Menu::onUp      );
  40.   stop_keystroke_cue( DOWNARROW, (callback)&Menu::onDown    );
  41.   stop_keystroke_cue( ENTER,     (callback)&Menu::onEnter   );
  42.   stop_keystroke_cue( ESC,       (callback)&Menu::onEscape  );
  43.   stop_keystroke_cue( 'p',       (callback)&Menu::onPlay    );
  44.   stop_keystroke_cue( 'h',       (callback)&Menu::onHelp    );
  45.   stop_keystroke_cue( 'q',       (callback)&Menu::onQuit    );
  46.   for ( int i=1; i<=MENUGFXITEMS; i++ )
  47.     delete item[i];
  48. }
  49.  
  50. const Type_info& Menu::get_next_director()
  51. {
  52.   return CurSelection==PLAYSEL ? typeid( AlphaMission ) :
  53.          CurSelection==HELPSEL ? typeid( HelpScreen ) :
  54.          typeid( StopDirector );
  55. }
  56.  
  57. void Menu::initialize()
  58. {
  59.   request_keystroke_cue( UP,        (callback)&Menu::onUp      );
  60.   request_keystroke_cue( DOWNARROW, (callback)&Menu::onDown    );
  61.   request_keystroke_cue( ENTER,     (callback)&Menu::onEnter   );
  62.   request_keystroke_cue( ESC,       (callback)&Menu::onEscape  );
  63.   request_keystroke_cue( 'p',       (callback)&Menu::onPlay    );
  64.   request_keystroke_cue( 'h',       (callback)&Menu::onHelp    );
  65.   request_keystroke_cue( 'q',       (callback)&Menu::onQuit    );
  66.  
  67.   for ( int i=1; i<=MENUGFXITEMS; i++ )
  68.     item[i]->initialize();
  69.   CurSelection=PLAYSEL;
  70. }
  71.  
  72. void Menu::display()
  73. {
  74.   init_video();
  75.   show_pcx( "menu.pcx" );
  76.   swap_video_pages();
  77.   synch_video_pages();
  78.   UpdateScreen();
  79. }
  80.  
  81. void Menu::UpdateScreen(void)
  82. {
  83.   item[PLAY]->display();
  84.   item[HELP]->display();
  85.   item[QUIT]->display();
  86.   item[CurSelection]->display();
  87.   item[CurSelection]->playSwitchSound();
  88.   swap_video_pages();
  89. }
  90.  
  91. void Menu::onUp(int)
  92. {
  93.   CurSelection=(CurSelection>PLAYSEL ? CurSelection-2:QUITSEL);
  94.   UpdateScreen();
  95. }
  96.  
  97. void Menu::onDown(int)
  98. {
  99.   CurSelection=(CurSelection<QUITSEL ? CurSelection+2:PLAYSEL);
  100.   UpdateScreen();
  101. }
  102.  
  103. void Menu::onEnter(int)
  104. {
  105.   stop_director();
  106. }
  107.  
  108. void Menu::onEscape(int)
  109. {
  110.   CurSelection=QUITSEL;
  111.   stop_director();
  112. }
  113.  
  114. void Menu::onPlay(int)
  115. {
  116.   if ( CurSelection!=PLAYSEL )
  117.   {
  118.     CurSelection=PLAYSEL;
  119.     UpdateScreen();
  120.   }
  121. }
  122.  
  123. void Menu::onHelp(int)
  124. {
  125.   if ( CurSelection!=HELPSEL )
  126.   {
  127.     CurSelection=HELPSEL;
  128.     UpdateScreen();
  129.   }
  130. }
  131.  
  132. void Menu::onQuit(int)
  133. {
  134.   if ( CurSelection!=QUITSEL )
  135.   {
  136.     CurSelection=QUITSEL;
  137.     UpdateScreen();
  138.   }
  139. }
  140.