ManaPlus
partytab.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
25 
26 #include "configuration.h"
27 #include "party.h"
28 #include "soundmanager.h"
29 
30 #include "being/localplayer.h"
31 
32 #include "const/sound.h"
33 
34 #include "gui/windows/chatwindow.h"
35 
36 #include "input/inputmanager.h"
37 
38 #include "net/net.h"
39 #include "net/partyhandler.h"
40 
41 #include "utils/gettext.h"
42 
43 #include "debug.h"
44 
45 PartyTab *partyTab = nullptr;
46 
47 PartyTab::PartyTab(const Widget2 *const widget) :
48  // TRANSLATORS: party chat tab name
49  ChatTab(widget, _("Party"), "", "#Party", ChatTabType::PARTY)
50 {
51  setTabColors(ThemeColorId::PARTY_CHAT_TAB);
52  mShowOnline = config.getBoolValue("showPartyOnline");
53  config.addListener("showPartyOnline", this);
54 }
55 
57 {
58  config.removeListeners(this);
60 }
61 
62 void PartyTab::handleInput(const std::string &msg)
63 {
65 }
66 
67 bool PartyTab::handleCommand(const std::string &restrict type,
68  const std::string &restrict args)
69 {
70  if (type == "invite")
71  {
72  partyHandler->invite(args);
73  }
74  else if (type == "leave")
75  {
77  args,
78  this);
79  }
80  else if (type == "kick")
81  {
83  args,
84  this);
85  }
86  else if (type == "item")
87  {
89  args,
90  this);
91  }
92  else if (type == "autoitem")
93  {
95  args,
96  this);
97  }
98  else if (type == "exp")
99  {
101  args,
102  this);
103  }
104  else if (type == "setleader" &&
106  {
109  args,
110  this);
111  }
112  else
113  {
114  return false;
115  }
116 
117  return true;
118 }
119 
121 {
122  if (localPlayer == nullptr)
123  return;
124 
125  const Party *const p = localPlayer->getParty();
126 
127  if (p != nullptr)
128  p->getNames(names);
129 }
130 
132 {
133  names.push_back("/help");
134  names.push_back("/invite ");
135  names.push_back("/leave");
136  names.push_back("/kick ");
137  names.push_back("/item");
138  names.push_back("/exp");
140  names.push_back("/setleader ");
141 }
142 
144 {
146 }
147 
148 void PartyTab::optionChanged(const std::string &value)
149 {
150  if (value == "showPartyOnline")
151  mShowOnline = config.getBoolValue("showPartyOnline");
152 }
#define setTabColors(name)
Definition: chattab.h:51
Party * getParty() const
Definition: being.h:330
bool mShowOnline
Definition: chattab.h:215
static std::string doReplace(const std::string &msg)
bool getBoolValue(const std::string &key) const
void addListener(const std::string &key, ConfigListener *const listener)
void removeListeners(ConfigListener *const listener)
bool executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
virtual void invite(const std::string &name) const =0
virtual void chat(const std::string &text) const =0
void playNewMessageSound() const
Definition: partytab.cpp:143
~PartyTab()
Definition: partytab.cpp:56
void getAutoCompleteList(StringVect &names) const
Definition: partytab.cpp:120
void optionChanged(const std::string &value)
Definition: partytab.cpp:148
PartyTab(const Widget2 *const widget)
Definition: partytab.cpp:47
void handleInput(const std::string &msg)
Definition: partytab.cpp:62
bool handleCommand(const std::string &type, const std::string &args)
Definition: partytab.cpp:67
void getAutoCompleteCommands(StringVect &names) const
Definition: partytab.cpp:131
Definition: party.h:63
void getNames(StringVect &names) const
Definition: party.cpp:285
void playGuiSound(const std::string &name)
Configuration config
#define _(s)
Definition: gettext.h:35
InputManager inputManager
#define restrict
Definition: localconsts.h:165
#define CHECKLISTENERS
Definition: localconsts.h:277
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39
@ PARTY_AUTO_ITEM_SHARE
Definition: inputaction.h:687
@ COMMAND_CHANGE_PARTY_LEADER
Definition: inputaction.h:667
ServerTypeT getNetworkType()
Definition: net.cpp:189
Net::PartyHandler * partyHandler
Definition: net.cpp:94
PartyTab * partyTab
Definition: partytab.cpp:45
static const std::string SOUND_PARTY
Definition: sound.h:35
SoundManager soundManager
std::vector< std::string > StringVect
Definition: stringvector.h:29