Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
RaceOptions Class Reference

#include <race_options.hpp>

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

List of all members.

Public Member Functions

 RaceOptions ()
 ~RaceOptions ()
void select ()
virtual void update (float dt)
virtual void handle (GameAction, int)
virtual void inputKeyboard (SDLKey, int)
virtual void countdown ()
void inputPointer (int x, int y)
void lockInput ()
void unlockInput ()
void TimeToString (const double time, char *s)

Protected Attributes

bool m_locked
int m_menu_id

Private Member Functions

const char * getDifficultyString (int) const

Private Attributes

int m_difficulty
int m_num_karts
int m_num_laps

Detailed Description

Definition at line 23 of file race_options.hpp.


Constructor & Destructor Documentation

Definition at line 54 of file race_options.cpp.

{
    m_difficulty=race_manager->getDifficulty();
    // FIXME: no medium AI atm
    if(m_difficulty==RaceManager::RD_MEDIUM) m_difficulty=RaceManager::RD_HARD;
    m_num_karts=race_manager->getNumKarts();
    m_num_laps=race_manager->getNumLaps();

    const int DESC_WIDTH=48;
    const int ITEM_WIDTH=35;

    // Difficulty
    // ==========
    widget_manager->addTextWgt( WTOK_DIFFICULTY_TITLE, DESC_WIDTH, 7, _("Difficulty") );
    widget_manager->hideWgtRect(WTOK_DIFFICULTY_TITLE);
    widget_manager->setWgtTextSize(WTOK_DIFFICULTY_TITLE, WGT_FNT_LRG);
    widget_manager->addTextButtonWgt( WTOK_DIFFICULTY_DOWN, 3, 7, " < " );

    widget_manager->addTextWgt( WTOK_DIFFICULTY, ITEM_WIDTH, 7, getDifficultyString(m_difficulty));
    widget_manager->setWgtBorderPercentage( WTOK_DIFFICULTY, 10 );
    widget_manager->showWgtBorder( WTOK_DIFFICULTY );
    widget_manager->hideWgtRect( WTOK_DIFFICULTY );

    widget_manager->addTextButtonWgt( WTOK_DIFFICULTY_UP, 3, 7, " > " );

    widget_manager->breakLine();

    // Number of karts
    // ===============
    widget_manager->addTextWgt( WTOK_KARTS_TITLE, DESC_WIDTH, 7, _("Number of karts") );
    widget_manager->hideWgtRect(WTOK_KARTS_TITLE);
    widget_manager->setWgtTextSize(WTOK_KARTS_TITLE, WGT_FNT_LRG);
    widget_manager->addTextButtonWgt( WTOK_KARTS_DOWN, 3, 7, " < " );

    char string_num_karts[MAX_MESSAGE_LENGTH];
    snprintf(string_num_karts, MAX_MESSAGE_LENGTH, "%d", m_num_karts);
    widget_manager->addTextWgt( WTOK_KARTS, ITEM_WIDTH, 7, string_num_karts );
    widget_manager->setWgtBorderPercentage( WTOK_KARTS, 10 );
    widget_manager->showWgtBorder( WTOK_KARTS );
    widget_manager->hideWgtRect( WTOK_KARTS );

    widget_manager->addTextButtonWgt( WTOK_KARTS_UP, 3, 7, " > " );

    widget_manager->breakLine();

    // Number of laps
    // ==============
    if( race_manager->getRaceMode() != RaceManager::RM_GRAND_PRIX   &&
        race_manager->getRaceMode() != RaceManager::RM_FOLLOW_LEADER   )
    {
        widget_manager->addTextWgt( WTOK_LAPS_TITLE, DESC_WIDTH, 7, _("Number of laps") );
        widget_manager->hideWgtRect(WTOK_LAPS_TITLE);
        widget_manager->setWgtTextSize(WTOK_LAPS_TITLE, WGT_FNT_LRG);
        widget_manager->addTextButtonWgt( WTOK_LAPS_DOWN, 3, 7, " < " );

        char string_num_laps[MAX_MESSAGE_LENGTH];
        snprintf(string_num_laps, MAX_MESSAGE_LENGTH, "%d", m_num_laps);
        widget_manager->addTextWgt( WTOK_LAPS, ITEM_WIDTH, 7, string_num_laps );
        widget_manager->setWgtBorderPercentage( WTOK_LAPS, 10 );
        widget_manager->showWgtBorder( WTOK_LAPS );
        widget_manager->hideWgtRect( WTOK_LAPS );

        widget_manager->addTextButtonWgt( WTOK_LAPS_UP, 3, 7, " > " );
    }
    widget_manager->breakLine();
    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 10, 10 );
    widget_manager->breakLine();

    //Lower buttons
    //=============
    widget_manager->addTextButtonWgt( WTOK_START, 60, 7, _("Start race") );
    widget_manager->setWgtBorderPercentage( WTOK_START, 20 );
    widget_manager->setWgtBorderColor( WTOK_START, WGT_TRANS_BLUE );
    widget_manager->showWgtBorder( WTOK_START );
    widget_manager->breakLine();
    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 10);

    widget_manager->addTextButtonWgt( WTOK_QUIT, 60, 7, _("Press <ESC> to go back") );

    widget_manager->layout(WGT_AREA_ALL);
}   // RaceOptions

Here is the call graph for this function:

Definition at line 137 of file race_options.cpp.

{
    widget_manager->reset();
}   // ~RaceOptions

Here is the call graph for this function:


Member Function Documentation

void BaseGUI::countdown ( ) [virtual, inherited]

Reimplemented in DisplayResConfirm.

Definition at line 147 of file base_gui.cpp.

{
}
const char * RaceOptions::getDifficultyString ( int  difficulty) const [private]

Definition at line 274 of file race_options.cpp.

{
    switch(difficulty)
    {
    case RaceManager::RD_EASY:     return _("Novice");
    case RaceManager::RD_MEDIUM:   return _("Driver");
    case RaceManager::RD_HARD:     return _("Racer" );
    case RaceManager::RD_SKIDDING: return _("Skidding Preview");
    default:                       return _("Novice");

    }   // switch
}   // getDifficultyString

Here is the caller graph for this function:

void BaseGUI::handle ( GameAction  action,
int  value 
) [virtual, inherited]

Reimplemented in RaceGUI, LeaderResult, PlayerControls, RaceResultsGUI, DisplayResConfirm, MainMenu, Options, and RaceMenu.

Definition at line 43 of file base_gui.cpp.

{
    if( m_locked ) return;

    // Skip on keypress, act on keyrelease only.
    if (value) return;

       int previous = widget_manager->getSelectedWgt();

    switch ( action )
    {
    case GA_CURSOR_LEFT:
              animateWidget(previous,
                                     widget_manager->handleLeft());

              break;
    case GA_CURSOR_RIGHT:
              animateWidget(previous,
                                     widget_manager->handleRight());
              break;
    case GA_CURSOR_UP:
              animateWidget(previous,
                                     widget_manager->handleUp());
              break;
    case GA_CURSOR_DOWN:
              animateWidget(previous,
                                     widget_manager->handleDown());
              break;
       case GA_INC_SCROLL_SPEED:
              widget_manager->increaseScrollSpeed();
              break;
       case GA_INC_SCROLL_SPEED_FAST:
              widget_manager->increaseScrollSpeed(true);
              break;
       case GA_DEC_SCROLL_SPEED:
              widget_manager->decreaseScrollSpeed();
              break;
       case GA_DEC_SCROLL_SPEED_FAST:
              widget_manager->decreaseScrollSpeed(true);
              break;
    case GA_ENTER:
        select();
        break;
    case GA_LEAVE:
        if (menu_manager->getMenuStackSize() > 1)
        {
           if(menu_manager->isCurrentMenu(MENUID_RACEMENU))
             world->unpause();

           menu_manager->popMenu();
        }
        break;

    default:
        break;
    }   // switch
}   // handle

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::inputKeyboard ( SDLKey  ,
int   
) [virtual, inherited]

Reimplemented in PlayerControls.

Definition at line 139 of file base_gui.cpp.

{
       // This method is not supposed to be called since BaseGUI does not
       // handle low-level keyboard input.
       assert(false);
}

Here is the caller graph for this function:

void BaseGUI::inputPointer ( int  x,
int  y 
) [inherited]

Definition at line 102 of file base_gui.cpp.

