Removed m_all_players from UserConfigParams (though there are stil

bugs in the new code).
This commit is contained in:
hiker 2014-02-06 23:08:55 +11:00
parent 78b73aa3c8
commit 045bfeaf13
15 changed files with 196 additions and 191 deletions

View File

@ -18,13 +18,14 @@
#include "achievements/achievements_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "online/current_user.hpp"
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "io/file_manager.hpp"
#include "config/player.hpp"
#include "config/user_config.hpp"
#include "online/current_user.hpp"
#include "challenges/unlock_manager.hpp"
#include <sstream>
#include <stdlib.h>
@ -155,12 +156,12 @@ void AchievementsManager::createSlotsIfNeeded()
bool something_changed = false;
// make sure all players have at least one game slot associated
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
for (unsigned int n=0; n<players.size(); n++)
for (unsigned int i=0; i<PlayerManager::get()->getNumPlayers(); i++)
{
if (getSlot(players[n].getUniqueID(), false) == NULL )
const PlayerProfile *player = PlayerManager::get()->getPlayer(i);
if (getSlot(player->getUniqueID(), false) == NULL )
{
createNewSlot(players[n].getUniqueID(), false);
createNewSlot(player->getUniqueID(), false);
something_changed = true;
}
}

View File

@ -18,17 +18,13 @@
#include "challenges/unlock_manager.hpp"
#include <set>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
#include "achievements/achievements_manager.hpp"
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/challenge_data.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "io/file_manager.hpp"
#include "karts/kart_properties_manager.hpp"
@ -37,6 +33,12 @@
#include "utils/log.hpp"
#include "utils/string_utils.hpp"
#include <set>
#include <string>
#include <vector>
#include <stdio.h>
#include <iostream>
UnlockManager* unlock_manager=0;
//-----------------------------------------------------------------------------
@ -283,11 +285,12 @@ void UnlockManager::save()
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
{
std::string name = "unknown player";
for (unsigned int i = 0; i < UserConfigParams::m_all_players.size(); i++)
for (unsigned int i = 0; i < PlayerManager::get()->getNumPlayers(); i++)
{
if (UserConfigParams::m_all_players[i].getUniqueID() == it->second->getPlayerID())
const PlayerProfile *player = PlayerManager::get()->getPlayer(i);
if (player->getUniqueID() == it->second->getPlayerID())
{
name = core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str();
name = core::stringc(player->getName().c_str()).c_str();
break;
}
}
@ -308,25 +311,25 @@ bool UnlockManager::createSlotsIfNeeded()
bool something_changed = false;
// make sure all players have at least one game slot associated
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
for (unsigned int n=0; n<players.size(); n++)
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
bool exists = false;
const PlayerProfile *profile = PlayerManager::get()->getPlayer(n);
std::map<unsigned int, GameSlot*>::iterator it;
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
{
GameSlot* curr_slot = it->second;
if (curr_slot->getPlayerID() == players[n].getUniqueID())
if (curr_slot->getPlayerID() == profile->getUniqueID())
{
exists = true;
break;
}
}
} // for it in m_game_slots
if (!exists)
{
GameSlot* slot = new GameSlot(players[n].getUniqueID());
GameSlot* slot = new GameSlot(profile->getUniqueID());
for(AllChallengesType::iterator i = m_all_challenges.begin();
i!=m_all_challenges.end(); i++)
{
@ -335,7 +338,7 @@ bool UnlockManager::createSlotsIfNeeded()
}
slot->computeActive();
m_game_slots[players[n].getUniqueID()] = slot;
m_game_slots[profile->getUniqueID()] = slot;
something_changed = true;
}
@ -355,11 +358,11 @@ bool UnlockManager::deleteSlotsIfNeeded()
while (it != m_game_slots.end())
{
bool found = false;
const int playerAmount = UserConfigParams::m_all_players.size();
for (int i = 0; i < playerAmount; i++)
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int i = 0; i < player_amount; i++)
{
if (it->second->getPlayerID() ==
UserConfigParams::m_all_players[i].getUniqueID())
PlayerManager::get()->getPlayer(i)->getUniqueID())
{
found = true;
break;
@ -407,10 +410,10 @@ bool UnlockManager::isSupportedVersion(const ChallengeData &challenge)
PlayerProfile* UnlockManager::getCurrentPlayer()
{
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
for (unsigned int n=0; n<players.size(); n++)
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
if (players[n].getUniqueID() == m_current_game_slot) return players.get(n);
PlayerProfile* player = PlayerManager::get()->getPlayer(n);
if (player->getUniqueID() == m_current_game_slot) return player;
}
return NULL;
}

