ManaPlus
whispertab.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 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 "being/localplayer.h"
27 
28 #include "net/chathandler.h"
29 
30 #include "gui/windows/chatwindow.h"
31 
33 
34 #include "utils/chatutils.h"
35 
36 #include "debug.h"
37 
38 WhisperTab::WhisperTab(const Widget2 *const widget,
39  const std::string &caption,
40  const std::string &nick) :
41  ChatTab(widget, caption, nick, nick, ChatTabType::WHISPER),
42  mNick(nick)
43 {
45 }
46 
48 {
49  if (chatWindow != nullptr)
51 }
52 
53 void WhisperTab::handleInput(const std::string &msg)
54 {
55  std::string newMsg;
56  newMsg = ChatWindow::doReplace(msg);
58 
59  if (localPlayer != nullptr)
60  chatLog(localPlayer->getName(), newMsg);
61  else
62  chatLog("?", newMsg);
63 }
64 
65 void WhisperTab::handleCommandStr(const std::string &msg)
66 {
67  if (msg == "close")
68  {
69  delete this;
70  return;
71  }
72 
73  const size_t pos = msg.find(' ');
74  const std::string type(msg, 0, pos);
75 
76  if (type == "me")
77  {
78  const std::string args(msg, pos == std::string::npos
79  ? msg.size() : pos + 1);
80  std::string str = textToMe(args);
82  if (localPlayer != nullptr)
83  chatLog(localPlayer->getName(), str);
84  else
85  chatLog("?", str);
86  }
87  else
88  {
90  }
91 }
92 
93 bool WhisperTab::handleCommand(const std::string &restrict type,
94  const std::string &restrict args A_UNUSED)
95 {
96  if (type == "close")
97  {
98  if (windowContainer != nullptr)
100  else
101  delete this;
102  if (chatWindow != nullptr)
104  }
105  else
106  {
107  return false;
108  }
109 
110  return true;
111 }
112 
114 {
115  names.push_back(mNick);
116 }
117 
119 {
120  commands.push_back("/close");
121 }
122 
124 {
125  setTabColors(ThemeColorId::WHISPER_TAB);
126 }
127 
129 {
130  setTabColors(ThemeColorId::WHISPER_TAB_OFFLINE);
131 }
Net::ChatHandler * chatHandler
Definition: net.cpp:86
#define setTabColors(name)
Definition: chattab.h:51
std::string textToMe(const std::string &str)
Definition: chatutils.cpp:203
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
const std::string & getName() const
Definition: being.h:232
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:111
virtual void handleCommandStr(const std::string &msg)
Definition: chattab.cpp:441
void defaultTab()
Definition: chatwindow.cpp:433
void removeWhisper(const std::string &nick)
Definition: chatwindow.cpp:598
static std::string doReplace(const std::string &msg)
virtual void privateMessage(const std::string &recipient, const std::string &text) const =0
void setWhisperTabOfflineColors()
Definition: whispertab.cpp:128
void handleCommandStr(const std::string &msg)
Definition: whispertab.cpp:65
WhisperTab(const Widget2 *const widget, const std::string &caption, const std::string &nick)
Definition: whispertab.cpp:38
void setWhisperTabColors()
Definition: whispertab.cpp:123
void handleInput(const std::string &msg)
Definition: whispertab.cpp:53
bool handleCommand(const std::string &type, const std::string &args)
Definition: whispertab.cpp:93
std::string mNick
Definition: whispertab.h:71
void getAutoCompleteList(StringVect &names) const
Definition: whispertab.cpp:113
void getAutoCompleteCommands(StringVect &commands) const
Definition: whispertab.cpp:118
void scheduleDelete(Widget *const widget)
#define restrict
Definition: localconsts.h:165
#define A_UNUSED
Definition: localconsts.h:160
LocalPlayer * localPlayer
bool msg(InputEvent &event)
Definition: chat.cpp:39
std::vector< std::string > StringVect
Definition: stringvector.h:29
WindowContainer * windowContainer