Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2009, 12:43:12 PM (15 years ago)
Author:
rgrieder
Message:

Added LuaFunctor that can execute arbitrary lua code.
Also added LuaState::createLuaFunctor(std::string) and implemented that for the keybindings menu.

Location:
code/branches/presentation2/src/libraries/core/input
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc

    r6266 r6281  
    2929#include "KeyBinderManager.h"
    3030
     31#include <CEGUIWindow.h>
     32
    3133#include "util/Debug.h"
    3234#include "util/Exception.h"
     
    3739#include "InputManager.h"
    3840#include "KeyDetector.h"
    39 
    40 #include <CEGUIWindow.h>
    4141
    4242namespace orxonox
     
    4949        , bBinding_(false)
    5050    {
    51         this->callbackFunction_ = createFunctor(&KeyBinderManager::callback, this);
    52 
    5351        RegisterObject(KeyBinderManager);
    5452        this->setConfigValues();
     
    6967        for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it)
    7068            delete it->second;
    71         delete this->callbackFunction_;
    7269    }
    7370
     
    152149        {
    153150            COUT(0) << "Press any button/key or move a mouse/joystick axis" << std::endl;
    154             KeyDetector::getInstance().setCallback(callbackFunction_);
     151            KeyDetector::getInstance().setCallback(shared_ptr<Functor>(createFunctor(&KeyBinderManager::keybindKeyPressed, this)));
    155152            InputManager::getInstance().enterState("detector");
    156153            this->command_ = command;
     
    162159
    163160    // Gets called by the KeyDetector (registered with a Functor)
    164     void KeyBinderManager::callback(const std::string& keyName)
     161    void KeyBinderManager::keybindKeyPressed(const std::string& keyName)
    165162    {
    166163        if (this->bBinding_)
     
    169166            this->currentBinder_->setBinding(command_, keyName, bTemporary_);
    170167            InputManager::getInstance().leaveState("detector");
     168            // inform whatever was calling the command
     169            if (this->callbackFunction_)
     170                (*this->callbackFunction_)();
    171171            this->bBinding_ = false;
    172172        }
  • code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h

    r6280 r6281  
    3434#include <map>
    3535#include <string>
     36#include <boost/shared_ptr.hpp>
     37#include <CEGUIForwardRefs.h>
     38
    3639#include "util/Singleton.h"
    3740#include "core/OrxonoxClass.h"
    38 
    39 #include <CEGUIForwardRefs.h>
    4041
    4142namespace orxonox //tolua_export
     
    99100        inline void tkeybind(const std::string& command)
    100101            { this->keybindInternal(command, true); }
     102        inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
    101103
    102104    private:
    103105        KeyBinderManager(const KeyBinderManager&);
    104106        void keybindInternal(const std::string& command, bool bTemporary);
    105         void callback(const std::string& keyName);
     107        void keybindKeyPressed(const std::string& keyName);
    106108        void defaultFilenameChanged();
    107109
     
    113115
    114116        // keybind command related
    115         Functor* callbackFunction_;                  //! Function to be called when key was pressed after "keybind" command
     117        shared_ptr<Functor> callbackFunction_;       //! Function to be called when key was pressed after "keybind" command
    116118        bool bBinding_;                              //! Tells whether a key binding process is active
    117119        bool bTemporary_;                            //! Stores tkeybind/keybind value
  • code/branches/presentation2/src/libraries/core/input/KeyDetector.h

    r5929 r6281  
    3232#include "InputPrereqs.h"
    3333
     34#include <boost/shared_ptr.hpp>
    3435#include "util/Singleton.h"
    3536#include "KeyBinder.h"
     
    4546        ~KeyDetector();
    4647
    47         void setCallback(Functor* function) { this->callbackFunction_ = function; }
     48        void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; }
    4849
    4950    private:
     
    5455        void assignCommands();
    5556
    56         Functor* callbackFunction_;
     57        shared_ptr<Functor> callbackFunction_;
    5758        InputState* inputState_;
    5859        static std::string callbackCommand_s;
Note: See TracChangeset for help on using the changeset viewer.