Reworked the login and register dialog to be a screen - still

work in progress (and guest login does not work yet).
This commit is contained in:
hiker 2014-01-20 21:39:59 +11:00
parent 0817ec4ee0
commit 260f4f148d
17 changed files with 847 additions and 367 deletions

View File

@ -0,0 +1,44 @@
<?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="category" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="guest_login" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Sign In As Guest"/>
<icon-button id="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 login dialog" text="Guest Sign in"/>
<spacer height="15" width="10"/>
<box proportion="4" width="90%" layout="vertical-row" align="center">
<div x="2%" y="2%" width="96%" height="80%" layout="vertical-row" id="outer_box" >
<label I18N="In the online multiplayer screen" proportion="4" word_wrap="true" text=
"Signing in as a guest allows you to participate in online races,
but it does not allow you to vote for addons,
or collect any achievements while being online."
align="center"/>
</div>
</box>
<spacer height="15" width="10"/>
<buttonbar id="options" width="90%" height="13%" align="bottom">
<icon-button id="sign_in" width="64" height="64" icon="gui/green_check.png"
I18N="Login dialog" text="Sign In" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Login dialog" text="Close" label_location="bottom"/>
</buttonbar>
<spacer height="15" width="10"/>
</box>
</div>
<icon-button id="back" x="0" y="0" height="15%" icon="gui/back.png"/>
</stkgui>

View File

@ -0,0 +1,58 @@
<?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="category" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="guest_login" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Sign In As Guest"/>
<icon-button id="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 login dialog" 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 login dialog" text="Username"/>
<textbox proportion="2" height="fit" id="username" I18N="In the login dialog"/>
</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 login dialog" text="Password"/>
<textbox x="5" proportion="2" height="fit" id="password" I18N="In the login dialog"/>
</div>
<spacer height="20" width="20"/>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the login dialog" text="Stay signed in"/>
<div proportion="2" height="100%" layout="horizontal-row">
<checkbox width="fit" height="fit" id="remember" I18N="In the login dialog"/>
</div>
</div>
</div>
<label id="info" proportion="1" width="90%" align="center" text_align="center"
word_wrap="true" text=""/>
<spacer height="40" 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="Login dialog" text="Sign In" label_location="bottom"/>
<icon-button id="recovery" width="64" height="64" icon="gui/main_help.png"
I18N="Login dialog" text="Recovery" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Login dialog" text="Close" label_location="bottom"/>
</buttonbar>
</box>
</div>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
</stkgui>

View File

@ -5,11 +5,11 @@
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
I18N="In the login dialog" text="Sign in"/>
<spacer height="25" width="50">
<spacer height="25" width="50"/>
<label id="message" proportion="2" width="90%" align="center" text_align="left" word_wrap="true" text=""/>
<spacer height="40" width="50">
<spacer height="40" width="50"/>
<div width="80%" align="center" layout="vertical-row" height="fit" >
<div width="100%" height="fit" layout="horizontal-row" >
@ -17,14 +17,14 @@
<textbox proportion="2" height="fit" id="username" I18N="In the login dialog"/>
</div>
<spacer height="20" width="20">
<spacer height="20" width="20"/>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left" I18N="In the login dialog" text="Password"/>
<textbox x="5" proportion="2" height="fit" id="password" I18N="In the login dialog"/>
</div>
<spacer height="20" width="20">
<spacer height="20" width="20"/>
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the login dialog" text="Stay signed in"/>
@ -34,11 +34,11 @@
</div>
</div>
<spacer height="20" width="50">
<spacer height="20" width="50"/>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
<spacer height="20" width="50">
<spacer height="20" width="50"/>
<buttonbar id="options" width="90%" height="13%" align="center">
<icon-button id="sign_in" width="64" height="64" icon="gui/green_check.png"

View File

