Even more achievements stuff. Unlock manager is a mess!
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13630 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
178fc8613d
commit
03be63ea5b
@ -1,8 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<achievements>
|
||||
<achievement id="1" type="map" title="Christoffel Columbus" description="Play every official track at least once." >
|
||||
<entry key="mapid1" goal="1"/>
|
||||
<entry key="mapid2" goal="1"/>
|
||||
<entry key="farm" goal="1"/>
|
||||
<entry key="scotland" goal="1"/>
|
||||
<entry key="lighthouse" goal="1"/>
|
||||
<entry key="sandtrack" goal="1"/>
|
||||
<entry key="olivermath" goal="1"/>
|
||||
<entry key="subsea" goal="1"/>
|
||||
<entry key="mansion" goal="1"/>
|
||||
<entry key="minigolf" goal="1"/>
|
||||
<entry key="hacienda" goal="1"/>
|
||||
<entry key="jungle" goal="1"/>
|
||||
</achievement>
|
||||
<achievement id="2" type="single" goal="1" title="Strike!" description="Hit a kart with a bowling-ball." />
|
||||
</achievements>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -45,7 +45,6 @@ private :
|
||||
PtrVector<AchievementInfo> 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
|
||||
|
@ -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];
|
||||
|
@ -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
|
||||
|
@ -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")) );
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -36,7 +36,8 @@ class NotificationDialog : public GUIEngine::ModalDialog
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
T_Friends = 1
|
||||
T_Friends = 1,
|
||||
T_Achievements = 2
|
||||
};
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user