From fc45d76d279693cc5c5a6a4cbbda68d39677577b Mon Sep 17 00:00:00 2001 From: unitraxx Date: Wed, 11 Sep 2013 19:23:54 +0000 Subject: [PATCH] Special case for viewing your own achievements. (Shows the progress) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13662 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/achievements/achievement.cpp | 21 +++++++++++++++++++ src/achievements/achievement.hpp | 4 ++++ src/achievements/achievement_info.hpp | 1 + src/achievements/achievements_slot.hpp | 1 + .../online_profile_achievements.cpp | 13 ++++++++++-- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/achievements/achievement.cpp b/src/achievements/achievement.cpp index 4738d27c5..5f46c1121 100644 --- a/src/achievements/achievement.cpp +++ b/src/achievements/achievement.cpp @@ -116,6 +116,12 @@ void SingleAchievement::increase(int increase) check(); } +// ============================================================================ +irr::core::stringw SingleAchievement::getProgressAsString() +{ + return StringUtils::toWString(m_progress) + "/" + StringUtils::toWString(((SingleAchievementInfo *) m_achievement_info)->getGoalValue()); +} + // ============================================================================ MapAchievement::MapAchievement(const AchievementInfo * info) : Achievement(info) @@ -187,3 +193,18 @@ void MapAchievement::increase(const std::string & key, int increase) } } +// ============================================================================ +irr::core::stringw MapAchievement::getProgressAsString() +{ + int progress(0); + int goal(0); + const std::map goal_values = ((MapAchievementInfo *) m_achievement_info)->getGoalValues(); + std::map::const_iterator iter; + for ( iter = goal_values.begin(); iter != goal_values.end(); ++iter ) { + goal += iter->second; + progress += m_progress_map[iter->first]; + Log::info("ach","%s",iter->first.c_str()); + } + return StringUtils::toWString(progress) + "/" + StringUtils::toWString(goal); +} + diff --git a/src/achievements/achievement.hpp b/src/achievements/achievement.hpp index 22ac25658..8da035877 100644 --- a/src/achievements/achievement.hpp +++ b/src/achievements/achievement.hpp @@ -46,11 +46,13 @@ public: Achievement (const AchievementInfo * info); virtual ~Achievement (); uint32_t getID () const { return m_id; } + const AchievementInfo * getInfo () const { return m_achievement_info;} virtual void load (XMLNode * input) = 0; virtual void save (std::ofstream & out) = 0; virtual void reset () = 0; void onRaceEnd (); void setAchieved () {m_achieved = true; }; + virtual irr::core::stringw getProgressAsString () = 0; enum AchievementType { @@ -74,6 +76,7 @@ public: void save (std::ofstream & out); void increase (int increase = 1); void reset (); + virtual irr::core::stringw getProgressAsString (); }; // class SingleAchievement class MapAchievement : public Achievement @@ -90,6 +93,7 @@ public: void increase (const std::string & key, int increase = 1); void save (std::ofstream & out); void reset (); + virtual irr::core::stringw getProgressAsString (); }; // class MapAchievement #endif diff --git a/src/achievements/achievement_info.hpp b/src/achievements/achievement_info.hpp index 847ac4316..626e1d132 100644 --- a/src/achievements/achievement_info.hpp +++ b/src/achievements/achievement_info.hpp @@ -77,6 +77,7 @@ public: MapAchievementInfo (const XMLNode * input); virtual ~MapAchievementInfo () {}; int getGoalValue (const std::string & key) { return m_goal_values[key];} + const std::map & getGoalValues() const {return m_goal_values;} virtual bool checkCompletion (Achievement * achievement) const; virtual Achievement::AchievementType getType() const { return Achievement::AT_MAP; }; }; // class MapAchievementInfo diff --git a/src/achievements/achievements_slot.hpp b/src/achievements/achievements_slot.hpp index 6ddf28972..97ed65d72 100644 --- a/src/achievements/achievements_slot.hpp +++ b/src/achievements/achievements_slot.hpp @@ -55,6 +55,7 @@ public : void sync(const std::vector & achieved_ids); void onRaceEnd(); const std::string & getID() const {return m_id;} + const std::map & getAllAchievements() {return m_achievements;} Achievement * getAchievement(uint32_t id); }; diff --git a/src/states_screens/online_profile_achievements.cpp b/src/states_screens/online_profile_achievements.cpp index ef3798d5f..532d5d362 100644 --- a/src/states_screens/online_profile_achievements.cpp +++ b/src/states_screens/online_profile_achievements.cpp @@ -78,12 +78,21 @@ void OnlineProfileAchievements::init() assert(m_visiting_profile != NULL); if(m_visiting_profile->isCurrentUser()) { - //fill with local FIXME + m_waiting_for_achievements = false; + m_achievements_list_widget->clear(); + const std::map & all_achievements = AchievementsManager::get()->getActive()->getAllAchievements(); + std::map::const_iterator it; + for ( it = all_achievements.begin(); it != all_achievements.end(); ++it ) { + PtrVector * row = new PtrVector; + row->push_back(new GUIEngine::ListWidget::ListCell(it->second->getInfo()->getTitle(),-1,2)); + row->push_back(new GUIEngine::ListWidget::ListCell(it->second->getProgressAsString(),-1,1, true)); + m_achievements_list_widget->addItem(StringUtils::toString(it->second->getInfo()->getID()), row); + } } else { - m_visiting_profile->fetchAchievements(); m_waiting_for_achievements = true; + m_visiting_profile->fetchAchievements(); m_achievements_list_widget->clear(); m_achievements_list_widget->addItem("loading", Messages::fetchingAchievements()); }