ManaPlus
socialpartytab.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_SOCIALPARTYTAB_H
23 #define GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
24 
26 
27 #include "const/sound.h"
28 
29 #include "party.h"
30 
31 #include "being/localplayer.h"
32 
33 #include "net/partyhandler.h"
34 
35 #include "utils/delete2.h"
36 #include "utils/foreach.h"
37 #include "utils/gettext.h"
38 #include "utils/stringutils.h"
39 
40 #include "localconsts.h"
41 
43  public ActionListener
44 {
45  public:
46  SocialPartyTab(const Widget2 *const widget,
47  Party *const party,
48  const Opaque showBackground) :
49  SocialTab(widget),
51  mParty(party)
52  {
53  // TRANSLATORS: tab in social window
54  setCaption(_("Party"));
55 
66 
67  createControls(party, showBackground);
68  mMenuAction = "party";
69  }
70 
72 
74  {
75  delete2(mList)
77  }
78 
79  void action(const ActionEvent &event) override final
80  {
81  const std::string &eventId = event.getId();
82  if (eventId == "do invite")
83  {
84  const std::string name = mInviteDialog->getText();
85  partyHandler->invite(name);
86 
87  if (localChatTab != nullptr)
88  {
90  // TRANSLATORS: chat message
91  _("Invited user %s to party."),
92  name.c_str()),
96  }
97  mInviteDialog = nullptr;
98  }
99  else if (eventId == "~do invite")
100  {
101  mInviteDialog = nullptr;
102  }
103  else if (eventId == "yes")
104  {
105  partyHandler->leave();
106  if (localChatTab != nullptr)
107  {
109  // TRANSLATORS: tab in social window
110  _("Party %s quit requested."),
111  mParty->getName().c_str()),
115  }
116  mConfirmDialog = nullptr;
117  }
118  else if (eventId == "~yes")
119  {
120  mConfirmDialog = nullptr;
121  }
122  }
123 
125  {
127  // TRANSLATORS: party invite message
128  _("Member Invite to Party"),
129  // TRANSLATORS: party invite message
130  strprintf(_("Who would you like to invite to party %s?"),
131  mParty->getName().c_str()),
132  socialWindow,
133  false);
134  mInviteDialog->setActionEventId("do invite");
136  }
137 
139  {
141  // TRANSLATORS: party leave message
142  _("Leave Party?"),
143  // TRANSLATORS: party leave message
144  strprintf(_("Are you sure you want to leave party %s?"),
145  mParty->getName().c_str()),
147  false,
148  Modal_false,
149  socialWindow);
151  }
152 
153  void buildCounter(const int online0 A_UNUSED,
154  const int total0 A_UNUSED) override final
155  {
156  if (localPlayer == nullptr)
157  return;
158 
159  const Party *const party = localPlayer->getParty();
160  if (party == nullptr)
161  return;
162 
163  const Party::MemberList *const members = party->getMembers();
164  int online = 0;
165  int total = 0;
166  FOR_EACHP (Party::MemberList::const_iterator, it, members)
167  {
168  if ((*it)->getOnline())
169  online ++;
170  total ++;
171  }
172 
173  // TRANSLATORS: social window label
174  mCounterString = strprintf(_("Players: %u/%u"),
175  CAST_U32(online),
176  CAST_U32(total));
177  updateCounter();
178  }
179 
180  private:
182 };
183 
184 #endif // GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
#define CAST_U32
Definition: cast.h:30
virtual void leave() const =0
#define _(s)
Definition: gettext.h:34
#define FOR_EACHP(type, iter, array)
Definition: foreach.h:30
Definition: party.h:61
void buildCounter(const int online0, const int total0)
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
TextDialog * mInviteDialog
Definition: socialtab.h:135
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
void action(const ActionEvent &event)
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
Party * getParty() const
Definition: being.h:329
void setActionEventId(const std::string &actionEventId)
Definition: widget.h:595
#define CREATEWIDGETV(var, type,...)
Definition: createwidget.h:24
const std::string & getName() const
Definition: party.h:96
#define delete2(var)
Definition: delete2.h:24
uint32_t party
std::vector< PartyMember * > MemberList
Definition: party.h:156
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:123
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
SocialWindow * socialWindow
const MemberList * getMembers() const
Definition: party.h:158
#define A_UNUSED
Definition: localconsts.h:159
virtual void invite(const std::string &name) const =0
SocialPartyTab(const Widget2 *const widget, Party *const party, const Opaque showBackground)
Net::PartyHandler * partyHandler
Definition: net.cpp:91
const Color & getThemeColor(const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
Definition: widget2.h:44
#define override
Definition: localconsts.h:46
void updateCounter() const
Definition: socialtab.h:123