View File

@ -79,3 +79,24 @@ void PlayerProfile::incrementUseFrequency()
if (m_is_guest_account) m_use_frequency = -1;
else m_use_frequency++;
} // incrementUseFrequency
//------------------------------------------------------------------------------
/** Comparison used to sort players. Most frequent players should be
* listed first, so a<b actually means that
* a.m_use_frequency > b.m_use_frequency
* This way we get a reversed sorted list.
*/
bool PlayerProfile::operator<(const PlayerProfile &other)
{
return getUseFrequency() > other.getUseFrequency();
} // operator<
// -----------------------------------------------------------------------------
/** \brief Needed for toggling sort order **/
bool PlayerProfile::operator>(const PlayerProfile &other)
{
return getUseFrequency() < other.getUseFrequency();
} // operator>
// -----------------------------------------------------------------------------

View File

@ -65,6 +65,9 @@ public:
void save(UTFWriter &out);
void incrementUseFrequency();
bool operator<(const PlayerProfile &other);
bool operator>(const PlayerProfile &other);
~PlayerProfile()
{

View File

@ -58,8 +58,13 @@ void PlayerManager::load()
{
const XMLNode *player_xml = players->getNode(i);
PlayerProfile *profile = new PlayerProfile(player_xml);
if(profile->isGuestAccount())
profile->setName(_LTR("Guest"));
m_all_players.push_back(profile);
}
m_all_players.insertionSort();
} // load
// ----------------------------------------------------------------------------
@ -100,6 +105,12 @@ void PlayerManager::addNewPlayer(const core::stringw& name)
m_all_players.push_back( new PlayerProfile(name) );
} // addNewPlayer
// ----------------------------------------------------------------------------
void PlayerManager::deletePlayer(PlayerProfile *player)
{
m_all_players.erase(player);
} // deletePlayer
// ----------------------------------------------------------------------------
void PlayerManager::addDefaultPlayer()
{
@ -137,5 +148,27 @@ unsigned int PlayerManager::getUniqueId() const
} // getUniqueId
// ----------------------------------------------------------------------------
const PlayerProfile *PlayerManager::getPlayerById(unsigned int id)
{
const PlayerProfile *player;
for_in(player, m_all_players)
{
if(player->getUniqueID()==id)
return player;
}
return NULL;
} // getPlayerById
// ----------------------------------------------------------------------------
PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name)
{
PlayerProfile *player;
for_in(player, m_all_players)
{
if(player->getName()==name)
return player;
}
return NULL;
} // getPlayer
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------

View File

@ -63,12 +63,22 @@ public:
unsigned int getUniqueId() const;
void addDefaultPlayer();
void addNewPlayer(const irr::core::stringw& name);
void deletePlayer(PlayerProfile *player);
const PlayerProfile *getPlayerById(unsigned int id);
// ------------------------------------------------------------------------
PlayerProfile *getPlayer(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];}
const PlayerProfile *getPlayer(unsigned int n) const
{
return &m_all_players[n];
} // getPlayer
// ------------------------------------------------------------------------
/** Returns a player with a given unique id. */
PlayerProfile *getPlayer(unsigned int n) { return &m_all_players[n];}
// ------------------------------------------------------------------------
}; // PlayerManager

View File

