Big commit. Everything related to friending & friendslist GUI, dialog queue and callbacks for the 3 requests.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13518 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
unitraxx 2013-08-20 01:10:07 +00:00
parent d40dd67e96
commit 445706793e
9 changed files with 119 additions and 36 deletions

View File

@ -26,6 +26,8 @@
#include "utils/log.hpp"
#include "utils/translation.hpp"
#include "addons/addon.hpp"
#include "guiengine/dialog_queue.hpp"
#include "states_screens/dialogs/user_info_dialog.hpp"
#include <sstream>
#include <stdlib.h>
@ -309,7 +311,7 @@ namespace Online{
// ============================================================================
const CurrentUser::FriendRequest * CurrentUser::requestFriendRequest(const uint32_t friend_id) const
void CurrentUser::requestFriendRequest(const uint32_t friend_id) const
{
assert(isRegisteredUser());
CurrentUser::FriendRequest * request = new CurrentUser::FriendRequest();
@ -319,20 +321,26 @@ namespace Online{
request->setParameter("userid", getID());
request->setParameter("friendid", friend_id);
HTTPManager::get()->addRequest(request);
return request;
}
void CurrentUser::FriendRequest::callback()
{
uint32_t id(0);
m_result->get("friendid", &id);
irr::core::stringw info_text("");
if(m_success)
{
//FIXME
ProfileManager::get()->getProfileByID(id)->setRelationInfo(new Profile::RelationInfo(_("Today"), false, true, false));
info_text = _("Friend request send!");
}
else
info_text = m_info;
GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true);
}
// ============================================================================
const CurrentUser::AcceptFriendRequest * CurrentUser::requestAcceptFriend(const uint32_t friend_id) const
void CurrentUser::requestAcceptFriend(const uint32_t friend_id) const
{
assert(isRegisteredUser());
CurrentUser::AcceptFriendRequest * request = new CurrentUser::AcceptFriendRequest();
@ -342,20 +350,28 @@ namespace Online{
request->setParameter("userid", getID());
request->setParameter("friendid", friend_id);
HTTPManager::get()->addRequest(request);
return request;
}
void CurrentUser::AcceptFriendRequest::callback()
{
uint32_t id(0);
m_result->get("friendid", &id);
irr::core::stringw info_text("");
if(m_success)
{
//FIXME
Profile * profile = ProfileManager::get()->getProfileByID(id);
profile->setFriend();
profile->setRelationInfo(new Profile::RelationInfo(_("Today"), false, false, true));
info_text = _("Friend request accepted!");
}
else
info_text = m_info;
GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true);
}
// ============================================================================
const CurrentUser::DeclineFriendRequest * CurrentUser::requestDeclineFriend(const uint32_t friend_id) const
void CurrentUser::requestDeclineFriend(const uint32_t friend_id) const
{
assert(isRegisteredUser());
CurrentUser::DeclineFriendRequest * request = new CurrentUser::DeclineFriendRequest();
@ -365,15 +381,22 @@ namespace Online{
request->setParameter("userid", getID());
request->setParameter("friendid", friend_id);
HTTPManager::get()->addRequest(request);
return request;
}
void CurrentUser::DeclineFriendRequest::callback()
{
uint32_t id(0);
m_result->get("friendid", &id);
irr::core::stringw info_text("");
if(m_success)
{
//FIXME
ProfileManager::get()->removePersistent(id);
info_text = _("Friend request declined!");
}
else
info_text = m_info;
GUIEngine::DialogQueue::get()->pushDialog( new UserInfoDialog(id, info_text,!m_success, true), true);
}
// ============================================================================
void CurrentUser::requestPoll()

View File

@ -87,19 +87,19 @@ namespace Online{
class FriendRequest : public XMLRequest {
virtual void callback ();
public:
FriendRequest() : XMLRequest() {}
FriendRequest() : XMLRequest(true) {}
};
class AcceptFriendRequest : public XMLRequest {
virtual void callback ();
public:
AcceptFriendRequest() : XMLRequest() {}
AcceptFriendRequest() : XMLRequest(true) {}
};
class DeclineFriendRequest : public XMLRequest {
virtual void callback ();
public:
DeclineFriendRequest() : XMLRequest() {}
DeclineFriendRequest() : XMLRequest(true) {}
};
@ -147,9 +147,9 @@ namespace Online{
const XMLRequest * requestGetAddonVote(const std::string & addon_id) const;
const SetAddonVoteRequest * requestSetAddonVote(const std::string & addon_id, float rating) const;
const FriendRequest * requestFriendRequest(const uint32_t friend_id) const;
const AcceptFriendRequest * requestAcceptFriend(const uint32_t friend_id) const;
const DeclineFriendRequest * requestDeclineFriend(const uint32_t friend_id) const;
void requestFriendRequest(const uint32_t friend_id) const;
void requestAcceptFriend(const uint32_t friend_id) const;
void requestDeclineFriend(const uint32_t friend_id) const;
const XMLRequest * requestUserSearch(const irr::core::stringw & search_string) const;

View File

@ -82,6 +82,13 @@ namespace Online
return irr::core::stringw(_("Fetching friends")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw processing()
{
return irr::core::stringw(_("Processing")) + loadingDots();
}
// ------------------------------------------------------------------------
irr::core::stringw loadingDots(bool spaces, float interval, int max_dots)
{

View File

@ -36,6 +36,7 @@ namespace Online
irr::core::stringw creatingServer ();
irr::core::stringw fetchingServers ();
irr::core::stringw fetchingFriends ();
irr::core::stringw processing ();
irr::core::stringw signedInAs (const irr::core::stringw & name);
} // namespace Messages
}// namespace Online

View File

@ -65,15 +65,13 @@ namespace Online{
m_relation_info = NULL;
m_is_friend = false;
if(type == C_RELATION_INFO){
std::string is_online_string("");
xml->get("online", &is_online_string);
bool is_online = is_online_string == "yes";
irr::core::stringw date("");
xml->get("date", &date);
std::string is_pending_string("");
xml->get("is_pending", &is_pending_string);
bool is_pending = is_pending_string == "yes";
bool is_asker(false);
bool is_online(false);
if(is_pending)
{
std::string is_asker_string("");
@ -82,6 +80,9 @@ namespace Online{
}
else
{
std::string is_online_string("");
xml->get("online", &is_online_string);
is_online = is_online_string == "yes";
m_is_friend = true;
}
m_relation_info = new RelationInfo(date, is_online, is_pending, is_asker);

View File

@ -106,7 +106,9 @@ namespace Online{
bool isCurrentUser() const { return m_is_current_user; }
bool isFriend() const { return m_is_friend; }
void setFriend() { m_is_friend = true; }
RelationInfo * getRelationInfo() { return m_relation_info; }
void setRelationInfo(RelationInfo * r){ delete m_relation_info; m_relation_info = r;}
void setCacheBit() { m_cache_bit = true; }
void unsetCacheBit() { m_cache_bit = false; }

View File

@ -20,18 +20,11 @@
#include <IGUIEnvironment.h>
#include "audio/sfx_manager.hpp"
#include "config/player.hpp"
#include "guiengine/engine.hpp"
#include "states_screens/state_manager.hpp"
#include "states_screens/online_profile_overview.hpp"
#include "utils/translation.hpp"
#include "utils/string_utils.hpp"
#include "network/protocol_manager.hpp"
#include "network/protocols/connect_to_server.hpp"
#include "online/messages.hpp"
#include "states_screens/dialogs/registration_dialog.hpp"
#include "states_screens/networking_lobby.hpp"
using namespace GUIEngine;
@ -41,14 +34,25 @@ using namespace Online;
// -----------------------------------------------------------------------------
UserInfoDialog::UserInfoDialog(uint32_t showing_id)
: ModalDialog(0.8f,0.8f), m_showing_id(showing_id)
UserInfoDialog::UserInfoDialog(uint32_t showing_id, const core::stringw info, bool error, bool from_queue)
: ModalDialog(0.8f,0.8f, !from_queue), m_showing_id(showing_id)
{
m_profile = ProfileManager::get()->getProfileByID(showing_id);
if(m_profile->isCurrentUser())
ModalDialog::dismiss();
m_self_destroy = false;
m_enter_profile = false;
m_processing = false;
m_error = error;
m_info = info;
}
void UserInfoDialog::beforeAddingWidgets()
{
loadFromFile("online/user_info_dialog.stkgui");
m_profile = ProfileManager::get()->getProfileByID(showing_id);
if(m_error)
m_info_widget->setErrorColor();
m_info_widget->setText(m_info, false);
m_name_widget = getWidget<LabelWidget>("name");
assert(m_name_widget != NULL);
m_name_widget->setText(m_profile->getUserName(),false);
@ -68,12 +72,20 @@ UserInfoDialog::UserInfoDialog(uint32_t showing_id)
assert(m_cancel_widget != NULL);
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
}
Profile::RelationInfo * relation_info = m_profile->getRelationInfo();
if(relation_info == NULL || !relation_info->isPending() || !relation_info->isAsker())
{
m_accept_widget->setVisible(false);
m_decline_widget->setVisible(false);
if (relation_info == NULL) return;
}
if(m_profile->isFriend() || relation_info->isPending())
{
m_friend_widget->setVisible(false);
}
void UserInfoDialog::beforeAddingWidgets()
{
/*m_accept_widget->setVisible(false);
m_decline_widget->setVisible(false);*/
}
@ -101,10 +113,41 @@ GUIEngine::EventPropagation UserInfoDialog::processEvent(const std::string& even
m_enter_profile = true;
return GUIEngine::EVENT_BLOCK;
}
else if(selection == m_friend_widget->m_properties[PROP_ID])
{
CurrentUser::get()->requestFriendRequest(m_profile->getID());
m_processing = true;
return GUIEngine::EVENT_BLOCK;
}
else if(selection == m_accept_widget->m_properties[PROP_ID])
{
CurrentUser::get()->requestAcceptFriend(m_profile->getID());
m_processing = true;
return GUIEngine::EVENT_BLOCK;
}
else if(selection == m_decline_widget->m_properties[PROP_ID])
{
CurrentUser::get()->requestDeclineFriend(m_profile->getID());
m_processing = true;
return GUIEngine::EVENT_BLOCK;
}
}
return GUIEngine::EVENT_LET;
}
// -----------------------------------------------------------------------------
void UserInfoDialog::deactivate()
{
m_options_widget->setDeactivated();
}
// -----------------------------------------------------------------------------
void UserInfoDialog::activate()
{
}
// -----------------------------------------------------------------------------
void UserInfoDialog::onEnterPressedInternal()
@ -130,7 +173,7 @@ bool UserInfoDialog::onEscapePressed()
void UserInfoDialog::onUpdate(float dt)
{
if(m_processing) m_info_widget->setText(Messages::processing(), false);
//If we want to open the registration dialog, we need to close this one first
m_enter_profile && (m_self_destroy = true);

View File

@ -39,6 +39,10 @@ private:
bool m_self_destroy;
bool m_enter_profile;
bool m_processing;
bool m_error;
irr::core::stringw m_info;
const uint32_t m_showing_id;
Online::Profile * m_profile;
@ -54,9 +58,11 @@ private:
GUIEngine::IconButtonWidget * m_cancel_widget;
void requestJoin();
void activate();
void deactivate();
public:
UserInfoDialog(uint32_t showing_id);
UserInfoDialog(uint32_t showing_id, const core::stringw info = "", bool error = false, bool from_queue = false);
~UserInfoDialog();
virtual void beforeAddingWidgets();

View File

@ -130,7 +130,7 @@ void OnlineProfileFriends::onUpdate(float delta, irr::video::IVideoDriver* driv
irr::core::stringw status("");
if(relation_info->isPending())
{
status = (relation_info->isAsker() ? _("Pending") : _("New request"));
status = (relation_info->isAsker() ? _("New Request") : _("Pending"));
}
else
status = (relation_info->isOnline() ? _("Online") : _("Offline"));