ManaPlus
Public Member Functions | Protected Member Functions | Protected Attributes | Friends
ChatTab Class Reference

#include <chattab.h>

Inheritance diagram for ChatTab:
Tab BasicContainer MouseListener WidgetListener Widget WidgetDeathListener Widget2 BattleTab ChannelTab EmulateGuildTab GmTab GuildTab LangTab PartyTab TradeTab WhisperTab

Public Member Functions

 ChatTab (const Widget2 *const widget, const std::string &name, const std::string &channel, const std::string &logName, const ChatTabTypeT &type)
 
 ~ChatTab ()
 
void chatLog (std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
 
void chatLog (const std::string &nick, std::string msg)
 
void chatInput (const std::string &msg)
 
void scroll (const int amount)
 
void clearText ()
 
virtual bool handleCommand (const std::string &type, const std::string &args)
 
virtual bool handleCommands (const std::string &type, const std::string &args)
 
ChatTabTypeT getType () const
 
void saveToLogFile (const std::string &msg) const
 
const std::list< std::string > & getRows () const
 
bool hasRows () const
 
void loadFromLogFile (const std::string &name)
 
bool getAllowHighlight () const
 
void setAllowHighlight (const bool n)
 
bool getRemoveNames () const
 
void setRemoveNames (const bool n)
 
bool getNoAway () const
 
void setNoAway (const bool n)
 
void addNewRow (std::string &line)
 
void showOnline (const std::string &nick, const Online online)
 
virtual void playNewMessageSound () const
 
const std::string & getChannelName () const
 
- Public Member Functions inherited from Tab
 Tab (const Widget2 *const widget)
 
 ~Tab ()
 
void updateAlpha ()
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
void setTabColor (const Color *const color1, const Color *const color2)
 
void setHighlightedTabColor (const Color *const color1, const Color *const color2)
 
void setSelectedTabColor (const Color *const color1, const Color *const color2)
 
void setFlashTabColor (const Color *const color1, const Color *const color2)
 
void setPlayerFlashTabColor (const Color *const color1, const Color *const color2)
 
void setFlash (const int flash)
 
int getFlash () const
 
void widgetResized (const Event &event)
 
void widgetMoved (const Event &event)
 
void setLabelFont (Font *const font)
 
LabelgetLabel () const
 
void adjustSize ()
 
void setTabbedArea (TabbedArea *tabbedArea)
 
TabbedAreagetTabbedArea () const
 
void setCaption (const std::string &caption)
 
const std::string & getCaption () const
 
void mouseEntered (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
void setImage (Image *const image)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mousePressed (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseMoved (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 
- Public Member Functions inherited from WidgetListener
virtual ~WidgetListener ()
 
virtual void widgetHidden (const Event &event)
 
virtual void widgetShown (const Event &event)
 

Protected Member Functions

void setCurrent ()
 
virtual void handleInput (const std::string &msg)
 
virtual void handleCommandStr (const std::string &msg)
 
virtual void handleHelp (const std::string &msg)
 
virtual void getAutoCompleteList (StringVect &names) const
 
virtual void getAutoCompleteCommands (StringVect &names) const
 
void addRow (std::string &line)
 
- Protected Member Functions inherited from BasicContainer
virtual void drawChildren (Graphics *const graphics)
 
virtual void safeDrawChildren (Graphics *const graphics)
 
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 
- Protected Member Functions inherited from WidgetListener
 WidgetListener ()
 

Protected Attributes

BrowserBoxmTextOutput
 
ScrollAreamScrollArea
 
std::string mChannelName
 
std::string mLogName
 
ChatTabTypeT mType
 
bool mAllowHightlight
 
bool mRemoveNames
 
bool mNoAway
 
bool mShowOnline
 
- Protected Attributes inherited from Tab
LabelmLabel
 
TabbedAreamTabbedArea
 
bool mHasMouse
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 

Friends

class ChatWindow
 
class WhisperWindow
 

Additional Inherited Members

- Public Types inherited from Tab
enum  {
  TAB_STANDARD = 0, TAB_HIGHLIGHTED = 1, TAB_SELECTED = 2, TAB_UNUSED = 3,
  TAB_COUNT = 4
}
 
- Static Public Member Functions inherited from Tab
static void finalCleanup ()
 
- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

A tab for the chat window. This is special to ease chat handling.

Definition at line 61 of file chattab.h.

Constructor & Destructor Documentation

◆ ChatTab()

ChatTab::ChatTab ( const Widget2 *const  widget,
const std::string &  name,
const std::string &  channel,
const std::string &  logName,
const ChatTabTypeT type 
)

Constructor.

Definition at line 66 of file chattab.cpp.

References ChatWindow::addTab(), chatWindow, config, Configuration::getIntValue(), ChatWindow::mItemLinkHandler, mScrollArea, mTextOutput, Opaque_false, BrowserBox::setAlwaysUpdate(), Tab::setCaption(), BrowserBox::setLinkHandler(), BrowserBox::setMaxRow(), BrowserBox::setOpaque(), ScrollArea::setScrollAmount(), ScrollArea::setScrollPolicy(), ScrollArea::SHOW_ALWAYS, ScrollArea::SHOW_NEVER, and BrowserBox::updateSize().

70  :
71  Tab(widget),
73  "browserbox.xml")),
74  mScrollArea(new ScrollArea(this,
75  mTextOutput, Opaque_false, std::string())),
77  mLogName(logName),
78  mType(type),
79  mAllowHightlight(true),
80  mRemoveNames(false),
81  mNoAway(false),
82  mShowOnline(false)
83 {
84  setCaption(name);
85 
87  mTextOutput->setMaxRow(config.getIntValue("ChatLogLength"));
88  if (chatWindow != nullptr)
91 
95 
96  if (chatWindow != nullptr)
97  chatWindow->addTab(this);
98  mTextOutput->updateSize(true);
99 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
bool mNoAway
Definition: chattab.h:213
Tab(const Widget2 *const widget)
Definition: tab.cpp:102
ScrollArea * mScrollArea
Definition: chattab.h:207
void addTab(ChatTab *const tab)
Definition: chatwindow.cpp:583
void setCaption(const std::string &caption)
Definition: tab.cpp:457
void setScrollPolicy(const ScrollPolicy hPolicy, const ScrollPolicy vPolicy)
Configuration config
int getIntValue(const std::string &key) const
bool mAllowHightlight
Definition: chattab.h:211
std::string mLogName
Definition: chattab.h:209
const bool Opaque_false
Definition: opaque.h:29
BrowserBox * mTextOutput
Definition: chattab.h:206
bool mRemoveNames
Definition: chattab.h:212
bool mShowOnline
Definition: chattab.h:214
void setMaxRow(unsigned max)
Definition: browserbox.h:80
void setLinkHandler(LinkHandler *linkHandler)
Definition: browserbox.cpp:165
const bool Opaque_true
Definition: opaque.h:29
void setScrollAmount(const int hScroll, const int vScroll)
ItemLinkHandler * mItemLinkHandler
Definition: chatwindow.h:340
std::string mChannelName
Definition: chattab.h:208
void setOpaque(Opaque opaque)
Definition: browserbox.h:74
ChatTabTypeT mType
Definition: chattab.h:210
void updateSize(const bool always)
Definition: browserbox.cpp:862
void setAlwaysUpdate(const bool n)
Definition: browserbox.h:129

◆ ~ChatTab()

ChatTab::~ChatTab ( )

Definition at line 101 of file chattab.cpp.

References chatWindow, delete2, mScrollArea, mTextOutput, and ChatWindow::removeTab().

102 {
103  if (chatWindow != nullptr)
104  chatWindow->removeTab(this);
105 
108 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
ScrollArea * mScrollArea
Definition: chattab.h:207
void removeTab(ChatTab *const tab)
Definition: chatwindow.cpp:578
#define delete2(var)
Definition: delete2.h:24
BrowserBox * mTextOutput
Definition: chattab.h:206

Member Function Documentation

◆ addNewRow()

void ChatTab::addNewRow ( std::string &  line)

Definition at line 526 of file chattab.cpp.

References addRow(), ScrollArea::getVerticalMaxScroll(), ScrollArea::getVerticalScrollAmount(), ScrollArea::logic(), mScrollArea, and ScrollArea::setVerticalScrollAmount().

Referenced by ChatWindow::displayAwayLog(), and setNoAway().

527 {
530  {
531  addRow(line);
534  }
535  else
536  {
537  addRow(line);
538  }
539  mScrollArea->logic();
540 }
ScrollArea * mScrollArea
Definition: chattab.h:207
void setVerticalScrollAmount(const int vScroll)
void addRow(std::string &line)
Definition: chattab.cpp:488
int getVerticalMaxScroll()
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
void logic()
Definition: scrollarea.cpp:272

◆ addRow()

void ChatTab::addRow ( std::string &  line)
protected

Definition at line 488 of file chattab.cpp.

References BrowserBox::addRow(), and mTextOutput.

Referenced by addNewRow(), chatLog(), getAutoCompleteCommands(), and loadFromLogFile().

489 {
490  if (line.find("[@@http") == std::string::npos)
491  {
492  size_t idx = 0;
493  for (size_t f = 0; f < line.length(); f++)
494  {
495  if (line.at(f) == ' ')
496  {
497  idx = f;
498  }
499  else if (f - idx > MAX_WORD_SIZE)
500  {
501  line.insert(f, " ");
502  idx = f;
503  }
504  }
505  }
506  mTextOutput->addRow(line,
507  false);
508 }
BrowserBox * mTextOutput
Definition: chattab.h:206
static const unsigned int MAX_WORD_SIZE
Definition: chattab.cpp:64
void addRow(const std::string &row, const bool atTop)
Definition: browserbox.cpp:170

◆ chatInput()

void ChatTab::chatInput ( const std::string &  msg)

Determines whether the message is a command or message, then sends the given message to the game server to be said, or to the command handler

Parameters
msgThe message text which is to be sent.

Definition at line 381 of file chattab.cpp.

References handleCommandStr(), handleHelp(), handleInput(), Actions::msg(), replaceItemLinks(), BrowserBoxTools::replaceVars(), and Catch::trim().

Referenced by ChatWindow::addWhisper(), ChatWindow::chatInput(), ChatWindow::localChatInput(), Actions::outString(), and Actions::splitWhisper().

382 {
383  std::string msg = message;
384  trim(msg);
385 
386  if (msg.empty())
387  return;
388 
389  replaceItemLinks(msg);
390  replaceVars(msg);
391 
392  switch (msg[0])
393  {
394  case '/':
395  handleCommandStr(std::string(msg, 1));
396  break;
397  case '?':
398  if (msg.size() > 1 &&
399  msg[1] != '!' &&
400  msg[1] != '?' &&
401  msg[1] != '.' &&
402  msg[1] != ' ' &&
403  msg[1] != ',')
404  {
405  handleHelp(std::string(msg, 1));
406  }
407  else
408  {
409  handleInput(msg);
410  }
411  break;
412  default:
413  handleInput(msg);
414  break;
415  }
416 }
void replaceItemLinks(std::string &msg)
void replaceVars(std::string &data)
virtual void handleHelp(const std::string &msg)
Definition: chattab.cpp:452
bool msg(InputEvent &event)
Definition: chat.cpp:38
std::string trim(std::string const &str)
virtual void handleInput(const std::string &msg)
Definition: chattab.cpp:432
virtual void handleCommandStr(const std::string &msg)
Definition: chattab.cpp:441

◆ chatLog() [1/2]

void ChatTab::chatLog ( std::string  line,
ChatMsgTypeT  own,
const IgnoreRecord  ignoreRecord,
const TryRemoveColors  tryRemoveColors 
)

Adds a line of text to our message list. Parameters:

Parameters
lineText message.
ownType of message (usually the owner-type).
ignoreRecordshould this not be recorded?
tryRemoveColorstry remove color if configured

Definition at line 110 of file chattab.cpp.

References _, ChatMsgType::ACT_IS, ChatMsgType::ACT_WHISPER, addRow(), ChatWindow::addToAwayLog(), ChatMsgType::BY_CHANNEL, ChatMsgType::BY_GM, ChatMsgType::BY_LOGGER, ChatMsgType::BY_OTHER, ChatMsgType::BY_PLAYER, ChatMsgType::BY_SERVER, ChatMsgType::BY_UNKNOWN, CAST_S32, ChatTabType::CHANNEL, chatLog(), chatWindow, config, ChatWindow::findHighlight(), getAllowHighlight(), Configuration::getBoolValue(), Tab::getFlash(), Configuration::getIntValue(), WindowManager::getIsMinimized(), Net::getNetworkType(), TabbedArea::getSelectedTab(), Tab::getTabbedArea(), getType(), ScrollArea::getVerticalMaxScroll(), ScrollArea::getVerticalScrollAmount(), ChatTabType::GUILD, Settings::inputFocused, ScrollArea::logic(), Settings::mouseFocused, mScrollArea, mTextOutput, WindowManager::newChatMessage(), CHATLOG::nick, CHATLOG::own, ChatTabType::PARTY, SoundManager::playGuiSound(), playNewMessageSound(), removeColors(), saveToLogFile(), Tab::setFlash(), BrowserBox::setMaxRow(), settings, ScrollArea::setVerticalScrollAmount(), SOUND_GLOBAL, SOUND_HIGHLIGHT, soundManager, strprintf(), CHATLOG::text, ServerCommandType::time, ServerType::TMWATHENA, Catch::trim(), TryRemoveColors_true, KeyboardFocus::Unfocused, and ChatWindow::unHideWindow().

Referenced by SocialWindow::action(), SocialGuildTab::action(), SocialPartyTab::action(), TradeWindow::action(), ChatWindow::addGlobalMessage(), ChatWindow::addWhisper(), Game::adjustPerfomance(), LocalPlayer::afkRespond(), ChatWindow::battleChatLog(), Actions::changeRelation(), ChatWindow::channelChatLog(), GuildManager::chat(), NotifyManager::chatLog(), chatLog(), TradeWindow::checkItem(), createGuiWindows(), ChatWindow::debugMessage(), StatusEffect::deliverMessage(), ChatWindow::doPresent(), Actions::doSit(), Actions::getNick(), WhisperTab::handleCommandStr(), WhisperTab::handleInput(), NotifyManager::notify(), outStringNormal(), LocalPlayer::pickedUp(), ActorManager::printBeingsToChat(), GuildManager::process(), EAthena::ChatRecv::processChatTalkieBox(), EAthena::GuildRecv::processGuildBasicInfo(), EAthena::GuildRecv::processGuildMessage(), EAthena::GuildRecv::processGuildNotice(), TmwAthena::PartyRecv::processPartyMessage(), EAthena::PartyRecv::processPartyMessage(), TmwAthena::ChatRecv::processScriptMessage(), EAthena::ChatRecv::processScriptMessage(), TmwAthena::ChatRecv::processWhisperContinue(), EAthena::ChatRecv::processWhisperContinue(), ChatWindow::resortChatLog(), Game::saveScreenshot(), SocialWindow::showGuildInvite(), showOnline(), SocialWindow::showPartyInvite(), and Actions::splitWhisper().

114 {
115  // Trim whitespace
116  trim(line);
117 
118  if (line.empty())
119  return;
120 
121  if (tryRemoveColors == TryRemoveColors_true &&
122  own == ChatMsgType::BY_OTHER &&
123  config.getBoolValue("removeColors"))
124  {
125  line = removeColors(line);
126  if (line.empty())
127  return;
128  }
129 
130  const unsigned lineLim = config.getIntValue("chatMaxCharLimit");
131  if (lineLim > 0 && line.length() > lineLim)
132  line = line.substr(0, lineLim);
133 
134  if (line.empty())
135  return;
136 
137  CHATLOG tmp;
138  tmp.own = own;
139  tmp.nick.clear();
140  tmp.text = line;
141 
142  const size_t pos = line.find(" : ");
143  if (pos != std::string::npos)
144  {
145  if (line.length() <= pos + 3)
146  return;
147 
148  tmp.nick = line.substr(0, pos);
149  tmp.text = line.substr(pos + 3);
150  }
151  else
152  {
153  // Fix the owner of welcome message.
154  if (line.length() > 7 && line.substr(0, 7) == "Welcome")
156  }
157 
158  // *implements actions in a backwards compatible way*
159  if ((own == ChatMsgType::BY_PLAYER || own == ChatMsgType::BY_OTHER) &&
160  tmp.text.at(0) == '*' &&
161  tmp.text.at(tmp.text.length()-1) == '*')
162  {
163  tmp.text[0] = ' ';
164  tmp.text.erase(tmp.text.length() - 1);
165  own = ChatMsgType::ACT_IS;
166  }
167 
168  std::string lineColor("##C");
169  switch (own)
170  {
171  case ChatMsgType::BY_GM:
172  if (tmp.nick.empty())
173  {
174  // TRANSLATORS: chat message
175  tmp.nick = std::string(_("Global announcement:")).append(" ");
176  lineColor = "##G";
177  }
178  else
179  {
180  // TRANSLATORS: chat message
181  tmp.nick = strprintf(_("Global announcement from %s:"),
182  tmp.nick.c_str()).append(" ");
183  lineColor = "##g"; // Equiv. to BrowserBox::RED
184  }
185  break;
187  tmp.nick.append(": ");
188  lineColor = "##Y";
189  break;
192  tmp.nick.append(": ");
193  lineColor = "##C";
194  break;
196  // TRANSLATORS: chat message
197  tmp.nick.clear();
198  tmp.text = line;
199  lineColor = "##S";
200  break;
202  tmp.nick.clear();
203  lineColor = "##2"; // Equiv. to BrowserBox::GREEN
204  break;
206  // TRANSLATORS: chat message
207  tmp.nick = strprintf(_("%s whispers: %s"), tmp.nick.c_str(), "");
208  lineColor = "##W";
209  break;
210  case ChatMsgType::ACT_IS:
211  lineColor = "##I";
212  break;
214  tmp.nick.clear();
215  tmp.text = line;
216  lineColor = "##L";
217  break;
218  default:
219  break;
220  }
221 
222  if (tmp.nick == ": ")
223  {
224  tmp.nick.clear();
225  lineColor = "##S";
226  }
227 
228  // if configured, move magic messages log to debug chat tab
230  && (localChatTab != nullptr) && this == localChatTab
231  && ((config.getBoolValue("showMagicInDebug")
232  && own == ChatMsgType::BY_PLAYER
233  && tmp.text.length() > 1
234  && tmp.text.at(0) == '#'
235  && tmp.text.at(1) != '#')
236  || (config.getBoolValue("serverMsgInDebug")
237  && (own == ChatMsgType::BY_SERVER
238  || tmp.nick.empty()))))
239  {
240  if (debugChatTab != nullptr)
241  debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
242  return;
243  }
244 
245  // Get the current system time
246  time_t t;
247  time(&t);
248 
249  if (config.getBoolValue("useLocalTime"))
250  {
251  const tm *const timeInfo = localtime(&t);
252  if (timeInfo != nullptr)
253  {
254  line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
255  timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
256  tmp.text.c_str());
257  }
258  else
259  {
260  line = strprintf("%s %s%s", lineColor.c_str(),
261  tmp.nick.c_str(), tmp.text.c_str());
262  }
263  }
264  else
265  {
266  // Format the time string properly
267  std::stringstream timeStr;
268  timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
269  << CAST_S32(((t / 60) / 60) % 24)
270  << ":" << (((t / 60) % 60 < 10) ? "0" : "")
271  << CAST_S32((t / 60) % 60)
272  << "] ";
273  line = std::string(lineColor).append(timeStr.str()).append(
274  tmp.nick).append(tmp.text);
275  }
276 
277  if (config.getBoolValue("enableChatLog"))
278  saveToLogFile(line);
279 
280  mTextOutput->setMaxRow(config.getIntValue("chatMaxLinesLimit"));
281 
282  // We look if the Vertical Scroll Bar is set at the max before
283  // adding a row, otherwise the max will always be a row higher
284  // at comparison.
287  {
288  addRow(line);
291  }
292  else
293  {
294  addRow(line);
295  }
296 
297  if ((chatWindow != nullptr) && this == localChatTab)
298  chatWindow->addToAwayLog(line);
299 
300  mScrollArea->logic();
301  if (own != ChatMsgType::BY_PLAYER)
302  {
303  if (own == ChatMsgType::BY_SERVER &&
304  (getType() == ChatTabType::PARTY ||
307  {
308  return;
309  }
310 
311  const TabbedArea *const tabArea = getTabbedArea();
312  if (tabArea == nullptr)
313  return;
314 
315  const bool notFocused = WindowManager::getIsMinimized() ||
318 
319  if (this != tabArea->getSelectedTab() || notFocused)
320  {
321  if (getFlash() == 0)
322  {
323  if (chatWindow != nullptr &&
325  {
326  setFlash(2);
328  }
329  else
330  {
331  setFlash(1);
332  }
333  }
334  else if (getFlash() == 2)
335  {
336  if (chatWindow != nullptr &&
338  {
340  }
341  }
342  }
343 
344  if ((getAllowHighlight() ||
345  own == ChatMsgType::BY_GM) &&
346  (this != tabArea->getSelectedTab() ||
347  notFocused))
348  {
349  if (own == ChatMsgType::BY_GM)
350  {
351  if (chatWindow != nullptr)
354  }
355  else if (own != ChatMsgType::BY_SERVER)
356  {
357  if (chatWindow != nullptr)
360  }
362  }
363  }
364 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
#define _(s)
Definition: gettext.h:34
ScrollArea * mScrollArea
Definition: chattab.h:207
void saveToLogFile(const std::string &msg) const
Definition: chattab.cpp:468
ChatTab * localChatTab
Definition: chattab.cpp:61
TabbedArea * getTabbedArea() const
Definition: tab.cpp:452
SoundManager soundManager
Configuration config
void setFlash(const int flash)
Definition: tab.h:174
void unHideWindow()
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
int getIntValue(const std::string &key) const
std::string removeColors(std::string msg)
void setVerticalScrollAmount(const int vScroll)
void addRow(std::string &line)
Definition: chattab.cpp:488
int getVerticalMaxScroll()
Settings settings
Definition: settings.cpp:31
bool getBoolValue(const std::string &key) const
ChatMsgTypeT own
Definition: chatlog.h:46
#define CAST_S32
Definition: cast.h:29
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
int getFlash() const
Definition: tab.h:177
std::string trim(std::string const &str)
KeyboardFocusT inputFocused
Definition: settings.h:152
ChatTabTypeT getType() const
Definition: chattab.h:144
BrowserBox * mTextOutput
Definition: chattab.h:206
ServerTypeT getNetworkType()
Definition: net.cpp:178
ChatTab * debugChatTab
Definition: chattab.cpp:62
void setMaxRow(unsigned max)
Definition: browserbox.h:80
virtual void playNewMessageSound() const
Definition: chattab.cpp:542
Tab * getSelectedTab() const
Definition: tabbedarea.h:174
bool getAllowHighlight() const
Definition: chattab.h:157
static const std::string SOUND_GLOBAL
Definition: sound.h:32
static const std::string SOUND_HIGHLIGHT
Definition: sound.h:31
void addToAwayLog(const std::string &line)
std::string text
Definition: chatlog.h:45
bool findHighlight(const std::string &str)
bool mouseFocused
Definition: settings.h:153
std::string nick
Definition: chatlog.h:44
void playGuiSound(const std::string &name)
void logic()
Definition: scrollarea.cpp:272

◆ chatLog() [2/2]

void ChatTab::chatLog ( const std::string &  nick,
std::string  msg 
)

Adds the text to the message list

Parameters
msgThe message text which is to be sent.

Definition at line 366 of file chattab.cpp.

References ChatMsgType::BY_OTHER, ChatMsgType::BY_PLAYER, chatLog(), config, Configuration::getBoolValue(), Being::getName(), IgnoreRecord_false, localPlayer, removeColors(), and TryRemoveColors_false.

367 {
368  if (localPlayer == nullptr)
369  return;
370 
371  const ChatMsgTypeT byWho = (nick == localPlayer->getName()
373  if (byWho == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors"))
374  msg = removeColors(msg);
375  chatLog(std::string(nick).append(" : ").append(msg),
376  byWho,
379 }
Configuration config
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
bool msg(InputEvent &event)
Definition: chat.cpp:38
std::string removeColors(std::string msg)
bool getBoolValue(const std::string &key) const
LocalPlayer * localPlayer
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
const std::string & getName() const
Definition: being.h:231
const bool TryRemoveColors_false
ChatMsgType ::T ChatMsgTypeT
Definition: chatmsgtype.h:40

◆ clearText()

void ChatTab::clearText ( )

Clears the text from the tab

Definition at line 427 of file chattab.cpp.

References BrowserBox::clearRows(), and mTextOutput.

Referenced by ChatWindow::clearTab().

428 {
430 }
BrowserBox * mTextOutput
Definition: chattab.h:206
void clearRows()
Definition: browserbox.cpp:358

◆ getAllowHighlight()

bool ChatTab::getAllowHighlight ( ) const
inline

Definition at line 157 of file chattab.h.

References mAllowHightlight.

Referenced by chatLog(), ChatWindow::saveTab(), and PopupMenu::showChatPopup().

158  { return mAllowHightlight; }
bool mAllowHightlight
Definition: chattab.h:211

◆ getAutoCompleteCommands()

virtual void ChatTab::getAutoCompleteCommands ( StringVect names) const
inlineprotectedvirtual

Reimplemented in EmulateGuildTab, GuildTab, PartyTab, WhisperTab, and ChannelTab.

Definition at line 201 of file chattab.h.

References addRow().

Referenced by ChatWindow::autoComplete().

202  {}

◆ getAutoCompleteList()

virtual void ChatTab::getAutoCompleteList ( StringVect names) const
inlineprotectedvirtual

Reimplemented in EmulateGuildTab, GuildTab, PartyTab, WhisperTab, and GmTab.

Definition at line 198 of file chattab.h.

Referenced by ChatWindow::autoComplete().

199  {}

◆ getChannelName()

const std::string& ChatTab::getChannelName ( ) const
inline

Definition at line 182 of file chattab.h.

References mChannelName.

Referenced by ChatWindow::addSpecialChannelTab(), ChatWindow::postConnection(), ChatWindow::resortChatLog(), and ChatWindow::saveTab().

183  { return mChannelName; }
std::string mChannelName
Definition: chattab.h:208

◆ getNoAway()

bool ChatTab::getNoAway ( ) const
inline

Definition at line 169 of file chattab.h.

References mNoAway.

Referenced by LocalPlayer::afkRespond(), ChatWindow::saveTab(), and PopupMenu::showChatPopup().

170  { return mNoAway; }
bool mNoAway
Definition: chattab.h:213

◆ getRemoveNames()

bool ChatTab::getRemoveNames ( ) const
inline

Definition at line 163 of file chattab.h.

References mRemoveNames.

Referenced by ChatWindow::addWhisper(), ChatWindow::saveTab(), and PopupMenu::showChatPopup().

164  { return mRemoveNames; }
bool mRemoveNames
Definition: chattab.h:212

◆ getRows()

const std::list<std::string>& ChatTab::getRows ( ) const
inline

Definition at line 149 of file chattab.h.

References BrowserBox::getRows(), and mTextOutput.

Referenced by ChatWindow::keyPressed().

150  { return mTextOutput->getRows(); }
TextRows & getRows()
Definition: browserbox.h:123
BrowserBox * mTextOutput
Definition: chattab.h:206

◆ getType()

ChatTabTypeT ChatTab::getType ( ) const
inline

Returns type of the being.

Definition at line 144 of file chattab.h.

References mType, and saveToLogFile().

Referenced by chatLog(), ChatWindow::closeTab(), Actions::getNick(), Actions::outString(), outStringNormal(), saveToLogFile(), ChatWindow::selectTabByType(), and PopupMenu::showChatPopup().

145  { return mType; }
ChatTabTypeT mType
Definition: chattab.h:210

◆ handleCommand()

virtual bool ChatTab::handleCommand ( const std::string &  type,
const std::string &  args 
)
inlinevirtual

Handle special commands. Allows a tab to handle commands it defines itself.

Returns
true if the command was handled false if the command was not handled

Reimplemented in ChannelTab, EmulateGuildTab, GuildTab, PartyTab, and WhisperTab.

Definition at line 127 of file chattab.h.

References handleCommands().

Referenced by ChatWindow::closeTab(), handleCommands(), and handleCommandStr().

129  { return false; }

◆ handleCommands()

bool ChatTab::handleCommands ( const std::string &  type,
const std::string &  args 
)
virtual

Handle special commands. Allows a tab to handle commands it defines itself.

Returns
true if the command was handled false if the command was not handled

Definition at line 461 of file chattab.cpp.

References handleCommand().

Referenced by handleCommand().

462 {
463  // need split to commands and call each
464 
465  return handleCommand(type, args);
466 }
virtual bool handleCommand(const std::string &type, const std::string &args)
Definition: chattab.h:127

◆ handleCommandStr()

void ChatTab::handleCommandStr ( const std::string &  msg)
protectedvirtual

Reimplemented in WhisperTab, and GmTab.

Definition at line 441 of file chattab.cpp.

References InputManager::executeChatCommand(), handleCommand(), inputManager, and Catch::trim().

Referenced by chatInput(), WhisperTab::handleCommandStr(), and setCurrent().

442 {
443  const size_t pos = msg.find(' ');
444  const std::string type(msg, 0, pos);
445  std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
446 
447  args = trim(args);
448  if (!handleCommand(type, args))
449  inputManager.executeChatCommand(type, args, this);
450 }
bool msg(InputEvent &event)
Definition: chat.cpp:38
virtual bool handleCommand(const std::string &type, const std::string &args)
Definition: chattab.h:127
std::string trim(std::string const &str)
InputManager inputManager
bool executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)

◆ handleHelp()

void ChatTab::handleHelp ( const std::string &  msg)
protectedvirtual

Definition at line 452 of file chattab.cpp.

References helpWindow, Widget::requestMoveToTop(), and HelpWindow::search().

Referenced by chatInput(), and setCurrent().

453 {
454  if (helpWindow != nullptr)
455  {
458  }
459 }
virtual void requestMoveToTop()
Definition: widget.cpp:212
bool msg(InputEvent &event)
Definition: chat.cpp:38
void search(const std::string &text)
Definition: helpwindow.cpp:185
HelpWindow * helpWindow
Definition: helpwindow.cpp:53

◆ handleInput()

void ChatTab::handleInput ( const std::string &  msg)
protectedvirtual

Reimplemented in WhisperTab, EmulateGuildTab, GuildTab, PartyTab, ChannelTab, GmTab, and TradeTab.

Definition at line 432 of file chattab.cpp.

References chatHandler, ChatWindow::doReplace(), mChannelName, and Net::ChatHandler::talk().

Referenced by chatInput(), and setCurrent().

433 {
434  if (chatHandler)
435  {
437  mChannelName);
438  }
439 }
virtual void talk(const std::string &text, const std::string &channel) const =0
bool msg(InputEvent &event)
Definition: chat.cpp:38
static std::string doReplace(const std::string &msg)
Net::ChatHandler * chatHandler
Definition: net.cpp:80
std::string mChannelName
Definition: chattab.h:208

◆ hasRows()

bool ChatTab::hasRows ( ) const
inline

Definition at line 152 of file chattab.h.

References BrowserBox::hasRows(), loadFromLogFile(), and mTextOutput.

Referenced by ChatWindow::keyPressed().

153  { return mTextOutput->hasRows(); }
bool hasRows() const
Definition: browserbox.h:126
BrowserBox * mTextOutput
Definition: chattab.h:206

◆ loadFromLogFile()

void ChatTab::loadFromLogFile ( const std::string &  name)

Definition at line 510 of file chattab.cpp.

References addRow(), chatLogger, and ChatLogger::loadLast().

Referenced by ChatWindow::addChannelTab(), ChatWindow::addWhisperTab(), BattleTab::BattleTab(), createGuiWindows(), Ea::PartyRecv::createTab(), GuildManager::createTab(), hasRows(), and EAthena::GuildRecv::processGuildPositionInfo().

511 {
512  if (chatLogger != nullptr)
513  {
514  std::list<std::string> list;
515  chatLogger->loadLast(name, list, 5);
516  std::list<std::string>::const_iterator i = list.begin();
517  while (i != list.end())
518  {
519  std::string line("##o" + *i);
520  addRow(line);
521  ++i;
522  }
523  }
524 }
void addRow(std::string &line)
Definition: chattab.cpp:488
void loadLast(std::string name, std::list< std::string > &list, const unsigned int n) const
Definition: chatlogger.cpp:197
ChatLogger * chatLogger
Definition: chatlogger.cpp:43

◆ playNewMessageSound()

void ChatTab::playNewMessageSound ( ) const
virtual

Reimplemented in EmulateGuildTab, GuildTab, and PartyTab.

Definition at line 542 of file chattab.cpp.

References SoundManager::playGuiSound(), SOUND_WHISPER, and soundManager.

Referenced by chatLog(), and setNoAway().

543 {
545 }
SoundManager soundManager
static const std::string SOUND_WHISPER
Definition: sound.h:30
void playGuiSound(const std::string &name)

◆ saveToLogFile()

void ChatTab::saveToLogFile ( const std::string &  msg) const

Definition at line 468 of file chattab.cpp.

References chatLogger, config, ChatTabType::DEBUG, Configuration::getBoolValue(), getType(), ChatTabType::INPUT, ChatLogger::log(), and mLogName.

Referenced by chatLog(), and getType().

469 {
470  if (chatLogger != nullptr)
471  {
472  if (getType() == ChatTabType::INPUT)
473  {
474  chatLogger->log(msg);
475  }
476  else if (getType() == ChatTabType::DEBUG)
477  {
478  if (config.getBoolValue("enableDebugLog"))
479  chatLogger->log("#Debug", msg);
480  }
481  else if (!mLogName.empty())
482  {
484  }
485  }
486 }
void log(std::string str)
Definition: chatlogger.cpp:91
Configuration config
bool msg(InputEvent &event)
Definition: chat.cpp:38
bool getBoolValue(const std::string &key) const
std::string mLogName
Definition: chattab.h:209
ChatTabTypeT getType() const
Definition: chattab.h:144
ChatLogger * chatLogger
Definition: chatlogger.cpp:43

◆ scroll()

void ChatTab::scroll ( const int  amount)

Scrolls the chat window

Parameters
amountdirection and amount to scroll. Negative numbers scroll up, positive numbers scroll down. The absolute amount indicates the amount of 1/8ths of chat window real estate that should be scrolled.

Definition at line 418 of file chattab.cpp.

References Widget::getHeight(), ScrollArea::getVerticalScrollAmount(), Rect::height, mScrollArea, mTextOutput, Widget::showPart(), and Rect::y.

Referenced by ChatWindow::scroll().

419 {
420  const int range = mScrollArea->getHeight() / 8 * amount;
421  Rect scr;
422  scr.y = mScrollArea->getVerticalScrollAmount() + range;
423  scr.height = abs(range);
424  mTextOutput->showPart(scr);
425 }
ScrollArea * mScrollArea
Definition: chattab.h:207
Definition: rect.h:72
int getVerticalScrollAmount() const
Definition: scrollarea.h:273
int y
Definition: rect.h:213
BrowserBox * mTextOutput
Definition: chattab.h:206
int height
Definition: rect.h:223
virtual void showPart(const Rect &rectangle)
Definition: widget.cpp:510
int getHeight() const
Definition: widget.h:239

◆ setAllowHighlight()

void ChatTab::setAllowHighlight ( const bool  n)
inline

◆ setCurrent()

void ChatTab::setCurrent ( )
inlineprotectedvirtual

Reimplemented from Tab.

Definition at line 189 of file chattab.h.

References handleCommandStr(), handleHelp(), handleInput(), and Tab::setFlash().

190  { setFlash(0); }
void setFlash(const int flash)
Definition: tab.h:174

◆ setNoAway()

void ChatTab::setNoAway ( const bool  n)
inline

Definition at line 172 of file chattab.h.

References addNewRow(), mNoAway, playNewMessageSound(), and showOnline().

Referenced by ChatWindow::loadState().

173  { mNoAway = n; }
bool mNoAway
Definition: chattab.h:213

◆ setRemoveNames()

void ChatTab::setRemoveNames ( const bool  n)
inline

Definition at line 166 of file chattab.h.

References mRemoveNames.

Referenced by ChatWindow::loadState().

167  { mRemoveNames = n; }
bool mRemoveNames
Definition: chattab.h:212

◆ showOnline()

void ChatTab::showOnline ( const std::string &  nick,
const Online  online 
)

Definition at line 547 of file chattab.cpp.

References _, ChatMsgType::BY_SERVER, chatLog(), IgnoreRecord_false, mShowOnline, Online_true, strprintf(), and TryRemoveColors_true.

Referenced by GuildManager::process(), EAthena::GuildRecv::processGuildMemberLogin(), TmwAthena::PartyRecv::processPartyInfo(), EAthena::PartyRecv::processPartyInfo(), EAthena::PartyRecv::processPartyMemberInfo(), TmwAthena::PartyRecv::processPartyMove(), and setNoAway().

549 {
550  if (!mShowOnline)
551  return;
552 
553  if (online == Online_true)
554  {
555  // TRANSLATORS: chat message
556  chatLog(strprintf(_("%s is now Online."), nick.c_str()),
560  }
561  else
562  {
563  // TRANSLATORS: chat message
564  chatLog(strprintf(_("%s is now Offline."), nick.c_str()),
568  }
569 }
#define _(s)
Definition: gettext.h:34
const bool TryRemoveColors_true
void chatLog(std::string line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
Definition: chattab.cpp:110
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
const bool IgnoreRecord_false
Definition: ignorerecord.h:29
bool mShowOnline
Definition: chattab.h:214
const bool Online_true
Definition: online.h:29

Friends And Related Function Documentation

◆ ChatWindow

friend class ChatWindow
friend

Definition at line 186 of file chattab.h.

◆ WhisperWindow

friend class WhisperWindow
friend

Definition at line 187 of file chattab.h.

Field Documentation

◆ mAllowHightlight

bool ChatTab::mAllowHightlight
protected

Definition at line 211 of file chattab.h.

Referenced by getAllowHighlight(), and setAllowHighlight().

◆ mChannelName

std::string ChatTab::mChannelName
protected

◆ mLogName

std::string ChatTab::mLogName
protected

Definition at line 209 of file chattab.h.

Referenced by saveToLogFile().

◆ mNoAway

bool ChatTab::mNoAway
protected

Definition at line 213 of file chattab.h.

Referenced by getNoAway(), and setNoAway().

◆ mRemoveNames

bool ChatTab::mRemoveNames
protected

Definition at line 212 of file chattab.h.

Referenced by getRemoveNames(), and setRemoveNames().

◆ mScrollArea

ScrollArea* ChatTab::mScrollArea
protected

◆ mShowOnline

bool ChatTab::mShowOnline
protected

◆ mTextOutput

BrowserBox* ChatTab::mTextOutput
protected

◆ mType

ChatTabTypeT ChatTab::mType
protected

Definition at line 210 of file chattab.h.

Referenced by getType().


The documentation for this class was generated from the following files: