ManaPlus
socialguildtab2.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2010 The Mana Developers
4  * Copyright (C) 2011-2018 The ManaPlus Developers
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_SOCIALGUILDTAB2_H
23 #define GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
24 
26 
27 #include "guild.h"
28 
29 #include "being/localplayer.h"
30 
31 #include "utils/delete2.h"
32 #include "utils/foreach.h"
33 #include "utils/gettext.h"
34 #include "utils/stringutils.h"
35 
36 #include "localconsts.h"
37 
39  public ActionListener
40 {
41  public:
42  SocialGuildTab2(const Widget2 *const widget,
43  Guild *const guild,
44  const Opaque showBackground) :
45  SocialTab(widget),
47  {
48  // TRANSLATORS: tab in social window
49  setCaption(_("Guild"));
50 
61 
62  createControls(guild, showBackground);
63  mMenuAction = "guild";
64  }
65 
67 
69  {
70  delete2(mList)
72  }
73 
74  void action(const ActionEvent &event A_UNUSED) override final
75  {
76  }
77 
78  void buildCounter(const int online0 A_UNUSED,
79  const int total0 A_UNUSED) override final
80  {
81  if (localPlayer == nullptr)
82  return;
83 
84  const Guild *const guild = localPlayer->getGuild();
85  if (guild == nullptr)
86  return;
87 
88  const Guild::MemberList *const members = guild->getMembers();
89  int online = 0;
90  int total = 0;
91  FOR_EACHP (Guild::MemberList::const_iterator, it, members)
92  {
93  if ((*it)->getOnline())
94  online ++;
95  total ++;
96  }
97 
98  // TRANSLATORS: social window label
99  mCounterString = strprintf(_("Players: %u/%u"),
100  CAST_U32(online),
101  CAST_U32(total));
102  updateCounter();
103  }
104 };
105 
106 #endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
#define CAST_U32
Definition: cast.h:30
#define _(s)
Definition: gettext.h:34
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
void setCaption(const std::string &caption)
Definition: tab.cpp:457
SocialGuildTab2(const Widget2 *const widget, Guild *const guild, const Opaque showBackground)
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1229
ScrollArea * mScroll
Definition: socialtab.h:137
#define final
Definition: localconsts.h:45
void setSelectedTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:141
std::string mCounterString
Definition: socialtab.h:139
void setHighlightedTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:130
#define delete2(var)
Definition: delete2.h:24
void createControls(AvatarListModel *const listModel, const Opaque showBackground)
Definition: socialtab.h:106
void setTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:119
void buildCounter(const int online0, const int total0)
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
std::string mMenuAction
Definition: socialtab.h:140
LocalPlayer * localPlayer
AvatarListBox * mList
Definition: socialtab.h:138
std::vector< GuildMember * > MemberList
Definition: guild.h:201
const MemberList * getMembers() const
Definition: guild.h:203
#define A_UNUSED
Definition: localconsts.h:171
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
#define override
Definition: localconsts.h:46
void action(const ActionEvent &event)
uint32_t guild
Definition: guild.h:68
void updateCounter() const
Definition: socialtab.h:123