Lots of improvements, mainly related to login (dialog)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13576 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
1591eb4126
commit
217ec5ce9c
@ -27,6 +27,7 @@
|
|||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
#include "addons/addon.hpp"
|
#include "addons/addon.hpp"
|
||||||
#include "guiengine/dialog_queue.hpp"
|
#include "guiengine/dialog_queue.hpp"
|
||||||
|
#include "states_screens/dialogs/login_dialog.hpp"
|
||||||
#include "states_screens/dialogs/user_info_dialog.hpp"
|
#include "states_screens/dialogs/user_info_dialog.hpp"
|
||||||
#include "states_screens/dialogs/notification_dialog.hpp"
|
#include "states_screens/dialogs/notification_dialog.hpp"
|
||||||
#include "states_screens/online_profile_friends.hpp"
|
#include "states_screens/online_profile_friends.hpp"
|
||||||
@ -34,6 +35,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace Online;
|
using namespace Online;
|
||||||
|
|
||||||
@ -118,7 +120,7 @@ namespace Online{
|
|||||||
{
|
{
|
||||||
assert(m_state == US_SIGNED_OUT);
|
assert(m_state == US_SIGNED_OUT);
|
||||||
m_save_session = save_session;
|
m_save_session = save_session;
|
||||||
SignInRequest * request = new SignInRequest();
|
SignInRequest * request = new SignInRequest(request_now);
|
||||||
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||||
request->setParameter("action",std::string("connect"));
|
request->setParameter("action",std::string("connect"));
|
||||||
request->setParameter("username",username);
|
request->setParameter("username",username);
|
||||||
@ -135,9 +137,7 @@ namespace Online{
|
|||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
std::string token("");
|
int token_fetched = input->get("token", &m_token);
|
||||||
int token_fetched = input->get("token", &token);
|
|
||||||
setToken(token);
|
|
||||||
irr::core::stringw username("");
|
irr::core::stringw username("");
|
||||||
int username_fetched = input->get("username", &username);
|
int username_fetched = input->get("username", &username);
|
||||||
uint32_t userid(0);
|
uint32_t userid(0);
|
||||||
@ -156,12 +156,25 @@ namespace Online{
|
|||||||
HTTPManager::get()->startPolling();
|
HTTPManager::get()->startPolling();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
m_state = US_SIGNED_OUT;
|
m_state = US_SIGNED_OUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CurrentUser::SignInRequest::callback()
|
void CurrentUser::SignInRequest::callback()
|
||||||
{
|
{
|
||||||
CurrentUser::get()->signIn(m_success, m_result);
|
CurrentUser::get()->signIn(m_success, m_result);
|
||||||
|
if(GUIEngine::ModalDialog::isADialogActive())
|
||||||
|
{
|
||||||
|
LoginDialog * dialog = dynamic_cast<LoginDialog*>(GUIEngine::ModalDialog::getCurrent());
|
||||||
|
if(dialog != NULL)
|
||||||
|
{
|
||||||
|
if(m_success)
|
||||||
|
dialog->success();
|
||||||
|
else
|
||||||
|
dialog->error(m_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -211,7 +224,7 @@ namespace Online{
|
|||||||
{
|
{
|
||||||
Log::warn("CurrentUser::signOut", "%s", _("There were some connection issues while signing out. Report a bug if this caused issues."));
|
Log::warn("CurrentUser::signOut", "%s", _("There were some connection issues while signing out. Report a bug if this caused issues."));
|
||||||
}
|
}
|
||||||
setToken("");
|
m_token = "";
|
||||||
ProfileManager::get()->clearPersistent();
|
ProfileManager::get()->clearPersistent();
|
||||||
m_profile = NULL;
|
m_profile = NULL;
|
||||||
m_state = US_SIGNED_OUT;
|
m_state = US_SIGNED_OUT;
|
||||||
@ -504,17 +517,12 @@ namespace Online{
|
|||||||
for(unsigned int i = 0; i < friends.size(); ++i)
|
for(unsigned int i = 0; i < friends.size(); ++i)
|
||||||
{
|
{
|
||||||
bool now_online = false;
|
bool now_online = false;
|
||||||
std::vector<uint32_t>::iterator iter;
|
std::vector<uint32_t>::iterator iter =
|
||||||
for (iter = online_friends.begin(); iter != online_friends.end();)
|
std::find(online_friends.begin(),online_friends.end(), friends[i]);
|
||||||
|
if (iter != online_friends.end())
|
||||||
{
|
{
|
||||||
if (*iter == friends[i])
|
now_online = true;
|
||||||
{
|
online_friends.erase(iter);
|
||||||
now_online = true;
|
|
||||||
online_friends.erase(iter++);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
++iter;
|
|
||||||
}
|
}
|
||||||
Profile * profile = ProfileManager::get()->getProfileByID(friends[i]);
|
Profile * profile = ProfileManager::get()->getProfileByID(friends[i]);
|
||||||
Profile::RelationInfo * relation_info = profile->getRelationInfo();
|
Profile::RelationInfo * relation_info = profile->getRelationInfo();
|
||||||
|
@ -43,7 +43,7 @@ namespace Online{
|
|||||||
public:
|
public:
|
||||||
enum UserState
|
enum UserState
|
||||||
{
|
{
|
||||||
US_SIGNED_OUT,
|
US_SIGNED_OUT = 0,
|
||||||
US_SIGNED_IN,
|
US_SIGNED_IN,
|
||||||
US_GUEST,
|
US_GUEST,
|
||||||
US_SIGNING_IN,
|
US_SIGNING_IN,
|
||||||
@ -129,10 +129,6 @@ namespace Online{
|
|||||||
|
|
||||||
bool getSaveSession() const { return m_save_session; }
|
bool getSaveSession() const { return m_save_session; }
|
||||||
|
|
||||||
void setUserState (UserState user_state) { m_state = user_state; }
|
|
||||||
void setSaveSession (bool save_session) { m_save_session = save_session; }
|
|
||||||
void setToken (const std::string & token) { m_token= token; }
|
|
||||||
|
|
||||||
CurrentUser();
|
CurrentUser();
|
||||||
|
|
||||||
void signIn (bool success, const XMLNode * input);
|
void signIn (bool success, const XMLNode * input);
|
||||||
|
@ -43,12 +43,14 @@ LoginDialog::LoginDialog(const Message message_type, const LoginDialog::Listener
|
|||||||
m_self_destroy = false;
|
m_self_destroy = false;
|
||||||
m_open_registration_dialog = false;
|
m_open_registration_dialog = false;
|
||||||
m_open_recovery_dialog = false;
|
m_open_recovery_dialog = false;
|
||||||
m_sign_in_request = NULL;
|
m_success = false;
|
||||||
|
|
||||||
loadFromFile("online/login_dialog.stkgui");
|
loadFromFile("online/login_dialog.stkgui");
|
||||||
|
|
||||||
m_message_widget = getWidget<LabelWidget>("message");
|
m_message_widget = getWidget<LabelWidget>("message");
|
||||||
assert(m_message_widget != NULL);
|
assert(m_message_widget != NULL);
|
||||||
irr::core::stringw message;
|
|
||||||
|
irr::core::stringw message("");
|
||||||
if (message_type == Normal)
|
if (message_type == Normal)
|
||||||
message = _("Fill in your username and password. ");
|
message = _("Fill in your username and password. ");
|
||||||
else if (message_type == Signing_In_Required)
|
else if (message_type == Signing_In_Required)
|
||||||
@ -91,19 +93,14 @@ LoginDialog::LoginDialog(const Message message_type, const LoginDialog::Listener
|
|||||||
m_as_guest_widget->setDeactivated();
|
m_as_guest_widget->setDeactivated();
|
||||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||||
assert(m_cancel_widget != NULL);
|
assert(m_cancel_widget != NULL);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
LoginDialog::~LoginDialog()
|
LoginDialog::~LoginDialog()
|
||||||
{
|
{
|
||||||
delete m_sign_in_request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void LoginDialog::login()
|
void LoginDialog::login()
|
||||||
{
|
{
|
||||||
@ -118,7 +115,8 @@ void LoginDialog::login()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_options_widget->setDeactivated();
|
m_options_widget->setDeactivated();
|
||||||
m_sign_in_request = Online::CurrentUser::get()->requestSignIn(username,password, m_remember_widget->getState());
|
m_info_widget->setDefaultColor();
|
||||||
|
Online::CurrentUser::get()->requestSignIn(username,password, m_remember_widget->getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,53 +173,47 @@ bool LoginDialog::onEscapePressed()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void LoginDialog::success()
|
||||||
|
{
|
||||||
|
m_success = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
void LoginDialog::error(const irr::core::stringw & error)
|
||||||
|
{
|
||||||
|
sfx_manager->quickSound("anvil");
|
||||||
|
m_info_widget->setErrorColor();
|
||||||
|
m_info_widget->setText(error, false);
|
||||||
|
m_options_widget->setActivated();
|
||||||
|
m_as_guest_widget->setDeactivated();
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void LoginDialog::onUpdate(float dt)
|
void LoginDialog::onUpdate(float dt)
|
||||||
{
|
{
|
||||||
bool success = false;
|
if(!m_options_widget->isActivated())
|
||||||
if(m_sign_in_request != NULL)
|
m_info_widget->setText(Online::Messages::signingIn(), false);
|
||||||
{
|
|
||||||
if(m_sign_in_request->isDone())
|
|
||||||
{
|
|
||||||
if(m_sign_in_request->isSuccess())
|
|
||||||
{
|
|
||||||
success = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sfx_manager->quickSound( "anvil" );
|
|
||||||
m_info_widget->setErrorColor();
|
|
||||||
m_info_widget->setText(m_sign_in_request->getInfo(), false);
|
|
||||||
}
|
|
||||||
delete m_sign_in_request;
|
|
||||||
m_sign_in_request = NULL;
|
|
||||||
m_options_widget->setActivated();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_info_widget->setDefaultColor();
|
|
||||||
m_info_widget->setText(Online::Messages::signingIn(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//If we want to open another dialog, we need to close this one first
|
//If we want to open another dialog, we need to close this one first
|
||||||
m_self_destroy = m_open_registration_dialog || m_open_recovery_dialog || success;
|
m_self_destroy |= (m_open_registration_dialog || m_open_recovery_dialog || m_success);
|
||||||
|
|
||||||
|
|
||||||
|
bool open_registration_dialog = m_open_registration_dialog;
|
||||||
|
bool open_recovery_dialog = m_open_recovery_dialog;
|
||||||
|
bool success = m_success;
|
||||||
|
const LoginDialog::Listener *listener = m_listener;
|
||||||
|
|
||||||
// It's unsafe to delete from inside the event handler so we do it here
|
// It's unsafe to delete from inside the event handler so we do it here
|
||||||
if (m_self_destroy)
|
if (m_self_destroy)
|
||||||
{
|
{
|
||||||
// Get a copy of all member variables that are still needed after
|
|
||||||
// dismiss (which deletes this).
|
|
||||||
bool open_registration_dialog = m_open_registration_dialog;
|
|
||||||
bool open_recovery_dialog = m_open_recovery_dialog;
|
|
||||||
const LoginDialog::Listener *listener = m_listener;
|
|
||||||
ModalDialog::dismiss();
|
ModalDialog::dismiss();
|
||||||
if (open_registration_dialog)
|
if (open_registration_dialog)
|
||||||
new RegistrationDialog();
|
new RegistrationDialog();
|
||||||
else if (open_recovery_dialog)
|
else if (open_recovery_dialog)
|
||||||
new RecoveryDialog();
|
new RecoveryDialog();
|
||||||
else if (success && listener )
|
else if (success && (listener != NULL) )
|
||||||
listener->onSuccess();
|
listener->onClose();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,33 @@ public:
|
|||||||
class Listener
|
class Listener
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
virtual void onSuccess() const = 0;
|
virtual void onClose() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum Message
|
||||||
|
{
|
||||||
|
Normal = 0, // If the user presses the sign in button himself
|
||||||
|
Signing_In_Required = 1, // If the user needs to be signed in
|
||||||
|
Registration_Required = 2 // If the user needs to be registered
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a modal dialog with given percentage of screen width and height
|
||||||
|
*/
|
||||||
|
LoginDialog(const Message = Normal, const LoginDialog::Listener * = NULL);
|
||||||
|
~LoginDialog();
|
||||||
|
|
||||||
|
virtual void onEnterPressedInternal();
|
||||||
|
void success();
|
||||||
|
void error(const irr::core::stringw & error_message);
|
||||||
|
|
||||||
|
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||||
|
|
||||||
|
virtual bool onEscapePressed();
|
||||||
|
virtual void onUpdate(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const Listener * m_listener;
|
const Listener * m_listener;
|
||||||
@ -47,7 +71,8 @@ private:
|
|||||||
bool m_self_destroy;
|
bool m_self_destroy;
|
||||||
bool m_open_registration_dialog;
|
bool m_open_registration_dialog;
|
||||||
bool m_open_recovery_dialog;
|
bool m_open_recovery_dialog;
|
||||||
const Online::CurrentUser::SignInRequest * m_sign_in_request;
|
bool m_success;
|
||||||
|
|
||||||
GUIEngine::LabelWidget * m_message_widget;
|
GUIEngine::LabelWidget * m_message_widget;
|
||||||
GUIEngine::TextBoxWidget * m_username_widget;
|
GUIEngine::TextBoxWidget * m_username_widget;
|
||||||
GUIEngine::TextBoxWidget * m_password_widget;
|
GUIEngine::TextBoxWidget * m_password_widget;
|
||||||
@ -62,29 +87,6 @@ private:
|
|||||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||||
|
|
||||||
void login();
|
void login();
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum Message
|
|
||||||
{
|
|
||||||
Normal = 1, // If the user presses the sign in button himself
|
|
||||||
Signing_In_Required = 2, // If the user needs to be signed in
|
|
||||||
Registration_Required = 3 // If the user needs to be registered
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a modal dialog with given percentage of screen width and height
|
|
||||||
*/
|
|
||||||
LoginDialog(const Message, const LoginDialog::Listener * = NULL);
|
|
||||||
~LoginDialog();
|
|
||||||
|
|
||||||
void onEnterPressedInternal();
|
|
||||||
|
|
||||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
|
||||||
|
|
||||||
virtual bool onEscapePressed();
|
|
||||||
virtual void onUpdate(float dt);
|
|
||||||
//virtual void onTextUpdated();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,7 +39,7 @@ public :
|
|||||||
const std::string m_addon_id;
|
const std::string m_addon_id;
|
||||||
public :
|
public :
|
||||||
LoginListener(const std::string & addon_id) : m_addon_id(addon_id) {}
|
LoginListener(const std::string & addon_id) : m_addon_id(addon_id) {}
|
||||||
virtual void onSuccess() const { new VoteDialog(m_addon_id); }
|
virtual void onClose() const { new VoteDialog(m_addon_id); }
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -69,7 +69,9 @@ OnlineScreen::~OnlineScreen()
|
|||||||
|
|
||||||
void OnlineScreen::loadedFromFile()
|
void OnlineScreen::loadedFromFile()
|
||||||
{
|
{
|
||||||
//Box ? FIXME
|
m_back_widget = getWidget<IconButtonWidget>("back");
|
||||||
|
assert(m_back_widget != NULL);
|
||||||
|
|
||||||
m_top_menu_widget = getWidget<RibbonWidget>("menu_toprow");
|
m_top_menu_widget = getWidget<RibbonWidget>("menu_toprow");
|
||||||
assert(m_top_menu_widget != NULL);
|
assert(m_top_menu_widget != NULL);
|
||||||
m_quick_play_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("quick_play");
|
m_quick_play_widget = (IconButtonWidget *) m_top_menu_widget->findWidgetNamed("quick_play");
|
||||||
@ -156,7 +158,11 @@ void OnlineScreen::init()
|
|||||||
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
||||||
{
|
{
|
||||||
if (hasStateChanged())
|
if (hasStateChanged())
|
||||||
|
{
|
||||||
GUIEngine::reshowCurrentScreen();
|
GUIEngine::reshowCurrentScreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_recorded_state == CurrentUser::US_SIGNING_IN)
|
if (m_recorded_state == CurrentUser::US_SIGNING_IN)
|
||||||
{
|
{
|
||||||
m_online_status_widget->setText(Messages::signingIn(), false);
|
m_online_status_widget->setText(Messages::signingIn(), false);
|
||||||
@ -171,7 +177,7 @@ void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
|
|||||||
|
|
||||||
void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const int playerID)
|
void OnlineScreen::eventCallback(Widget* widget, const std::string& name, const int playerID)
|
||||||
{
|
{
|
||||||
if (name == "back")
|
if (name == m_back_widget->m_properties[PROP_ID])
|
||||||
{
|
{
|
||||||
StateManager::get()->escapePressed();
|
StateManager::get()->escapePressed();
|
||||||
return;
|
return;
|
||||||
|
@ -40,6 +40,8 @@ private:
|
|||||||
OnlineScreen();
|
OnlineScreen();
|
||||||
~OnlineScreen();
|
~OnlineScreen();
|
||||||
|
|
||||||
|
GUIEngine::IconButtonWidget * m_back_widget;
|
||||||
|
|
||||||
GUIEngine::RibbonWidget * m_top_menu_widget;
|
GUIEngine::RibbonWidget * m_top_menu_widget;
|
||||||
GUIEngine::IconButtonWidget * m_quick_play_widget;
|
GUIEngine::IconButtonWidget * m_quick_play_widget;
|
||||||
GUIEngine::IconButtonWidget * m_find_server_widget;
|
GUIEngine::IconButtonWidget * m_find_server_widget;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user