{
    if( m_locked ) return;

    const int PREV_SELECTED_WGT = widget_manager->getSelectedWgt();
    const int SELECTED_WGT = widget_manager->handlePointer( x, y );

    if( SELECTED_WGT != WidgetManager::WGT_NONE )
    {
        if( PREV_SELECTED_WGT != WidgetManager::WGT_NONE )
        {
            widget_manager->darkenWgtColor( PREV_SELECTED_WGT );
        }

        widget_manager->lightenWgtColor( SELECTED_WGT );
        widget_manager->pulseWgt( SELECTED_WGT );
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void BaseGUI::lockInput ( ) [inline, inherited]

Definition at line 49 of file base_gui.hpp.

{ m_locked = true; }
void RaceOptions::select ( ) [virtual]

Implements BaseGUI.

Definition at line 143 of file race_options.cpp.

{
    switch ( widget_manager->getSelectedWgt() )
    {
        case WTOK_DIFFICULTY_UP:
            if( m_difficulty == RaceManager::RD_HARD && !unlock_manager->isLocked("skidding"))
            {
                m_difficulty = RaceManager::RD_SKIDDING;
            }
            else if( m_difficulty == RaceManager::RD_MEDIUM )
            {
                m_difficulty = RaceManager::RD_HARD;
            }
            else if( m_difficulty == RaceManager::RD_EASY )
            {
//TEMP: done just for the release after 0.4 because of AI problems
#undef ENABLE_MEDIUM_AI
#if ENABLE_MEDIUM_AI
                m_difficulty = RaceManager::RD_MEDIUM;
#else
                m_difficulty = RaceManager::RD_HARD;
#endif
            }
            widget_manager->setWgtText( WTOK_DIFFICULTY, getDifficultyString(m_difficulty) );
            break;

        case WTOK_DIFFICULTY_DOWN:
            if( m_difficulty == RaceManager::RD_SKIDDING )
            {
                m_difficulty = RaceManager::RD_HARD;
            }

            else if( m_difficulty == RaceManager::RD_HARD )
            {
//TEMP: done just for the release after 0.4 because of AI problems
#if ENABLE_MEDIUM_AI
                m_difficulty = RaceManager::RD_MEDIUM;
#else
                m_difficulty = RaceManager::RD_EASY;
#endif
            }
            else if( m_difficulty == RaceManager::RD_MEDIUM )
            {
                m_difficulty = RaceManager::RD_EASY;
            }
            widget_manager->setWgtText( WTOK_DIFFICULTY, getDifficultyString(m_difficulty) );

            break;

        case WTOK_KARTS_UP:
            {
                m_num_karts = std::min( stk_config->m_max_karts, m_num_karts + 1 );

                char label[ MAX_MESSAGE_LENGTH ];
                snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_karts );

                widget_manager->setWgtText( WTOK_KARTS, label );
            }
            break;

        case WTOK_KARTS_DOWN:
            {
                // Follow the leader needs at least three karts
                if(race_manager->getRaceMode() == RaceManager::RM_FOLLOW_LEADER)
                {
                    m_num_karts = std::max( 3, m_num_karts - 1 );
                }
                else
                {
                    m_num_karts = std::max( (int)race_manager->getNumPlayers(),
                        m_num_karts - 1 );
                }

                char label[ MAX_MESSAGE_LENGTH ];
                snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_karts );

                widget_manager->setWgtText( WTOK_KARTS, label );
            }
            break;

        case WTOK_LAPS_UP:
            {
                m_num_laps = std::min( 10, m_num_laps + 1 );

                char label[ MAX_MESSAGE_LENGTH ];
                snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_laps );

                widget_manager->setWgtText( WTOK_LAPS, label);
            }
            break;

        case WTOK_LAPS_DOWN:
            {
                m_num_laps = std::max( 1, m_num_laps - 1 );

                char label[ MAX_MESSAGE_LENGTH ];
                snprintf( label, MAX_MESSAGE_LENGTH, "%d", m_num_laps );

                widget_manager->setWgtText( WTOK_LAPS, label);
            }
            break;

    case WTOK_START:
        if( m_difficulty >= RaceManager::RD_EASY &&
            m_difficulty <= RaceManager::RD_SKIDDING)
        {
            race_manager->setDifficulty((RaceManager::Difficulty)m_difficulty);
        }
        else // invalid difficulty
        {
            race_manager->setDifficulty( RaceManager::RD_EASY );
        }

        race_manager->setNumKarts(m_num_karts);

        if( race_manager->getRaceMode() != RaceManager::RM_GRAND_PRIX    &&
            race_manager->getRaceMode() != RaceManager::RM_FOLLOW_LEADER    )
        {
            race_manager->setNumLaps( m_num_laps );
        }

        menu_manager->pushMenu(MENUID_START_RACE_FEEDBACK);
        break;
    case WTOK_QUIT:
        menu_manager->popMenu();
        break;
    default: break;
    }   // switch
}   // select

Here is the call graph for this function:

void BaseGUI::TimeToString ( const double  time,
char *  s 
) [inherited]

Definition at line 130 of file base_gui.cpp.

{
    int min     = (int) floor ( TIME / 60.0 ) ;
    int sec     = (int) floor ( TIME - (double) ( 60 * min ) ) ;
    int tenths  = (int) floor ( 10.0f * (TIME - (double)(sec + 60* min)));
    sprintf ( s, "%d:%02d:%d", min,  sec,  tenths ) ;
}   // TimeToString

Here is the caller graph for this function:

void BaseGUI::unlockInput ( ) [inline, inherited]

Definition at line 50 of file base_gui.hpp.

{ m_locked = false; }
void BaseGUI::update ( float  dt) [virtual, inherited]

Reimplemented in RaceGUI, CharSel, HelpPageOne, GrandPrixEnd, LeaderResult, GrandPrixSelect, ChallengesMenu, StartRaceFeedback, and TrackSel.

Definition at line 123 of file base_gui.cpp.

{
    widget_manager->update(dt);
}   // update

Here is the call graph for this function:


Member Data Documentation

Definition at line 26 of file race_options.hpp.

bool BaseGUI::m_locked [protected, inherited]

Definition at line 55 of file base_gui.hpp.

int BaseGUI::m_menu_id [protected, inherited]

Definition at line 56 of file base_gui.hpp.

int RaceOptions::m_num_karts [private]

Definition at line 27 of file race_options.hpp.

int RaceOptions::m_num_laps [private]

Definition at line 28 of file race_options.hpp.


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