Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 3, 2009, 5:33:31 PM (15 years ago)
Author:
rgrieder
Message:

New class: KeyBinderManager (yes, it really was necessary, I'm not such a Fan of zillions of classes as well) and moved the keybind command to it from GSLevel.
This new Singleton simply maps the keybind command to the right KeyBinder, selected by KeyBinderManager::setCurrent().
There is also a default KeyBinder (with keybindings.ini as file), which should do the Trick for now. Other Keybinders should only server special purposes (like in mini games or so).

DELETE YOUR keybindings.ini FILE! =
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/orxonox/gamestates/GSLevel.cc

    r5855 r5863  
    3535#include "core/input/InputManager.h"
    3636#include "core/input/InputState.h"
    37 #include "core/input/KeyBinder.h"
     37#include "core/input/KeyBinderManager.h"
    3838#include "core/ConsoleCommand.h"
    3939#include "core/ConfigValueIncludes.h"
     
    5757    GSLevel::GSLevel(const GameStateInfo& info)
    5858        : GameState(info)
    59         , keyBinder_(0)
    6059        , gameInputState_(0)
    6160        , guiMouseOnlyInputState_(0)
     
    6362    {
    6463        RegisterObject(GSLevel);
    65 
    66         this->ccKeybind_ = 0;
    67         this->ccTkeybind_ = 0;
    6864    }
    6965
     
    7470    void GSLevel::setConfigValues()
    7571    {
    76         SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
    7772    }
    7873
     
    8479        {
    8580            gameInputState_ = InputManager::getInstance().createInputState("game");
    86             keyBinder_ = new KeyBinder();
    87             keyBinder_->loadBindings("keybindings.ini");
    88             gameInputState_->setHandler(keyBinder_);
     81            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
     82            KeyBinderManager::getInstance().setToDefault();
    8983
    9084            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
     
    10296        if (GameMode::showsGraphics())
    10397        {
    104             // keybind console command
    105             ccKeybind_ = createConsoleCommand(createFunctor(&GSLevel::keybind, this), "keybind");
    106             CommandExecutor::addConsoleCommandShortcut(ccKeybind_);
    107             ccTkeybind_ = createConsoleCommand(createFunctor(&GSLevel::tkeybind, this), "tkeybind");
    108             CommandExecutor::addConsoleCommandShortcut(ccTkeybind_);
    109             // set our console command as callback for the key detector
    110             InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
    111 
    11298            // level is loaded: we can start capturing the input
    11399            InputManager::getInstance().enterState("game");
     
    136122    void GSLevel::deactivate()
    137123    {
    138 /*
    139         // destroy console commands
    140         if (this->ccKeybind_)
    141         {
    142             delete this->ccKeybind_;
    143             this->ccKeybind_ = 0;
    144         }
    145         if (this->ccTkeybind_)
    146         {
    147             delete this->ccTkeybind_;
    148             this->ccTkeybind_ = 0;
    149         }
    150 */
    151 
    152124        if (GameMode::showsGraphics())
    153125        {
     
    181153            InputManager::getInstance().destroyState("guiKeysOnly");
    182154            InputManager::getInstance().destroyState("guiMouseOnly");
    183             if (this->keyBinder_)
    184             {
    185                 this->keyBinder_->destroy();
    186                 this->keyBinder_ = 0;
    187             }
    188155        }
    189156    }
     
    211178        delete startFile_s;
    212179    }
    213 
    214     void GSLevel::keybind(const std::string &command)
    215     {
    216         this->keybindInternal(command, false);
    217     }
    218 
    219     void GSLevel::tkeybind(const std::string &command)
    220     {
    221         this->keybindInternal(command, true);
    222     }
    223 
    224     /**
    225     @brief
    226         Assigns a command string to a key/button/axis. The name is determined via KeyDetector.
    227     @param command
    228         Command string that can be executed by the CommandExecutor
    229         OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
    230         the key/button/axis that has been activated. This is configured above in activate().
    231     */
    232     void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
    233     {
    234         if (GameMode::showsGraphics())
    235         {
    236             static std::string bindingString = "";
    237             static bool bTemporarySaved = false;
    238             static bool bound = true;
    239             // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
    240             // Howerver there will be no real issue if it happens anyway.
    241             if (command.find(keyDetectorCallbackCode_) != 0)
    242             {
    243                 if (bound)
    244                 {
    245                     COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    246                     InputManager::getInstance().enterState("detector");
    247                     bindingString = command;
    248                     bTemporarySaved = bTemporary;
    249                     bound = false;
    250                 }
    251                 //else:  We're still in a keybind command. ignore this call.
    252             }
    253             else
    254             {
    255                 if (!bound)
    256                 {
    257                     // user has pressed the key
    258                     std::string name = command.substr(this->keyDetectorCallbackCode_.size());
    259                     COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
    260                     this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
    261                     InputManager::getInstance().leaveState("detector");
    262                     bound = true;
    263                 }
    264                 // else: A key was pressed within the same tick, ignore it.
    265             }
    266         }
    267     }
    268180}
Note: See TracChangeset for help on using the changeset viewer.