[GSoC uni] Small increment.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@12900 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
be11ce1cd0
commit
a3ec5c3d97
@ -3,25 +3,37 @@
|
|||||||
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
|
<div x="2%" y="10%" width="96%" height="80%" layout="vertical-row" >
|
||||||
|
|
||||||
|
|
||||||
<label id="title" width="100%" text_align="center" word_wrap="true"
|
<label id="title" width="100%" height="fit" text_align="center" word_wrap="true"
|
||||||
I18N="In the 'add new player' dialog" text="Sign in" proportion="1" />
|
I18N="In the login dialog' dialog" text="Sign in" proportion="1" />
|
||||||
|
|
||||||
<spacer height="25" width="10" />
|
<spacer height="25" width="10" />
|
||||||
|
|
||||||
|
<div width="95%" height="fit" layout="horizontal-row" >
|
||||||
<div width="75%" height="fit" layout="horizontal-row" >
|
<label proportion="1" text_align="center" I18N="In the login form" text="Username"/>
|
||||||
<label proportion="1" height="100%" text_align="center" I18N="In the login form" text="Username"/>
|
<div proportion="2" height="fit" layout="horizontal-row" >
|
||||||
<div proportion="1" height="fit" layout="horizontal-row" >
|
<textbox id="username" width="100%" I18N="In the login dialog" align="center"/>
|
||||||
<textbox id="username" width="100%" I18N="In the 'login' dialog" align="center"/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<spacer height="20" width="20" />
|
<spacer height="20" width="20" />
|
||||||
|
|
||||||
<!-- TODO: ok button? -->
|
<div width="95%" height="fit" layout="horizontal-row" >
|
||||||
|
<label proportion="1" text_align="center" I18N="In the login form" text="Password"/>
|
||||||
|
<div proportion="2" height="fit" layout="horizontal-row" >
|
||||||
|
<textbox id="password" width="100%" I18N="In the login dialog" align="center"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<spacer height="20" width="20" />
|
||||||
|
|
||||||
|
<label id="errormsg" width="100%" height="fit" text_align="center" word_wrap="true"
|
||||||
|
I18N="In the login dialog' dialog" text="" proportion="1" />
|
||||||
|
|
||||||
|
<spacer height="20" width="20" />
|
||||||
|
|
||||||
|
<button id="signin" height="fit" I18N="In the login dialog" text="Sign In" align="center"/>
|
||||||
|
<button id="cancel" height="fit" I18N="In the login dialog" text="Cancel" align="center"/>
|
||||||
|
|
||||||
<button id="cancel" I18N="When configuring input" text="Press ESC to cancel" align="center"/>
|
|
||||||
|
|
||||||
<spacer height="15" width="20" />
|
<spacer height="15" width="20" />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -128,6 +128,15 @@ stringw TextBoxWidget::getText() const
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void TextBoxWidget::setPasswordBox(bool passwordBox, wchar_t passwordChar)
|
||||||
|
{
|
||||||
|
IGUIEditBox* textCtrl = Widget::getIrrlichtElement<IGUIEditBox>();
|
||||||
|
assert(textCtrl != NULL);
|
||||||
|
textCtrl->setPasswordBox(passwordBox, passwordChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
EventPropagation TextBoxWidget::focused(const int playerID)
|
EventPropagation TextBoxWidget::focused(const int playerID)
|
||||||
{
|
{
|
||||||
assert(playerID == 0); // No support for multiple players in text areas!
|
assert(playerID == 0); // No support for multiple players in text areas!
|
||||||
|
@ -68,6 +68,7 @@ namespace GUIEngine
|
|||||||
void clearListeners();
|
void clearListeners();
|
||||||
|
|
||||||
irr::core::stringw getText() const;
|
irr::core::stringw getText() const;
|
||||||
|
void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
|
||||||
|
|
||||||
virtual void elementRemoved();
|
virtual void elementRemoved();
|
||||||
};
|
};
|
||||||
|
@ -49,8 +49,9 @@ CurrentOnlineUser::CurrentOnlineUser(){
|
|||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
bool CurrentOnlineUser::signIn(const std::string &username, const std::string &password)
|
bool CurrentOnlineUser::signIn(const stringw &username, const stringw &password)
|
||||||
{
|
{
|
||||||
|
return false; //FIXME : only temporary
|
||||||
assert(m_is_signed_in == false);
|
assert(m_is_signed_in == false);
|
||||||
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
HTTPConnector * connector = new HTTPConnector((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||||
HTTPConnector::Parameters parameters;
|
HTTPConnector::Parameters parameters;
|
||||||
@ -73,7 +74,7 @@ bool CurrentOnlineUser::signIn(const std::string &username, const std::string &p
|
|||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
std::string CurrentOnlineUser::getUserName() const
|
core::stringw CurrentOnlineUser::getUserName() const
|
||||||
{
|
{
|
||||||
if(m_is_signed_in){
|
if(m_is_signed_in){
|
||||||
assert(m_user != NULL);
|
assert(m_user != NULL);
|
||||||
|
@ -19,9 +19,10 @@
|
|||||||
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
|
#ifndef HEADER_CURRENT_ONLINE_USER_HPP
|
||||||
#define HEADER_CURRENT_ONLINE_USER_HPP
|
#define HEADER_CURRENT_ONLINE_USER_HPP
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "online/online_user.hpp"
|
#include "online/online_user.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <irrString.h>
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -44,9 +45,10 @@ class CurrentOnlineUser
|
|||||||
// singleton
|
// singleton
|
||||||
static CurrentOnlineUser* get();
|
static CurrentOnlineUser* get();
|
||||||
static void deallocate();
|
static void deallocate();
|
||||||
bool signIn(const std::string &username, const std::string &password);
|
bool signIn(const core::stringw &username, const core::stringw &password);
|
||||||
/** Returns the username if signed in. */
|
/** Returns the username if signed in. */
|
||||||
std::string getUserName() const;
|
core::stringw getUserName() const;
|
||||||
|
bool isSignedIn(){ return m_is_signed_in; }
|
||||||
|
|
||||||
}; // class CurrentOnlineUser
|
}; // class CurrentOnlineUser
|
||||||
|
|
||||||
|
@ -60,8 +60,7 @@ XMLNode * HTTPConnector::getXMLFromPage(Parameters & post_parameters)
|
|||||||
std::string HTTPConnector::getPage(Parameters & post_parameters)
|
std::string HTTPConnector::getPage(Parameters & post_parameters)
|
||||||
{
|
{
|
||||||
Parameters::iterator iter;
|
Parameters::iterator iter;
|
||||||
std::string postString;
|
core::stringw postString;
|
||||||
|
|
||||||
for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter)
|
for (iter = post_parameters.begin(); iter != post_parameters.end(); ++iter)
|
||||||
{
|
{
|
||||||
if(iter != post_parameters.begin())
|
if(iter != post_parameters.begin())
|
||||||
@ -70,15 +69,16 @@ std::string HTTPConnector::getPage(Parameters & post_parameters)
|
|||||||
postString.append("=");
|
postString.append("=");
|
||||||
postString.append(iter->second);
|
postString.append(iter->second);
|
||||||
}
|
}
|
||||||
printf("Poststring: %s\n", postString.c_str());
|
|
||||||
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
|
curl_easy_setopt(this->curl, CURLOPT_POSTFIELDS, postString.c_str());
|
||||||
std::string readBuffer;
|
std::string readBuffer;
|
||||||
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||||
curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer);
|
curl_easy_setopt(this->curl, CURLOPT_FILE, &readBuffer);
|
||||||
res = curl_easy_perform(this->curl);
|
res = curl_easy_perform(this->curl);
|
||||||
if(res != CURLE_OK)
|
if(res != CURLE_OK)
|
||||||
|
{
|
||||||
Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
Log::error("online/http_functions", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||||
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
printf("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||||
|
}
|
||||||
return readBuffer;
|
return readBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "io/xml_node.hpp"
|
#include "io/xml_node.hpp"
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include <irrString.h>
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Class to connect with a server over HTTP
|
* \brief Class to connect with a server over HTTP
|
||||||
@ -34,7 +36,7 @@ class HTTPConnector
|
|||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef std::map <std::string, std::string> Parameters;
|
typedef std::map<core::stringw, core::stringw> Parameters;
|
||||||
HTTPConnector(const std::string &url);
|
HTTPConnector(const std::string &url);
|
||||||
~HTTPConnector();
|
~HTTPConnector();
|
||||||
std::string getPage(Parameters & post_parameters);
|
std::string getPage(Parameters & post_parameters);
|
||||||
|
@ -24,8 +24,8 @@
|
|||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
OnlineUser::OnlineUser(const std::string &username)
|
OnlineUser::OnlineUser(const core::stringw &username)
|
||||||
{
|
{
|
||||||
|
m_username = username;
|
||||||
} // OnlineUser
|
} // OnlineUser
|
||||||
|
|
||||||
|
@ -19,7 +19,8 @@
|
|||||||
#ifndef HEADER_ONLINE_USER_HPP
|
#ifndef HEADER_ONLINE_USER_HPP
|
||||||
#define HEADER_ONLINE_USER_HPP
|
#define HEADER_ONLINE_USER_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <irrString.h>
|
||||||
|
using namespace irr;
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -34,17 +35,17 @@ class OnlineUser
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::string m_username;
|
core::stringw m_username;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
OnlineUser(const std::string &username);
|
OnlineUser(const core::stringw &username);
|
||||||
|
|
||||||
/** Returns the username. */
|
/** Returns the username. */
|
||||||
std::string getUserName() const { return m_username; }
|
core::stringw getUserName() const { return m_username; }
|
||||||
|
|
||||||
}; // class OnlineUser
|
}; // class OnlineUser
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include "guiengine/widgets/text_box_widget.hpp"
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
using namespace irr;
|
using namespace irr;
|
||||||
@ -101,20 +103,7 @@ void EnterPlayerNameDialog::onEnterPressedInternal()
|
|||||||
// ---- Otherwise, see if we can accept the new name
|
// ---- Otherwise, see if we can accept the new name
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("textfield");
|
||||||
stringw playerName = textCtrl->getText().trim();
|
stringw playerName = textCtrl->getText().trim();
|
||||||
const int size = playerName.size();
|
if (StringUtils::notEmpty(playerName))
|
||||||
|
|
||||||
// sanity check
|
|
||||||
int nonEmptyChars = 0;
|
|
||||||
for (int n=0; n<size; n++)
|
|
||||||
{
|
|
||||||
if (playerName[n] != L' ')
|
|
||||||
{
|
|
||||||
nonEmptyChars++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (size > 0 && nonEmptyChars > 0)
|
|
||||||
{
|
{
|
||||||
// check for duplicates
|
// check for duplicates
|
||||||
const int amount = UserConfigParams::m_all_players.size();
|
const int amount = UserConfigParams::m_all_players.size();
|
||||||
|
@ -28,8 +28,10 @@
|
|||||||
#include "guiengine/widgets/text_box_widget.hpp"
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "states_screens/state_manager.hpp"
|
#include "states_screens/state_manager.hpp"
|
||||||
#include "utils/translation.hpp"
|
#include "utils/translation.hpp"
|
||||||
|
#include "utils/string_utils.hpp"
|
||||||
#include "online/current_online_user.hpp"
|
#include "online/current_online_user.hpp"
|
||||||
|
|
||||||
|
|
||||||
using namespace GUIEngine;
|
using namespace GUIEngine;
|
||||||
using namespace irr;
|
using namespace irr;
|
||||||
using namespace irr::gui;
|
using namespace irr::gui;
|
||||||
@ -42,11 +44,13 @@ LoginDialog::LoginDialog(const float w, const float h) :
|
|||||||
m_self_destroy = false;
|
m_self_destroy = false;
|
||||||
loadFromFile("login_dialog.stkgui");
|
loadFromFile("login_dialog.stkgui");
|
||||||
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username");
|
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("password");
|
||||||
|
assert(textCtrl != NULL);
|
||||||
|
textCtrl->setPasswordBox(true,L'*');
|
||||||
|
|
||||||
|
textCtrl = getWidget<TextBoxWidget>("username");
|
||||||
assert(textCtrl != NULL);
|
assert(textCtrl != NULL);
|
||||||
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
textCtrl->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||||
|
|
||||||
//if (translations->isRTLLanguage()) textCtrl->addListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -64,6 +68,36 @@ GUIEngine::EventPropagation LoginDialog::processEvent(const std::string& eventSo
|
|||||||
dismiss();
|
dismiss();
|
||||||
return GUIEngine::EVENT_BLOCK;
|
return GUIEngine::EVENT_BLOCK;
|
||||||
}
|
}
|
||||||
|
else if(eventSource == "signin")
|
||||||
|
{
|
||||||
|
// ---- See if we can accept the input
|
||||||
|
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username");
|
||||||
|
const stringw username = textCtrl->getText().trim();
|
||||||
|
if (!StringUtils::notEmpty(username)){
|
||||||
|
getWidget<LabelWidget>("errormsg")->setText(_("Username was empty"), false);
|
||||||
|
sfx_manager->quickSound( "anvil" );
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
textCtrl = getWidget<TextBoxWidget>("password");
|
||||||
|
const stringw password = textCtrl->getText().trim();
|
||||||
|
if (!StringUtils::notEmpty(password)){
|
||||||
|
getWidget<LabelWidget>("errormsg")->setText(_("Password was empty"), false);
|
||||||
|
sfx_manager->quickSound( "anvil" );
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(CurrentOnlineUser::get()->signIn(username, password))
|
||||||
|
{
|
||||||
|
m_self_destroy = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getWidget<LabelWidget>("errormsg")->setText(_("Signing in went wrong."), false);
|
||||||
|
sfx_manager->quickSound( "anvil" );
|
||||||
|
m_self_destroy = false;
|
||||||
|
}
|
||||||
|
return GUIEngine::EVENT_BLOCK;
|
||||||
|
}
|
||||||
return GUIEngine::EVENT_LET;
|
return GUIEngine::EVENT_LET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,40 +115,7 @@ void LoginDialog::onEnterPressedInternal()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Otherwise, see if we can accept the new name
|
|
||||||
TextBoxWidget* textCtrl = getWidget<TextBoxWidget>("username");
|
|
||||||
stringw username = textCtrl->getText().trim();
|
|
||||||
const int size = username.size();
|
|
||||||
|
|
||||||
// sanity check
|
|
||||||
int nonEmptyChars = 0;
|
|
||||||
for (int n=0; n<size; n++)
|
|
||||||
{
|
|
||||||
if (username[n] != L' ')
|
|
||||||
{
|
|
||||||
nonEmptyChars++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::string msg;
|
|
||||||
if (size > 0 && nonEmptyChars > 0)
|
|
||||||
{
|
|
||||||
Log::info("Login Dialog","Username : %ls", username.c_str());
|
|
||||||
if(CurrentOnlineUser::get()->signIn(core::stringc(username.c_str()).c_str(), ""))
|
|
||||||
{
|
|
||||||
m_self_destroy = true;
|
|
||||||
}else{
|
|
||||||
msg = "Signing in failed.";
|
|
||||||
m_self_destroy = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // if valid name
|
|
||||||
else
|
|
||||||
msg = "Invalid username.";
|
|
||||||
{
|
|
||||||
LabelWidget* label = getWidget<LabelWidget>("title");
|
|
||||||
label->setText(_(msg.c_str()), false);
|
|
||||||
sfx_manager->quickSound( "anvil" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -110,6 +110,23 @@ namespace StringUtils
|
|||||||
return filename;
|
return filename;
|
||||||
} // getExtension
|
} // getExtension
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/** Checks if the input string is not empty. ( = has characters different from a space)
|
||||||
|
*/
|
||||||
|
bool notEmpty(const irr::core::stringw& input)
|
||||||
|
{
|
||||||
|
const int size = input.size();
|
||||||
|
int nonEmptyChars = 0;
|
||||||
|
for (int n=0; n<size; n++)
|
||||||
|
{
|
||||||
|
if (input[n] != L' ')
|
||||||
|
{
|
||||||
|
nonEmptyChars++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (nonEmptyChars > 0);
|
||||||
|
} // getExtension
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
/** Returns a string converted to upper case.
|
/** Returns a string converted to upper case.
|
||||||
*/
|
*/
|
||||||
|
@ -41,6 +41,8 @@ namespace StringUtils
|
|||||||
std::string removeExtension(const std::string& filename);
|
std::string removeExtension(const std::string& filename);
|
||||||
std::string getExtension(const std::string& filename);
|
std::string getExtension(const std::string& filename);
|
||||||
|
|
||||||
|
bool notEmpty(const irr::core::stringw& input);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string toString (const T& any)
|
std::string toString (const T& any)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user