Back to index

extremetuxracer  0.5beta
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
EventRaceSelect Class Reference

#include <event_race_select.h>

Inheritance diagram for EventRaceSelect:
Inheritance graph
[legend]
Collaboration diagram for EventRaceSelect:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EventRaceSelect ()
 ~EventRaceSelect ()
void loop (float timeStep)
void start ()
void back ()
void listboxItemChange ()
void handlePreview (const char *preview)
bool keyPressEvent (SDLKey key)
virtual bool keyboardEvent (SDLKey key, bool release)
virtual bool keyReleaseEvent (SDLKey key)
virtual bool mouseButtonEvent (int button, int x, int y, bool pressed)
virtual bool mouseButtonPressEvent (int button, int x, int y)
virtual bool mouseButtonReleaseEvent (int button, int x, int y)

Static Public Attributes

static GameModecurrentMode = NULL
static game_mode_t mode
static game_mode_t prevmode

Protected Member Functions

void drawSnow (float timeStep, bool windy=false)
 custom function for drawing snow in the ui

Private Types

enum  { DEAD, RACEWON, PLAYABLE, UNPLAYABLE }

Private Member Functions

void updateStates ()
void setWidgetPositionsAndDrawDecorations ()
void drawStatusMsg (int x_org, int y_org, int box_width, int box_height)

Private Attributes

pp::Labelmp_titleLbl
pp::Textareamp_descTa
pp::Listbox< CourseData > * mp_raceListbox
pp::SSButtonmp_previewSSBtn
pp::Buttonmp_backBtn
pp::Buttonmp_startBtn
pp::SSButtonmp_conditionsSSBtn
pp::SSButtonmp_snowSSBtn
pp::SSButtonmp_windSSBtn
pp::SSButtonmp_mirrorSSBtn
PlayerCourseData m_data
enum EventRaceSelect:: { ... }  state

Detailed Description

Definition at line 35 of file event_race_select.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
DEAD 
RACEWON 
PLAYABLE 
UNPLAYABLE 

Definition at line 50 of file event_race_select.h.


Constructor & Destructor Documentation

Definition at line 41 of file event_race_select.cpp.

{
    pp::Vec2d pos(0,0);

       mp_titleLbl = new pp::Label(pos, "heading", _("Select a race"));
       mp_titleLbl->alignment.center();
       mp_titleLbl->alignment.middle();   
       
       
    mp_backBtn = new pp::Button(pos,
                           pp::Vec2d(150, 40), 
                           "button_label", 
                           _("Back") );
    mp_backBtn->setHilitFontBinding( "button_label_hilit" );
    mp_backBtn->signalClicked.Connect(pp::CreateSlot(this,&EventRaceSelect::back));

    mp_startBtn = new pp::Button(pos,
                            pp::Vec2d(150, 40),
                            "button_label",
                            _("Race!") );
    mp_startBtn->setHilitFontBinding( "button_label_hilit" );
    mp_startBtn->setDisabledFontBinding( "button_label_disabled" );
       mp_startBtn->signalClicked.Connect(pp::CreateSlot(this,&EventRaceSelect::start));

       if ( GameMode::prevmode != GAME_OVER ) {
              curElem = gameMgr->getCurrentCup().raceList.begin();
    } else {
              if( gameMgr->wasRaceWon() ){
                     if(curElem != --gameMgr->getCurrentCup().raceList.end()){
                            curElem++;
                     }
              }
    }

       mp_raceListbox = new pp::Listbox<CourseData>(pos,
                               pp::Vec2d(460, 44),
                               "listbox_item",
                               gameMgr->getCurrentCup().raceList);
    mp_raceListbox->setCurrentItem( curElem );
       mp_raceListbox->signalChange.Connect(pp::CreateSlot(this,&EventRaceSelect::listboxItemChange));
    // Create text area 
     
    mp_descTa = new pp::Textarea( pos,
                            pp::Vec2d(312, 107),
                            "race_description",
                            "" );
       mp_descTa->setText( (*curElem).description.c_str() );

// Create preview

       mp_previewSSBtn = new pp::SSButton( pos, pp::Vec2d(132,99), 1);
       handlePreview( (*curElem).course.c_str() );
       mp_previewSSBtn->signalClicked.Connect(pp::CreateSlot(this,&EventRaceSelect::start));

    // Create state buttons - only if practicing or if cup_complete
    
       mp_conditionsSSBtn = NULL;
       mp_windSSBtn = NULL;
       mp_snowSSBtn = NULL;
       mp_mirrorSSBtn = NULL;
    
    updateStates();

    play_music( "start_screen" );
}

Here is the call graph for this function:

Definition at line 107 of file event_race_select.cpp.

