From d6f638383382747e1f646500ba668da758d60a9e Mon Sep 17 00:00:00 2001 From: unitraxx Date: Thu, 5 Sep 2013 02:41:08 +0000 Subject: [PATCH] While one issue is fixed, another one popped up. Pretty late, I'll look at it tomorrow. (Feel free to have a look ;) ) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13632 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/achievements/achievement.cpp | 9 +++++---- src/achievements/achievement.hpp | 8 ++++---- src/achievements/achievement_info.hpp | 8 ++++---- src/achievements/achievements_manager.cpp | 6 ++---- src/achievements/achievements_manager.hpp | 2 -- src/achievements/achievements_slot.cpp | 13 ++++++------- src/achievements/achievements_slot.hpp | 6 +++--- src/io/file_manager.cpp | 2 +- 8 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/achievements/achievement.cpp b/src/achievements/achievement.cpp index 71fcd8455..49105f099 100644 --- a/src/achievements/achievement.cpp +++ b/src/achievements/achievement.cpp @@ -32,7 +32,8 @@ #include // ============================================================================ -Achievement::Achievement(AchievementInfo * info) +Achievement::Achievement(const AchievementInfo * info) + :m_achievement_info(info) { m_id = info->getID(); m_achieved = false; @@ -62,7 +63,7 @@ void Achievement::check() //show achievement GUIEngine::DialogQueue::get()->pushDialog( new NotificationDialog(NotificationDialog::T_Achievements, - _("Completed achievement") + '"' + m_achievement_info->getDescription() + '".' + irr::core::stringw(_("Completed achievement")) + irr::core::stringw("\"") + m_achievement_info->getDescription() + irr::core::stringw("\".") )); //send to server Online::CurrentUser::get()->onAchieving(m_id); @@ -71,7 +72,7 @@ void Achievement::check() } // ============================================================================ -SingleAchievement::SingleAchievement(AchievementInfo * info) +SingleAchievement::SingleAchievement(const AchievementInfo * info) : Achievement(info) { } @@ -111,7 +112,7 @@ void SingleAchievement::increase(int increase) } // ============================================================================ -MapAchievement::MapAchievement(AchievementInfo * info) +MapAchievement::MapAchievement(const AchievementInfo * info) : Achievement(info) { } diff --git a/src/achievements/achievement.hpp b/src/achievements/achievement.hpp index f738b6f71..f08b6a1fb 100644 --- a/src/achievements/achievement.hpp +++ b/src/achievements/achievement.hpp @@ -39,11 +39,11 @@ class Achievement protected: uint32_t m_id; bool m_achieved; - AchievementInfo * m_achievement_info; + const AchievementInfo * m_achievement_info; void check (); public: - Achievement (AchievementInfo * info); + Achievement (const AchievementInfo * info); virtual ~Achievement (); uint32_t getID () const { return m_id; } virtual void load (XMLNode * input) = 0; @@ -65,7 +65,7 @@ protected: int m_progress; public: - SingleAchievement (AchievementInfo * info); + SingleAchievement (const AchievementInfo * info); virtual ~SingleAchievement () {}; void load (XMLNode * input); @@ -81,7 +81,7 @@ protected: std::map m_progress_map; public: - MapAchievement (AchievementInfo * info); + MapAchievement (const AchievementInfo * info); virtual ~MapAchievement () {}; void load (XMLNode * input); diff --git a/src/achievements/achievement_info.hpp b/src/achievements/achievement_info.hpp index 8cfadf64c..f52a45039 100644 --- a/src/achievements/achievement_info.hpp +++ b/src/achievements/achievement_info.hpp @@ -48,9 +48,9 @@ public: virtual ~AchievementInfo () {}; uint32_t getID () const { return m_id; } irr::core::stringw getDescription () const { return m_description; } - virtual Achievement::AchievementType getType () = 0; + virtual Achievement::AchievementType getType () const = 0; virtual bool checkCompletion (Achievement * achievement) const = 0; - bool needsResetAfterRace() {return m_reset_after_race; } + bool needsResetAfterRace() const {return m_reset_after_race; } }; // class AchievementInfo class SingleAchievementInfo : public AchievementInfo @@ -64,7 +64,7 @@ public: int getGoalValue () const { return m_goal_value; } virtual bool checkCompletion (Achievement * achievement) const; - virtual Achievement::AchievementType getType() { return Achievement::AT_SINGLE; }; + virtual Achievement::AchievementType getType() const { return Achievement::AT_SINGLE; }; }; // class SingleAchievementInfo class MapAchievementInfo : public AchievementInfo @@ -78,7 +78,7 @@ public: int getGoalValue (const std::string & key) { return m_goal_values[key];} virtual bool checkCompletion (Achievement * achievement) const; - virtual Achievement::AchievementType getType() { return Achievement::AT_MAP; }; + virtual Achievement::AchievementType getType() const { return Achievement::AT_MAP; }; }; // class MapAchievementInfo #endif diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp index 42a1320a2..50cb1a871 100644 --- a/src/achievements/achievements_manager.cpp +++ b/src/achievements/achievements_manager.cpp @@ -104,8 +104,6 @@ void AchievementsManager::parseConfigFile() Log::info("AchievementsManager", "Achievements file '%s' will be created.", filename.c_str()); createSlotsIfNeeded(); - save(); - if (root) delete root; return; } @@ -114,7 +112,7 @@ void AchievementsManager::parseConfigFile() root->getNodes("slot", xml_slots); for (unsigned int n=0; n < xml_slots.size(); n++) { - AchievementsSlot * slot = new AchievementsSlot(xml_slots[n]); + AchievementsSlot * slot = new AchievementsSlot(xml_slots[n], m_achievements_info); if(!slot->isValid()) { Log::warn("AchievementsManager", "Found game slot with faulty or missing information. Discarding it."); @@ -129,7 +127,7 @@ void AchievementsManager::parseConfigFile() AchievementsSlot * AchievementsManager::createNewSlot(std::string id, bool online) { - AchievementsSlot* slot = new AchievementsSlot(id, false); + AchievementsSlot* slot = new AchievementsSlot(id, false, m_achievements_info); m_slots.push_back(slot); return slot; } diff --git a/src/achievements/achievements_manager.hpp b/src/achievements/achievements_manager.hpp index fcaa68634..e0c391158 100644 --- a/src/achievements/achievements_manager.hpp +++ b/src/achievements/achievements_manager.hpp @@ -52,8 +52,6 @@ public: static AchievementsManager * get(); static void deallocate(); - const PtrVector & getAllInfo() const { return m_achievements_info;}; - void parseDataFile(); void parseConfigFile(); void save(); diff --git a/src/achievements/achievements_slot.cpp b/src/achievements/achievements_slot.cpp index a598d1110..e38a93968 100644 --- a/src/achievements/achievements_slot.cpp +++ b/src/achievements/achievements_slot.cpp @@ -31,7 +31,7 @@ #include #include // ============================================================================ -AchievementsSlot::AchievementsSlot(const XMLNode * input) +AchievementsSlot::AchievementsSlot(const XMLNode * input, const PtrVector & info) { int fetched_user_id = input->get("user_id", &m_id); std::string online; @@ -43,7 +43,7 @@ AchievementsSlot::AchievementsSlot(const XMLNode * input) m_valid = true; m_online = online == "true"; - createFreshSlot(); + createFreshSlot(info); std::vector xml_achievements; input->getNodes("achievement", xml_achievements); @@ -62,23 +62,22 @@ AchievementsSlot::AchievementsSlot(const XMLNode * input) } // ============================================================================ -AchievementsSlot::AchievementsSlot(std::string id, bool online) +AchievementsSlot::AchievementsSlot(std::string id, bool online, const PtrVector & info) { m_valid = true; m_online = online; m_id = id; - createFreshSlot(); + createFreshSlot(info); } // ============================================================================ -void AchievementsSlot::createFreshSlot() +void AchievementsSlot::createFreshSlot( const PtrVector & all_info) { m_achievements.clear(); - PtrVector all_info = AchievementsManager::get()->getAllInfo(); for(int i=0; i < all_info.size(); i++) { - AchievementInfo * info = all_info.get(i); + const AchievementInfo * info = all_info.get(i); Achievement::AchievementType achievement_type = info->getType(); Achievement * achievement; if(achievement_type == Achievement::AT_SINGLE) diff --git a/src/achievements/achievements_slot.hpp b/src/achievements/achievements_slot.hpp index 34cea7cfc..9dff409d0 100644 --- a/src/achievements/achievements_slot.hpp +++ b/src/achievements/achievements_slot.hpp @@ -35,11 +35,11 @@ private: bool m_valid; std::string m_id; - void createFreshSlot(); + void createFreshSlot( const PtrVector & info); public : - AchievementsSlot(const XMLNode * input); - AchievementsSlot(std::string id, bool online); + AchievementsSlot(const XMLNode * input, const PtrVector & info); + AchievementsSlot(std::string id, bool online, const PtrVector & info); bool isValid() const { return m_valid;} void save(std::ofstream & out); bool isOnline() const {return m_online;} diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 42c27f760..f44567998 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -916,7 +916,7 @@ std::string FileManager::getFontFile(const std::string& file_name) const */ std::string FileManager::getConfigFile(const std::string &file_name) const { - return getConfigDir()+"/"+file_name; + return getConfigDir()+file_name; } // getChallengeFile