And you now get immediate notifications for new friend requests! (easily extendable for future personal message notifications)
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/uni@13537 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
c3c1e1b054
commit
ff877b60ca
19
data/gui/online/notification_dialog.stkgui
Normal file
19
data/gui/online/notification_dialog.stkgui
Normal file
@ -0,0 +1,19 @@
|
||||
<stkgui>
|
||||
|
||||
<div x="2%" y="5%" width="96%" height="85%" layout="vertical-row" >
|
||||
|
||||
<label id="info" proportion="1" width="90%" align="center" text_align="center" word_wrap="true" text=""/>
|
||||
|
||||
<spacer height="20" width="50">
|
||||
|
||||
<buttonbar id="options" width="90%" height="20%" align="center">
|
||||
<icon-button id="view" width="64" height="64" icon="gui/difficulty_medium.png"
|
||||
I18N="User info dialog" text="View" label_location="bottom"/>
|
||||
<icon-button id="cancel" width="64" height="64" icon="gui/main_quit.png"
|
||||
I18N="User info dialog" text="Close" label_location="bottom"/>
|
||||
</buttonbar>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</stkgui>
|
@ -208,6 +208,7 @@ src/states_screens/dialogs/enter_player_name_dialog.cpp
|
||||
src/states_screens/dialogs/gp_info_dialog.cpp
|
||||
src/states_screens/dialogs/login_dialog.cpp
|
||||
src/states_screens/dialogs/message_dialog.cpp
|
||||
src/states_screens/dialogs/notification_dialog.cpp
|
||||
src/states_screens/dialogs/player_info_dialog.cpp
|
||||
src/states_screens/dialogs/press_a_key_dialog.cpp
|
||||
src/states_screens/dialogs/race_paused_dialog.cpp
|
||||
@ -510,6 +511,7 @@ src/states_screens/dialogs/enter_player_name_dialog.hpp
|
||||
src/states_screens/dialogs/gp_info_dialog.hpp
|
||||
src/states_screens/dialogs/login_dialog.hpp
|
||||
src/states_screens/dialogs/message_dialog.hpp
|
||||
src/states_screens/dialogs/notification_dialog.hpp
|
||||
src/states_screens/dialogs/player_info_dialog.hpp
|
||||
src/states_screens/dialogs/press_a_key_dialog.hpp
|
||||
src/states_screens/dialogs/race_paused_dialog.hpp
|
||||
|
@ -28,7 +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/dialogs/notification_dialog.hpp"
|
||||
#include "states_screens/online_profile_friends.hpp"
|
||||
|
||||
#include <sstream>
|
||||
@ -423,80 +423,109 @@ namespace Online{
|
||||
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)
|
||||
|
||||
if(m_result->get("online", &online_friends_string) == 1)
|
||||
{
|
||||
online_friends.push_back(atoi(parts[i].c_str()));
|
||||
}
|
||||
bool went_offline = false;
|
||||
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])
|
||||
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()));
|
||||
}
|
||||
bool went_offline = false;
|
||||
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);
|
||||
went_offline = true;
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
online_friends.erase(iter--);
|
||||
break;
|
||||
message = to_notify[0] + irr::core::stringw(_(" is now online."));
|
||||
}
|
||||
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);
|
||||
went_offline = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (now_online)
|
||||
{
|
||||
relation_info->setOnline(true);
|
||||
to_notify.push_back(profile->getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
else if(to_notify.size() == 2)
|
||||
{
|
||||
message = to_notify[0] + irr::core::stringw(_(" and ")) + to_notify[1] + irr::core::stringw(_(" are now online."));
|
||||
}
|
||||
else if(to_notify.size() == 3)
|
||||
{
|
||||
message = to_notify[0] + irr::core::stringw(_(", ")) + to_notify[1] + irr::core::stringw(_(" and ")) + to_notify[2] + irr::core::stringw(_(" are now online."));
|
||||
}
|
||||
else if(to_notify.size() > 3)
|
||||
{
|
||||
message = StringUtils::toWString(to_notify.size()) + irr::core::stringw(_(" friends are now online."));
|
||||
}
|
||||
GUIEngine::DialogQueue::get()->pushDialog( new NotificationDialog(NotificationDialog::T_Friends, message), false);
|
||||
OnlineProfileFriends::getInstance()->refreshFriendsList();
|
||||
}
|
||||
else if(went_offline)
|
||||
{
|
||||
OnlineProfileFriends::getInstance()->refreshFriendsList();
|
||||
}
|
||||
}
|
||||
|
||||
if(to_notify.size() > 0)
|
||||
int friend_request_count = 0;
|
||||
for(unsigned int i = 0; i < m_result->getNumNodes(); i++)
|
||||
{
|
||||
const XMLNode * node = m_result->getNode(i);
|
||||
if(node->getName() == "new_friend_request")
|
||||
{
|
||||
Profile::RelationInfo * ri = new Profile::RelationInfo("New", false, true, true);
|
||||
Profile * p = new Profile(node);
|
||||
p->setRelationInfo(ri);
|
||||
ProfileManager::get()->addPersistent(p);
|
||||
}
|
||||
}
|
||||
if(friend_request_count > 0)
|
||||
{
|
||||
irr::core::stringw message("");
|
||||
if(to_notify.size() == 1)
|
||||
if(friend_request_count > 1)
|
||||
{
|
||||
message = to_notify[0] + irr::core::stringw(_(" is now online."));
|
||||
message = irr::core::stringw(_("You have ")) + StringUtils::toWString(friend_request_count) + irr::core::stringw(_(" new friend requests!."));
|
||||
}
|
||||
else if(to_notify.size() == 2)
|
||||
else
|
||||
{
|
||||
message = to_notify[0] + irr::core::stringw(_(" and ")) + to_notify[1] + irr::core::stringw(_(" are now online."));
|
||||
message = _("You have a new friend request!.");
|
||||
}
|
||||
else if(to_notify.size() == 3)
|
||||
{
|
||||
message = to_notify[0] + irr::core::stringw(_(", ")) + to_notify[1] + irr::core::stringw(_(" and ")) + to_notify[2] + irr::core::stringw(_(" are now online."));
|
||||
}
|
||||
else if(to_notify.size() > 3)
|
||||
{
|
||||
message = StringUtils::toWString(to_notify.size()) + irr::core::stringw(_(" friends are now online."));
|
||||
}
|
||||
GUIEngine::DialogQueue::get()->pushDialog( new MessageDialog(message, true), false);
|
||||
OnlineProfileFriends::getInstance()->refreshFriendsList();
|
||||
}
|
||||
else if(went_offline)
|
||||
{
|
||||
GUIEngine::DialogQueue::get()->pushDialog( new NotificationDialog(NotificationDialog::T_Friends, message), false);
|
||||
OnlineProfileFriends::getInstance()->refreshFriendsList();
|
||||
}
|
||||
}
|
||||
|
134
src/states_screens/dialogs/notification_dialog.cpp
Normal file
134
src/states_screens/dialogs/notification_dialog.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "states_screens/dialogs/notification_dialog.hpp"
|
||||
|
||||
#include <IGUIEnvironment.h>
|
||||
|
||||
#include "audio/sfx_manager.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/online_profile_friends.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
|
||||
using namespace GUIEngine;
|
||||
using namespace irr;
|
||||
using namespace irr::gui;
|
||||
using namespace Online;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
NotificationDialog::NotificationDialog(Type type, const core::stringw info, bool from_queue)
|
||||
: ModalDialog(0.8f,0.5f)
|
||||
{
|
||||
m_info = info;
|
||||
if(!from_queue) load();
|
||||
}
|
||||
|
||||
void NotificationDialog::load()
|
||||
{
|
||||
loadFromFile("online/notification_dialog.stkgui");
|
||||
}
|
||||
|
||||
void NotificationDialog::beforeAddingWidgets()
|
||||
{
|
||||
m_self_destroy = false;
|
||||
m_view = false;
|
||||
m_info_widget = getWidget<LabelWidget>("info");
|
||||
assert(m_info_widget != NULL);
|
||||
m_info_widget->setText(m_info, false);
|
||||
m_options_widget = getWidget<RibbonWidget>("options");
|
||||
assert(m_options_widget != NULL);
|
||||
m_view_widget = getWidget<IconButtonWidget>("view");
|
||||
assert(m_view_widget != NULL);
|
||||
m_cancel_widget = getWidget<IconButtonWidget>("cancel");
|
||||
assert(m_cancel_widget != NULL);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
NotificationDialog::~NotificationDialog()
|
||||
{
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
GUIEngine::EventPropagation NotificationDialog::processEvent(const std::string& eventSource)
|
||||
{
|
||||
|
||||
if (eventSource == m_options_widget->m_properties[PROP_ID])
|
||||
{
|
||||
const std::string& selection = m_options_widget->getSelectionIDString(PLAYER_ID_GAME_MASTER);
|
||||
if (selection == m_cancel_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_self_destroy = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
else if(selection == m_view_widget->m_properties[PROP_ID])
|
||||
{
|
||||
m_view = true;
|
||||
return GUIEngine::EVENT_BLOCK;
|
||||
}
|
||||
}
|
||||
return GUIEngine::EVENT_LET;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void NotificationDialog::onEnterPressedInternal()
|
||||
{
|
||||
|
||||
//If enter was pressed while none of the buttons was focused interpret as close
|
||||
const int playerID = PLAYER_ID_GAME_MASTER;
|
||||
if (GUIEngine::isFocusedForPlayer(m_options_widget, playerID))
|
||||
return;
|
||||
m_self_destroy = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
bool NotificationDialog::onEscapePressed()
|
||||
{
|
||||
if (m_cancel_widget->isActivated())
|
||||
m_self_destroy = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void NotificationDialog::onUpdate(float dt)
|
||||
{
|
||||
//If we want to open the registration dialog, we need to close this one first
|
||||
m_view && (m_self_destroy = true);
|
||||
|
||||
// It's unsafe to delete from inside the event handler so we do it here
|
||||
if (m_self_destroy)
|
||||
{
|
||||
ModalDialog::dismiss();
|
||||
if (m_view)
|
||||
{
|
||||
if(m_type == T_Friends)
|
||||
{
|
||||
ProfileManager::get()->setVisiting(CurrentUser::get()->getID());
|
||||
StateManager::get()->pushScreen(OnlineProfileFriends::getInstance());
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
68
src/states_screens/dialogs/notification_dialog.hpp
Normal file
68
src/states_screens/dialogs/notification_dialog.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2013 Glenn De Jonghe
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
#ifndef HEADER_NOTIFICATION_DIALOG_HPP
|
||||
#define HEADER_NOTIFICATION_DIALOG_HPP
|
||||
|
||||
#include <irrString.h>
|
||||
|
||||
#include "guiengine/modaldialog.hpp"
|
||||
#include "guiengine/widgets.hpp"
|
||||
#include "online/current_user.hpp"
|
||||
#include "utils/types.hpp"
|
||||
|
||||
|
||||
/**
|
||||
* \brief Dialog that allows a user to sign in
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class NotificationDialog : public GUIEngine::ModalDialog
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
T_Friends = 1
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_self_destroy;
|
||||
bool m_view;
|
||||
Type m_type;
|
||||
irr::core::stringw m_info;
|
||||
|
||||
GUIEngine::LabelWidget * m_info_widget;
|
||||
|
||||
GUIEngine::RibbonWidget * m_options_widget;
|
||||
GUIEngine::IconButtonWidget * m_view_widget;
|
||||
GUIEngine::IconButtonWidget * m_cancel_widget;
|
||||
|
||||
public:
|
||||
NotificationDialog(Type type, const core::stringw info, bool from_queue = true);
|
||||
~NotificationDialog();
|
||||
|
||||
virtual void beforeAddingWidgets();
|
||||
virtual void load();
|
||||
|
||||
void onEnterPressedInternal();
|
||||
GUIEngine::EventPropagation processEvent(const std::string& eventSource);
|
||||
|
||||
virtual bool onEscapePressed();
|
||||
virtual void onUpdate(float dt);
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user