summaryrefslogtreecommitdiff
path: root/src/gui/socialwindow.cpp
diff options
context:
space:
mode:
authorReid <reidyaro@gmail.com>2012-01-25 22:05:36 +0100
committerReid <reidyaro@gmail.com>2012-01-25 22:05:36 +0100
commit8b612abb42853a22c1a9545e2c9280d154646543 (patch)
treef466167087c2b2de4b8aa9e6d1d1986f72f84147 /src/gui/socialwindow.cpp
parenta913dd41df61760de6ece552f941e002251ff54c (diff)
parentd340b5a27a8f3b05d1764da9c114f5f59bd0cd46 (diff)
downloadplus-8b612abb42853a22c1a9545e2c9280d154646543.tar.gz
plus-8b612abb42853a22c1a9545e2c9280d154646543.tar.bz2
plus-8b612abb42853a22c1a9545e2c9280d154646543.tar.xz
plus-8b612abb42853a22c1a9545e2c9280d154646543.zip
Merge branch 'master' of gitorious.org:manaplus/manaplus
Diffstat (limited to 'src/gui/socialwindow.cpp')
-rw-r--r--src/gui/socialwindow.cpp147
1 files changed, 138 insertions, 9 deletions
diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp
index 2bc8aba9b..a1a6c1cee 100644
--- a/src/gui/socialwindow.cpp
+++ b/src/gui/socialwindow.cpp
@@ -1,7 +1,7 @@
/*
* The ManaPlus Client
* Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011 The ManaPlus Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
*
* This file is part of The ManaPlus Client.
*
@@ -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);
@@ -650,7 +674,7 @@ public:
return;
Map* map = socialWindow->getMap();
- if (!map)
+ if (!map || map->empty())
return;
if (socialWindow->getProcessedPortals())
@@ -848,11 +872,11 @@ public:
std::vector<Avatar*> *avatars = mBeings->getMembers();
- std::vector<Avatar*>::iterator i = avatars->begin();
-
if (!avatars)
return;
+ std::vector<Avatar*>::iterator i = avatars->begin();
+
while (i != avatars->end())
{
Avatar *ava = (*i);
@@ -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 A_UNUSED)
+ {
+ }
+
+ void resetDamage(std::string name A_UNUSED)
+ {
+ }
+
+ 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:
@@ -1152,9 +1273,14 @@ SocialWindow::SocialWindow() :
loadWindowState();
- mPlayers = new SocialPlayersTab("P");
+ // TRANSLATORS: here P is title for visible players tab in social window
+ mPlayers = new SocialPlayersTab(_("P"));
mTabs->addTab(mPlayers, mPlayers->mScroll);
+ // TRANSLATORS: here F is title for friends tab in social window
+ mFriends = new SocialFriendsTab(_("F"));
+ mTabs->addTab(mFriends, mFriends->mScroll);
+
mNavigation = new SocialNavigationTab();
mTabs->addTab(mNavigation, mNavigation->mScroll);
@@ -1205,6 +1331,8 @@ SocialWindow::~SocialWindow()
mNavigation = nullptr;
delete mAttackFilter;
mAttackFilter = nullptr;
+ delete mFriends;
+ mFriends = nullptr;
}
bool SocialWindow::addTab(Guild *guild)
@@ -1523,6 +1651,7 @@ void SocialWindow::logic()
if (mNeedUpdate && nowTime - mLastUpdateTime > 1)
{
mPlayers->updateList();
+ mFriends->updateList();
mNeedUpdate = false;
mLastUpdateTime = nowTime;
}
@@ -1610,7 +1739,7 @@ void SocialWindow::nextTab()
if (tab == mTabs->getNumberOfTabs())
tab = 0;
- mTabs->setSelectedTab(tab);
+ mTabs->setSelectedTabByPos(tab);
}
void SocialWindow::prevTab()
@@ -1624,7 +1753,7 @@ void SocialWindow::prevTab()
tab = mTabs->getNumberOfTabs();
tab--;
- mTabs->setSelectedTab(tab);
+ mTabs->setSelectedTabByPos(tab);
}
void SocialWindow::updateAttackFilter()