From 870c470eab7aea6f512af1654e5800b9cbbcb7cf Mon Sep 17 00:00:00 2001 From: auria Date: Sat, 29 Aug 2009 18:12:31 +0000 Subject: [PATCH] Highscores are now displayed in the track screen git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3951 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/modes/follow_the_leader.cpp | 2 +- src/modes/follow_the_leader.hpp | 1 + src/modes/standard_race.cpp | 5 ++- src/modes/three_strikes_battle.cpp | 2 +- src/modes/three_strikes_battle.hpp | 1 + src/race/race_manager.hpp | 19 +++++++++ .../dialogs/track_info_dialog.cpp | 42 ++++++++++++++++++- 7 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/modes/follow_the_leader.cpp b/src/modes/follow_the_leader.cpp index 8bac57fee..1d88c8b7c 100644 --- a/src/modes/follow_the_leader.cpp +++ b/src/modes/follow_the_leader.cpp @@ -143,7 +143,7 @@ void FollowTheLeaderRace::restartRace() */ std::string FollowTheLeaderRace::getIdent() const { - return "FOLLOW_LEADER"; + return FTL_IDENT; } //----------------------------------------------------------------------------- RaceGUI::KartIconDisplayInfo* FollowTheLeaderRace::getKartsDisplayInfo() diff --git a/src/modes/follow_the_leader.hpp b/src/modes/follow_the_leader.hpp index ba0194c24..d10bc3bc2 100644 --- a/src/modes/follow_the_leader.hpp +++ b/src/modes/follow_the_leader.hpp @@ -25,6 +25,7 @@ class FollowTheLeaderRace : public LinearWorld { std::vector m_leader_intervals; // time till elimination in follow leader public: + FollowTheLeaderRace(); virtual ~FollowTheLeaderRace(); diff --git a/src/modes/standard_race.cpp b/src/modes/standard_race.cpp index 1b49926fe..ffde4c84b 100644 --- a/src/modes/standard_race.cpp +++ b/src/modes/standard_race.cpp @@ -123,7 +123,8 @@ bool StandardRace::haveBonusBoxes() std::string StandardRace::getIdent() const { if(race_manager->getMinorMode() == RaceManager::MINOR_MODE_TIME_TRIAL) - return "STD_TIMETRIAL"; + return IDENT_TTRIAL; else - return "STANDARD"; + return IDENT_STD; + } // getIdent diff --git a/src/modes/three_strikes_battle.cpp b/src/modes/three_strikes_battle.cpp index 4d68dac3d..baac9aabb 100644 --- a/src/modes/three_strikes_battle.cpp +++ b/src/modes/three_strikes_battle.cpp @@ -129,7 +129,7 @@ void ThreeStrikesBattle::kartHit(const int kart_id) */ std::string ThreeStrikesBattle::getIdent() const { - return "BATTLE_3_STRIKES"; + return STRIKES_IDENT; } // getIdent //----------------------------------------------------------------------------- diff --git a/src/modes/three_strikes_battle.hpp b/src/modes/three_strikes_battle.hpp index a50d5c76c..b50cb6747 100644 --- a/src/modes/three_strikes_battle.hpp +++ b/src/modes/three_strikes_battle.hpp @@ -39,6 +39,7 @@ class ThreeStrikesBattle : public World std::vector m_kart_info; public: + ThreeStrikesBattle(); virtual ~ThreeStrikesBattle(); diff --git a/src/race/race_manager.hpp b/src/race/race_manager.hpp index d486449f2..2f0b6502a 100644 --- a/src/race/race_manager.hpp +++ b/src/race/race_manager.hpp @@ -87,6 +87,25 @@ public: MINOR_MODE_3_STRIKES = BATTLE_ARENA(0) }; + + // Stupid C++ doesn't accept string constants + #define IDENT_STD "STANDARD" + #define IDENT_TTRIAL "STD_TIMETRIAL" + #define FTL_IDENT "FOLLOW_LEADER" + #define STRIKES_IDENT "BATTLE_3_STRIKES" + + static const char* getIdentOf(const MinorRaceModeType mode) + { + switch (mode) + { + case MINOR_MODE_QUICK_RACE: return IDENT_STD; + case MINOR_MODE_TIME_TRIAL: return IDENT_TTRIAL; + case MINOR_MODE_FOLLOW_LEADER: return FTL_IDENT; + case MINOR_MODE_3_STRIKES: return STRIKES_IDENT; + default: assert(false); return NULL; + } + } + #undef LINEAR_RACE #undef BATTLE_ARENA diff --git a/src/states_screens/dialogs/track_info_dialog.cpp b/src/states_screens/dialogs/track_info_dialog.cpp index d257133a2..965e83a9d 100644 --- a/src/states_screens/dialogs/track_info_dialog.cpp +++ b/src/states_screens/dialogs/track_info_dialog.cpp @@ -19,6 +19,8 @@ #include "guiengine/engine.hpp" #include "guiengine/widget.hpp" #include "network/network_manager.hpp" +#include "race/highscores.hpp" +#include "race/highscore_manager.hpp" #include "race/race_manager.hpp" #include "states_screens/dialogs/track_info_dialog.hpp" #include "states_screens/state_manager.hpp" @@ -74,9 +76,45 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const char* trac m_irrlicht_window); a->setTabStop(false); + // ======== High Scores + std::string game_mode_ident = RaceManager::getIdentOf( race_manager->getMinorMode() ); + const HighscoreEntry::HighscoreType type = "HST_" + game_mode_ident; + + HighscoreEntry* highscores = highscore_manager->getHighscoreEntry(type, + race_manager->getNumKarts(), + race_manager->getDifficulty(), + trackIdent, + race_manager->getNumLaps()); + + // TODO: update highscores display when number of laps changes + const int amount = highscores->getNumberEntries(); + stringw highscores_string = "= Highscores =\n"; + std::cout << "====== Highscores =====\n"; + std::cout << "Checking for highscores of type " << type.c_str() << " with nkarts=" << race_manager->getNumKarts() + << ", difficulty=" << race_manager->getDifficulty() << ", track=" << trackIdent.c_str() + << ", nlaps=" << race_manager->getNumLaps() << std::endl; + std::cout << "Got " << amount << " entries\n"; + + std::string kart_name; + std::string name; + float time; + + char buffer[512]; + for (int n=0; ngetEntry(n, kart_name, name, &time); + + sprintf(buffer, "%s (%s) : %.2f\n", kart_name.c_str(), name.c_str(), time); + + std::cout << buffer << std::endl; + highscores_string += buffer; + } + std::cout << "======================\n"; + + core::rect< s32 > area_left(0, y1, m_area.getWidth()/2, y2); - IGUIStaticText* b = GUIEngine::getGUIEnv()->addStaticText( stringw(_("High Scores & Track Info")).c_str(), + IGUIStaticText* b = GUIEngine::getGUIEnv()->addStaticText( highscores_string.c_str(), area_left, false , true , // border, word warp m_irrlicht_window); b->setTabStop(false); @@ -93,7 +131,7 @@ TrackInfoDialog::TrackInfoDialog(const std::string& trackIdent, const char* trac a->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); b->setTextAlignment(EGUIA_CENTER, EGUIA_CENTER); - + } // ------------------------------------------------------------------------------------------------------