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-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_SOCIALPARTYTAB_H
24 #define GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
25 
27 
28 #include "const/sound.h"
29 
30 #include "party.h"
31 
32 #include "being/localplayer.h"
33 
34 #include "net/partyhandler.h"
35 
36 #include "utils/delete2.h"
37 #include "utils/foreach.h"
38 #include "utils/gettext.h"
39 #include "utils/stringutils.h"
40 
41 #include "localconsts.h"
42 
44  public ActionListener
45 {
46  public:
47  SocialPartyTab(const Widget2 *const widget,
48  Party *const party,
49  const Opaque showBackground) :
50  SocialTab(widget),
52  mParty(party)
53  {
54  // TRANSLATORS: tab in social window
55  setCaption(_("Party"));
56 
57  setTabColor(&getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB, 255U),
58  &getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB_OUTLINE, 255U));
60  ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED, 255U),
62  ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE, 255U));
64  ThemeColorId::PARTY_SOCIAL_TAB_SELECTED, 255U),
66  ThemeColorId::PARTY_SOCIAL_TAB_SELECTED_OUTLINE, 255U));
67 
68  createControls(party, showBackground);
69  mMenuAction = "party";
70  }
71 
73 
75  {
76  delete2(mList)
78  }
79 
80  void action(const ActionEvent &event) override final
81  {
82  const std::string &eventId = event.getId();
83  if (eventId == "do invite")
84  {
85  const std::string name = mInviteDialog->getText();
86  partyHandler->invite(name);
87 
88  if (localChatTab != nullptr)
89  {
91  // TRANSLATORS: chat message
92  _("Invited user %s to party."),
93  name.c_str()),
97  }
98  mInviteDialog = nullptr;
99  }
100  else if (eventId == "~do invite")
101  {
102  mInviteDialog = nullptr;
103  }
104  else if (eventId == "yes")
105  {
106  partyHandler->leave();
107  if (localChatTab != nullptr)
108  {
110  // TRANSLATORS: tab in social window
111  _("Party %s quit requested."),
112  mParty->getName().c_str()),
116  }
117  mConfirmDialog = nullptr;
118  }
119  else if (eventId == "~yes")
120  {
121  mConfirmDialog = nullptr;
122  }
123  }
124 
126  {
128  // TRANSLATORS: party invite message
129  _("Member Invite to Party"),
130  // TRANSLATORS: party invite message
131  strprintf(_("Who would you like to invite to party %s?"),
132  mParty->getName().c_str()),
133  socialWindow,
134  false);
135  mInviteDialog->setActionEventId("do invite");
137  }
138 
140  {
142  // TRANSLATORS: party leave message
143  _("Leave Party?"),
144  // TRANSLATORS: party leave message
145  strprintf(_("Are you sure you want to leave party %s?"),
146  mParty->getName().c_str()),
148  false,
149  Modal_false,
150  socialWindow);
152  }
153 
154  void buildCounter(const int online0 A_UNUSED,
155  const int total0 A_UNUSED) override final
156  {
157  if (localPlayer == nullptr)
158  return;
159 
160  const Party *const party = localPlayer->getParty();
161  if (party == nullptr)
162  return;
163 
164  const Party::MemberList *const members = party->getMembers();
165  int online = 0;
166  int total = 0;
167  FOR_EACHP (Party::MemberList::const_iterator, it, members)
168  {
169  if ((*it)->getOnline())
170  online ++;
171  total ++;
172  }
173 
174  // TRANSLATORS: social window label
175  mCounterString = strprintf(_("Players: %u/%u"),
176  CAST_U32(online),
177  CAST_U32(total));
178  updateCounter();
179  }
180 
181  private:
183 };
184 
185 #endif // GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
#define CAST_U32
Definition: cast.h:31
ChatTab * localChatTab
Definition: chattab.cpp:62
Party * getParty() const
Definition: being.h:330
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
virtual void leave() const =0
virtual void invite(const std::string &name) const =0
Definition: party.h:63
std::vector< PartyMember * > MemberList
Definition: party.h:157
const std::string & getName() const
Definition: party.h:97
void action(const ActionEvent &event)
void buildCounter(const int online0, const int total0)
SocialPartyTab(const Widget2 *const widget, Party *const party, const Opaque showBackground)
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
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
#define A_UNUSED
Definition: localconsts.h:160
LocalPlayer * localPlayer
uint32_t party
const bool Modal_false
Definition: modal.h:30
Net::PartyHandler * partyHandler
Definition: net.cpp:94
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