From f99f27cbf1bd484cd9e5a749ecdecad2049ecd1e Mon Sep 17 00:00:00 2001 From: unitraxx Date: Fri, 28 Jun 2013 01:33:15 +0000 Subject: [PATCH] [_GSoC Uni_] Signing out. Online screen (beta) improvements. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13001 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/online/main.stkgui | 52 +++++++++++----- src/online/current_online_user.cpp | 2 + src/online/current_online_user.hpp | 2 + src/states_screens/dialogs/login_dialog.cpp | 1 - .../dialogs/registration_dialog.cpp | 1 - src/states_screens/online_screen.cpp | 62 ++++++++++++------- src/states_screens/online_screen.hpp | 5 ++ 7 files changed, 85 insertions(+), 40 deletions(-) diff --git a/data/gui/online/main.stkgui b/data/gui/online/main.stkgui index e66a03990..27dfbf95f 100644 --- a/data/gui/online/main.stkgui +++ b/data/gui/online/main.stkgui @@ -1,31 +1,53 @@ - -
- -
+ +
diff --git a/src/online/current_online_user.cpp b/src/online/current_online_user.cpp index 3703456ee..0056a2718 100644 --- a/src/online/current_online_user.cpp +++ b/src/online/current_online_user.cpp @@ -46,6 +46,7 @@ void CurrentOnlineUser::deallocate() CurrentOnlineUser::CurrentOnlineUser(){ m_is_signed_in = false; + m_is_guest = true; m_id = 0; m_name = ""; m_token = ""; @@ -104,6 +105,7 @@ bool CurrentOnlineUser::signIn( const irr::core::stringw &username, assert(result->get("username", &m_name)); assert(result->get("userid", &m_id)); m_is_signed_in = true; + m_is_guest = false; } result->get("info", &info); } diff --git a/src/online/current_online_user.hpp b/src/online/current_online_user.hpp index bc5a2933a..987d77a9d 100644 --- a/src/online/current_online_user.hpp +++ b/src/online/current_online_user.hpp @@ -37,6 +37,7 @@ class CurrentOnlineUser : public OnlineUser protected: std::string m_token; bool m_is_signed_in; + bool m_is_guest; CurrentOnlineUser(); public: @@ -59,6 +60,7 @@ class CurrentOnlineUser : public OnlineUser /** Returns the username if signed in. */ irr::core::stringw getUserName() const; bool isSignedIn(){ return m_is_signed_in; } + bool isGuest(){ return m_is_guest; } }; // class CurrentOnlineUser diff --git a/src/states_screens/dialogs/login_dialog.cpp b/src/states_screens/dialogs/login_dialog.cpp index d0feb2d0c..1fccaeb9b 100644 --- a/src/states_screens/dialogs/login_dialog.cpp +++ b/src/states_screens/dialogs/login_dialog.cpp @@ -127,7 +127,6 @@ void LoginDialog::onUpdate(float dt) // It's unsafe to delete from inside the event handler so we do it here if (m_self_destroy) { - GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); ModalDialog::dismiss(); if (m_open_registration_dialog) new RegistrationDialog(0.8f, 0.9f); diff --git a/src/states_screens/dialogs/registration_dialog.cpp b/src/states_screens/dialogs/registration_dialog.cpp index a3941e952..edaf04a21 100644 --- a/src/states_screens/dialogs/registration_dialog.cpp +++ b/src/states_screens/dialogs/registration_dialog.cpp @@ -277,7 +277,6 @@ void RegistrationDialog::onUpdate(float dt) // It's unsafe to delete from inside the event handler so we do it here if (m_self_destroy) { - GUIEngine::getGUIEnv()->removeFocus( m_irrlicht_window ); ModalDialog::dismiss(); } if (m_show_registration_info) diff --git a/src/states_screens/online_screen.cpp b/src/states_screens/online_screen.cpp index 60964cca7..75530829b 100644 --- a/src/states_screens/online_screen.cpp +++ b/src/states_screens/online_screen.cpp @@ -27,8 +27,8 @@ #include "graphics/irr_driver.hpp" #include "guiengine/scalable_font.hpp" #include "guiengine/widgets/label_widget.hpp" -#include "guiengine/widgets/list_widget.hpp" #include "guiengine/widgets/ribbon_widget.hpp" +#include "guiengine/widgets/icon_button_widget.hpp" #include "input/device_manager.hpp" #include "input/input_manager.hpp" #include "io/file_manager.hpp" @@ -38,6 +38,7 @@ #include "modes/demo_world.hpp" #include "utils/translation.hpp" +#include "online/current_online_user.hpp" #include "states_screens/dialogs/login_dialog.hpp" using namespace GUIEngine; @@ -62,31 +63,37 @@ void OnlineScreen::loadedFromFile() void OnlineScreen::init() { Screen::init(); - - // Avoid incorrect behaviour in certain race circumstances: - // If a multi-player game is played with two keyboards, the 2nd - // player selects his kart last, and only the keyboard is used - // to select all other settings - then if the next time the kart - // selection screen comes up, the default device will still be - // the 2nd player. So if the first player presses 'select', it - // will instead add a second player (so basically the key - // binding for the second player become the default, so pressing - // select will add a new player). See bug 3090931 - // To avoid this, we will clean the last used device, making - // the key bindings for the first player the default again. - input_manager->getDeviceList()->clearLatestUsedDevice(); - RibbonWidget* r = getWidget("menu_toprow"); r->setFocusForPlayer(PLAYER_ID_GAME_MASTER); DemoWorld::resetIdleTime(); -#if _IRR_MATERIAL_MAX_TEXTURES_ < 8 - getWidget("logo")->setImage("gui/logo_broken.png", - IconButtonWidget::ICON_PATH_TYPE_RELATIVE); -#endif - } // init + +void OnlineScreen::beforeAddingWidget() +{ + RibbonWidget* topRow = getWidget("menu_toprow"); + assert(topRow != NULL); + RibbonWidget* bottomRow = getWidget("menu_bottomrow"); + assert(bottomRow != NULL); + if(CurrentOnlineUser::get()->isSignedIn()) + { + if(CurrentOnlineUser::get()->isGuest()) + { + + } + else + { + //Signed in and not guest + bottomRow->removeChildNamed("sign_in"); + } + } + else + { + bottomRow->removeChildNamed("sign_out"); + } +} + // ---------------------------------------------------------------------------- void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver) { @@ -106,13 +113,13 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const if (ribbon == NULL) return; // what's that event?? std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER); - if (selection == "signin") + if (selection == "sign_in") { new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!")); } - else if (selection == "signout") + else if (selection == "sign_out") { - new LoginDialog(0.6f, 0.6f, _("Not yet an account? Press register beneath!")); + CurrentOnlineUser::get()->signOut(); } } // eventCallback @@ -128,3 +135,12 @@ void OnlineScreen::tearDown() void OnlineScreen::onDisabledItemClicked(const std::string& item) { } // onDisabledItemClicked + +// ---------------------------------------------------------------------------- + +void OnlineScreen::reload() +{ + this->unload(); + if (!this->isLoaded()) this->loadFromFile(); + this->init(); +} diff --git a/src/states_screens/online_screen.hpp b/src/states_screens/online_screen.hpp index 549fa055a..329d2ba3f 100644 --- a/src/states_screens/online_screen.hpp +++ b/src/states_screens/online_screen.hpp @@ -35,6 +35,8 @@ private: public: + void reload(); + virtual void onUpdate(float delta, irr::video::IVideoDriver* driver) OVERRIDE; /** \brief implement callback from parent class GUIEngine::Screen */ @@ -44,6 +46,9 @@ public: virtual void eventCallback(GUIEngine::Widget* widget, const std::string& name, const int playerID) OVERRIDE; + /** \brief implement callback from parent class GUIEngine::Screen */ + virtual void beforeAddingWidget() OVERRIDE; + /** \brief implement callback from parent class GUIEngine::Screen */ virtual void init() OVERRIDE;