Recovery dialog finally added. Some additional GUI changes.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13361 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-07-27 20:55:10 +00:00
parent 328e186014
commit 4091c4c965
18 changed files with 522 additions and 190 deletions

View File

@ -0,0 +1,23 @@
<stkgui>
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text="Account Recovery"/>
<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 will receive an email with further instructions on how to reset your password. Please be patient and be sure to check your spam folder."/>
<spacer height="20" width="50">
<buttonbar id="options" width="25%" proportion="1" align="center">
<icon-button id="cancel" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Close" label_location="none"/>
</buttonbar>
</div>
</stkgui>

View File

@ -0,0 +1,46 @@
<stkgui>
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" height="fit" text_align="center" word_wrap="true"
I18N="In the recovery dialog' dialog" text="Account Recovery"/>
<spacer height="20" width="50">
<label id="message" proportion="2" width="90%" align="center" text_align="left" word_wrap="true"
text="Fill in the username and email address you supplied at registration to be able to reset your password."/>
<spacer height="40" width="50">
<div width="80%" align="center" layout="vertical-row" height="fit">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the recovery dialog" text="Username"/>
<textbox proportion="2" id="username" I18N="In the recovery dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the recovery dialog" text="Email"/>
<textbox proportion="2" id="email" I18N="In the recovery dialog"/>
</div>
</div>
<spacer height="20" width="50">
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true"
I18N="In the recovery" text=""/>
<spacer height="20" width="50">
<buttonbar id="options" width="25%" proportion="1" align="center">
<icon-button id="submit" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Submit" 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>
</div>
</stkgui>

View File

@ -1,28 +0,0 @@
<stkgui>
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" proportion="1" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text="User Activation"/>
<spacer height="20" width="50">
<label id="terms" proportion="6" width="90%" align="center" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text="Activation information will come here."/>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text=""/>
<spacer height="20" width="50">
<buttonbar id="options" width="25%" proportion="1" 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>
</div>
</stkgui>

View File

@ -3,58 +3,20 @@
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" proportion="1" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text="Registration"/>
I18N="In the registration dialog' dialog" text="Registration Complete"/>
<spacer height="40" width="50">
<spacer height="20" width="50">
<div width="80%" align="center" layout="vertical-row" height="fit">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Username"/>
<textbox proportion="2" id="username" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Password"/>
<textbox proportion="2" id="password" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Confirm"/>
<textbox proportion="2" 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" text_align="left" I18N="In the registration dialog" text="Email"/>
<textbox proportion="2" id="email" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Confirm"/>
<textbox proportion="2" id="email_confirm" I18N="In the registration dialog"/>
</div>
</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' dialog" text=""/>
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" I18N="In the registration dialog"
text="You will receive an email with further instructions regarding account activation. Please be patient and be sure to check your spam folder."/>
<spacer height="20" width="50">
<buttonbar id="options" width="25%" proportion="1" 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"/>
<icon-button id="cancel" width="64" height="64" icon="gui/green_check.png"
I18N="Registration dialog" text="Close" label_location="none"/>
</buttonbar>
</div>

View File

@ -0,0 +1,61 @@
<stkgui>
<div x="2%" y="5%" width="96%" height="90%" layout="vertical-row" >
<header id="title" width="96%" proportion="1" text_align="center" word_wrap="true"
I18N="In the registration dialog' dialog" text="Registration"/>
<spacer height="40" width="50">
<div width="80%" align="center" layout="vertical-row" height="fit">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Username"/>
<textbox proportion="2" id="username" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Password"/>
<textbox proportion="2" id="password" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Confirm"/>
<textbox proportion="2" 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" text_align="left" I18N="In the registration dialog" text="Email"/>
<textbox proportion="2" id="email" I18N="In the registration dialog"/>
</div>
<spacer height="20" width="20">
<div width="100%" height="fit" layout="horizontal-row" >
<label proportion="1" text_align="left" I18N="In the registration dialog" text="Confirm"/>
<textbox proportion="2" id="email_confirm" I18N="In the registration dialog"/>
</div>
</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">
<buttonbar id="options" width="25%" proportion="1" 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>
</div>
</stkgui>

View File

@ -19,7 +19,7 @@
<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' dialog" text=""/>
I18N="In the registration dialog" text=""/>
<spacer height="20" width="50">

View File

@ -184,6 +184,7 @@ src/states_screens/dialogs/message_dialog.cpp
src/states_screens/dialogs/player_info_dialog.cpp
src/states_screens/dialogs/press_a_key_dialog.cpp
src/states_screens/dialogs/race_paused_dialog.cpp
src/states_screens/dialogs/recovery_dialog.cpp
src/states_screens/dialogs/registration_dialog.cpp
src/states_screens/dialogs/select_challenge.cpp
src/states_screens/dialogs/server_info_dialog.cpp
@ -458,6 +459,7 @@ src/states_screens/dialogs/message_dialog.hpp
src/states_screens/dialogs/player_info_dialog.hpp
src/states_screens/dialogs/press_a_key_dialog.hpp
src/states_screens/dialogs/race_paused_dialog.hpp
src/states_screens/dialogs/recovery_dialog.hpp
src/states_screens/dialogs/registration_dialog.hpp
src/states_screens/dialogs/select_challenge.hpp
src/states_screens/dialogs/server_info_dialog.hpp

View File

@ -54,6 +54,20 @@ namespace Online{
setSaveSession(false);
}
// ============================================================================
const XMLRequest * CurrentUser::requestRecovery( const irr::core::stringw &username,
const irr::core::stringw &email)
{
assert(getUserState() == US_SIGNED_OUT || getUserState() == US_GUEST);
XMLRequest * request = new XMLRequest();
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
request->setParameter("action", std::string("recovery"));
request->setParameter("username", username);
request->setParameter("email", email);
HTTPManager::get()->addRequest(request);
return request;
}
// ============================================================================
const XMLRequest * CurrentUser::requestSignUp( const irr::core::stringw &username,
const irr::core::stringw &password,

View File

@ -105,7 +105,7 @@ namespace Online{
void createServer (const ServerCreationRequest * input);
public:
//Singleton
/**Singleton */
static CurrentUser * get();
static void deallocate();
@ -118,13 +118,16 @@ namespace Online{
const ServerJoinRequest * requestServerJoin( uint32_t server_id);
// Register
/** Register */
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 XMLRequest * requestRecovery( const irr::core::stringw &username,
const irr::core::stringw &email);
/** Returns the username if signed in. */
const irr::core::stringw getUserName() const;
const UserState getUserState() const { return m_state.getAtomic(); }

View File

@ -40,6 +40,11 @@ namespace Online
return irr::core::stringw(_("Validating registration info")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw recovery()
{
return irr::core::stringw(_("Validating recovery info")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw signedInAs(const irr::core::stringw & name)
{

View File

@ -30,6 +30,7 @@ namespace Online
irr::core::stringw signingIn ();
irr::core::stringw signingOut ();
irr::core::stringw signingUp ();
irr::core::stringw recovery ();
irr::core::stringw joiningServer ();
irr::core::stringw creatingServer ();
irr::core::stringw fetchingServers ();

View File

@ -92,7 +92,7 @@ namespace Online{
curl_session = curl_easy_init();
if(!curl_session)
{
Log::error("online/http_functions", "Error while initialising libCurl session");
Log::error("HTTPRequest::downloadPage", "Error while initialising libCurl session");
return "";
}
curl_easy_setopt(curl_session, CURLOPT_URL, m_url.getAtomic().c_str());
@ -132,7 +132,7 @@ namespace Online{
CURLcode res = curl_easy_perform(curl_session);
if(res == CURLE_OK)
{
Log::info("online/http_functions", "Received : %s", readBuffer.c_str());
Log::info("HTTPRequest::downloadPage", "Received : %s", readBuffer.c_str());
setProgress(1.0f);
}
else

View File

@ -26,6 +26,7 @@
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"
#include "states_screens/dialogs/recovery_dialog.hpp"
#include "online/messages.hpp"
@ -41,6 +42,7 @@ LoginDialog::LoginDialog(const Message message_type) :
{
m_self_destroy = false;
m_open_registration_dialog = false;
m_open_recovery_dialog = false;
m_sign_in_request = NULL;
loadFromFile("online/login_dialog.stkgui");
@ -86,6 +88,7 @@ LoginDialog::LoginDialog(const Message message_type) :
assert(m_register_widget != NULL);
m_as_guest_widget = getWidget<IconButtonWidget>("as_guest");
assert(m_as_guest_widget != NULL);
m_as_guest_widget->setDeactivated();
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
@ -141,6 +144,11 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
m_open_registration_dialog = true;
return GUIEngine::EVENT_BLOCK;
}
else if(selection == m_recovery_widget->m_properties[PROP_ID])
{
m_open_recovery_dialog = true;
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
}
@ -191,8 +199,8 @@ void LoginDialog::onUpdate(float dt)
m_info_widget->setText(Online::Messages::signingIn(), false);
}
}
//If we want to open the registration dialog, we need to close this one first
m_open_registration_dialog && (m_self_destroy = true);
//If we want to open another dialog, we need to close this one first
(m_open_registration_dialog || m_open_recovery_dialog) && (m_self_destroy = true);
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
@ -200,6 +208,8 @@ void LoginDialog::onUpdate(float dt)
ModalDialog::dismiss();
if (m_open_registration_dialog)
new RegistrationDialog();
else if (m_open_recovery_dialog)
new RecoveryDialog();
return;
}
}

View File

@ -37,6 +37,7 @@ private:
bool m_self_destroy;
bool m_open_registration_dialog;
bool m_open_recovery_dialog;
const Online::CurrentUser::SignInRequest * m_sign_in_request;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::TextBoxWidget * m_username_widget;

View File

@ -0,0 +1,190 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// 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/dialogs/recovery_dialog.hpp"
#include <IGUIEnvironment.h>
#include "audio/sfx_manager.hpp"
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "online/messages.hpp"
using namespace GUIEngine;
using namespace irr;
using namespace irr::gui;
using namespace Online;
// -----------------------------------------------------------------------------
RecoveryDialog::RecoveryDialog() :
ModalDialog(0.8f,0.8f)
{
m_recovery_request = NULL;
m_self_destroy = false;
m_show_recovery_input = true;
}
// -----------------------------------------------------------------------------
RecoveryDialog::~RecoveryDialog()
{
delete m_recovery_request;
}
// -----------------------------------------------------------------------------
void RecoveryDialog::showRecoveryInput(){
m_show_recovery_input = false;
clearWindow();
m_phase = Input;
loadFromFile("online/recovery_input.stkgui");
m_username_widget = getWidget<TextBoxWidget>("username");
assert(m_username_widget != NULL);
m_username_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_email_widget = getWidget<TextBoxWidget>("email");
assert(m_email_widget != NULL);
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget != NULL);
m_submit_widget = getWidget<IconButtonWidget>("submit");
assert(m_submit_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
void RecoveryDialog::showRecoveryInfo(){
m_show_recovery_info = false;
clearWindow();
m_phase = Info;
loadFromFile("online/recovery_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);
}
// -----------------------------------------------------------------------------
bool RecoveryDialog::onEscapePressed()
{
return m_cancel_widget->isActivated();
}
// -----------------------------------------------------------------------------
void RecoveryDialog::processInput()
{
const stringw username = m_username_widget->getText().trim();
const stringw email = m_email_widget->getText().trim();
if (username.size() < 4 || username.size() > 30 || email.size() < 4 || email.size() > 50)
{
sfx_manager->quickSound("anvil");
m_info_widget->setErrorColor();
m_info_widget->setText(_("Username and/or email address invalid."), false);
}
else
{
m_info_widget->setDefaultColor();
m_options_widget->setDeactivated();
m_recovery_request = CurrentUser::get()->requestRecovery(username, email);
}
}
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation RecoveryDialog::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 (selection == m_submit_widget->m_properties[PROP_ID])
{
processInput();
return GUIEngine::EVENT_BLOCK;
}
return GUIEngine::EVENT_LET;
}
// -----------------------------------------------------------------------------
void RecoveryDialog::onEnterPressedInternal()
{
if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER))
return;
if (m_submit_widget->isActivated())
processInput();
}
// -----------------------------------------------------------------------------
void RecoveryDialog::onUpdate(float dt)
{
if(m_recovery_request != NULL)
{
if(m_recovery_request->isDone())
{
if(m_recovery_request->isSuccess())
{
m_show_recovery_info = true;
}
else
{
sfx_manager->quickSound( "anvil" );
m_info_widget->setErrorColor();
m_info_widget->setText(m_recovery_request->getInfo(), false);
m_options_widget->setActivated();
}
delete m_recovery_request;
m_recovery_request = NULL;
}
else
{
m_info_widget->setText(Messages::recovery(), false);
}
}
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
ModalDialog::dismiss();
else if (m_show_recovery_input)
showRecoveryInput();
else if (m_show_recovery_info)
showRecoveryInfo();
}

View File

@ -0,0 +1,71 @@
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2013 Glenn De Jonghe
//
// 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_RECOVERY_DIALOG_HPP
#define HEADER_RECOVERY_DIALOG_HPP
#include <irrString.h>
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets.hpp"
#include "online/current_user.hpp"
/**
* \brief Dialog that allows a user to recover his account
* \ingroup states_screens
*/
class RecoveryDialog : public GUIEngine::ModalDialog
{
public:
enum Phase
{
Input = 1,
Info = 2,
};
RecoveryDialog();
~RecoveryDialog();
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_recovery_input;
bool m_show_recovery_info;
const Online::XMLRequest * m_recovery_request;
GUIEngine::TextBoxWidget * m_username_widget;
GUIEngine::TextBoxWidget * m_email_widget;
GUIEngine::LabelWidget * m_info_widget;
GUIEngine::RibbonWidget * m_options_widget;
GUIEngine::IconButtonWidget * m_submit_widget;
GUIEngine::IconButtonWidget * m_cancel_widget;
void showRecoveryInput();
void showRecoveryInfo();
void processInput();
};
#endif

View File

@ -35,26 +35,20 @@ using namespace Online;
// -----------------------------------------------------------------------------
RegistrationDialog::RegistrationDialog(const Phase phase) :
RegistrationDialog::RegistrationDialog() :
ModalDialog(0.8f,0.9f)
{
m_sign_up_request = NULL;
m_activation_request = NULL;
m_self_destroy = false;
m_show_registration_info = false;
m_show_registration_input = true;
m_show_registration_terms = false;
m_show_registration_activation = false;
m_show_registration_info = false;
m_username = "";
m_email = "";
m_email_confirm = "";
m_password = "";
m_password_confirm = "";
m_agreement = false;
//If not asked for the Activation phase, default to the Info phase.
if (phase == Activation)
m_show_registration_activation = true;
else
m_show_registration_info = true;
}
// -----------------------------------------------------------------------------
@ -62,16 +56,16 @@ RegistrationDialog::RegistrationDialog(const Phase phase) :
RegistrationDialog::~RegistrationDialog()
{
delete m_sign_up_request;
delete m_activation_request;
}
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationInfo(){
m_show_registration_info = false;
void RegistrationDialog::showRegistrationInput()
{
m_show_registration_input = false;
clearWindow();
m_phase = Info;
loadFromFile("online/registration_info.stkgui");
m_phase = Input;
loadFromFile("online/registration_input.stkgui");
//Password should always be reentered if previous has been clicked, or an error occurred.
m_password = "";
@ -113,7 +107,8 @@ void RegistrationDialog::showRegistrationInfo(){
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationTerms(){
void RegistrationDialog::showRegistrationTerms()
{
m_show_registration_terms = false;
clearWindow();
m_phase = Terms;
@ -139,64 +134,71 @@ void RegistrationDialog::showRegistrationTerms(){
// -----------------------------------------------------------------------------
void RegistrationDialog::showRegistrationActivation(){
m_show_registration_activation = false;
void RegistrationDialog::showRegistrationInfo()
{
m_show_registration_info = false;
clearWindow();
m_phase = Activation;
loadFromFile("online/registration_activation.stkgui");
m_phase = Info;
loadFromFile("online/registration_info.stkgui");
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
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);
}
// -----------------------------------------------------------------------------
bool RegistrationDialog::processInfoEvent(const std::string& eventSource){
if (m_phase == Info)
void RegistrationDialog::processInput()
{
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)
{
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])
{
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)
{
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 true;
}
sfx_manager->quickSound( "anvil" );
processInput();
return true;
}
}
@ -205,7 +207,8 @@ bool RegistrationDialog::processInfoEvent(const std::string& eventSource){
// -----------------------------------------------------------------------------
bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
bool RegistrationDialog::processTermsEvent(const std::string& eventSource)
{
if (m_phase == Terms)
{
if (eventSource == m_next_widget->m_properties[PROP_ID])
@ -238,16 +241,8 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
// -----------------------------------------------------------------------------
bool RegistrationDialog::processActivationEvent(const std::string& eventSource){
if (m_phase == Activation)
{
if (eventSource == m_next_widget->m_properties[PROP_ID])
{
//FIXME : activate
m_self_destroy = true;
return true;
}
}
bool RegistrationDialog::processInfoEvent(const std::string& eventSource)
{
return false;
}
@ -272,7 +267,7 @@ GUIEngine::EventPropagation RegistrationDialog::processEvent(const std::string&
m_self_destroy = true;
return GUIEngine::EVENT_BLOCK;
}
else if (processInfoEvent(selection) || processTermsEvent(selection) || processActivationEvent(selection))
else if (processInputEvent(selection) || processTermsEvent(selection) || processInfoEvent(selection))
{
return GUIEngine::EVENT_BLOCK;
}
@ -287,7 +282,7 @@ void RegistrationDialog::onEnterPressedInternal()
if (GUIEngine::isFocusedForPlayer(m_options_widget, PLAYER_ID_GAME_MASTER))
return;
if (m_next_widget->isActivated())
processEvent("next");
processInput();
}
// -----------------------------------------------------------------------------
@ -302,12 +297,12 @@ void RegistrationDialog::onUpdate(float dt)
{
if(m_sign_up_request->isSuccess())
{
m_show_registration_activation = true;
m_show_registration_info = true;
}
else
{
sfx_manager->quickSound( "anvil" );
m_show_registration_info = true;
m_show_registration_input = true;
m_registration_error = m_sign_up_request->getInfo();
}
delete m_sign_up_request;
@ -321,34 +316,13 @@ void RegistrationDialog::onUpdate(float dt)
}
}
}
else if (m_phase == Activation)
{
/*
XMLRequest * sign_up_request = HTTPManager::get()->getXMLResponse(Request::RT_SIGN_UP);
if(sign_up_request != NULL)
{
if(sign_up_request->isSuccess())
{
m_show_registration_activation = true;
}
else
{
sfx_manager->quickSound( "anvil" );
m_show_registration_info = true;
m_registration_error = sign_up_request->getInfo();
}
delete sign_up_request;
m_signing_up = false;
//FIXME m_options_widget->setActivated();
}*/
}
// It's unsafe to delete from inside the event handler so we do it here
if (m_self_destroy)
ModalDialog::dismiss();
else if (m_show_registration_info)
showRegistrationInfo();
else if (m_show_registration_input)
showRegistrationInput();
else if (m_show_registration_terms)
showRegistrationTerms();
else if (m_show_registration_activation)
showRegistrationActivation();
else if (m_show_registration_info)
showRegistrationInfo();
}

View File

@ -31,15 +31,13 @@
class RegistrationDialog : public GUIEngine::ModalDialog
{
public:
enum Phase
{
Info = 1,
Input = 1,
Terms = 2,
Activation = 4
Info = 4
};
RegistrationDialog(const Phase phase = Info);
RegistrationDialog();
~RegistrationDialog();
void onEnterPressedInternal();
@ -49,15 +47,13 @@ public:
virtual bool onEscapePressed();
private:
Phase m_phase;
bool m_self_destroy;
bool m_show_registration_info;
bool m_show_registration_input;
bool m_show_registration_terms;
bool m_show_registration_activation;
bool m_show_registration_info;
const Online::XMLRequest * m_sign_up_request;
const Online::XMLRequest * m_activation_request;
//Saved user input :
irr::core::stringw m_username;
@ -83,12 +79,13 @@ private:
GUIEngine::CheckBoxWidget * m_accept_terms_widget;
void showRegistrationInfo();
void showRegistrationInput();
void showRegistrationTerms();
void showRegistrationActivation();
bool processInfoEvent(const std::string& eventSource);
void showRegistrationInfo();
void processInput();
bool processInputEvent(const std::string& eventSource);
bool processTermsEvent(const std::string& eventSource);
bool processActivationEvent(const std::string& eventSource);
bool processInfoEvent(const std::string& eventSource);
};