Keep track of online ids used in the player.xml file.

This commit is contained in:
hiker
2014-04-24 08:17:44 +10:00
parent d7684668db
commit ea2b797bb3
4 changed files with 60 additions and 0 deletions

View File

@@ -197,6 +197,19 @@ void PlayerManager::load()
return;
}
const XMLNode *online = m_player_data->getNode("online-ids");
if (online)
{
for (unsigned int i = 0; i < online->getNumNodes(); i++)
{
core::stringw s;
online->getNode(i)->get("name", &s);
if (s.size()>0) m_all_online_ids.push_back(s);
} // for i<online->getNumNodes()
}
else
m_all_online_ids.clear();
m_current_player = NULL;
for(unsigned int i=0; i<m_player_data->getNumNodes(); i++)
{
@@ -249,6 +262,14 @@ void PlayerManager::save()
players_file << L"<?xml version=\"1.0\"?>\n";
players_file << L"<players version=\"1\" >\n";
players_file << L" <online-ids>\n";
for (unsigned int i = 0; i < m_all_online_ids.size(); i++)
{
players_file << L" <id name=\""<<m_all_online_ids[i]
<< "\"/>\n";
}
players_file << L" </online-ids>\n";
PlayerProfile *player;
for_in(player, m_all_players)
{
@@ -420,3 +441,28 @@ void PlayerManager::setCurrentPlayer(PlayerProfile *player, bool remember_me)
} // setCurrentPlayer
// ----------------------------------------------------------------------------
/** Adds an online id to the list of all online ids, if that id is not already
* in the list. An added id is always moved to the front of the list, so that
* the list of online ids shown to the user is sorted by recently-used ids.
* \param online_id An online id.
*/
void PlayerManager::addOnlineId(const core::stringw &online_id)
{
std::vector<core::stringw>::iterator i = std::find(m_all_online_ids.begin(),
m_all_online_ids.end(),
online_id);
if (i == m_all_online_ids.end())
{
m_all_online_ids.insert(m_all_online_ids.begin(), online_id);
}
else
{
// If the online_id is not already at the front of the list,
// move it to the front.
if (i != m_all_online_ids.begin())
{
m_all_online_ids.erase(i);
m_all_online_ids.insert(m_all_online_ids.begin(), online_id);
}
}
} // addOnlineId

View File

@@ -58,6 +58,9 @@ private:
PtrVector<PlayerProfile> m_all_players;
/** A list of all online ids created locally. */
std::vector<core::stringw> m_all_online_ids;
/** A pointer to the current player. */
PlayerProfile* m_current_player;
@@ -113,6 +116,7 @@ public:
const irr::core::stringw &password,
bool save_session,
bool request_now = true);
void addOnlineId(const core::stringw &online_id);
// ------------------------------------------------------------------------
/** Returns the current player. */
@@ -155,6 +159,13 @@ public:
a->increase(key, increase);
} // increaseAchievement
// ------------------------------------------------------------------------
/** Returns the list of all online ids. */
const std::vector<core::stringw>& getAllOnlineIds() const
{
return m_all_online_ids;
} // getAllOnlineIds
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
}; // PlayerManager

View File

@@ -99,6 +99,7 @@ void LoginScreen::login()
info_widget->setDefaultColor();
bool remember = getWidget<CheckBoxWidget>("remember")->getState();
PlayerManager::requestSignIn(username, password, remember);
PlayerManager::get()->addOnlineId(username);
}
} // login

View File

@@ -17,6 +17,7 @@
#include "states_screens/register_screen.hpp"
#include "config/player_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
@@ -103,6 +104,7 @@ void RegisterScreen::doRegister()
}
else
{
PlayerManager::get()->addOnlineId(username);
m_info_widget->setDefaultColor();
new RegistrationDialog();
return;