home *** CD-ROM | disk | FTP | other *** search
- #include "menu.h"
- #include "help.h"
- #include "alpha.h"
-
- MenuItem::MenuItem( Director* d, int X, int Y, int Image ) : Performer( d )
- {
- x=X, y=Y, image=Image;
- }
-
- void MenuItem::display()
- {
- show_image( x, y, image );
- }
-
- void MenuItem::initialize()
- {
- load_gfxlib( "menu.gfx" );
- load_sfxlib( "menu.sfx" );
- }
-
- void MenuItem::playSwitchSound()
- {
- play_sound_clip( SWITCH );
- }
-
- //---------------------------------------------- MENU -----------
- Menu::Menu()
- {
- item[1]=new MenuItem( this, 95, 20, PLAY );
- item[2]=new MenuItem( this, 95, 20, PLAYSEL );
- item[3]=new MenuItem( this, 95, 70, HELP );
- item[4]=new MenuItem( this, 95, 70, HELPSEL );
- item[5]=new MenuItem( this, 95, 115, QUIT );
- item[6]=new MenuItem( this, 95, 115, QUITSEL );
- }
-
- Menu::~Menu()
- {
- stop_keystroke_cue( UP, (callback)&Menu::onUp );
- stop_keystroke_cue( DOWNARROW, (callback)&Menu::onDown );
- stop_keystroke_cue( ENTER, (callback)&Menu::onEnter );
- stop_keystroke_cue( ESC, (callback)&Menu::onEscape );
- stop_keystroke_cue( 'p', (callback)&Menu::onPlay );
- stop_keystroke_cue( 'h', (callback)&Menu::onHelp );
- stop_keystroke_cue( 'q', (callback)&Menu::onQuit );
- for ( int i=1; i<=MENUGFXITEMS; i++ )
- delete item[i];
- }
-
- const Type_info& Menu::get_next_director()
- {
- return CurSelection==PLAYSEL ? typeid( AlphaMission ) :
- CurSelection==HELPSEL ? typeid( HelpScreen ) :
- typeid( StopDirector );
- }
-
- void Menu::initialize()
- {
- request_keystroke_cue( UP, (callback)&Menu::onUp );
- request_keystroke_cue( DOWNARROW, (callback)&Menu::onDown );
- request_keystroke_cue( ENTER, (callback)&Menu::onEnter );
- request_keystroke_cue( ESC, (callback)&Menu::onEscape );
- request_keystroke_cue( 'p', (callback)&Menu::onPlay );
- request_keystroke_cue( 'h', (callback)&Menu::onHelp );
- request_keystroke_cue( 'q', (callback)&Menu::onQuit );
-
- for ( int i=1; i<=MENUGFXITEMS; i++ )
- item[i]->initialize();
- CurSelection=PLAYSEL;
- }
-
- void Menu::display()
- {
- init_video();
- show_pcx( "menu.pcx" );
- swap_video_pages();
- synch_video_pages();
- UpdateScreen();
- }
-
- void Menu::UpdateScreen(void)
- {
- item[PLAY]->display();
- item[HELP]->display();
- item[QUIT]->display();
- item[CurSelection]->display();
- item[CurSelection]->playSwitchSound();
- swap_video_pages();
- }
-
- void Menu::onUp(int)
- {
- CurSelection=(CurSelection>PLAYSEL ? CurSelection-2:QUITSEL);
- UpdateScreen();
- }
-
- void Menu::onDown(int)
- {
- CurSelection=(CurSelection<QUITSEL ? CurSelection+2:PLAYSEL);
- UpdateScreen();
- }
-
- void Menu::onEnter(int)
- {
- stop_director();
- }
-
- void Menu::onEscape(int)
- {
- CurSelection=QUITSEL;
- stop_director();
- }
-
- void Menu::onPlay(int)
- {
- if ( CurSelection!=PLAYSEL )
- {
- CurSelection=PLAYSEL;
- UpdateScreen();
- }
- }
-
- void Menu::onHelp(int)
- {
- if ( CurSelection!=HELPSEL )
- {
- CurSelection=HELPSEL;
- UpdateScreen();
- }
- }
-
- void Menu::onQuit(int)
- {
- if ( CurSelection!=QUITSEL )
- {
- CurSelection=QUITSEL;
- UpdateScreen();
- }
- }
-