From f84f49dfc8ae9b407ecb2794aef0cef26de531b7 Mon Sep 17 00:00:00 2001 From: pgabor Date: Sat, 15 Mar 2014 21:15:04 +0100 Subject: [PATCH 001/365] Adding a Wiimote with other one alredy placed - Bug: #1209 fixed --- src/input/wiimote_manager.cpp | 78 ++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/input/wiimote_manager.cpp b/src/input/wiimote_manager.cpp index 73cf2bbcd..01687ef7d 100644 --- a/src/input/wiimote_manager.cpp +++ b/src/input/wiimote_manager.cpp @@ -17,6 +17,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef ENABLE_WIIUSE +#define WCONST #include "input/wiimote_manager.hpp" @@ -61,24 +62,99 @@ WiimoteManager::~WiimoteManager() */ void WiimoteManager::launchDetection(int timeout) { + // It's only needed on systems with bluez, because wiiuse_find does not find alredy connected wiimotes +#ifdef WIIUSE_BLUEZ + //Cleans up the config and the disconnected wiimotes + int number_previous_wiimotes = 0; + wiimote_t** previous_wiimotes = (wiimote_t**) malloc(sizeof(struct wiimote_t*) * MAX_WIIMOTES); + memset(previous_wiimotes,0,sizeof(struct wiimote_t*) * MAX_WIIMOTES); + for (unsigned int i = 0; i < m_wiimotes.size(); i++) + { + if (WIIMOTE_IS_CONNECTED(m_all_wiimote_handles[i])) + { + previous_wiimotes[i]=m_all_wiimote_handles[i]; + m_all_wiimote_handles[i] = NULL; + number_previous_wiimotes++; + } + } + + //To prevent segmentation fault, have to delete NULLs + wiimote_t** deletable_wiimotes = (wiimote_t**) malloc(sizeof(struct wiimote_t*) * (m_wiimotes.size()-number_previous_wiimotes)); + memset(deletable_wiimotes,0,sizeof(struct wiimote_t*) * (m_wiimotes.size()-number_previous_wiimotes)); + int number_deletables = 0; + for (unsigned int i = 0; i < m_wiimotes.size(); i++) + { + if (m_all_wiimote_handles[i] != NULL) + { + deletable_wiimotes[number_deletables++] = m_all_wiimote_handles[i]; + } + } + m_all_wiimote_handles = wiiuse_init(MAX_WIIMOTES); + wiiuse_cleanup(deletable_wiimotes, number_deletables); + +#endif + // Stop WiiUse, remove wiimotes, gamepads, gamepad configs. cleanup(); - m_all_wiimote_handles = wiiuse_init(MAX_WIIMOTES); + m_all_wiimote_handles = wiiuse_init(MAX_WIIMOTES); // Detect wiimotes int nb_found_wiimotes = wiiuse_find(m_all_wiimote_handles, MAX_WIIMOTES, timeout); +#ifndef WIIUSE_BLUEZ // Couldn't find any wiimote? if(nb_found_wiimotes == 0) return; +#endif + +#ifdef WIIUSE_BLUEZ + // Couldn't find any wiimote? + if(nb_found_wiimotes + number_previous_wiimotes == 0) + return; +#endif // Try to connect to all found wiimotes int nb_wiimotes = wiiuse_connect(m_all_wiimote_handles, nb_found_wiimotes); +#ifndef WIIUSE_BLUEZ // Couldn't connect to any wiimote? if(nb_wiimotes == 0) return; +#endif + +#ifdef WIIUSE_BLUEZ + // Couldn't connect to any wiimote? + if(nb_wiimotes + number_previous_wiimotes == 0) + return; + + //Merges previous and new wiimote's list + int number_merged_wiimotes = 0; + for (int i = 0; i < number_previous_wiimotes && i + nb_wiimotes < MAX_WIIMOTES; i++) + { + m_all_wiimote_handles[i+nb_wiimotes] = previous_wiimotes[i]; + previous_wiimotes[i] = NULL; + m_all_wiimote_handles[i]->unid = nb_wiimotes+i+1; + number_merged_wiimotes++; + } + nb_wiimotes += number_merged_wiimotes; + + //To prevent segmentation fault, have to delete NULLs + number_deletables = 0; + number_deletables = 0; + deletable_wiimotes = (wiimote_t**) malloc(sizeof(struct wiimote_t*) * (number_previous_wiimotes-number_merged_wiimotes)); + memset(deletable_wiimotes,0,sizeof(struct wiimote_t*) * (number_previous_wiimotes-number_merged_wiimotes)); + for (int i = 0; i < number_previous_wiimotes; i++) + { + if (previous_wiimotes[i] != NULL) + { + deletable_wiimotes[number_deletables++] = previous_wiimotes[i]; + } + } + // Cleans up wiimotes which ones didn't fit in limit + wiiuse_cleanup(deletable_wiimotes, number_deletables); + +#endif // --------------------------------------------------- // Create or find a GamepadConfig for all wiimotes From d7684668db8a12f916dee5127523f210ec76d9de Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 24 Apr 2014 08:16:19 +1000 Subject: [PATCH 002/365] Fixed comments. --- data/gui/online/login.stkgui | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/data/gui/online/login.stkgui b/data/gui/online/login.stkgui index 547f1de34..04bbff810 100644 --- a/data/gui/online/login.stkgui +++ b/data/gui/online/login.stkgui @@ -17,24 +17,24 @@
+ I18N="In the create login screen" text="Sign in"/>
-
-
-
@@ -43,11 +43,11 @@ + I18N="Create login screen" text="Sign In" label_location="bottom"/> + I18N="Create login screen" text="Recovery" label_location="bottom"/> + I18N="Create login screen" text="Close" label_location="bottom"/> From ea2b797bb32e389e42d8acf56ba56c8ebdcd6d2f Mon Sep 17 00:00:00 2001 From: hiker Date: Thu, 24 Apr 2014 08:17:44 +1000 Subject: [PATCH 003/365] Keep track of online ids used in the player.xml file. --- src/config/player_manager.cpp | 46 ++++++++++++++++++++++++++ src/config/player_manager.hpp | 11 ++++++ src/states_screens/login_screen.cpp | 1 + src/states_screens/register_screen.cpp | 2 ++ 4 files changed, 60 insertions(+) diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 7ebd07a00..85e4fbdb0 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -197,6 +197,19 @@ void PlayerManager::load() return; } + const XMLNode *online = m_player_data->getNode("online-ids"); + if (online) + { + for (unsigned int i = 0; i < online->getNumNodes(); i++) + { + core::stringw s; + online->getNode(i)->get("name", &s); + if (s.size()>0) m_all_online_ids.push_back(s); + } // for igetNumNodes() + } + else + m_all_online_ids.clear(); + m_current_player = NULL; for(unsigned int i=0; igetNumNodes(); i++) { @@ -249,6 +262,14 @@ void PlayerManager::save() players_file << L"\n"; players_file << L"\n"; + players_file << L" \n"; + for (unsigned int i = 0; i < m_all_online_ids.size(); i++) + { + players_file << L" \n"; + } + players_file << L" \n"; + PlayerProfile *player; for_in(player, m_all_players) { @@ -420,3 +441,28 @@ void PlayerManager::setCurrentPlayer(PlayerProfile *player, bool remember_me) } // setCurrentPlayer // ---------------------------------------------------------------------------- +/** Adds an online id to the list of all online ids, if that id is not already + * in the list. An added id is always moved to the front of the list, so that + * the list of online ids shown to the user is sorted by recently-used ids. + * \param online_id An online id. + */ +void PlayerManager::addOnlineId(const core::stringw &online_id) +{ + std::vector::iterator i = std::find(m_all_online_ids.begin(), + m_all_online_ids.end(), + online_id); + if (i == m_all_online_ids.end()) + { + m_all_online_ids.insert(m_all_online_ids.begin(), online_id); + } + else + { + // If the online_id is not already at the front of the list, + // move it to the front. + if (i != m_all_online_ids.begin()) + { + m_all_online_ids.erase(i); + m_all_online_ids.insert(m_all_online_ids.begin(), online_id); + } + } +} // addOnlineId diff --git a/src/config/player_manager.hpp b/src/config/player_manager.hpp index 7d3c8dfde..5154c2b8c 100644 --- a/src/config/player_manager.hpp +++ b/src/config/player_manager.hpp @@ -58,6 +58,9 @@ private: PtrVector m_all_players; + /** A list of all online ids created locally. */ + std::vector m_all_online_ids; + /** A pointer to the current player. */ PlayerProfile* m_current_player; @@ -113,6 +116,7 @@ public: const irr::core::stringw &password, bool save_session, bool request_now = true); + void addOnlineId(const core::stringw &online_id); // ------------------------------------------------------------------------ /** Returns the current player. */ @@ -155,6 +159,13 @@ public: a->increase(key, increase); } // increaseAchievement // ------------------------------------------------------------------------ + /** Returns the list of all online ids. */ + const std::vector& getAllOnlineIds() const + { + return m_all_online_ids; + } // getAllOnlineIds + // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ }; // PlayerManager diff --git a/src/states_screens/login_screen.cpp b/src/states_screens/login_screen.cpp index 6f6b69e4a..569eac0bf 100644 --- a/src/states_screens/login_screen.cpp +++ b/src/states_screens/login_screen.cpp @@ -99,6 +99,7 @@ void LoginScreen::login() info_widget->setDefaultColor(); bool remember = getWidget("remember")->getState(); PlayerManager::requestSignIn(username, password, remember); + PlayerManager::get()->addOnlineId(username); } } // login diff --git a/src/states_screens/register_screen.cpp b/src/states_screens/register_screen.cpp index d9a3ee45a..c7458fe33 100644 --- a/src/states_screens/register_screen.cpp +++ b/src/states_screens/register_screen.cpp @@ -17,6 +17,7 @@ #include "states_screens/register_screen.hpp" +#include "config/player_manager.hpp" #include "audio/sfx_manager.hpp" #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" @@ -103,6 +104,7 @@ void RegisterScreen::doRegister() } else { + PlayerManager::get()->addOnlineId(username); m_info_widget->setDefaultColor(); new RegistrationDialog(); return; From b3291caea2f0f6837ffcedbd76784c856efdf6aa Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 28 Apr 2014 07:51:24 +1000 Subject: [PATCH 004/365] Moved 'startup now' code in separate function to make main more readable. --- src/main.cpp | 69 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9b286c32f..bae754040 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -383,6 +383,43 @@ void handleXmasMode() if(xmas) kart_properties_manager->setHatMeshName("christmas_hat.b3d"); } // handleXmasMode +// ============================================================================ +/** This function sets up all data structure for an immediate race start. + * It is used when the -N or -R command line options are used. + */ +void setupRaceStart() +{ + // Skip the start screen. This esp. means that no login screen is + // displayed (if necessary), so we have to make sure there is + // a current player + PlayerManager::get()->enforceCurrentPlayer(); + + InputDevice *device; + + // Use keyboard 0 by default in --no-start-screen + device = input_manager->getDeviceList()->getKeyboard(0); + + // Create player and associate player with keyboard + StateManager::get()->createActivePlayer( + PlayerManager::get()->getPlayer(0), device, NULL); + + if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) + { + Log::warn("main", "Kart '%s' is unknown so will use the " + "default kart.", + UserConfigParams::m_default_kart.c_str()); + race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart.getDefaultValue()); + } + else + { + // Set up race manager appropriately + race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); + } + + // ASSIGN should make sure that only input from assigned devices + // is read. + input_manager->getDeviceList()->setAssignMode(ASSIGN); +} // setupRaceMode // ---------------------------------------------------------------------------- /** Prints help for command line options to stdout. @@ -1262,37 +1299,7 @@ int main(int argc, char *argv[] ) } else { - // Skip the start screen. This esp. means that no login screen is - // displayed (if necessary), so we have to make sure there is - // a current player - PlayerManager::get()->enforceCurrentPlayer(); - - InputDevice *device; - - // Use keyboard 0 by default in --no-start-screen - device = input_manager->getDeviceList()->getKeyboard(0); - - // Create player and associate player with keyboard - StateManager::get()->createActivePlayer( - PlayerManager::get()->getPlayer(0), device, NULL); - - if (kart_properties_manager->getKart(UserConfigParams::m_default_kart) == NULL) - { - Log::warn("main", "Kart '%s' is unknown so will use the " - "default kart.", - UserConfigParams::m_default_kart.c_str()); - race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart.getDefaultValue()); - } - else - { - // Set up race manager appropriately - race_manager->setLocalKartInfo(0, UserConfigParams::m_default_kart); - } - - // ASSIGN should make sure that only input from assigned devices - // is read. - input_manager->getDeviceList()->setAssignMode(ASSIGN); - + setupRaceStart(); // Go straight to the race StateManager::get()->enterGameState(); } From 2f17264f398e09187ebd5872af95393f90a9b80e Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 28 Apr 2014 07:54:09 +1000 Subject: [PATCH 005/365] 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()); From 812da3e0c0f9400b9670bcabca70a4791a608c64 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 29 Apr 2014 09:02:44 +1000 Subject: [PATCH 006/365] Some work on new login screen, though wip atm. --- data/gui/story_mode_lobby.stkgui | 61 ++++++++++------- data/gui/story_mode_new.stkgui | 36 ---------- src/config/player_manager.cpp | 3 +- src/config/player_profile.cpp | 23 ++++--- src/config/player_profile.hpp | 15 +++++ src/online/online_player_profile.cpp | 1 + src/states_screens/story_mode_lobby.cpp | 89 +++++++++++++------------ src/states_screens/story_mode_lobby.hpp | 23 ++++++- 8 files changed, 134 insertions(+), 117 deletions(-) delete mode 100644 data/gui/story_mode_new.stkgui diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui index 65b0d5e93..b84f035a0 100644 --- a/data/gui/story_mode_lobby.stkgui +++ b/data/gui/story_mode_lobby.stkgui @@ -1,32 +1,47 @@ -
+
- -
- + +
+ - + + +
+
+
+
+
+ -
- - - - - - - - - - +
+
+
- -
+ + + + + + + + + +
diff --git a/data/gui/story_mode_new.stkgui b/data/gui/story_mode_new.stkgui deleted file mode 100644 index f910288ba..000000000 --- a/data/gui/story_mode_new.stkgui +++ /dev/null @@ -1,36 +0,0 @@ - - -
- -
- - - -
-
- - - - - - - - - - - -
- -
diff --git a/src/config/player_manager.cpp b/src/config/player_manager.cpp index 9cd0852ad..2d5a6b5ec 100644 --- a/src/config/player_manager.cpp +++ b/src/config/player_manager.cpp @@ -114,7 +114,8 @@ void PlayerManager::resumeSavedSession() */ void PlayerManager::onSTKQuit() { - getCurrentPlayer()->onSTKQuit(); + if (getCurrentPlayer()) + getCurrentPlayer()->onSTKQuit(); } // onSTKQuit // ---------------------------------------------------------------------------- diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index 121cd68a4..0e761aed5 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -48,6 +48,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) m_saved_session = false; m_saved_token = ""; m_saved_user_id = 0; + m_last_online_name = ""; m_achievements_status = NULL; m_story_mode_status = NULL; } // PlayerProfile @@ -71,17 +72,19 @@ PlayerProfile::PlayerProfile(const XMLNode* node) m_saved_session = false; m_saved_token = ""; m_saved_user_id = 0; + m_last_online_name = ""; m_story_mode_status = NULL; m_achievements_status = NULL; - node->get("name", &m_local_name ); - node->get("guest", &m_is_guest_account); - node->get("use-frequency", &m_use_frequency ); - node->get("unique-id", &m_unique_id ); - node->get("is-default", &m_is_default ); - node->get("saved-session", &m_saved_session ); - node->get("saved-user", &m_saved_user_id ); - node->get("saved-token", &m_saved_token ); + node->get("name", &m_local_name ); + node->get("guest", &m_is_guest_account); + node->get("use-frequency", &m_use_frequency ); + node->get("unique-id", &m_unique_id ); + node->get("is-default", &m_is_default ); + node->get("saved-session", &m_saved_session ); + node->get("saved-user", &m_saved_user_id ); + node->get("saved-token", &m_saved_token ); + node->get("last-online-name", &m_last_online_name); #ifdef DEBUG m_magic_number = 0xABCD1234; @@ -138,8 +141,8 @@ void PlayerProfile::save(UTFWriter &out) << L"\" saved-session=\"" << m_saved_session << L"\"\n"; out << L" saved-user=\"" << m_saved_user_id - << L"\" saved-token=\"" << m_saved_token << L"\">\n"; - + << L"\" saved-token=\"" << m_saved_token << L"\"\n"; + out << L" last-online-name=\"" << m_last_online_name<< L"\">\n"; { if(m_story_mode_status) m_story_mode_status->save(out); diff --git a/src/config/player_profile.hpp b/src/config/player_profile.hpp index 5b6132305..b5d2e0576 100644 --- a/src/config/player_profile.hpp +++ b/src/config/player_profile.hpp @@ -95,6 +95,9 @@ private: /** The token of the saved session. */ std::string m_saved_token; + /** The online user name used last (empty if not used online). */ + core::stringw m_last_online_name; + /** The complete challenge state. */ StoryModeStatus *m_story_mode_status; @@ -161,6 +164,18 @@ public: return m_is_guest_account; } // isGuestAccount + // ------------------------------------------------------------------------ + /** Returns the last used online name. */ + const core::stringw& getLastOnlineName() const + { + return m_last_online_name; + } // getLastOnlineName + // ------------------------------------------------------------------------ + /** Sets the last used online name. */ + void setLastOnlineName(const core::stringw &name) + { + m_last_online_name = name; + } // setLastOnlineName // ------------------------------------------------------------------------ /** Returns the unique id of this player. */ unsigned int getUniqueID() const { return m_unique_id; } diff --git a/src/online/online_player_profile.cpp b/src/online/online_player_profile.cpp index 546b4dac2..582be02cc 100644 --- a/src/online/online_player_profile.cpp +++ b/src/online/online_player_profile.cpp @@ -170,6 +170,7 @@ namespace Online int username_fetched = input->get("username", &username); uint32_t userid(0); int userid_fetched = input->get("userid", &userid); + PlayerManager::getCurrentPlayer()->setLastOnlineName(username); m_profile = new OnlineProfile(userid, username, true); assert(token_fetched && username_fetched && userid_fetched); m_online_state = OS_SIGNED_IN; diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 05f770556..2a1e253f0 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -21,8 +21,10 @@ #include "config/player_manager.hpp" #include "guiengine/widgets/check_box_widget.hpp" #include "guiengine/widgets/dynamic_ribbon_widget.hpp" +#include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" +#include "states_screens/login_screen.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" @@ -41,12 +43,21 @@ StoryModeLobbyScreen::StoryModeLobbyScreen() : Screen("story_mode_lobby.stkgui") void StoryModeLobbyScreen::loadedFromFile() { + } // loadedFromFile // ---------------------------------------------------------------------------- void StoryModeLobbyScreen::init() { + m_online_cb = getWidget("online"); + assert(m_online_cb); + m_username_tb = getWidget("username"); + assert(m_username_tb); + m_password_tb = getWidget("password"); + assert(m_password_tb); + //m_password_tb->setPasswordBox(true, L'*'); + Screen::init(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player) @@ -55,28 +66,6 @@ void StoryModeLobbyScreen::init() //return; } - //CheckBoxWidget* cb = getWidget("rememberme"); - //cb->setState(false); - - ListWidget* list = getWidget("gameslots"); - - //PtrVector& players = UserConfigParams::m_all_players; -#if 0 - - if (UserConfigParams::m_default_player.toString().size() > 0) - { - for (unsigned int n=0; nsetCurrentSlot(players[n].getUniqueID()); - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - return; - } - } - }. -#endif - DynamicRibbonWidget* local = getWidget("local"); assert( local != NULL ); @@ -85,30 +74,12 @@ void StoryModeLobbyScreen::init() const PlayerProfile *player = PlayerManager::get()->getPlayer(n); if (player->isGuestAccount()) continue; std::string s = StringUtils::toString(n); - local->addItem(player->getName(), s, "", 0, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + local->addItem(player->getName(), s, "", 0, + IconButtonWidget::ICON_PATH_TYPE_RELATIVE); } - 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(); + update(); } // init @@ -120,14 +91,43 @@ void StoryModeLobbyScreen::tearDown() } // tearDown // ---------------------------------------------------------------------------- +void StoryModeLobbyScreen::update() +{ + bool online = m_online_cb->getState(); + getWidget("label_username")->setVisible(online); + m_username_tb->setVisible(online); + getWidget("label_password")->setVisible(online); + m_password_tb->setVisible(online); +} // update +// ---------------------------------------------------------------------------- void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { if (name == "local") { - // FIXME nothing to do + // Clicked on a name --> Find the corresponding online data + // and display them + const std::string &s_index = getWidget("local") + ->getSelectionIDString(player_id); + if (s_index == "") return; // can happen if the list is empty + + unsigned int id; + StringUtils::fromString(s_index, id); + PlayerProfile *profile = PlayerManager::get()->getPlayer(id); + assert(profile); + getWidget("username")->setText(profile + ->getLastOnlineName()); + // In case of a saved session, remove the password field, + // since it is not necessary to display it. + getWidget("password")->setVisible(profile + ->hasSavedSession()); + + } + else if (name == "online") + { + update(); // This will make the fields (in)visible } else if (name == "options") { @@ -151,6 +151,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, } // button==ok || ok_and_save } // options + update(); return; diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp index a38b83c24..dcd647925 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/story_mode_lobby.hpp @@ -24,18 +24,35 @@ #include "guiengine/screen.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" -namespace GUIEngine { class Widget; } +namespace GUIEngine +{ + class CheckBoxWidget; + class TextBoxWidget; + class Widget; +} /** * \brief Audio options screen * \ingroup states_screens */ -class StoryModeLobbyScreen : public GUIEngine::Screen, public EnterPlayerNameDialog::INewPlayerListener, - public GUIEngine::ScreenSingleton +class StoryModeLobbyScreen : public GUIEngine::Screen, + public EnterPlayerNameDialog::INewPlayerListener, + public GUIEngine::ScreenSingleton { StoryModeLobbyScreen(); +private: + /** Online check box. */ + GUIEngine::CheckBoxWidget *m_online_cb; + + /** User name entry field. */ + GUIEngine::TextBoxWidget *m_username_tb; + + /** Password widget. */ + GUIEngine::TextBoxWidget *m_password_tb; + + void update(); public: friend class GUIEngine::ScreenSingleton; From 6f5c523e86c4e7f05ebd1ff6eacc67a6c6bdc79c Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 29 Apr 2014 09:46:00 +1000 Subject: [PATCH 007/365] Fixed display of players, thanks to auria. --- src/states_screens/story_mode_lobby.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 2a1e253f0..fe46ce4bf 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -74,10 +74,10 @@ void StoryModeLobbyScreen::init() const PlayerProfile *player = PlayerManager::get()->getPlayer(n); if (player->isGuestAccount()) continue; std::string s = StringUtils::toString(n); - local->addItem(player->getName(), s, "", 0, + local->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); } - + local->updateItemDisplay(); update(); From ecef685b32f6aff408b7e67e5d5f164df84eca16 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 07:54:49 +1000 Subject: [PATCH 008/365] Adding new players now works. --- data/gui/story_mode_lobby.stkgui | 8 +- src/config/player_manager.cpp | 5 +- src/config/player_profile.cpp | 9 +- src/states_screens/story_mode_lobby.cpp | 132 ++++++++++++++---------- src/states_screens/story_mode_lobby.hpp | 6 +- 5 files changed, 97 insertions(+), 63 deletions(-) diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui index b84f035a0..5d8c4bf69 100644 --- a/data/gui/story_mode_lobby.stkgui +++ b/data/gui/story_mode_lobby.stkgui @@ -6,14 +6,14 @@
-
- +
+
player_nodes; - m_player_data->getNodes("player", player_nodes); + if(m_player_data) + m_player_data->getNodes("player", player_nodes); for (unsigned int i = 0; iisGuestAccount()) { Log::info("PlayerManager", "Enfocring current player '%s'.", - player->getName().c_str()); + player->getName().c_str()); m_current_player = player; return; } diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index 0e761aed5..9cebfedb1 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -49,8 +49,13 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) m_saved_token = ""; m_saved_user_id = 0; m_last_online_name = ""; - m_achievements_status = NULL; - m_story_mode_status = NULL; + if (unlock_manager && AchievementsManager::get()) + initRemainingData(); + else + { + m_achievements_status = NULL; + m_story_mode_status = NULL; + } } // PlayerProfile //------------------------------------------------------------------------------ diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index fe46ce4bf..a3451a457 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -56,7 +56,9 @@ void StoryModeLobbyScreen::init() assert(m_username_tb); m_password_tb = getWidget("password"); assert(m_password_tb); - //m_password_tb->setPasswordBox(true, L'*'); + m_password_tb->setPasswordBox(true, L'*'); + m_players = getWidget("players"); + assert(m_players); Screen::init(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); @@ -66,20 +68,23 @@ void StoryModeLobbyScreen::init() //return; } - DynamicRibbonWidget* local = getWidget("local"); - assert( local != NULL ); - + m_players->clearItems(); for (unsigned int n=0; ngetNumPlayers(); n++) { const PlayerProfile *player = PlayerManager::get()->getPlayer(n); if (player->isGuestAccount()) continue; std::string s = StringUtils::toString(n); - local->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0, + m_players->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0, IconButtonWidget::ICON_PATH_TYPE_RELATIVE); } - local->updateItemDisplay(); - update(); + m_players->updateItemDisplay(); + + // Select the first user (the list of users is sorted by usage, so it + // is the most frequently used user). + if (PlayerManager::get()->getNumPlayers()>0) + selectUser(0); + } // init @@ -91,9 +96,47 @@ void StoryModeLobbyScreen::tearDown() } // tearDown // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::update() +/** Called when a user is selected. It updates the online checkbox and + * entrye fields. + */ +void StoryModeLobbyScreen::selectUser(int index) +{ + PlayerProfile *profile = PlayerManager::get()->getPlayer(index); + assert(profile); + getWidget("username")->setText(profile + ->getLastOnlineName()); + m_players->setSelection(StringUtils::toString(index), 0, /*focusIt*/true); + + // Last game was not online, so make the offline settings the default + // (i.e. unckeck online checkbox, and make entry fields invisible). + if (profile->getLastOnlineName() == "") + { + m_online_cb->setState(false); + makeEntryFieldsVisible(false); + return; + } + + // Now last use was with online --> Display the saved data + makeEntryFieldsVisible(true); + m_username_tb->setText(profile->getLastOnlineName()); + + // And make the password invisible if the session is saved (i.e + // the user does not need to enter a password). + if (profile->hasSavedSession()) + { + m_password_tb->setVisible(false); + getWidget("label_password")->setVisible(false); + } + +} // selectUser + +// ---------------------------------------------------------------------------- +/** Make the entry fields either visible or invisible. + * \param online Online state, which dicates if the entry fields are + * visible (true) or not. + */ +void StoryModeLobbyScreen::makeEntryFieldsVisible(bool online) { - bool online = m_online_cb->getState(); getWidget("label_username")->setVisible(online); m_username_tb->setVisible(online); getWidget("label_password")->setVisible(online); @@ -101,33 +144,27 @@ void StoryModeLobbyScreen::update() } // update // ---------------------------------------------------------------------------- +/** Called when the user selects anything on the screen. + */ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { - if (name == "local") + if (name == "players") { // Clicked on a name --> Find the corresponding online data // and display them - const std::string &s_index = getWidget("local") - ->getSelectionIDString(player_id); + const std::string &s_index = getWidget("players") + ->getSelectionIDString(player_id); if (s_index == "") return; // can happen if the list is empty unsigned int id; - StringUtils::fromString(s_index, id); - PlayerProfile *profile = PlayerManager::get()->getPlayer(id); - assert(profile); - getWidget("username")->setText(profile - ->getLastOnlineName()); - // In case of a saved session, remove the password field, - // since it is not necessary to display it. - getWidget("password")->setVisible(profile - ->hasSavedSession()); - + if (StringUtils::fromString(s_index, id)) + selectUser(id); } else if (name == "online") { - update(); // This will make the fields (in)visible + makeEntryFieldsVisible(m_online_cb->getState()); } else if (name == "options") { @@ -135,13 +172,14 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, 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") + if (m_online_cb->getState() && m_password_tb->getText() == "") { - // create new local player + getWidget("message")->setText("Enter password",true); return; } + + const std::string &name = m_players->getSelectionIDString(player_id); + unsigned int id; StringUtils::fromString(name, id); PlayerProfile *profile = PlayerManager::get()->getPlayer(id); @@ -149,9 +187,12 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, StateManager::get()->pushScreen(MainMenuScreen::getInstance()); return; } // button==ok || ok_and_save + else if (button == "new_user") + { + new EnterPlayerNameDialog(this, 0.5f, 0.4f); + } } // options - update(); return; @@ -159,10 +200,6 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { StateManager::get()->escapePressed(); } - else if (name == "creategame") - { - new EnterPlayerNameDialog(this, 0.5f, 0.4f); - } else if (name == "gameslots") { ListWidget* list = getWidget("gameslots"); @@ -206,30 +243,15 @@ void StoryModeLobbyScreen::unloaded() } // unloaded // ---------------------------------------------------------------------------- - -void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& newName) +/** This is a callback from the new user dialog. + */ +void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& new_name) { - bool slot_found = false; - - for (unsigned int n=0; ngetNumPlayers(); n++) - { - PlayerProfile *player = PlayerManager::get()->getPlayer(n); - if (player->getName() == newName) - { - PlayerManager::get()->setCurrentPlayer(player, false); - slot_found = true; - break; - } - } - - if (!slot_found) - { - Log::error("StoryModeLobbyScreen", - "Cannot find player corresponding to slot '%s'.", - core::stringc(newName.c_str()).c_str()); - } - - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + init(); + // Select the newly added player + selectUser(PlayerManager::get()->getNumPlayers() - 1); + + return; } // onNewPlayerWithName // ----------------------------------------------------------------------------- diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp index dcd647925..ce506f97f 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/story_mode_lobby.hpp @@ -52,7 +52,11 @@ private: /** Password widget. */ GUIEngine::TextBoxWidget *m_password_tb; - void update(); + /** The dynamic ribbon containing all players. */ + GUIEngine::DynamicRibbonWidget* m_players; + + void selectUser(int index); + void makeEntryFieldsVisible(bool online); public: friend class GUIEngine::ScreenSingleton; From 13024bf6ef67c37e97d04c90da5eab0e2bf284e5 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 08:42:43 +1000 Subject: [PATCH 009/365] On first time start the player is automatically asked to create a new player with a sensible default name. --- src/config/player_profile.cpp | 19 +++--- .../dialogs/enter_player_name_dialog.cpp | 62 +++++++++---------- src/states_screens/story_mode_lobby.cpp | 30 ++++++++- src/states_screens/story_mode_lobby.hpp | 1 + 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/config/player_profile.cpp b/src/config/player_profile.cpp index 9cebfedb1..bdf6224ac 100644 --- a/src/config/player_profile.cpp +++ b/src/config/player_profile.cpp @@ -49,13 +49,7 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) m_saved_token = ""; m_saved_user_id = 0; m_last_online_name = ""; - if (unlock_manager && AchievementsManager::get()) - initRemainingData(); - else - { - m_achievements_status = NULL; - m_story_mode_status = NULL; - } + initRemainingData(); } // PlayerProfile //------------------------------------------------------------------------------ @@ -65,11 +59,12 @@ PlayerProfile::PlayerProfile(const core::stringw& name, bool is_guest) * that the achievement and story mode data depends on other data to be * read first (challenges and achievement files), which in turn can only be * created later in the startup process (they depend on e.g. all tracks to - * be known). On the other hand, automatic login needs to happen asap - * (i.e. as soon as the network thread is started), which needs the main - * player data (i.e. the default player, and saved session data). So the - * constructor only reads this data, the rest of the player data is handled - * in loadRemainingData later in the initialisation process. + * be known). On the other hand, automatic login needs to happen asap (i.e. + * as soon as the network thread is started) to avoid the player having to + * wait for the login to finish , which needs the main player data (i.e. + * the default player, and saved session data). So the constructor only + * reads this data, the rest of the player data is handled in + * loadRemainingData later in the initialisation process. * \param node The XML node representing this player. */ PlayerProfile::PlayerProfile(const XMLNode* node) diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index 0647a5cbf..e711f1ccd 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -47,37 +47,35 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener, m_self_destroy = false; loadFromFile("enter_player_name_dialog.stkgui"); - TextBoxWidget* textCtrl = getWidget("textfield"); - assert(textCtrl != NULL); - textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + TextBoxWidget* text_field = getWidget("textfield"); + assert(text_field != NULL); + text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER); - //if (translations->isRTLLanguage()) textCtrl->addListener(this); -} + std::string username = ""; + + // If there is no player (i.e. first start of STK), try to pick + // a good default name + if (PlayerManager::get()->getNumPlayers() == 0) + { + if (getenv("USERNAME") != NULL) // for windows + username = getenv("USERNAME"); + else if (getenv("USER") != NULL) // Linux, Macs + username = getenv("USER"); + else if (getenv("LOGNAME") != NULL) // Linux, Macs + username = getenv("LOGNAME"); + } + text_field->setText(username.c_str()); +} // EnterPlayerNameDialog // ----------------------------------------------------------------------------- EnterPlayerNameDialog::~EnterPlayerNameDialog() { - // FIXME: what is this code for? - TextBoxWidget* textCtrl = getWidget("textfield"); - textCtrl->getIrrlichtElement()->remove(); - textCtrl->clearListeners(); -} +} // ~EnterPlayerNameDialog // ----------------------------------------------------------------------------- - -/* -void EnterPlayerNameDialog::onTextUpdated() -{ - TextBoxWidget* textCtrl = getWidget("textfield"); - LabelWidget* lbl = getWidget("preview"); - - lbl->setText( core::stringw(translations->fribidize(textCtrl->getText())), false ); -} -*/ -// ----------------------------------------------------------------------------- - -GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(const std::string& eventSource) +GUIEngine::EventPropagation + EnterPlayerNameDialog::processEvent(const std::string& eventSource) { if (eventSource == "cancel") { @@ -85,10 +83,9 @@ GUIEngine::EventPropagation EnterPlayerNameDialog::processEvent(const std::strin return GUIEngine::EVENT_BLOCK; } return GUIEngine::EVENT_LET; -} +} // processEvent // ----------------------------------------------------------------------------- - void EnterPlayerNameDialog::onEnterPressedInternal() { // ---- Cancel button pressed @@ -102,8 +99,8 @@ void EnterPlayerNameDialog::onEnterPressedInternal() } // ---- Otherwise, see if we can accept the new name - TextBoxWidget* textCtrl = getWidget("textfield"); - stringw player_name = textCtrl->getText().trim(); + TextBoxWidget* text_field = getWidget("textfield"); + stringw player_name = text_field->getText().trim(); if (StringUtils::notEmpty(player_name)) { // check for duplicates @@ -133,21 +130,20 @@ void EnterPlayerNameDialog::onEnterPressedInternal() label->setText(_("Cannot add a player with this name."), false); sfx_manager->quickSound( "anvil" ); } -} +} // onEnterPressedInternal // ----------------------------------------------------------------------------- - void EnterPlayerNameDialog::onUpdate(float dt) { // It's unsafe to delete from inside the event handler so we do it here if (m_self_destroy) { - TextBoxWidget* textCtrl = getWidget("textfield"); - stringw player_name = textCtrl->getText().trim(); + TextBoxWidget* text_field = getWidget("textfield"); + stringw player_name = text_field->getText().trim(); // irrLicht is too stupid to remove focus from deleted widgets // so do it by hand - GUIEngine::getGUIEnv()->removeFocus( textCtrl->getIrrlichtElement() ); + GUIEngine::getGUIEnv()->removeFocus( text_field->getIrrlichtElement() ); GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); // we will destroy the dialog before notifying the listener to be safer. @@ -159,4 +155,4 @@ void EnterPlayerNameDialog::onUpdate(float dt) if (listener != NULL) listener->onNewPlayerWithName( player_name ); } -} +} // onUpdate diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index a3451a457..f37577b3d 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -81,11 +81,10 @@ void StoryModeLobbyScreen::init() m_players->updateItemDisplay(); // Select the first user (the list of users is sorted by usage, so it - // is the most frequently used user). + // is the most frequently used user). if (PlayerManager::get()->getNumPlayers()>0) selectUser(0); - } // init // ---------------------------------------------------------------------------- @@ -242,6 +241,33 @@ void StoryModeLobbyScreen::unloaded() { } // unloaded +// ---------------------------------------------------------------------------- +/** Gets called when a dialog closes. At a first time start of STK the + * internet dialog is shown first. Only when this dialog closes is it possible + * to open the next dialog, which is the one to create a new player (which + * is conventient on a first start). + */ +void StoryModeLobbyScreen::onDialogClose() +{ + // To allow players to exit the game without creating a player, we count + // how often this function was called. The first time is after the + // internet allowed dialog, the 2nd time + static int number_of_calls = 0; + number_of_calls++; + if(PlayerManager::get()->getNumPlayers() == 0) + { + // Still 0 players after the enter player dialog was shown + // --> User wanted to abort, so pop this menu, which will + // trigger the end of STK. + if (number_of_calls > 1) + { + StateManager::get()->popMenu(); + return; + } + new EnterPlayerNameDialog(this, 0.5f, 0.4f); + } // getNumPlayers == 0 +} // onDialogClose + // ---------------------------------------------------------------------------- /** This is a callback from the new user dialog. */ diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp index ce506f97f..5c97634f2 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/story_mode_lobby.hpp @@ -57,6 +57,7 @@ private: void selectUser(int index); void makeEntryFieldsVisible(bool online); + virtual void onDialogClose(); public: friend class GUIEngine::ScreenSingleton; From 3b8d988cd2051710c3fad4508b536d87ca6e7040 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 11:34:53 +1000 Subject: [PATCH 010/365] Fixed compiler warnings. --- src/karts/kart.cpp | 2 +- src/states_screens/dialogs/debug_slider.cpp | 10 +++++----- src/tracks/track.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/karts/kart.cpp b/src/karts/kart.cpp index cfc59616f..388fff348 100644 --- a/src/karts/kart.cpp +++ b/src/karts/kart.cpp @@ -2291,7 +2291,7 @@ void Kart::updateFlying() { float orientation = getHeading(); m_body->applyCentralImpulse(btVector3(-100.0f*sin(orientation), 0.0, - -100.0*cos(orientation))); + -100.0f*cos(orientation))); } } diff --git a/src/states_screens/dialogs/debug_slider.cpp b/src/states_screens/dialogs/debug_slider.cpp index d8b7b9536..bd0bb7635 100644 --- a/src/states_screens/dialogs/debug_slider.cpp +++ b/src/states_screens/dialogs/debug_slider.cpp @@ -51,11 +51,11 @@ DebugSliderDialog::DebugSliderDialog(std::string id, irr::core::stringw msg) : float val; if (m_id == "lwhite") - val = irr_driver->getLwhite() * 10.; + val = irr_driver->getLwhite() * 10.f; if (m_id == "exposure") - val = irr_driver->getExposure() * 100.; + val = irr_driver->getExposure() * 100.f; - getWidget("value_slider")->setValue(val); + getWidget("value_slider")->setValue(int(val)); } // ------------------------------------------------------------------------------------------------------ @@ -83,9 +83,9 @@ GUIEngine::EventPropagation DebugSliderDialog::processEvent(const std::string& e int value = getWidget("value_slider")->getValue(); Log::info("DebugSlider", "Value for <%s> : %i", m_id.c_str(), value); if (m_id == "lwhite") - irr_driver->setLwhite(value / 10.); + irr_driver->setLwhite(value / 10.f); if (m_id == "exposure") - irr_driver->setExposure(value / 100.); + irr_driver->setExposure(value / 100.f); return GUIEngine::EVENT_BLOCK; } diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index cf6068168..dd5504dff 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -357,7 +357,7 @@ void Track::cleanup() void Track::loadTrackInfo() { irr_driver->setLwhite(1.); - irr_driver->setExposure(0.09); + irr_driver->setExposure(0.09f); // Default values m_use_fog = false; m_fog_max = 1.0f; From 5c7d29830d5cad54967db1facf5a92ad23cbdd81 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 12:23:54 +1000 Subject: [PATCH 011/365] Fixed compiler warning. --- src/karts/controller/skidding_ai.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 309b05974..155bf3b36 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1276,8 +1276,8 @@ void SkiddingAI::handleItems(const float dt) break; // Don't fire if the kart we are aiming at is invulnerable. - if (fire_backwards && m_kart_behind->isInvulnerable() || - !fire_backwards && m_kart_ahead->isInvulnerable() ) + if ( (fire_backwards && m_kart_behind->isInvulnerable()) || + (!fire_backwards && m_kart_ahead->isInvulnerable() ) return; float distance = fire_backwards ? m_distance_behind From a52b92083ead7245532a2bf5b959448afdf5ef14 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 12:25:34 +1000 Subject: [PATCH 012/365] Fixed typo. --- src/karts/controller/skidding_ai.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/karts/controller/skidding_ai.cpp b/src/karts/controller/skidding_ai.cpp index 155bf3b36..a82a1a7c9 100644 --- a/src/karts/controller/skidding_ai.cpp +++ b/src/karts/controller/skidding_ai.cpp @@ -1277,7 +1277,7 @@ void SkiddingAI::handleItems(const float dt) // Don't fire if the kart we are aiming at is invulnerable. if ( (fire_backwards && m_kart_behind->isInvulnerable()) || - (!fire_backwards && m_kart_ahead->isInvulnerable() ) + (!fire_backwards && m_kart_ahead->isInvulnerable() ) ) return; float distance = fire_backwards ? m_distance_behind From af9fb24d2e8c30d871af378d14563560f56c8362 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 16:37:05 +1000 Subject: [PATCH 013/365] Handle disabled internet (and provide a message to the user if he tries to login with internet disabled). --- data/gui/story_mode_lobby.stkgui | 2 +- src/states_screens/story_mode_lobby.cpp | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui index 5d8c4bf69..d7bbfd4dd 100644 --- a/data/gui/story_mode_lobby.stkgui +++ b/data/gui/story_mode_lobby.stkgui @@ -28,7 +28,7 @@ -
+
diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index f37577b3d..23a76b3bd 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -19,12 +19,12 @@ #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/label_widget.hpp" #include "guiengine/widgets/list_widget.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" -#include "states_screens/login_screen.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" @@ -149,6 +149,10 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { + LabelWidget *info = getWidget("message"); + info->setText("", true); + info->setErrorColor(); + if (name == "players") { // Clicked on a name --> Find the corresponding online data @@ -163,6 +167,16 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, } else if (name == "online") { + // If online access is not allowed, do not accept an online account + // but advice the user where to enable this option. + if (m_online_cb->getState() && UserConfigParams::m_internet_status == + Online::RequestManager::IPERM_NOT_ALLOWED) + { + info->setText( + "Internet access is disabled, please enable it in the options", + true); + m_online_cb->setState(false); + } makeEntryFieldsVisible(m_online_cb->getState()); } else if (name == "options") @@ -173,7 +187,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { if (m_online_cb->getState() && m_password_tb->getText() == "") { - getWidget("message")->setText("Enter password",true); + info->setText("You need to enter a password.",true); return; } From bb737d04483aa3de7a0f8d34c31cc1d8bd362a0a Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 16:57:04 +1000 Subject: [PATCH 014/365] Added error sfx. --- src/states_screens/story_mode_lobby.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 23a76b3bd..8d4b64722 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -17,6 +17,7 @@ #include "states_screens/story_mode_lobby.hpp" +#include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" #include "config/user_config.hpp" @@ -175,6 +176,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, info->setText( "Internet access is disabled, please enable it in the options", true); + sfx_manager->quickSound( "anvil" ); m_online_cb->setState(false); } makeEntryFieldsVisible(m_online_cb->getState()); @@ -187,7 +189,8 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { if (m_online_cb->getState() && m_password_tb->getText() == "") { - info->setText("You need to enter a password.",true); + info->setText(_("You need to enter a password."),true); + sfx_manager->quickSound( "anvil" ); return; } From d7219f3a2d54d6e27cd51546813aa357c7d26da9 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 30 Apr 2014 16:57:22 +1000 Subject: [PATCH 015/365] Added 'ok' button to 'new player' dialog. I can't seem to get them next to each other, so for now they are just on top of each other. --- data/gui/enter_player_name_dialog.stkgui | 8 ++++---- src/states_screens/dialogs/enter_player_name_dialog.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/data/gui/enter_player_name_dialog.stkgui b/data/gui/enter_player_name_dialog.stkgui index d70aa3264..e8385bf25 100644 --- a/data/gui/enter_player_name_dialog.stkgui +++ b/data/gui/enter_player_name_dialog.stkgui @@ -11,10 +11,10 @@ - - -
diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index e711f1ccd..c70fa1c49 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -17,8 +17,6 @@ #include "states_screens/dialogs/enter_player_name_dialog.hpp" -#include - #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" #include "config/player_manager.hpp" @@ -31,6 +29,7 @@ #include "utils/translation.hpp" #include "utils/string_utils.hpp" +#include using namespace GUIEngine; using namespace irr; @@ -82,6 +81,11 @@ GUIEngine::EventPropagation dismiss(); return GUIEngine::EVENT_BLOCK; } + else if (eventSource == "ok") + { + onEnterPressedInternal(); + return GUIEngine::EVENT_BLOCK; + } return GUIEngine::EVENT_LET; } // processEvent From 5ff9d7f1982008a7f3fdf109ef3857a182bde8b4 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 5 May 2014 08:59:27 +1000 Subject: [PATCH 016/365] Block new StoryModeLobbyScreen while login is in progress (and display ... while this is happening). This allows to show error messages (e.g. user can re-enter the password if login failed, without having to go to another menu or perhaps even missing the fact that they are not logged in). --- src/online/messages.cpp | 6 + src/online/messages.hpp | 1 + src/online/online_player_profile.cpp | 6 +- src/states_screens/login_screen.cpp | 24 --- src/states_screens/login_screen.hpp | 2 - src/states_screens/main_menu_screen.cpp | 8 +- src/states_screens/story_mode_lobby.cpp | 190 ++++++++++++++++-------- src/states_screens/story_mode_lobby.hpp | 27 +++- 8 files changed, 168 insertions(+), 96 deletions(-) diff --git a/src/online/messages.cpp b/src/online/messages.cpp index 3b9bf2298..9bdfce9b9 100644 --- a/src/online/messages.cpp +++ b/src/online/messages.cpp @@ -85,6 +85,12 @@ namespace Online return irr::core::stringw(_("Processing")) + loadingDots(); } + // ------------------------------------------------------------------------ + /** Convenience function to type less in calls. */ + irr::core::stringw loadingDots(const wchar_t *s) + { + return irr::core::stringw(s)+loadingDots(); + } // ------------------------------------------------------------------------ /** * Shows a increasing number of dots. diff --git a/src/online/messages.hpp b/src/online/messages.hpp index c2f4fbc5c..9349caf91 100644 --- a/src/online/messages.hpp +++ b/src/online/messages.hpp @@ -31,6 +31,7 @@ namespace Online namespace Messages { irr::core::stringw loadingDots (float interval = 0.5f, int max_dots = 3); + irr::core::stringw loadingDots (const wchar_t *s); irr::core::stringw signingIn (); irr::core::stringw signingOut (); irr::core::stringw validatingInfo (); diff --git a/src/online/online_player_profile.cpp b/src/online/online_player_profile.cpp index 582be02cc..6ffe7928a 100644 --- a/src/online/online_player_profile.cpp +++ b/src/online/online_player_profile.cpp @@ -27,11 +27,11 @@ #include "online/online_profile.hpp" #include "online/profile_manager.hpp" #include "online/servers_manager.hpp" -#include "states_screens/login_screen.hpp" +#include "states_screens/story_mode_lobby.hpp" #include "states_screens/online_profile_friends.hpp" #include "states_screens/dialogs/change_password_dialog.hpp" -#include "states_screens/dialogs/user_info_dialog.hpp" #include "states_screens/dialogs/notification_dialog.hpp" +#include "states_screens/dialogs/user_info_dialog.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" @@ -143,7 +143,7 @@ namespace Online { PlayerManager::getCurrentPlayer()->signIn(isSuccess(), getXMLData()); GUIEngine::Screen *screen = GUIEngine::getCurrentScreen(); - LoginScreen *login = dynamic_cast(screen); + StoryModeLobbyScreen *login = dynamic_cast(screen); if(login) { if(isSuccess()) diff --git a/src/states_screens/login_screen.cpp b/src/states_screens/login_screen.cpp index 8f6e39e70..219fb04fd 100644 --- a/src/states_screens/login_screen.cpp +++ b/src/states_screens/login_screen.cpp @@ -103,30 +103,6 @@ void LoginScreen::login() } } // login -// ----------------------------------------------------------------------------- -/** Called from the login request when it was successfully exected. - */ -void LoginScreen::loginSuccessful() -{ - // The callback is done from the main thread, so no need to sync - // access to m_success - m_success = true; -} // loginSuccessful - -// ----------------------------------------------------------------------------- -/** Called from the login request when the login was not successful. - * \param error_message The error message from the server (or curl). - */ -void LoginScreen::loginError(const irr::core::stringw & error_message) -{ - sfx_manager->quickSound("anvil"); - LabelWidget *info_widget = getWidget("info"); - info_widget->setErrorColor(); - info_widget->setText(error_message, false); - - m_options_widget->setActivated(); -} // loginError - // ----------------------------------------------------------------------------- /** Called in each frame. If a successful login is detected, the online screen * will be displayed. diff --git a/src/states_screens/login_screen.hpp b/src/states_screens/login_screen.hpp index b86fd5c57..bf739f037 100644 --- a/src/states_screens/login_screen.hpp +++ b/src/states_screens/login_screen.hpp @@ -56,8 +56,6 @@ public: const std::string& name, const int playerID) OVERRIDE; - void loginSuccessful(); - void loginError(const irr::core::stringw & error_message); }; // class LoginScreen #endif diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 98927d034..b0404954a 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -41,11 +41,11 @@ #include "states_screens/credits.hpp" #include "states_screens/grand_prix_editor_screen.hpp" #include "states_screens/help_screen_1.hpp" -#include "states_screens/login_screen.hpp" #include "states_screens/offline_kart_selection.hpp" #include "states_screens/online_screen.hpp" #include "states_screens/options_screen_video.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/story_mode_lobby.hpp" #if DEBUG_MENU_ITEM #include "states_screens/feature_unlocked.hpp" #include "states_screens/grand_prix_lose.hpp" @@ -408,7 +408,11 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, if (PlayerManager::getCurrentOnlineId()) StateManager::get()->pushScreen(OnlineScreen::getInstance()); else - StateManager::get()->pushScreen(LoginScreen::getInstance()); + { + StoryModeLobbyScreen *login = StoryModeLobbyScreen::getInstance(); + login->setIsPopup(true); + StateManager::get()->pushScreen(login); + } } else if (selection == "addons") { diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 8d4b64722..6afe56df8 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -25,6 +25,7 @@ #include "guiengine/widgets/dynamic_ribbon_widget.hpp" #include "guiengine/widgets/label_widget.hpp" #include "guiengine/widgets/list_widget.hpp" +#include "online/messages.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" @@ -38,6 +39,7 @@ DEFINE_SCREEN_SINGLETON( StoryModeLobbyScreen ); StoryModeLobbyScreen::StoryModeLobbyScreen() : Screen("story_mode_lobby.stkgui") { + m_is_popup_window = false; } // StoryModeLobbyScreen // ---------------------------------------------------------------------------- @@ -51,6 +53,7 @@ void StoryModeLobbyScreen::loadedFromFile() void StoryModeLobbyScreen::init() { + m_login_successful = false; m_online_cb = getWidget("online"); assert(m_online_cb); m_username_tb = getWidget("username"); @@ -60,13 +63,17 @@ void StoryModeLobbyScreen::init() m_password_tb->setPasswordBox(true, L'*'); m_players = getWidget("players"); assert(m_players); + m_options_widget = getWidget("options"); + assert(m_options_widget); + m_info_widget = getWidget("message"); + assert(m_info_widget); Screen::init(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); - if (player) + if (player && !m_is_popup_window) { - //StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - //return; + StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + return; } m_players->clearItems(); @@ -103,6 +110,11 @@ void StoryModeLobbyScreen::selectUser(int index) { PlayerProfile *profile = PlayerManager::get()->getPlayer(index); assert(profile); + PlayerProfile *cp = PlayerManager::getCurrentPlayer(); + // If the current user is logged in, a logout is required now. + if(profile!=cp && cp && cp->isLoggedIn()) + cp->requestSignOut(); + getWidget("username")->setText(profile ->getLastOnlineName()); m_players->setSelection(StringUtils::toString(index), 0, /*focusIt*/true); @@ -117,6 +129,7 @@ void StoryModeLobbyScreen::selectUser(int index) } // Now last use was with online --> Display the saved data + m_online_cb->setState(true); makeEntryFieldsVisible(true); m_username_tb->setText(profile->getLastOnlineName()); @@ -141,7 +154,7 @@ void StoryModeLobbyScreen::makeEntryFieldsVisible(bool online) m_username_tb->setVisible(online); getWidget("label_password")->setVisible(online); m_password_tb->setVisible(online); -} // update +} // makeEntryFieldsVisible // ---------------------------------------------------------------------------- /** Called when the user selects anything on the screen. @@ -150,18 +163,18 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { - LabelWidget *info = getWidget("message"); - info->setText("", true); - info->setErrorColor(); + // Clean any error message still shown + m_info_widget->setText("", true); + m_info_widget->setErrorColor(); if (name == "players") { // Clicked on a name --> Find the corresponding online data // and display them - const std::string &s_index = getWidget("players") - ->getSelectionIDString(player_id); - if (s_index == "") return; // can happen if the list is empty - + const std::string &s_index = getWidget("players") + ->getSelectionIDString(player_id); + if (s_index == "") return; // can happen if the list is empty + unsigned int id; if (StringUtils::fromString(s_index, id)) selectUser(id); @@ -173,7 +186,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, if (m_online_cb->getState() && UserConfigParams::m_internet_status == Online::RequestManager::IPERM_NOT_ALLOWED) { - info->setText( + m_info_widget->setText( "Internet access is disabled, please enable it in the options", true); sfx_manager->quickSound( "anvil" ); @@ -183,77 +196,126 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, } else if (name == "options") { - const std::string &button = - getWidget("options")->getSelectionIDString(player_id); + const std::string &button = + m_options_widget->getSelectionIDString(player_id); if (button == "ok" || button == "ok_and_save") { if (m_online_cb->getState() && m_password_tb->getText() == "") { - info->setText(_("You need to enter a password."),true); - sfx_manager->quickSound( "anvil" ); + m_info_widget->setText(_("You need to enter a password."), true); + sfx_manager->quickSound("anvil"); return; } - - const std::string &name = m_players->getSelectionIDString(player_id); - - 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; + login(button=="ok_and_save"); } // button==ok || ok_and_save else if (button == "new_user") { new EnterPlayerNameDialog(this, 0.5f, 0.4f); } + else if (button == "cancel") + { + PlayerProfile *cp = PlayerManager::getCurrentPlayer(); + if(cp && cp->isLoggedIn()) + cp->requestSignOut(); + StateManager::get()->popMenu(); + } } // options return; - - if (name == "back") - { - StateManager::get()->escapePressed(); - } - else if (name == "gameslots") - { - ListWidget* list = getWidget("gameslots"); - - bool slot_found = false; - - for (unsigned int n=0; ngetNumPlayers(); n++) - { - PlayerProfile *player = PlayerManager::get()->getPlayer(n); - if (list->getSelectionLabel() == player->getName()) - { - PlayerManager::get()->setCurrentPlayer(player, false); - slot_found = true; - break; - } - } - - 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()); - } } // eventCallback // ---------------------------------------------------------------------------- +/** Called when OK or OK-and-save is clicked. + * This will trigger the actual login (if requested) etc. + * \param remember_me True if the login details should be remembered, + * so that next time this menu can be skipped. + */ +void StoryModeLobbyScreen::login(bool remember_me) +{ + m_options_widget->setDeactivated(); + const std::string &s_id = m_players->getSelectionIDString(0); + unsigned int n_id; + StringUtils::fromString(s_id, n_id); + PlayerProfile *profile = PlayerManager::get()->getPlayer(n_id); + PlayerManager::get()->setCurrentPlayer(profile, remember_me); + assert(profile); + + // If no online login requested, go straight to the main menu screen. + if(!m_online_cb->getState()) + { + if(profile->isLoggedIn()) + { + // The player is logged in, but online is now disabled, + // so log the player out. There is no error handling of + // a failed logout request + profile->requestSignOut(); + } + m_login_successful = true; + // This will trigger replacing this screen with the main menu screen. + onUpdate(0.0f); + return; + } + + // If the user is not already logged in, start a login request + if (!profile->isLoggedIn()) + { + if (profile->hasSavedSession()) + profile->requestSavedSession(); + else + profile->requestSignIn(m_username_tb->getText(), + m_password_tb->getText(), + remember_me); + } + return; +} // login + +// ---------------------------------------------------------------------------- +/** Called once every frame. It will replace this screen with the main menu + * screen if a successful login happened. + */ +void StoryModeLobbyScreen::onUpdate(float dt) +{ + if (!m_options_widget->isActivated()) + m_info_widget->setText(Online::Messages::loadingDots( _("Signing in")), + false); + + if(m_online_cb->getState() && m_login_successful) + { + StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); + return; + } + + + PlayerProfile *cp = PlayerManager::getCurrentPlayer(); + if (cp && cp->isLoggedIn()) + cp->requestSignOut(); +} // onUpdate + +// ---------------------------------------------------------------------------- +/** Callback from player profile if login was successful. + */ +void StoryModeLobbyScreen::loginSuccessful() +{ + // The callback is done from the main thread, so no need to sync + // access to m_success + m_login_successful = true; +} // loginSuccessful + +// ---------------------------------------------------------------------------- +/** Callback from player profile if login was unsuccessful. + * \param error_message Contains the error message. + */ +void StoryModeLobbyScreen::loginError(const irr::core::stringw & error_message) +{ + sfx_manager->quickSound("anvil"); + m_info_widget->setErrorColor(); + m_info_widget->setText(error_message, false); + m_options_widget->setActivated(); +} // loginError + +// ---------------------------------------------------------------------------- void StoryModeLobbyScreen::unloaded() { } // unloaded diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp index 5c97634f2..996c58538 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/story_mode_lobby.hpp @@ -43,6 +43,15 @@ class StoryModeLobbyScreen : public GUIEngine::Screen, StoryModeLobbyScreen(); private: + + /** True if this window is a popup window, which means it will not + * immediately go to the main menu if a current player is defined. */ + bool m_is_popup_window; + + /** Set in the callback from the login request to indicate that this + * window can be closed. */ + bool m_login_successful; + /** Online check box. */ GUIEngine::CheckBoxWidget *m_online_cb; @@ -52,12 +61,21 @@ private: /** Password widget. */ GUIEngine::TextBoxWidget *m_password_tb; + /** Label field for warning and error messages. */ + GUIEngine::LabelWidget * m_info_widget; + + /** The ribbon with all buttons. */ + GUIEngine::RibbonWidget *m_options_widget; + /** The dynamic ribbon containing all players. */ GUIEngine::DynamicRibbonWidget* m_players; void selectUser(int index); void makeEntryFieldsVisible(bool online); + void login(bool remember_me); virtual void onDialogClose(); + virtual void onUpdate(float dt) OVERRIDE; + public: friend class GUIEngine::ScreenSingleton; @@ -78,6 +96,13 @@ public: /** \brief implement callback from EnterPlayerNameDialog::INewPlayerListener */ virtual void onNewPlayerWithName(const irr::core::stringw& newName); -}; + + void loginSuccessful(); + void loginError(const irr::core::stringw & error_message); + // ------------------------------------------------------------------------ + /** True if this window is a popup window (i.e. it should not exit even if + * the current player exists. */ + void setIsPopup(bool popup) { m_is_popup_window = popup; } +}; // class StoryModeLobby #endif From fc3213a47dc9398c54fb634d30f248673ef8f8a2 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 5 May 2014 09:17:19 +1000 Subject: [PATCH 017/365] Fixed linux compilation. --- src/states_screens/story_mode_lobby.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/story_mode_lobby.hpp index 996c58538..d39853312 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/story_mode_lobby.hpp @@ -27,6 +27,7 @@ namespace GUIEngine { class CheckBoxWidget; + class RibbonWidget; class TextBoxWidget; class Widget; } From 601083165465a91643f30d4058235ef0e1b9a449 Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 5 May 2014 20:46:48 +1000 Subject: [PATCH 018/365] Removed original login screen, made the new login screen a tab. Removed guest tab (and started to use a checkbox for that for now). Work in progress. --- data/gui/online/login.stkgui | 58 -------- data/gui/online/register.stkgui | 2 - data/gui/story_mode_lobby.stkgui | 25 +++- src/states_screens/guest_login_screen.cpp | 78 ---------- src/states_screens/guest_login_screen.hpp | 48 ------- src/states_screens/login_screen.cpp | 166 ---------------------- src/states_screens/login_screen.hpp | 61 -------- src/states_screens/register_screen.cpp | 7 +- src/states_screens/story_mode_lobby.cpp | 53 ++++--- 9 files changed, 56 insertions(+), 442 deletions(-) delete mode 100644 data/gui/online/login.stkgui delete mode 100644 src/states_screens/guest_login_screen.cpp delete mode 100644 src/states_screens/guest_login_screen.hpp delete mode 100644 src/states_screens/login_screen.cpp delete mode 100644 src/states_screens/login_screen.hpp diff --git a/data/gui/online/login.stkgui b/data/gui/online/login.stkgui deleted file mode 100644 index 04bbff810..000000000 --- a/data/gui/online/login.stkgui +++ /dev/null @@ -1,58 +0,0 @@ - - - -
- -
- - - - - - - - - -
- - -
-
-
- -
-
- -
-
-
-
- - - -
diff --git a/data/gui/online/register.stkgui b/data/gui/online/register.stkgui index 1a29c818a..4a0476fe9 100644 --- a/data/gui/online/register.stkgui +++ b/data/gui/online/register.stkgui @@ -9,8 +9,6 @@ - diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/story_mode_lobby.stkgui index d7bbfd4dd..4cd43f4b2 100644 --- a/data/gui/story_mode_lobby.stkgui +++ b/data/gui/story_mode_lobby.stkgui @@ -1,9 +1,16 @@ +
-
- +
-
+ + + + + +
+
+
+
+
-
+
- getWidget("login_tabs"); - if (tabs) tabs->select( "tab_guest_login", PLAYER_ID_GAME_MASTER ); -} // init - -// ----------------------------------------------------------------------------- - -void GuestLoginScreen::eventCallback(Widget* widget, const std::string& name, - const int playerID) -{ - if (name == "login_tabs") - { - const std::string selection = - ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if (selection == "tab_login") - StateManager::get()->replaceTopMostScreen(LoginScreen::getInstance()); - else if (selection == "tab_register") - StateManager::get()->replaceTopMostScreen(RegisterScreen::getInstance()); - } - else if (name=="options") - { - const std::string button = - getWidget("options") - ->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if(button=="sign_in") - { - // FIXME TODO: guest login - } - else if(button=="cancel") - StateManager::get()->escapePressed(); - } - else if (name == "back") - { - StateManager::get()->escapePressed(); - } - -} // eventCallback - -// ----------------------------------------------------------------------------- diff --git a/src/states_screens/guest_login_screen.hpp b/src/states_screens/guest_login_screen.hpp deleted file mode 100644 index e33c7434b..000000000 --- a/src/states_screens/guest_login_screen.hpp +++ /dev/null @@ -1,48 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2014 Joerg Henrichs -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef HEADER_GUEST_LOGIN_SCREEN_HPP -#define HEADER_GUEST_LOGIN_SCREEN_HPP - -#include "guiengine/screen.hpp" - -namespace GUIEngine { class Widget; } - -/** - * \brief Gest-Login screen. - * \ingroup states_screens - */ -class GuestLoginScreen : public GUIEngine::Screen, - public GUIEngine::ScreenSingleton -{ - friend class GUIEngine::ScreenSingleton; - GuestLoginScreen(); - -public: - - virtual void init() OVERRIDE; - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void loadedFromFile() OVERRIDE {}; - - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void eventCallback(GUIEngine::Widget* widget, - const std::string& name, - const int playerID) OVERRIDE; - -}; // GuestLoginScreen - -#endif diff --git a/src/states_screens/login_screen.cpp b/src/states_screens/login_screen.cpp deleted file mode 100644 index 219fb04fd..000000000 --- a/src/states_screens/login_screen.cpp +++ /dev/null @@ -1,166 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2014 Joerg Henrichs -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include "states_screens/login_screen.hpp" - -#include "audio/sfx_manager.hpp" -#include "config/player_manager.hpp" -#include "guiengine/widgets/check_box_widget.hpp" -#include "guiengine/widgets/label_widget.hpp" -#include "guiengine/widgets/ribbon_widget.hpp" -#include "guiengine/widgets/text_box_widget.hpp" -#include "guiengine/widgets/check_box_widget.hpp" -#include "online/messages.hpp" -#include "states_screens/guest_login_screen.hpp" -#include "states_screens/online_screen.hpp" -#include "states_screens/register_screen.hpp" -#include "states_screens/state_manager.hpp" -#include "states_screens/dialogs/recovery_dialog.hpp" -#include "utils/log.hpp" -#include "utils/translation.hpp" - -#include - -using namespace GUIEngine; -using namespace irr; - -DEFINE_SCREEN_SINGLETON( LoginScreen ); - -// ----------------------------------------------------------------------------- - -LoginScreen::LoginScreen() : Screen("online/login.stkgui") -{ -} // LoginScreen - -// ----------------------------------------------------------------------------- -void LoginScreen::init() -{ - Screen::init(); - // Make sure this tab is actually focused. - RibbonWidget* tabs = this->getWidget("login_tabs"); - if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER ); - - TextBoxWidget *password_widget = getWidget("password"); - password_widget->setPasswordBox(true,L'*'); - - m_options_widget = getWidget("options"); - assert(m_options_widget); - m_options_widget->setActivated(); - - m_info_widget = getWidget("info"); - assert(m_info_widget != NULL); - m_success = false; - - // As default don't select 'remember' - getWidget("remember")->setState(false); -} // init - -// ----------------------------------------------------------------------------- -/** Collects the data entered into the gui and submits a login request. - * The login request is processes asynchronously b the ReqeustManager. - */ -void LoginScreen::login() -{ - // Reset any potential error message shown. - LabelWidget *info_widget = getWidget("info"); - info_widget->setDefaultColor(); - info_widget->setText("", false); - - const core::stringw username = getWidget("username") - ->getText().trim(); - const core::stringw password = getWidget("password") - ->getText().trim(); - - if (username.size() < 4 || username.size() > 30 || - password.size() < 8 || password.size() > 30 ) - { - sfx_manager->quickSound("anvil"); - info_widget->setErrorColor(); - info_widget->setText(_("Username and/or password too short or too long."), - false); - } - else - { - m_options_widget->setDeactivated(); - info_widget->setDefaultColor(); - bool remember = getWidget("remember")->getState(); - PlayerManager::requestSignIn(username, password, remember); - PlayerManager::get()->addOnlineId(username); - } -} // login - -// ----------------------------------------------------------------------------- -/** Called in each frame. If a successful login is detected, the online screen - * will be displayed. - */ -void LoginScreen::onUpdate(float dt) -{ - - if(!m_options_widget->isActivated()) - m_info_widget->setText(Online::Messages::signingIn(), false); - - // Login was successful, so put the online main menu on the screen - if(m_success) - { - StateManager::get()->replaceTopMostScreen(OnlineScreen::getInstance()); - } -} // onUpdate - -// ----------------------------------------------------------------------------- -/** Called when the user clicks on a widget. - * \param widget that was clicked on. - * \param name Name of the widget. - * \param playerID The id of the player who clicked the item. - */ -void LoginScreen::eventCallback(Widget* widget, const std::string& name, - const int playerID) -{ - if (name == "login_tabs") - { - StateManager *sm = StateManager::get(); - const std::string selection = - ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); - - if (selection == "tab_guest_login") - sm->replaceTopMostScreen(GuestLoginScreen::getInstance()); - else if (selection == "tab_register") - sm->replaceTopMostScreen(RegisterScreen::getInstance()); - } - else if (name=="options") - { - const std::string button = - getWidget("options") - ->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if(button=="sign_in") - { - login(); - } - else if(button=="recovery") - { - new RecoveryDialog(); - } - else if(button=="cancel") - StateManager::get()->escapePressed(); - } - else if (name == "back") - { - StateManager::get()->escapePressed(); - } - -} // eventCallback - -// ----------------------------------------------------------------------------- diff --git a/src/states_screens/login_screen.hpp b/src/states_screens/login_screen.hpp deleted file mode 100644 index bf739f037..000000000 --- a/src/states_screens/login_screen.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2014 Joerg Henrichs -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef HEADER_LOGIN_SCREEN_HPP -#define HEADER_LOGIN_SCREEN_HPP - -#include "guiengine/screen.hpp" - -namespace GUIEngine { class LabelWidget; - class RibbonWidget; - class Widget; } - -/** - * \brief Login screen. - * \ingroup states_screens - */ -class LoginScreen : public GUIEngine::Screen, - public GUIEngine::ScreenSingleton -{ -private: - friend class GUIEngine::ScreenSingleton; - LoginScreen(); - void login(); - - /** Store a pointer to the options buttons. */ - GUIEngine::RibbonWidget *m_options_widget; - GUIEngine::LabelWidget * m_info_widget; - - bool m_success; - - -public: - - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void loadedFromFile() OVERRIDE {}; - virtual void init() OVERRIDE; - virtual void onUpdate(float dt) OVERRIDE; - - - /** \brief implement callback from parent class GUIEngine::Screen */ - virtual void eventCallback(GUIEngine::Widget* widget, - const std::string& name, - const int playerID) OVERRIDE; - -}; // class LoginScreen - -#endif diff --git a/src/states_screens/register_screen.cpp b/src/states_screens/register_screen.cpp index 31ee3f376..acaa2b209 100644 --- a/src/states_screens/register_screen.cpp +++ b/src/states_screens/register_screen.cpp @@ -26,10 +26,9 @@ #include "online/xml_request.hpp" #include "states_screens/dialogs/registration_dialog.hpp" #include "states_screens/dialogs/message_dialog.hpp" -#include "states_screens/guest_login_screen.hpp" -#include "states_screens/login_screen.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/story_mode_lobby.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" @@ -188,9 +187,7 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name, ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); StateManager *sm = StateManager::get(); if (selection == "tab_login") - sm->replaceTopMostScreen(LoginScreen::getInstance()); - else if (selection == "tab_guest_login") - sm->replaceTopMostScreen(GuestLoginScreen::getInstance()); + sm->replaceTopMostScreen(StoryModeLobbyScreen::getInstance()); } else if (name=="options") { diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/story_mode_lobby.cpp index 6afe56df8..607ad22d8 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/story_mode_lobby.cpp @@ -28,6 +28,7 @@ #include "online/messages.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" #include "states_screens/main_menu_screen.hpp" +#include "states_screens/register_screen.hpp" #include "states_screens/state_manager.hpp" @@ -68,6 +69,10 @@ void StoryModeLobbyScreen::init() m_info_widget = getWidget("message"); assert(m_info_widget); + // Make sure this tab is actually focused. + RibbonWidget* tabs = getWidget("login_tabs"); + if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER ); + Screen::init(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player && !m_is_popup_window) @@ -167,7 +172,14 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, m_info_widget->setText("", true); m_info_widget->setErrorColor(); - if (name == "players") + if (name == "login_tabs") + { + const std::string selection = + ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); + if (selection == "tab_register") + StateManager::get()->replaceTopMostScreen(RegisterScreen::getInstance()); + } + else if (name == "players") { // Clicked on a name --> Find the corresponding online data // and display them @@ -198,16 +210,10 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, { const std::string &button = m_options_widget->getSelectionIDString(player_id); - if (button == "ok" || button == "ok_and_save") + if (button == "ok") { - if (m_online_cb->getState() && m_password_tb->getText() == "") - { - m_info_widget->setText(_("You need to enter a password."), true); - sfx_manager->quickSound("anvil"); - return; - } - login(button=="ok_and_save"); - } // button==ok || ok_and_save + login(getWidget("remember_me")->getState()); + } // button==ok else if (button == "new_user") { new EnterPlayerNameDialog(this, 0.5f, 0.4f); @@ -258,17 +264,28 @@ void StoryModeLobbyScreen::login(bool remember_me) return; } + if(profile->isLoggedIn()) + return; + // If the user is not already logged in, start a login request - if (!profile->isLoggedIn()) + if (profile->hasSavedSession()) { - if (profile->hasSavedSession()) - profile->requestSavedSession(); - else - profile->requestSignIn(m_username_tb->getText(), - m_password_tb->getText(), - remember_me); + // Online login with saved token + profile->requestSavedSession(); } - return; + else + { + // Online login with password + if (m_password_tb->getText() == "") + { + m_info_widget->setText(_("You need to enter a password."), true); + sfx_manager->quickSound("anvil"); + return; + } + profile->requestSignIn(m_username_tb->getText(), + m_password_tb->getText(), + remember_me); + } // !hasSavedSession } // login // ---------------------------------------------------------------------------- From d847e8de00b2069ff18fa53e8689b2734b34a85f Mon Sep 17 00:00:00 2001 From: hiker Date: Mon, 5 May 2014 21:17:46 +1000 Subject: [PATCH 019/365] Renamed StoryModeLobby to UserScreen. --- ...y_mode_lobby.stkgui => user_screen.stkgui} | 0 src/main.cpp | 4 +-- src/online/online_player_profile.cpp | 4 +-- src/states_screens/main_menu_screen.cpp | 4 +-- src/states_screens/options_screen_players.cpp | 4 +-- src/states_screens/register_screen.cpp | 4 +-- .../{story_mode_lobby.cpp => user_screen.cpp} | 34 +++++++++---------- .../{story_mode_lobby.hpp => user_screen.hpp} | 16 ++++----- 8 files changed, 35 insertions(+), 35 deletions(-) rename data/gui/{story_mode_lobby.stkgui => user_screen.stkgui} (100%) rename src/states_screens/{story_mode_lobby.cpp => user_screen.cpp} (93%) rename src/states_screens/{story_mode_lobby.hpp => user_screen.hpp} (88%) diff --git a/data/gui/story_mode_lobby.stkgui b/data/gui/user_screen.stkgui similarity index 100% rename from data/gui/story_mode_lobby.stkgui rename to data/gui/user_screen.stkgui diff --git a/src/main.cpp b/src/main.cpp index bae754040..6aad44288 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -187,9 +187,9 @@ #include "race/race_manager.hpp" #include "replay/replay_play.hpp" #include "replay/replay_recorder.hpp" -#include "states_screens/story_mode_lobby.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" +#include "states_screens/user_screen.hpp" #include "states_screens/dialogs/message_dialog.hpp" #include "tracks/track.hpp" #include "tracks/track_manager.hpp" @@ -1287,7 +1287,7 @@ int main(int argc, char *argv[] ) if(!UserConfigParams::m_no_start_screen) { - StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance()); + StateManager::get()->pushScreen(UserScreen::getInstance()); #ifdef ENABLE_WIIUSE // Show a dialog to allow connection of wiimotes. */ if(WiimoteManager::isEnabled()) diff --git a/src/online/online_player_profile.cpp b/src/online/online_player_profile.cpp index 6ffe7928a..5fc59109c 100644 --- a/src/online/online_player_profile.cpp +++ b/src/online/online_player_profile.cpp @@ -27,8 +27,8 @@ #include "online/online_profile.hpp" #include "online/profile_manager.hpp" #include "online/servers_manager.hpp" -#include "states_screens/story_mode_lobby.hpp" #include "states_screens/online_profile_friends.hpp" +#include "states_screens/user_screen.hpp" #include "states_screens/dialogs/change_password_dialog.hpp" #include "states_screens/dialogs/notification_dialog.hpp" #include "states_screens/dialogs/user_info_dialog.hpp" @@ -143,7 +143,7 @@ namespace Online { PlayerManager::getCurrentPlayer()->signIn(isSuccess(), getXMLData()); GUIEngine::Screen *screen = GUIEngine::getCurrentScreen(); - StoryModeLobbyScreen *login = dynamic_cast(screen); + UserScreen *login = dynamic_cast(screen); if(login) { if(isSuccess()) diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index eb5db6fee..c76084f21 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -45,7 +45,7 @@ #include "states_screens/online_screen.hpp" #include "states_screens/options_screen_video.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/story_mode_lobby.hpp" +#include "states_screens/user_screen.hpp" #if DEBUG_MENU_ITEM #include "states_screens/feature_unlocked.hpp" #include "states_screens/grand_prix_lose.hpp" @@ -425,7 +425,7 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name, StateManager::get()->pushScreen(OnlineScreen::getInstance()); else { - StoryModeLobbyScreen *login = StoryModeLobbyScreen::getInstance(); + UserScreen *login = UserScreen::getInstance(); login->setIsPopup(true); StateManager::get()->pushScreen(login); } diff --git a/src/states_screens/options_screen_players.cpp b/src/states_screens/options_screen_players.cpp index 9854d583a..c535c864a 100644 --- a/src/states_screens/options_screen_players.cpp +++ b/src/states_screens/options_screen_players.cpp @@ -35,7 +35,7 @@ #include "states_screens/options_screen_video.hpp" #include "states_screens/options_screen_ui.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/story_mode_lobby.hpp" +#include "states_screens/user_screen.hpp" #include @@ -186,7 +186,7 @@ void OptionsScreenPlayers::eventCallback(Widget* widget, const std::string& name { race_manager->clearKartLastPositionOnOverworld(); PlayerManager::get()->setCurrentPlayer(NULL,false); - StateManager::get()->pushScreen(StoryModeLobbyScreen::getInstance()); + StateManager::get()->pushScreen(UserScreen::getInstance()); } } // eventCallback diff --git a/src/states_screens/register_screen.cpp b/src/states_screens/register_screen.cpp index acaa2b209..fb11c2f52 100644 --- a/src/states_screens/register_screen.cpp +++ b/src/states_screens/register_screen.cpp @@ -28,7 +28,7 @@ #include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/state_manager.hpp" -#include "states_screens/story_mode_lobby.hpp" +#include "states_screens/user_screen.hpp" #include "utils/log.hpp" #include "utils/translation.hpp" @@ -187,7 +187,7 @@ void RegisterScreen::eventCallback(Widget* widget, const std::string& name, ((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER); StateManager *sm = StateManager::get(); if (selection == "tab_login") - sm->replaceTopMostScreen(StoryModeLobbyScreen::getInstance()); + sm->replaceTopMostScreen(UserScreen::getInstance()); } else if (name=="options") { diff --git a/src/states_screens/story_mode_lobby.cpp b/src/states_screens/user_screen.cpp similarity index 93% rename from src/states_screens/story_mode_lobby.cpp rename to src/states_screens/user_screen.cpp index 607ad22d8..da02e0e47 100644 --- a/src/states_screens/story_mode_lobby.cpp +++ b/src/states_screens/user_screen.cpp @@ -15,7 +15,7 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include "states_screens/story_mode_lobby.hpp" +#include "states_screens/user_screen.hpp" #include "audio/sfx_manager.hpp" #include "challenges/unlock_manager.hpp" @@ -34,25 +34,25 @@ using namespace GUIEngine; -DEFINE_SCREEN_SINGLETON( StoryModeLobbyScreen ); +DEFINE_SCREEN_SINGLETON( UserScreen ); // ---------------------------------------------------------------------------- -StoryModeLobbyScreen::StoryModeLobbyScreen() : Screen("story_mode_lobby.stkgui") +UserScreen::UserScreen() : Screen("user_screen.stkgui") { m_is_popup_window = false; -} // StoryModeLobbyScreen +} // UserScreen // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::loadedFromFile() +void UserScreen::loadedFromFile() { } // loadedFromFile // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::init() +void UserScreen::init() { m_login_successful = false; m_online_cb = getWidget("online"); @@ -102,7 +102,7 @@ void StoryModeLobbyScreen::init() // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::tearDown() +void UserScreen::tearDown() { Screen::tearDown(); } // tearDown @@ -111,7 +111,7 @@ void StoryModeLobbyScreen::tearDown() /** Called when a user is selected. It updates the online checkbox and * entrye fields. */ -void StoryModeLobbyScreen::selectUser(int index) +void UserScreen::selectUser(int index) { PlayerProfile *profile = PlayerManager::get()->getPlayer(index); assert(profile); @@ -153,7 +153,7 @@ void StoryModeLobbyScreen::selectUser(int index) * \param online Online state, which dicates if the entry fields are * visible (true) or not. */ -void StoryModeLobbyScreen::makeEntryFieldsVisible(bool online) +void UserScreen::makeEntryFieldsVisible(bool online) { getWidget("label_username")->setVisible(online); m_username_tb->setVisible(online); @@ -164,7 +164,7 @@ void StoryModeLobbyScreen::makeEntryFieldsVisible(bool online) // ---------------------------------------------------------------------------- /** Called when the user selects anything on the screen. */ -void StoryModeLobbyScreen::eventCallback(Widget* widget, +void UserScreen::eventCallback(Widget* widget, const std::string& name, const int player_id) { @@ -237,7 +237,7 @@ void StoryModeLobbyScreen::eventCallback(Widget* widget, * \param remember_me True if the login details should be remembered, * so that next time this menu can be skipped. */ -void StoryModeLobbyScreen::login(bool remember_me) +void UserScreen::login(bool remember_me) { m_options_widget->setDeactivated(); @@ -292,7 +292,7 @@ void StoryModeLobbyScreen::login(bool remember_me) /** Called once every frame. It will replace this screen with the main menu * screen if a successful login happened. */ -void StoryModeLobbyScreen::onUpdate(float dt) +void UserScreen::onUpdate(float dt) { if (!m_options_widget->isActivated()) m_info_widget->setText(Online::Messages::loadingDots( _("Signing in")), @@ -313,7 +313,7 @@ void StoryModeLobbyScreen::onUpdate(float dt) // ---------------------------------------------------------------------------- /** Callback from player profile if login was successful. */ -void StoryModeLobbyScreen::loginSuccessful() +void UserScreen::loginSuccessful() { // The callback is done from the main thread, so no need to sync // access to m_success @@ -324,7 +324,7 @@ void StoryModeLobbyScreen::loginSuccessful() /** Callback from player profile if login was unsuccessful. * \param error_message Contains the error message. */ -void StoryModeLobbyScreen::loginError(const irr::core::stringw & error_message) +void UserScreen::loginError(const irr::core::stringw & error_message) { sfx_manager->quickSound("anvil"); m_info_widget->setErrorColor(); @@ -333,7 +333,7 @@ void StoryModeLobbyScreen::loginError(const irr::core::stringw & error_message) } // loginError // ---------------------------------------------------------------------------- -void StoryModeLobbyScreen::unloaded() +void UserScreen::unloaded() { } // unloaded @@ -343,7 +343,7 @@ void StoryModeLobbyScreen::unloaded() * to open the next dialog, which is the one to create a new player (which * is conventient on a first start). */ -void StoryModeLobbyScreen::onDialogClose() +void UserScreen::onDialogClose() { // To allow players to exit the game without creating a player, we count // how often this function was called. The first time is after the @@ -367,7 +367,7 @@ void StoryModeLobbyScreen::onDialogClose() // ---------------------------------------------------------------------------- /** This is a callback from the new user dialog. */ -void StoryModeLobbyScreen::onNewPlayerWithName(const core::stringw& new_name) +void UserScreen::onNewPlayerWithName(const core::stringw& new_name) { init(); // Select the newly added player diff --git a/src/states_screens/story_mode_lobby.hpp b/src/states_screens/user_screen.hpp similarity index 88% rename from src/states_screens/story_mode_lobby.hpp rename to src/states_screens/user_screen.hpp index d39853312..c286e7747 100644 --- a/src/states_screens/story_mode_lobby.hpp +++ b/src/states_screens/user_screen.hpp @@ -16,8 +16,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef __HEADER_STORY_MODE_LOBBY_HPP__ -#define __HEADER_STORY_MODE_LOBBY_HPP__ +#ifndef __HEADER_USER_SCREEN_HPP__ +#define __HEADER_USER_SCREEN_HPP__ #include @@ -37,11 +37,11 @@ namespace GUIEngine * \brief Audio options screen * \ingroup states_screens */ -class StoryModeLobbyScreen : public GUIEngine::Screen, - public EnterPlayerNameDialog::INewPlayerListener, - public GUIEngine::ScreenSingleton +class UserScreen : public GUIEngine::Screen, + public EnterPlayerNameDialog::INewPlayerListener, + public GUIEngine::ScreenSingleton { - StoryModeLobbyScreen(); + UserScreen(); private: @@ -78,7 +78,7 @@ private: virtual void onUpdate(float dt) OVERRIDE; public: - friend class GUIEngine::ScreenSingleton; + friend class GUIEngine::ScreenSingleton; /** \brief implement callback from parent class GUIEngine::Screen */ virtual void loadedFromFile(); @@ -104,6 +104,6 @@ public: /** True if this window is a popup window (i.e. it should not exit even if * the current player exists. */ void setIsPopup(bool popup) { m_is_popup_window = popup; } -}; // class StoryModeLobby +}; // class UserScreen #endif From bef811e0988f051add6a518edc1e0cdcbba879aa Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 6 May 2014 08:21:53 +1000 Subject: [PATCH 020/365] Fixed login problems (e.g. only online log in worked), improved handling of error message, removed need for m_login_successful. --- src/states_screens/user_screen.cpp | 53 +++++++++++++++++++----------- src/states_screens/user_screen.hpp | 5 +-- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index da02e0e47..29d50f261 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -54,7 +54,6 @@ void UserScreen::loadedFromFile() void UserScreen::init() { - m_login_successful = false; m_online_cb = getWidget("online"); assert(m_online_cb); m_username_tb = getWidget("username"); @@ -73,6 +72,12 @@ void UserScreen::init() RibbonWidget* tabs = getWidget("login_tabs"); if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER ); + // It should always be activated ... but just in case + m_options_widget->setActivated(); + // Clean any error message still shown + m_info_widget->setText("", true); + m_info_widget->setErrorColor(); + Screen::init(); PlayerProfile *player = PlayerManager::getCurrentPlayer(); if (player && !m_is_popup_window) @@ -231,6 +236,15 @@ void UserScreen::eventCallback(Widget* widget, } // eventCallback +// ---------------------------------------------------------------------------- +/** Closes the UserScreen, and makes sure that the right screen is displayed + * next. + */ +void UserScreen::closeScreen() +{ + StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); +} // closeScreen + // ---------------------------------------------------------------------------- /** Called when OK or OK-and-save is clicked. * This will trigger the actual login (if requested) etc. @@ -239,6 +253,8 @@ void UserScreen::eventCallback(Widget* widget, */ void UserScreen::login(bool remember_me) { + // If an error occurs, the callback informing this screen about the + // problem will activate the widget again. m_options_widget->setDeactivated(); const std::string &s_id = m_players->getSelectionIDString(0); @@ -258,16 +274,21 @@ void UserScreen::login(bool remember_me) // a failed logout request profile->requestSignOut(); } - m_login_successful = true; - // This will trigger replacing this screen with the main menu screen. - onUpdate(0.0f); + closeScreen(); return; } + // Player wants to be online, and is already online - nothing to do if(profile->isLoggedIn()) + { + closeScreen(); return; + } - // If the user is not already logged in, start a login request + // Now we need to start a login request to the server + // This implies that this screen will wait till the server responds, so + // that error messages ('invalid password') can be shown, and the user + // can decide what to do about them. if (profile->hasSavedSession()) { // Online login with saved token @@ -275,7 +296,7 @@ void UserScreen::login(bool remember_me) } else { - // Online login with password + // Online login with password --> we need a valid password if (m_password_tb->getText() == "") { m_info_widget->setText(_("You need to enter a password."), true); @@ -286,6 +307,7 @@ void UserScreen::login(bool remember_me) m_password_tb->getText(), remember_me); } // !hasSavedSession + } // login // ---------------------------------------------------------------------------- @@ -297,17 +319,6 @@ void UserScreen::onUpdate(float dt) if (!m_options_widget->isActivated()) m_info_widget->setText(Online::Messages::loadingDots( _("Signing in")), false); - - if(m_online_cb->getState() && m_login_successful) - { - StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); - return; - } - - - PlayerProfile *cp = PlayerManager::getCurrentPlayer(); - if (cp && cp->isLoggedIn()) - cp->requestSignOut(); } // onUpdate // ---------------------------------------------------------------------------- @@ -315,9 +326,13 @@ void UserScreen::onUpdate(float dt) */ void UserScreen::loginSuccessful() { + m_options_widget->setActivated(); + // Clean any error message still shown + m_info_widget->setText("", true); + m_info_widget->setErrorColor(); // The callback is done from the main thread, so no need to sync - // access to m_success - m_login_successful = true; + // access to m_success. OnUpdate will check this flag + closeScreen(); } // loginSuccessful // ---------------------------------------------------------------------------- diff --git a/src/states_screens/user_screen.hpp b/src/states_screens/user_screen.hpp index c286e7747..dd8116069 100644 --- a/src/states_screens/user_screen.hpp +++ b/src/states_screens/user_screen.hpp @@ -49,10 +49,6 @@ private: * immediately go to the main menu if a current player is defined. */ bool m_is_popup_window; - /** Set in the callback from the login request to indicate that this - * window can be closed. */ - bool m_login_successful; - /** Online check box. */ GUIEngine::CheckBoxWidget *m_online_cb; @@ -74,6 +70,7 @@ private: void selectUser(int index); void makeEntryFieldsVisible(bool online); void login(bool remember_me); + void closeScreen(); virtual void onDialogClose(); virtual void onUpdate(float dt) OVERRIDE; From bb18d65ccd14f8687a7c78759bca1070e408d614 Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 6 May 2014 11:39:55 +1000 Subject: [PATCH 021/365] Select the current player by default. --- src/states_screens/user_screen.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index 29d50f261..b66876a47 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -87,21 +87,32 @@ void UserScreen::init() } m_players->clearItems(); + std::string current_player_index=""; + for (unsigned int n=0; ngetNumPlayers(); n++) { const PlayerProfile *player = PlayerManager::get()->getPlayer(n); if (player->isGuestAccount()) continue; std::string s = StringUtils::toString(n); m_players->addItem(player->getName(), s, "/karts/nolok/nolokicon.png", 0, - IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + IconButtonWidget::ICON_PATH_TYPE_RELATIVE); + if(player==PlayerManager::getCurrentPlayer()) + current_player_index = s; } m_players->updateItemDisplay(); - // Select the first user (the list of users is sorted by usage, so it - // is the most frequently used user). - if (PlayerManager::get()->getNumPlayers()>0) - selectUser(0); + // Select the current player. That can only be done after + // updateItemDisplay is called. + if(current_player_index.size()>0) + m_players->setSelection(current_player_index, PLAYER_ID_GAME_MASTER, + /*focus*/ true); + else // no current player found + { + // The first player is the most frequently used, so select it + if (PlayerManager::get()->getNumPlayers() > 0) + selectUser(0); + } } // init From 737c8a9983d680810bcfacd1f4eb9de49a06306c Mon Sep 17 00:00:00 2001 From: hiker Date: Tue, 6 May 2014 16:52:36 +1000 Subject: [PATCH 022/365] Added 'delete player' functionality. --- data/gui/user_screen.stkgui | 4 ++ src/states_screens/user_screen.cpp | 61 ++++++++++++++++++++++++++++-- src/states_screens/user_screen.hpp | 5 +++ 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/data/gui/user_screen.stkgui b/data/gui/user_screen.stkgui index 4cd43f4b2..049369ceb 100644 --- a/data/gui/user_screen.stkgui +++ b/data/gui/user_screen.stkgui @@ -52,6 +52,10 @@ I18N="Login dialog" text="OK" label_location="bottom"/> + + diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index b66876a47..de5b56dda 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -27,6 +27,7 @@ #include "guiengine/widgets/list_widget.hpp" #include "online/messages.hpp" #include "states_screens/dialogs/enter_player_name_dialog.hpp" +#include "states_screens/dialogs/message_dialog.hpp" #include "states_screens/main_menu_screen.hpp" #include "states_screens/register_screen.hpp" #include "states_screens/state_manager.hpp" @@ -116,6 +117,16 @@ void UserScreen::init() } // init +// ---------------------------------------------------------------------------- +PlayerProfile* UserScreen::getSelectedPlayer() +{ + const std::string &s_id = m_players + ->getSelectionIDString(PLAYER_ID_GAME_MASTER); + unsigned int n_id; + StringUtils::fromString(s_id, n_id); + return PlayerManager::get()->getPlayer(n_id); +} // getSelectedPlayer + // ---------------------------------------------------------------------------- void UserScreen::tearDown() @@ -241,6 +252,13 @@ void UserScreen::eventCallback(Widget* widget, cp->requestSignOut(); StateManager::get()->popMenu(); } + else if (button == "rename") + { + } + else if (button == "delete") + { + deletePlayer(); + } } // options return; @@ -268,10 +286,7 @@ void UserScreen::login(bool remember_me) // problem will activate the widget again. m_options_widget->setDeactivated(); - const std::string &s_id = m_players->getSelectionIDString(0); - unsigned int n_id; - StringUtils::fromString(s_id, n_id); - PlayerProfile *profile = PlayerManager::get()->getPlayer(n_id); + PlayerProfile *profile = getSelectedPlayer(); PlayerManager::get()->setCurrentPlayer(profile, remember_me); assert(profile); @@ -358,11 +373,49 @@ void UserScreen::loginError(const irr::core::stringw & error_message) m_options_widget->setActivated(); } // loginError +// ---------------------------------------------------------------------------- +/** Called when a player will be deleted. + */ +void UserScreen::deletePlayer() +{ + PlayerProfile *player = getSelectedPlayer(); + irr::core::stringw message = + //I18N: In the player info dialog (when deleting) + _("Do you really want to delete player '%s' ?", player->getName()); + + class ConfirmServer : public MessageDialog::IConfirmDialogListener + { + public: + virtual void onConfirm() + { + UserScreen::getInstance()->doDeletePlayer(); + } // onConfirm + }; // ConfirmServer + + + new MessageDialog(message, MessageDialog::MESSAGE_DIALOG_CONFIRM, + new ConfirmServer(), true); +} // deletePlayer + +// ---------------------------------------------------------------------------- +/** Callback when the user confirms to delete a player. This function actually + * deletes the player, discards the dialog, and re-initialised the UserScreen + * to display only the available players. + */ +void UserScreen::doDeletePlayer() +{ + PlayerProfile *player = getSelectedPlayer(); + PlayerManager::get()->deletePlayer(player); + GUIEngine::ModalDialog::dismiss(); + init(); +} // doDeletePlayer + // ---------------------------------------------------------------------------- void UserScreen::unloaded() { } // unloaded + // ---------------------------------------------------------------------------- /** Gets called when a dialog closes. At a first time start of STK the * internet dialog is shown first. Only when this dialog closes is it possible diff --git a/src/states_screens/user_screen.hpp b/src/states_screens/user_screen.hpp index dd8116069..1631df179 100644 --- a/src/states_screens/user_screen.hpp +++ b/src/states_screens/user_screen.hpp @@ -32,6 +32,8 @@ namespace GUIEngine class Widget; } +class PlayerProfile; + /** * \brief Audio options screen @@ -71,6 +73,9 @@ private: void makeEntryFieldsVisible(bool online); void login(bool remember_me); void closeScreen(); + void deletePlayer(); + void doDeletePlayer(); + PlayerProfile* getSelectedPlayer(); virtual void onDialogClose(); virtual void onUpdate(float dt) OVERRIDE; From a22b407568fbe6557260661d60df9b72a241ae1c Mon Sep 17 00:00:00 2001 From: konstin Date: Tue, 6 May 2014 19:46:20 +0200 Subject: [PATCH 023/365] removing git blame output file in src --- src/states_screens/xx | 212 ------------------------------------------ 1 file changed, 212 deletions(-) delete mode 100644 src/states_screens/xx diff --git a/src/states_screens/xx b/src/states_screens/xx deleted file mode 100644 index bb522ef9e..000000000 --- a/src/states_screens/xx +++ /dev/null @@ -1,212 +0,0 @@ -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 1) // SuperTuxKart - a fun racing game with go-kart -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 2) // Copyright (C) 2013 Glenn De Jonghe -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 3) // -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 4) // This program is free software; you can redistribute it and/or -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 5) // modify it under the terms of the GNU General Public License -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 6) // as published by the Free Software Foundation; either version 3 -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 7) // of the License, or (at your option) any later version. -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 8) // -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 9) // This program is distributed in the hope that it will be useful, -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 10) // but WITHOUT ANY WARRANTY; without even the implied warranty of -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 11) // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 12) // GNU General Public License for more details. -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 13) // -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 14) // You should have received a copy of the GNU General Public License -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 15) // along with this program; if not, write to the Free Software -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 16) // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 17) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 18) #include "states_screens/dialogs/recovery_dialog.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 19) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 20) #include "audio/sfx_manager.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 21) #include "guiengine/engine.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 22) #include "states_screens/state_manager.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 23) #include "utils/translation.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 24) #include "utils/string_utils.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 25) #include "online/messages.hpp" -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 26) -4d6b110e (hiker 2014-02-26 12:52:16 +1100 27) #include -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 28) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 29) using namespace GUIEngine; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 30) using namespace irr; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 31) using namespace irr::gui; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 32) using namespace Online; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 33) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 34) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 35) /** Constructor for the recovery dialog. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 36) */ -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 37) RecoveryDialog::RecoveryDialog() : ModalDialog(0.8f,0.8f) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 38) { -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 39) m_recovery_request = NULL; -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 40) m_self_destroy = false; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 41) m_show_recovery_input = true; -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 42) m_show_recovery_info = false; -8e8f02a1 (hiker 2014-04-06 01:27:04 +1100 43) doInit(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 44) showRecoveryInput(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 45) } // RecoveryDialog -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 46) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 47) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 48) /** Destructor, destroys the recovery request. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 49) */ -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 50) RecoveryDialog::~RecoveryDialog() -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 51) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 52) delete m_recovery_request; -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 53) } //~RecoverDialog -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 54) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 55) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 56) /** Shows the input screen to get the account name and email address. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 57) */ -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 58) void RecoveryDialog::showRecoveryInput() -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 59) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 60) m_show_recovery_input = false; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 61) clearWindow(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 62) m_phase = Input; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 63) loadFromFile("online/recovery_input.stkgui"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 64) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 65) m_username_widget = getWidget("username"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 66) assert(m_username_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 67) m_username_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 68) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 69) m_email_widget = getWidget("email"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 70) assert(m_email_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 71) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 72) m_info_widget = getWidget("info"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 73) assert(m_info_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 74) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 75) m_options_widget = getWidget("options"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 76) assert(m_options_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 77) m_submit_widget = getWidget("submit"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 78) assert(m_submit_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 79) m_cancel_widget = getWidget("cancel"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 80) assert(m_cancel_widget != NULL); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 81) } // showRecoveryInput -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 82) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 83) // ----------------------------------------------------------------------------- -7cc83e14 (konstin 2014-03-29 11:33:43 +0100 84) /** Informs the user that an email will be sent. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 85) */ -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 86) void RecoveryDialog::showRecoveryInfo() -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 87) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 88) m_show_recovery_info = false; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 89) clearWindow(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 90) m_phase = Info; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 91) loadFromFile("online/recovery_info.stkgui"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 92) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 93) m_info_widget = getWidget("info"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 94) assert(m_info_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 95) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 96) m_options_widget = getWidget("options"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 97) assert(m_options_widget != NULL); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 98) m_cancel_widget = getWidget("cancel"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 99) assert(m_cancel_widget != NULL); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 100) } // showRecoveryInfo -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 101) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 102) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 103) /** Let esc act as cancel. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 104) */ -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 105) bool RecoveryDialog::onEscapePressed() -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 106) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 107) return m_cancel_widget->isActivated(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 108) } // onEscapePressed -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 109) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 110) // ----------------------------------------------------------------------------- -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 111) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 112) void RecoveryDialog::processInput() -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 113) { -4d6b110e (hiker 2014-02-26 12:52:16 +1100 114) const core::stringw username = m_username_widget->getText().trim(); -4d6b110e (hiker 2014-02-26 12:52:16 +1100 115) const core::stringw email = m_email_widget->getText().trim(); -7cc83e14 (konstin 2014-03-29 11:33:43 +0100 116) if (username.size() < 4 || username.size() > 30 || -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 117) email.size() < 4 || email.size() > 50 ) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 118) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 119) sfx_manager->quickSound("anvil"); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 120) m_info_widget->setErrorColor(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 121) m_info_widget->setText(_("Username and/or email address invalid."), -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 122) false); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 123) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 124) else -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 125) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 126) m_info_widget->setDefaultColor(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 127) m_options_widget->setDeactivated(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 128) m_recovery_request = new XMLRequest(); -cb959acb (hiker 2014-04-07 08:25:48 +1000 129) // This function also works when the current user is not logged in -cb959acb (hiker 2014-04-07 08:25:48 +1000 130) CurrentUser::setUserDetails(m_recovery_request, "recovery"); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 131) m_recovery_request->addParameter("username", username); -cb959acb (hiker 2014-04-07 08:25:48 +1000 132) m_recovery_request->addParameter("email", email ); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 133) m_recovery_request->queue(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 134) } -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 135) } // processInput -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 136) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 137) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 138) /** Handle a user event. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 139) */ -7cc83e14 (konstin 2014-03-29 11:33:43 +0100 140) GUIEngine::EventPropagation -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 141) RecoveryDialog::processEvent(const std::string& eventSource) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 142) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 143) std::string selection; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 144) if (eventSource == m_options_widget->m_properties[PROP_ID]) -7cc83e14 (konstin 2014-03-29 11:33:43 +0100 145) selection = -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 146) m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 147) else -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 148) selection = eventSource; -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 149) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 150) if (selection == m_cancel_widget->m_properties[PROP_ID]) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 151) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 152) m_self_destroy = true; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 153) return GUIEngine::EVENT_BLOCK; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 154) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 155) else if (selection == m_submit_widget->m_properties[PROP_ID]) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 156) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 157) processInput(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 158) return GUIEngine::EVENT_BLOCK; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 159) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 160) return GUIEngine::EVENT_LET; -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 161) } // processEvent -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 162) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 163) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 164) /** Called when the user pressed enter. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 165) */ -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 166) void RecoveryDialog::onEnterPressedInternal() -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 167) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 168) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 169) if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER)) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 170) return; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 171) if (m_submit_widget->isActivated()) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 172) processInput(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 173) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 174) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 175) // ----------------------------------------------------------------------------- -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 176) /** This is called every frame and checks if an outstanding recovery request -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 177) * was finished. If so, it displays the results. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 178) * \param dt Time step size. -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 179) */ -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 180) void RecoveryDialog::onUpdate(float dt) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 181) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 182) if(m_recovery_request != NULL) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 183) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 184) if(m_recovery_request->isDone()) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 185) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 186) if(m_recovery_request->isSuccess()) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 187) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 188) m_show_recovery_info = true; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 189) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 190) else -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 191) { -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 192) sfx_manager->quickSound( "anvil" ); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 193) m_info_widget->setErrorColor(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 194) m_info_widget->setText(m_recovery_request->getInfo(), false); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 195) m_options_widget->setActivated(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 196) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 197) delete m_recovery_request; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 198) m_recovery_request = NULL; -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 199) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 200) else -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 201) { -99e7b565 (unitraxx 2013-09-14 01:07:22 +0000 202) m_info_widget->setText(Messages::validatingInfo(), false); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 203) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 204) } -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 205) // It's unsafe to delete from inside the event handler so we do it here -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 206) if (m_self_destroy) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 207) ModalDialog::dismiss(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 208) else if (m_show_recovery_input) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 209) showRecoveryInput(); -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 210) else if (m_show_recovery_info) -4091c4c9 (unitraxx 2013-07-27 20:55:10 +0000 211) showRecoveryInfo(); -6afc12c8 (hiker 2014-03-14 16:44:58 +1100 212) } // onUpdates From 0be01a5977667d19b40743df5f0badb35caf6bbf Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 7 May 2014 08:00:03 +1000 Subject: [PATCH 024/365] Added rename functionality. --- .../dialogs/enter_player_name_dialog.cpp | 24 ++++++++++++++----- .../dialogs/enter_player_name_dialog.hpp | 14 +++++++---- src/states_screens/user_screen.cpp | 5 +++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/states_screens/dialogs/enter_player_name_dialog.cpp b/src/states_screens/dialogs/enter_player_name_dialog.cpp index c70fa1c49..6215934fb 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.cpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.cpp @@ -39,7 +39,8 @@ using namespace irr::gui; // ----------------------------------------------------------------------------- EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener, - const float w, const float h) : + const float w, const float h, + const core::stringw &name): ModalDialog(w, h) { m_listener = listener; @@ -48,9 +49,14 @@ EnterPlayerNameDialog::EnterPlayerNameDialog(INewPlayerListener* listener, TextBoxWidget* text_field = getWidget("textfield"); assert(text_field != NULL); + text_field->setText(name); text_field->setFocusForPlayer(PLAYER_ID_GAME_MASTER); + if(name!=L"") + m_original_player = PlayerManager::get()->getPlayer(name); + else + m_original_player = NULL; - std::string username = ""; + core::stringw username = name; // If there is no player (i.e. first start of STK), try to pick // a good default name @@ -120,10 +126,16 @@ void EnterPlayerNameDialog::onEnterPressedInternal() } } - // Finally, add the new player. - PlayerManager::get()->addNewPlayer(player_name); - PlayerManager::get()->save(); - + if(m_original_player) + { + m_original_player->setName(player_name); + } + else + { + // Finally, add the new player. + PlayerManager::get()->addNewPlayer(player_name); + PlayerManager::get()->save(); + } // It's unsafe to delete from inside the event handler so we do it // in onUpdate (which checks for m_self_destroy) m_self_destroy = true; diff --git a/src/states_screens/dialogs/enter_player_name_dialog.hpp b/src/states_screens/dialogs/enter_player_name_dialog.hpp index deb811a0d..bb6623e43 100644 --- a/src/states_screens/dialogs/enter_player_name_dialog.hpp +++ b/src/states_screens/dialogs/enter_player_name_dialog.hpp @@ -31,11 +31,13 @@ namespace GUIEngine class LabelWidget; } -/** - * \brief Dialog that allows the player to enter the name for a new player +class PlayerProfile; + +/** Dialog that allows the player to enter the name for a new player or + * rename an existing player. * \ingroup states_screens */ -class EnterPlayerNameDialog : public GUIEngine::ModalDialog//, public GUIEngine::ITextBoxWidgetListener +class EnterPlayerNameDialog : public GUIEngine::ModalDialog { public: @@ -51,6 +53,10 @@ private: INewPlayerListener* m_listener; bool m_self_destroy; + + /** Pointer to the original PlayerProfile if it's a rename, or NULL if it + * is a new player. */ + PlayerProfile *m_original_player; public: @@ -58,7 +64,7 @@ public: * Creates a modal dialog with given percentage of screen width and height */ EnterPlayerNameDialog(INewPlayerListener* listener, const float percentWidth, - const float percentHeight); + const float percentHeight, const core::stringw &name=""); ~EnterPlayerNameDialog(); void onEnterPressedInternal(); diff --git a/src/states_screens/user_screen.cpp b/src/states_screens/user_screen.cpp index de5b56dda..ef72d9f47 100644 --- a/src/states_screens/user_screen.cpp +++ b/src/states_screens/user_screen.cpp @@ -254,6 +254,10 @@ void UserScreen::eventCallback(Widget* widget, } else if (button == "rename") { + PlayerProfile *cp = getSelectedPlayer(); + new EnterPlayerNameDialog(this, 0.5f, 0.4f, cp->getName()); + // Init will automatically be called, which + // refreshes the player list } else if (button == "delete") { @@ -392,7 +396,6 @@ void UserScreen::deletePlayer() } // onConfirm }; // ConfirmServer - new MessageDialog(message, MessageDialog::MESSAGE_DIALOG_CONFIRM, new ConfirmServer(), true); } // deletePlayer From 83c29b0778d83b5869b55d455a993532e4d7aafc Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 7 May 2014 16:39:09 +1000 Subject: [PATCH 025/365] Instead of individual 'remember-me' settings, use one global setting. --- data/gui/options_ui.stkgui | 6 ++++++ data/gui/user_screen.stkgui | 4 ---- src/config/user_config.hpp | 5 +++++ src/states_screens/options_screen_ui.cpp | 10 ++++++++++ src/states_screens/user_screen.cpp | 2 +- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/data/gui/options_ui.stkgui b/data/gui/options_ui.stkgui index ce5fca0e1..592c4c283 100644 --- a/data/gui/options_ui.stkgui +++ b/data/gui/options_ui.stkgui @@ -39,6 +39,12 @@
+
+ + +
+ diff --git a/data/gui/user_screen.stkgui b/data/gui/user_screen.stkgui index 049369ceb..be49d70b6 100644 --- a/data/gui/user_screen.stkgui +++ b/data/gui/user_screen.stkgui @@ -22,10 +22,6 @@