diff --git a/data/achievements.xml b/data/achievements.xml
index edc8c7345..e19b1824e 100644
--- a/data/achievements.xml
+++ b/data/achievements.xml
@@ -1,8 +1,16 @@
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/src/achievements/achievement.cpp b/src/achievements/achievement.cpp
index e7f8394fb..71fcd8455 100644
--- a/src/achievements/achievement.cpp
+++ b/src/achievements/achievement.cpp
@@ -20,6 +20,8 @@
#include "achievements/achievement.hpp"
#include "achievements/achievement_info.hpp"
+#include "guiengine/dialog_queue.hpp"
+#include "states_screens/dialogs/notification_dialog.hpp"
#include "io/xml_writer.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
@@ -58,7 +60,12 @@ void Achievement::check()
if(m_achievement_info->checkCompletion(this))
{
//show achievement
+ GUIEngine::DialogQueue::get()->pushDialog(
+ new NotificationDialog(NotificationDialog::T_Achievements,
+ _("Completed achievement") + '"' + m_achievement_info->getDescription() + '".'
+ ));
//send to server
+ Online::CurrentUser::get()->onAchieving(m_id);
m_achieved = true;
}
}
@@ -100,6 +107,7 @@ void SingleAchievement::reset()
void SingleAchievement::increase(int increase)
{
m_progress += increase;
+ check();
}
// ============================================================================
@@ -164,6 +172,9 @@ void MapAchievement::reset()
void MapAchievement::increase(const std::string & key, int increase)
{
if ( m_progress_map.find(key) != m_progress_map.end())
+ {
m_progress_map[key] += increase;
+ check();
+ }
}
diff --git a/src/achievements/achievements_manager.cpp b/src/achievements/achievements_manager.cpp
index 441d433cd..42a1320a2 100644
--- a/src/achievements/achievements_manager.cpp
+++ b/src/achievements/achievements_manager.cpp
@@ -57,6 +57,7 @@ AchievementsManager::AchievementsManager()
// ============================================================================
AchievementsManager::~AchievementsManager()
{
+ save();
m_slots.clearAndDeleteAll();
m_achievements_info.clearAndDeleteAll();
}
@@ -122,10 +123,6 @@ void AchievementsManager::parseConfigFile()
}
m_slots.push_back(slot);
}
-
- bool something_changed = createSlotsIfNeeded();
- if (something_changed) save();
-
delete root;
} // load
@@ -142,7 +139,7 @@ AchievementsSlot * AchievementsManager::createNewSlot(std::string id, bool onlin
/** Creates a slot for players that don't have one yet
* \return true if any were created
*/
-bool AchievementsManager::createSlotsIfNeeded()
+void AchievementsManager::createSlotsIfNeeded()
{
bool something_changed = false;
@@ -157,7 +154,7 @@ bool AchievementsManager::createSlotsIfNeeded()
}
}
- return something_changed;
+ if(something_changed) save();
} // UnlockManager::createSlotsIfNeeded
@@ -212,13 +209,13 @@ AchievementsSlot * AchievementsManager::getSlot(const std::string & id, bool onl
// ============================================================================
void AchievementsManager::updateCurrentPlayer()
{
+ createSlotsIfNeeded();
if(Online::CurrentUser::get()->isRegisteredUser())
{
m_active_slot = getSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true);
if(m_active_slot == NULL)
{
m_active_slot = createNewSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true);
- m_active_slot->sync();
}
}
else
diff --git a/src/achievements/achievements_manager.hpp b/src/achievements/achievements_manager.hpp
index 680983874..fcaa68634 100644
--- a/src/achievements/achievements_manager.hpp
+++ b/src/achievements/achievements_manager.hpp
@@ -45,7 +45,6 @@ private :
PtrVector m_achievements_info;
AchievementsManager ();
~AchievementsManager ();
- bool createSlotsIfNeeded();
AchievementsSlot * createNewSlot(std::string id, bool online);
public:
@@ -60,7 +59,9 @@ public:
void save();
void onRaceEnd();
void updateCurrentPlayer();
+ AchievementsSlot * getActive() const { return m_active_slot; }
AchievementsSlot * getSlot(const std::string & id, bool online);
+ void createSlotsIfNeeded();
}; // class AchievementsManager
#endif
diff --git a/src/achievements/achievements_slot.cpp b/src/achievements/achievements_slot.cpp
index 032a54ee2..a598d1110 100644
--- a/src/achievements/achievements_slot.cpp
+++ b/src/achievements/achievements_slot.cpp
@@ -51,7 +51,7 @@ AchievementsSlot::AchievementsSlot(const XMLNode * input)
{
uint32_t achievement_id(0);
xml_achievements[i]->get("id", &achievement_id);
- Achievement * achievement = findAchievement(achievement_id);
+ Achievement * achievement = getAchievement(achievement_id);
if(achievement == NULL)
{
Log::warn("AchievementsSlot", "Found saved achievement data for a non-existent achievement. Discarding.");
@@ -109,7 +109,7 @@ void AchievementsSlot::save(std::ofstream & out)
}
// ============================================================================
-Achievement * AchievementsSlot::findAchievement(uint32_t id)
+Achievement * AchievementsSlot::getAchievement(uint32_t id)
{
if ( m_achievements.find(id) != m_achievements.end())
return m_achievements[id];
diff --git a/src/achievements/achievements_slot.hpp b/src/achievements/achievements_slot.hpp
index 89ff4931e..34cea7cfc 100644
--- a/src/achievements/achievements_slot.hpp
+++ b/src/achievements/achievements_slot.hpp
@@ -46,7 +46,7 @@ public :
void sync();
void onRaceEnd();
const std::string & getID() const {return m_id;}
- Achievement * findAchievement(uint32_t id);
+ Achievement * getAchievement(uint32_t id);
};
#endif
diff --git a/src/main.cpp b/src/main.cpp
index 3dc95f53d..bee57504e 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1242,15 +1242,17 @@ void cleanSuperTuxKart()
if(INetworkHttp::get())
INetworkHttp::get()->stopNetworkThread();
- if(Online::HTTPManager::isRunning())
- Online::HTTPManager::get()->stopNetworkThread();
//delete in reverse order of what they were created in.
//see InitTuxkart()
Online::ServersManager::deallocate();
Online::ProfileManager::deallocate();
+ AchievementsManager::deallocate();
Online::CurrentUser::deallocate();
GUIEngine::DialogQueue::deallocate();
+ if(Online::HTTPManager::isRunning())
+ Online::HTTPManager::get()->stopNetworkThread();
+
Referee::cleanup();
if(ReplayPlay::get()) ReplayPlay::destroy();
@@ -1365,6 +1367,7 @@ int main(int argc, char *argv[] )
file_manager->getGUIDir() + "options_video.png") );
kart_properties_manager -> loadAllKarts ();
unlock_manager = new UnlockManager();
+ AchievementsManager::get();
//m_tutorial_manager = new TutorialManager();
GUIEngine::addLoadingIcon( irr_driver->getTexture(
file_manager->getTextureFile("gui_lock.png")) );
diff --git a/src/online/current_user.cpp b/src/online/current_user.cpp
index 1e33e9fd9..bf5e2f461 100644
--- a/src/online/current_user.cpp
+++ b/src/online/current_user.cpp
@@ -19,6 +19,7 @@
#include "online/current_user.hpp"
+#include "achievements/achievements_manager.hpp"
#include "addons/addons_manager.hpp"
#include "config/user_config.hpp"
#include "online/servers_manager.hpp"
@@ -152,6 +153,8 @@ namespace Online{
UserConfigParams::m_saved_session = true;
}
ProfileManager::get()->addPersistent(m_profile);
+ AchievementsManager::get()->updateCurrentPlayer();
+ AchievementsManager::get()->getActive()->sync();
m_profile->fetchFriends();
}
else
@@ -229,6 +232,7 @@ namespace Online{
UserConfigParams::m_saved_user = 0;
UserConfigParams::m_saved_token = "";
UserConfigParams::m_saved_session = false;
+ AchievementsManager::get()->updateCurrentPlayer();
}
void CurrentUser::SignOutRequest::callback()
@@ -627,6 +631,23 @@ namespace Online{
}
}
+
+ // ============================================================================
+
+ void CurrentUser::onAchieving(uint32_t achievement_id) const
+ {
+ if(isRegisteredUser())
+ {
+ HTTPRequest * request = new HTTPRequest(true);
+ request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
+ request->setParameter("action", std::string("achieving"));
+ request->setParameter("token", getToken());
+ request->setParameter("userid", getID());
+ request->setParameter("achievementid", achievement_id);
+ HTTPManager::get()->addRequest(request);
+ }
+ }
+
// ============================================================================
irr::core::stringw CurrentUser::getUserName() const
{
diff --git a/src/online/current_user.hpp b/src/online/current_user.hpp
index 95778b6f4..2c0b838e9 100644
--- a/src/online/current_user.hpp
+++ b/src/online/current_user.hpp
@@ -170,6 +170,7 @@ namespace Online{
const XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const;
void onSTKQuit() const;
+ void onAchieving(uint32_t achievement_id) const;
/** Returns the username if signed in. */
irr::core::stringw getUserName() const;
diff --git a/src/states_screens/dialogs/notification_dialog.cpp b/src/states_screens/dialogs/notification_dialog.cpp
index 70443244b..b080ee447 100644
--- a/src/states_screens/dialogs/notification_dialog.cpp
+++ b/src/states_screens/dialogs/notification_dialog.cpp
@@ -129,6 +129,11 @@ void NotificationDialog::onUpdate(float dt)
ProfileManager::get()->setVisiting(CurrentUser::get()->getID());
StateManager::get()->pushScreen(OnlineProfileFriends::getInstance());
}
+ else if (m_type == T_Achievements)
+ {
+ ProfileManager::get()->setVisiting(CurrentUser::get()->getID());
+ StateManager::get()->pushScreen(OnlineProfileFriends::getInstance()); //FIXME should actually pop up achievements screen
+ }
}
return;
}
diff --git a/src/states_screens/dialogs/notification_dialog.hpp b/src/states_screens/dialogs/notification_dialog.hpp
index 149c92b14..70bbcf598 100644
--- a/src/states_screens/dialogs/notification_dialog.hpp
+++ b/src/states_screens/dialogs/notification_dialog.hpp
@@ -36,7 +36,8 @@ class NotificationDialog : public GUIEngine::ModalDialog
public:
enum Type
{
- T_Friends = 1
+ T_Friends = 1,
+ T_Achievements = 2
};
private: