Fix #3513
This commit is contained in:
@@ -75,23 +75,26 @@ irr::core::stringw Achievement::getGoalProgressAsString()
|
||||
{
|
||||
irr::core::stringw target = getInfo()->goalString();
|
||||
|
||||
// Return N/N in case of an achieved achievement.
|
||||
if (m_achieved)
|
||||
return target + "/" + target;
|
||||
|
||||
int fullfiled_goals = computeFullfiledGoals(m_progress_goal_tree, m_achievement_info->m_goal_tree);
|
||||
|
||||
return StringUtils::toWString(fullfiled_goals) + "/" + target;
|
||||
return StringUtils::toWString(getFullfiledGoals()) + "/" + target;
|
||||
} // getGoalProgressAsString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns how many goals of an achievement have been achieved.
|
||||
*/
|
||||
int Achievement::getFullfiledGoals()
|
||||
{
|
||||
int fullfiled_goals = (m_achieved) ? getInfo()->getGoalCount() :
|
||||
computeFullfiledGoals(m_progress_goal_tree, m_achievement_info->m_goal_tree);
|
||||
return fullfiled_goals;
|
||||
} // getFullfiledGoals
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int Achievement::computeFullfiledGoals(AchievementInfo::goalTree &progress, AchievementInfo::goalTree &reference)
|
||||
{
|
||||
|
||||
if (progress.children.size() != 1)
|
||||
{
|
||||
// This always returns 0 if the achievement has not been completed
|
||||
if (progress.children[0].type == "OR")
|
||||
if (progress.children.size() != 0 && progress.children[0].type == "OR")
|
||||
{
|
||||
bool completed = false;
|
||||
for (unsigned int i=0;i<progress.children.size();i++)
|
||||
@@ -141,15 +144,20 @@ irr::core::stringw Achievement::getProgressAsString()
|
||||
if (target == "-1")
|
||||
return empty;
|
||||
|
||||
// Return N/N in case of an achieved achievement.
|
||||
if (m_achieved)
|
||||
return target + "/" + target;
|
||||
|
||||
int progress = computeGoalProgress(m_progress_goal_tree, m_achievement_info->m_goal_tree);
|
||||
|
||||
return StringUtils::toWString(progress) + "/" + target;
|
||||
return StringUtils::toWString(getProgress()) + "/" + target;
|
||||
} // getProgressAsString
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Returns how many goals of an achievement have been achieved.
|
||||
*/
|
||||
int Achievement::getProgress()
|
||||
{
|
||||
int progress = (m_achieved) ? getInfo()->getProgressTarget() :
|
||||
computeGoalProgress(m_progress_goal_tree, m_achievement_info->m_goal_tree);
|
||||
return progress;
|
||||
} // getProgress
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Should ONLY be called if the achievement has one goal (a sum counts as one goal).
|
||||
* Returning an error code with a number is not full-proof because a sum goal can
|
||||
@@ -163,7 +171,7 @@ int Achievement::computeGoalProgress(AchievementInfo::goalTree &progress, Achiev
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
// Can happen when showing the progress status of all parts of the goal tree
|
||||
// Can happen when showing the progress status of all parts fof the goal tree
|
||||
else if (progress.children.size() == 0)
|
||||
{
|
||||
//TODO : find a more automatic way ; clean up repetition
|
||||
|
||||
@@ -82,6 +82,8 @@ public:
|
||||
|
||||
uint32_t getID() const { return m_id; }
|
||||
AchievementInfo * getInfo() { return m_achievement_info; }
|
||||
int getFullfiledGoals();
|
||||
int getProgress();
|
||||
|
||||
void setAchieved() { m_achieved = true; };
|
||||
bool isAchieved() const { return m_achieved; }
|
||||
|
||||
@@ -87,6 +87,8 @@ public:
|
||||
virtual irr::core::stringw goalString();
|
||||
virtual irr::core::stringw progressString();
|
||||
|
||||
int getProgressTarget() { return recursiveProgressCount(m_goal_tree); }
|
||||
int getGoalCount() { return recursiveGoalCount(m_goal_tree); }
|
||||
int getDepth() { return getRecursiveDepth(m_goal_tree); }
|
||||
uint32_t getID() const { return m_id; }
|
||||
irr::core::stringw getDescription() const { return _(m_description.c_str()); }
|
||||
|
||||
@@ -195,22 +195,17 @@ void BaseOnlineProfileAchievements::displayResults()
|
||||
all_achievements_list.push_back(it->second);
|
||||
}
|
||||
|
||||
auto compAchievement = [=](Achievement *a, Achievement *b) {
|
||||
auto compAchievement = [=](Achievement *a, Achievement *b)
|
||||
{
|
||||
// Sort by name
|
||||
if (m_sort_column == 0)
|
||||
{
|
||||
// Sort by name
|
||||
return a->getInfo()->getName().lower_ignore_case(b->getInfo()->getName());
|
||||
}
|
||||
// Sort by goals
|
||||
else if (m_sort_column == 1)
|
||||
{
|
||||
// Sort by goals
|
||||
return a->getInfo()->goalString().lower_ignore_case(b->getInfo()->goalString());
|
||||
}
|
||||
return goalSort(a, b);
|
||||
// Sort by progress
|
||||
else
|
||||
{
|
||||
// Sort by progress
|
||||
return a->getProgressAsString().lower_ignore_case(b->getProgressAsString());
|
||||
}
|
||||
return progressSort(a, b);
|
||||
};
|
||||
|
||||
if (m_sort_desc && !m_sort_default)
|
||||
@@ -271,6 +266,39 @@ void BaseOnlineProfileAchievements::displayResults()
|
||||
}
|
||||
} // displayResults
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** True if a's goal progression is <= to b's.
|
||||
* If they are equal, goalSort(a,b) != goalSort(b,a),
|
||||
ù as the bool can't handle the 3 values required to avoid this
|
||||
*/
|
||||
bool BaseOnlineProfileAchievements::goalSort(Achievement *a, Achievement *b)
|
||||
{
|
||||
float goals_a = ((float) a->getFullfiledGoals()) / a->getInfo()->getGoalCount();
|
||||
float goals_b = ((float) b->getFullfiledGoals()) / b->getInfo()->getGoalCount();
|
||||
if (goals_a == goals_b)
|
||||
return (a->getInfo()->getGoalCount() < b->getInfo()->getGoalCount());
|
||||
else
|
||||
return (goals_a < goals_b);
|
||||
} // goalSort
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** True if a's single-goal progress is <= to b's.
|
||||
*/
|
||||
bool BaseOnlineProfileAchievements::progressSort(Achievement *a, Achievement *b)
|
||||
{
|
||||
if (a->getInfo()->getGoalCount() >= 2)
|
||||
return true;
|
||||
else if (b->getInfo()->getGoalCount() >= 2)
|
||||
return false;
|
||||
|
||||
float progress_a = ((float) a->getProgress()) / a->getInfo()->getProgressTarget();
|
||||
float progress_b = ((float) b->getProgress()) / b->getInfo()->getProgressTarget();
|
||||
if (progress_a == progress_b)
|
||||
return (a->getInfo()->getProgressTarget() < b->getInfo()->getProgressTarget());
|
||||
else
|
||||
return (progress_a < progress_b);
|
||||
} // progressSort
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Called every frame. It will check if results from an achievement request
|
||||
* have been received, and if so, display them.
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <string>
|
||||
#include <irrString.h>
|
||||
|
||||
#include "achievements/achievement.hpp"
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets.hpp"
|
||||
#include "states_screens/online/online_profile_base.hpp"
|
||||
@@ -53,6 +54,9 @@ private:
|
||||
bool m_sort_default;
|
||||
|
||||
void displayResults();
|
||||
// True if a > b
|
||||
bool goalSort(Achievement *a, Achievement *b);
|
||||
bool progressSort(Achievement *a, Achievement *b);
|
||||
|
||||
protected:
|
||||
BaseOnlineProfileAchievements(const std::string &filename);
|
||||
|
||||
Reference in New Issue
Block a user