Orxonox  0.0.5 Codename: Arcturus
KeyBinderManager.h
Go to the documentation of this file.
1 /*
2  * ORXONOX - the hottest 3D action shooter ever to exist
3  * > www.orxonox.net <
4  *
5  *
6  * License notice:
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) 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, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  * Author:
23  * Reto Grieder
24  * Co-authors:
25  * ...
26  *
27  */
28 
29 #ifndef _KeyBinderManager_H__
30 #define _KeyBinderManager_H__
31 
32 #include "InputPrereqs.h"
33 
34 #include <map>
35 #include <string>
36 #include <memory>
37 
38 #include "util/Singleton.h"
40 
41 namespace orxonox //tolua_export
42 { //tolua_export
55  class _CoreExport KeyBinderManager //tolua_export
56  : public Singleton<KeyBinderManager>, public Configurable
57  { //tolua_export
58  friend class Singleton<KeyBinderManager>;
59  public:
62  void setConfigValues();
63 
66  KeyBinder* getCurrent() { return this->currentBinder_; } //tolua_export
68  InputHandler* getCurrentAsHandler();
70  void setCurrent(const std::string& filename);
71 
74  { return binders_[this->defaultFilename_]; }
76  InputHandler* getDefaultAsHandler();
79  { return defaultFilename_; }
81  void setToDefault()
82  { this->setCurrent(this->defaultFilename_); }
83 
85  KeyBinder* get(const std::string& name);
87  InputHandler* getAsHandler(const std::string& name);
88 
90  void load(const std::string& filename);
92  void unload(const std::string& filename);
93 
95  inline void keybind(const std::string& command) { this->keybindInternal(command, false); } //tolua_export
97  inline void tkeybind(const std::string& command)
98  { this->keybindInternal(command, true); }
99  void unbind(const std::string& binding); //tolua_export
100  void tunbind(const std::string& binding);
101  void registerKeybindCallback(LuaFunctor* function); //tolua_export
102 
103  private:
104  // non-copyable:
105  KeyBinderManager(const KeyBinderManager&) = delete;
106  KeyBinderManager& operator=(const KeyBinderManager&) = delete;
107 
108  void keybindInternal(const std::string& command, bool bTemporary);
109  void keybindKeyPressed(const std::string& keyName);
110  void defaultFilenameChanged();
111 
112  // KeyBinder management
114  std::map<std::string, KeyBinder*> binders_;
117 
118  // keybind command related
119  std::shared_ptr<LuaFunctor> callbackFunction_;
120  bool bBinding_;
121  bool bTemporary_;
123 
125  }; //tolua_export
126 } //tolua_export
127 
128 #endif /* _KeyBinderManager_H__ */
Base class for all input handlers like KeyBinder, InputBuffer, etc.
Definition: InputHandler.h:118
::std::string string
Definition: gtest-port.h:756
std::map< std::string, KeyBinder * > binders_
Currently selected KeyBinder (never nullptr!)
Definition: KeyBinderManager.h:114
This is the base class of all objects which may contain config values.
Definition: Configurable.h:47
void keybind(const std::string &command)
Bind &#39;command&#39; to any key pressed after this call (use with care!)
Definition: KeyBinderManager.h:95
KeyBinder * getCurrent()
Returns the currently selected KeyBinder.
Definition: KeyBinderManager.h:66
Declarations of all key/button/axis code enumeration and string literals and an input device enumerat...
Base for singleton classes.
Definition: Singleton.h:114
static KeyBinderManager & getInstance()
Definition: KeyBinderManager.h:64
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
void setToDefault()
Selects the default KeyBinder as current one.
Definition: KeyBinderManager.h:81
ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION_MULTI() command(const std::string &fragment)
Returns a list of commands and groups and also supports auto-completion of the arguments of these com...
Definition: ArgumentCompletionFunctions.cc:178
std::string defaultFilename_
Tells whether the default one is loaded.
Definition: KeyBinderManager.h:116
Maps mouse, keyboard and joy stick input to command strings and executes them.
Definition: KeyBinder.h:59
#define _CoreExport
Definition: CorePrereqs.h:61
callback class that executes lua code
Definition: LuaState.h:58
std::string command_
Stores tkeybind/keybind value.
Definition: KeyBinderManager.h:122
Declaration of Configurable, the base class of all objects which may contain config values...
static KeyBinderManager * singletonPtr_s
Stores the command received by (t)keybind.
Definition: KeyBinderManager.h:124
KeyBinder * currentBinder_
Definition: KeyBinderManager.h:113
std::shared_ptr< LuaFunctor > callbackFunction_
Name of the file with the default key bindings.
Definition: KeyBinderManager.h:119
KeyBinder * getDefault()
Returns the default KeyBinder.
Definition: KeyBinderManager.h:73
Definition of the Singleton template that is used as base class for classes that allow only one insta...
bool bBinding_
Function to be called when key was pressed after "keybind" command.
Definition: KeyBinderManager.h:120
bool bDefaultFileLoaded_
All loaded KeyBinders.
Definition: KeyBinderManager.h:115
static T & getInstance()
Returns a reference to the singleton instance.
Definition: Singleton.h:118
bool bTemporary_
Tells whether a key binding process is active.
Definition: KeyBinderManager.h:121
const std::string & getDefaultFilename()
Returns the filename of the default key bindings.
Definition: KeyBinderManager.h:78
Handles the KeyBinders and supplies them throughout the game.
Definition: KeyBinderManager.h:55
void tkeybind(const std::string &command)
Bind &#39;command&#39; to any key pressed after this call (use with care!), but temporarily (no file save) ...
Definition: KeyBinderManager.h:97