@ -724,29 +724,9 @@ UserConfig::UserConfig()
// -----------------------------------------------------------------------------
UserConfig::~UserConfig()
{
UserConfigParams::m_all_players.clearAndDeleteAll();
UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll();
} // ~UserConfig
// -----------------------------------------------------------------------------
/** Comparison used to sort players. Most frequent players should be
* listed first, so a<b actually means that
* a.m_use_frequency > b.m_use_frequency
* This way we get a reversed sorted list.
*/
bool operator<(const PlayerProfile &a, const PlayerProfile &b)
{
return a.getUseFrequency() > b.getUseFrequency();
} // operator<
// -----------------------------------------------------------------------------
/** \brief Needed for toggling sort order **/
bool operator>(const PlayerProfile &a, const PlayerProfile &b)
{
return a.getUseFrequency() < b.getUseFrequency();
} // operator>
// -----------------------------------------------------------------------------
/** Load configuration values from file. */
bool UserConfig::loadConfig()
@ -791,26 +771,6 @@ bool UserConfig::loadConfig()
}
// ---- Read players
// we create those AFTER other values are being read simply because we have many Player
// nodes that all bear the same name, so the generic loading code won't work here
UserConfigParams::m_all_players.clearAndDeleteAll();
std::vector<XMLNode*> players;
root->getNodes("Player", players);
const int amount = players.size();
for (int i=0; i<amount; i++)
{
//std::string name;
//players[i]->get("name", &name);
UserConfigParams::m_all_players.push_back(
new PlayerProfile(players[i]) );
}
// sort players by frequency of use
UserConfigParams::m_all_players.insertionSort();
// ---- Read Saved GP's
UserConfigParams::m_saved_grand_prix_list.clearAndDeleteAll();
std::vector<XMLNode*> saved_gps;
@ -826,17 +786,6 @@ bool UserConfig::loadConfig()
return true;
} // loadConfig
// ----------------------------------------------------------------------------
void UserConfig::postLoadInit()
{
for (unsigned int i = 0; i < UserConfigParams::m_all_players.size(); i++)
{
PlayerProfile* player = UserConfigParams::m_all_players.get(i);
if (player->isGuestAccount()) player->setName(_LTR("Guest"));
}
}
// ----------------------------------------------------------------------------
/** Write settings to config file. */
void UserConfig::saveConfig()

View File

@ -769,8 +769,6 @@ namespace UserConfigParams
// TODO? implement blacklist for new irrlicht device and GUI
PARAM_PREFIX std::vector<std::string> m_blacklist_res;
PARAM_PREFIX PtrVector<PlayerProfile> m_all_players;
/** List of all saved GPs. */
PARAM_PREFIX PtrVector<SavedGrandPrix> m_saved_grand_prix_list;
@ -825,7 +823,6 @@ public:
const irr::core::stringw& getWarning() { return m_warning; }
void resetWarning() { m_warning=""; }
void setWarning(irr::core::stringw& warning) { m_warning=warning; }
void postLoadInit();
}; // UserConfig

View File