@ -0,0 +1,78 @@
<?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="category" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="login" width="128" height="128" icon="gui/track_random.png"
I18N="Tab in login menu" text="Sign In"/>
<icon-button id="guest_login" width="128" height="128" icon="gui/mode_ftl.png"
I18N="Tab in login menu" text="Sign In As Guest"/>
<icon-button id="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 login dialog" text="Sign in"/>
<spacer height="40" 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 registration dialog" text="Username"/>
<textbox proportion="2" height="fit" id="username" I18N="In the registration dialog"/>
</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 registration dialog" text="Password"/>
<textbox proportion="2" height="fit" id="password" I18N="In the registration dialog"/>
</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 registration dialog" text="Confirm"/>
<textbox proportion="2" height="fit" id="password_confirm" I18N="In the registration dialog"/>
</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 registration dialog" text="Email"/>
<textbox proportion="2" height="fit" id="email" I18N="In the registration dialog"/>
</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 registration dialog" text="Confirm"/>
<textbox proportion="2" height="fit" id="email_confirm" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="50"/>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true"
I18N="In the registration dialog" text="You don't need to register if you have a STK Addons account!"/>
<spacer height="20" width="50"/>
</div>
<spacer height="20" width="50"/>
<buttonbar id="options" width="25%" height="14%" align="center">
<icon-button id="next" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Next" label_location="none"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Registration dialog" text="Cancel" label_location="none"/>
</buttonbar>
</box>
</div>
<icon-button id="back" x="0" y="0" height="8%" icon="gui/back.png"/>
</stkgui>

View File

@ -14,7 +14,6 @@
<div align="center" width="fit" height="fit" layout="horizontal-row" >
<label text_align="center" align="center" I18N="In the registration dialog" word_wrap="true"
text="I agree to the above terms and am 13 years or older. "/>
<checkbox id="accepted" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="50">
@ -25,12 +24,10 @@
<spacer height="20" width="50">
<buttonbar id="options" width="45%" height="14%" align="center">
<icon-button id="previous" width="64" height="64" icon="gui/back.png"
I18N="Registration dialog" text="Previous" label_location="bottom"/>
<icon-button id="next" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Submit" label_location="bottom"/>
<icon-button id="accept" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Accept" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Registration dialog" text="Cancel" label_location="bottom"/>
I18N="Registration dialog" text="Cancel" label_location="bottom"/>
</buttonbar>

View File

@ -243,11 +243,13 @@ src/states_screens/easter_egg_screen.cpp
src/states_screens/feature_unlocked.cpp
src/states_screens/grand_prix_lose.cpp
src/states_screens/grand_prix_win.cpp
src/states_screens/guest_login_screen.cpp
src/states_screens/help_screen_1.cpp
src/states_screens/help_screen_2.cpp
src/states_screens/help_screen_3.cpp
src/states_screens/help_screen_4.cpp
src/states_screens/kart_selection.cpp
src/states_screens/login_screen.cpp
src/states_screens/main_menu_screen.cpp
src/states_screens/network_kart_selection.cpp
src/states_screens/networking_lobby.cpp
@ -270,6 +272,7 @@ src/states_screens/race_gui_base.cpp
src/states_screens/race_gui_overworld.cpp
src/states_screens/race_result_gui.cpp
src/states_screens/race_setup_screen.cpp
src/states_screens/register_screen.cpp
src/states_screens/server_selection.cpp
src/states_screens/soccer_setup_screen.cpp
src/states_screens/state_manager.cpp
@ -572,11 +575,13 @@ src/states_screens/easter_egg_screen.hpp
src/states_screens/feature_unlocked.hpp
src/states_screens/grand_prix_lose.hpp
src/states_screens/grand_prix_win.hpp
src/states_screens/guest_login_screen.hpp
src/states_screens/help_screen_1.hpp
src/states_screens/help_screen_2.hpp
src/states_screens/help_screen_3.hpp
src/states_screens/help_screen_4.hpp
src/states_screens/kart_selection.hpp
src/states_screens/login_screen.hpp
src/states_screens/main_menu_screen.hpp
src/states_screens/network_kart_selection.hpp
src/states_screens/networking_lobby.hpp
@ -599,6 +604,7 @@ src/states_screens/race_gui_base.hpp
src/states_screens/race_gui_overworld.hpp
src/states_screens/race_result_gui.hpp
src/states_screens/race_setup_screen.hpp
src/states_screens/register_screen.hpp
src/states_screens/server_selection.hpp
src/states_screens/soccer_setup_screen.hpp
src/states_screens/state_manager.hpp

View File

