made use of highscores optional (for instance battle mode may not ahve high scores so we need a way to turn them off)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2298 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2008-09-24 00:13:31 +00:00
parent b1ffefe0a4
commit 03ae2ce6d4
3 changed files with 42 additions and 27 deletions

View File

@@ -163,35 +163,39 @@ Widget *RaceResultsGUI::displayRaceResults()
order, /*displayTime*/ true, 0.1f);
delete[] order;
w_prev=widget_manager->addTextWgt( WTOK_HIGHSCORES, 5, 7, _("Highscores") );
widget_manager->hideWgtRect(WTOK_HIGHSCORES);
w_prev->setPosition(WGT_DIR_FROM_RIGHT, 0.1f, NULL, WGT_DIR_FROM_TOP, 0.1f, NULL);
const HighscoreEntry *hs = RaceManager::getWorld()->getHighscores();
unsigned int num_scores = hs->getNumberEntries();
char *highscores = new char[num_scores * MAX_STR_LEN];
for(unsigned int i=0; i<num_scores; i++)
if(hs != NULL)
{
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*)( highscores + MAX_STR_LEN * i ),
"%s: %3d:%02d.%01d", name.c_str(), MINS, SECS, TENTHS);
Widget *w=widget_manager->addTextWgt(WTOK_FIRST_HIGHSCORE + i, 5, 7,
(char*)( highscores+MAX_STR_LEN*i ) );
w->setPosition(WGT_DIR_FROM_RIGHT, 0.1f, NULL, WGT_DIR_UNDER_WIDGET, 0, w_prev);
w_prev=w;
}
widget_manager->sameWidth(WTOK_HIGHSCORES, WTOK_FIRST_HIGHSCORE+num_scores-1);
bottom_of_list = (num_scores > NUM_KARTS) ? w_prev : bottom_of_list;
w_prev=widget_manager->addTextWgt( WTOK_HIGHSCORES, 5, 7, _("Highscores") );
widget_manager->hideWgtRect(WTOK_HIGHSCORES);
w_prev->setPosition(WGT_DIR_FROM_RIGHT, 0.1f, NULL, WGT_DIR_FROM_TOP, 0.1f, NULL);
unsigned int num_scores = hs->getNumberEntries();
char *highscores = new char[num_scores * MAX_STR_LEN];
for(unsigned 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*)( highscores + MAX_STR_LEN * i ),
"%s: %3d:%02d.%01d", name.c_str(), MINS, SECS, TENTHS);
Widget *w=widget_manager->addTextWgt(WTOK_FIRST_HIGHSCORE + i, 5, 7,
(char*)( highscores+MAX_STR_LEN*i ) );
w->setPosition(WGT_DIR_FROM_RIGHT, 0.1f, NULL, WGT_DIR_UNDER_WIDGET, 0, w_prev);
w_prev=w;
} // next score
widget_manager->sameWidth(WTOK_HIGHSCORES, WTOK_FIRST_HIGHSCORE+num_scores-1);
bottom_of_list = (num_scores > NUM_KARTS) ? w_prev : bottom_of_list;
} // end if hs != NULL
return bottom_of_list;
} // displayRaceResults

View File

@@ -71,6 +71,8 @@ World::World()
// FIXME - not really used yet, only a placeholder to be implemented fully later
m_order_karts = true;
m_use_highscores = true;
// Grab the track file
try
{
@@ -288,6 +290,8 @@ void World::update(float dt)
// ----------------------------------------------------------------------------
HighscoreEntry* World::getHighscores() const
{
if(!m_use_highscores) return NULL;
const HighscoreEntry::HighscoreType type = "HST_" + getInternalCode();
HighscoreEntry* highscores =
@@ -306,6 +310,8 @@ HighscoreEntry* World::getHighscores() const
*/
void World::updateHighscores()
{
if(!m_use_highscores) return;
// Add times to highscore list. First compute the order of karts,
// so that the timing of the fastest kart is added first (otherwise
// someone might get into the highscore list, only to be kicked out

View File

@@ -114,6 +114,11 @@ protected:
Track* m_track;
/** Whether highscores should be used for this kind of race.
* True by default, change to false in a child class to disable.
*/
bool m_use_highscores;
public:
/** debug text that will be overlaid to the screen */
std::string m_debug_text[10];