Merge branch 'new_register_screen'

This commit is contained in:
hiker 2015-01-12 12:19:56 +11:00
commit 342cb82653
5 changed files with 143 additions and 63 deletions

View File

@ -4,22 +4,23 @@
<header align="center" width="80%" text="Create User" text_align="center"
I18N="In the registration dialog" />
<spacer height="15" width="10"/>
<spacer height="15" width="10"/>
<tabs id="mode_tabs" height="10%" max_height="110" x="2%" width="98%" align="center">
<icon-button id="tab_new_online" width="128" height="128" icon="gui/main_network.png"
I18N="Section in the register screen" text="New Online Account"/>
<icon-button id="tab_existing_online" width="128" height="128" icon="gui/main_network.png"
I18N="Section in the register screen" text="Existing Online Account"/>
<icon-button id="tab_offline" width="128" height="128" icon="gui/options_players.png"
I18N="Section in the register screen" text="Offline Account"/>
</tabs>
<box proportion="1" width="100%" height="100%" layout="vertical-row">
<box proportion="1" width="100%" height="100%" layout="vertical-row">
<div width="90%" align="center" layout="vertical-row" height="80%">
<div width="100%" height="12%" layout="horizontal-row" >
<label proportion="1" height="100%" text_align="left"
I18N="In the registration dialog" text="Local Username"/>
I18N="In the registration dialog" text="Name"/>
<textbox id="local_username" proportion="2" height="fit" I18N="In the registration dialog"/>
</div>
<div width="100%" height="12%" layout="horizontal-row" >
<label id="label_online" proportion="1" height="100%" text_align="left"
I18N="In the registration dialog" text="Create online account"/>
<div proportion="2" layout="horizontal-row" height="fit">
<checkbox id="online" I18N="In the registration dialog" text_align="left"/>
</div>
</div>
<div width="100%" height="12%" layout="horizontal-row" >
<label id="label_username" proportion="1" height="100%" text_align="left"

View File