@ -28,8 +28,9 @@
#include "utils/translation.hpp"
#include "addons/addon.hpp"
#include "guiengine/dialog_queue.hpp"
#include "guiengine/screen.hpp"
#include "states_screens/login_screen.hpp"
#include "states_screens/dialogs/change_password_dialog.hpp"
#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/dialogs/user_info_dialog.hpp"
#include "states_screens/dialogs/notification_dialog.hpp"
#include "states_screens/online_profile_friends.hpp"
@ -88,8 +89,7 @@ namespace Online
const XMLRequest * CurrentUser::requestSignUp(const core::stringw &username,
const core::stringw &password,
const core::stringw &password_confirm,
const core::stringw &email,
bool terms)
const core::stringw &email)
{
assert(m_state == US_SIGNED_OUT || m_state == US_GUEST);
XMLRequest * request = new XMLRequest();
@ -139,7 +139,7 @@ namespace Online
{
assert(m_state == US_SIGNED_OUT);
m_save_session = save_session;
SignInRequest * request = new SignInRequest(request_now);
SignInRequest * request = new SignInRequest(false);
request->setServerURL("client-user.php");
request->addParameter("action","connect");
request->addParameter("username",username);
@ -159,18 +159,15 @@ namespace Online
void CurrentUser::SignInRequest::callback()
{
CurrentUser::get()->signIn(isSuccess(), getXMLData());
if(GUIEngine::ModalDialog::isADialogActive())
GUIEngine::Screen *screen = GUIEngine::getCurrentScreen();
LoginScreen *login = dynamic_cast<LoginScreen*>(screen);
if(login)
{
LoginDialog * dialog =
dynamic_cast<LoginDialog*>(GUIEngine::ModalDialog::getCurrent());
if(dialog)
{
if(isSuccess())
dialog->success();
else
dialog->error(getInfo());
} // if dialog
} // isDialogActive
if(isSuccess())
login->loginSuccessful();
else
login->loginError(getInfo());
} // if dialog
} // SignInRequest::callback
// ------------------------------------------------------------------------
@ -841,7 +838,8 @@ namespace Online
} // getUserName
// ------------------------------------------------------------------------
/** \return the online id. */
/** \return the online id, or 0 if the user is not signed in.
*/
uint32_t CurrentUser::getID() const
{
if((m_state == US_SIGNED_IN ))

View File

@ -180,8 +180,7 @@ namespace Online
const XMLRequest * requestSignUp( const irr::core::stringw &username,
const irr::core::stringw &password,
const irr::core::stringw &password_ver,
const irr::core::stringw &email,
bool terms);
const irr::core::stringw &email);
const XMLRequest * requestRecovery(const irr::core::stringw &username,
const irr::core::stringw &email);

View File

