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.
This commit is contained in:
hiker 2014-05-05 20:46:48 +10:00
parent 00cf9a3dbe
commit 6010831654
9 changed files with 56 additions and 442 deletions

View File

@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-16"?>
<stkgui>
<div x="1%" y="1%" width="98%" height="98%" layout="vertical-row" >
<header align="center" width="80%" text="Login" text_align="center"/>
<spacer height="15" width="10"/>
<tabs id="login_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="tab_guest_login" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Sign In As Guest"/>
<icon-button id="tab_register" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Register"/>
</tabs>
<box proportion="1" width="100%" layout="vertical-row">
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
I18N="In the create login screen" text="Sign in"/>
<spacer height="20" width="20"/>
<div width="80%" align="center" layout="vertical-row" height="fit" >
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left" I18N="In the crete login screen" text="Username"/>
<textbox proportion="2" height="fit" id="username" I18N="In the create login screen"/>
</div>
<spacer height="20" width="20"/>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left" I18N="In the create login screen" text="Password"/>
<textbox x="5" proportion="2" height="fit" id="password" I18N="In the create login screen"/>
</div>
<spacer height="20" width="20"/>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the create login screen" text="Stay signed in"/>
<div proportion="2" height="100%" layout="horizontal-row">
<checkbox width="fit" height="fit" id="remember" I18N="In the create login screen"/>
</div>
</div>
</div>
<label id="info" proportion="1" width="90%" align="center" text_align="center"
word_wrap="true" text=""/>
<spacer height="20" width="20"/>
<buttonbar id="options" width="90%" height="13%" align="bottom">
<icon-button id="sign_in" width="64" height="64" icon="gui/green_check.png"
I18N="Create login screen" text="Sign In" label_location="bottom"/>
<icon-button id="recovery" width="64" height="64" icon="gui/main_help.png"
I18N="Create login screen" text="Recovery" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Create login screen" text="Close" label_location="bottom"/>
</buttonbar>
<spacer height="20" width="20"/>
</box>
</div>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
</stkgui>

View File

@ -9,8 +9,6 @@
<tabs id="login_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="tab_guest_login" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Sign In As Guest"/>
<icon-button id="tab_register" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Register"/>
</tabs>

View File

@ -1,9 +1,16 @@
<stkgui>
<div x="1%" y="1%" width="98%" height="98%" layout="vertical-row" >
<div x="2%" y="2%" width="96%" height="97%" layout="vertical-row" >
<header align="center" width="80%" text="Login" text_align="center"/>
<spacer height="15" width="10"/>
<header text_align="center" width="80%" align="center" text="Select a Local Player"/>
<tabs id="login_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="tab_register" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Register"/>
</tabs>
<spacer height="15" width="10"/>
<scrollable_ribbon id="players" height="120" y="10" x="10" width="98%" align="center" label_location="each"
@ -15,6 +22,14 @@
<label proportion="1" height="100%" text_align="left" I18N="In the login screen" text="Online"/>
<checkbox id="online" I18N="In the login screen" text_align="left"/>
</div>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left" I18N="In the login screen" text="Remember me"/>
<checkbox id="remember_me" I18N="In the login screen" text_align="left"/>
</div>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left" I18N="In the login screen" text="Guest login"/>
<checkbox id="guest_login" I18N="In the login screen" text_align="left"/>
</div>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" id="label_username" text_align="left"
I18N="In the login screen" text="Username"/>
@ -28,15 +43,13 @@
<textbox proportion="2" height="fit" id="password" I18N="In the registration dialog"/>
</div>
</div>
<div width="80%" align="center" layout="vertical-row" height="20%">
<div width="80%" align="center" layout="vertical-row" height="fit">
<label id="message" width="80%" align="center" text_align="left"/>
</div>
<spacer width="20" height="25"/>
<buttonbar id="options" width="90%" height="13%" align="bottom">
<icon-button id="ok" width="64" height="64" icon="gui/green_check.png"
I18N="Login dialog" text="OK" label_location="bottom"/>
<icon-button id="ok_and_save" width="64" height="64" icon="gui/main_help.png"
I18N="Login dialog" text="OK and Save" label_location="bottom"/>
<icon-button id="new_user" width="64" height="64" icon="gui/main_help.png"
I18N="Login dialog" text="Create new user" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_help.png"

View File

@ -1,78 +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/guest_login_screen.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "states_screens/login_screen.hpp"
#include "states_screens/register_screen.hpp"
#include "states_screens/state_manager.hpp"
using namespace GUIEngine;
DEFINE_SCREEN_SINGLETON( GuestLoginScreen );
// -----------------------------------------------------------------------------
GuestLoginScreen::GuestLoginScreen() : Screen("online/guest_login.stkgui")
{
} // GuestLoginScreen
// -----------------------------------------------------------------------------
/** Make sure this tab is actually selected.
*/
void GuestLoginScreen::init()
{
Screen::init();
RibbonWidget* tabs = this->getWidget<RibbonWidget>("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<RibbonWidget>("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
// -----------------------------------------------------------------------------

View File

@ -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<GuestLoginScreen>
{
friend class GUIEngine::ScreenSingleton<GuestLoginScreen>;
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

View File

@ -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 <irrString.h>
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<RibbonWidget>("login_tabs");
if (tabs) tabs->select( "tab_login", PLAYER_ID_GAME_MASTER );
TextBoxWidget *password_widget = getWidget<TextBoxWidget>("password");
password_widget->setPasswordBox(true,L'*');
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget);
m_options_widget->setActivated();
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_success = false;
// As default don't select 'remember'
getWidget<CheckBoxWidget>("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<LabelWidget>("info");
info_widget->setDefaultColor();
info_widget->setText("", false);
const core::stringw username = getWidget<TextBoxWidget>("username")
->getText().trim();
const core::stringw password = getWidget<TextBoxWidget>("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<CheckBoxWidget>("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<RibbonWidget>("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
// -----------------------------------------------------------------------------

View File

@ -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<LoginScreen>
{
private:
friend class GUIEngine::ScreenSingleton<LoginScreen>;
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

View File

@ -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")
{

View File

@ -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<LabelWidget>("message");
assert(m_info_widget);
// Make sure this tab is actually focused.
RibbonWidget* tabs = getWidget<RibbonWidget>("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<CheckBoxWidget>("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
// ----------------------------------------------------------------------------