Added new player manager, and started to replace the saved data

from user_config with player manager.
This commit is contained in:
hiker 2014-02-06 14:43:47 +11:00
parent 62d46b7ec0
commit 78b73aa3c8
21 changed files with 345 additions and 177 deletions

View File

@ -23,6 +23,7 @@ src/challenges/game_slot.cpp
src/challenges/unlock_manager.cpp
src/config/device_config.cpp
src/config/player.cpp
src/config/player_manager.cpp
src/config/saved_grand_prix.cpp
src/config/stk_config.cpp
src/config/user_config.cpp
@ -101,8 +102,8 @@ src/input/input_manager.cpp
src/input/wiimote.cpp
src/input/wiimote_manager.cpp
src/io/file_manager.cpp
src/io/utf_writer.cpp
src/io/xml_node.cpp
src/io/xml_writer.cpp
src/items/attachment.cpp
src/items/attachment_manager.cpp
src/items/bowling.cpp
@ -351,6 +352,7 @@ src/challenges/game_slot.hpp
src/challenges/unlock_manager.hpp
src/config/device_config.hpp
src/config/player.hpp
src/config/player_manager.hpp
src/config/saved_grand_prix.hpp
src/config/stk_config.hpp
src/config/user_config.hpp
@ -428,8 +430,8 @@ src/input/input_manager.hpp
src/input/wiimote.hpp
src/input/wiimote_manager.hpp
src/io/file_manager.hpp
src/io/utf_writer.hpp
src/io/xml_node.hpp
src/io/xml_writer.hpp
src/items/attachment.hpp
src/items/attachment_manager.hpp
src/items/attachment_plugin.hpp

View File