@ -23,6 +23,7 @@
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/register_screen.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
@ -38,86 +39,7 @@ using namespace Online;
RegistrationDialog::RegistrationDialog() :
ModalDialog(0.8f,0.9f)
{
m_sign_up_request = NULL;
m_self_destroy = false;
m_show_registration_input = false;
m_show_registration_terms = false;
m_show_registration_info = false;
m_username = "";
m_email = "";
m_email_confirm = "";
m_password = "";
m_password_confirm = "";
m_agreement = false;
showRegistrationInput();
}
// -----------------------------------------------------------------------------
RegistrationDialog::~RegistrationDialog()
{
delete m_sign_up_request;
}
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationInput()
{
if(isInited())
clearWindow();
m_show_registration_input = false;
m_phase = Input;
loadFromFile("online/registration_input.stkgui");
//Password should always be reentered if previous has been clicked, or an error occurred.
m_password = "";
m_password_confirm = "";
m_username_widget = getWidget<TextBoxWidget>("username");
assert(m_username_widget != NULL);
m_username_widget->setText(m_username);
m_username_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_password_widget = getWidget<TextBoxWidget>("password");
assert(m_password_widget != NULL);
m_password_widget->setPasswordBox(true,L'*');
m_password_confirm_widget = getWidget<TextBoxWidget>("password_confirm");
assert(m_password_confirm_widget != NULL);
m_password_confirm_widget->setPasswordBox(true,L'*');
m_email_widget = getWidget<TextBoxWidget>("email");
assert(m_email_widget != NULL);
m_email_widget->setText(m_email);
m_email_confirm_widget = getWidget<TextBoxWidget>("email_confirm");
assert(m_email_confirm_widget != NULL);
m_email_confirm_widget->setText(m_email_confirm);
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_info_widget->setErrorColor();
m_info_widget->setText(m_registration_error, false);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_next_widget = getWidget<IconButtonWidget>("next");
assert(m_next_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationTerms()
{
m_show_registration_terms = false;
if(isInited())
clearWindow();
m_phase = Terms;
loadFromFile("online/registration_terms.stkgui");
ListWidget * terms_widget = getWidget<ListWidget>("terms");
@ -132,218 +54,35 @@ void RegistrationDialog::showRegistrationTerms()
"one of the members of the development team would gladly assist you."
, -1 , false );
m_accept_terms_widget = getWidget<CheckBoxWidget>("accepted");
assert(m_accept_terms_widget != NULL);
m_accept_terms_widget->setState(false);
m_accept_terms_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER); //FIXME set focus on the terms
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_previous_widget = getWidget<IconButtonWidget>("previous");
assert(m_previous_widget != NULL);
m_next_widget = getWidget<IconButtonWidget>("next");
assert(m_next_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
m_next_widget->setDeactivated();
// showRegistrationTerms();
}
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationInfo()
RegistrationDialog::~RegistrationDialog()
{
m_show_registration_info = false;
if(isInited())
clearWindow();
m_phase = Info;
loadFromFile("online/registration_info.stkgui");
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
void RegistrationDialog::processInput()
/** Process input events.
* \event_source name of the widget that triggered the event.
*/
EventPropagation RegistrationDialog::processEvent(const std::string& event_source)
{
m_username = m_username_widget->getText().trim();
m_password = m_password_widget->getText().trim();
m_password_confirm = m_password_confirm_widget->getText().trim();
m_email = m_email_widget->getText().trim();
m_email_confirm = m_email_confirm_widget->getText().trim();
//FIXME More validation of registration information
m_info_widget->setErrorColor();
if (m_password != m_password_confirm)
if (event_source == "options")
{
m_info_widget->setText(_("Passwords don't match!"), false);
}
else if (m_email != m_email_confirm)
{
m_info_widget->setText(_("Emails don't match!"), false);
}
else if (m_username.size() < 4 || m_username.size() > 30)
{
m_info_widget->setText(_("Username has to be between 4 and 30 characters long!"), false);
}
else if (m_password.size() < 8 || m_password.size() > 30)
{
m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
}
else if (m_email.size() < 4 || m_email.size() > 50)
{
m_info_widget->setText(_("Email has to be between 4 and 50 characters long!"), false);
}
else
{
m_show_registration_terms = true;
return;
}
sfx_manager->quickSound( "anvil" );
}
// -----------------------------------------------------------------------------
bool RegistrationDialog::processInputEvent(const std::string& eventSource)
{
if (m_phase == Input)
{
if (eventSource == m_next_widget->m_properties[PROP_ID])
RibbonWidget *rib = getWidget<RibbonWidget>("options");
std::string s = rib->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if(s=="accept")
{
processInput();
return true;
Screen *s = GUIEngine::getCurrentScreen();
RegisterScreen *r = dynamic_cast<RegisterScreen*>(s);
assert(r);
r->acceptTerms();
}
}
return false;
}
// -----------------------------------------------------------------------------
bool RegistrationDialog::processTermsEvent(const std::string& eventSource)
{
if (m_phase == Terms)
{
if (eventSource == m_next_widget->m_properties[PROP_ID])
{
assert(m_accept_terms_widget->getState());
m_options_widget->setDeactivated();
m_info_widget->setDefaultColor();
m_info_widget->setText(Messages::validatingInfo(), false);
m_sign_up_request = CurrentUser::get()->requestSignUp(m_username, m_password, m_password_confirm, m_email, true);
return true;
}
else if (eventSource == m_accept_terms_widget->m_properties[PROP_ID])
{
bool new_state = !m_accept_terms_widget->getState();
m_accept_terms_widget->setState(new_state);
if(new_state)
m_next_widget->setActivated();
else
m_next_widget->setDeactivated();
return true;
}
else if (eventSource == m_previous_widget->m_properties[PROP_ID])
{
m_show_registration_info = true;
return true;
}
}
return false;
}
// -----------------------------------------------------------------------------
bool RegistrationDialog::processInfoEvent(const std::string& eventSource)
{
return false;
}
// -----------------------------------------------------------------------------
bool RegistrationDialog::onEscapePressed()
{
return m_cancel_widget->isActivated();
}
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation RegistrationDialog::processEvent(const std::string& eventSource)
{
std::string selection;
if (eventSource == m_options_widget->m_properties[PROP_ID])
selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
else
selection = eventSource;
if (selection == m_cancel_widget->m_properties[PROP_ID])
{
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
else if (processInputEvent(selection) || processTermsEvent(selection) || processInfoEvent(selection))
{
return GUIEngine::EVENT_BLOCK;
}
return GUIEngine::EVENT_LET;
}
// -----------------------------------------------------------------------------
void RegistrationDialog::onEnterPressedInternal()
{
if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER))
return;
if (m_next_widget->isActivated())
processInput();
}
// -----------------------------------------------------------------------------
void RegistrationDialog::onUpdate(float dt)
{
if (m_phase == Terms)
{
if(m_sign_up_request != NULL)
{
if(m_sign_up_request->isDone())
{
if(m_sign_up_request->isSuccess())
{
m_show_registration_info = true;
}
else
{
sfx_manager->quickSound( "anvil" );
m_show_registration_input = true;
m_registration_error = m_sign_up_request->getInfo();
}
delete m_sign_up_request;
m_sign_up_request = NULL;
//FIXME m_options_widget->setActivated();
}
else
{
m_info_widget->setDefaultColor();
m_info_widget->setText(Messages::validatingInfo(), false);
}
}
}
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
// If it's not accept, it's cancel - anyway, close dialog
ModalDialog::dismiss();
else if (m_show_registration_input)
showRegistrationInput();
else if (m_show_registration_terms)
showRegistrationTerms();
else if (m_show_registration_info)
showRegistrationInfo();
}
return EVENT_BLOCK;
}
return EVENT_LET;
} // processEvent

