From f26a34647e8b493d2fe9dba3869df0d70189e885 Mon Sep 17 00:00:00 2001 From: wardje Date: Sun, 8 Jul 2012 23:35:18 +0000 Subject: [PATCH] Fix #647, again Didn't take into account the lack of optionsscreen teardown when storymodelobby gets called up at STK startup (had it disabled). Creating slots and saving the configuration immediately when entering a player name now. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11377 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- .../dialogs/enter_player_name_dialog.cpp | 8 +++++++- .../dialogs/player_info_dialog.cpp | 19 ++++++++++--------- src/states_screens/options_screen_players.cpp | 12 ++++++------ src/states_screens/story_mode_lobby.cpp | 1 - 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index c1819399b..b8e5fe3ee 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -20,6 +20,8 @@ #include #include "audio/sfx_manager.hpp" +#include "challenges/unlock_manager.hpp" +#include "config/player.hpp" #include "guiengine/engine.hpp" #include "guiengine/widgets/button_widget.hpp" #include "guiengine/widgets/label_widget.hpp" @@ -96,7 +98,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal() return; } - // ---- Otherwise, accept entered name + // ---- Otherwise, see if we can accept the new name TextBoxWidget* textCtrl = getWidget("textfield"); stringw playerName = textCtrl->getText().trim(); const int size = playerName.size(); @@ -127,7 +129,11 @@ void EnterPlayerNameDialog::onEnterPressedInternal() } } + // Finally, add the new player. UserConfigParams::m_all_players.push_back( new PlayerProfile(playerName) ); + bool created = unlock_manager->createSlotsIfNeeded(); + if (created) unlock_manager->save(); + user_config->saveConfig(); // It's unsafe to delete from inside the event handler so we do it // in onUpdate (which checks for m_self_destroy) diff --git a/src/states_screens/dialogs/player_info_dialog.cpp b/src/states_screens/dialogs/player_info_dialog.cpp index 52630c41d..5edf7a396 100644 --- a/src/states_screens/dialogs/player_info_dialog.cpp +++ b/src/states_screens/dialogs/player_info_dialog.cpp @@ -37,7 +37,7 @@ using namespace GUIEngine; using namespace irr::gui; using namespace irr::core; -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- PlayerInfoDialog::PlayerInfoDialog(PlayerProfile* player, const float w, const float h) : ModalDialog(w, h) { @@ -46,7 +46,7 @@ PlayerInfoDialog::PlayerInfoDialog(PlayerProfile* player, const float w, const f showRegularDialog(); } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- PlayerInfoDialog::~PlayerInfoDialog() { @@ -56,7 +56,7 @@ PlayerInfoDialog::~PlayerInfoDialog() } } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- void PlayerInfoDialog::showRegularDialog() { clearWindow(); @@ -139,7 +139,7 @@ void PlayerInfoDialog::showRegularDialog() textCtrl->setFocusForPlayer( PLAYER_ID_GAME_MASTER ); } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- void PlayerInfoDialog::showConfirmDialog() { @@ -162,8 +162,9 @@ void PlayerInfoDialog::showConfirmDialog() core::rect< s32 > area_left(5, 0, m_area.getWidth()-5, m_area.getHeight()/2); - // When there is no need to tab through / click on images/labels, we can add directly - // irrlicht labels (more complicated uses require the use of our widget set) + // When there is no need to tab through / click on images/labels, + // we can add irrlicht labels directly + // (more complicated uses require the use of our widget set) IGUIStaticText* a = GUIEngine::getGUIEnv()->addStaticText( message.c_str(), area_left, false /* border */, true /* word wrap */, m_irrlicht_window); @@ -212,13 +213,13 @@ void PlayerInfoDialog::showConfirmDialog() } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- void PlayerInfoDialog::onEnterPressedInternal() { } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& eventSource) { @@ -291,5 +292,5 @@ GUIEngine::EventPropagation PlayerInfoDialog::processEvent(const std::string& ev return GUIEngine::EVENT_LET; } -// ------------------------------------------------------------------------------------------------------ +// ----------------------------------------------------------------------------- diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index cb9c02d13..9730f444c 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -67,7 +67,7 @@ void OptionsScreenPlayers::init() RibbonWidget* tabBar = this->getWidget("options_choice"); if (tabBar != NULL) tabBar->select( "tab_players", PLAYER_ID_GAME_MASTER ); - + tabBar->getRibbonChildren()[0].setTooltip( _("Graphics") ); tabBar->getRibbonChildren()[1].setTooltip( _("Audio") ); tabBar->getRibbonChildren()[2].setTooltip( _("User Interface") ); @@ -131,7 +131,7 @@ void OptionsScreenPlayers::onNewPlayerWithName(const stringw& newName) void OptionsScreenPlayers::deletePlayer(PlayerProfile* player) { UserConfigParams::m_all_players.erase(player); - + refreshPlayerList(); } // deletePlayer @@ -153,7 +153,7 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name if (name == "options_choice") { std::string selection = ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER).c_str(); - + if (selection == "tab_audio") StateManager::get()->replaceTopMostScreen(OptionsScreenAudio::getInstance()); else if (selection == "tab_video") StateManager::get()->replaceTopMostScreen(OptionsScreenVideo::getInstance()); else if (selection == "tab_players") StateManager::get()->replaceTopMostScreen(OptionsScreenPlayers::getInstance()); @@ -173,7 +173,7 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name // Find which player in the list was clicked ListWidget* players = this->getWidget("players"); assert(players != NULL); - + core::stringw selectedPlayer = players->getSelectionLabel(); const int playerAmount = UserConfigParams::m_all_players.size(); for (int n=0; npushScreen(StoryModeLobbyScreen::getInstance()); } - + } // eventCallback // ----------------------------------------------------------------------------- @@ -203,7 +203,7 @@ void OptionsScreenPlayers::selectPlayer(const irr::core::stringw& name) ListWidget* players = this->getWidget("players"); assert(players != NULL); players->selectItemWithLabel(name); - + players->setFocusForPlayer(PLAYER_ID_GAME_MASTER); } diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 847470f5e..0f1426e28 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -147,7 +147,6 @@ void StoryModeLobbyScreen::unloaded() void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& newName) { - bool slot_found = false; PtrVector& players = UserConfigParams::m_all_players;