Back to index

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

#include <leader_result.hpp>

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

List of all members.

Public Member Functions

 LeaderResult ()
 ~LeaderResult ()
void update (float dt)
void select ()
void handle (GameAction ga, int value)
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 Attributes

ssgContext * m_context
ssgTransform * m_kart
int m_current_kart
int m_kart_name_label
char * m_score
float m_clock

Detailed Description

Definition at line 29 of file leader_result.hpp.


Constructor & Destructor Documentation

Definition at line 53 of file leader_result.cpp.

        : m_kart(0)
{
    // 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();

    const unsigned int MAX_STR_LEN = 60;
    const unsigned int NUM_KARTS = race_manager->getNumKarts();

    int *scores   = new int[NUM_KARTS];
    int *position = new int[NUM_KARTS];
    double *race_time = new double[NUM_KARTS];

    // Ignore kart 0, since it was the leader
    for( unsigned int kart_id = 1; kart_id < NUM_KARTS; ++kart_id )
    {
        position[kart_id]  = kart_id;
        scores[kart_id]    = race_manager->getKartScore(kart_id);
        race_time[kart_id] = race_manager->getOverallTime(kart_id);
    }

    //Bubblesort
    bool sorted;
    do
    {
        sorted = true;
        for( unsigned int i = 1; i < NUM_KARTS - 1; ++i )
        {
            if( scores[i] < scores[i+1] || (scores[i] == scores[i+1] 
              && race_time[i] > race_time[i+1]))
            {
                int tmp_score[2];
                double tmp_time;

                tmp_score[0]   = position[i];
                tmp_score[1]   = scores[i];
                tmp_time       = race_time[i];

                position[i]    = position[i+1];
                scores[i]      = scores[i+1];
                race_time[i]   = race_time[i+1];

                position[i+1]  = tmp_score[0];
                scores[i+1]    = tmp_score[1];
                race_time[i+1] = tmp_time;

                sorted = false;
            }
        }
    } while(!sorted);
    
    static char output[MAX_MESSAGE_LENGTH];
    snprintf(output, sizeof(output),
        _("The winner is %s!"),race_manager->getKartName(position[1]).c_str());
    widget_manager->addWgt( WTOK_TITLE, 60, 10);
    widget_manager->showWgtRect(WTOK_TITLE);
    widget_manager->showWgtText(WTOK_TITLE);
    widget_manager->setWgtText(WTOK_TITLE, output);
    widget_manager->setWgtTextSize(WTOK_TITLE, WGT_FNT_LRG);
    widget_manager->breakLine();

    m_score = new char[MAX_STR_LEN*NUM_KARTS];

    for(unsigned int i=1; i < NUM_KARTS; ++i)
    {
        // char sTime[20];
        // For now: don't display the time, since it's not correctly
        // set in follow-the-leader
        //TimeToString(race_time[i], sTime);
        sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %d",
            i , race_manager->getKartName(position[i]).c_str(), scores[i]);

        widget_manager->addWgt(WTOK_FIRSTKART + i, 40, 5);
        widget_manager->showWgtRect(WTOK_FIRSTKART + i);
        widget_manager->showWgtText(WTOK_FIRSTKART + i);
        widget_manager->setWgtText(WTOK_FIRSTKART + i,
            (char*)(m_score + MAX_STR_LEN * i));
        widget_manager->setWgtTextSize(WTOK_FIRSTKART + i, WGT_FNT_SML);
    widget_manager->breakLine();
    }
    const std::string KART_NAME = race_manager->getKartName(position[1]);
    const KartProperties* WINNING_KART = kart_properties_manager->getKart(KART_NAME);
    delete []scores;
    delete []position;
    delete []race_time;

    widget_manager->addWgt(WTOK_QUIT, 50, 7);
    widget_manager->activateWgt(WTOK_QUIT);
    widget_manager->showWgtRect(WTOK_QUIT);
    widget_manager->showWgtText(WTOK_QUIT);
    if(unlock_manager->getUnlockedFeatures().size()>0)
    {
        widget_manager->setWgtText(WTOK_QUIT, _("Continue"));
    }
    else
    {
        widget_manager->setWgtText(WTOK_QUIT, _("Back to the main menu"));
    }

    widget_manager->layout(WGT_AREA_TOP);

    m_kart = new ssgTransform;
    m_kart->ref();
    ssgEntity* kartentity = WINNING_KART->getModel();
    m_kart->addKid(kartentity);

    sound_manager->playSfx(SOUND_WINNER);

    m_clock = 0;

    //FIXME: this is taken from RaceMode::exit_race,
    //this should be organized better.
    scene->clear();
    delete world;
    world = 0;
    race_manager->m_active_race = false;

}

Here is the call graph for this function:

Definition at line 176 of file leader_result.cpp.

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

    delete m_context;
    delete[] m_score;

    //The next line prevents textures like the background of the main menu from
    //going white after finishing the grandprix
    // FIXME: I think this is not necessary anymore after the
    //        texture bug fix (r733) - but I can't currently test this.
    loader->shared_textures.removeAll();
}

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 LeaderResult::handle ( GameAction  ga,
int  value 
) [virtual]

Reimplemented from BaseGUI.

Definition at line 244 of file leader_result.cpp.

{
  // Attempts to close the menu are silently discarded
  // since they do not make sense at this point.
  if (ga == GA_LEAVE)
   return;
  else
    BaseGUI::handle(ga, value);
}
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 LeaderResult::select ( ) [virtual]

Implements BaseGUI.

Definition at line 227 of file leader_result.cpp.

{
    // If a new feature was unlocked, display the new feature first
    // before returning to the main menu
    if(unlock_manager->getUnlockedFeatures().size()>0)
    {
        // This removes this menu from the stack, and adds the main menu. 
        // Then we push the new feature menu on top, so that it will be
        // displayed next, and on return the main menu is shown.
        menu_manager->switchToMainMenu();
        menu_manager->pushMenu(MENUID_UNLOCKED_FEATURE);
        return;
    }

    menu_manager->switchToMainMenu();
}

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 LeaderResult::update ( float  dt) [virtual]

Reimplemented from BaseGUI.

Definition at line 193 of file leader_result.cpp.

{
    m_clock += dt * 40.0f;

    glClearColor (0.1f, 0.1f, 0.1f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    ssgContext* oldContext = ssgGetCurrentContext();
    m_context -> makeCurrent();

    // FIXME: A bit hackish...
    glViewport ( 0, 0, 800, 320);

    m_context -> setFOV ( 45.0f, 45.0f * 320.0f/800.0f ) ;
    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();
    BaseGUI::update(dt);
}

Member Data Documentation

float LeaderResult::m_clock [private]

Definition at line 37 of file leader_result.hpp.

ssgContext* LeaderResult::m_context [private]

Definition at line 32 of file leader_result.hpp.

Definition at line 34 of file leader_result.hpp.

ssgTransform* LeaderResult::m_kart [private]

Definition at line 33 of file leader_result.hpp.

Definition at line 35 of file leader_result.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.

char* LeaderResult::m_score [private]

Definition at line 36 of file leader_result.hpp.


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