View File

@ -31,62 +31,10 @@
class RegistrationDialog : public GUIEngine::ModalDialog
{
public:
enum Phase
{
Input = 1,
Terms = 2,
Info = 4
};
RegistrationDialog();
~RegistrationDialog();
void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
virtual void onUpdate(float dt);
virtual bool onEscapePressed();
private:
Phase m_phase;
bool m_self_destroy;
bool m_show_registration_input;
bool m_show_registration_terms;
bool m_show_registration_info;
const Online::XMLRequest * m_sign_up_request;
//Saved user input :
irr::core::stringw m_username;
irr::core::stringw m_password;
irr::core::stringw m_password_confirm;
irr::core::stringw m_email;
irr::core::stringw m_email_confirm;
irr::core::stringw m_registration_error;
bool m_agreement;
GUIEngine::TextBoxWidget * m_username_widget;
GUIEngine::TextBoxWidget * m_password_widget;
GUIEngine::TextBoxWidget * m_password_confirm_widget;
GUIEngine::TextBoxWidget * m_email_widget;
GUIEngine::TextBoxWidget * m_email_confirm_widget;
GUIEngine::LabelWidget * m_info_widget;
GUIEngine::RibbonWidget * m_options_widget;
GUIEngine::IconButtonWidget * m_previous_widget;
GUIEngine::IconButtonWidget * m_next_widget;
GUIEngine::IconButtonWidget * m_cancel_widget;
GUIEngine::CheckBoxWidget * m_accept_terms_widget;
void showRegistrationInput();
void showRegistrationTerms();
void showRegistrationInfo();
void processInput();
bool processInputEvent(const std::string& eventSource);
bool processTermsEvent(const std::string& eventSource);
bool processInfoEvent(const std::string& eventSource);
};
}; // class RegistrationDialog
#endif

View File

