Simplified handling of current player: instead of storing a flag
in each player, PlayerManager now just uses its m_current_player to write this information in the players.xml file.
This commit is contained in:
parent
63b270283d
commit
b38a31f303
@ -190,7 +190,6 @@ void PlayerManager::load()
|
||||
return;
|
||||
}
|
||||
|
||||
m_current_player = NULL;
|
||||
std::vector<XMLNode*> player_list;
|
||||
m_player_data->getNodes("player", player_list);
|
||||
for(unsigned int i=0; i<player_list.size(); i++)
|
||||
@ -198,8 +197,14 @@ void PlayerManager::load()
|
||||
const XMLNode *player_xml = player_list[i];
|
||||
PlayerProfile *player = new Online::OnlinePlayerProfile(player_xml);
|
||||
m_all_players.push_back(player);
|
||||
if(player->isDefault())
|
||||
m_current_player = player;
|
||||
}
|
||||
m_current_player = NULL;
|
||||
const XMLNode *current = m_player_data->getNode("current");
|
||||
if(current)
|
||||
{
|
||||
stringw name;
|
||||
current->get("player", &name);
|
||||
m_current_player = getPlayer(name);
|
||||
}
|
||||
|
||||
} // load
|
||||
@ -250,6 +255,12 @@ void PlayerManager::save()
|
||||
players_file << L"<?xml version=\"1.0\"?>\n";
|
||||
players_file << L"<players version=\"1\" >\n";
|
||||
|
||||
if(m_current_player && UserConfigParams::m_remember_user)
|
||||
{
|
||||
players_file << L" <current player=\""
|
||||
<< m_current_player->getName() << L"\"/>\n";
|
||||
}
|
||||
|
||||
PlayerProfile *player;
|
||||
for_in(player, m_all_players)
|
||||
{
|
||||
@ -404,23 +415,14 @@ PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name)
|
||||
} // getPlayer
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets the current player. This is the player that is used for story mode
|
||||
* and achievements. If 'remember_me' is set, this information will be
|
||||
* stored in the players.xml file, and automatically loaded next time
|
||||
* STK is started.
|
||||
* and achievements.
|
||||
* \param Player profile to be the current player.
|
||||
* \param remember_me If this player should be marked as default
|
||||
* player in players.xml
|
||||
*/
|
||||
void PlayerManager::setCurrentPlayer(PlayerProfile *player)
|
||||
{
|
||||
bool remember_me = UserConfigParams::m_remember_user;
|
||||
// Reset current default player
|
||||
if(m_current_player)
|
||||
m_current_player->setDefault(false);
|
||||
m_current_player = player;
|
||||
if(m_current_player)
|
||||
{
|
||||
m_current_player->setDefault(remember_me);
|
||||
m_current_player->computeActive();
|
||||
}
|
||||
} // setCurrentPlayer
|
||||
|
@ -43,8 +43,6 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
|
||||
m_is_guest_account = is_guest;
|
||||
m_use_frequency = is_guest ? -1 : 0;
|
||||
m_unique_id = PlayerManager::get()->getUniqueId();
|
||||
m_is_default = false;
|
||||
m_is_default = false;
|
||||
m_saved_session = false;
|
||||
m_saved_token = "";
|
||||
m_saved_user_id = 0;
|
||||
@ -80,7 +78,6 @@ PlayerProfile::PlayerProfile(const XMLNode* node)
|
||||
node->get("guest", &m_is_guest_account);
|
||||
node->get("use-frequency", &m_use_frequency );
|
||||
node->get("unique-id", &m_unique_id );
|
||||
node->get("is-default", &m_is_default );
|
||||
node->get("saved-session", &m_saved_session );
|
||||
node->get("saved-user", &m_saved_user_id );
|
||||
node->get("saved-token", &m_saved_token );
|
||||
@ -136,8 +133,7 @@ void PlayerProfile::save(UTFWriter &out)
|
||||
<< L"\" guest=\"" << m_is_guest_account
|
||||
<< L"\" use-frequency=\"" << m_use_frequency << L"\"\n";
|
||||
|
||||
out << L" is-default=\"" << m_is_default
|
||||
<< L"\" unique-id=\"" << m_unique_id
|
||||
out << L" unique-id=\"" << m_unique_id
|
||||
<< L"\" saved-session=\"" << m_saved_session << L"\"\n";
|
||||
|
||||
out << L" saved-user=\"" << m_saved_user_id
|
||||
|
@ -83,9 +83,6 @@ private:
|
||||
/** A unique number for this player, used to link it to challenges etc. */
|
||||
unsigned int m_unique_id;
|
||||
|
||||
/** True if this is the default (last used) player. */
|
||||
bool m_is_default;
|
||||
|
||||
/** True if this user has a saved session. */
|
||||
bool m_saved_session;
|
||||
|
||||
@ -177,12 +174,6 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the unique id of this player. */
|
||||
unsigned int getUniqueID() const { return m_unique_id; }
|
||||
// -----------------------------------------------------------------------
|
||||
/** Returns true if this is the default (last used) player. */
|
||||
bool isDefault() const { return m_is_default; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Sets if this player is the default player or not. */
|
||||
void setDefault(bool is_default) { m_is_default = is_default; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returnes if the feature (kart, track) is locked. */
|
||||
bool isLocked(const std::string &feature) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user