This commit is contained in:
hiker
2014-03-01 09:47:59 +11:00
7 changed files with 92 additions and 200 deletions

View File

@@ -91,22 +91,6 @@ void PlayerManager::load()
}
m_all_players.insertionSort(/*start*/0, /*desc*/true);
if(!m_current_player)
{
PlayerProfile *player;
for_in(player, m_all_players)
{
if(!player->isGuestAccount())
{
m_current_player = player;
player->setDefault(true);
break;
}
}
}
if(!m_current_player)
Log::fatal("PlayerManager", "Can't find a default player.");
delete players;
} // load
@@ -213,14 +197,17 @@ PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name)
return NULL;
} // getPlayer
// ----------------------------------------------------------------------------
void PlayerManager::setCurrentPlayer(PlayerProfile *player)
void PlayerManager::setCurrentPlayer(PlayerProfile *player, bool remember_me)
{
// Reset current default player
if(m_current_player)
m_current_player->setDefault(false);
m_current_player = player;
m_current_player->setDefault(true);
m_current_player->computeActive();
if(m_current_player)
{
m_current_player->setDefault(remember_me);
m_current_player->computeActive();
}
} // setCurrentPlayer
// ----------------------------------------------------------------------------

View File

@@ -76,7 +76,7 @@ public:
void addDefaultPlayer();
void addNewPlayer(const irr::core::stringw& name);
void deletePlayer(PlayerProfile *player);
void setCurrentPlayer(PlayerProfile *player);
void setCurrentPlayer(PlayerProfile *player, bool remember_me);
const PlayerProfile *getPlayerById(unsigned int id);
// ------------------------------------------------------------------------
/** Returns the current player. */

View File

@@ -44,6 +44,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
m_use_frequency = is_guest ? -1 : 0;
m_unique_id = PlayerManager::get()->getUniqueId();
m_story_mode_status = unlock_manager->createStoryModeStatus();
m_is_default = false;
m_achievements_status =
AchievementsManager::get()->createAchievementsStatus();
} // PlayerProfile

View File