@ -0,0 +1,66 @@
// 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
// -----------------------------------------------------------------------------
void GuestLoginScreen::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
if (name == "category")
{
const std::string selection =
((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
Log::warn("login", "selection %s", selection.c_str());
if (selection == "login")
StateManager::get()->replaceTopMostScreen(LoginScreen::getInstance());
else if (selection == "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();
}
} // eventCallback
// -----------------------------------------------------------------------------

View File

@ -0,0 +1,47 @@
// 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:
/** \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

@ -0,0 +1,173 @@
// 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 "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/current_user.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 "utils/log.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
DEFINE_SCREEN_SINGLETON( LoginScreen );
// -----------------------------------------------------------------------------
LoginScreen::LoginScreen() : Screen("online/login.stkgui")
{
} // LoginScreen
// -----------------------------------------------------------------------------
void LoginScreen::init()
{
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;
} // loadedFromFile
// -----------------------------------------------------------------------------
/** 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 stringw username = getWidget<TextBoxWidget>("username")
->getText().trim();
const 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();
Online::CurrentUser::get()->requestSignIn(username,password,
remember );
}
} // 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<LabelWidget>("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.
*/
void LoginScreen::onUpdate(float dt, irr::video::IVideoDriver*)
{
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 == "category")
{
StateManager *sm = StateManager::get();
const std::string selection =
((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if (selection == "guest_login")
sm->replaceTopMostScreen(GuestLoginScreen::getInstance());
else if (selection == "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")
{
}
else if(button=="cancel")
StateManager::get()->escapePressed();
}
} // eventCallback
// -----------------------------------------------------------------------------

View File

@ -0,0 +1,63 @@
// 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, irr::video::IVideoDriver*) OVERRIDE;
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID) OVERRIDE;
void loginSuccessful();
void loginError(const irr::core::stringw & error_message);
}; // class LoginScreen
#endif

View File

@ -37,12 +37,12 @@
#include "modes/overworld.hpp"
#include "modes/demo_world.hpp"
#include "online/request_manager.hpp"
#include "states_screens/online_screen.hpp"
#include "states_screens/addons_screen.hpp"
#include "states_screens/credits.hpp"
#include "states_screens/help_screen_1.hpp"
#include "states_screens/login_screen.hpp"
#include "states_screens/offline_kart_selection.hpp"
#include "states_screens/network_kart_selection.hpp" // FIXME : remove when not testing
#include "states_screens/online_screen.hpp"
#include "states_screens/options_screen_video.hpp"
#include "states_screens/state_manager.hpp"
@ -111,6 +111,11 @@ void MainMenuScreen::init()
w->setBadge(LOADING_BADGE);
}
IconButtonWidget* online = getWidget<IconButtonWidget>("online");
if(CurrentUser::get()->getID())
online->setLabel(_("Online"));
else
online->setLabel(_("Login"));
LabelWidget* w = getWidget<LabelWidget>("info_addons");
const core::stringw &news_text = NewsManager::get()->getNextNewsMessage();
@ -380,7 +385,10 @@ void MainMenuScreen::eventCallback(Widget* widget, const std::string& name,
"\"Allow STK to connect to the Internet\"."));
return;
}
StateManager::get()->pushScreen(OnlineScreen::getInstance());
if(CurrentUser::get()->getID())
StateManager::get()->pushScreen(OnlineScreen::getInstance());
else
StateManager::get()->pushScreen(LoginScreen::getInstance());
}
else if (selection == "addons")
{

View File

@ -0,0 +1,192 @@
// 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/register_screen.hpp"
#include "audio/sfx_manager.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "online/current_user.hpp"
#include "online/messages.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 "utils/log.hpp"
#include "utils/translation.hpp"
using namespace GUIEngine;
using namespace Online;
DEFINE_SCREEN_SINGLETON( RegisterScreen );
// -----------------------------------------------------------------------------
RegisterScreen::RegisterScreen() : Screen("online/register.stkgui")
{
} // RegisterScreen
// -----------------------------------------------------------------------------
void RegisterScreen::init()
{
TextBoxWidget *password_widget = getWidget<TextBoxWidget>("password");
password_widget->setPasswordBox(true,L'*');
password_widget = getWidget<TextBoxWidget>("password_confirm");
password_widget->setPasswordBox(true,L'*');
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget);
m_signup_request = NULL;
m_info_message_shown = false;
} // init
// -----------------------------------------------------------------------------
void RegisterScreen::doRegister()
{
core::stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
core::stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
core::stringw password_confirm = getWidget<TextBoxWidget>("password_confirm")
->getText().trim();
core::stringw email = getWidget<TextBoxWidget>("email")->getText().trim();
core::stringw email_confirm = getWidget<TextBoxWidget>("email_confirm")
->getText().trim();
m_info_widget->setErrorColor();
if (password != password_confirm)
{
m_info_widget->setText(_("Passwords don't match!"), false);
}
else if (email != email_confirm)
{
m_info_widget->setText(_("Emails don't match!"), false);
}
else if (username.size() < 4 || username.size() > 30)
{
m_info_widget->setText(_("Username has to be between 4 and 30 characters long!"), false);
}
else if (password.size() < 8 || password.size() > 30)
{
m_info_widget->setText(_("Password has to be between 8 and 30 characters long!"), false);
}
else if (email.size() < 4 || email.size() > 50)
{
m_info_widget->setText(_("Email has to be between 4 and 50 characters long!"), false);
}
else
{
m_info_widget->setDefaultColor();
new RegistrationDialog();
return;
}
sfx_manager->quickSound( "anvil" );
} // doRegister
// -----------------------------------------------------------------------------
/** Called from the registration info dialog when 'accept' is clicked.
*/
void RegisterScreen::acceptTerms()
{
m_options_widget->setDeactivated();
core::stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
core::stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
core::stringw password_confirm= getWidget<TextBoxWidget>("password_confirm")->getText().trim();
core::stringw email = getWidget<TextBoxWidget>("email")->getText().trim();
m_signup_request = CurrentUser::get()->requestSignUp(username, password,
password_confirm, email);
} // acceptTerms
// -----------------------------------------------------------------------------
void RegisterScreen::onUpdate(float dt, irr::video::IVideoDriver*)
{
if(m_signup_request)
{
if(!m_options_widget->isActivated())
m_info_widget->setText(Messages::validatingInfo(), false);
if(m_signup_request->isDone())
{
if(m_signup_request->isSuccess())
{
new MessageDialog(
_("You will receive an email with further instructions "
"regarding account activation. Please be patient and be "
"sure to check your spam folder."),
MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
// Set the flag that the message was shown, which will triger
// a pop of this menu and so a return to the main menu
m_info_message_shown = true;
}
else
{
// Error signing up, display error message
m_info_widget->setText(m_signup_request->getInfo(), false);
}
delete m_signup_request;
m_signup_request = NULL;
m_options_widget->setActivated();
}
}
else if(m_info_message_shown && !ModalDialog::isADialogActive())
{
// Once the info message was shown (signup was successful), but the
// message has been gone (user clicked on OK), go back to main menu
StateManager::get()->popMenu();
}
} // onUpdate
// -----------------------------------------------------------------------------
void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
if (name == "category")
{
const std::string selection =
((RibbonWidget*)widget)->getSelectionIDString(PLAYER_ID_GAME_MASTER);
StateManager *sm = StateManager::get();
if (selection == "login")
sm->replaceTopMostScreen(RegisterScreen::getInstance());
else if (selection == "guest_login")
sm->replaceTopMostScreen(GuestLoginScreen::getInstance());
}
else if (name=="options")
{
const std::string button = m_options_widget
->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if(button=="next")
{
doRegister();
}
else if(button=="cancel")
StateManager::get()->escapePressed();
}
} // eventCallback
// -----------------------------------------------------------------------------

