Dialog screens now pop up when a friend comes online ! hurray
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13523 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
a4bb17d2ca
commit
72a3015e1a
@ -28,6 +28,7 @@
|
||||
#include "addons/addon.hpp"
|
||||
#include "guiengine/dialog_queue.hpp"
|
||||
#include "states_screens/dialogs/user_info_dialog.hpp"
|
||||
#include "states_screens/dialogs/message_dialog.hpp"
|
||||
#include "states_screens/online_profile_friends.hpp"
|
||||
|
||||
#include <sstream>
|
||||
@ -407,9 +408,90 @@ namespace Online{
|
||||
// ============================================================================
|
||||
void CurrentUser::requestPoll()
|
||||
{
|
||||
//FIXME
|
||||
assert(isRegisteredUser());
|
||||
CurrentUser::PollRequest * request = new CurrentUser::PollRequest();
|
||||
request->setURL((std::string)UserConfigParams::m_server_multiplayer + "client-user.php");
|
||||
request->setParameter("action", std::string("poll"));
|
||||
request->setParameter("token", getToken());
|
||||
request->setParameter("userid", getID());
|
||||
HTTPManager::get()->addRequest(request);
|
||||
}
|
||||
|
||||
void CurrentUser::PollRequest::callback()
|
||||
{
|
||||
if(m_success)
|
||||
{
|
||||
std::string online_friends_string("");
|
||||
m_result->get("online", &online_friends_string);
|
||||
std::vector<std::string> parts = StringUtils::split(online_friends_string, ' ');
|
||||
std::vector<uint32_t> online_friends;
|
||||
for(unsigned int i = 0; i < parts.size(); ++i)
|
||||
{
|
||||
online_friends.push_back(atoi(parts[i].c_str()));
|
||||
}
|
||||
std::vector<uint32_t> friends = CurrentUser::get()->getProfile()->getFriends();
|
||||
std::vector<irr::core::stringw> to_notify;
|
||||
for(unsigned int i = 0; i < friends.size(); ++i)
|
||||
{
|
||||
std::vector<uint32_t>::iterator iter;
|
||||
for (iter = online_friends.begin(); iter != online_friends.end();)
|
||||
{
|
||||
if (*iter == friends[i])
|
||||
{
|
||||
online_friends.erase(iter++);
|
||||
break;
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
bool now_online = false;
|
||||
if(iter != online_friends.end())
|
||||
now_online = true;
|
||||
|
||||
Profile * profile = ProfileManager::get()->getProfileByID(friends[i]);
|
||||
Profile::RelationInfo * relation_info = profile->getRelationInfo();
|
||||
if( relation_info->isOnline() )
|
||||
{
|
||||
if (!now_online)
|
||||
relation_info->setOnline(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (now_online)
|
||||
{
|
||||
relation_info->setOnline(true);
|
||||
to_notify.push_back(profile->getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(to_notify.size() > 0)
|
||||
{
|
||||
irr::core::stringw message("");
|
||||
if(to_notify.size() == 1)
|
||||
{
|
||||
message = to_notify[0] + _(" is now online.");
|
||||
}
|
||||
else if(to_notify.size() == 2)
|
||||
{
|
||||
message = to_notify[0] + _(" and ") + to_notify[1] + _(" are now online.");
|
||||
}
|
||||
else if(to_notify.size() == 3)
|
||||
{
|
||||
message = to_notify[0] + _(", ") + to_notify[1] + _(" and ") + to_notify[2] + _(" are now online.");
|
||||
}
|
||||
else if(to_notify.size() > 3)
|
||||
{
|
||||
message = StringUtils::toWString(to_notify.size()) + _(" friends are now online.");
|
||||
}
|
||||
GUIEngine::DialogQueue::get()->pushDialog( new MessageDialog(message, true), false);
|
||||
OnlineProfileFriends::getInstance()->refreshFriendsList();
|
||||
}
|
||||
}
|
||||
// FIXME show connection error?
|
||||
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
irr::core::stringw CurrentUser::getUserName() const
|
||||
|
@ -102,6 +102,12 @@ namespace Online{
|
||||
DeclineFriendRequest() : XMLRequest(true) {}
|
||||
};
|
||||
|
||||
class PollRequest : public XMLRequest {
|
||||
virtual void callback ();
|
||||
public:
|
||||
PollRequest() : XMLRequest(true) {}
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
std::string m_token;
|
||||
|
@ -47,8 +47,8 @@
|
||||
using namespace Online;
|
||||
|
||||
namespace Online{
|
||||
#define MENU_POLLING_INTERVAL 5.0f
|
||||
#define GAME_POLLING_INTERVAL 10.0f
|
||||
#define MENU_POLLING_INTERVAL 10.0f
|
||||
#define GAME_POLLING_INTERVAL 15.0f
|
||||
|
||||
static HTTPManager * http_singleton = NULL;
|
||||
|
||||
|
@ -32,15 +32,24 @@ using namespace GUIEngine;
|
||||
MessageDialog::MessageDialog(irr::core::stringw msg, MessageDialogType type, IConfirmDialogListener* listener, bool own_listener) :
|
||||
ModalDialog(0.6f, 0.6f)
|
||||
{
|
||||
doInit(msg, type, listener, own_listener);
|
||||
m_msg = msg;
|
||||
doInit(type, listener, own_listener);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
MessageDialog::MessageDialog(irr::core::stringw msg) :
|
||||
MessageDialog::MessageDialog(irr::core::stringw msg, bool from_queue) :
|
||||
ModalDialog(0.6f, 0.6f)
|
||||
{
|
||||
doInit(msg, MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
|
||||
m_msg = msg;
|
||||
if(!from_queue) load();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
void MessageDialog::load()
|
||||
{
|
||||
doInit(MessageDialog::MESSAGE_DIALOG_OK, NULL, false);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
@ -57,7 +66,7 @@ MessageDialog::~MessageDialog()
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
void MessageDialog::doInit(irr::core::stringw msg, MessageDialogType type,
|
||||
void MessageDialog::doInit(MessageDialogType type,
|
||||
IConfirmDialogListener* listener, bool own_listener)
|
||||
{
|
||||
if (StateManager::get()->getGameState() == GUIEngine::GAME)
|
||||
@ -72,7 +81,7 @@ void MessageDialog::doInit(irr::core::stringw msg, MessageDialogType type,
|
||||
m_own_listener = own_listener;
|
||||
|
||||
LabelWidget* message = getWidget<LabelWidget>("title");
|
||||
message->setText( msg.c_str(), false );
|
||||
message->setText( m_msg.c_str(), false );
|
||||
|
||||
// If the dialog is a simple 'OK' dialog, then hide the "Yes" button and
|
||||
// change "Cancel" to "OK"
|
||||
|
@ -68,7 +68,8 @@ private:
|
||||
|
||||
IConfirmDialogListener* m_listener;
|
||||
bool m_own_listener;
|
||||
void doInit(irr::core::stringw msg, MessageDialogType type, IConfirmDialogListener* listener, bool own_listener);
|
||||
irr::core::stringw m_msg;
|
||||
void doInit(MessageDialogType type, IConfirmDialogListener* listener, bool own_listener);
|
||||
|
||||
public:
|
||||
|
||||
@ -84,13 +85,14 @@ public:
|
||||
* Variant of MessageDialog where cancelling is not possible (i.e. just shows a message box with OK)
|
||||
* \param msg Message to display in the dialog
|
||||
*/
|
||||
MessageDialog(irr::core::stringw msg);
|
||||
MessageDialog(irr::core::stringw msg, bool from_queue = false);
|
||||
|
||||
|
||||
~MessageDialog();
|
||||
|
||||
virtual void onEnterPressedInternal();
|
||||
virtual void onUpdate(float dt);
|
||||
virtual void load();
|
||||
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user