From d0f93d3b9844d4e864ad079bbd01f0d7d7c70399 Mon Sep 17 00:00:00 2001 From: Dimitrije Jankov Date: Fri, 28 Feb 2014 02:36:53 +0100 Subject: [PATCH] Fixed the skiping of the lobby screen :) --- src/config/player_manager.cpp | 42 ++++++++++++------- src/config/player_manager.hpp | 7 +++- src/states_screens/options_screen_players.cpp | 1 + src/states_screens/story_mode_lobby.cpp | 11 ++--- 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 005383928..79cccd2fd 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -86,26 +86,17 @@ void PlayerManager::load() const XMLNode *player_xml = players->getNode(i); PlayerProfile *player = new PlayerProfile(player_xml); m_all_players.push_back(player); - if(player->isDefault()) + if(player->isDefault()){ m_current_player = player; + } } m_all_players.insertionSort(/*start*/0, /*desc*/true); - if(!m_current_player) + if(!m_current_player) // if there is no default player assigned set the current player to guest { - PlayerProfile *player; - for_in(player, m_all_players) - { - if(!player->isGuestAccount()) - { - m_current_player = player; - player->setDefault(true); - break; - } - } + m_current_player = getGuestPlayer(); + m_current_player->setDefault(true); } - if(!m_current_player) - Log::fatal("PlayerManager", "Can't find a default player."); delete players; } // load @@ -201,6 +192,24 @@ const PlayerProfile *PlayerManager::getPlayerById(unsigned int id) return NULL; } // getPlayerById + +PlayerProfile* PlayerManager::getGuestPlayer(){ + + PlayerProfile *player; + for_in(player, m_all_players) + { + if(player->isGuestAccount()) + { + return player; + } + } + + player = new PlayerProfile(_LTR("Guest"), /*guest*/true); + m_all_players.push_back( player ); + + return player; +} + // ---------------------------------------------------------------------------- PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name) { @@ -213,14 +222,15 @@ PlayerProfile *PlayerManager::getPlayer(const irr::core::stringw &name) return NULL; } // getPlayer // ---------------------------------------------------------------------------- -void PlayerManager::setCurrentPlayer(PlayerProfile *player) +void PlayerManager::setCurrentPlayer(PlayerProfile *player, bool remember_me) { // Reset current default player if(m_current_player) m_current_player->setDefault(false); m_current_player = player; - m_current_player->setDefault(true); + m_current_player->setDefault(remember_me); m_current_player->computeActive(); + m_remember_me = false; } // setCurrentPlayer // ---------------------------------------------------------------------------- diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index a9a13f45a..1323af4bf 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -47,6 +47,7 @@ private: /** A pointer to the current player. */ PlayerProfile* m_current_player; + bool m_remember_me; void load(); PlayerManager(); @@ -76,12 +77,16 @@ public: void addDefaultPlayer(); void addNewPlayer(const irr::core::stringw& name); void deletePlayer(PlayerProfile *player); - void setCurrentPlayer(PlayerProfile *player); + void setCurrentPlayer(PlayerProfile *player, bool remember_me); + void rememberCurrentPlayer(bool value) { m_remember_me = value; } const PlayerProfile *getPlayerById(unsigned int id); // ------------------------------------------------------------------------ /** Returns the current player. */ PlayerProfile* getCurrentPlayer() { return m_current_player; } // ------------------------------------------------------------------------ + /** Returns the guest player. */ + PlayerProfile* getGuestPlayer(); + // ------------------------------------------------------------------------ PlayerProfile *getPlayer(const irr::core::stringw &name); // ------------------------------------------------------------------------ /** Returns the number of players in the config file.*/ diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 1dd71f7c1..562605bf3 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -185,6 +185,7 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name else if (name == "playername") { race_manager->clearKartLastPositionOnOverworld(); + PlayerManager::get()->setCurrentPlayer(PlayerManager::get()->getGuestPlayer(),false); StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance()); } diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 27e30ee6d..fb07a97a8 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -56,7 +56,7 @@ void StoryModeLobbyScreen::init() list->clear(); PlayerProfile *player = PlayerManager::get()->getCurrentPlayer(); - if(player) + if(!player->isGuestAccount()) { StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); return; @@ -107,14 +107,9 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, ->getPlayer(list->getSelectionLabel()); if(player) { - PlayerManager::get()->setCurrentPlayer(player); player->computeActive(); CheckBoxWidget* cb = getWidget("rememberme"); - if (cb->getState()) - { - PlayerManager::get()->setCurrentPlayer(PlayerManager::get() - ->getPlayer(list->getSelectionLabel())); - } + PlayerManager::get()->setCurrentPlayer(player,cb->getState()); } else { @@ -140,7 +135,7 @@ void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name) PlayerProfile *player = PlayerManager::get()->getPlayer(new_name); if(player) { - PlayerManager::get()->setCurrentPlayer(player); + PlayerManager::get()->setCurrentPlayer(player,false); player->computeActive(); } else