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
This commit is contained in:
unitraxx 2013-09-11 19:23:54 +00:00
parent cbca9404e3
commit fc45d76d27
5 changed files with 38 additions and 2 deletions

View File

@ -116,6 +116,12 @@ void SingleAchievement::increase(int increase)
check(); check();
} }
// ============================================================================
irr::core::stringw SingleAchievement::getProgressAsString()
{
return StringUtils::toWString(m_progress) + "/" + StringUtils::toWString(((SingleAchievementInfo *) m_achievement_info)->getGoalValue());
}
// ============================================================================ // ============================================================================
MapAchievement::MapAchievement(const AchievementInfo * info) MapAchievement::MapAchievement(const AchievementInfo * info)
: Achievement(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<std::string, int> goal_values = ((MapAchievementInfo *) m_achievement_info)->getGoalValues();
std::map<std::string, int>::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);
}

View File

@ -46,11 +46,13 @@ public:
Achievement (const AchievementInfo * info); Achievement (const AchievementInfo * info);
virtual ~Achievement (); virtual ~Achievement ();
uint32_t getID () const { return m_id; } uint32_t getID () const { return m_id; }
const AchievementInfo * getInfo () const { return m_achievement_info;}
virtual void load (XMLNode * input) = 0; virtual void load (XMLNode * input) = 0;
virtual void save (std::ofstream & out) = 0; virtual void save (std::ofstream & out) = 0;
virtual void reset () = 0; virtual void reset () = 0;
void onRaceEnd (); void onRaceEnd ();
void setAchieved () {m_achieved = true; }; void setAchieved () {m_achieved = true; };
virtual irr::core::stringw getProgressAsString () = 0;
enum AchievementType enum AchievementType
{ {
@ -74,6 +76,7 @@ public:
void save (std::ofstream & out); void save (std::ofstream & out);
void increase (int increase = 1); void increase (int increase = 1);
void reset (); void reset ();
virtual irr::core::stringw getProgressAsString ();
}; // class SingleAchievement }; // class SingleAchievement
class MapAchievement : public Achievement class MapAchievement : public Achievement
@ -90,6 +93,7 @@ public:
void increase (const std::string & key, int increase = 1); void increase (const std::string & key, int increase = 1);
void save (std::ofstream & out); void save (std::ofstream & out);
void reset (); void reset ();
virtual irr::core::stringw getProgressAsString ();
}; // class MapAchievement }; // class MapAchievement
#endif #endif

View File

@ -77,6 +77,7 @@ public:
MapAchievementInfo (const XMLNode * input); MapAchievementInfo (const XMLNode * input);
virtual ~MapAchievementInfo () {}; virtual ~MapAchievementInfo () {};
int getGoalValue (const std::string & key) { return m_goal_values[key];} int getGoalValue (const std::string & key) { return m_goal_values[key];}
const std::map<std::string, int> & getGoalValues() const {return m_goal_values;}
virtual bool checkCompletion (Achievement * achievement) const; virtual bool checkCompletion (Achievement * achievement) const;
virtual Achievement::AchievementType getType() const { return Achievement::AT_MAP; }; virtual Achievement::AchievementType getType() const { return Achievement::AT_MAP; };
}; // class MapAchievementInfo }; // class MapAchievementInfo

View File

@ -55,6 +55,7 @@ public :
void sync(const std::vector<uint32_t> & achieved_ids); void sync(const std::vector<uint32_t> & achieved_ids);
void onRaceEnd(); void onRaceEnd();
const std::string & getID() const {return m_id;} const std::string & getID() const {return m_id;}
const std::map<uint32_t, Achievement *> & getAllAchievements() {return m_achievements;}
Achievement * getAchievement(uint32_t id); Achievement * getAchievement(uint32_t id);
}; };

View File

@ -78,12 +78,21 @@ void OnlineProfileAchievements::init()
assert(m_visiting_profile != NULL); assert(m_visiting_profile != NULL);
if(m_visiting_profile->isCurrentUser()) if(m_visiting_profile->isCurrentUser())
{ {
//fill with local FIXME m_waiting_for_achievements = false;
m_achievements_list_widget->clear();
const std::map<uint32_t, Achievement *> & all_achievements = AchievementsManager::get()->getActive()->getAllAchievements();
std::map<uint32_t, Achievement *>::const_iterator it;
for ( it = all_achievements.begin(); it != all_achievements.end(); ++it ) {
PtrVector<GUIEngine::ListWidget::ListCell> * row = new PtrVector<GUIEngine::ListWidget::ListCell>;
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 else
{ {
m_visiting_profile->fetchAchievements();
m_waiting_for_achievements = true; m_waiting_for_achievements = true;
m_visiting_profile->fetchAchievements();
m_achievements_list_widget->clear(); m_achievements_list_widget->clear();
m_achievements_list_widget->addItem("loading", Messages::fetchingAchievements()); m_achievements_list_widget->addItem("loading", Messages::fetchingAchievements());
} }