Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / client / src / interfaces_manager / chat_control.h
blobc346ffec9fe40c8ab7bd38ab759cb03cb1beec50
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef NL_CHAT_CONTROL_H
20 #define NL_CHAT_CONTROL_H
22 // Misc
23 #include "nel/misc/types_nl.h"
24 #include "nel/misc/rgba.h"
25 #include "nel/misc/ucstring.h"
26 // Client
27 #include "multi_list.h"
28 // Game Share
29 #include "game_share/ryzom_entity_id.h"
30 // Std
31 #include <map>
34 ///////////
35 // Using //
36 ///////////
37 using NLMISC::CRGBA;
38 using std::map;
41 /**
42 * class for the basic chat control interface (double list, mute/unmute of players, different colors can be assigned for each player)
43 * text can be saved in .txt format. The list is sensible to move-over, left click and right click
44 * \author David Fleury
45 * \author Nevrax France
46 * \date 2001
48 class CChatControl : public CMultiList
50 public:
51 /// Default Constructor
52 CChatControl(uint id);
54 /// Constructor
55 CChatControl(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, uint leftFunc, uint rightFunc, const CPen &pen);
56 CChatControl(uint id, float x, float y, float x_pixel, float y_pixel, float w, float h, float w_pixel, float h_pixel, uint leftFunc, uint rightFunc, uint32 fontSize, CRGBA color, bool shadow);
60 private:
61 /**
62 * add a line of text (private because this function, herited from CMultiList should be avoided for chat box,
63 * use add( const NLMISC::CEntityId sid, const ucstring &name, const ucstring &text) or add(const ucstring &text) for player msg and system msg
65 virtual void add(const std::list<ucstring> &str);
67 public:
69 /**
70 * add text from a player message to the chat box
71 * \param NLMISC::CEntityId& sid of the player who sent the msg
72 * \param ucstring& name of the player who sent the msg
73 * \param ucstring& the message to display
75 void add( const NLMISC::CEntityId &sid, const ucstring &name, const ucstring &text);
77 /**
78 * display text from a system message (not a player message, for player use the other public add method)
79 * \param ucstring& the message to display
81 void add( const ucstring &text);
83 /// Display the Bitmap.
84 virtual void display();
86 /**
87 * clear the control, erasing all stored sentences
89 void clear();
92 /// Manage the left click of the mouse for the list
93 virtual void click(float x, float y, bool &taken);
95 /// Manage the right click of the mouse for the list
96 virtual void clickRight(float x, float y, bool &taken);
98 /// called when the mouse move, indicate new mouse coordinates
99 virtual void mouseMove( float x, float y);
102 * unmute all the players
104 inline void unmuteAll() { _MutedPlayers.clear(); }
107 * set the color for system messages
108 * \param the new color
110 void setSysColor(CRGBA &color)
112 _SysTextColor = color; // map the command dummy NLMISC::CEntityId with the display color
113 _PlayersColor.insert( std::make_pair( _CommandSid, &_SysTextColor ) );
117 * set the muted color
118 * \param the new color
120 void setMutedColor(CRGBA &color) { _MutedColor = color; }
123 * set the color for highlighted messages
124 * \param the new color
126 void setHighlightColor(CRGBA &color) { _HighlightColor = color; }
129 * set the color for highlighted messages from muted players
130 * \param the new color
132 void setMutedHighlightColor(CRGBA &color) { _MutedHighlightColor = color; }
136 * get a pointer to the name of the currently selected player, or NULL
137 * \return ucstring* pointer to the player name (or NULL if there is no player selected)
139 ucstring *CChatControl::getSelectedPlayerName() const { return _SelectedPlayer; }
142 * get adress of the NLMISC::CEntityId of the currently selected player, or NULL if no player selected
143 * \return NLMISC::CEntityId* pointer to the player NLMISC::CEntityId (or NULL)
145 NLMISC::CEntityId *CChatControl::getSelectedPlayerSid() const { return _SelectedPlayerSid; }
148 * mute the specified player
149 * \param ucstring& name of the player to mute
151 void mutePlayer(const NLMISC::CEntityId &sid) { _MutedPlayers.insert(sid); }
154 * unmute the specified player
155 * \param ucstring& name of the player to unmute
157 void unmutePlayer(const NLMISC::CEntityId &sid) { _MutedPlayers.erase(sid); }
160 * return true if the specified player is muted
161 * \param ucstring& name of the player
162 * \return bool true if the player is muted
164 bool isMuted(const NLMISC::CEntityId &sid) const { return ( _MutedPlayers.find(sid) != _MutedPlayers.end() ); }
167 * get a color not allready used for display
168 * \return CRBGA a color different from the ones allready used
170 CRGBA getNewColor() const;
172 /// scroll verticaly by 'scroll' units in either direction
173 void scrollV(sint32 scroll);
175 private:
176 /// Initialize the control (1 function called for all constructors -> easier).
177 inline void init(uint leftFunc, uint rightFunc);
180 * search into _NamesYPos list for the specified y coordinate
181 * \param the searched y coordinate
182 * \param NLMISC::CEntityId*& the variable that will receive the adress of the NLMISC::CEntityId of the player (or NULL if not found)
183 * \param ucstring*& the variable that will receive the pointer to the name of the player (or NULL if not found)
184 * \return bool true if a player was found, false otherwise
186 bool searchPlayerAtPos(float y, NLMISC::CEntityId *&sid, ucstring *&name) const;
188 // attributes
189 private:
190 /// the set of muted player names
191 typedef std::set<NLMISC::CEntityId> TSidSet;
192 TSidSet _MutedPlayers;
194 /// the set of NLMISC::CEntityId (match the list of ucstring associated to player names and messages)
195 typedef std::list<NLMISC::CEntityId> TSidList;
196 TSidList _PlayersSid;
198 /// the set of colors already used for display
199 typedef std::set<CRGBA> TSetColors;
200 TSetColors _UsedColors;
202 /// map NLMISC::CEntityId with the associated display color for that player
203 typedef map<const NLMISC::CEntityId, const CRGBA *> TMapSidToColor;
204 TMapSidToColor _PlayersColor;
207 * list Y coordinates of displayed player name, used when a user left click on the control to determine if he clicked on a player name,
208 * and which one(to mute that player)
209 * NB : the second type (ucstring*) is a pointer to the player name in _ItemsList
211 typedef std::list< std::pair< std::pair<float,float>, std::pair<const ucstring*, const NLMISC::CEntityId*> > > TPairPFloatPStrSid;
212 TPairPFloatPStrSid _NamesYPos;
214 /// mouse current position
215 mutable float _MouseX;
216 mutable float _MouseY;
218 /// heigth of the last computed string, used to determine if the mouse if over a line or not
219 float _LastStringHeight;
221 /// the text displayed as 'player name' for system messages
222 ucstring _SystemDisplayText;
224 /// text color for system messages
225 CRGBA _SysTextColor;
226 /// text color for muted players messages (the messages received before the player was muted)
227 CRGBA _MutedColor;
228 /// text highlight color
229 CRGBA _HighlightColor;
230 /// text highlight color for muted players
231 CRGBA _MutedHighlightColor;
233 /// the currently selected character name (either by left click or right click) (pointer to the player name in _ItemsList)
234 ucstring* _SelectedPlayer;
236 /// the currently selected character NLMISC::CEntityId (either by left click or right click)
237 NLMISC::CEntityId* _SelectedPlayerSid;
239 /// number of the function to run when the user left click on a character name
240 uint _LeftClickFunction;
242 /// number of the function to run when user right click on a player name
243 uint _RightClickFunction;
246 * the ending position in the list of NLMISC::CEntityId for display, by default it's the last item in the list (the newest one)
247 * if auto scroll mode is 'on' (_AutoScroll == true), this iterator is allways equal to the last item in the list
248 * this iterator is used to keep the NLMISC::CEntityId List and the ucstring list coordinated
250 TSidList::reverse_iterator _EndingSidIterator;
253 /// Dummy NLMISC::CEntityId used for system messages
254 NLMISC::CEntityId _CommandSid;
258 #endif // NL_CHAT_CONTROL_H
260 /* End of chat_control.h */