View File

@ -0,0 +1,64 @@
// 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_REGISTER_SCREEN_HPP
#define HEADER_REGISTER_SCREEN_HPP
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; class LabelWidget; }
namespace Online { class XMLRequest; }
/**
* \brief Screen to register an online account.
* \ingroup states_screens
*/
class RegisterScreen : public GUIEngine::Screen,
public GUIEngine::ScreenSingleton<RegisterScreen>
{
private:
friend class GUIEngine::ScreenSingleton<RegisterScreen>;
void doRegister();
void init();
RegisterScreen();
/** Save the pointer to the info widget, it is widely used. */
GUIEngine::LabelWidget *m_info_widget;
/** Save the pointer to the options widget, it is widely used. */
GUIEngine::RibbonWidget *m_options_widget;
const Online::XMLRequest *m_signup_request;
/** True if the info message (email was sent...) is shown. */
bool m_info_message_shown;
public:
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void loadedFromFile() OVERRIDE {};
virtual void onUpdate(float dt, irr::video::IVideoDriver*) OVERRIDE;
void acceptTerms();
/** \brief implement callback from parent class GUIEngine::Screen */
virtual void eventCallback(GUIEngine::Widget* widget,
const std::string& name,
const int playerID) OVERRIDE;
}; // class RegisterScreen
#endif