- 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
// ----------------------------------------------------------------------------