From 72277b0c8a16a5a2aabd634b127bcadd698430d5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 17 Jan 2012 02:32:13 +0300 Subject: Add friends tab to social window. --- src/gui/socialwindow.cpp | 131 ++++++++++++++++++++++++++++++++++++++++++++++- src/gui/socialwindow.h | 1 + src/gui/whoisonline.cpp | 22 ++++++-- src/playerrelations.cpp | 18 +++++++ src/playerrelations.h | 3 ++ 5 files changed, 168 insertions(+), 7 deletions(-) (limited to 'src') 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 beings = actorSpriteManager->getAll(); std::vector 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 *avatars = mBeings->getMembers(); + if (!avatars) + return; + + std::vector::iterator ia = avatars->begin(); + while (ia != avatars->end()) + { + delete *ia; + ++ ia; + } + avatars->clear(); + + std::vector *players + = player_relations.getPlayersByRelation(PlayerRelation::FRIEND); + + std::set players2 = whoIsOnline->getOnlinePlayers(); + + if (!players) + return; + + std::vector::iterator it = players->begin(); + std::vector::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 #include #include #include +#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 &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 * PlayerRelationsManager::getPlayers() return retval; } +std::vector *PlayerRelationsManager::getPlayersByRelation( + PlayerRelation::Relation rel) +{ + std::vector *retval = new std::vector(); + + for (std::map::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 *getPlayers(); + std::vector *getPlayersByRelation(PlayerRelation::Relation + rel); + /** * Removes all recorded player info. */ -- cgit v1.2.3-60-g2f50