@ -138,7 +138,7 @@ void AchievementsManager::parseUserConfigFile()
} // load
AchievementsSlot * AchievementsManager::createNewSlot(std::string id, bool online)
AchievementsSlot * AchievementsManager::createNewSlot(unsigned int id, bool online)
{
AchievementsSlot* slot = new AchievementsSlot(id, online);
m_slots.push_back(slot);
@ -207,7 +207,7 @@ void AchievementsManager::onRaceEnd()
}
// ============================================================================
AchievementsSlot * AchievementsManager::getSlot(const std::string & id, bool online)
AchievementsSlot * AchievementsManager::getSlot(unsigned int id, bool online)
{
for(unsigned int i = 0; i < m_slots.size(); i++)
{
@ -224,10 +224,10 @@ void AchievementsManager::updateCurrentPlayer()
{
if(Online::CurrentUser::get()->isRegisteredUser())
{
m_active_slot = getSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true);
m_active_slot = getSlot(Online::CurrentUser::get()->getID(), true);
if(m_active_slot == NULL)
{
m_active_slot = createNewSlot(StringUtils::toString(Online::CurrentUser::get()->getID()), true);
m_active_slot = createNewSlot(Online::CurrentUser::get()->getID(), true);
save();
}
}

View File

@ -45,7 +45,7 @@ private :
std::map<uint32_t, AchievementInfo *> m_achievements_info;
AchievementsManager ();
~AchievementsManager ();
AchievementsSlot * createNewSlot(std::string id, bool online);
AchievementsSlot * createNewSlot(unsigned int id, bool online);
void parseAssetFile();
void parseUserConfigFile();
@ -59,7 +59,7 @@ public:
void onRaceEnd();
void updateCurrentPlayer();
AchievementsSlot * getActive() const { return m_active_slot; }
AchievementsSlot * getSlot(const std::string & id, bool online);
AchievementsSlot * getSlot(unsigned int id, bool online);
void createSlotsIfNeeded();
AchievementInfo * getAchievementInfo(uint32_t id);
const std::map<uint32_t, AchievementInfo *> & getAllInfo() { return m_achievements_info;}

View File

@ -63,11 +63,11 @@ AchievementsSlot::AchievementsSlot(const XMLNode * input)
}
// ============================================================================
AchievementsSlot::AchievementsSlot(std::string id, bool online)
AchievementsSlot::AchievementsSlot(unsigned int id, bool online)
{
m_valid = true;
m_valid = true;
m_online = online;
m_id = id;
m_id = id;
createFreshSlot();
}
@ -112,7 +112,7 @@ void AchievementsSlot::createFreshSlot()
// ============================================================================
void AchievementsSlot::save(std::ofstream & out)
{
out << " <slot user_id=\"" << m_id.c_str()
out << " <slot user_id=\"" << m_id
<< "\" online=\"" << StringUtils::toString(m_online)
<< "\"> \n";
std::map<uint32_t, Achievement*>::const_iterator i;

View File

@ -33,9 +33,9 @@ class AchievementsSlot
{
private:
std::map<uint32_t, Achievement *> m_achievements;
bool m_online;
bool m_valid;
std::string m_id;
bool m_online;
bool m_valid;
unsigned int m_id;
void createFreshSlot();
void deleteAchievements();
@ -48,14 +48,14 @@ private:
public :
AchievementsSlot(const XMLNode * input);
AchievementsSlot(std::string id, bool online);
AchievementsSlot(unsigned int id, bool online);
~AchievementsSlot();
bool isValid() const { return m_valid;}
void save(std::ofstream & out);
bool isOnline() const {return m_online;}
void sync(const std::vector<uint32_t> & achieved_ids);
void onRaceEnd();
const std::string & getID() const {return m_id;}
unsigned int getID() const {return m_id;}
const std::map<uint32_t, Achievement *> & getAllAchievements() {return m_achievements;}
Achievement * getAchievement(uint32_t id);
};

View File

@ -22,7 +22,6 @@
#include "challenges/challenge.hpp"
#include "challenges/challenge_data.hpp"
#include "challenges/unlock_manager.hpp"
#include "io/xml_writer.hpp"
//-----------------------------------------------------------------------------
GameSlot::~GameSlot()
@ -238,7 +237,7 @@ void GameSlot::grandPrixFinished()
void GameSlot::save(std::ofstream& out, const std::string& name)
{
out << " <gameslot playerID=\"" << m_player_unique_id.c_str()
out << " <gameslot playerID=\"" << m_player_unique_id
<< "\" kart=\"" << m_kart_ident.c_str()
<< "\" firstTime=\"" << (m_first_time ? "true" : "false")
<< "\"> <!-- " << name.c_str() << " -->\n";

View File

@ -46,7 +46,7 @@ class GameSlot
* are done everywhere, assign a unique ID to each profiler.
* Will save much headaches.
*/
std::string m_player_unique_id;
unsigned int m_player_unique_id;
/** Contains whether each feature of the challenge is locked or unlocked */
std::map<std::string, bool> m_locked_features;
@ -79,19 +79,19 @@ public:
// do NOT attempt to pass 'player_unique_id' by reference here. I don't
// know why (compiler bug maybe?) but this screws up everything. Better
// pass by copy.
GameSlot(std::string player_unique_id)
GameSlot(unsigned int player_unique_id)
{
m_player_unique_id = player_unique_id;
m_points = 0;
m_first_time = true;
m_easy_challenges = 0;
m_player_unique_id = player_unique_id;
m_points = 0;
m_first_time = true;
m_easy_challenges = 0;
m_medium_challenges = 0;
m_hard_challenges = 0;
m_hard_challenges = 0;
m_current_challenge = NULL;
}
~GameSlot();
const std::string& getPlayerID() const { return m_player_unique_id; }
unsigned int getPlayerID() const { return m_player_unique_id; }
const std::string& getKartIdent () const { return m_kart_ident; }
void setKartIdent(const std::string& kart_ident)
{

View File

@ -47,7 +47,7 @@ UnlockManager::UnlockManager()
// in main).
unlock_manager = this;
m_current_game_slot = "";
m_current_game_slot = 0;
m_locked_sound = sfx_manager->createSoundSource("locked");
@ -94,7 +94,7 @@ UnlockManager::~UnlockManager()
}
std::map<std::string, GameSlot*>::iterator it;
std::map<unsigned int, GameSlot*>::iterator it;
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
{
delete it->second;
@ -222,7 +222,7 @@ void UnlockManager::load()
root->getNodes("gameslot", xml_game_slots);
for (unsigned int n=0; n<xml_game_slots.size(); n++)
{
std::string player_id;
unsigned int player_id;
if (!xml_game_slots[n]->get("playerID", &player_id))
{
Log::warn("unlock_manager", "Found game slot without "
@ -279,7 +279,7 @@ void UnlockManager::save()
challenge_file << "<?xml version=\"1.0\"?>\n";
challenge_file << "<challenges>\n";
std::map<std::string, GameSlot*>::iterator it;
std::map<unsigned int, GameSlot*>::iterator it;
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
{
std::string name = "unknown player";
@ -313,7 +313,7 @@ bool UnlockManager::createSlotsIfNeeded()
{
bool exists = false;
std::map<std::string, GameSlot*>::iterator it;
std::map<unsigned int, GameSlot*>::iterator it;
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
{
GameSlot* curr_slot = it->second;
@ -351,7 +351,7 @@ bool UnlockManager::createSlotsIfNeeded()
bool UnlockManager::deleteSlotsIfNeeded()
{
bool changed = false;
std::map<std::string, GameSlot*>::iterator it = m_game_slots.begin();
std::map<unsigned int, GameSlot*>::iterator it = m_game_slots.begin();
while (it != m_game_slots.end())
{
bool found = false;
@ -370,7 +370,7 @@ bool UnlockManager::deleteSlotsIfNeeded()
{
#ifdef DEBUG
printf("Deleting gameslot %s, no player found.\n",
it->second->getPlayerID().c_str());
it->second->getPlayerID());
#endif
// Iterators aren't invalidated this way
m_game_slots.erase(it++);
@ -424,7 +424,7 @@ void UnlockManager::updateActiveChallengeList()
//-----------------------------------------------------------------------------
void UnlockManager::setCurrentSlot(std::string slotid)
void UnlockManager::setCurrentSlot(unsigned int slotid)
{
m_current_game_slot = slotid;
AchievementsManager::get()->updateCurrentPlayer();

View File

@ -48,12 +48,12 @@ private:
typedef std::map<std::string, ChallengeData*> AllChallengesType;
AllChallengesType m_all_challenges;
std::map<std::string, GameSlot*> m_game_slots;
std::map<unsigned int , GameSlot*> m_game_slots;
void readAllChallengesInDirs(const std::vector<std::string>* all_dirs);
/** ID of the active player */
std::string m_current_game_slot;
unsigned int m_current_game_slot;
friend class GameSlot;
@ -73,7 +73,7 @@ public:
/** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */
void playLockSound() const;
const std::string& getCurrentSlotID() const { return m_current_game_slot; }
unsigned int getCurrentSlotID() const { return m_current_game_slot; }
GameSlot* getCurrentSlot()
{
@ -82,7 +82,7 @@ public:
}
/** \param slotid name of the player */
void setCurrentSlot(std::string slotid);
void setCurrentSlot(unsigned int slotid);
void findWhatWasUnlocked(int pointsBefore, int pointsNow,
std::vector<std::string>& tracks,
std::vector<std::string>& gps);

View File

@ -16,77 +16,66 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "io/xml_node.hpp"
#include "io/utf_writer.hpp"
#include "utils/string_utils.hpp"
#include <sstream>
#include <stdlib.h>
#include "config/player.hpp"
#include "utils/string_utils.hpp"
#include <sstream>
//------------------------------------------------------------------------------
PlayerProfile::PlayerProfile(const core::stringw& name) :
m_player_group("Player", "Represents one human player"),
m_name(name, "name", &m_player_group),
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
/** Constructor to create a new player that didn't exist before.
* \param name Name of the player.
* \param is_guest True if this is a guest account.
*/
PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest)
{
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str());
m_name = name;
m_is_guest_account = is_guest;
m_use_frequency = 0;
m_unique_id = PlayerManager::get()->getUniqueId();
std::ostringstream to_string;
to_string << std::hex << unique_id;
m_unique_id = to_string.str();
}
} // PlayerProfile
//------------------------------------------------------------------------------
PlayerProfile::PlayerProfile(const XMLNode* node) :
m_player_group("Player", "Represents one human player"),
m_name("-", "name", &m_player_group),
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
/** Constructor to deserialize a player that was saved to a XML file.
* \param node The XML node representing this player.
*/
PlayerProfile::PlayerProfile(const XMLNode* node)
{
//m_player_group.findYourDataInAChildOf(node);
m_name.findYourDataInAnAttributeOf(node);
m_is_guest_account.findYourDataInAnAttributeOf(node);
m_use_frequency.findYourDataInAnAttributeOf(node);
m_unique_id.findYourDataInAnAttributeOf(node);
if ((std::string)m_unique_id == "")
{
fprintf(stderr, "** WARNING: Player has no unique ID, probably it is from an older STK version\n");
int64_t unique_id = generateUniqueId(core::stringc(m_name.c_str()).c_str());
std::ostringstream tostring;
tostring << std::hex << unique_id;
m_unique_id = tostring.str();
}
node->get("name", &m_name );
node->get("guest", &m_is_guest_account);
node->get("use-frequency", &m_use_frequency );
node->get("unique-id", &m_unique_id );
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
} // PlayerProfile
//------------------------------------------------------------------------------
/** Writes the data for this player to the specified UTFWriter.
* \param out The utf writer to write the data to.
*/
void PlayerProfile::save(UTFWriter &out)
{
out << L" <player name=\"" << m_name << L"\"\n";
out << L" guest=\"" << m_is_guest_account << L"\"\n";
out << L" use-frequency=\""<< m_use_frequency << L"\"\n";
out << L" unique-id=\"" << m_unique_id << L"\"\n";
out << L" />\n";
} // save
//------------------------------------------------------------------------------
/** Increments how often that account was used. Guest accounts are not counted.
*/
void PlayerProfile::incrementUseFrequency()
{
if (m_is_guest_account) m_use_frequency = -1;
else m_use_frequency++;
} // incrementUseFrequency
//------------------------------------------------------------------------------
int64_t PlayerProfile::generateUniqueId(const char* player_name)
{
// First create a simple hash based on he player name
int hash = 0;
for (int n=0; player_name[n] != 0; n++)
{
hash += (hash << (hash & 0xF)) ^ player_name[n];
}
return ((int64_t)(StkTime::getTimeSinceEpoch()) << 32) |
((rand() << 16) & 0xFFFF0000) |
hash;
} // generateUniqueId

View File

@ -19,13 +19,17 @@
#ifndef HEADER_PLAYER_HPP
#define HEADER_PLAYER_HPP
#include <string>
#include "config/user_config.hpp"
#include "utils/no_copy.hpp"
#include "utils/types.hpp"
#include <irrString.h>
using namespace irr;
#include <string>
class UTFWriter;
/**
* \brief Class for managing player profiles (name, control configuration, etc.)
* A list of all possible players is stored as PlayerProfiles in the user config.
@ -36,43 +40,31 @@ class PlayerProfile : public NoCopy
{
protected:
/**
* For saving to config file.
* WARNING : m_player_group has to be declared before the other userconfigparams!
*/
GroupUserConfigParam m_player_group;
/** The name of the player (wide string, so it can be in native
* language). */
core::stringw m_name;
WStringUserConfigParam m_name;
BoolUserConfigParam m_is_guest_account;
/** True if this account is a guest account. */
bool m_is_guest_account;
#ifdef DEBUG
unsigned int m_magic_number;
#endif
IntUserConfigParam m_use_frequency;
/** Counts how often this player was used. */
unsigned int m_use_frequency;
/** Profile names can change, so rather than try to make sure all renames are done everywhere,
* assign a unique ID to each profiler. Will save much headaches.
*/
StringUserConfigParam m_unique_id;
int64_t generateUniqueId(const char* playerName);
/** A unique number for this player, used to link it to challenges etc. */
unsigned int m_unique_id;
public:
/**
* Constructor to create a new player that didn't exist before
*/
PlayerProfile(const core::stringw& name);
PlayerProfile(const core::stringw& name, bool is_guest = false);
/**
* Constructor to deserialize a player that was saved to a XML file
* (...UserConfigParam classes will automagically take care of serializing all
* create players to the user's config file)
*/
PlayerProfile(const XMLNode* node);
void save(UTFWriter &out);
void incrementUseFrequency();
~PlayerProfile()
{
@ -112,15 +104,12 @@ public:
}
void incrementUseFrequency();
// please do NOT try to optimise this to return a reference, I don't know why,
// maybe compiler bug, but hell breaks loose when you do that
std::string getUniqueID() const
{
return m_unique_id;
}
};
// ------------------------------------------------------------------------
/** Returns the unique id of this player. */
unsigned int getUniqueID() const { return m_unique_id; }
}; // class PlayerProfile
#endif

View File

@ -0,0 +1,141 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2012-2014 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "config/player_manager.hpp"
#include "config/player.hpp"
#include "io/file_manager.hpp"
#include "io/utf_writer.hpp"
#include "io/xml_node.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
PlayerManager *PlayerManager::m_player_manager = NULL;
/** Constructor.
*/
PlayerManager::PlayerManager()
{
} // PlayerManager
// ----------------------------------------------------------------------------
/** Destructor.
*/
PlayerManager::~PlayerManager()
{
save();
} // ~PlayerManager
// ----------------------------------------------------------------------------
void PlayerManager::load()
{
std::string filename = file_manager->getUserConfigFile("players.xml");
const XMLNode *players = file_manager->createXMLTree(filename);
if(!players || players->getName()!="players")
{
Log::info("player_manager", "The players.xml file is invalid.");
return;
}
for(unsigned int i=0; i<players->getNumNodes(); i++)
{
const XMLNode *player_xml = players->getNode(i);
PlayerProfile *profile = new PlayerProfile(player_xml);
m_all_players.push_back(profile);
}
} // load
// ----------------------------------------------------------------------------
void PlayerManager::save()
{
std::string filename = file_manager->getUserConfigFile("players.xml");
try
{
UTFWriter players_file(filename.c_str());
players_file << L"<?xml version=\"1.0\"?>\n";
players_file << L"<players version=\"1\" >\n";
PlayerProfile *player;
for_in(player, m_all_players)
{
player->save(players_file);
}
players_file << L"</players>\n";
players_file.close();
}
catch (std::runtime_error& e)
{
Log::error("PlayerManager", "Failed to write config to %s.",
filename.c_str());
Log::error("PlayerManager", "Error: %s", e.what());
}
} // save
// ----------------------------------------------------------------------------
/** Adds a new player to the list of all players.
* \param name Name of the new player.
*/
void PlayerManager::addNewPlayer(const core::stringw& name)
{
m_all_players.push_back( new PlayerProfile(name) );
} // addNewPlayer
// ----------------------------------------------------------------------------
void PlayerManager::addDefaultPlayer()
{
std::string username = "unnamed player";
if(getenv("USERNAME")!=NULL) // for windows
username = getenv("USERNAME");
else if(getenv("USER")!=NULL) // Linux, Macs
username = getenv("USER");
else if(getenv("LOGNAME")!=NULL) // Linux, Macs
username = getenv("LOGNAME");
// Set the name as the default name for all players.
m_all_players.push_back(new PlayerProfile(username.c_str()) );
// add default guest player
m_all_players.push_back( new PlayerProfile(_LTR("Guest")) );
} // addDefaultPlayer
// ----------------------------------------------------------------------------
/** This returns a unique id. This is 1 + larger id so far used.
*/
unsigned int PlayerManager::getUniqueId() const
{
unsigned int max_id=0;
const PlayerProfile *player;
for_in(player, m_all_players)
{
if(player->getUniqueID()>max_id)
max_id = player->getUniqueID();
}
return max_id+1;
} // getUniqueId
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

View File

@ -0,0 +1,78 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2014 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PLAYER_CONFIG_HPP
#define HEADER_PLAYER_CONFIG_HPP
#include "utils/no_copy.hpp"
#include "utils/ptr_vector.hpp"
#include <irrString.h>
#include <cstddef> // NULL
class PlayerProfile;
/** A special class that manages all local player accounts.
*/
class PlayerManager : public NoCopy
{
private:
static PlayerManager* m_player_manager;
PtrVector<PlayerProfile> m_all_players;
PlayerManager();
~PlayerManager();
public:
/** Static singleton get function. */
static PlayerManager* get()
{
if(!m_player_manager)
m_player_manager = new PlayerManager();
return m_player_manager;
} // get
// ------------------------------------------------------------------------
static void destroy()
{
delete m_player_manager;
m_player_manager = NULL;
} // destroy
// ------------------------------------------------------------------------
void load();
void save();
unsigned int getUniqueId() const;
void addDefaultPlayer();
void addNewPlayer(const irr::core::stringw& name);
// ------------------------------------------------------------------------
/** Returns the number of players in the config file.*/
unsigned int getNumPlayers() const { return m_all_players.size(); }
// ------------------------------------------------------------------------
/** Returns a player with a given unique id. */
const PlayerProfile &getPlayer(unsigned int n) { return m_all_players[n];}
// ------------------------------------------------------------------------
}; // PlayerManager
#endif
/*EOF*/

View File

@ -63,7 +63,7 @@ SavedGrandPrix::SavedGPKart::SavedGPKart(GroupUserConfigParam * group,
} // SavedGPKart
// ============================================================================
SavedGrandPrix::SavedGrandPrix(const std::string &player_id,
SavedGrandPrix::SavedGrandPrix(unsigned int player_id,
const std::string &gp_id,
RaceManager::Difficulty difficulty,
int player_karts,
@ -71,7 +71,7 @@ SavedGrandPrix::SavedGrandPrix(const std::string &player_id,
const std::vector<RaceManager::KartStatus> &kart_list)
: m_savedgp_group("SavedGP",
"Represents the saved state of a GP"),
m_player_id(player_id.c_str(), "player_id", &m_savedgp_group),
m_player_id(player_id),
m_gp_id(gp_id.c_str(), "gp_id", &m_savedgp_group),
m_difficulty((int)difficulty,"difficulty", &m_savedgp_group),
m_player_karts(player_karts,"player_karts", &m_savedgp_group),
@ -94,14 +94,13 @@ SavedGrandPrix::SavedGrandPrix(const std::string &player_id,
SavedGrandPrix::SavedGrandPrix(const XMLNode* node)
: m_savedgp_group("SavedGP",
"Represents the saved state of a GP"),
m_player_id("-", "player_id", &m_savedgp_group),
m_player_id(0),
m_gp_id("-", "gp_id", &m_savedgp_group),
m_difficulty(0,"difficulty", &m_savedgp_group),
m_player_karts(0,"player_karts", &m_savedgp_group),
m_next_track(0,"last_track", &m_savedgp_group)
{
//m_player_group.findYourDataInAChildOf(node);
m_player_id.findYourDataInAnAttributeOf(node);
m_gp_id.findYourDataInAnAttributeOf(node);
m_difficulty.findYourDataInAnAttributeOf(node);
m_player_karts.findYourDataInAnAttributeOf(node);

View File

@ -60,7 +60,7 @@ protected:
* WARNING : m_savedgp_group has to be declared before the other userconfigparams!
*/
GroupUserConfigParam m_savedgp_group;
StringUserConfigParam m_player_id;
unsigned int m_player_id;
/** Identifier of this GP. */
StringUserConfigParam m_gp_id;
@ -81,7 +81,7 @@ public:
/**
* Constructor to create a new entry.
*/
SavedGrandPrix(const std::string &player_id,
SavedGrandPrix(unsigned int player_id,
const std::string &gp_id,
RaceManager::Difficulty difficulty,
int player_karts,
@ -98,7 +98,7 @@ public:
// ------------------------------------------------------------------------
/** Returns the player id for this saved GP. */
const std::string getPlayerID() const { return m_player_id; }
unsigned int getPlayerID() const { return m_player_id; }
// ------------------------------------------------------------------------
/** Returns the grand prix id. */
@ -137,7 +137,7 @@ public:
/** Finds the right SavedGrandPrix given the specified data, or
* NULL if no matching GP was found.
*/
static SavedGrandPrix* getSavedGP(const std::string &player,
static SavedGrandPrix* getSavedGP(unsigned int player,
const std::string &gpid,
int difficulty, int total_karts,
int player_karts)

View File

@ -728,38 +728,6 @@ UserConfig::~UserConfig()
UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll();
} // ~UserConfig
// -----------------------------------------------------------------------------
void UserConfig::addDefaultPlayer()
{
std::string username = "unnamed player";
if(getenv("USERNAME")!=NULL) // for windows
username = getenv("USERNAME");
else if(getenv("USER")!=NULL) // Linux, Macs
username = getenv("USER");
else if(getenv("LOGNAME")!=NULL) // Linux, Macs
username = getenv("LOGNAME");
class GuestPlayerProfile : public PlayerProfile
{
public:
GuestPlayerProfile() : PlayerProfile(_LTR("Guest"))
{
m_is_guest_account = true;
}
};
// add default guest player
UserConfigParams::m_all_players.push_back( new GuestPlayerProfile() );
// Set the name as the default name for all players.
UserConfigParams::m_all_players.push_back(
new PlayerProfile(username.c_str()) );
} // addDefaultPlayer
// -----------------------------------------------------------------------------
/** Comparison used to sort players. Most frequent players should be

View File

@ -826,7 +826,6 @@ public:
void resetWarning() { m_warning=""; }
void setWarning(irr::core::stringw& warning) { m_warning=warning; }
void postLoadInit();
void addDefaultPlayer();
}; // UserConfig

View File

@ -149,6 +149,7 @@
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "graphics/hardware_skinning.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
@ -680,8 +681,7 @@ int handleCmdLine()
if(CommandLine::has("--kart", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0).getUniqueID());
if (!unlock_manager->getCurrentSlot()->isLocked(s))
{
@ -972,6 +972,7 @@ void initUserConfig()
{
irr_driver = new IrrDriver();
file_manager = new FileManager();
PlayerManager::get()->load();
user_config = new UserConfig(); // needs file_manager
const bool config_ok = user_config->loadConfig();
if (UserConfigParams::m_language.toString() != "system")
@ -989,10 +990,10 @@ void initUserConfig()
stk_config = new STKConfig(); // in case of --stk-config
// command line parameters
user_config->postLoadInit();
if (!config_ok || UserConfigParams::m_all_players.size() == 0)
if (!config_ok || PlayerManager::get()->getNumPlayers() == 0)
{
user_config->addDefaultPlayer();
user_config->saveConfig();
PlayerManager::get()->addDefaultPlayer();
PlayerManager::get()->save();
}
} // initUserConfig
@ -1113,6 +1114,7 @@ static void cleanSuperTuxKart()
delete ParticleKindManager::get();
if(stk_config) delete stk_config;
if(user_config) delete user_config;
PlayerManager::destroy();
if(unlock_manager) delete unlock_manager;
if(translations) delete translations;
if(file_manager) delete file_manager;

0
src/modes/easter_egg_hunt.hpp Executable file → Normal file
View File

View File

@ -22,6 +22,7 @@
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
@ -102,14 +103,14 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
// ---- Otherwise, see if we can accept the new name
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
stringw playerName = textCtrl->getText().trim();
if (StringUtils::notEmpty(playerName))
stringw player_name = textCtrl->getText().trim();
if (StringUtils::notEmpty(player_name))
{
// check for duplicates
const int amount = UserConfigParams::m_all_players.size();
for (int n=0; n<amount; n++)
{
if (UserConfigParams::m_all_players[n].getName() == playerName)
if (UserConfigParams::m_all_players[n].getName() == player_name)
{
LabelWidget* label = getWidget<LabelWidget>("title");
label->setText(_("Cannot add a player with this name."), false);
@ -119,7 +120,8 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
}
// Finally, add the new player.
UserConfigParams::m_all_players.push_back( new PlayerProfile(playerName) );
PlayerManager::get()->addNewPlayer(player_name);
UserConfigParams::m_all_players.push_back( new PlayerProfile(player_name));
bool created = unlock_manager->createSlotsIfNeeded();
if (created) unlock_manager->save();
user_config->saveConfig();
@ -144,7 +146,7 @@ void EnterPlayerNameDialog::onUpdate(float dt)
if (m_self_destroy)
{
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
stringw playerName = textCtrl->getText().trim();
stringw player_name = textCtrl->getText().trim();
// irrLicht is too stupid to remove focus from deleted widgets
// so do it by hand
@ -158,6 +160,6 @@ void EnterPlayerNameDialog::onUpdate(float dt)
ModalDialog::dismiss();
if (listener != NULL) listener->onNewPlayerWithName( playerName );
if (listener != NULL) listener->onNewPlayerWithName( player_name );
}
}

View File

@ -78,7 +78,7 @@ void OptionsScreenPlayers::init()
refreshPlayerList();
ButtonWidget* you = getWidget<ButtonWidget>("playername");
const std::string& playerID = unlock_manager->getCurrentSlot()->getPlayerID();
unsigned int playerID = unlock_manager->getCurrentSlot()->getPlayerID();
core::stringw playerName = L"-";
PlayerProfile* curr;
for_in (curr, UserConfigParams::m_all_players)