Fix css style order when using external css files
[ryzomcore.git] / ryzom / client / src / interface_v3 / chat_window.h
blob88104e4f9fd77b67e9648ec27b33117015e012bf
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
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 Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef CL_CHAT_WINDOW_H
24 #define CL_CHAT_WINDOW_H
26 #include "nel/misc/smart_ptr.h"
28 #include "game_share/chat_group.h"
31 namespace NLGUI
33 class CCtrlBase;
34 class CViewText;
35 class CGroupList;
36 class CGroupEditBox;
37 class CGroupContainer;
38 class CCtrlTabButton;
41 class CChatWindow;
43 /** Interface to react to a chat box entry
44 * Derivers should define the msgEntered member function to handle entry event.
46 struct IChatWindowListener
48 // the user entered a msg in the given chat box
49 virtual void msgEntered(const std::string &msg, CChatWindow *chatWindow) = 0;
53 /** description of a chat window
55 struct CChatWindowDesc
57 typedef std::vector<std::pair<std::string,std::string> > TTemplateParams;
59 std::string Title; // unique title for the window
60 std::string FatherContainer; // name of the father container. If empty, the chat box must be added manually in the hierarchy
61 std::string ChatTemplate; // Template for the chat interface, or "" to use the default one
62 TTemplateParams ChatTemplateParams; // optional template parameters
63 sint InsertPosition; // [optional] -1 if the chat box should be inserted at the end of the container list, or the index otherwise
64 bool ParentBlink; // [optional] when true, make the parent group blink
65 bool Savable; // should the position of the chat box be saved between session ? Default is false
66 bool Localize; // should we have to localize the window?
67 IChatWindowListener *Listener;
68 std::string Id;
69 std::string AHOnActive;
70 std::string AHOnActiveParams;
71 std::string AHOnDeactive;
72 std::string AHOnDeactiveParams;
73 std::string AHOnCloseButton;
74 std::string AHOnCloseButtonParams;
75 std::string HeaderColor;
76 // default ctor : build optional parameters with their default values
77 CChatWindowDesc();
80 /** This class can be used to easily manipulate a chat box without having to deal directly with the ui.
81 * Each chat box must have a unique identifier.
82 * For that reason, they should be created from a CChatWindowManager instance
83 * \author Nicolas Vizerie
84 * \author Nevrax France
85 * \date 2003
87 class CChatWindow : public NLMISC::CRefCount
89 public:
90 // a listener to know when a chat window is removed, or when a msg is displayed to it
91 struct IObserver
93 // called by a CChatWindow when it is deleted
94 virtual void chatWindowRemoved(CChatWindow * /* cw */) {}
95 // called by a CChatWindow when a msg has been displayed in it ('displayMessage' has been called)
96 //virtual void displayMessage(CChatWindow *cw, const std::string &msg, NLMISC::CRGBA col, uint numBlinks = 0) {}
98 public:
99 // display a message in this chat box with the given color
100 virtual void displayMessage(const std::string &msg, NLMISC::CRGBA col, CChatGroup::TGroupType gt, uint32 dynamicChatDbIndex, uint numBlinks = 0, bool *windowVisible = NULL);
101 virtual void displayTellMessage(const std::string &/* msg */, NLMISC::CRGBA /* col */, const std::string &/* sender */) {}
102 virtual void clearMessages(CChatGroup::TGroupType gt, uint32 dynamicChatDbIndex);
103 // Test if the window is visible
104 bool isVisible() const;
105 // set the keyboard focus to this chat window (if it has a edit box)
106 void setKeyboardFocus();
107 // Make the window blink
108 void enableBlink(uint numBlinks);
109 // set a command to be displayed and eventually executed in this chat window. std::string version for backward compatibility
110 void setCommand(const std::string &command, bool execute);
111 // set a string to be displayed in the edit box of this window (if it has one)
112 void setEntry(const std::string &entry);
113 // Set listener to react to a chat entry
114 void setListener(IChatWindowListener *listener) { _Listener = listener; }
115 IChatWindowListener *getListener() const { return _Listener; }
116 // Set the menu for the chat
117 void setMenu(const std::string &menuName);
118 // Set a new prompt for the chat window
119 void setPrompt(const std::string &prompt);
120 // Set the color for the chat window
121 void setPromptColor(NLMISC::CRGBA col);
122 /** Get the container associated with this chat window
123 * NB : you should not change the name of the window ! Use rename instead
125 NLGUI::CGroupContainer *getContainer() const { return _Chat; }
127 NLGUI::CGroupEditBox *getEditBox() const;
128 /** try to rename the chat window
129 * \return true if success
131 bool rename(const std::string &newName, bool newNameLocalize);
132 /** delete the container
133 * Don't do it in the dtor, because done automatically at the end of the app by the interface manager.
134 * Useful only if querried by the user
136 void deleteContainer();
137 // get the last chat window from which a command has been called
138 static CChatWindow *getChatWindowLaunchingCommand() { return _ChatWindowLaunchingCommand; }
139 // get the title of this chat window
140 std::string getTitle() const;
141 // observers
142 void addObserver(IObserver *obs);
143 void removeObserver(IObserver *obs);
144 bool isObserver(const IObserver *obs) const;
145 // AH adder
146 void setAHOnActive(const std::string &n);
147 void setAHOnActiveParams(const std::string &n);
148 void setAHOnDeactive(const std::string &n);
149 void setAHOnDeactiveParams(const std::string &n);
150 void setAHOnCloseButton(const std::string &n);
151 void setAHOnCloseButtonParams(const std::string &n);
152 void setHeaderColor(const std::string &n);
154 void displayLocalPlayerTell(const std::string &receiver, const std::string &msg, uint numBlinks = 0);
156 /// Encode a color tag '@{RGBA}' in the text. If append is true, append at end of text, otherwise, replace the text
157 static void encodeColorTag(const NLMISC::CRGBA &color, std::string &text, bool append=true);
159 ///////////////////////////////////////////////////////////////////////////////////////
160 protected:
161 // ctor
162 CChatWindow();
163 // dtor
164 virtual ~CChatWindow();
165 protected:
166 IChatWindowListener *_Listener;
167 NLMISC::CRefPtr<NLGUI::CGroupContainer> _Chat;
168 NLGUI::CGroupEditBox *_EB;
169 bool _ParentBlink;
170 static CChatWindow *_ChatWindowLaunchingCommand;
171 std::vector<IObserver *> _Observers;
172 protected:
173 friend class CChatWindowManager;
174 friend class CHandlerChatBoxEntry;
175 friend class CHandlerContactEntry; // TODO : remove this if CChatBox are used in people lists
176 /** Create a chat window
177 * The name and the id should be unique
178 * The id shouldn't contains ui:interface
180 bool create(const CChatWindowDesc &desc, const std::string &id);
183 // -----------------------------------------------------------------------------------
184 class CChatGroupWindow : public CChatWindow
186 public:
187 CChatGroupWindow() {}
188 // display a message in this chat box with the given color (callback from chat input filter)
189 virtual void displayMessage(const std::string &msg, NLMISC::CRGBA col, CChatGroup::TGroupType gt, uint32 dynamicChatDbIndex, uint numBlinks = 0, bool *windowVisible = NULL);
190 virtual void displayTellMessage(const std::string &msg, NLMISC::CRGBA col, const std::string &sender);
191 virtual void clearMessages(CChatGroup::TGroupType gt, uint32 dynamicChatDbIndex);
192 sint32 getTabIndex();
193 void setTabIndex(sint32 n);
195 // Free Teller
196 NLGUI::CGroupContainer *createFreeTeller(const std::string &winName, const std::string &winColor="");
197 void setActiveFreeTeller(const std::string &winName, bool bActive=true);
198 std::string getFreeTellerName(const std::string &containerID);
199 bool removeFreeTeller(const std::string &containerID); // Return true if free teller found
200 void removeAllFreeTellers();
201 void saveFreeTeller(NLMISC::IStream &f);
202 void loadFreeTeller(NLMISC::IStream &f);
203 // update headers of all free tellers
204 void updateAllFreeTellerHeaders();
207 protected:
208 friend class CChatWindowManager;
210 std::vector<NLGUI::CGroupContainer*> _FreeTellers;
212 void getAssociatedSubWindow(CChatGroup::TGroupType gt, uint32 dynamicChatDbIndex, NLGUI::CGroupList *&gl, NLGUI::CCtrlTabButton *&tab);
213 void updateFreeTellerHeader(NLGUI::CGroupContainer &ft);
215 private:
216 /** Get a valid string to use like ui id
217 * \param stringId initial unchecked string
218 * \return valid string
220 const std::string getValidUiStringId(const std::string &stringId);
224 /** Class that manage several chat windows with unique names
225 * \author Nicolas Vizerie
226 * \author Nevrax France
227 * \date 2003
229 class CChatWindowManager
231 public:
232 // dtor
233 ~CChatWindowManager();
234 /** Create a new chat window. Each chat window should have a unique name
235 * The window should be inserted in another container by the caller.
236 * \param name A unique title to affect to that window
237 * \param listener A listener to react to the event of the window
238 * \return A pointer on the window, or NULL, if creation failed or if name already exists.
240 CChatWindow *createChatWindow(const CChatWindowDesc &desc);
242 CChatWindow *createChatGroupWindow(const CChatWindowDesc &desc);
244 // Get a chat window by its title
245 CChatWindow *getChatWindow(const std::string &title);
246 /// Remove a chat window by its title
247 void removeChatWindow(const std::string &title);
248 // Remove a chat window by its pointer
249 void removeChatWindow(CChatWindow *cw);
250 /// from a ctrl of a chat box that triggered a menu, or an event, retrieve the associated chat box
251 CChatWindow *getChatWindowFromCaller(NLGUI::CCtrlBase *caller);
252 // Singleton pattern applied to the chat window manager
253 static CChatWindowManager &getInstance();
254 // try to rename a window
255 bool rename(const std::string &oldName, const std::string &newName, bool newNameLocalize);
256 // warning : this is slow
257 uint getNumChatWindow() const { return (uint)_ChatWindowMap.size(); }
258 // warning : this is slow : for debug only
259 CChatWindow *getChatWindowByIndex(uint index);
260 ///////////////////////////////////////////////////////////////////////////////////////
261 private:
262 typedef std::map<std::string, NLMISC::CRefPtr<CChatWindow> > TChatWindowMap;
263 private:
265 TChatWindowMap _ChatWindowMap;
266 uint _WindowID;
267 private:
268 // ctor
269 CChatWindowManager();
272 // shortcut to get instance of the chat window manager
273 inline CChatWindowManager &getChatWndMgr() { return CChatWindowManager::getInstance(); }
275 #endif