From 9589f7c9a5c1a19b6ad720e2678602c8ccac4bfd Mon Sep 17 00:00:00 2001 From: wardje Date: Thu, 21 Jun 2012 16:33:30 +0000 Subject: [PATCH] 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 --- src/config/player.hpp | 10 +-- src/states_screens/options_screen_players.cpp | 71 ++++++++----------- src/states_screens/options_screen_players.hpp | 3 +- 3 files changed, 37 insertions(+), 47 deletions(-) diff --git a/src/config/player.hpp b/src/config/player.hpp index 67bf9daa9..81cbe3ec4 100644 --- a/src/config/player.hpp +++ b/src/config/player.hpp @@ -80,9 +80,9 @@ public: void setName(const core::stringw& name) { #ifdef DEBUG - assert(m_magic_number == 0xABCD1234); + assert(m_magic_number == 0xABCD1234); #endif - m_name = name; + m_name = name; } core::stringw getName() const @@ -90,15 +90,15 @@ public: #ifdef DEBUG assert(m_magic_number == 0xABCD1234); #endif - return m_name.c_str(); + return m_name.c_str(); } bool isGuestAccount() const { #ifdef DEBUG - assert(m_magic_number == 0xABCD1234); + assert(m_magic_number == 0xABCD1234); #endif - return m_is_guest_account; + return m_is_guest_account; } int getUseFrequency() const diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index d356fa0e7..86c2545fb 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -72,20 +72,12 @@ void OptionsScreenPlayers::init() tabBar->getRibbonChildren()[1].setTooltip( _("Audio") ); tabBar->getRibbonChildren()[2].setTooltip( _("User Interface") ); tabBar->getRibbonChildren()[4].setTooltip( _("Controls") ); - + ListWidget* players = this->getWidget("players"); assert(players != NULL); - - const int playerAmount = UserConfigParams::m_all_players.size(); - for(int n=0; naddItem( core::stringc(UserConfigParams::m_all_players[n].getName().c_str()).c_str(), - translations->fribidize(UserConfigParams::m_all_players[n].getName()) ); - } - + + refreshPlayerList(); + ButtonWidget* you = getWidget("playername"); const std::string& playerID = unlock_manager->getCurrentSlot()->getPlayerID(); core::stringw playerName = L"-"; @@ -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("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; naddItem(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("players"); - if(players == NULL) return; - players->clear(); - - const int playerAmount = UserConfigParams::m_all_players.size(); - for(int n=0; naddItem(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("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; +} diff --git a/src/states_screens/options_screen_players.hpp b/src/states_screens/options_screen_players.hpp index d1afa6167..d59db3f17 100644 --- a/src/states_screens/options_screen_players.hpp +++ b/src/states_screens/options_screen_players.hpp @@ -36,8 +36,9 @@ class PlayerProfile; class OptionsScreenPlayers : public GUIEngine::Screen, public EnterPlayerNameDialog::INewPlayerListener, public GUIEngine::ScreenSingleton { - +private: OptionsScreenPlayers(); + bool refreshPlayerList(); public: friend class GUIEngine::ScreenSingleton;