From 2f17264f398e09187ebd5872af95393f90a9b80e Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 28 Apr 2014 07:54:09 +1000 Subject: [PATCH] Very eary first version of a new login screen. --- data/gui/story_mode_lobby.stkgui | 34 +++--- src/config/player_manager.cpp | 19 +-- src/states_screens/story_mode_lobby.cpp | 148 ++++++++++++++++++------ 3 files changed, 142 insertions(+), 59 deletions(-) diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui index 4d5ae117c..65b0d5e93 100644 --- a/data/gui/story_mode_lobby.stkgui +++ b/data/gui/story_mode_lobby.stkgui @@ -2,25 +2,29 @@
-
+ +
- - - + + + +
+ + - -
- -
- - - -
diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 85e4fbdb0..9cd0852ad 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -38,12 +38,6 @@ void PlayerManager::create() { assert(!m_player_manager); m_player_manager = new PlayerManager(); - if(m_player_manager->getNumPlayers() == 0) - { - m_player_manager->addDefaultPlayer(); - m_player_manager->save(); - } - } // create // ---------------------------------------------------------------------------- @@ -211,9 +205,11 @@ void PlayerManager::load() m_all_online_ids.clear(); m_current_player = NULL; - for(unsigned int i=0; igetNumNodes(); i++) + std::vector player_list; + m_player_data->getNodes("player", player_list); + for(unsigned int i=0; igetNode(i); + const XMLNode *player_xml = player_list[i]; PlayerProfile *player = new Online::OnlinePlayerProfile(player_xml); m_all_players.push_back(player); if(player->isDefault()) @@ -231,6 +227,11 @@ void PlayerManager::load() */ void PlayerManager::initRemainingData() { + // Filter the player nodes out (there is one additional node 'online-ids' + // which makes this necessary), otherwise the index of m_all_players + // is not identical with the index in the xml file. + std::vector player_nodes; + m_player_data->getNodes("player", player_nodes); for (unsigned int i = 0; igetNode(i)); + m_all_players[i].loadRemainingData(player_nodes[i]); } delete m_player_data; diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 73c050903..05f770556 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -19,8 +19,8 @@ #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" -#include "config/user_config.hpp" #include "guiengine/widgets/check_box_widget.hpp" +#include "guiengine/widgets/dynamic_ribbon_widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" #include "states_screens/main_menu_screen.hpp" @@ -48,33 +48,67 @@ void StoryModeLobbyScreen::loadedFromFile() void StoryModeLobbyScreen::init() { Screen::init(); + PlayerProfile *player = PlayerManager::getCurrentPlayer(); + if (player) + { + //StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + //return; + } - CheckBoxWidget* cb = getWidget("rememberme"); - cb->setState(false); + //CheckBoxWidget* cb = getWidget("rememberme"); + //cb->setState(false); ListWidget* list = getWidget("gameslots"); - list->clear(); - PlayerProfile *player = PlayerManager::getCurrentPlayer(); - if(player) + //PtrVector& players = UserConfigParams::m_all_players; +#if 0 + + if (UserConfigParams::m_default_player.toString().size() > 0) { - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - return; - } + for (unsigned int n=0; nsetCurrentSlot(players[n].getUniqueID()); + StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + return; + } + } + }. +#endif + + DynamicRibbonWidget* local = getWidget("local"); + assert( local != NULL ); for (unsigned int n=0; ngetNumPlayers(); n++) { const PlayerProfile *player = PlayerManager::get()->getPlayer(n); if (player->isGuestAccount()) continue; - - // FIXME: we're using a trunacted ascii version of the player name as - // identifier, let's hope this causes no issues... - list->addItem(core::stringc(player->getName().c_str()).c_str(), - player->getName() ); + std::string s = StringUtils::toString(n); + local->addItem(player->getName(), s, "", 0, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); } - list->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - list->setSelectionID(0); + local->addItem("Create new user", "local_new", + "karts/sara/icon-sara.png", 0, + IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + local->updateItemDisplay(); + + DynamicRibbonWidget* online = this->getWidget("online"); + assert( online != NULL ); + const std::vector &online_ids = + PlayerManager::get()->getAllOnlineIds(); + for (unsigned int i = 0; i < online_ids.size(); i++) + { + std::string s = StringUtils::toString(i); + online->addItem(online_ids[i], s, "karts/nolok/nolokicon.png", 0, + IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + + } + online->addItem("Create new online user", "online_new", + "karts/sara/icon-sara.png", 0, + IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + online->updateItemDisplay(); + } // init @@ -91,6 +125,35 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { + if (name == "local") + { + // FIXME nothing to do + } + else if (name == "options") + { + const std::string &button = + getWidget("options")->getSelectionIDString(player_id); + if (button == "ok" || button == "ok_and_save") + { + DynamicRibbonWidget *local = getWidget("local"); + const std::string &name = local->getSelectionIDString(player_id); + if (name == "local_new") + { + // create new local player + return; + } + unsigned int id; + StringUtils::fromString(name, id); + PlayerProfile *profile = PlayerManager::get()->getPlayer(id); + PlayerManager::get()->setCurrentPlayer(profile, button=="ok_and_save"); + StateManager::get()->pushScreen(MainMenuScreen::getInstance()); + return; + } // button==ok || ok_and_save + } // options + + return; + + if (name == "back") { StateManager::get()->escapePressed(); @@ -103,27 +166,35 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { ListWidget* list = getWidget("gameslots"); - PlayerProfile *player = PlayerManager::get() - ->getPlayer(list->getSelectionLabel()); - if(player) + bool slot_found = false; + + for (unsigned int n=0; ngetNumPlayers(); n++) { - player->computeActive(); - CheckBoxWidget* cb = getWidget("rememberme"); - PlayerManager::get()->setCurrentPlayer(player,cb->getState()); + PlayerProfile *player = PlayerManager::get()->getPlayer(n); + if (list->getSelectionLabel() == player->getName()) + { + PlayerManager::get()->setCurrentPlayer(player, false); + slot_found = true; + break; + } } - else + + if (!slot_found) { Log::error("StoryModeLobby", "Cannot find player corresponding to slot '%s'.", core::stringc(list->getSelectionLabel().c_str()).c_str()); } + else + { +// CheckBoxWidget* cb = getWidget("rememberme"); +// if (cb->getState()) + { +// UserConfigParams::m_default_player = list->getSelectionLabel(); + } + } StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - // Since only now the current player is defined, we have to request - // a login (if an online login was saved). If the current player was - // saved, this request will be started much earlier in the startup - // sequence from the RequestManager. - PlayerManager::resumeSavedSession(); } } // eventCallback @@ -135,19 +206,26 @@ void StoryModeLobbyScreen::unloaded() // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::onNewPlayerWithName(const stringw& new_name) +void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& newName) { - PlayerProfile *player = PlayerManager::get()->getPlayer(new_name); - if(player) + bool slot_found = false; + + for (unsigned int n=0; ngetNumPlayers(); n++) { - PlayerManager::get()->setCurrentPlayer(player,false); - player->computeActive(); + PlayerProfile *player = PlayerManager::get()->getPlayer(n); + if (player->getName() == newName) + { + PlayerManager::get()->setCurrentPlayer(player, false); + slot_found = true; + break; + } } - else + + if (!slot_found) { Log::error("StoryModeLobbyScreen", "Cannot find player corresponding to slot '%s'.", - core::stringc(new_name.c_str()).c_str()); + core::stringc(newName.c_str()).c_str()); } StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance());