ManaPlus
socialguildtab.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_SOCIALGUILDTAB_H
24 #define GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
25 
27 
28 #include "being/localplayer.h"
29 
30 #include "const/sound.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 "net/guildhandler.h"
38 
39 #include "localconsts.h"
40 
42  public ActionListener
43 {
44  public:
45  SocialGuildTab(const Widget2 *const widget,
46  Guild *const guild,
47  const Opaque showBackground) :
48  SocialTab(widget),
50  mGuild(guild)
51  {
52  // TRANSLATORS: tab in social window
53  setCaption(_("Guild"));
54 
55  setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB, 255U),
56  &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE, 255U));
58  ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED, 255U),
60  ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE, 255U));
62  ThemeColorId::GUILD_SOCIAL_TAB_SELECTED, 255U),
64  ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE, 255U));
65 
66  createControls(guild, showBackground);
67  mMenuAction = "guild";
68  }
69 
71 
73  {
74  delete2(mList)
76  }
77 
78  void action(const ActionEvent &event) override final
79  {
80  const std::string &eventId = event.getId();
81  if (eventId == "do invite")
82  {
83  const std::string name = mInviteDialog->getText();
84  guildHandler->invite(name);
85 
86  if (localChatTab != nullptr)
87  {
89  // TRANSLATORS: chat message
90  _("Invited user %s to guild %s."),
91  name.c_str(),
92  mGuild->getName().c_str()),
96  }
97  mInviteDialog = nullptr;
98  }
99  else if (eventId == "~do invite")
100  {
101  mInviteDialog = nullptr;
102  }
103  else if (eventId == "yes")
104  {
106  if (localChatTab != nullptr)
107  {
109  // TRANSLATORS: chat message
110  _("Guild %s quit requested."),
111  mGuild->getName().c_str()),
115  }
116  mConfirmDialog = nullptr;
117  }
118  else if (eventId == "~yes")
119  {
120  mConfirmDialog = nullptr;
121  }
122  }
123 
125  {
127  // TRANSLATORS: guild invite message
128  _("Member Invite to Guild"),
129  // TRANSLATORS: guild invite message
130  strprintf(_("Who would you like to invite to guild %s?"),
131  mGuild->getName().c_str()),
132  socialWindow,
133  false);
134  mInviteDialog->setActionEventId("do invite");
136  }
137 
139  {
141  // TRANSLATORS: guild leave message
142  _("Leave Guild?"),
143  // TRANSLATORS: guild leave message
144  strprintf(_("Are you sure you want to leave guild %s?"),
145  mGuild->getName().c_str()),
147  false,
148  Modal_false,
149  socialWindow);
151  }
152 
153  void buildCounter(const int online0, const int total0) override final
154  {
155  if ((online0 != 0) || (total0 != 0))
156  {
157  // TRANSLATORS: social window label
158  mCounterString = strprintf(_("Members: %u/%u"),
159  CAST_U32(online0),
160  CAST_U32(total0));
161  }
162  else
163  {
164  if (localPlayer == nullptr)
165  return;
166 
167  const Guild *const guild = localPlayer->getGuild();
168  if (guild == nullptr)
169  return;
170 
171  const Guild::MemberList *const members = guild->getMembers();
172  int online = 0;
173  int total = 0;
174  FOR_EACHP (Guild::MemberList::const_iterator, it, members)
175  {
176  if ((*it)->getOnline())
177  online ++;
178  total ++;
179  }
180 
181  // TRANSLATORS: social window label
182  mCounterString = strprintf(_("Players: %u/%u"),
183  CAST_U32(online),
184  CAST_U32(total));
185  }
186  updateCounter();
187  }
188 
189  private:
191 };
192 
193 #endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
#define CAST_U32
Definition: cast.h:31
ChatTab * localChatTab
Definition: chattab.cpp:62
const Guild * getGuild(const std::string &guildName) const
Definition: being.cpp:1258
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
Definition: guild.h:70
const std::string & getName() const
Definition: guild.h:128
int16_t getId() const
Definition: guild.h:135
std::vector< GuildMember * > MemberList
Definition: guild.h:209
virtual void invite(const std::string &name) const =0
virtual void leave(const int guildId) const =0
SocialGuildTab(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
ConfirmDialog * mConfirmDialog
Definition: socialtab.h:137
TextDialog * mInviteDialog
Definition: socialtab.h:136
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 std::string & getText() const
Definition: textdialog.cpp:124
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:45
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:596
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:25
#define delete2(var)
Definition: delete2.h:25
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:31
#define _(s)
Definition: gettext.h:35
Net::GuildHandler * guildHandler
Definition: net.cpp:92
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
#define override
Definition: localconsts.h:47
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
LocalPlayer * localPlayer
uint32_t guild
const bool Modal_false
Definition: modal.h:30
bool Opaque
Definition: opaque.h:30
SocialWindow * socialWindow
static const std::string SOUND_REQUEST
Definition: sound.h:29
std::string strprintf(const char *const format,...)
const bool TryRemoveColors_true