@@ -62,11 +62,11 @@ UserConfigParam::~UserConfigParam()
* \param stream the xml writer.
* \param level determines indentation level.
*/
void UserConfigParam::writeInner(UTFWriter& stream, int level) const
void UserConfigParam::writeInner(std::ofstream& stream, int level) const
{
std::string tab(level * 4,' ');
stream << L" " << tab.c_str() << m_param_name.c_str() << L"=\""
<< toString() << L"\"\n";
stream << " " << tab.c_str() << m_param_name.c_str() << "=\""
<< toString().c_str() << "\"\n";
} // writeInner
// ============================================================================
@@ -89,7 +89,7 @@ GroupUserConfigParam::GroupUserConfigParam(const char* group_name,
} // GroupUserConfigParam
// ----------------------------------------------------------------------------
void GroupUserConfigParam::write(UTFWriter& stream) const
void GroupUserConfigParam::write(std::ofstream& stream) const
{
const int attr_amount = m_attributes.size();
@@ -98,41 +98,41 @@ void GroupUserConfigParam::write(UTFWriter& stream) const
for(int n=0; n<attr_amount; n++)
{
if(m_attributes[n]->m_comment.size() > 0)
stream << L"\n " << m_attributes[n]->m_param_name.c_str()
<< L" : " << m_attributes[n]->m_comment.c_str();
stream << "\n " << m_attributes[n]->m_param_name.c_str()
<< " : " << m_attributes[n]->m_comment.c_str();
}
stream << L" -->\n <" << m_param_name.c_str() << "\n";
stream << " -->\n <" << m_param_name.c_str() << "\n";
// actual values
for (int n=0; n<attr_amount; n++)
{
m_attributes[n]->writeInner(stream, 1);
}
stream << L" >\n";
stream << " >\n";
const int children_amount = m_children.size();
for (int n=0; n<children_amount; n++)
{
m_children[n]->writeInner(stream, 1);
}
stream << L" </" << m_param_name.c_str() << ">\n\n";
stream << " </" << m_param_name.c_str() << ">\n\n";
} // write
// ----------------------------------------------------------------------------
void GroupUserConfigParam::writeInner(UTFWriter& stream, int level) const
void GroupUserConfigParam::writeInner(std::ofstream& stream, int level) const
{
std::string tab(level * 4,' ');
for(int i = 0; i < level; i++) tab =+ " ";
const int children_amount = m_attributes.size();
stream << L" " << tab.c_str() << "<" << m_param_name.c_str() << "\n";
stream << " " << tab.c_str() << "<" << m_param_name.c_str() << "\n";
// actual values
for (int n=0; n<children_amount; n++)
{
m_attributes[n]->writeInner(stream, level+1);
}
stream << L" " << tab.c_str() << "/>\n";
stream << " " << tab.c_str() << "/>\n";
} // writeInner
// ----------------------------------------------------------------------------
@@ -160,7 +160,7 @@ void GroupUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node)
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
irr::core::stringw GroupUserConfigParam::toString() const
irr::core::stringc GroupUserConfigParam::toString() const
{
return "";
} // toString
@@ -246,22 +246,22 @@ ListUserConfigParam<T, U>::ListUserConfigParam(const char* param_name,
// ----------------------------------------------------------------------------
template<typename T, typename U>
void ListUserConfigParam<T, U>::write(UTFWriter& stream) const
void ListUserConfigParam<T, U>::write(std::ofstream& stream) const
{
const int elts_amount = m_elements.size();
// comment
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str();
stream << L" -->\n <" << m_param_name.c_str() << "\n";
stream << " -->\n <" << m_param_name.c_str() << "\n";
stream << L" Size=\"" << elts_amount << "\"\n";
stream << " Size=\"" << elts_amount << "\"\n";
// actual elements
for (int n=0; n<elts_amount; n++)
{
stream << L" " << n << "=\"" << m_elements[n].c_str() << "\"\n";
stream << " " << n << "=\"" << m_elements[n].c_str() << "\"\n";
}
stream << L" >\n";
stream << L" </" << m_param_name.c_str() << ">\n\n";
stream << " >\n";
stream << " </" << m_param_name.c_str() << ">\n\n";
} // write
// ----------------------------------------------------------------------------
@@ -319,7 +319,7 @@ void ListUserConfigParam<T,U>::addElement(T element)
// ----------------------------------------------------------------------------
template<typename T, typename U>
irr::core::stringw ListUserConfigParam<T,U>::toString() const
core::stringc ListUserConfigParam<T, U>::toString() const
{
return "";
} // toString
@@ -352,19 +352,20 @@ IntUserConfigParam::IntUserConfigParam(int default_value,
} // IntUserConfigParam
// ----------------------------------------------------------------------------
void IntUserConfigParam::write(UTFWriter& stream) const
void IntUserConfigParam::write(std::ofstream& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
stream << L" <" << m_param_name.c_str() << L" value=\"" << m_value
<< L"\" />\n\n";
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str()
<< " -->\n";
stream << " <" << m_param_name.c_str() << " value=\"" << m_value
<< "\" />\n\n";
} // write
// ----------------------------------------------------------------------------
irr::core::stringw IntUserConfigParam::toString() const
irr::core::stringc IntUserConfigParam::toString() const
{
irr::core::stringw tmp;
irr::core::stringc tmp;
tmp += m_value;
return tmp;
} // toString
@@ -414,18 +415,18 @@ TimeUserConfigParam::TimeUserConfigParam(StkTime::TimeType default_value,
} // TimeUserConfigParam
// ----------------------------------------------------------------------------
void TimeUserConfigParam::write(UTFWriter& stream) const
void TimeUserConfigParam::write(std::ofstream& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str()
<< " -->\n";
std::ostringstream o;
o<<m_value;
stream << L" <" << m_param_name.c_str() << L" value=\""
<< core::stringw(o.str().c_str()) << L"\" />\n\n";
stream << " <" << m_param_name.c_str() << " value=\""
<< o.str().c_str() << "\" />\n\n";
} // write
// ----------------------------------------------------------------------------
irr::core::stringw TimeUserConfigParam::toString() const
irr::core::stringc TimeUserConfigParam::toString() const
{
// irrString does not have a += with a 64-bit int type, so
// we can't use an irrlicht's stringw directly. Since it's only a
@@ -433,7 +434,7 @@ irr::core::stringw TimeUserConfigParam::toString() const
std::ostringstream o;
o<<m_value;
return core::stringw(o.str().c_str());
return o.str().c_str();
} // toString
// ----------------------------------------------------------------------------
@@ -485,12 +486,12 @@ StringUserConfigParam::StringUserConfigParam(const char* default_value,
} // StringUserConfigParam
// ----------------------------------------------------------------------------
void StringUserConfigParam::write(UTFWriter& stream) const
void StringUserConfigParam::write(std::ofstream& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
stream << L" <" << m_param_name.c_str() << L" value=\""
<< m_value.c_str() << L"\" />\n\n";
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str()
<< " -->\n";
stream << " <" << m_param_name.c_str() << " value=\""
<< m_value.c_str() << "\" />\n\n";
} // write
// ----------------------------------------------------------------------------
@@ -508,57 +509,6 @@ void StringUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node)
node->get( m_param_name, &m_value );
} // findYourDataInAnAttributeOf
// ============================================================================
WStringUserConfigParam::WStringUserConfigParam(const core::stringw& default_value,
const char* param_name,
const char* comment)
{
m_value = default_value;
m_default_value = default_value;
m_param_name = param_name;
all_params.push_back(this);
if(comment != NULL) m_comment = comment;
} // WStringUserConfigParam
// ----------------------------------------------------------------------------
WStringUserConfigParam::WStringUserConfigParam(const core::stringw& default_value,
const char* param_name,
GroupUserConfigParam* group,
const char* comment)
{
m_value = default_value;
m_default_value = default_value;
m_param_name = param_name;
group->addChild(this);
if(comment != NULL) m_comment = comment;
} // WStringUserConfigParam
// ----------------------------------------------------------------------------
void WStringUserConfigParam::write(UTFWriter& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
stream << L" <" << m_param_name.c_str() << L" value=\"" << m_value
<< L"\" />\n\n";
} // write
// ----------------------------------------------------------------------------
void WStringUserConfigParam::findYourDataInAChildOf(const XMLNode* node)
{
const XMLNode* child = node->getNode( m_param_name );
if(child == NULL) return;
child->get( "value", &m_value );
} // findYourDataInAChildOf
// ----------------------------------------------------------------------------
void WStringUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node)
{
node->get( m_param_name, &m_value );
} // findYourDataInAnAttributeOf
// ============================================================================
BoolUserConfigParam::BoolUserConfigParam(bool default_value,
const char* param_name,
@@ -588,12 +538,12 @@ BoolUserConfigParam::BoolUserConfigParam(bool default_value,
// ----------------------------------------------------------------------------
void BoolUserConfigParam::write(UTFWriter& stream) const
void BoolUserConfigParam::write(std::ofstream& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
stream << L" <" << m_param_name.c_str() << L" value=\""
<< (m_value ? L"true" : L"false" ) << L"\" />\n\n";
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str()
<< " -->\n";
stream << " <" << m_param_name.c_str() << " value=\""
<< (m_value ? "true" : "false" ) << "\" />\n\n";
} // write
// ----------------------------------------------------------------------------
@@ -642,9 +592,9 @@ void BoolUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node)
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
irr::core::stringw BoolUserConfigParam::toString() const
irr::core::stringc BoolUserConfigParam::toString() const
{
return (m_value ? L"true" : L"false" );
return (m_value ? "true" : "false" );
} // toString
// ============================================================================
@@ -675,12 +625,12 @@ FloatUserConfigParam::FloatUserConfigParam(float default_value,
} // FloatUserConfigParam
// ----------------------------------------------------------------------------
void FloatUserConfigParam::write(UTFWriter& stream) const
void FloatUserConfigParam::write(std::ofstream& stream) const
{
if(m_comment.size() > 0) stream << L" <!-- " << m_comment.c_str()
<< L" -->\n";
stream << L" <" << m_param_name.c_str() << L" value=\"" << m_value
<< L"\" />\n\n";
if(m_comment.size() > 0) stream << " <!-- " << m_comment.c_str()
<< " -->\n";
stream << " <" << m_param_name.c_str() << " value=\"" << m_value
<< "\" />\n\n";
} // write
// ----------------------------------------------------------------------------
@@ -699,9 +649,9 @@ void FloatUserConfigParam::findYourDataInAnAttributeOf(const XMLNode* node)
} // findYourDataInAnAttributeOf
// ----------------------------------------------------------------------------
irr::core::stringw FloatUserConfigParam::toString() const
core::stringc FloatUserConfigParam::toString() const
{
irr::core::stringw tmp;
irr::core::stringc tmp;
tmp += m_value;
return tmp;
} // toString
@@ -802,11 +752,11 @@ void UserConfig::saveConfig()
try
{
UTFWriter configfile(filename.c_str());
std::ofstream configfile (filename.c_str(), std::ofstream::out);
configfile << L"<?xml version=\"1.0\"?>\n";
configfile << L"<stkconfig version=\"" << m_current_config_version
<< L"\" >\n\n";
configfile << "<?xml version=\"1.0\"?>\n";
configfile << "<stkconfig version=\"" << m_current_config_version
<< "\" >\n\n";
const int paramAmount = all_params.size();
for(int i=0; i<paramAmount; i++)
@@ -815,7 +765,7 @@ void UserConfig::saveConfig()
all_params[i].write(configfile);
}
configfile << L"</stkconfig>\n";
configfile << "</stkconfig>\n";
configfile.close();
}
catch (std::runtime_error& e)

