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