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 ClanTab 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 62 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 67 of file chattab.cpp.

71  :
72  Tab(widget),
74  "browserbox.xml")),
75  mScrollArea(new ScrollArea(this,
76  mTextOutput, Opaque_false, std::string())),
77  mChannelName(channel),
78  mLogName(logName),
79  mType(type),
80  mAllowHightlight(true),
81  mRemoveNames(false),
82  mNoAway(false),
83  mShowOnline(false)
84 {
85  setCaption(name);
86 
88  mTextOutput->setMaxRow(config.getIntValue("ChatLogLength"));
89  if (chatWindow != nullptr)
92 
96 
97  if (chatWindow != nullptr)
98  chatWindow->addTab(this);
99  mTextOutput->updateSize(true);
100 }
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
void setAlwaysUpdate(const bool n)
Definition: browserbox.h:130
void setMaxRow(unsigned max)
Definition: browserbox.h:81
void updateSize(const bool always)
Definition: browserbox.cpp:863
void setLinkHandler(LinkHandler *linkHandler)
Definition: browserbox.cpp:166
void setOpaque(Opaque opaque)
Definition: browserbox.h:75
bool mShowOnline
Definition: chattab.h:215
std::string mLogName
Definition: chattab.h:210
bool mRemoveNames
Definition: chattab.h:213
ChatTabTypeT mType
Definition: chattab.h:211
ScrollArea * mScrollArea
Definition: chattab.h:208
bool mAllowHightlight
Definition: chattab.h:212
bool mNoAway
Definition: chattab.h:214
std::string mChannelName
Definition: chattab.h:209
BrowserBox * mTextOutput
Definition: chattab.h:207
void addTab(ChatTab *const tab)
Definition: chatwindow.cpp:589
ItemLinkHandler * mItemLinkHandler
Definition: chatwindow.h:341
int getIntValue(const std::string &key) const
void setScrollPolicy(const ScrollPolicy hPolicy, const ScrollPolicy vPolicy)
void setScrollAmount(const int hScroll, const int vScroll)
Tab(const Widget2 *const widget)
Definition: tab.cpp:103
void setCaption(const std::string &caption)
Definition: tab.cpp:458
Configuration config
const bool Opaque_false
Definition: opaque.h:30
const bool Opaque_true
Definition: opaque.h:30

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().

◆ ~ChatTab()

ChatTab::~ChatTab ( )

Definition at line 102 of file chattab.cpp.

103 {
104  if (chatWindow != nullptr)
105  chatWindow->removeTab(this);
106 
109 }
void removeTab(ChatTab *const tab)
Definition: chatwindow.cpp:584
#define delete2(var)
Definition: delete2.h:25

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

Member Function Documentation

◆ addNewRow()

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

Definition at line 526 of file chattab.cpp.

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

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

Referenced by ChatWindow::displayAwayLog().

◆ addRow()

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

Definition at line 488 of file chattab.cpp.

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 }
static const unsigned int MAX_WORD_SIZE
Definition: chattab.cpp:65
void addRow(const std::string &row, const bool atTop)
Definition: browserbox.cpp:171

References BrowserBox::addRow(), MAX_WORD_SIZE, and mTextOutput.

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

◆ 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 382 of file chattab.cpp.

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

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

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