View File

@@ -68,11 +68,11 @@ protected:
std::string m_comment;
public:
virtual ~UserConfigParam();
virtual void write(UTFWriter& stream) const = 0;
virtual void writeInner(UTFWriter& stream, int level = 0) const;
virtual void write(std::ofstream & stream) const = 0;
virtual void writeInner(std::ofstream & stream, int level = 0) const;
virtual void findYourDataInAChildOf(const XMLNode* node) = 0;
virtual void findYourDataInAnAttributeOf(const XMLNode* node) = 0;
virtual irr::core::stringw toString() const = 0;
virtual irr::core::stringc toString() const = 0;
}; // UserConfigParam
// ============================================================================
@@ -85,8 +85,8 @@ public:
GroupUserConfigParam(const char* param_name,
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void writeInner(UTFWriter& stream, int level = 0) const;
void write(std::ofstream& stream) const;
void writeInner(std::ofstream& stream, int level = 0) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
@@ -94,7 +94,7 @@ public:
void addChild(GroupUserConfigParam* child);
void clearChildren();
irr::core::stringw toString() const;
irr::core::stringc toString() const;
}; // GroupUserConfigParam
// ============================================================================
@@ -119,13 +119,13 @@ public:
int nb_elts,
...);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
void addElement(T element);
irr::core::stringw toString() const;
irr::core::stringc toString() const;
operator std::vector<T>() const
{ return m_elements; }
@@ -150,11 +150,11 @@ public:
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
irr::core::stringw toString() const;
irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; }
operator int() const { return m_value; }
@@ -177,11 +177,11 @@ public:
TimeUserConfigParam(StkTime::TimeType default_value, const char* param_name,
GroupUserConfigParam* group, const char* comment=NULL);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
irr::core::stringw toString() const;
irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; }
operator StkTime::TimeType() const { return m_value; }
StkTime::TimeType& operator=(const StkTime::TimeType& v)
@@ -204,7 +204,7 @@ public:
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
@@ -212,7 +212,7 @@ public:
std::string getDefaultValue() const { return m_default_value; }
irr::core::stringw toString() const { return m_value.c_str(); }
irr::core::stringc toString() const { return m_value.c_str(); }
operator std::string() const { return m_value; }
std::string& operator=(const std::string& v)
@@ -223,37 +223,6 @@ public:
const char* c_str() const { return m_value.c_str(); }
}; // StringUserConfigParam
// ============================================================================
class WStringUserConfigParam : public UserConfigParam
{
stringw m_value;
stringw m_default_value;
public:
WStringUserConfigParam(const stringw& default_value,
const char* param_name,
const char* comment = NULL);
WStringUserConfigParam(const stringw& default_value,
const char* param_name,
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
void revertToDefaults() { m_value = m_default_value; }
irr::core::stringw toString() const { return m_value; }
operator stringw() const { return m_value; }
stringw& operator=(const stringw& v) { m_value = v; return m_value; }
stringw& operator=(const WStringUserConfigParam& v)
{ m_value = (stringw)v; return m_value; }
const wchar_t* c_str() const { return m_value.c_str(); }
}; // WStringUserConfigParam
// ============================================================================
class BoolUserConfigParam : public UserConfigParam
{
@@ -266,11 +235,11 @@ public:
BoolUserConfigParam(bool default_value, const char* param_name,
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
irr::core::stringw toString() const;
irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; }
operator bool() const { return m_value; }
@@ -292,11 +261,11 @@ public:
GroupUserConfigParam* group,
const char* comment = NULL);
void write(UTFWriter& stream) const;
void write(std::ofstream& stream) const;
void findYourDataInAChildOf(const XMLNode* node);
void findYourDataInAnAttributeOf(const XMLNode* node);
irr::core::stringw toString() const;
irr::core::stringc toString() const;
void revertToDefaults() { m_value = m_default_value; }
operator float() const { return m_value; }
@@ -677,10 +646,6 @@ namespace UserConfigParams
PARAM_DEFAULT( StringUserConfigParam("Peach.stkskin", "skin_file",
"Name of the skin to use") );
PARAM_PREFIX WStringUserConfigParam m_default_player
PARAM_DEFAULT( WStringUserConfigParam(L"", "default_player",
"Which player to use by default (if empty, will prompt)") );
// ---- Internet related
PARAM_PREFIX IntUserConfigParam m_internet_status

View File

@@ -184,8 +184,8 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name
}
else if (name == "playername")
{
UserConfigParams::m_default_player = L"";
race_manager->clearKartLastPositionOnOverworld();
PlayerManager::get()->setCurrentPlayer(NULL,false);
StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance());
}

View File

@@ -55,18 +55,11 @@ void StoryModeLobbyScreen::init()
ListWidget* list = getWidget<ListWidget>("gameslots");
list->clear();
core::stringw name = UserConfigParams::m_default_player.toString();
if (UserConfigParams::m_default_player.toString().size() > 0)
PlayerProfile *player = PlayerManager::get()->getCurrentPlayer();
if(player)
{
PlayerProfile *player = PlayerManager::get()->getPlayer(name);
if(player)
{
PlayerManager::get()->setCurrentPlayer(player);
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
@@ -114,13 +107,9 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
->getPlayer(list->getSelectionLabel());
if(player)
{
PlayerManager::get()->setCurrentPlayer(player);
player->computeActive();
CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
if (cb->getState())
{
UserConfigParams::m_default_player = list->getSelectionLabel();
}
PlayerManager::get()->setCurrentPlayer(player,cb->getState());
}
else
{
@@ -146,7 +135,7 @@ void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name)
PlayerProfile *player = PlayerManager::get()->getPlayer(new_name);
if(player)
{
PlayerManager::get()->setCurrentPlayer(player);
PlayerManager::get()->setCurrentPlayer(player,false);
player->computeActive();
}
else