Fixed bug when selecting player profile, don't rely on numerical IDs, they may not match because the guest profile is skipped
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10378 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b338e1f0d6
commit
eccc1a66b4
@ -44,9 +44,9 @@ UnlockManager::UnlockManager()
|
||||
// The global variable 'unlock_manager' is needed in the challenges,
|
||||
// but it's not set yet - so we define it here (and it gets re-assign
|
||||
// in main).
|
||||
unlock_manager=this;
|
||||
unlock_manager = this;
|
||||
|
||||
m_current_game_slot = 0;
|
||||
m_current_game_slot = L"";
|
||||
|
||||
m_locked_sound = sfx_manager->createSoundSource("locked");
|
||||
|
||||
@ -91,6 +91,13 @@ UnlockManager::~UnlockManager()
|
||||
delete i->second;
|
||||
}
|
||||
|
||||
|
||||
std::map<irr::core::stringw, GameSlot*>::iterator it;
|
||||
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
|
||||
// sfx_manager is destroyed before UnlockManager is, so SFX will be already deleted
|
||||
// sfx_manager->deleteSFX(m_locked_sound);
|
||||
} // ~UnlockManager
|
||||
@ -215,7 +222,7 @@ void UnlockManager::load()
|
||||
xml_game_slots[n]->get("kart", &kart_id);
|
||||
slot->setKartIdent(kart_id);
|
||||
|
||||
m_game_slots.push_back(slot);
|
||||
m_game_slots[player_name] = slot;
|
||||
|
||||
for(AllChallengesType::iterator i = m_all_challenges.begin();
|
||||
i!=m_all_challenges.end(); i++)
|
||||
@ -251,10 +258,11 @@ void UnlockManager::save()
|
||||
challenge_file << "<?xml version=\"1.0\"?>\n";
|
||||
challenge_file << "<challenges>\n";
|
||||
|
||||
GameSlot* curr;
|
||||
for_in (curr, m_game_slots)
|
||||
|
||||
std::map<irr::core::stringw, GameSlot*>::iterator it;
|
||||
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
|
||||
{
|
||||
curr->save(challenge_file);
|
||||
it->second->save(challenge_file);
|
||||
}
|
||||
|
||||
challenge_file << "</challenges>\n\n";
|
||||
@ -273,9 +281,10 @@ bool UnlockManager::createSlotsIfNeeded()
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
GameSlot* curr_slot;
|
||||
for_in(curr_slot, m_game_slots)
|
||||
std::map<irr::core::stringw, GameSlot*>::iterator it;
|
||||
for (it = m_game_slots.begin(); it != m_game_slots.end(); it++)
|
||||
{
|
||||
GameSlot* curr_slot = it->second;
|
||||
if (curr_slot->getPlayerName() == players[n].getName())
|
||||
{
|
||||
exists = true;
|
||||
@ -283,7 +292,6 @@ bool UnlockManager::createSlotsIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!exists)
|
||||
{
|
||||
GameSlot* slot = new GameSlot(players[n].getName());
|
||||
@ -295,7 +303,7 @@ bool UnlockManager::createSlotsIfNeeded()
|
||||
slot->m_challenges_state[cd->getId()] = new Challenge(cd);
|
||||
}
|
||||
slot->computeActive();
|
||||
m_game_slots.push_back(slot);
|
||||
m_game_slots[players[n].getName()] = slot;
|
||||
|
||||
something_changed = true;
|
||||
}
|
||||
@ -323,3 +331,16 @@ bool UnlockManager::isSupportedVersion(const ChallengeData &challenge)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
PlayerProfile* UnlockManager::getCurrentPlayer()
|
||||
{
|
||||
PtrVector<PlayerProfile>& players = UserConfigParams::m_all_players;
|
||||
for (int n=0; n<players.size(); n++)
|
||||
{
|
||||
if (players[n].getName() == m_current_game_slot) return players.get(n);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -48,12 +48,12 @@ private:
|
||||
typedef std::map<std::string, ChallengeData*> AllChallengesType;
|
||||
AllChallengesType m_all_challenges;
|
||||
|
||||
PtrVector<GameSlot> m_game_slots;
|
||||
std::map<irr::core::stringw, GameSlot*> m_game_slots;
|
||||
|
||||
void readAllChallengesInDirs(const std::vector<std::string>* all_dirs);
|
||||
bool createSlotsIfNeeded();
|
||||
|
||||
int m_current_game_slot;
|
||||
irr::core::stringw m_current_game_slot;
|
||||
|
||||
friend class GameSlot;
|
||||
|
||||
@ -71,11 +71,12 @@ public:
|
||||
/** Eye- (or rather ear-) candy. Play a sound when user tries to access a locked area */
|
||||
void playLockSound() const;
|
||||
|
||||
GameSlot* getCurrentSlot() { return m_game_slots.get(m_current_game_slot); }
|
||||
GameSlot* getCurrentSlot() { return m_game_slots[m_current_game_slot]; }
|
||||
|
||||
void setCurrentSlot(int slotid) { m_current_game_slot = slotid; }
|
||||
/** \param slotid name of the player */
|
||||
void setCurrentSlot(irr::core::stringw slotid) { m_current_game_slot = slotid; }
|
||||
|
||||
PlayerProfile* getCurrentPlayer() { return UserConfigParams::m_all_players.get(m_current_game_slot); };
|
||||
PlayerProfile* getCurrentPlayer();
|
||||
|
||||
}; // UnlockManager
|
||||
|
||||
|
@ -61,7 +61,7 @@ void StoryModeLobbyScreen::init()
|
||||
{
|
||||
if (players[n].getName() == UserConfigParams::m_default_player.toString())
|
||||
{
|
||||
unlock_manager->setCurrentSlot(n);
|
||||
unlock_manager->setCurrentSlot(players[n].getName());
|
||||
StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());
|
||||
return;
|
||||
}
|
||||
@ -113,7 +113,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name
|
||||
{
|
||||
if (list->getSelectionLabel() == players[n].getName())
|
||||
{
|
||||
unlock_manager->setCurrentSlot(n);
|
||||
unlock_manager->setCurrentSlot(players[n].getName());
|
||||
slot_found = true;
|
||||
break;;
|
||||
}
|
||||
@ -155,7 +155,7 @@ void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName)
|
||||
{
|
||||
if (players[n].getName() == newName)
|
||||
{
|
||||
unlock_manager->setCurrentSlot(n);
|
||||
unlock_manager->setCurrentSlot(players[n].getName());
|
||||
slot_found = true;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user