- Timestamp:
- Dec 9, 2009, 12:43:12 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
r6268 r6281 86 86 87 87 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) 88 89 88 end 90 89 91 90 function P.keybind() 91 local funct = luaState:createLuaFunctor("InfoPopup:close()") 92 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 92 93 orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr]) 93 94 end -
code/branches/presentation2/src/libraries/core/LuaState.cc
r6190 r6281 263 263 } 264 264 } 265 266 267 LuaFunctor::LuaFunctor(const std::string& code, LuaState* luaState) 268 { 269 this->code_ = code; 270 this->lua_ = luaState; 271 } 272 273 void LuaFunctor::operator()(const MultiType& param1, const MultiType& param2, const MultiType& param3, const MultiType& param4, const MultiType& param5) 274 { 275 lua_->doString(this->code_); 276 } 265 277 } -
code/branches/presentation2/src/libraries/core/LuaState.h
r6150 r6281 40 40 41 41 #include "util/ScopeGuard.h" 42 #include "core/Functor.h" 42 43 #include "ToluaInterface.h" 43 44 44 // tolua_begin 45 namespace orxonox 46 { 45 namespace orxonox // tolua_export 46 { // tolua_export 47 class Functor; // tolua_export 48 49 //! Functor subclass that simply executes code with 0 arguments. 50 class _CoreExport LuaFunctor : public Functor 51 { 52 public: 53 LuaFunctor(const std::string& code, LuaState* luaState); 54 void operator()(const MultiType& param1 = MT_Type::Null, const MultiType& param2 = MT_Type::Null, const MultiType& param3 = MT_Type::Null, const MultiType& param4 = MT_Type::Null, const MultiType& param5 = MT_Type::Null); 55 void evaluateParam(unsigned int index, MultiType& param) const {} 56 57 private: 58 std::string code_; 59 LuaState* lua_; 60 }; 61 62 47 63 /** 48 64 @brief 49 65 Representation of an interface to lua 50 66 */ 51 class _CoreExport LuaState 52 { 53 // tolua_end 67 class _CoreExport LuaState // tolua_export 68 { // tolua_export 54 69 public: 55 70 LuaState(); … … 74 89 void setDefaultResourceInfo(const shared_ptr<ResourceInfo>& sourceFileInfo) { this->sourceFileInfo_ = sourceFileInfo; } 75 90 const shared_ptr<ResourceInfo>& getDefaultResourceInfo() { return this->sourceFileInfo_; } 91 92 Functor* createLuaFunctor(const std::string& code) { return new LuaFunctor(code, this); } // tolua_export 76 93 77 94 static bool addToluaInterface(int (*function)(lua_State*), const std::string& name); -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
r6266 r6281 29 29 #include "KeyBinderManager.h" 30 30 31 #include <CEGUIWindow.h> 32 31 33 #include "util/Debug.h" 32 34 #include "util/Exception.h" … … 37 39 #include "InputManager.h" 38 40 #include "KeyDetector.h" 39 40 #include <CEGUIWindow.h>41 41 42 42 namespace orxonox … … 49 49 , bBinding_(false) 50 50 { 51 this->callbackFunction_ = createFunctor(&KeyBinderManager::callback, this);52 53 51 RegisterObject(KeyBinderManager); 54 52 this->setConfigValues(); … … 69 67 for (std::map<std::string, KeyBinder*>::const_iterator it = this->binders_.begin(); it != this->binders_.end(); ++it) 70 68 delete it->second; 71 delete this->callbackFunction_;72 69 } 73 70 … … 152 149 { 153 150 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))); 155 152 InputManager::getInstance().enterState("detector"); 156 153 this->command_ = command; … … 162 159 163 160 // 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) 165 162 { 166 163 if (this->bBinding_) … … 169 166 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 170 167 InputManager::getInstance().leaveState("detector"); 168 // inform whatever was calling the command 169 if (this->callbackFunction_) 170 (*this->callbackFunction_)(); 171 171 this->bBinding_ = false; 172 172 } -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
r6280 r6281 34 34 #include <map> 35 35 #include <string> 36 #include <boost/shared_ptr.hpp> 37 #include <CEGUIForwardRefs.h> 38 36 39 #include "util/Singleton.h" 37 40 #include "core/OrxonoxClass.h" 38 39 #include <CEGUIForwardRefs.h>40 41 41 42 namespace orxonox //tolua_export … … 99 100 inline void tkeybind(const std::string& command) 100 101 { this->keybindInternal(command, true); } 102 inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export 101 103 102 104 private: 103 105 KeyBinderManager(const KeyBinderManager&); 104 106 void keybindInternal(const std::string& command, bool bTemporary); 105 void callback(const std::string& keyName);107 void keybindKeyPressed(const std::string& keyName); 106 108 void defaultFilenameChanged(); 107 109 … … 113 115 114 116 // keybind command related 115 Functor* callbackFunction_;//! Function to be called when key was pressed after "keybind" command117 shared_ptr<Functor> callbackFunction_; //! Function to be called when key was pressed after "keybind" command 116 118 bool bBinding_; //! Tells whether a key binding process is active 117 119 bool bTemporary_; //! Stores tkeybind/keybind value -
code/branches/presentation2/src/libraries/core/input/KeyDetector.h
r5929 r6281 32 32 #include "InputPrereqs.h" 33 33 34 #include <boost/shared_ptr.hpp> 34 35 #include "util/Singleton.h" 35 36 #include "KeyBinder.h" … … 45 46 ~KeyDetector(); 46 47 47 void setCallback( Functor*function) { this->callbackFunction_ = function; }48 void setCallback(const shared_ptr<Functor>& function) { this->callbackFunction_ = function; } 48 49 49 50 private: … … 54 55 void assignCommands(); 55 56 56 Functor*callbackFunction_;57 shared_ptr<Functor> callbackFunction_; 57 58 InputState* inputState_; 58 59 static std::string callbackCommand_s;
Note: See TracChangeset
for help on using the changeset viewer.