1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2019 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
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/>.
32 #include "events_listener.h"
38 class CActionsManager
;
41 * The goal of CCombo is to gather together Inputs that will validate an Action.
42 * For now, CCombo is composed of keyboard inputs or mouse inputs
43 * (not Keyboard and mouse inputs in the same CCombo).
45 * \author Guillaume PUZIN
46 * \author Nevrax France
50 * \todo Check if there is memory leak.
51 * \todo Check comments.
60 // The CTRL - SHIFT - ALT state
61 NLMISC::TKeyButton KeyButtons
;
66 void init (NLMISC::TKey key
, NLMISC::TKeyButton keyButtons
);
68 /// Get the combo in human readable form
69 std::string
toString() const;
72 bool operator<(const CCombo
&other
) const
78 return KeyButtons
< other
.KeyButtons
;
84 * The Goal of CAction is to know the state of an Action.
86 * \author Guillaume PUZIN
87 * \author Nevrax France
90 * \todo Check comments.
96 // The name of an action
107 CName(const char *name
)
112 CName(const char *name
, const char *argu
)
120 bool operator<(const CName
&other
) const
122 if (Name
< other
.Name
)
124 if (Name
> other
.Name
)
126 return Argu
< other
.Argu
;
130 bool operator== (const CName
&other
) const
132 return (Name
== other
.Name
) && (Argu
== other
.Argu
);
136 // The icon of an action
141 // The background color
144 // The bitmaps (1 over 0)
145 std::string Bitmaps
[2];
147 // The text (6 letters, only A-Z 0-9)
154 // Execute the action
157 // True if the action has begun (key down..)
160 // Repetition for this action ?
163 // Do we have to run an AH on key up ?
166 // Do we have to run an AH on key down ?
169 // The name of the action
174 * The base action is a class used to generate actions
180 // Init default values
183 // The parameter descriptor of an action
190 Constant
, // The parameter is a list of const string
191 User
, // The parameter is a user string
192 UserName
, // The parameter is a user "name" string
195 // Init default values
198 // The parameter name (optional)
201 // The parameter localized name (optional)
202 std::string LocalizedName
;
205 std::string DefaultValue
;
207 // The parameter constant value is Type == Constant
214 // contexts in which this value is possible
215 std::string Contexts
;
217 // The localized value
218 std::string LocalizedValue
;
220 std::vector
<CValue
> Values
;
223 // The action parameter descritors
224 std::vector
<CParameter
> Parameters
;
226 // Repetition for this action ?
229 // Do we have to run an AH on key up ?
232 // Do we have to run an AH on key down ?
235 // Do we have to wait for an answer from the server before continuing execution in macros ?
238 // Is this action can be macroized?
241 // The name of the action handler used by the action
244 // The localized name
245 std::string LocalizedName
;
247 // Contexts in which this action exists
248 std::string Contexts
;
250 /// Get an action localized text
251 std::string
getActionLocalizedText (const CAction::CName
&name
) const;
253 // see if there's at least one set of parameters for which this action is usable in current context
254 bool isUsableInCurrentContext() const;
257 // CAction::CIcon Icon;
269 // The category localized name
270 std::string LocalizedName
;
272 // The set of base action for this category
273 std::vector
<CBaseAction
> BaseActions
;
275 // Is this whole category can be macroized?
285 // HashMapTraits for NLMISC::TKey
286 struct CTKeyHashMapTraits
288 enum { bucket_size
= 4, min_buckets
= 8, };
289 CTKeyHashMapTraits() { }
290 size_t operator() (NLMISC::TKey key
) const
294 bool operator() (NLMISC::TKey key1
, NLMISC::TKey key2
) const
301 * The aims of CActionsManager ...
303 * \author Guillaume PUZIN
304 * \author Nevrax France
307 * \todo DelCombo(...);
309 * \todo Check if there is memory leak.
310 * \todo Check comments.
312 class CActionsManager
316 /// Typedef to use the map easily.
317 typedef std::map
<CAction::CName
, CAction
> TActionsMap
;
318 typedef std::set
<CAction::CName
> TActionsForceDisplaySet
;
319 typedef std::map
<CAction::CName
, CCombo
> TActionComboMap
;
320 typedef std::map
<CCombo
, CAction::CName
> TComboActionMap
;
321 typedef CHashMultiMap
<NLMISC::TKey
, CAction::CName
, CTKeyHashMapTraits
> TKeyActionMap
;
324 class CCategoryLocator
331 typedef CHashMultiMap
<std::string
, CCategoryLocator
> TActionBaseActionMap
;
336 /// Add a new Action in the context.
337 bool addAction(const CAction::CName
&name
);
339 /// Return an action from its name
340 CAction
* getAction(const CAction::CName
&name
);
345 /// Enable / disable combos
346 void enable (bool enable
);
349 void removeCombo (const CCombo
&combo
);
351 // Remove all the combos
352 void removeAllCombos();
354 /// Add a combo in an Action.
355 bool addCombo(const CAction::CName
&name
, const CCombo
&combo
, bool createAction
= true);
357 /// Get the base action and category of an action
358 const CCategoryLocator
*getActionLocator (const CAction::CName
&name
) const;
360 /// Get the base action of an action
361 const CBaseAction
*getBaseAction (const CAction::CName
&name
) const;
363 // remove an action from the action manager
364 void removeBaseAction(const CAction::CName
&name
);
366 /// Get the category of an action
367 const CCategory
*getCategory (const CAction::CName
&name
) const;
369 /// Return if the Action is valide.
370 bool valide(const CAction::CName
&name
) const;
371 void validate(const CAction::CName
&name
);
372 void unvalidate(const CAction::CName
&name
);
374 // Return true if the action is present in current (global) context
375 bool isActionPresentInContext(const CAction::CName
&name
) const;
377 /// A key has been pushed. Return true if an action handler is associated with this key.
378 bool keyPushed (const NLMISC::CEventKeyDown
&keyDown
);
380 /// A key has been released
381 void keyReleased (const NLMISC::CEventKeyUp
&keyUp
);
383 /// Get the category array
384 const std::vector
<CCategory
> &getCategories () const;
386 /// Reserve space in the category array
387 void reserveCategories (uint space
);
390 void addCategory (const CCategory
&category
);
392 /// Remove a category
393 void removeCategory (const std::string
&catName
);
395 /// Get combo / action map
396 const TComboActionMap
&getComboActionMap () const;
398 /// Get action / combo map
399 const TActionComboMap
&getActionComboMap () const;
401 /// Release All keys, without running any AH
402 void releaseAllKeyNoRunning();
404 /// true if a combo is already associated to an action
405 bool isComboAssociated(const CCombo
&combo
) const {return _ComboAction
.find(combo
)!=_ComboAction
.end();}
407 /// true if an action is already associated to a combo
408 bool isActionAssociated(const CAction::CName
&name
) const {return _ActionCombo
.find(name
)!=_ActionCombo
.end();}
410 /// Force the action to be always displayed in the "Keys" interface, even if the key is unbound. default is false
411 void forceDisplayForAction(const CAction::CName
&name
, bool state
);
413 /// see forceDisplayForAction
414 bool isActionDisplayForced(const CAction::CName
&name
) const;
416 /// see forceDisplayForAction
417 const TActionsForceDisplaySet
&getActionsForceDisplaySet() const {return _ActionForceDisplay
;}
419 /// Get an action localized text
420 std::string
getActionLocalizedText (const CAction::CName
&name
) const;
426 /// Update key buttons
427 void updateKeyButton (NLMISC::TKeyButton
);
429 /// Map with all Actions in the context. the string = Action name.
430 TActionsMap _Actions
;
431 TActionsForceDisplaySet _ActionForceDisplay
;
432 TActionComboMap _ActionCombo
;
433 TComboActionMap _ComboAction
;
434 TKeyActionMap _KeyAction
;
435 TKeyActionMap _WatchedActions
;
436 TActionBaseActionMap _ActionCategory
;
437 std::vector
<CCategory
> _Categories
;
441 };// CActionsManager //
446 class CActionsContext
451 // Add an action manager.
452 bool addActionsManager (CActionsManager
*actionManager
, const std::string
&category
="");
454 // Get an action manager. Returns NULL if not found.
455 CActionsManager
*getActionsManager (const std::string
&category
="") const;
457 void setContext(const std::string
&context
) { _Context
= context
; }
458 bool matchContext(const std::string
&contexts
) const;
460 void removeAllCombos();
463 typedef std::map
<std::string
, CActionsManager
*> TActionsManagerMap
;
464 TActionsManagerMap _ActionsManagers
;
465 std::string _Context
;
468 extern CActionsContext ActionsContext
;
470 #endif // CL_ACTIONS_H
472 /* End of actions.h */