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:
unitraxx 2013-08-27 00:07:29 +00:00
parent 1591eb4126
commit 217ec5ce9c
7 changed files with 95 additions and 89 deletions

View File

@ -27,6 +27,7 @@
#include "utils/translation.hpp"
#include "addons/addon.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/notification_dialog.hpp"
#include "states_screens/online_profile_friends.hpp"
@ -34,6 +35,7 @@
#include <sstream>
#include <stdlib.h>
#include <assert.h>
#include <algorithm>
using namespace Online;
@ -118,7 +120,7 @@ namespace Online{
{
assert(m_state == US_SIGNED_OUT);
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->setParameter("action",std::string("connect"));
request->setParameter("username",username);
@ -135,9 +137,7 @@ namespace Online{
{
if (success)
{
std::string token("");
int token_fetched = input->get("token", &token);
setToken(token);
int token_fetched = input->get("token", &m_token);
irr::core::stringw username("");
int username_fetched = input->get("username", &username);
uint32_t userid(0);
@ -156,12 +156,25 @@ namespace Online{
HTTPManager::get()->startPolling();
}
else
{
m_state = US_SIGNED_OUT;
}
}
void CurrentUser::SignInRequest::callback()
{
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."));
}
setToken("");
m_token = "";
ProfileManager::get()->clearPersistent();
m_profile = NULL;
m_state = US_SIGNED_OUT;
@ -504,17 +517,12 @@ namespace Online{
for(unsigned int i = 0; i < friends.size(); ++i)
{
bool now_online = false;
std::vector<uint32_t>::iterator iter;
for (iter = online_friends.begin(); iter != online_friends.end();)
std::vector<uint32_t>::iterator iter =
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++);
break;
}
else
++iter;
now_online = true;
online_friends.erase(iter);
}
Profile * profile = ProfileManager::get()->getProfileByID(friends[i]);
Profile::RelationInfo * relation_info = profile->getRelationInfo();

View File

@ -43,7 +43,7 @@ namespace Online{
public:
enum UserState
{
US_SIGNED_OUT,
US_SIGNED_OUT = 0,
US_SIGNED_IN,
US_GUEST,
US_SIGNING_IN,
@ -129,10 +129,6 @@ namespace Online{
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();
void signIn (bool success, const XMLNode * input);

View File

@ -43,12 +43,14 @@ LoginDialog::LoginDialog(const Message message_type, const LoginDialog::Listener
m_self_destroy = false;
m_open_registration_dialog = false;
m_open_recovery_dialog = false;
m_sign_in_request = NULL;
m_success = false;
loadFromFile("online/login_dialog.stkgui");
m_message_widget = getWidget<LabelWidget>("message");
assert(m_message_widget != NULL);
irr::core::stringw message;
irr::core::stringw message("");
if (message_type == Normal)
message = _("Fill in your username and password. ");
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_cancel_widget = getWidget<IconButtonWidget>("cancel");
assert(m_cancel_widget != NULL);
}
// -----------------------------------------------------------------------------
LoginDialog::~LoginDialog()
{
delete m_sign_in_request;
}
// -----------------------------------------------------------------------------
void LoginDialog::login()
{
@ -118,7 +115,8 @@ void LoginDialog::login()
else
{
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;
}
// -----------------------------------------------------------------------------
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)
{
bool success = false;
if(m_sign_in_request != NULL)
{
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(!m_options_widget->isActivated())
m_info_widget->setText(Online::Messages::signingIn(), false);
//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
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();
if (open_registration_dialog)
new RegistrationDialog();
else if (open_recovery_dialog)
new RecoveryDialog();
else if (success && listener )
listener->onSuccess();
else if (success && (listener != NULL) )
listener->onClose();
return;
}
}

View File

@ -37,9 +37,33 @@ public:
class Listener
{
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:
const Listener * m_listener;
@ -47,7 +71,8 @@ private:
bool m_self_destroy;
bool m_open_registration_dialog;
bool m_open_recovery_dialog;
const Online::CurrentUser::SignInRequest * m_sign_in_request;
bool m_success;
GUIEngine::LabelWidget * m_message_widget;
GUIEngine::TextBoxWidget * m_username_widget;
GUIEngine::TextBoxWidget * m_password_widget;
@ -62,29 +87,6 @@ private:
GUIEngine::IconButtonWidget * m_cancel_widget;
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

View File

@ -39,7 +39,7 @@ public :
const std::string m_addon_id;
public :
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:

View File

@ -69,7 +69,9 @@ OnlineScreen::~OnlineScreen()
void OnlineScreen::loadedFromFile()
{
//Box ? FIXME
m_back_widget = getWidget<IconButtonWidget>("back");
assert(m_back_widget != NULL);
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");
@ -156,7 +158,11 @@ void OnlineScreen::init()
void OnlineScreen::onUpdate(float delta, irr::video::IVideoDriver* driver)
{
if (hasStateChanged())
{
GUIEngine::reshowCurrentScreen();
return;
}
if (m_recorded_state == CurrentUser::US_SIGNING_IN)
{
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)
{
if (name == "back")
if (name == m_back_widget->m_properties[PROP_ID])
{
StateManager::get()->escapePressed();
return;

View File

@ -40,6 +40,8 @@ private:
OnlineScreen();
~OnlineScreen();
GUIEngine::IconButtonWidget * m_back_widget;
GUIEngine::RibbonWidget * m_top_menu_widget;
GUIEngine::IconButtonWidget * m_quick_play_widget;
GUIEngine::IconButtonWidget * m_find_server_widget;