@ -45,11 +45,36 @@ DEFINE_SCREEN_SINGLETON( RegisterScreen );
RegisterScreen::RegisterScreen() : Screen("online/register.stkgui")
{
m_existing_player = NULL;
m_account_mode = ACCOUNT_OFFLINE;
} // RegisterScreen
// -----------------------------------------------------------------------------
void RegisterScreen::init()
{
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget);
m_info_widget->setDefaultColor();
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget);
m_password_widget = getWidget<TextBoxWidget>("password");
assert(m_password_widget);
RibbonWidget* ribbon = getWidget<RibbonWidget>("mode_tabs");
assert(ribbon);
if (UserConfigParams::m_internet_status !=
Online::RequestManager::IPERM_NOT_ALLOWED)
{
m_account_mode = ACCOUNT_NEW_ONLINE;
ribbon->select("tab_new_online", PLAYER_ID_GAME_MASTER);
}
else
{
m_account_mode = ACCOUNT_OFFLINE;
ribbon->select("tab_offline", PLAYER_ID_GAME_MASTER);
}
// Hide the tabs in case of a rename
ribbon->setVisible(m_existing_player == NULL);
Screen::init();
// If there is no player (i.e. first start of STK), try to pick
@ -71,27 +96,14 @@ void RegisterScreen::init()
getWidget<TextBoxWidget>("local_username")->setText(username);
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_info_widget->setDefaultColor();
m_options_widget = getWidget<RibbonWidget>("options");
assert(m_options_widget);
m_password_widget->setPasswordBox(true, L'*');
getWidget<TextBoxWidget>("password_confirm")->setPasswordBox(true, L'*');
m_signup_request = NULL;
m_info_message_shown = false;
getWidget<CheckBoxWidget>("online")->setVisible(true);
getWidget<LabelWidget>("label_online")->setVisible(true);
onDialogClose();
bool online = UserConfigParams::m_internet_status
!= Online::RequestManager::IPERM_NOT_ALLOWED;
getWidget<CheckBoxWidget>("online")->setState(online);
makeEntryFieldsVisible(online);
makeEntryFieldsVisible();
} // init
// -----------------------------------------------------------------------------
@ -109,8 +121,8 @@ void RegisterScreen::onDialogClose()
{
bool online = UserConfigParams::m_internet_status
!= Online::RequestManager::IPERM_NOT_ALLOWED;
getWidget<CheckBoxWidget>("online")->setState(online);
makeEntryFieldsVisible(online);
m_account_mode = online ? ACCOUNT_NEW_ONLINE : ACCOUNT_OFFLINE;
makeEntryFieldsVisible();
} // onDialogClose
// -----------------------------------------------------------------------------
@ -118,29 +130,30 @@ void RegisterScreen::onDialogClose()
* online mode.
* \param online True if an online account should be created.
*/
void RegisterScreen::makeEntryFieldsVisible(bool online)
void RegisterScreen::makeEntryFieldsVisible()
{
// In case of a rename, hide all other fields.
if(m_existing_player)
{
m_info_widget->setVisible(false);
getWidget<CheckBoxWidget>("online")->setVisible(false);
getWidget<LabelWidget>("label_online")->setVisible(false);
online = false;
m_account_mode = ACCOUNT_OFFLINE;
}
bool online = m_account_mode != ACCOUNT_OFFLINE;
getWidget<TextBoxWidget>("username")->setVisible(online);
getWidget<LabelWidget >("label_username")->setVisible(online);
getWidget<TextBoxWidget>("password")->setVisible(online);
m_password_widget->setVisible(online);
getWidget<LabelWidget >("label_password")->setVisible(online);
getWidget<TextBoxWidget>("password_confirm")->setVisible(online);
getWidget<LabelWidget >("label_password_confirm")->setVisible(online);
getWidget<TextBoxWidget>("email")->setVisible(online);
getWidget<LabelWidget >("label_email")->setVisible(online);
bool new_account = online && (m_account_mode == ACCOUNT_NEW_ONLINE);
getWidget<TextBoxWidget>("password_confirm")->setVisible(new_account);
getWidget<LabelWidget >("label_password_confirm")->setVisible(new_account);
getWidget<TextBoxWidget>("email")->setVisible(new_account);
getWidget<LabelWidget >("label_email")->setVisible(new_account);
if(getWidget<TextBoxWidget>("email_confirm"))
{
getWidget<TextBoxWidget>("email_confirm")->setVisible(online);
getWidget<LabelWidget >("label_email_confirm")->setVisible(online);
getWidget<TextBoxWidget>("email_confirm")->setVisible(new_account);
getWidget<LabelWidget >("label_email_confirm")->setVisible(new_account);
}
} // makeEntryFieldsVisible
@ -199,15 +212,22 @@ void RegisterScreen::doRegister()
handleLocalName(local_name);
// If no online account is requested, don't register
if(!getWidget<CheckBoxWidget>("online")->getState() || m_existing_player)
if(m_account_mode!=ACCOUNT_NEW_ONLINE|| m_existing_player)
{
StateManager::get()->popMenu();
bool online = m_account_mode == ACCOUNT_EXISTING_ONLINE;
core::stringw password = online ? m_password_widget->getText() : "";
core::stringw online_name =
online ? getWidget<TextBoxWidget>("username")->getText().trim()
: "";
//m_parent_screen->setNewAccountData(online, online_name, password);
m_parent_screen->setNewAccountData(true, "online", "password");
m_existing_player = NULL;
StateManager::get()->popMenu();
return;
}
stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
stringw password = m_password_widget->getText().trim();
stringw password_confirm = getWidget<TextBoxWidget>("password_confirm")
->getText().trim();
stringw email = getWidget<TextBoxWidget>("email")->getText().trim();
@ -260,6 +280,10 @@ void RegisterScreen::doRegister()
PlayerProfile *player = PlayerManager::get()->getPlayer(local_name);
if (player)
{
core::stringw online_name = getWidget<TextBoxWidget>("username")->getText().trim();
m_parent_screen->setNewAccountData(/*online*/true,
username, password);
player->setLastOnlineName(username);
player->setWasOnlineLastTime(true);
}
@ -278,7 +302,7 @@ 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 = m_password_widget->getText().trim();
core::stringw password_confirm= getWidget<TextBoxWidget>("password_confirm")->getText().trim();
core::stringw email = getWidget<TextBoxWidget>("email")->getText().trim();
@ -339,16 +363,25 @@ void RegisterScreen::onUpdate(float dt)
void RegisterScreen::eventCallback(Widget* widget, const std::string& name,
const int playerID)
{
if (name == "online")
if (name == "mode_tabs")
{
if (UserConfigParams::m_internet_status == Online::RequestManager::IPERM_NOT_ALLOWED)
RibbonWidget *ribbon = static_cast<RibbonWidget*>(widget);
std::string selection = ribbon->getSelectionIDString(PLAYER_ID_GAME_MASTER);
if ( (selection == "tab_new_online" || selection == "tab_existing_online")
&& (UserConfigParams::m_internet_status == Online::RequestManager::IPERM_NOT_ALLOWED) )
{
m_info_widget->setErrorColor();
m_info_widget->setText(_("Internet access is disabled, please enable it in the options"), false);
getWidget<CheckBoxWidget>("online")->setState(false);
return;
}
else
makeEntryFieldsVisible(getWidget<CheckBoxWidget>("online")->getState());
if (selection == "tab_new_online")
m_account_mode = ACCOUNT_NEW_ONLINE;
else if (selection == "tab_existing_online")
m_account_mode = ACCOUNT_EXISTING_ONLINE;
else if (selection == "tab_offline")
m_account_mode = ACCOUNT_OFFLINE;
makeEntryFieldsVisible();
}
else if (name=="options")
{

View File

@ -20,11 +20,12 @@
#include "guiengine/screen.hpp"
namespace GUIEngine { class Widget; class LabelWidget;
class RibbonWidget; }
namespace GUIEngine { class Widget; class LabelWidget;
class RibbonWidget; class TextBoxWidget; }
namespace Online { class XMLRequest; }
class PlayerProfile;
class BaseUserScreen;
/**
* \brief Screen to register an online account.
@ -36,7 +37,7 @@ class RegisterScreen : public GUIEngine::Screen,
private:
friend class GUIEngine::ScreenSingleton<RegisterScreen>;
void makeEntryFieldsVisible(bool online);
void makeEntryFieldsVisible();
void handleLocalName(const irr::core::stringw &local_name);
void doRegister();
void init();
@ -48,6 +49,9 @@ private:
/** Save the pointer to the options widget, it is widely used. */
GUIEngine::RibbonWidget *m_options_widget;
/** Save the pointer to the options widget, it is widely used. */
GUIEngine::TextBoxWidget *m_password_widget;
/** The XML request to the server. */
Online::XMLRequest *m_signup_request;
@ -58,6 +62,16 @@ private:
/** True if the info message (email was sent...) is shown. */
bool m_info_message_shown;
/** Which kind of account to create: new online account, new account
* using an existing online account, offline account. */
enum { ACCOUNT_NEW_ONLINE,
ACCOUNT_EXISTING_ONLINE,
ACCOUNT_OFFLINE } m_account_mode;
/** A pointer to the parent UserScreen, in order to allow this screen
* to pass information back. */
BaseUserScreen *m_parent_screen;
public:
/** \brief implement callback from parent class GUIEngine::Screen */
@ -73,6 +87,9 @@ public:
const std::string& name,
const int playerID) OVERRIDE;
// ------------------------------------------------------------------------
/** Set the parent screen. */
void setParent(BaseUserScreen *us) { m_parent_screen = us; }
}; // class RegisterScreen
#endif

