Mana
Loading...
Searching...
No Matches
chatwindow.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "eventlistener.h"
25
26#include "gui/widgets/window.h"
28
29#include <guichan/actionlistener.hpp>
30#include <guichan/keylistener.hpp>
31#include <guichan/widget.hpp>
32#include <guichan/widgetlistener.hpp>
33
34#include <string>
35#include <map>
36
37class ChatTab;
38class ChatInput;
39class Recorder;
40class TabbedArea;
41class ItemLinkHandler;
42
43#define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'.
44
45enum Own
46{
52 ACT_WHISPER, // getting whispered at
53 ACT_IS, // equivalent to "/me" on IRC
55};
56
58struct CHATLOG
59{
60 std::string nick;
61 std::string text;
63};
64
70class ChatWindow : public Window,
71 public gcn::ActionListener,
72 public EventListener
73{
74 public:
75 ChatWindow();
76
80 ~ChatWindow() override;
81
86 void resetToDefaultSize() override;
87
91 ChatTab *getFocused() const;
92
96 void clearTab();
97
101 void prevTab();
102
106 void nextTab();
107
111 void action(const gcn::ActionEvent &event) override;
112
119 bool requestChatFocus();
120
124 bool isInputFocused() const;
125
131 void chatInput(const std::string &msg);
132
134 void addInputText(const std::string &text);
135
137 void addItemText(const std::string &item);
138
140 void setVisible(bool visible) override;
141
142 void mousePressed(gcn::MouseEvent &event) override;
143 void mouseDragged(gcn::MouseEvent &event) override;
144
145 void event(Event::Channel channel, const Event &event) override;
146
154 void scroll(int amount);
155
161 void setRecordingFile(const std::string &msg);
162
163 void doPresent();
164
165 void whisper(const std::string &nick, const std::string &mes,
166 Own own = BY_OTHER);
167
168 ChatTab *addWhisperTab(const std::string &nick, bool switchTo = false);
169
170 protected:
171 friend class ChatTab;
172 friend class WhisperTab;
173 friend class ChatAutoComplete;
174
176 void removeTab(ChatTab *tab);
177
179 void addTab(ChatTab *tab);
180
181 void removeWhisper(const std::string &nick);
182
183 void removeAllWhispers();
184
188
191
194
195 private:
196 bool mTmpVisible = false;
197
200
202 std::map<const std::string, ChatTab *> mWhispers;
203};
204
205extern ChatWindow *chatWindow;
ChatWindow * chatWindow
Definition game.cpp:93
Own
Definition chatwindow.h:46
@ BY_GM
Definition chatwindow.h:47
@ BY_CHANNEL
Definition chatwindow.h:51
@ ACT_WHISPER
Definition chatwindow.h:52
@ ACT_IS
Definition chatwindow.h:53
@ BY_LOGGER
Definition chatwindow.h:54
@ BY_OTHER
Definition chatwindow.h:49
@ BY_PLAYER
Definition chatwindow.h:48
@ BY_SERVER
Definition chatwindow.h:50
The chat input hides when it loses focus.
A tab for the chat window.
Definition chattab.h:36
The chat window.
Definition chatwindow.h:73
void whisper(const std::string &nick, const std::string &mes, Own own=BY_OTHER)
void clearTab()
Clear the current tab.
void addItemText(const std::string &item)
Called to add item to chat.
ChatInput * mChatInput
Input box for typing chat messages.
Definition chatwindow.h:190
TabbedArea * mChatTabs
Tabbed area for holding each channel.
Definition chatwindow.h:199
bool isInputFocused() const
Checks whether ChatWindow is Focused or not.
void setVisible(bool visible) override
Override to reset mTmpVisible.
void setRecordingFile(const std::string &msg)
Sets the file being recorded to.
void removeWhisper(const std::string &nick)
~ChatWindow() override
Destructor: used to write back values to the config file.
void addInputText(const std::string &text)
Add the given text to the chat input.
bool mTmpVisible
Definition chatwindow.h:196
void mouseDragged(gcn::MouseEvent &event) override
bool requestChatFocus()
Request focus for typing chat message.
void scroll(int amount)
Scrolls the chat window.
ItemLinkHandler * mItemLinkHandler
Used for showing item popup on clicking links.
Definition chatwindow.h:186
void removeTab(ChatTab *tab)
Remove the given tab from the window.
AutoCompleteLister * mAutoComplete
Definition chatwindow.h:193
void nextTab()
Switch to the next tab in order.
TextHistory mHistory
Definition chatwindow.h:192
ChatTab * addWhisperTab(const std::string &nick, bool switchTo=false)
void action(const gcn::ActionEvent &event) override
Performs action.
void mousePressed(gcn::MouseEvent &event) override
void doPresent()
void chatInput(const std::string &msg)
Passes the text to the current tab as input.
void prevTab()
Switch to the previous tab in order.
void removeAllWhispers()
std::map< const std::string, ChatTab * > mWhispers
Manage whisper tabs.
Definition chatwindow.h:202
void resetToDefaultSize() override
Reset the chat window and recorder window attached to it to their default positions.
Recorder * mRecorder
Definition chatwindow.h:187
void addTab(ChatTab *tab)
Add the tab to the window.
ChatTab * getFocused() const
Gets the focused tab.
void event(Event::Channel channel, const Event &event) override
Definition event.h:42
Channel
Definition event.h:45
A tabbed area, the same as the guichan tabbed area in 0.8, but extended.
Definition tabbedarea.h:40
A tab for whispers from a single player.
Definition whispertab.h:32
A window.
Definition window.h:59
One item in the chat log.
Definition chatwindow.h:59
Own own
Definition chatwindow.h:62
std::string text
Definition chatwindow.h:61
std::string nick
Definition chatwindow.h:60