Fixes minor bug in player options screen

* Fixes minor bug where incorrect internal name was set to the listitem.
 * Moves refreshing of player list to its own (private) function.
 * Also a small indentation correction in accordance with the style
   guide, which sadly makes for a big heap of recompiling.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11322 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
wardje 2012-06-21 16:33:30 +00:00
parent 7dc4e585d1
commit 9589f7c9a5
3 changed files with 37 additions and 47 deletions

View File

@ -76,15 +76,7 @@ void OptionsScreenPlayers::init()
ListWidget* players = this->getWidget<ListWidget>("players");
assert(players != NULL);
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
// 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...
players->addItem( core::stringc(UserConfigParams::m_all_players[n].getName().c_str()).c_str(),
translations->fribidize(UserConfigParams::m_all_players[n].getName()) );
}
refreshPlayerList();
ButtonWidget* you = getWidget<ButtonWidget>("playername");
const std::string& playerID = unlock_manager->getCurrentSlot()->getPlayerID();
@ -117,25 +109,8 @@ void OptionsScreenPlayers::init()
bool OptionsScreenPlayers::renamePlayer(const stringw& newName, PlayerProfile* player)
{
// 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...
stringc newNameC( newName );
ListWidget* players = this->getWidget<ListWidget>("players");
if (players == NULL) return false;
player->setName( newName );
// refresh list display
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(newNameC.c_str(), translations->fribidize(UserConfigParams::m_all_players[n].getName()));
}
refreshPlayerList();
return true;
} // renamePlayer
@ -157,17 +132,7 @@ void OptionsScreenPlayers::deletePlayer(PlayerProfile* player)
{
UserConfigParams::m_all_players.erase(player);
// refresh list display
ListWidget* players = this->getWidget<ListWidget>("players");
if(players == NULL) return;
players->clear();
const int playerAmount = UserConfigParams::m_all_players.size();
for(int n=0; n<playerAmount; n++)
{
players->addItem(core::stringc(UserConfigParams::m_all_players[n].getName().c_str()).c_str(),
translations->fribidize(UserConfigParams::m_all_players[n].getName()));
}
refreshPlayerList();
} // deletePlayer
// -----------------------------------------------------------------------------
@ -238,3 +203,27 @@ void OptionsScreenPlayers::selectPlayer(const irr::core::stringw& name)
players->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
// ----------------------------------------------------------------------------
/** Refreshes the list of players.
*/
bool OptionsScreenPlayers::refreshPlayerList()
{
ListWidget* players = this->getWidget<ListWidget>("players");
if (players == NULL) return false;
// Get rid of previous
players->clear();
// Rebuild it
const int playerAmount = UserConfigParams::m_all_players.size();
for (int i = 0; i < playerAmount; 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...
players->addItem(
core::stringc(UserConfigParams::m_all_players[i].getName().c_str()).c_str(),
translations->fribidize(UserConfigParams::m_all_players[i].getName()));
}
return true;
}

View File

@ -36,8 +36,9 @@ class PlayerProfile;
class OptionsScreenPlayers : public GUIEngine::Screen, public EnterPlayerNameDialog::INewPlayerListener,
public GUIEngine::ScreenSingleton<OptionsScreenPlayers>
{
private:
OptionsScreenPlayers();
bool refreshPlayerList();
public:
friend class GUIEngine::ScreenSingleton<OptionsScreenPlayers>;