Back to index

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

GUI that shows the RaceResults, times and such. More...

#include <race_results_gui.hpp>

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

List of all members.

Public Member Functions

 RaceResultsGUI ()
 ~RaceResultsGUI ()
void handle (GameAction, int)
void select ()
virtual void update (float dt)
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

char * m_score
char * m_highscores

Detailed Description

GUI that shows the RaceResults, times and such.

Definition at line 26 of file race_results_gui.hpp.


Constructor & Destructor Documentation

Definition at line 46 of file race_results_gui.cpp.

{
    widget_manager->addTitleWgt( WTOK_TITLE, 60, 7, _("Result") );
    widget_manager->breakLine();

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 5 );
    widget_manager->breakLine();

    widget_manager->addTextWgt( WTOK_RESULTS, 50, 7, _("Race results") );
    widget_manager->addTextWgt( WTOK_HIGHSCORES, 50, 7, _("Highscores") );
    widget_manager->breakLine();

    widget_manager->switchOrder();

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

    int*  order = new int [NUM_KARTS];
    m_score = new char[NUM_KARTS * MAX_STR_LEN];
    unsigned int max_name_len = 1;

    for(unsigned int i=0; i < NUM_KARTS; i++)
    {
        Kart *k = world->getKart(i);             // Display even for eliminated karts!
        order[k->getPosition()-1] = i;
        const std::string& s = k->getName();
        unsigned int l = (unsigned int)s.size();
        if(l>max_name_len) max_name_len = l;
    }   // for i

    for(unsigned int i = 0; i < NUM_KARTS; ++i)
    {
        const Kart *KART = world->getKart(order[i]);
        const std::string& KART_NAME = KART->getName();
        char sTime[20];
        const float T      = KART->getFinishTime();
        TimeToString(T, sTime);

        //This shows position + driver name + time + points earned + total points
        if(race_manager->getRaceMode()==RaceManager::RM_GRAND_PRIX)
        {
            sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s +%d %d",
                KART->getPosition(), KART_NAME.c_str(), sTime,
                race_manager->getPositionScore(i+1),
                race_manager->getKartScore(order[i]));
        }
        else
            {
            sprintf((char*)(m_score + MAX_STR_LEN * i), "%d. %s %s",
                KART->getPosition(), KART_NAME.c_str(), sTime);
        }

        widget_manager->addTextWgt( WTOK_FIRST_RESULT + i, 50, 7,
            (char*)(m_score + MAX_STR_LEN * i) );
    }

    delete[] order;

    widget_manager->breakLine();
    widget_manager->switchOrder();

    const Highscores *hs = world->getHighscores();
    int num_scores = hs->getNumberEntries();
    m_highscores = new char[num_scores * MAX_STR_LEN];

    for(int i=0; i<num_scores; i++)
    {
        std::string kart_name, name;
        float T;
        hs->getEntry(i, kart_name, name, &T);
        const int   MINS   = (int) floor ( T / 60.0 ) ;
        const int   SECS   = (int) floor ( T - (float) ( 60 * MINS ) ) ;
        const int   TENTHS = (int) floor ( 10.0f * (T - (float)(SECS + 60*MINS)));
        sprintf((char*)( m_highscores + MAX_STR_LEN * i ),
                "%s: %3d:%02d.%01d", name.c_str(), MINS, SECS, TENTHS);
        widget_manager->addTextWgt( WTOK_FIRST_HIGHSCORE + i, 50, 7,
            (char*)( m_highscores+MAX_STR_LEN*i ) );
    }
    widget_manager->breakLine();
    widget_manager->breakLine();

    widget_manager->addEmptyWgt( WidgetManager::WGT_NONE, 60, 5 );
    widget_manager->breakLine();

    // If a new feature was unlocked, only offer 'continue' otherwise add the 
    // full menu choices. The new feature menu returns to this menu, and will
    // then display the whole menu.
    if(unlock_manager->getUnlockedFeatures().size()>0)
    {
        widget_manager->addTextButtonWgt( WTOK_CONTINUE, 60, 7, _("Continue") );
    } else
    {
        if(race_manager->getRaceMode()==RaceManager::RM_GRAND_PRIX)
        {
            widget_manager->addTextButtonWgt( WTOK_CONTINUE, 60, 7, _("Continue Grand Prix"));
        }
        else
        {
            widget_manager->addTextButtonWgt( WTOK_CONTINUE, 60, 7, _("Back to the main menu"));
        }
        widget_manager->breakLine();

        widget_manager->addTextButtonWgt( WTOK_RESTART_RACE, 60, 7, _("Race in this track again"));
        widget_manager->breakLine();

        if(race_manager->getRaceMode()==RaceManager::RM_QUICK_RACE)
        {
            widget_manager->addTextButtonWgt( WTOK_SETUP_NEW_RACE, 60, 7, _("Setup New Race"));
        }
    }   // if !unlock_manager has something unlocked*/

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

Here is the call graph for this function:

Definition at line 161 of file race_results_gui.cpp.

{
    widget_manager->reset();
    delete[] m_score;
    delete[] m_highscores;
}   // ~RaceResultsGUI

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

Reimplemented from BaseGUI.

Definition at line 206 of file race_results_gui.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 RaceResultsGUI::select ( ) [virtual]

Implements BaseGUI.

Definition at line 169 of file race_results_gui.cpp.

{
    // Push the unlocked-feature menu in for now
    if(unlock_manager->getUnlockedFeatures().size()>0)
    {
        // Push the new feature menu on the stack, from where
        // control will be returned to this menu.
        menu_manager->pushMenu(MENUID_UNLOCKED_FEATURE);
        return;
    }
    switch( widget_manager->getSelectedWgt() )
    {
    case WTOK_CONTINUE:
        // Gets called when:
        // 1) something was unlocked
        // 2) a Grand Prix is run
        // 3) "back to the main menu" otherwise
        world->unpause();
        race_manager->next();
        break;
    case WTOK_RESTART_RACE:
        world->unpause();
        menu_manager->popMenu();
        race_manager->restartRace();
        break;
    case WTOK_SETUP_NEW_RACE:
        world->unpause();
        race_manager->exit_race();
        menu_manager->pushMenu(MENUID_CHARSEL_P1);
        break;

    default:
        break;
    }
}   // 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 30 of file race_results_gui.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* RaceResultsGUI::m_score [private]

Definition at line 29 of file race_results_gui.hpp.


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