Back to index

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

#include <char_sel.hpp>

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

List of all members.

Public Member Functions

 CharSel (int which_player)
 ~CharSel ()
void switchCharacter (int n)
void update (float dt)
void select ()
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

bool kartAvailable (int kart)

Private Attributes

ssgContext * m_context
ssgTransform * m_kart
int m_current_kart
float m_clock
int m_player_index

Detailed Description

Definition at line 28 of file char_sel.hpp.


Constructor & Destructor Documentation

CharSel::CharSel ( int  which_player)

Definition at line 47 of file char_sel.cpp.

        : m_kart(0), m_player_index(whichPlayer)
{
    // For some strange reasons plib calls makeCurrent() in ssgContext
    // constructor, so we have to save the old one here and restore it
    ssgContext* oldContext = ssgGetCurrentContext();
    m_context = new ssgContext;
    oldContext->makeCurrent();

    // If m_player_index is 0 then this is a single player game or the first
    // player of a multiplayer game so we need to ensure that all karts are available.
    // If m_player_index is less than the number of elements in selected_karts then
    // the user is moving back through the menus and the last value in the vector
    // needs to be made available again.
    if (m_player_index == 0)
        kart_properties_manager->m_selected_karts.clear();

    if (m_player_index < (int)kart_properties_manager->m_selected_karts.size())
    kart_properties_manager->m_selected_karts.pop_back();

    char heading[MAX_MESSAGE_LENGTH];
    snprintf(heading, sizeof(heading), _("Player %d, choose a driver"),
             m_player_index + 1);
    widget_manager->addTitleWgt( WTOK_TITLE, 100, 10, heading );
    widget_manager->breakLine();

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2);
    widget_manager->breakLine();

    for (unsigned int i = 0; i < kart_properties_manager->getNumberOfKarts(); i++)
    {
        // Check if i has been previously selected
        if (kartAvailable(i))
        {
            const KartProperties* kp= kart_properties_manager->getKartById(i);
            if(unlock_manager->isLocked(kp->getIdent())) continue;

            widget_manager->addImgButtonWgt( WTOK_RACER0 + i, 8, 11,
                                             kp->getIconFile() );
        }
    }

    widget_manager->breakLine();
    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 1, 2);
    widget_manager->breakLine();

    widget_manager->addTextWgt( WTOK_NAME, 30, 7, "");

    widget_manager->layout(WGT_AREA_TOP);

    m_current_kart = -1;

    const int LAST_KART = user_config->m_player[m_player_index].getLastKartId();
    if( LAST_KART != -1 && kartAvailable(LAST_KART))// is LAST_KART not in vector of selected karts
    {
        widget_manager->setSelectedWgt(WTOK_RACER0 + LAST_KART);
        switchCharacter(LAST_KART);
    }
    else
    {
        switchCharacter(0);
    }


    m_clock = 0;
    //test

}

Here is the call graph for this function:

Definition at line 117 of file char_sel.cpp.

{
    widget_manager->reset();
    ssgDeRefDelete(m_kart);

    delete m_context;
}

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.

{
}
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:

bool CharSel::kartAvailable ( int  kart) [private]

Definition at line 239 of file char_sel.cpp.

{
       if (!kart_properties_manager->m_selected_karts.empty())
        {
            std::vector<int>::iterator it;
            for (it = kart_properties_manager->m_selected_karts.begin();
                it < kart_properties_manager->m_selected_karts.end(); it++)
            {
                if ( kart == *it)
                return false;
            }
        }
    return true;
}

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 CharSel::select ( ) [virtual]

Implements BaseGUI.

Definition at line 189 of file char_sel.cpp.

Here is the call graph for this function:

void CharSel::switchCharacter ( int  n)

Definition at line 126 of file char_sel.cpp.

{
    const KartProperties* kp= kart_properties_manager->getKartById(n);
    if (m_current_kart != n && kp != NULL)
    {
        widget_manager->setWgtText( WTOK_NAME, kp->getName().c_str());

        m_current_kart = n;
        ssgDeRefDelete(m_kart);
        m_kart = new ssgTransform;
        m_kart->ref();
        ssgEntity* kartentity = kp->getModel();

        m_kart->addKid(kartentity);
    }
}

Here is the call graph for this function:

Here is the caller 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 CharSel::update ( float  dt) [virtual]

Reimplemented from BaseGUI.

Definition at line 144 of file char_sel.cpp.

{
    m_clock += dt * 40.0f;

    if( widget_manager->selectionChanged() )
    {
        switchCharacter(widget_manager->getSelectedWgt() - WTOK_RACER0);
    }

    if (m_kart != NULL)
    {
        ssgContext* oldContext = ssgGetCurrentContext();
        m_context -> makeCurrent();

        glClear(GL_DEPTH_BUFFER_BIT);

        // Puts the character in the center. Scaling is done by
        // applying a big camera FOV.
        int w = user_config->m_width;
        int h = user_config->m_height;
        glViewport ( 0, 0, w, h);

        m_context -> setFOV ( 65.0f, 65.0f * h/w ) ;
        m_context -> setNearFar ( 0.05f, 1000.0f ) ;

        sgCoord cam_pos;
        sgSetCoord(&cam_pos, 0, 0, 0, 0, 0, 0);
        m_context -> setCamera ( &cam_pos ) ;

        glEnable (GL_DEPTH_TEST);
        sgCoord trans;
        sgSetCoord(&trans, 0, 3, -.4f, m_clock, 0, 0);
        m_kart->setTransform (&trans) ;
        //glShadeModel(GL_SMOOTH);
        ssgCullAndDraw ( m_kart ) ;
        glViewport ( 0, 0, user_config->m_width, user_config->m_height ) ;

        glDisable (GL_DEPTH_TEST);
        oldContext->makeCurrent();
    }

    widget_manager->update(dt);
}

Here is the call graph for this function:


Member Data Documentation

float CharSel::m_clock [private]

Definition at line 34 of file char_sel.hpp.

ssgContext* CharSel::m_context [private]

Definition at line 31 of file char_sel.hpp.

int CharSel::m_current_kart [private]

Definition at line 33 of file char_sel.hpp.

ssgTransform* CharSel::m_kart [private]

Definition at line 32 of file char_sel.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 CharSel::m_player_index [private]

Definition at line 36 of file char_sel.hpp.


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