@ -146,10 +146,10 @@
#include "audio/music_manager.hpp"
#include "audio/sfx_manager.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "config/stk_config.hpp"
#include "config/user_config.hpp"
#include "graphics/hardware_skinning.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/material_manager.hpp"
@ -681,7 +681,8 @@ int handleCmdLine()
if(CommandLine::has("--kart", &s))
{
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0).getUniqueID());
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0)
->getUniqueID());
if (!unlock_manager->getCurrentSlot()->isLocked(s))
{
@ -750,8 +751,8 @@ int handleCmdLine()
if(CommandLine::has("--track", &s) || CommandLine::has("-t", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0)
->getUniqueID());
if (!unlock_manager->getCurrentSlot()->isLocked(s))
{
race_manager->setTrack(s);
@ -898,8 +899,8 @@ int handleCmdLine()
// Demo mode
if(CommandLine::has("--demo-mode", &s))
{
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0)
->getUniqueID());
float t;
StringUtils::fromString(s, t);
DemoWorld::enableDemoMode(t);
@ -941,8 +942,8 @@ int handleCmdLine()
CommandLine::reportInvalidParameters();
if(UserConfigParams::m_no_start_screen)
unlock_manager->setCurrentSlot(UserConfigParams::m_all_players[0]
.getUniqueID() );
unlock_manager->setCurrentSlot(PlayerManager::get()->getPlayer(0)
->getUniqueID());
if(ProfileWorld::isProfileMode())
{
UserConfigParams::m_sfx = false; // Disable sound effects
@ -989,7 +990,6 @@ void initUserConfig()
translations = new Translations(); // needs file_manager
stk_config = new STKConfig(); // in case of --stk-config
// command line parameters
user_config->postLoadInit();
if (!config_ok || PlayerManager::get()->getNumPlayers() == 0)
{
PlayerManager::get()->addDefaultPlayer();
@ -1257,12 +1257,11 @@ int main(int argc, char *argv[] )
// no graphics, and no profile mode
if (ProfileWorld::isNoGraphics() && !ProfileWorld::isProfileMode())
{
core::stringw name = UserConfigParams::m_default_player.toString();
PlayerProfile *player = PlayerManager::get()->getPlayer(name);
// hack to have a running game slot :
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
if (UserConfigParams::m_default_player.toString().size() > 0)
for (unsigned int n=0; n<players.size(); n++)
if (players[n].getName() == UserConfigParams::m_default_player.toString())
unlock_manager->setCurrentSlot(players[n].getUniqueID());
if(player)
unlock_manager->setCurrentSlot(player->getUniqueID());
}
else if(!UserConfigParams::m_no_start_screen)
@ -1316,7 +1315,7 @@ int main(int argc, char *argv[] )
// Create player and associate player with keyboard
StateManager::get()->createActivePlayer(
UserConfigParams::m_all_players.get(0), device, NULL);
PlayerManager::get()->getPlayer(0), device, NULL);
if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL)
{

View File

@ -18,6 +18,7 @@
#include "modes/demo_world.hpp"
#include "config/player_manager.hpp"
#include "guiengine/modaldialog.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
@ -140,7 +141,7 @@ bool DemoWorld::updateIdleTimeAndStartDemo(float dt)
// Use keyboard 0 by default in --no-start-screen
device = input_manager->getDeviceList()->getKeyboard(0);
StateManager::get()->createActivePlayer(
UserConfigParams::m_all_players.get(0), device , NULL);
PlayerManager::get()->getPlayer(0), device , NULL);
// ASSIGN should make sure that only input from assigned devices
// is read.
input_manager->getDeviceList()->setAssignMode(ASSIGN);

View File

@ -107,10 +107,10 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
if (StringUtils::notEmpty(player_name))
{
// check for duplicates
const int amount = UserConfigParams::m_all_players.size();
const int amount = PlayerManager::get()->getNumPlayers();
for (int n=0; n<amount; n++)
{
if (UserConfigParams::m_all_players[n].getName() == player_name)
if (PlayerManager::get()->getPlayer(n)->getName() == player_name)
{
LabelWidget* label = getWidget<LabelWidget>("title");
label->setText(_("Cannot add a player with this name."), false);
@ -121,7 +121,6 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
// Finally, add the new player.
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();

View File

@ -23,6 +23,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"
@ -228,12 +229,13 @@ GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& ev
// accept entered name
stringw playerName = textCtrl->getText().trim();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
const int player_amount = PlayerManager::get()->getNumPlayers();
for(int n=0; n<player_amount; n++)
{
if (UserConfigParams::m_all_players.get(n) == m_player) continue;
const PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player == m_player) continue;
if (UserConfigParams::m_all_players[n].getName() == playerName)
if (player->getName() == playerName)
{
ButtonWidget* label = getWidget<ButtonWidget>("renameplayer");
label->setBadge(BAD_BADGE);

View File

@ -16,10 +16,12 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "states_screens/kart_selection.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "config/user_config.hpp"
#include "kart_selection.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/screen.hpp"
@ -252,10 +254,10 @@ PlayerKartWidget::PlayerKartWidget(KartSelectionScreen* parent,
m_player_ident_spinner->m_properties[PROP_ID] = spinnerID;
if (parent->m_multiplayer)
{
const int playerAmount = UserConfigParams::m_all_players.size();
const int player_amount = PlayerManager::get()->getNumPlayers();
m_player_ident_spinner->m_properties[PROP_MIN_VALUE] = "0";
m_player_ident_spinner->m_properties[PROP_MAX_VALUE] =
StringUtils::toString(playerAmount-1);
StringUtils::toString(player_amount-1);
m_player_ident_spinner->m_properties[PROP_WRAP_AROUND] = "true";
}
else
@ -474,10 +476,10 @@ void PlayerKartWidget::add()
if (m_parent_screen->m_multiplayer)
{
const int playerAmount = UserConfigParams::m_all_players.size();
for (int n=0; n<playerAmount; n++)
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int n=0; n<player_amount; n++)
{
core::stringw name = UserConfigParams::m_all_players[n].getName();
core::stringw name = PlayerManager::get()->getPlayer(n)->getName();
m_player_ident_spinner->addLabel( translations->fribidize(name) );
}
@ -700,7 +702,7 @@ GUIEngine::EventPropagation PlayerKartWidget::transmitEvent(
if (m_parent_screen->m_multiplayer)
{
m_associatedPlayer->setPlayerProfile(
UserConfigParams::m_all_players.get(m_player_ident_spinner
PlayerManager::get()->getPlayer(m_player_ident_spinner
->getValue()) );
}
}
@ -1097,16 +1099,17 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
kartsAreaWidget->m_y + kartsAreaWidget->m_h);
// ---- Create new active player
PlayerProfile* profileToUse = unlock_manager->getCurrentPlayer();
PlayerProfile* profile_to_use = unlock_manager->getCurrentPlayer();
if (!firstPlayer)
{
const int playerProfileCount = UserConfigParams::m_all_players.size();
for (int n=0; n<playerProfileCount; n++)
const int player_profile_count = PlayerManager::get()->getNumPlayers();
for (int i=0; i<player_profile_count; i++)
{
if (UserConfigParams::m_all_players[n].isGuestAccount())
PlayerProfile *player = PlayerManager::get()->getPlayer(i);
if (player->isGuestAccount())
{
profileToUse = UserConfigParams::m_all_players.get(n);
profile_to_use = player;
break;
}
}
@ -1124,7 +1127,7 @@ bool KartSelectionScreen::playerJoin(InputDevice* device, bool firstPlayer)
}
const int new_player_id =
StateManager::get()->createActivePlayer( profileToUse, device, NULL );
StateManager::get()->createActivePlayer( profile_to_use, device, NULL );
StateManager::ActivePlayer* aplayer =
StateManager::get()->getActivePlayer(new_player_id);
@ -1817,8 +1820,9 @@ bool KartSelectionScreen::validateIdentChoices()
if (m_multiplayer)
{
assert(m_kart_widgets[n].getAssociatedPlayer()->getProfile() ==
UserConfigParams::m_all_players.get(m_kart_widgets[n]
.m_player_ident_spinner->getValue()) );
PlayerManager::get()->getPlayer(m_kart_widgets[n]
.m_player_ident_spinner->getValue())
);
}
}
}

View File

@ -19,6 +19,7 @@
#include "challenges/unlock_manager.hpp"
#include "config/player.hpp"
#include "config/player_manager.hpp"
#include "config/device_config.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/scalable_font.hpp"
@ -79,17 +80,12 @@ void OptionsScreenPlayers::init()
ButtonWidget* you = getWidget<ButtonWidget>("playername");
unsigned int playerID = unlock_manager->getCurrentSlot()->getPlayerID();
core::stringw playerName = L"-";
PlayerProfile* curr;
for_in (curr, UserConfigParams::m_all_players)
{
if (curr->getUniqueID() == playerID)
{
playerName = curr->getName();
break;
}
}
you->setText( playerName );
core::stringw player_name = L"-";
const PlayerProfile* curr = PlayerManager::get()->getPlayerById(playerID);
if(curr)
player_name = curr->getName();
you->setText( player_name );
((gui::IGUIButton*)you->getIrrlichtElement())->setOverrideFont( GUIEngine::getSmallFont() );
if (StateManager::get()->getGameState() == GUIEngine::INGAME_MENU)
@ -129,7 +125,7 @@ void OptionsScreenPlayers::onNewPlayerWithName(const stringw& newName)
void OptionsScreenPlayers::deletePlayer(PlayerProfile* player)
{
UserConfigParams::m_all_players.erase(player);
PlayerManager::get()->deletePlayer(player);
refreshPlayerList();
} // deletePlayer
@ -174,14 +170,15 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name
assert(players != NULL);
core::stringw selectedPlayer = players->getSelectionLabel();
const int playerAmount = UserConfigParams::m_all_players.size();
for (int n=0; n<playerAmount; n++)
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int i=0; i<player_amount; i++)
{
if (selectedPlayer == translations->fribidize(UserConfigParams::m_all_players[n].getName()))
PlayerProfile *player = PlayerManager::get()->getPlayer(i);
if (selectedPlayer == translations->fribidize(player->getName()))
{
if (!(UserConfigParams::m_all_players[n].isGuestAccount()))
if (!(player->isGuestAccount()))
{
new PlayerInfoDialog( &UserConfigParams::m_all_players[n], 0.5f, 0.6f );
new PlayerInfoDialog( player, 0.5f, 0.6f );
}
return;
}
@ -217,15 +214,16 @@ bool OptionsScreenPlayers::refreshPlayerList()
// Get rid of previous
players->clear();
// Rebuild it
const int playerAmount = UserConfigParams::m_all_players.size();
for (int i = 0; i < playerAmount; i++)
const int player_amount = PlayerManager::get()->getNumPlayers();
for (int i = 0; i < player_amount; i++)
{
// FIXME: Using a truncated ASCII string for internal ID. Let's cross
// our fingers and hope no one enters two player names that,
// when stripped down to ASCII, give the same identifier...
const PlayerProfile *player = PlayerManager::get()->getPlayer(i);
players->addItem(
core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str(),
translations->fribidize(UserConfigParams::m_all_players[i].getName()));
core::stringc(player->getName().c_str()).c_str(),
translations->fribidize(player->getName()));
}
return true;

View File

@ -18,6 +18,7 @@
#include "states_screens/story_mode_lobby.hpp"
#include "challenges/unlock_manager.hpp"
#include "config/player_manager.hpp"
#include "guiengine/widgets/check_box_widget.hpp"
#include "guiengine/widgets/list_widget.hpp"
#include "states_screens/dialogs/enter_player_name_dialog.hpp"
@ -53,29 +54,29 @@ void StoryModeLobbyScreen::init()
ListWidget* list = getWidget<ListWidget>("gameslots");
list->clear();
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
core::stringw name = UserConfigParams::m_default_player.toString();
if (UserConfigParams::m_default_player.toString().size() > 0)
{
for (unsigned int n=0; n<players.size(); n++)
PlayerProfile *player = PlayerManager::get()->getPlayer(name);
if(player)
{
if (players[n].getName() == UserConfigParams::m_default_player.toString())
{
unlock_manager->setCurrentSlot(players[n].getUniqueID());
unlock_manager->setCurrentSlot(player->getUniqueID());
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
return;
}
}
}
for (unsigned int n=0; n<players.size(); n++)
for (unsigned int n=0; n<PlayerManager::get()->getNumPlayers(); n++)
{
if (players[n].isGuestAccount()) continue;
const PlayerProfile *player = PlayerManager::get()->getPlayer(n);
if (player->isGuestAccount()) continue;
// FIXME: we're using a trunacted ascii version of the player name as
// identifier, let's hope this causes no issues...
list->addItem(core::stringc(players[n].getName().c_str()).c_str(),
players[n].getName() );
list->addItem(core::stringc(player->getName().c_str()).c_str(),
player->getName() );
}
list->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
@ -110,32 +111,24 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget,
bool slot_found = false;
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
for (unsigned int n=0; n<players.size(); n++)
PlayerProfile *player = PlayerManager::get()
->getPlayer(list->getSelectionLabel());
if(player)
{
if (list->getSelectionLabel() == players[n].getName())
{
unlock_manager->setCurrentSlot(players[n].getUniqueID());
unlock_manager->setCurrentSlot(player->getUniqueID());
unlock_manager->updateActiveChallengeList();
slot_found = true;
break;
}
}
if (!slot_found)
{
Log::error("StoryModeLobby",
"Cannot find player corresponding to slot '%s'.",
core::stringc(list->getSelectionLabel().c_str()).c_str());
}
else
{
CheckBoxWidget* cb = getWidget<CheckBoxWidget>("rememberme");
if (cb->getState())
{
UserConfigParams::m_default_player = list->getSelectionLabel();
}
}
else
{
Log::error("StoryModeLobby",
"Cannot find player corresponding to slot '%s'.",
core::stringc(list->getSelectionLabel().c_str()).c_str());
}
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
}
@ -149,27 +142,19 @@ void StoryModeLobbyScreen::unloaded()
// ----------------------------------------------------------------------------
void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName)
void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name)
{
bool slot_found = false;
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
for (unsigned int n=0; n<players.size(); n++)
PlayerProfile *player = PlayerManager::get()->getPlayer(new_name);
if(player)
{
if (players[n].getName() == newName)
{
unlock_manager->setCurrentSlot(players[n].getUniqueID());
unlock_manager->setCurrentSlot(player->getUniqueID());
unlock_manager->updateActiveChallengeList();
slot_found = true;
break;
}
}
if (!slot_found)
else
{
Log::error("StoryModeLobbyScreen",
"Cannot find player corresponding to slot '%s'.",
core::stringc(newName.c_str()).c_str());
core::stringc(new_name.c_str()).c_str());
}
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());