Remove gameslots when they don't have a player
Gameslots were not getting removed when players got removed. Add a check when the player options screen gets torn down. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11325 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
97c5153832
commit
1caba55886
@ -278,7 +278,9 @@ void UnlockManager::save()
|
||||
} // save
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/** Creates a gameslot for players that don't have one yet
|
||||
* \return true if any were created
|
||||
*/
|
||||
bool UnlockManager::createSlotsIfNeeded()
|
||||
{
|
||||
bool something_changed = false;
|
||||
@ -318,7 +320,48 @@ bool UnlockManager::createSlotsIfNeeded()
|
||||
}
|
||||
|
||||
return something_changed;
|
||||
}
|
||||
} // UnlockManager::createSlotsIfNeeded
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Removes gameslots that refer to a non-existing player.
|
||||
* \return true if any were removed
|
||||
*/
|
||||
bool UnlockManager::deleteSlotsIfNeeded()
|
||||
{
|
||||
bool changed = false;
|
||||
std::map<std::string, GameSlot*>::iterator it = m_game_slots.begin();
|
||||
while (it != m_game_slots.end())
|
||||
{
|
||||
bool found = false;
|
||||
const int playerAmount = UserConfigParams::m_all_players.size();
|
||||
for (int i = 0; i < playerAmount; i++)
|
||||
{
|
||||
if (it->second->getPlayerID() ==
|
||||
UserConfigParams::m_all_players[i].getUniqueID())
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
} // for players
|
||||
|
||||
if (!found)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("Deleting gameslot %s, no player found.\n",
|
||||
it->second->getPlayerID().c_str());
|
||||
#endif
|
||||
// Iterators aren't invalidated this way
|
||||
m_game_slots.erase(it++);
|
||||
changed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
} // for gameslots
|
||||
|
||||
return changed;
|
||||
} // UnlockManager::deleteSlotsIfNeeded
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void UnlockManager::playLockSound() const
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
void addChallenge (const std::string& filename);
|
||||
void save ();
|
||||
bool createSlotsIfNeeded();
|
||||
bool deleteSlotsIfNeeded();
|
||||
|
||||
const ChallengeData *getChallenge (const std::string& id);
|
||||
|
||||
|
@ -141,8 +141,9 @@ void OptionsScreenPlayers::tearDown()
|
||||
{
|
||||
Screen::tearDown();
|
||||
user_config->saveConfig();
|
||||
bool changed = unlock_manager->createSlotsIfNeeded();
|
||||
if (changed) unlock_manager->save();
|
||||
bool created = unlock_manager->createSlotsIfNeeded();
|
||||
bool removed = unlock_manager->deleteSlotsIfNeeded();
|
||||
if (created || removed) unlock_manager->save();
|
||||
} // tearDown
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user