Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/core/input/KeyDetector.cc @ 7284

Last change on this file since 7284 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[1526]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#include "KeyDetector.h"
[3196]30
[7284]31#include "util/ScopedSingletonManager.h"
[1526]32#include "core/CoreIncludes.h"
[7284]33#include "core/command/ConsoleCommand.h"
[1526]34#include "Button.h"
[5929]35#include "InputManager.h"
36#include "InputState.h"
[1526]37
38namespace orxonox
39{
[5929]40    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
41
[7284]42    static const std::string __CC_KeyDetector_callback_name = "KeyDetectorKeyPressed";
43    DeclareConsoleCommand(__CC_KeyDetector_callback_name, &prototype::void__string).hide();
44
[1755]45    KeyDetector::KeyDetector()
[5929]46        : KeyBinder("")
[1755]47    {
48        RegisterObject(KeyDetector);
[5929]49
[7284]50        ModifyConsoleCommand(__CC_KeyDetector_callback_name).setFunction(&KeyDetector::callback, this);
51
[5929]52        this->assignCommands();
53
54        inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector);
55        // Create a callback to avoid buttonHeld events after the key has been detected
56        inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance()));
57        inputState_->setHandler(this);
[1755]58    }
[1526]59
[1755]60    KeyDetector::~KeyDetector()
61    {
[5929]62        inputState_->setHandler(NULL);
63        InputManager::getInstance().destroyState("detector");
[7284]64        ModifyConsoleCommand(__CC_KeyDetector_callback_name).resetFunction();
[1755]65    }
[1526]66
[5929]67    void KeyDetector::assignCommands()
[1755]68    {
[5929]69        // Assign every button/axis the same command, but with its name as argument
[1887]70        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
[7284]71            it->second->parse(__CC_KeyDetector_callback_name + ' ' + it->second->groupName_ + "." + it->second->name_);
[1755]72    }
[1526]73
[5929]74    void KeyDetector::callback(const std::string& name)
75    {
76        // Call the registered function
77        if (this->callbackFunction_)
78            (*this->callbackFunction_)(name);
79    }
80
[3327]81    void KeyDetector::JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList)
[1755]82    {
[3327]83        KeyBinder::JoyStickQuantityChanged(joyStickList);
[5929]84        this->assignCommands();
[1755]85    }
[1526]86}
Note: See TracBrowser for help on using the repository browser.