Partial work towards showing highscores when they are made

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8697 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-05-24 01:34:02 +00:00
parent 19ce15aee9
commit da85204faf
4 changed files with 65 additions and 11 deletions

View File

@@ -316,7 +316,13 @@ void World::terminateRace()
}
} // i<kart_amount
updateHighscores();
// Update highscores, and retrieve the best highscore if relevant to show it in the GUI
int best_highscore_rank = -1;
int best_finish_time = -1;
std::string highscore_who = "";
updateHighscores(&best_highscore_rank, &best_finish_time, &highscore_who);
unlock_manager->raceFinished();
if (m_race_gui) m_race_gui->clearAllMessages();
@@ -327,8 +333,20 @@ void World::terminateRace()
// and save the pointer.
assert(m_saved_race_gui==NULL);
m_saved_race_gui = m_race_gui;
m_race_gui = RaceResultGUI::getInstance();
StateManager::get()->pushScreen(RaceResultGUI::getInstance());
RaceResultGUI* results = RaceResultGUI::getInstance();
m_race_gui = results;
if (best_highscore_rank > 0)
{
results->setHighscore(highscore_who, best_highscore_rank, best_finish_time);
}
else
{
results->clearHighscores();
}
StateManager::get()->pushScreen(results);
WorldStatus::terminateRace();
} // terminateRace
@@ -637,10 +655,12 @@ Highscores* World::getHighscores() const
* score, if so it notifies the HighscoreManager so the new score is added
* and saved.
*/
void World::updateHighscores()
void World::updateHighscores(int* best_highscore_rank, int* best_finish_time, std::string* highscore_who)
{
if(!m_use_highscores) return;
*best_highscore_rank = -1;
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
@@ -660,9 +680,8 @@ void World::updateHighscores()
index[pos] = i;
}
for(unsigned int pos=0; pos<kart_amount; pos++)
for (unsigned int pos=0; pos<kart_amount; pos++)
{
if(index[pos] == 999)
{
// no kart claimed to be in this position, most likely means
@@ -689,10 +708,20 @@ void World::updateHighscores()
Highscores* highscores = getHighscores();
PlayerController *controller = (PlayerController*)(k->getController());
if(highscores->addData(k->getIdent(),
controller->getPlayer()->getProfile()->getName(),
k->getFinishTime())>0 )
int highscore_rank = highscores->addData(k->getIdent(),
controller->getPlayer()->getProfile()->getName(),
k->getFinishTime());
if (highscore_rank > 0)
{
if (*best_highscore_rank == -1 || highscore_rank < *best_highscore_rank)
{
*best_highscore_rank = highscore_rank;
*best_finish_time = k->getFinishTime();
*highscore_who = k->getIdent();
}
highscore_manager->saveHighscores();
}
} // next position

View File

@@ -83,7 +83,7 @@ protected:
*/
bool m_use_highscores;
void updateHighscores ();
void updateHighscores (int* best_highscore_rank, int* best_finish_time, std::string* highscore_who);
void resetAllKarts ();
void removeKart (int kart_number, bool notifyOfElimination=true);
Controller*

View File

@@ -665,3 +665,16 @@ void RaceResultGUI::displayOneEntry(unsigned int x, unsigned int y,
} // displayOneEntry
//-----------------------------------------------------------------------------
void RaceResultGUI::clearHighscores()
{
// TODO
}
//-----------------------------------------------------------------------------
void RaceResultGUI::setHighscore(std::string who, int rank, int time)
{
// TODO
}

View File

@@ -211,6 +211,18 @@ public:
virtual void clearAllMessages() {assert(false); }
void nextPhase();
/** Show no highscore */
void clearHighscores();
/**
* To call if the user got a new highscore
* \param who identity of the kart that made the highscore
* \param rank Highscore rank (first highscore, second highscore, etc.). This is not the race rank
* \param time Finish time in seconds
*/
void setHighscore(std::string who, int rank, int time);
}; // RaceResultGUI
#endif