{
       delete mp_titleLbl;
       delete mp_backBtn;
       delete mp_startBtn;
       delete mp_raceListbox;
       delete mp_previewSSBtn;
       delete mp_conditionsSSBtn;
       delete mp_snowSSBtn;
       delete mp_windSSBtn;
       delete mp_mirrorSSBtn;
       delete mp_descTa;
}

Member Function Documentation

Definition at line 420 of file event_race_select.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void GameMode::drawSnow ( float  timeStep,
bool  windy = false 
) [protected, inherited]

custom function for drawing snow in the ui

Definition at line 203 of file loop.cpp.

{
       // check wether ui snow is 
       if(getparam_ui_snow()){
              // update and draw snow
              update_ui_snow( timeStep, windy );
              draw_ui_snow();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void EventRaceSelect::drawStatusMsg ( int  x_org,
int  y_org,
int  box_width,
int  box_height 
) [private]

Definition at line 282 of file event_race_select.cpp.

{
    const char *msg;
    char buff[BUFF_LEN];
    bool draw_stats = true; 
       
       switch(state){
              case DEAD:
                     msg = _("You don't have any lives left.");
              draw_stats = false;
                     break;
              
              case RACEWON:
                     msg = _("Race won! Your result:"); 
                     break;
              
              case PLAYABLE:
                     msg = _("Needed to advance:");
                     break;
              
              case UNPLAYABLE:
                     msg = _("You can't enter this race yet.");
                     draw_stats = false;
                     break;
              default:
                     msg = "";
                     draw_stats = false;
                     break;
       }
              
       pp::Font *font = pp::Font::get("race_requirements");
       pp::Font *labelfont = pp::Font::get("race_requirements_label");
       
       labelfont->draw(msg,pp::Vec2d(x_org,y_org + 200));
       
       if ( draw_stats ) {
              int minutes;
              int seconds;
              int hundredths;

              pp::Vec2d pos(x_org,y_org + 184);
              
              getTimeComponents( m_data.time, minutes, seconds, hundredths );
              
              const char* string = _("Time:");
              labelfont->draw(string, pos);
              pos.x+=labelfont->advance(string) + 5;
              
              sprintf( buff, _("%02d:%02d.%02d"),minutes, seconds, hundredths);
              font->draw(buff, pos);
              
              pos.x+=75;
              string = _("Herring:");
              labelfont->draw(string, pos);
              pos.x+=labelfont->advance(string) + 5;

              sprintf( buff, "%03d", m_data.herring ); 
              font->draw(buff, pos);
              
              pos.x+=40;    
              string = _("Score:");
              labelfont->draw(string, pos);
              pos.x+=labelfont->advance(string) + 5;
       
              sprintf( buff, "%06d", m_data.score );
              font->draw(buff, pos);
       
       }
              
       const char* string = _("Contributed by:");
       pp::Vec2d pos(x_org,y_org+50);
       labelfont->draw(string,pos);
       pos.x += labelfont->advance(string) + 5;
              
       if(!(*curElem).contributed.empty()){
              font->draw((*curElem).contributed.c_str(),pos);         
       }else{
              font->draw(_("Unknown"),pos);
       }      
}

Here is the call graph for this function:

Here is the caller graph for this function:

void EventRaceSelect::handlePreview ( const char *  preview)

Definition at line 451 of file event_race_select.cpp.

{
       GLuint texobj;
       if ( get_texture_binding( preview, &texobj ) ) 
              mp_previewSSBtn->setStateImage(0, preview, pp::Vec2d(0.0, 0.0), pp::Vec2d(1.0, 1.0), pp::Color::white);  
       else
              mp_previewSSBtn->setStateImage(0, "no_preview", pp::Vec2d(0.0, 0.0), pp::Vec2d(1.0, 1.0), pp::Color::white);
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool GameMode::keyboardEvent ( SDLKey  key,
bool  release 
) [inline, virtual, inherited]

Reimplemented in Racing.

Definition at line 90 of file loop.h.

{return false;};
bool EventRaceSelect::keyPressEvent ( SDLKey  key) [virtual]

Reimplemented from GameMode.

Definition at line 462 of file event_race_select.cpp.

{
       switch (key){
              case SDLK_UP:
              case SDLK_LEFT:
                     mp_raceListbox->gotoPrevItem();
              return true;
              case SDLK_RIGHT:
              case SDLK_DOWN:
                     mp_raceListbox->gotoNextItem();
              return true;
              case SDLK_RETURN:
              mp_startBtn->simulateMouseClick();
                     UIMgr.setDirty();
                     return true;
              case SDLK_ESCAPE:
              mp_backBtn->simulateMouseClick();
                     UIMgr.setDirty();
                     return true;
              case 'c': 
              mp_conditionsSSBtn->simulateMouseClick();
              return true;
              case 'w': 
              mp_windSSBtn->simulateMouseClick();
              return true;
              case 'm':
              mp_mirrorSSBtn->simulateMouseClick();
              return true;
              default:
                     return false;
       }      
}

Here is the call graph for this function:

virtual bool GameMode::keyReleaseEvent ( SDLKey  key) [inline, virtual, inherited]

Reimplemented in HighscoreShow, and SplashScreen.

Definition at line 92 of file loop.h.

{return false;};

Definition at line 441 of file event_race_select.cpp.

{
       curElem = mp_raceListbox->getCurrentItem();
       mp_descTa->setText( (*curElem).description.c_str() );
       handlePreview( (*curElem).course.c_str() );
       updateStates();
       UIMgr.setDirty();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void EventRaceSelect::loop ( float  timeStep) [virtual]

Implements GameMode.

Definition at line 122 of file event_race_select.cpp.

{
       update_audio();

    set_gl_options( GUI );

    clear_rendering_context();

    UIMgr.setupDisplay();

       // todo: detect wether the cours is windy
       // in the meantime we always set windy to true
       drawSnow(timeStep, true);
       
    theme.drawMenuDecorations();

    setWidgetPositionsAndDrawDecorations();

    UIMgr.draw();

    reshape( getparam_x_resolution(), getparam_y_resolution() );

    winsys_swap_buffers();
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool GameMode::mouseButtonEvent ( int  button,
int  x,
int  y,
bool  pressed 
) [inline, virtual, inherited]

Reimplemented in GameOver.

Definition at line 94 of file loop.h.

{return false;};
virtual bool GameMode::mouseButtonPressEvent ( int  button,
int  x,
int  y 
) [inline, virtual, inherited]

Definition at line 95 of file loop.h.

{return false;};
virtual bool GameMode::mouseButtonReleaseEvent ( int  button,
int  x,
int  y 
) [inline, virtual, inherited]

Reimplemented in CreditsTrans, and SplashScreen.

Definition at line 96 of file loop.h.

{return false;};

Definition at line 148 of file event_race_select.cpp.

{
    int w = getparam_x_resolution();
    int h = getparam_y_resolution();
    int box_width, box_height, box_max_y;
    int x_org, y_org;
    GLuint texobj;

    // set the dimensions of the box in which all widgets should fit
    box_width = 460;
    box_height = 310;
    box_max_y = h - 128;

    x_org = w/2 - box_width/2;
    y_org = h/2 - box_height/2;
    if ( y_org + box_height > box_max_y ) {
       y_org = box_max_y - box_height;
    }

    mp_backBtn->setPosition(pp::Vec2d( x_org + 131 - mp_backBtn->getWidth()/2.0,
                    42 ) );

    mp_startBtn->setPosition(pp::Vec2d( x_org + 343 - mp_startBtn->getWidth()/2.0,
                    42 ) );

       mp_raceListbox->setPosition(pp::Vec2d( x_org,y_org + 221 ) );

       mp_descTa->setPosition(pp::Vec2d( x_org,y_org + 66 ) );
    
       // Draw tux life icons
       int i;
       
       glPushMatrix();
       {

           glTranslatef( x_org + box_width - 4*36 + 4,
                       y_org + 181,
                       0 );
           
           check_assertion( INIT_NUM_LIVES == 4, 
                          "Assumption about number of lives invalid -- "
                          "need to recode this part" );

           if ( !get_texture_binding( "tux_life", &texobj ) ) {
              texobj = 0;
           }

           glBindTexture( GL_TEXTURE_2D, texobj );

           for ( i=0; i<4; i++ ) {
              pp::Vec2d ll, ur;
              if ( players[0].getLives() > i ) {
                  ll = pp::Vec2d( 0, 0.5 );
                  ur = pp::Vec2d( 1, 1 );
              } else {
                  ll = pp::Vec2d( 0, 0 );
                  ur = pp::Vec2d( 1, 0.5 );
              }
              glBegin( GL_QUADS );
              {
                  glTexCoord2f( ll.x, ll.y );
                  glVertex2f( 0, 0 );

                  glTexCoord2f( ur.x, ll.y );
                  glVertex2f( 32, 0 );

                  glTexCoord2f( ur.x, ur.y );
                  glVertex2f( 32, 32 );

                  glTexCoord2f( ll.x, ur.y );
                  glVertex2f( 0, 32 );
              }
              glEnd();

              glTranslatef( 36, 0, 0 );
           }
       }
       glPopMatrix();
    
    // Draw other stuff
       
       mp_titleLbl->setPosition(pp::Vec2d(x_org + box_width/2.0,y_org + 310));
       
       // Draw text indicating race requirements (if race not completed), 
    //   or results in race if race completed.
    drawStatusMsg( x_org, y_org, box_width, box_height );

    // Draw preview
       mp_previewSSBtn->setPosition(pp::Vec2d( x_org+box_width-136, y_org+70 ));
       
       //std::list<CourseData>::iterator elem;
       //elem = mp_raceListbox->getCurrentItem();

    glDisable( GL_TEXTURE_2D );

    glColor4f( 1.0, 1.0, 1.0, 1.0 );
    glBegin( GL_QUADS );
    {
              glVertex2f( x_org+box_width-140, y_org+66 );
              glVertex2f( x_org+box_width, y_org+66 );
              glVertex2f( x_org+box_width, y_org+66+107 );
              glVertex2f( x_org+box_width-140, y_org+66+107 );
    }
    glEnd();

    glEnable( GL_TEXTURE_2D );
/* Old preview system
    if ( !get_texture_binding( (*elem).course.c_str(), &texobj ) ) {
       if ( !get_texture_binding( "no_preview", &texobj ) ) {
           texobj = 0;
       }
    }

    glBindTexture( GL_TEXTURE_2D, texobj );

    glBegin( GL_QUADS );
    {
       glTexCoord2d( 0, 0);
       glVertex2f( x_org+box_width-136, y_org+70 );

       glTexCoord2d( 1, 0);
       glVertex2f( x_org+box_width-4, y_org+70 );

       glTexCoord2d( 1, 1);
       glVertex2f( x_org+box_width-4, y_org+70+99 );

       glTexCoord2d( 0, 1);
       glVertex2f( x_org+box_width-136, y_org+70+99 );
    }
    glEnd();
*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 428 of file event_race_select.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EventRaceSelect::updateStates ( ) [private]

Definition at line 365 of file event_race_select.cpp.

{
       //mp_startBtn->setSensitive( true );
       if ( players[0].getLives() <= 0 ) {
              state=DEAD;
              mp_startBtn->setSensitive( false );
              mp_previewSSBtn->setSensitive( false );
       } else {
              m_data.won=false;
              players[0].getCupCourseData(
                            std::string(gameMgr->getCurrentEvent().name),
                            std::string(gameMgr->getCurrentCup().name),
                            std::string((*curElem).name),
                            m_data);
       
              if(m_data.won){
                     state=RACEWON;
                     mp_startBtn->setSensitive( false );
                     mp_previewSSBtn->setSensitive( false );
              }else{
                     
                     difficulty_level_t d = gameMgr->difficulty;
                     m_data.time = (*curElem).time_req[d];
                     m_data.herring = (*curElem).herring_req[d];
                     m_data.score = int((*curElem).score_req[d]);

                     if(curElem==gameMgr->getCurrentCup().raceList.begin()){
                            state=PLAYABLE;
                            mp_startBtn->setSensitive( true );
                            mp_previewSSBtn->setSensitive( true );
                     }else{
                            PlayerCourseData prev;
                            curElem--;
                            players[0].getCupCourseData(
                                   std::string(gameMgr->getCurrentEvent().name),
                                   std::string(gameMgr->getCurrentCup().name),
                                   std::string((*curElem).name),
                                   prev);
                            curElem++;
                            
                            if(prev.won){
                                   state=PLAYABLE;
                                   mp_startBtn->setSensitive( true );
                                   mp_previewSSBtn->setSensitive( true );
                            } else {
                                   state=UNPLAYABLE;
                                   mp_startBtn->setSensitive( false );
                                   mp_previewSSBtn->setSensitive( false );
                            }
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

GameMode * GameMode::currentMode = NULL [static, inherited]

Definition at line 96 of file loop.h.

Definition at line 48 of file event_race_select.h.

game_mode_t GameMode::mode [static, inherited]

Definition at line 99 of file loop.h.

Definition at line 41 of file event_race_select.h.

Definition at line 43 of file event_race_select.h.

Definition at line 38 of file event_race_select.h.

Definition at line 46 of file event_race_select.h.

Definition at line 40 of file event_race_select.h.

Definition at line 39 of file event_race_select.h.

Definition at line 44 of file event_race_select.h.

Definition at line 42 of file event_race_select.h.

Definition at line 37 of file event_race_select.h.

Definition at line 45 of file event_race_select.h.

game_mode_t GameMode::prevmode [static, inherited]

Definition at line 100 of file loop.h.

enum { ... } EventRaceSelect::state [private]

The documentation for this class was generated from the following files: