[_GSoC Uni_] Updated the interface code for the online part and some small adjustments to the underlying code. -- Ready for user testing! Can connect to the api server now. Activation not yet needed, mail addresses will not be saved, don't pick an important password. (Users will sometimes be deleted during development anyway.)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13031 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-06-29 22:55:15 +00:00
parent 0850ccf617
commit 4e2ef1347a
10 changed files with 194 additions and 97 deletions

View File

@ -33,15 +33,15 @@
<buttonbar id="options" width="90%" proportion="1" align="center">
<icon-button id="sign_in" width="64" height="64" icon="gui/main_options.png"
I18N="Main menu button" text="Sign In" label_location="bottom"/>
<icon-button id="forgot_password" width="64" height="64" icon="gui/main_help.png"
I18N="Main menu button" text="Recovery" label_location="bottom"/>
<icon-button id="sign_up" width="64" height="64" icon="gui/tutorial.png"
I18N="Main menu button" text="Register" label_location="bottom"/>
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="register" width="64" height="64" icon="gui/tutorial.png"
I18N="Login dialog" text="Register" label_location="bottom"/>
<icon-button id="as_guest" width="64" height="64" icon="gui/main_about.png"
I18N="Main menu button" text="As guest" label_location="bottom"/>
I18N="Login dialog" text="As guest" label_location="bottom"/>
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
I18N="Main menu button" text="Cancel" label_location="bottom"/>
I18N="Login dialog" text="Cancel" label_location="bottom"/>
</buttonbar>

View File

@ -6,7 +6,9 @@
<box proportion="4" width="90%" layout="vertical-row" align="center">
<div x="2%" y="2%" width="96%" height="96%" layout="vertical-row" id="outer_box" >
<label I18N="In the online multiplayer screen" proportion="4" word_wrap="true" text=
"Here will come some information.. or statistic.. or whatever. Yet to be filled in!" align="center"/>
"Here will come some information.. or statistics.. or whatever. Yet to be filled in! It will change depending on state. And I'd also like a close button at the right top.
" align="center"/>
</div>
</box>
@ -32,10 +34,10 @@
<buttonbar id="menu_bottomrow" x="0" y="0" width="20%" height="100%" align="center">
<icon-button id="sign_in" width="64" height="64" icon="gui/main_about.png" extend_label="50"
I18N="Main menu button" text="Sign In" label_location="hover"/>
<icon-button id="register" width="64" height="64" icon="gui/tutorial.png" extend_label="50"
I18N="Main menu button" text="Register" label_location="hover"/>
<icon-button id="sign_out" width="64" height="64" icon="gui/main_quit.png" extend_label="50"
I18N="Main menu button" text="Sign Out" label_location="hover"/>
<icon-button id="sign_up" width="64" height="64" icon="gui/tutorial.png" extend_label="50"
I18N="Main menu button" text="Register" label_location="hover"/>
</buttonbar>
</bottombar>

View File

@ -8,7 +8,7 @@
<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="The terms will come here. In a fancy scroll box."/>
I18N="In the registration dialog' dialog" text="The terms will come here. In a fancy scroll box."/>
<div align="center" width="fit" height="fit" layout="horizontal-row" >
<label text_align="center" align="center" I18N="In the registration dialog" word_wrap="true"

View File

