ManaPlus
socialfriendstab.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
23 #define GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
24 
26 
27 #include "actormanager.h"
28 
29 #include "being/playerrelations.h"
30 
32 
34 
36 
37 #include "utils/delete2.h"
38 #include "utils/foreach.h"
39 #include "utils/gettext.h"
40 
41 #include "localconsts.h"
42 
44 {
45  public:
46  SocialFriendsTab(const Widget2 *const widget,
47  const std::string &name,
48  const Opaque showBackground) :
49  SocialTab(widget),
52  {
53  createControls(mBeings, showBackground);
54 
56  setCaption(name);
57  mMenuAction = "friends";
58  }
59 
61 
63  {
64  delete2(mList)
67  }
68 
70  {
72  }
73 
75  {
76  if (actorManager == nullptr)
77  return;
78 
79  STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
80 
81  STD_VECTOR<Avatar*>::iterator ia = avatars->begin();
82  while (ia != avatars->end())
83  {
84  delete *ia;
85  ++ ia;
86  }
87  avatars->clear();
88 
89  const StringVect *const players
91 
92  const std::set<std::string> &players2
94 
95  if (players == nullptr)
96  return;
97 
98  int online = 0;
99  int total = 0;
100 
101  FOR_EACHP (StringVectCIter, it, players)
102  {
103  Avatar *const ava = new Avatar(*it);
105  nullptr || players2.find(*it) != players2.end())
106  {
107  ava->setOnline(true);
108  online ++;
109  }
110  total ++;
111  avatars->push_back(ava);
112  }
113  std::sort(avatars->begin(), avatars->end(), mFriendSorter);
114  delete players;
115 
116  // TRANSLATORS: social window label
117  mCounterString = strprintf(_("Friends: %u/%u"),
118  CAST_U32(online),
119  CAST_U32(total));
120  updateCounter();
121  }
122 
123  private:
126 };
127 
128 #endif // GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
ActorManager * actorManager
#define CAST_U32
Definition: cast.h:31
Being * findBeingByName(const std::string &name, const ActorTypeT type) const
Definition: avatar.h:41
void setOnline(const bool online)
Definition: avatar.h:87
std::vector< Avatar * > * getMembers()
StringVect * getPlayersByRelation(const RelationT rel) const
BeingsListModel * mBeings
SocialFriendsTab(const Widget2 *const widget, const std::string &name, const Opaque showBackground)
SortFriendsFunctor mFriendSorter
void createControls(AvatarListModel *const listModel, const Opaque showBackground)
Definition: socialtab.h:107
ScrollArea * mScroll
Definition: socialtab.h:138
std::string mMenuAction
Definition: socialtab.h:141
AvatarListBox * mList
Definition: socialtab.h:139
void updateCounter() const
Definition: socialtab.h:124
std::string mCounterString
Definition: socialtab.h:140
void setCaption(const std::string &caption)
Definition: tab.cpp:458
const std::set< std::string > & getOnlineNicks() const
Definition: whoisonline.h:85
#define new
Definition: debug_new.h:147
#define delete2(var)
Definition: delete2.h:25
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:31
#define _(s)
Definition: gettext.h:35
#define override
Definition: localconsts.h:47
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
@ FRIEND
Definition: relation.h:32
bool Opaque
Definition: opaque.h:30
PlayerRelationsManager playerRelations
std::string strprintf(const char *const format,...)
StringVect::const_iterator StringVectCIter
Definition: stringvector.h:31
std::vector< std::string > StringVect
Definition: stringvector.h:29
WhoIsOnline * whoIsOnline
Definition: whoisonline.cpp:82