Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questlog/src/libraries/core/input/KeyBinderManager.h @ 10031

Last change on this file since 10031 was 8729, checked in by rgrieder, 13 years ago

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
  • Property svn:eol-style set to native
File size: 5.4 KB
Line 
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
37#include "util/Singleton.h"
38#include "core/OrxonoxClass.h"
39
40namespace orxonox //tolua_export
41{ //tolua_export
42    /**
43    @brief
44        Handles the KeyBinders and supplies them throughout the game.
45
46        This interface merely serves to provide a static "keybind" command that always
47        maps to the currently active KeyBinder. You can set that with setCurrent().
48        There is also a default one, retrieved with getDefault(). The idea is that
49        mostly the default KeyBinder is active except for special situations (mini-game for inst).
50    @remarks
51        You are not forced to use the KeyBinder imposed by getCurrent(). But be aware that "keybind"
52        will not work as expected!
53    */
54    class _CoreExport KeyBinderManager //tolua_export
55        : public Singleton<KeyBinderManager>, public OrxonoxClass
56    { //tolua_export
57        friend class Singleton<KeyBinderManager>;
58    public:
59        KeyBinderManager();
60        ~KeyBinderManager();
61        void setConfigValues();
62
63        static KeyBinderManager& getInstance() { return Singleton<KeyBinderManager>::getInstance(); } //tolua_export
64        //! Returns the currently selected KeyBinder
65        KeyBinder* getCurrent() { return this->currentBinder_; } //tolua_export
66        //! Like getCurrent(), but returns it as InputHandler* (so you don't have to include KeyBinder.h)
67        InputHandler* getCurrentAsHandler();
68        //! Selects the current KeyBinder and creates it if not yet loaded.
69        void setCurrent(const std::string& filename);
70
71        //! Returns the default KeyBinder
72        KeyBinder* getDefault()
73            { return binders_[this->defaultFilename_]; }
74        //! Returns the default KeyBinder as InputHandler* (so you don't have to include KeyBinder.h)
75        InputHandler* getDefaultAsHandler();
76        //! Returns the filename of the default key bindings
77        const std::string& getDefaultFilename()
78            { return defaultFilename_; }
79        //! Selects the default KeyBinder as current one
80        void setToDefault()
81            { this->setCurrent(this->defaultFilename_); }
82
83        //! Returns a pointer to a KeyBinder (creates it if not yet loaded)
84        KeyBinder* get(const std::string& name);
85        //! Like get() but return value is of type InputHandler* (so you don't have to include KeyBinder.h)
86        InputHandler* getAsHandler(const std::string& name);
87
88        //! Loads a KeyBinder by creating it (no different from get() except for the return value)
89        void load(const std::string& filename);
90        //! Destroys a KeyBinder completely (does nothing if not yet loaded)
91        void unload(const std::string& filename);
92
93        //! Bind 'command' to any key pressed after this call (use with care!)
94        inline void keybind(const std::string& command) { this->keybindInternal(command, false); } //tolua_export
95        //! Bind 'command' to any key pressed after this call (use with care!), but temporarily (no file save)
96        inline void tkeybind(const std::string& command)
97            { this->keybindInternal(command, true); }
98        void unbind(const std::string& binding); //tolua_export
99        void tunbind(const std::string& binding);
100        void registerKeybindCallback(LuaFunctor* function); //tolua_export
101
102    private:
103        KeyBinderManager(const KeyBinderManager&);
104        void keybindInternal(const std::string& command, bool bTemporary);
105        void keybindKeyPressed(const std::string& keyName);
106        void defaultFilenameChanged();
107
108        // KeyBinder management
109        KeyBinder* currentBinder_;                   //! Currently selected KeyBinder (never NULL!)
110        std::map<std::string, KeyBinder*> binders_;  //! All loaded KeyBinders
111        bool bDefaultFileLoaded_;                    //! Tells whether the default one is loaded
112        std::string defaultFilename_;                //! Name of the file with the default key bindings
113
114        // keybind command related
115        SharedPtr<LuaFunctor> callbackFunction_;     //! Function to be called when key was pressed after "keybind" command
116        bool bBinding_;                              //! Tells whether a key binding process is active
117        bool bTemporary_;                            //! Stores tkeybind/keybind value
118        std::string command_;                        //! Stores the command received by (t)keybind
119
120        static KeyBinderManager* singletonPtr_s;
121    }; //tolua_export
122} //tolua_export
123
124#endif /* _KeyBinderManager_H__ */
Note: See TracBrowser for help on using the repository browser.