@ -46,7 +46,7 @@ void CurrentOnlineUser::deallocate()
CurrentOnlineUser::CurrentOnlineUser(){
m_is_signed_in = false;
m_is_guest = true;
m_is_guest = false;
m_id = 0;
m_name = "";
m_token = "";
@ -78,7 +78,7 @@ bool CurrentOnlineUser::signUp( const irr::core::stringw &username,
}
else
{
info = _("Server error");
info = _("Unable to connect to the server. Check your internet connection or try again later.");
}
return success;
}
@ -134,6 +134,7 @@ bool CurrentOnlineUser::signOut(){
m_name = "";
m_id = 0;
m_is_signed_in = false;
m_is_guest = false;
}
}
return !m_is_signed_in;
@ -143,10 +144,8 @@ bool CurrentOnlineUser::signOut(){
irr::core::stringw CurrentOnlineUser::getUserName() const
{
if(m_is_signed_in){
if(m_is_signed_in)
return m_name;
}else{
return _("Not signed in");
}
else
return _("Currently not signed in");
}

View File

@ -22,8 +22,6 @@
#include "audio/sfx_manager.hpp"
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/widgets/button_widget.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
@ -45,15 +43,7 @@ LoginDialog::LoginDialog(const Message message_type) :
m_reshow_current_screen = false;
loadFromFile("online/login_dialog.stkgui");
TextBoxWidget* textBox = getWidget<TextBoxWidget>("password");
assert(textBox != NULL);
textBox->setPasswordBox(true,L'*');
textBox = getWidget<TextBoxWidget>("username");
assert(textBox != NULL);
textBox->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
LabelWidget * m_info_widget = getWidget<LabelWidget>("info");
m_info_widget = getWidget<LabelWidget>("info");
assert(m_info_widget != NULL);
irr::core::stringw info;
if (message_type == Normal)
@ -69,6 +59,28 @@ LoginDialog::LoginDialog(const Message message_type) :
info += _("If you do not have an account yet, you can choose to sign in as a guest "
"or press the register icon at the bottom to gain access to all the features!");
m_info_widget->setText(info, false);
m_username_widget = getWidget<TextBoxWidget>("username");
assert(m_username_widget != NULL);
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_message_widget = getWidget<LabelWidget>("message");
assert(m_message_widget != NULL);
m_sign_in_widget = getWidget<IconButtonWidget>("sign_in");
assert(m_sign_in_widget != NULL);
m_recovery_widget = getWidget<IconButtonWidget>("recovery");
assert(m_recovery_widget != NULL);
m_register_widget = getWidget<IconButtonWidget>("register");
assert(m_register_widget != NULL);
m_as_guest_widget = getWidget<IconButtonWidget>("as_guest");
assert(m_as_guest_widget != NULL);
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
@ -77,13 +89,6 @@ LoginDialog::~LoginDialog()
{
}
// -----------------------------------------------------------------------------
void LoginDialog::beforeAddingWidgets()
{
LabelWidget * m_message_widget = getWidget<LabelWidget>("message");
assert(m_message_widget != NULL);
}
// -----------------------------------------------------------------------------
GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSource)
@ -95,8 +100,8 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
}
else if(eventSource == "sign_in")
{
const stringw username = getWidget<TextBoxWidget>("username")->getText().trim();
const stringw password = getWidget<TextBoxWidget>("password")->getText().trim();
const stringw username = m_username_widget->getText().trim();
const stringw password = m_password_widget->getText().trim();
stringw info = "";
if(CurrentOnlineUser::get()->signIn(username,password,info))
{
@ -106,15 +111,12 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
else
{
sfx_manager->quickSound( "anvil" );
Log::info("Login Dialog", "check1");
irr::video::SColor red(255, 255, 0, 0);
m_message_widget->setColor(red);
m_message_widget->setColor(irr::video::SColor(255, 255, 0, 0));
m_message_widget->setText(info, false);
Log::info("Login Dialog", "check2");
}
return GUIEngine::EVENT_BLOCK;
}
else if(eventSource == "sign_up")
else if(eventSource == "register")
{
m_open_registration_dialog = true;
return GUIEngine::EVENT_BLOCK;
@ -128,12 +130,10 @@ void LoginDialog::onEnterPressedInternal()
{
//If enter was pressed while "cancel" nor "signup" was selected, then interpret as "signin" press.
const int playerID = PLAYER_ID_GAME_MASTER;
ButtonWidget* cancelButton = getWidget<ButtonWidget>("cancel");
assert(cancelButton != NULL);
ButtonWidget* registerButton = getWidget<ButtonWidget>("sign_up");
assert(registerButton != NULL);
if (!GUIEngine::isFocusedForPlayer(cancelButton, playerID) &&
!GUIEngine::isFocusedForPlayer(registerButton, playerID))
if (!GUIEngine::isFocusedForPlayer(m_recovery_widget, playerID) &&
!GUIEngine::isFocusedForPlayer(m_register_widget, playerID) &&
!GUIEngine::isFocusedForPlayer(m_as_guest_widget, playerID) &&
!GUIEngine::isFocusedForPlayer(m_cancel_widget, playerID))
{
processEvent("sign_in");
}
@ -151,7 +151,13 @@ void LoginDialog::onUpdate(float dt)
{
ModalDialog::dismiss();
if (m_reshow_current_screen)
GUIEngine::reshowCurrentScreen();
/*Replaced to online state screen. Not 100% how I will handle this.
* Thee options :
* - Listener
* - Directly calling GUIEngine::reshowCurrentScreen(); (old option)
* - Underlying stateschreen is responsible for polling changed state (current option)
*/
true;//GUIEngine::reshowCurrentScreen();
if (m_open_registration_dialog)
new RegistrationDialog(0.8f, 0.9f);

View File

@ -23,6 +23,7 @@
#include "guiengine/modaldialog.hpp"
#include "guiengine/widgets/text_box_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "guiengine/widgets/label_widget.hpp"
/**
@ -37,8 +38,17 @@ private:
bool m_self_destroy;
bool m_open_registration_dialog;
bool m_reshow_current_screen;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::LabelWidget * m_info_widget;
GUIEngine::TextBoxWidget * m_username_widget;
GUIEngine::TextBoxWidget * m_password_widget;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::IconButtonWidget * m_sign_in_widget;
GUIEngine::IconButtonWidget * m_recovery_widget;
GUIEngine::IconButtonWidget * m_register_widget;
GUIEngine::IconButtonWidget * m_as_guest_widget;
GUIEngine::IconButtonWidget * m_cancel_widget;
public:
@ -57,7 +67,6 @@ public:
void onEnterPressedInternal();
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
void beforeAddingWidgets();
virtual void onUpdate(float dt);
//virtual void onTextUpdated();

View File

@ -100,6 +100,14 @@ void RegistrationDialog::showRegistrationInfo(){
LabelWidget * label = getWidget<LabelWidget>("info");
assert(label != NULL);
label->setColor(irr::video::SColor(255, 255, 0, 0));
label->setText(m_registration_error, false);
ButtonWidget * button = getWidget<ButtonWidget>("next");
assert(button != NULL);
button = getWidget<ButtonWidget>("cancel");
assert(button != NULL);
}
// -----------------------------------------------------------------------------
@ -184,14 +192,14 @@ bool RegistrationDialog::processTermsEvent(const std::string& eventSource){
{
assert(getWidget<CheckBoxWidget>("accepted")->getState());
m_agreement = true;
irr::core::stringw info;
if(CurrentOnlineUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, info))
if(CurrentOnlineUser::get()->signUp(m_username, m_password, m_password_confirm, m_email, true, m_registration_error))
{
m_show_registration_activation = true;
m_registration_error = "";
}
else
{
Log::error("Registration dialog", "Info : %s", irr::core::stringc(info.c_str()).c_str());
m_show_registration_info = true;
}
return true;
}

View File

@ -34,7 +34,7 @@ public:
{
Info = 1,
Terms = 2,
Activation = 3
Activation = 4
};
RegistrationDialog(const float percentWidth, const float percentHeight, const Phase phase = Info);
@ -58,6 +58,7 @@ private:
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;
void showRegistrationInfo();

View File

@ -26,8 +26,6 @@
#include "challenges/unlock_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/scalable_font.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
#include "input/device_manager.hpp"
#include "input/input_manager.hpp"
#include "io/file_manager.hpp"
@ -36,6 +34,7 @@
#include "states_screens/state_manager.hpp"
#include "states_screens/dialogs/login_dialog.hpp"
#include "states_screens/dialogs/message_dialog.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"
#include "modes/demo_world.hpp"
#include "utils/translation.hpp"
@ -50,46 +49,86 @@ DEFINE_SCREEN_SINGLETON( OnlineScreen );
OnlineScreen::OnlineScreen() : Screen("online/main.stkgui")
{
m_recorded_state = Not;
} // OnlineScreen
// ----------------------------------------------------------------------------
void OnlineScreen::loadedFromFile()
{
Log::info("OnlineScreen", "Loaded from file");
//Box ? FIXME
m_top_menu_widget = getWidget<RibbonWidget>("menu_toprow");
assert(m_top_menu_widget != NULL);
m_quick_play_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("quick_play");
assert(m_quick_play_widget != NULL);
m_find_server_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("find_server");
assert(m_find_server_widget != NULL);
m_create_server_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("create_server");
assert(m_create_server_widget != NULL);
m_online_status_widget = getWidget<LabelWidget>("online_status");
assert(m_online_status_widget != NULL);
m_bottom_menu_widget = getWidget<RibbonWidget>("menu_bottomrow");
assert(m_bottom_menu_widget != NULL);
m_sign_in_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("sign_in");
assert(m_sign_in_widget != NULL);
m_register_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("register");
assert(m_register_widget != NULL);
m_sign_out_widget = (IconButtonWidget *) m_bottom_menu_widget->findWidgetNamed("sign_out");
assert(m_sign_out_widget != NULL);
} // loadedFromFile
// ----------------------------------------------------------------------------
bool OnlineScreen::hasStateChanged()
{
State previous_state = m_recorded_state;
if(CurrentOnlineUser::get()->isSignedIn())
{
if(CurrentOnlineUser::get()->isGuest())
m_recorded_state = Guest;
else
m_recorded_state = Registered;
}
else
m_recorded_state = Not;
if (previous_state != m_recorded_state)
return true;
return false;
}
// ----------------------------------------------------------------------------
void OnlineScreen::beforeAddingWidget()
{
Log::info("OnlineScreen", "Before adding widget");
RibbonWidget* topRow = getWidget<RibbonWidget>("menu_toprow");
assert(topRow != NULL);
RibbonWidget* bottomRow = getWidget<RibbonWidget>("menu_bottomrow");
assert(bottomRow != NULL);
if(CurrentOnlineUser::get()->isSignedIn())
//Set all children of the bottom menu visible (again)
for(int i = 0; i < m_bottom_menu_widget->getRibbonChildren().size(); i++)
m_bottom_menu_widget->getRibbonChildren()[i].setVisible(true);
//Remove all badges of the top menu
for(int i = 0; i < m_top_menu_widget->getRibbonChildren().size(); i++)
m_top_menu_widget->getRibbonChildren()[i].resetAllBadges();
hasStateChanged();
if (m_recorded_state == Registered)
{
if(CurrentOnlineUser::get()->isGuest())
{
}
else
{
//Signed in and not guest
bottomRow->removeChildNamed("sign_in");
}
bottomRow->removeChildNamed("sign_up");
m_register_widget->setVisible(false);
m_sign_in_widget->setVisible(false);
}
else
else if (m_recorded_state == Not)
{
//bottomRow->removeChildNamed("sign_out");
IconButtonWidget* iconbutton = getWidget<IconButtonWidget>("sign_out");
iconbutton->setVisible(false);
IconButtonWidget* quick_play = getWidget<IconButtonWidget>("quick_play");
quick_play->setVisible(false);
m_quick_play_widget->setBadge(LOCKED_BADGE);
m_find_server_widget->setBadge(LOCKED_BADGE);
m_create_server_widget->setBadge(LOCKED_BADGE);
m_sign_out_widget->setVisible(false);
}
else if (m_recorded_state == Guest)
{
m_find_server_widget->setBadge(LOCKED_BADGE);
m_create_server_widget->setBadge(LOCKED_BADGE);
m_sign_in_widget->setVisible(false);
}
} // beforeAddingWidget
@ -98,18 +137,16 @@ void OnlineScreen::beforeAddingWidget()
void OnlineScreen::init()
{
Screen::init();
m_online_status_widget = getWidget<LabelWidget>("online_status");
assert(m_online_status_widget != NULL);
RibbonWidget* r = getWidget<RibbonWidget>("menu_bottomrow");
r->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
m_top_menu_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
DemoWorld::resetIdleTime();
m_online_status_widget->setText(irr::core::stringw("Signed in as : ") + CurrentOnlineUser::get()->getUserName(), true);
m_online_status_widget->setText(irr::core::stringw(_("Signed in as : ")) + CurrentOnlineUser::get()->getUserName() + ".", false);
} // init
// ----------------------------------------------------------------------------
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
if (hasStateChanged())
GUIEngine::reshowCurrentScreen();
} // onUpdate
// ----------------------------------------------------------------------------
@ -134,25 +171,35 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const
if (CurrentOnlineUser::get()->signOut())
{
new MessageDialog( _("Signed out successfully.") );
GUIEngine::reshowCurrentScreen();
//GUIEngine::reshowCurrentScreen();
}
else
{
new MessageDialog( _("An error occured while signing out.") );
}
}
else if (selection == "register")
{
new RegistrationDialog(0.8f, 0.9f);
}
else if (selection == "find_server")
{
new LoginDialog(LoginDialog::Registration_Required);
if (m_recorded_state == Registered)
new MessageDialog("Coming soon!");
else
new LoginDialog(LoginDialog::Registration_Required);
}
else if (selection == "create_server")
{
new LoginDialog(LoginDialog::Registration_Required);
if (m_recorded_state == Registered)
new MessageDialog("Coming soon!");
else
new LoginDialog(LoginDialog::Registration_Required);
}
else if (selection == "quick_play")
{
new LoginDialog(LoginDialog::Signing_In_Required);
if (m_recorded_state == Registered || m_recorded_state == Guest)
new MessageDialog("Coming soon!");
else
new LoginDialog(LoginDialog::Signing_In_Required);
}
} // eventCallback

View File

@ -20,6 +20,8 @@
#include "guiengine/screen.hpp"
#include "guiengine/widgets/label_widget.hpp"
#include "guiengine/widgets/ribbon_widget.hpp"
#include "guiengine/widgets/icon_button_widget.hpp"
namespace GUIEngine { class Widget; class ListWidget; }
@ -33,7 +35,30 @@ private:
friend class GUIEngine::ScreenSingleton<OnlineScreen>;
OnlineScreen();
GUIEngine::LabelWidget* m_online_status_widget;
GUIEngine::RibbonWidget * m_top_menu_widget;
GUIEngine::IconButtonWidget * m_quick_play_widget;
GUIEngine::IconButtonWidget * m_find_server_widget;
GUIEngine::IconButtonWidget * m_create_server_widget;
GUIEngine::LabelWidget * m_online_status_widget;
GUIEngine::RibbonWidget * m_bottom_menu_widget;
GUIEngine::IconButtonWidget * m_sign_in_widget;
GUIEngine::IconButtonWidget * m_register_widget;
GUIEngine::IconButtonWidget * m_sign_out_widget;
enum State
{
Not = 1,
Guest = 2,
Registered = 4
};
State m_recorded_state;
/** \brief Checks if the recorded state differs from the actual state and sets it. */
bool hasStateChanged();
public: