Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2008, 12:31:32 AM (16 years ago)
Author:
rgrieder
Message:

FIRST THINGS FIRST: Delete or rename your keybindings.ini (def_keybindings.ini already has the most important bindings) or else you won't be able to do anything!

Changes:

  • Multiple joy stick support should now fully work with KeyBinder too (only tested with 0/1 joystick)
  • Reloading the OIS Devices now works with KeyBinder too
  • Modified ConfigValueContainer to accept arbitrary section names
  • added tkeybind to temporary bind a command to a key
  • Fixed dlleport issue in ArgumentCompletionFunctions.h

Internal changes:

  • General cleanup in initialisation of KeyBinder
  • All names of keys/buttons/axes are now statically saved in InputInterfaces.h
  • Move a magic value in KeyBinder to a configValue (MouseWheelStepSize_)
  • Separated ConfigValues from Keybinding ConfigValueContainer in KeyBinder (looks much nicer now ;))
  • Moved some performance critical small function to the inline section
  • Removed the ugly keybind function construct from the InputManager
  • More 'harmonising' work in KeyBinder
Location:
code/trunk/src/orxonox
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/gamestates/GSGraphics.cc

    r1878 r1887  
    114114        // Configure master input state with a KeyBinder
    115115        //masterKeyBinder_ = new KeyBinder();
     116        //masterKeyBinder_->loadBindings("master_keybindings.ini");
    116117        //inputManager_->getMasterInputState()->addKeyHandler(masterKeyBinder_);
    117118
  • code/trunk/src/orxonox/gamestates/GSLevel.cc

    r1826 r1887  
    3636#include "core/input/KeyBinder.h"
    3737#include "core/Loader.h"
     38#include "core/CommandExecutor.h"
     39#include "core/ConsoleCommand.h"
     40#include "core/ConfigValueIncludes.h"
     41#include "core/CoreIncludes.h"
    3842#include "objects/Backlight.h"
    3943#include "objects/Tickable.h"
     
    5559        , hud_(0)
    5660    {
     61        RegisterObject(GSLevel);
     62        setConfigValues();
    5763    }
    5864
    5965    GSLevel::~GSLevel()
    6066    {
     67    }
     68
     69    void GSLevel::setConfigValues()
     70    {
     71        SetConfigValue(keyDetectorCallbackCode_, "KeybindBindingStringKeyName=");
    6172    }
    6273
     
    6576        inputState_ = InputManager::getInstance().createInputState<SimpleInputState>("game", 20);
    6677        keyBinder_ = new KeyBinder();
    67         keyBinder_->loadBindings();
     78        keyBinder_->loadBindings("keybindings.ini");
    6879        inputState_->setHandler(keyBinder_);
    6980
     
    8899        // TODO: insert slomo console command with
    89100        // .accessLevel(AccessLevel::Offline).defaultValue(0, 1.0).axisParamIndex(0).isAxisRelative(false);
     101
     102        // keybind console command
     103        FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind);
     104        functor1->setObject(this);
     105        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind"));
     106        FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind);
     107        functor2->setObject(this);
     108        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind"));
     109        // set our console command as callback for the key detector
     110        InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_);
    90111    }
    91112
     
    145166        delete this->startLevel_;
    146167    }
     168
     169    void GSLevel::keybind(const std::string &command)
     170    {
     171        this->keybindInternal(command, false);
     172    }
     173
     174    void GSLevel::tkeybind(const std::string &command)
     175    {
     176        this->keybindInternal(command, true);
     177    }
     178
     179    /**
     180    @brief
     181        Assigns a command string to a key/button/axis. The name is determined via KeyDetector.
     182    @param command
     183        Command string that can be executed by the CommandExecutor
     184        OR: Internal string "KeybindBindingStringKeyName=" used for the second call to identify
     185        the key/button/axis that has been activated. This is configured above in enter().
     186    */
     187    void GSLevel::keybindInternal(const std::string& command, bool bTemporary)
     188    {
     189        static std::string bindingString = "";
     190        static bool bTemporarySaved = false;
     191        static bool bound = true;
     192        // note: We use a long name to make 'sure' that the user doesn't use it accidentally.
     193        // Howerver there will be no real issue if it happens anyway.
     194        if (command.find(keyDetectorCallbackCode_) != 0)
     195        {
     196            if (bound)
     197            {
     198                COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
     199                InputManager::getInstance().requestEnterState("detector");
     200                bindingString = command;
     201                bTemporarySaved = bTemporary;
     202                bound = false;
     203            }
     204            //else:  We're still in a keybind command. ignore this call.
     205        }
     206        else
     207        {
     208            if (!bound)
     209            {
     210                // user has pressed the key
     211                std::string name = command.substr(this->keyDetectorCallbackCode_.size());
     212                COUT(0) << "Binding string \"" << bindingString << "\" on key '" << name << "'" << std::endl;
     213                this->keyBinder_->setBinding(bindingString, name, bTemporarySaved);
     214                InputManager::getInstance().requestLeaveState("detector");
     215                bound = true;
     216            }
     217            // else: A key was pressed within the same tick, ignore it.
     218        }
     219    }
    147220}
  • code/trunk/src/orxonox/gamestates/GSLevel.h

    r1755 r1887  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSLevel : public GameState<GSGraphics>
     39    class _OrxonoxExport GSLevel : public GameState<GSGraphics>, public OrxonoxClass
    4040    {
     41        friend class ClassIdentifier<GSLevel>;
    4142    public:
    4243        GSLevel(const std::string& name);
     
    5859        float timeFactor_;       //!< A factor to change the gamespeed
    5960
     61        // console commands
     62        void keybind(const std::string& command);
     63        void tkeybind(const std::string& command);
     64        void keybindInternal(const std::string& command, bool bTemporary);
     65
    6066        Ogre::SceneManager*   sceneManager_;
    6167        KeyBinder*            keyBinder_;        //!< tool that loads and manages the input bindings
     
    6470        Level*                startLevel_;       //!< current hard coded default level
    6571        Level*                hud_;              //!< 'level' object fo the HUD
     72
     73        // config values
     74        std::string           keyDetectorCallbackCode_;
     75       
     76    private:
     77        void setConfigValues();
     78
    6679    };
    6780}
  • code/trunk/src/orxonox/gui/GUIManager.cc

    r1878 r1887  
    279279    }
    280280
    281     void GUIManager::mouseButtonPressed(MouseButton::Enum id)
     281    void GUIManager::mouseButtonPressed(MouseButtonCode::ByEnum id)
    282282    {
    283283        try
     
    292292    }
    293293
    294     void GUIManager::mouseButtonReleased(MouseButton::Enum id)
     294    void GUIManager::mouseButtonReleased(MouseButtonCode::ByEnum id)
    295295    {
    296296        try
     
    306306
    307307
    308     inline CEGUI::MouseButton GUIManager::convertButton(MouseButton::Enum button)
     308    inline CEGUI::MouseButton GUIManager::convertButton(MouseButtonCode::ByEnum button)
    309309    {
    310310        switch (button)
    311311        {
    312         case MouseButton::Left:
     312        case MouseButtonCode::Left:
    313313            return CEGUI::LeftButton;
    314314
    315         case MouseButton::Right:
     315        case MouseButtonCode::Right:
    316316            return CEGUI::RightButton;
    317317
    318         case MouseButton::Middle:
     318        case MouseButtonCode::Middle:
    319319            return CEGUI::MiddleButton;
    320320
    321         case MouseButton::Button3:
     321        case MouseButtonCode::Button3:
    322322            return CEGUI::X1Button;
    323323
    324         case MouseButton::Button4:
     324        case MouseButtonCode::Button4:
    325325            return CEGUI::X2Button;
    326326
  • code/trunk/src/orxonox/gui/GUIManager.h

    r1755 r1887  
    9393        { }
    9494
    95         void mouseButtonPressed (MouseButton::Enum id);
    96         void mouseButtonReleased(MouseButton::Enum id);
    97         void mouseButtonHeld    (MouseButton::Enum id)
     95        void mouseButtonPressed (MouseButtonCode::ByEnum id);
     96        void mouseButtonReleased(MouseButtonCode::ByEnum id);
     97        void mouseButtonHeld    (MouseButtonCode::ByEnum id)
    9898        { }
    9999        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
     
    123123        State state_;
    124124
    125         static CEGUI::MouseButton convertButton(MouseButton::Enum button);
     125        static CEGUI::MouseButton convertButton(MouseButtonCode::ByEnum button);
    126126
    127127        static GUIManager*        singletonRef_s;
Note: See TracChangeset for help on using the changeset viewer.