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-2019 The ManaPlus Developers
5  * Copyright (C) 2019-2021 Andrei Karas
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
24 #define GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
25 
27 
28 #include "guild.h"
29 
30 #include "being/localplayer.h"
31 
32 #include "utils/delete2.h"
33 #include "utils/foreach.h"
34 #include "utils/gettext.h"
35 #include "utils/stringutils.h"
36 
37 #include "localconsts.h"
38 
40  public ActionListener
41 {
42  public:
43  SocialGuildTab2(const Widget2 *const widget,
44  Guild *const guild,
45  const Opaque showBackground) :
46  SocialTab(widget),
48  {
49  // TRANSLATORS: tab in social window
50  setCaption(_("Guild"));
51 
52  setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB, 255U),
53  &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE, 255U));
55  ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED, 255U),
57  ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE, 255U));
59  ThemeColorId::GUILD_SOCIAL_TAB_SELECTED, 255U),
61  ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE, 255U));
62 
63  createControls(guild, showBackground);
64  mMenuAction = "guild";
65  }
66 
68 
70  {
71  delete2(mList)
73  }
74 
75  void action(const ActionEvent &event A_UNUSED) override final
76  {
77  }
78 
79  void buildCounter(const int online0 A_UNUSED,
80  const int total0 A_UNUSED) override final
81  {
82  if (localPlayer == nullptr)
83  return;
84 
85  const Guild *const guild = localPlayer->getGuild();
86  if (guild == nullptr)
87  return;
88 
89  const Guild::MemberList *const members = guild->getMembers();
90  int online = 0;
91  int total = 0;
92  FOR_EACHP (Guild::MemberList::const_iterator, it, members)
93  {
94  if ((*it)->getOnline())
95  online ++;
96  total ++;
97  }
98 
99  // TRANSLATORS: social window label
100  mCounterString = strprintf(_("Players: %u/%u"),
101  CAST_U32(online),
102  CAST_U32(total));
103  updateCounter();
104  }
105 };
106 
107 #endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
#define CAST_U32
Definition: cast.h:31
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1258
Definition: guild.h:70
std::vector< GuildMember * > MemberList
Definition: guild.h:209
SocialGuildTab2(const Widget2 *const widget, Guild *const guild, const Opaque showBackground)
void action(const ActionEvent &event)
void buildCounter(const int online0, const int total0)
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 setHighlightedTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:131
void setTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:120
void setCaption(const std::string &caption)
Definition: tab.cpp:458
void setSelectedTabColor(const Color *const color1, const Color *const color2)
Definition: tab.h:142
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
#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
#define A_UNUSED
Definition: localconsts.h:160
LocalPlayer * localPlayer
uint32_t guild
bool Opaque
Definition: opaque.h:30
std::string strprintf(const char *const format,...)