View File

@ -46,18 +46,13 @@ DEFINE_SCREEN_SINGLETON( TabbedUserScreen );
BaseUserScreen::BaseUserScreen(const std::string &name) : Screen(name.c_str())
{
m_online_cb = NULL;
m_new_registered_data = false;
} // BaseUserScreen
// ----------------------------------------------------------------------------
void BaseUserScreen::loadedFromFile()
{
} // loadedFromFile
// ----------------------------------------------------------------------------
void BaseUserScreen::init()
{
m_online_cb = getWidget<CheckBoxWidget>("online");
assert(m_online_cb);
@ -65,7 +60,6 @@ void BaseUserScreen::init()
assert(m_username_tb);
m_password_tb = getWidget<TextBoxWidget >("password");
assert(m_password_tb);
m_password_tb->setPasswordBox(true, L'*');
m_players = getWidget<DynamicRibbonWidget>("players");
assert(m_players);
m_options_widget = getWidget<RibbonWidget>("options");
@ -73,6 +67,25 @@ void BaseUserScreen::init()
m_info_widget = getWidget<LabelWidget>("message");
assert(m_info_widget);
} // loadedFromFile
// ----------------------------------------------------------------------------
void BaseUserScreen::setNewAccountData(bool online,
const core::stringw &online_name,
const core::stringw &password)
{
// Indicate for init that new user data is available.
m_new_registered_data = true;
m_online_cb->setState(online);
m_username_tb->setText(online_name);
m_password_tb->setText(password);
} // setOnline
// ----------------------------------------------------------------------------
void BaseUserScreen::init()
{
m_password_tb->setPasswordBox(true, L'*');
// The behaviour of the screen is slightly different at startup, i.e.
// when it is the first screen: cancel will exit the game, and in
// this case no 'back' error should be shown.
@ -139,6 +152,7 @@ void BaseUserScreen::init()
getWidget<IconButtonWidget>("rename")->setActivated();
getWidget<IconButtonWidget>("delete")->setActivated();
}
m_new_registered_data = false;
} // init
// ----------------------------------------------------------------------------
@ -170,15 +184,21 @@ void BaseUserScreen::selectUser(int index)
m_players->setSelection(StringUtils::toString(index), PLAYER_ID_GAME_MASTER,
/*focusIt*/ true);
m_username_tb->setText(profile->getLastOnlineName());
// Delete a password that might have been typed for another user
m_password_tb->setText("");
if (!m_new_registered_data)
m_username_tb->setText(profile->getLastOnlineName());
if (!m_new_registered_data)
{
// Delete a password that might have been typed for another user
m_password_tb->setText("");
}
// Last game was not online, so make the offline settings the default
// (i.e. unckeck online checkbox, and make entry fields invisible).
if (!profile->wasOnlineLastTime() || profile->getLastOnlineName() == "")
{
m_online_cb->setState(false);
if (!m_new_registered_data)
m_online_cb->setState(false);
makeEntryFieldsVisible();
return;
}
@ -299,6 +319,7 @@ void BaseUserScreen::eventCallback(Widget* widget,
else if (button == "new_user")
{
RegisterScreen::getInstance()->push();
RegisterScreen::getInstance()->setParent(this);
// Make sure the new user will have an empty online name field
// that can also be edited.
m_username_tb->setText("");
@ -318,6 +339,7 @@ void BaseUserScreen::eventCallback(Widget* widget,
PlayerProfile *cp = getSelectedPlayer();
RegisterScreen::getInstance()->setRename(cp);
RegisterScreen::getInstance()->push();
m_new_registered_data = false;
// Init will automatically be called, which
// refreshes the player list
}

View File

@ -89,6 +89,11 @@ private:
/** The dynamic ribbon containing all players. */
GUIEngine::DynamicRibbonWidget* m_players;
/** Set to indicate when the sceen is initialised that new data from a
* registration are available, and therefore entry fields are not
* all cleared. */
bool m_new_registered_data;
void selectUser(int index);
void makeEntryFieldsVisible();
void login();
@ -115,6 +120,8 @@ public:
/** \brief implement optional callback from parent class GUIEngine::Screen */
virtual void unloaded();
void setNewAccountData(bool online, const core::stringw &online_name="",
const core::stringw &password="");
void loginSuccessful();
void loginError(const irr::core::stringw &error_message);
void logoutSuccessful();