summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-01-17 02:32:13 +0300
committerAndrei Karas <akaras@inbox.ru>2012-01-17 18:19:12 +0300
commit72277b0c8a16a5a2aabd634b127bcadd698430d5 (patch)
tree5b12463d9463f718f999b77fca0a17e3dc663f7f /src
parent2cefbbdce67c51e0728f46ef9086a565c0d187cc (diff)
downloadmanaverse-72277b0c8a16a5a2aabd634b127bcadd698430d5.tar.gz
manaverse-72277b0c8a16a5a2aabd634b127bcadd698430d5.tar.bz2
manaverse-72277b0c8a16a5a2aabd634b127bcadd698430d5.tar.xz
manaverse-72277b0c8a16a5a2aabd634b127bcadd698430d5.zip
Add friends tab to social window.
Diffstat (limited to 'src')
-rw-r--r--src/gui/socialwindow.cpp131
-rw-r--r--src/gui/socialwindow.h1
-rw-r--r--src/gui/whoisonline.cpp22
-rw-r--r--src/playerrelations.cpp18
-rw-r--r--src/playerrelations.h3
5 files changed, 168 insertions, 7 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index b2c28e84e..4649c23a7 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -29,6 +29,8 @@
#include "logger.h"
#include "map.h"
#include "party.h"
+#include "playerrelations.h"
+#include "gui/whoisonline.h"
#include "gui/confirmdialog.h"
#include "gui/okdialog.h"
@@ -60,6 +62,30 @@
#include "debug.h"
+class SortFriendsFunctor
+{
+ public:
+ bool operator() (Avatar* m1, Avatar* m2)
+ {
+ if (!m1 || !m2)
+ return false;
+
+ if (m1->getOnline() != m2->getOnline())
+ return m1->getOnline() > m2->getOnline();
+
+ if (m1->getName() != m2->getName())
+ {
+ std::string s1 = m1->getName();
+ std::string s2 = m2->getName();
+ toLower(s1);
+ toLower(s2);
+ return s1 < s2;
+ }
+ return false;
+ }
+} friendSorter;
+
+
class SocialTab : public Tab
{
protected:
@@ -457,7 +483,6 @@ public:
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
-// mBeings->getMembers().push_back(new Avatar("test"));
updateList();
setCaption(name);
}
@@ -550,7 +575,6 @@ public:
if (actorSpriteManager)
{
-// std::list<Being*> beings = actorSpriteManager->getAll();
std::vector<std::string> names;
actorSpriteManager->getPlayerNames(names, false);
@@ -1058,6 +1082,103 @@ private:
};
+
+class SocialFriendsTab : public SocialTab
+{
+public:
+ SocialFriendsTab(std::string name)
+ {
+ mBeings = new BeingsListModal();
+
+ mList = new AvatarListBox(mBeings);
+ mScroll = new ScrollArea(mList);
+
+ mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
+ mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
+
+ updateList();
+ setCaption(name);
+ }
+
+ ~SocialFriendsTab()
+ {
+ delete mList;
+ mList = nullptr;
+ delete mScroll;
+ mScroll = nullptr;
+ delete mBeings;
+ mBeings = nullptr;
+ }
+
+ void updateList()
+ {
+ getPlayersAvatars();
+ }
+
+ void updateAvatar(std::string name)
+ {
+ }
+
+ void resetDamage(std::string name)
+ {
+ }
+
+ void getPlayersAvatars()
+ {
+ if (!actorSpriteManager)
+ return;
+
+ std::vector<Avatar*> *avatars = mBeings->getMembers();
+ if (!avatars)
+ return;
+
+ std::vector<Avatar*>::iterator ia = avatars->begin();
+ while (ia != avatars->end())
+ {
+ delete *ia;
+ ++ ia;
+ }
+ avatars->clear();
+
+ std::vector<std::string> *players
+ = player_relations.getPlayersByRelation(PlayerRelation::FRIEND);
+
+ std::set<std::string> players2 = whoIsOnline->getOnlinePlayers();
+
+ if (!players)
+ return;
+
+ std::vector<std::string>::iterator it = players->begin();
+ std::vector<std::string>::iterator it_end = players->end();
+ for (; it != it_end; ++ it)
+ {
+ Avatar *ava = nullptr;
+ ava = new Avatar(*it);
+ if (actorSpriteManager->findBeingByName(*it, Being::PLAYER)
+ || players2.find(*it) != players2.end())
+ {
+ ava->setOnline(true);
+ }
+ avatars->push_back(ava);
+ }
+ std::sort(avatars->begin(), avatars->end(), friendSorter);
+ delete players;
+ }
+
+protected:
+ void invite()
+ {
+ }
+
+ void leave()
+ {
+ }
+
+private:
+ BeingsListModal *mBeings;
+};
+
+
class CreatePopup : public Popup, public LinkHandler
{
public:
@@ -1155,6 +1276,9 @@ SocialWindow::SocialWindow() :
mPlayers = new SocialPlayersTab("P");
mTabs->addTab(mPlayers, mPlayers->mScroll);
+ mFriends = new SocialFriendsTab("F");
+ mTabs->addTab(mFriends, mFriends->mScroll);
+
mNavigation = new SocialNavigationTab();
mTabs->addTab(mNavigation, mNavigation->mScroll);
@@ -1205,6 +1329,8 @@ SocialWindow::~SocialWindow()
mNavigation = nullptr;
delete mAttackFilter;
mAttackFilter = nullptr;
+ delete mFriends;
+ mFriends = nullptr;
}
bool SocialWindow::addTab(Guild *guild)
@@ -1523,6 +1649,7 @@ void SocialWindow::logic()
if (mNeedUpdate && nowTime - mLastUpdateTime > 1)
{
mPlayers->updateList();
+ mFriends->updateList();
mNeedUpdate = false;
mLastUpdateTime = nowTime;
}
diff --git a/src/gui/socialwindow.h b/src/gui/socialwindow.h
index d99982c06..1429866ee 100644
--- a/src/gui/socialwindow.h
+++ b/src/gui/socialwindow.h
@@ -141,6 +141,7 @@ protected:
SocialTab *mAttackFilter;
SocialTab *mPlayers;
SocialTab *mNavigation;
+ SocialTab *mFriends;
CreatePopup *mCreatePopup;
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index 65bd1fcb5..a80fb4c89 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -21,14 +21,16 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "whoisonline.h"
+#include "gui/whoisonline.h"
#include <SDL.h>
#include <SDL_thread.h>
#include <vector>
#include <algorithm>
+#include "gui/socialwindow.h"
#include "gui/viewport.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/scrollarea.h"
@@ -288,8 +290,13 @@ void WhoIsOnline::loadList(std::vector<std::string> &list)
}
updateWindow(friends, neutral, disregard, enemy, numOnline);
- if (!mOnlinePlayers.empty() && chatWindow)
- chatWindow->updateOnline(mOnlinePlayers);
+ if (!mOnlinePlayers.empty())
+ {
+ if (chatWindow)
+ chatWindow->updateOnline(mOnlinePlayers);
+ if (socialWindow)
+ socialWindow->updateActiveList();
+ }
}
void WhoIsOnline::loadWebList()
@@ -589,8 +596,13 @@ void WhoIsOnline::logic()
mUpdateButton->setEnabled(true);
mUpdateTimer = 0;
updateSize();
- if (!mOnlinePlayers.empty() && chatWindow)
- chatWindow->updateOnline(mOnlinePlayers);
+ if (!mOnlinePlayers.empty())
+ {
+ if (chatWindow)
+ chatWindow->updateOnline(mOnlinePlayers);
+ if (socialWindow)
+ socialWindow->updateActiveList();
+ }
}
break;
case UPDATE_COMPLETE:
diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp
index 28596ac8b..6b5cb0199 100644
--- a/src/playerrelations.cpp
+++ b/src/playerrelations.cpp
@@ -361,6 +361,24 @@ std::vector<std::string> * PlayerRelationsManager::getPlayers()
return retval;
}
+std::vector<std::string> *PlayerRelationsManager::getPlayersByRelation(
+ PlayerRelation::Relation rel)
+{
+ std::vector<std::string> *retval = new std::vector<std::string>();
+
+ for (std::map<std::string,
+ PlayerRelation *>::const_iterator it = mRelations.begin();
+ it != mRelations.end(); ++it)
+ {
+ if (it->second && it->second->mRelation == rel)
+ retval->push_back(it->first);
+ }
+
+ sort(retval->begin(), retval->end(), playersSorter);
+
+ return retval;
+}
+
void PlayerRelationsManager::removePlayer(const std::string &name)
{
if (mRelations[name])
diff --git a/src/playerrelations.h b/src/playerrelations.h
index 20ba55fce..143a82477 100644
--- a/src/playerrelations.h
+++ b/src/playerrelations.h
@@ -202,6 +202,9 @@ class PlayerRelationsManager
*/
std::vector<std::string> *getPlayers();
+ std::vector<std::string> *getPlayersByRelation(PlayerRelation::Relation
+ rel);
+
/**
* Removes all recorded player info.
*/