Fix classique titles display
[ryzomcore.git] / ryzom / client / src / client_chat_manager.h
blob2cdc44c2408269af81bbe82ef629ba58de965f9d
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 CLIENT_CHAT_MANAGER_H
24 #define CLIENT_CHAT_MANAGER_H
26 // misc
27 #include "nel/misc/types_nl.h"
29 // game share
30 //#include "game_share/chat_static_database.h"
31 #include "game_share/chat_group.h"
32 #include "game_share/dyn_chat.h"
35 // std
36 #include <map>
37 #include <string>
39 namespace NLMISC{
40 class CCDBNodeLeaf;
44 //#define OLD_STRING_SYSTEM
46 /**
47 * CDynamicStringInfos
48 * \author Stephane Coutelas
49 * \author Nevrax France
50 * \date 2002
53 #ifdef OLD_STRING_SYSTEM
55 struct CDynamicStringInfos
57 /// string
58 ucstring Str; // OLD
60 /// index in the infos buffer, same as the index in the client dynamic string known buffer
61 uint32 Index;
63 /// true if the string has a Huffman code
64 bool IsHuffman;
66 /// true if we received the association
67 bool Associated;
69 /// Constructor
70 CDynamicStringInfos() : Associated(false), Index(0xffffffff), IsHuffman(true), Str("???") { }
74 #endif
76 /**
77 * CChatDynamicDatabase
78 * \author Stephane Coutelas
79 * \author Nevrax France
80 * \date 2002
82 #ifdef OLD_STRING_SYSTEM
84 class CChatDynamicDatabase
86 public :
88 /// Add a string to dynamic base( used by client, add the string with its code )
89 /// \param index the index of the string
90 /// \param str the string
91 /// \param huffCode the Huffman code(may be empty)
92 /// \return the index of the string
93 uint32 add( uint32 index, ucstring& str, std::vector<bool>& huffCode ); // OLD
95 /// Get the string from its Huffman code
96 /// \param str will be filled with the string
97 /// \param bms contains the Huffman code
98 void decodeString( ucstring& str, NLMISC::CBitMemStream& bms ); // OLD
100 /// Get infos on the dynamic string
101 CDynamicStringInfos * getDynamicStringInfos( uint32 index );
103 /// Destructor
104 ~CChatDynamicDatabase();
106 private :
108 /// Provides a Huffman tree to get huffman code of a string
109 / CHuffman _Huffman;
111 /// Dynamic base
112 std::map< uint32, CDynamicStringInfos *> _Data;
114 /// Map to find index from the string (only for uncoded strings)
115 std::map< ucstring, uint32> _StringToIndex; // OLD
118 #endif
124 // ***************************************************************************
126 * CClientChatManager
127 * \author Stephane Coutelas
128 * \author Nevrax France
129 * \date 2002
131 class CClientChatManager
133 public:
134 class IChatDisplayer
136 public:
138 * \param mode in which channel should this message goes
139 * \param dynChatId is valid only if mode==dyn_chat. This the Id of channel (not the index in DB!)
141 virtual void displayChat(TDataSetIndex compressedSenderIndex, const std::string &ucstr, const std::string &rawMessage, CChatGroup::TGroupType mode, NLMISC::CEntityId dynChatId, std::string &senderName, uint bubbleTimer=0) =0;
143 * display a player tell message
145 virtual void displayTell(/*TDataSetIndex senderIndex, */const std::string &ucstr, const std::string &senderName) =0;
147 * Clear a channel.
148 * \param dynChatDbIndex is valid only if mode==dyn_chat. Contrary to displayChat, this is the Db Index (0..MaxDynChanPerPlayer)
150 virtual void clearChannel(CChatGroup::TGroupType mode, uint32 dynChatDbIndex) =0;
153 public :
154 CClientChatManager();
156 * Init the manager. Init the static database
158 void init( const std::string& staticDBFileName );
160 // InGame init/release. call init after init of database
161 void initInGame();
162 void releaseInGame();
165 * Return a reference on the static database
167 // CChatStaticDatabase& getStaticDB() { return _StaticDB; }
170 * Return a reference on the dynamic database
172 // #ifdef OLD_STRING_SYSTEM
173 // CChatDynamicDatabase& getDynamicDB() { return _DynamicDB; }
174 // #endif
177 * Transmit a chat message to the last target group (see setChatMode)
178 * \param str is the chat content (truncated to 255 char max)
179 * \param isChatTeam special case for Chat TEAM
181 void chat( const std::string& str, bool isChatTeam = false );
184 * Transmit a chat message to the receiver
185 * \param receiver is the name of the listening char (truncated to 255 char max)
186 * \param str is the chat content (truncated to 255 char max)
188 void tell( const std::string& receiver, const std::string& str );
190 /** Get the last name of the people with which a 'tell' has been done, then move that name at the start of the list
192 const std::string *cycleLastTell();
194 /** Set the max number of name in the tell list
196 void setTellListSize(uint numPeople);
200 * Add or remove a character from the ignore list
201 * \param filter is the filter id
203 void filter( uint8 filter );
206 * Change the chat mode
207 * \param mode is the chat mode( say/shout/group/clade )
208 * \param dynChannelId the dynamic channel id (if group==dyn_chat).
209 * Not the db index! Use getDynamicChannelIdFromDbIndex() if you got a dbIndex
211 void setChatMode(CChatGroup::TGroupType group, TChanID dynamicChannelId=NLMISC::CEntityId::Unknown);
213 /// Reset the chat mode to force the client to resend it. Used during far TP.
214 void resetChatMode();
217 * update chat mode button
219 void updateChatModeAndButton(uint mode, uint32 dynamicChannelDbIndex = 0);
222 * Get the string for a tell. display now if ready or delay in flushBuffer()
224 void processTellString(NLMISC::CBitMemStream& bms, IChatDisplayer &chatDisplayer);
227 * Get the string for a far tell. display now if ready or delay in flushBuffer()
229 void processFarTellString(NLMISC::CBitMemStream& bms, IChatDisplayer &chatDisplayer);
232 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
234 void processChatString( NLMISC::CBitMemStream& bms, IChatDisplayer &chatDisplayer);
237 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
238 * Difference with processTellString() is that processTellString2() receive a DynamicString for the message
240 void processTellString2(NLMISC::CBitMemStream& bms, IChatDisplayer &chatDisplayer);
243 * Extract and decode the chat string from the stream. display now if ready or delay in flushBuffer()
244 * Difference with processChatString() is that processChatString2() receive a DynamicString for the message
246 void processChatString2(NLMISC::CBitMemStream& bms, IChatDisplayer &chatDisplayer);
249 * Extract and decode the chat string from the stream.
250 * the stream here is only a iunt32 for the id of the dynamic string
251 * \param type where do you want this string to go (dyn_chat is not allowed)
253 void processChatStringWithNoSender( NLMISC::CBitMemStream& bms, CChatGroup::TGroupType type, IChatDisplayer &chatDisplayer);
256 * Process any waiting string
258 void flushBuffer(IChatDisplayer &chatDisplayer);
261 * Extract and decode the chat string from a vector a uint64
262 * \param args vector of argument
263 * \param str string with parameter values at end
264 * \param result decoded string
265 * \return true if the string is finalize, false if some param are missing from network
267 bool getString( std::string &result, std::vector<uint64>& args, const std::string& strbase );
269 // build a sentence to be displayed in the chat (e.g add "you say", "you shout", "[user name] says" or "[user name] shout")
270 static void buildChatSentence(TDataSetIndex compressedSenderIndex, const std::string &sender, const std::string &msg, CChatGroup::TGroupType type, std::string &result);
271 // build a sentence to be displayed in the tell
272 static void buildTellSentence(const std::string &sender, const std::string &msg, std::string &result);
275 /// \name Dynamic Chat channel mgt
276 // @{
277 // Use info from DB SERVER:DYN_CHAT. return 0 if fails
278 TChanID getDynamicChannelIdFromDbIndex(uint32 dbIndex);
279 // Use info from DB SERVER:DYN_CHAT. return -1 if fails
280 sint32 getDynamicChannelDbIndexFromId(TChanID channelId);
281 // return true if channel exist (getDynamicChannelDbIndexFromId>=0 && <MaxDynChan)
282 bool isDynamicChannelExist(TChanID channelId);
283 // get the name id from the db index
284 uint32 getDynamicChannelNameFromDbIndex(uint32 dbIndex);
285 // @}
288 private :
290 uint8 _ChatMode;
292 /// static database
293 // CChatStaticDatabase _StaticDB;
295 /// dynamic database
296 // #ifdef OLD_STRING_SYSTEM
297 // CChatDynamicDatabase _DynamicDB;
298 // #endif
300 // List of messages that wait for String to complete.
301 struct CChatMsgNode
303 TDataSetIndex CompressedIndex;
304 uint32 SenderNameId;
305 uint8 ChatMode;
306 NLMISC::CEntityId DynChatChanID;
307 // For Chat and Tell messages
308 ucstring Content; // FIXME: UTF-8 (serial)
309 // For Chat2 and Tell2 messages
310 uint32 PhraseId;
311 // Use PhraseId or Content?
312 bool UsePhraseId;
313 // displayTell() or displayChat()
314 bool DisplayAsTell;
316 CChatMsgNode(const CChatMsg &chatMsg, bool displayAsTell)
318 CompressedIndex= chatMsg.CompressedIndex;
319 SenderNameId= chatMsg.SenderNameId;
320 ChatMode= chatMsg.ChatMode;
321 DynChatChanID= chatMsg.DynChatChanID;
322 Content= chatMsg.Content;
323 PhraseId= 0;
324 UsePhraseId= false;
325 DisplayAsTell= displayAsTell;
328 CChatMsgNode(const CChatMsg2 &chatMsg, bool displayAsTell)
330 CompressedIndex= chatMsg.CompressedIndex;
331 SenderNameId= chatMsg.SenderNameId;
332 ChatMode= chatMsg.ChatMode;
333 DynChatChanID= NLMISC::CEntityId::Unknown;
334 PhraseId= chatMsg.PhraseId;
335 UsePhraseId= true;
336 DisplayAsTell= displayAsTell;
339 std::list<CChatMsgNode> _ChatBuffer;
341 // peoples
342 std::list<std::string> _TellPeople; // the last people on which tells ha been done
343 uint _NumTellPeople;
344 uint _MaxNumTellPeople;
346 /// \name Dynamic Chat channel mgt
347 // @{
348 TChanID _ChatDynamicChannelId;
349 NLMISC::CCDBNodeLeaf *_DynamicChannelNameLeaf[CChatGroup::MaxDynChanPerPlayer];
350 NLMISC::CCDBNodeLeaf *_DynamicChannelIdLeaf[CChatGroup::MaxDynChanPerPlayer];
351 // Id cached. If different from precedent, then the channel must be flushed
352 enum {DynamicChannelEmptyId=-1};
353 uint32 _DynamicChannelIdCache[CChatGroup::MaxDynChanPerPlayer];
354 void updateDynamicChatChannels(IChatDisplayer &chatDisplayer);
355 // @}
357 private :
360 * Extract and decode the chat string from the stream
361 * \param bms the bit mem stream
362 * \param str string with parameter values at end (str will change after)
363 * \return decoded string (str)
365 std::string getString( NLMISC::CBitMemStream& bms, std::string& str );
369 /** This class enable you to store a static string + arg and evaluate it every frame.
370 All args could perhaps not be translated because all dynamic string are not received right now.
371 So you can call getString() every time to
373 #ifdef OLD_STRING_SYSTEM
374 class CNetworkString
376 ucstring StaticString; // OLD
377 public:
378 std::vector<uint64> Args;
380 bool getString (ucstring &result, CClientChatManager *mng); // OLD
382 void setString (const ucstring &staticStringId, CClientChatManager *mng); // OLD
384 #endif
388 #endif // CLIENT_CHAT_MANAGER_H
390 /* End of client_chat_manager.h */