◆ chatLog() [1/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 367 of file chattab.cpp.

368 {
369  if (localPlayer == nullptr)
370  return;
371 
372  const ChatMsgTypeT byWho = (nick == localPlayer->getName()
374  if (byWho == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors"))
375  msg = removeColors(msg);
376  chatLog(std::string(nick).append(" : ").append(msg),
377  byWho,
380 }
ChatMsgType ::T ChatMsgTypeT
Definition: chatmsgtype.h:41
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
bool getBoolValue(const std::string &key) const
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
LocalPlayer * localPlayer
std::string removeColors(std::string msg)
const bool TryRemoveColors_false

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

◆ chatLog() [2/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 111 of file chattab.cpp.

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

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, debugChatTab, 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, localChatTab, 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, ServerType::TMWATHENA, Catch::trim(), TryRemoveColors_true, KeyboardFocus::Unfocused, and ChatWindow::unHideWindow().

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

◆ clearText()

void ChatTab::clearText ( )

Clears the text from the tab

Definition at line 428 of file chattab.cpp.

429 {
431 }
void clearRows()
Definition: browserbox.cpp:359

References BrowserBox::clearRows(), and mTextOutput.

Referenced by ChatWindow::clearTab().

◆ getAllowHighlight()

bool ChatTab::getAllowHighlight ( ) const
inline

Definition at line 158 of file chattab.h.

159  { return mAllowHightlight; }

References mAllowHightlight.

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

◆ getAutoCompleteCommands()

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

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

Definition at line 202 of file chattab.h.

203  {}

Referenced by ChatWindow::autoComplete().

◆ getAutoCompleteList()

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

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

Definition at line 199 of file chattab.h.

200  {}

Referenced by ChatWindow::autoComplete().

◆ getChannelName()

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

◆ getNoAway()

bool ChatTab::getNoAway ( ) const
inline

Definition at line 170 of file chattab.h.

171  { return mNoAway; }

References mNoAway.

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

◆ getRemoveNames()

bool ChatTab::getRemoveNames ( ) const
inline

Definition at line 164 of file chattab.h.

165  { return mRemoveNames; }

References mRemoveNames.

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

◆ getRows()

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

Definition at line 150 of file chattab.h.

151  { return mTextOutput->getRows(); }
TextRows & getRows()
Definition: browserbox.h:124

References BrowserBox::getRows(), and mTextOutput.

Referenced by ChatWindow::keyPressed().

◆ getType()

ChatTabTypeT ChatTab::getType ( ) const
inline

Returns type of the being.

Definition at line 145 of file chattab.h.

146  { return mType; }

References mType.

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

◆ 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 WhisperTab, PartyTab, GuildTab, EmulateGuildTab, and ChannelTab.

Definition at line 128 of file chattab.h.

130  { return false; }

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

◆ 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.

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:128

References handleCommand().

◆ handleCommandStr()

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

Reimplemented in WhisperTab, and GmTab.

Definition at line 441 of file chattab.cpp.

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 executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
InputManager inputManager

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

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

◆ handleHelp()

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

Definition at line 452 of file chattab.cpp.

453 {
454  if (helpWindow != nullptr)
455  {
458  }
459 }
void search(const std::string &text)
Definition: helpwindow.cpp:187
virtual void requestMoveToTop()
Definition: widget.cpp:213
HelpWindow * helpWindow
Definition: helpwindow.cpp:54

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

Referenced by chatInput().

◆ handleInput()

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

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

Definition at line 433 of file chattab.cpp.

434 {
435  if (chatHandler)
436  {
438  }
439 }
Net::ChatHandler * chatHandler
Definition: net.cpp:86
static std::string doReplace(const std::string &msg)
virtual void talk(const std::string &text) const =0

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

Referenced by chatInput().

◆ hasRows()

bool ChatTab::hasRows ( ) const
inline

Definition at line 153 of file chattab.h.

154  { return mTextOutput->hasRows(); }
bool hasRows() const
Definition: browserbox.h:127

References BrowserBox::hasRows(), and mTextOutput.

Referenced by ChatWindow::keyPressed().

◆ loadFromLogFile()

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

Definition at line 510 of file chattab.cpp.

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 }
ChatLogger * chatLogger
Definition: chatlogger.cpp:43
void loadLast(std::string name, std::list< std::string > &list, const unsigned int n) const
Definition: chatlogger.cpp:197

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

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

◆ playNewMessageSound()

void ChatTab::playNewMessageSound ( ) const
virtual

Reimplemented in PartyTab, GuildTab, EmulateGuildTab, and ClanTab.

Definition at line 542 of file chattab.cpp.

543 {
545 }
static const std::string SOUND_WHISPER
Definition: sound.h:31

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

Referenced by chatLog().

◆ saveToLogFile()

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

Definition at line 468 of file chattab.cpp.

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

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

Referenced by chatLog().

◆ 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 419 of file chattab.cpp.

420 {
421  const int range = mScrollArea->getHeight() / 8 * amount;
422  Rect scr;
423  scr.y = mScrollArea->getVerticalScrollAmount() + range;
424  scr.height = abs(range);
425  mTextOutput->showPart(scr);
426 }
Definition: rect.h:74
int y
Definition: rect.h:214
int height
Definition: rect.h:224
virtual void showPart(const Rect &rectangle)
Definition: widget.cpp:511
int getHeight() const
Definition: widget.h:240

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

Referenced by ChatWindow::scroll().

◆ setAllowHighlight()

void ChatTab::setAllowHighlight ( const bool  n)
inline

◆ setCurrent()

void ChatTab::setCurrent ( )
inlineprotectedvirtual

Reimplemented from Tab.

Definition at line 190 of file chattab.h.

191  { setFlash(0); }

References Tab::setFlash().

◆ setNoAway()

void ChatTab::setNoAway ( const bool  n)
inline

Definition at line 173 of file chattab.h.

174  { mNoAway = n; }

References mNoAway.

Referenced by ChatWindow::loadState().

◆ setRemoveNames()

void ChatTab::setRemoveNames ( const bool  n)
inline

Definition at line 167 of file chattab.h.

168  { mRemoveNames = n; }

References mRemoveNames.

Referenced by ChatWindow::loadState().

◆ showOnline()

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

Definition at line 547 of file chattab.cpp.

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 }
const bool Online_true
Definition: online.h:30

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

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

Friends And Related Function Documentation

◆ ChatWindow

friend class ChatWindow
friend

Definition at line 187 of file chattab.h.

◆ WhisperWindow

friend class WhisperWindow
friend

Definition at line 188 of file chattab.h.

Field Documentation

◆ mAllowHightlight

bool ChatTab::mAllowHightlight
protected

Definition at line 212 of file chattab.h.

Referenced by getAllowHighlight(), and setAllowHighlight().

◆ mChannelName

std::string ChatTab::mChannelName
protected

◆ mLogName

std::string ChatTab::mLogName
protected

Definition at line 210 of file chattab.h.

Referenced by saveToLogFile().

◆ mNoAway

bool ChatTab::mNoAway
protected

Definition at line 214 of file chattab.h.

Referenced by getNoAway(), and setNoAway().

◆ mRemoveNames

bool ChatTab::mRemoveNames
protected

Definition at line 213 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 211 of file chattab.h.

Referenced by getType().


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