Changeset 6311 for code/branches/presentation2
- Timestamp:
- Dec 9, 2009, 11:17:14 PM (15 years ago)
- Location:
- code/branches/presentation2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout
r6292 r6311 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 3 4 3 <GUILayout > 5 6 4 <Window Type="DefaultWindow" Name="orxonox/KeyBindMenu/Background" > 7 8 5 <Property Name="InheritsAlpha" Value="False" /> 9 10 6 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 11 12 7 <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" /> 13 14 8 <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindWindow" > 15 16 9 <Property Name="Text" Value="Keybindings" /> 17 18 10 <Property Name="Alpha" Value="0.8" /> 19 20 11 <Property Name="InheritsAlpha" Value="False" /> 21 22 12 <Property Name="HorzFormatting" Value="HorzCentred" /> 23 24 13 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 25 26 14 <Property Name="VertFormatting" Value="TopAligned" /> 27 15 <Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.25,0},{0.8,0},{0.6,0}}" /> 28 29 16 <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindText" > 30 17 <Property Name="TextColours" Value="FF4444FF" /> … … 35 22 <Property Name="UnifiedAreaRect" Value="{{0.041666,0},{0.15,0},{0.958333,0},{0.92,0}}" /> 36 23 <Window Type="TaharezLook/ScrollablePane" Name="orxonox/KeyBindPane" > 37 38 24 <Property Name="ContentArea" Value="l:0 t:0 r:0 b:0" /> 39 40 25 <Property Name="HorzStepSize" Value="0.1" /> 41 42 26 <Property Name="VertStepSize" Value="0.1" /> 43 44 27 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 45 28 <Property Name="HorzOverlapSize" Value="0.01" /> 46 47 29 <Property Name="UnifiedAreaRect" Value="{{0.04,0},{0.005,0},{0.999,0},{0.99,0}}" /> 48 49 30 <Property Name="VertOverlapSize" Value="0.01" /> 50 51 31 <Property Name="HorzScrollPosition" Value="0" /> 52 53 32 <Property Name="VertScrollPosition" Value="0" /> 54 55 33 </Window> 56 57 34 </Window> 58 35 </Window> 59 60 36 <Window Type="TaharezLook/Button" Name="orxonox/KeyBindBackButton" > 61 62 37 <Property Name="Text" Value="Back" /> 63 64 38 <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" /> 65 66 39 <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.625,0},{0.6,0},{0.675,0}}" /> 67 68 40 <Event Name="Clicked" Function="KeyBindMenu.KeyBindBackButton_clicked"/> 69 70 41 </Window> 71 72 42 </Window> 73 74 43 </GUILayout> -
code/branches/presentation2/data/gui/scripts/GUITools.lua
r6283 r6311 5 5 end 6 6 7 function openInfoPopup(text, functionPtr, closeButton )7 function openInfoPopup(text, functionPtr, closeButton, arguments) 8 8 showGUI("InfoPopup", false, true) 9 InfoPopup.execute(functionPtr )9 InfoPopup.execute(functionPtr, arguments) 10 10 InfoPopup.setText(text) 11 11 InfoPopup.setCloseButton(closeButton) -
code/branches/presentation2/data/gui/scripts/InfoPopup.lua
r6283 r6311 15 15 end 16 16 17 function P.execute(functionPtr )17 function P.execute(functionPtr, arguments) 18 18 if functionPtr ~= nil then 19 functionPtr() 19 if arguments ~= nil then 20 functionPtr(arguments) 21 else 22 functionPtr() 23 end 20 24 end 21 25 end -
code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
r6292 r6311 52 52 table.insert(nameList, "Look Around") 53 53 table.insert(nameList, "Pause") 54 55 linesList = {} 54 56 55 local lineHeight = 30 57 lineHeight = 35 58 buttonWidth = 170 59 clearWidth = 20 56 60 57 61 local window = winMgr:getWindow("orxonox/KeyBindPane") 58 62 59 63 for k,v in pairs(commandList) do 60 local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) 61 local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") 62 local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button") 63 local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear") 64 local button2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button2") 65 local clear2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear2") 66 local add = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Add") 67 68 line:setSize(CEGUI.UVector2(CEGUI.UDim(1, -13), CEGUI.UDim(0, lineHeight))) 69 command:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0))) 70 button:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0))) 71 clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) 72 button2:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0))) 73 clear2:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) 74 add:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) 75 76 line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1)))) 77 command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 78 button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.2, 0))) 79 clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.2, 0))) 80 button2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(0.2, 0))) 81 clear2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.85, 0), CEGUI.UDim(0.2, 0))) 82 add:setPosition(CEGUI.UVector2(CEGUI.UDim(0.925, 0), CEGUI.UDim(0.2, 0))) 83 84 command:setText(nameList[k]) 85 button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) 86 clear:setText("X") 87 button2:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) 88 clear2:setText("X") 89 add:setText("+") 90 91 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") 92 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked") 93 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(add, "Clicked", P.filename .. ".KeyBindAdd_clicked") 94 --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") 95 96 line:addChildWindow(command) 97 line:addChildWindow(button) 98 line:addChildWindow(clear) 99 line:addChildWindow(button2) 100 line:addChildWindow(clear2) 101 line:addChildWindow(add) 64 local line = P.createLine(k) 65 table.insert(linesList, line) 102 66 window:addChildWindow(line) 103 67 end 68 69 local funct = luaState:createLuaFunctor("KeyBindMenu.callback()") 70 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 71 end 72 73 function P.createLine(k) 74 local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) 75 line:setHeight(CEGUI.UDim(0, lineHeight)) 76 line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1)))) 77 78 local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") 79 command:setSize(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(1, 0))) 80 command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 81 command:setText(nameList[k]) 82 line:addChildWindow(command) 83 84 local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus") 85 plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(1, 0))) 86 plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(0, 0))) 87 plus:setText("+") 88 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked") 89 line:addChildWindow(plus) 90 91 numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]); 92 for i=0,(numButtons-1) do 93 local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i) 94 button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.8, 0))) 95 button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth))+200+clearWidth), CEGUI.UDim(0.1, 0))) 96 button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)) 97 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") 98 --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") 99 line:addChildWindow(button) 100 101 local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i) 102 clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.8, 0))) 103 clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth)+buttonWidth)+200+clearWidth), CEGUI.UDim(0.1, 0))) 104 clear:setText("X") 105 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked") 106 line:addChildWindow(clear) 107 end 108 109 line:setWidth(CEGUI.UDim(0, 200+numButtons*(buttonWidth+clearWidth)+clearWidth)) 110 111 return line 104 112 end 105 113 … … 107 115 local we = CEGUI.toWindowEventArgs(e) 108 116 local name = we.window:getName() 109 buttonNr = tonumber(string.match(name, "%d+")) 110 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) 117 118 local match = string.gmatch(name, "%d+") 119 local commandNr = tonumber(match()) 120 local buttonNr = tonumber(match()) 121 122 local arguments = {} 123 arguments[1] = commandNr 124 arguments[2] = buttonNr 125 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments) 126 end 127 128 function P.KeyBindPlus_clicked(e) 129 local we = CEGUI.toWindowEventArgs(e) 130 local name = we.window:getName() 131 132 local match = string.gmatch(name, "%d+") 133 local commandNr = tonumber(match()) 134 135 local arguments = {} 136 arguments[1] = commandNr 137 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments) 111 138 end 112 139 … … 114 141 local we = CEGUI.toWindowEventArgs(e) 115 142 local name = we.window:getName() 116 clearNr = tonumber(string.match(name, "%d+")) 143 144 local match = string.gmatch(name, "%d+") 145 local commandNr = tonumber(match()) 146 local buttonNr = tonumber(match()) 147 148 orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)) 149 150 P.callback() 117 151 end 118 152 119 function P.KeyBindAdd_clicked(e) 120 153 function P.keybind(arguments) 154 local commandNr = arguments[1] 155 local buttonNr = arguments[2] 156 if buttonNr ~= nil then 157 orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)) 158 end 159 orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr]) 121 160 end 122 161 123 function P.keybind() 124 local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")") 125 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 126 orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr]) 127 end 162 function P.callback() 163 while table.getn(linesList) ~= 0 do 164 if linesList[1] ~= nil then 165 winMgr:destroyWindow(linesList[1]:getName()) 166 end 167 table.remove(linesList, 1) 168 end 169 170 linesList = {} 128 171 129 function P.callback(number) 130 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil) 131 local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button") 132 button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number])) 172 window = winMgr:getWindow("orxonox/KeyBindPane") 173 for q,w in pairs(commandList) do 174 local line = P.createLine(q) 175 table.insert(linesList, line) 176 window:addChildWindow(line) 177 end 133 178 134 InfoPopup.close() 179 if(InfoPopup ~= nil) then 180 InfoPopup.close() 181 end 135 182 end 136 183 -
code/branches/presentation2/src/libraries/core/input/KeyBinder.cc
r6214 r6311 29 29 #include "KeyBinder.h" 30 30 31 #include <algorithm> 32 #include <sstream> 31 33 #include "util/Convert.h" 32 34 #include "util/Debug.h" … … 256 258 { 257 259 it->second->readConfigValue(this->configFile_); 258 this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;260 addButtonToCommand(it->second->bindingString_, it->second); 259 261 } 260 262 … … 267 269 if (it != allButtons_.end()) 268 270 { 271 addButtonToCommand(binding, it->second); 269 272 if (bTemporary) 270 273 it->second->configContainer_->tset(binding); … … 272 275 it->second->configContainer_->set(binding); 273 276 it->second->configContainer_->getValue(&(it->second->bindingString_), it->second); 274 this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;275 277 return true; 276 278 } … … 282 284 } 283 285 284 /** 285 @brief 286 Return the key name for a specific command 286 void KeyBinder::addButtonToCommand(std::string command, Button* button) 287 { 288 std::ostringstream stream; 289 stream << button->groupName_ << "." << button->name_; 290 291 std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_]; 292 std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str()); 293 if(it != oldKeynames.end()) 294 { 295 oldKeynames.erase(it); 296 } 297 298 if(command != "") 299 { 300 std::vector<std::string>& keynames = this->allCommands_[command]; 301 if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end()) 302 { 303 this->allCommands_[command].push_back(stream.str()); 304 } 305 } 306 } 307 308 /** 309 @brief 310 Return the first key name for a specific command 287 311 */ 288 312 std::string KeyBinder::getBinding(std::string commandName) 289 313 { 290 COUT(0)<< commandName << endl;291 314 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 292 315 { 293 std::string keyname = this->allCommands_[commandName]; 294 // while(keyname.find(".")!=keyname.npos) 295 // keyname.replace(1, keyname.find("."), " "); 296 COUT(0) << keyname << endl; 297 return keyname; 298 } 299 else 316 std::vector<std::string>& keynames = this->allCommands_[commandName]; 317 return keynames.front(); 318 } 319 320 return ""; 321 } 322 323 /** 324 @brief 325 Return the key name for a specific command at a given index. 326 @param commandName 327 The command name the key name is returned for. 328 @param index 329 The index at which the key name is returned for. 330 */ 331 std::string KeyBinder::getBinding(std::string commandName, unsigned int index) 332 { 333 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 334 { 335 std::vector<std::string>& keynames = this->allCommands_[commandName]; 336 if(index < keynames.size()) 337 { 338 return keynames[index]; 339 } 340 300 341 return ""; 342 } 343 344 return ""; 345 } 346 347 /** 348 @brief 349 Get the number of different key bindings of a specific command. 350 @param commandName 351 The command. 352 */ 353 unsigned int KeyBinder::getNumberOfBindings(std::string commandName) 354 { 355 if( this->allCommands_.find(commandName) != this->allCommands_.end()) 356 { 357 std::vector<std::string>& keynames = this->allCommands_[commandName]; 358 return keynames.size(); 359 } 360 361 return 0; 301 362 } 302 363 -
code/branches/presentation2/src/libraries/core/input/KeyBinder.h
r6214 r6311 35 35 #include <string> 36 36 #include <vector> 37 #include <map> 37 38 #include <boost/shared_ptr.hpp> 38 39 … … 66 67 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 67 68 std::string getBinding(std::string commandName); //tolua_export 69 std::string getBinding(std::string commandName, unsigned int index); //tolua_export 70 unsigned int getNumberOfBindings(std::string commandName); //tolua_export 71 68 72 const std::string& getBindingsFilename() 69 73 { return this->filename_; } … … 135 139 std::vector<HalfAxis*> allHalfAxes_; 136 140 //! Maps input commands to all Button names, including half axes 137 std::map< std::string, std::string> allCommands_;141 std::map< std::string, std::vector<std::string> > allCommands_; 138 142 139 143 /** … … 156 160 157 161 private: 162 void addButtonToCommand(std::string command, Button* button); 163 158 164 //##### ConfigValues ##### 159 165 //! Whether to filter small value analog input -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
r6281 r6311 57 57 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind")) 58 58 .defaultValues(""); 59 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind")) 60 .defaultValues(""); 61 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind")) 62 .defaultValues(""); 59 63 60 64 // Load default key binder … … 89 93 else 90 94 this->bDefaultFileLoaded_ = false; 95 } 96 97 inline void KeyBinderManager::unbind(const std::string& binding) 98 { 99 this->currentBinder_->setBinding("", binding, false); 100 } 101 102 inline void KeyBinderManager::tunbind(const std::string& binding) 103 { 104 this->currentBinder_->setBinding("", binding, true); 91 105 } 92 106 … … 163 177 if (this->bBinding_) 164 178 { 165 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 166 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 179 if (keyName == "Keys.KeyEscape") 180 { 181 COUT(0) << "Keybinding aborted." << std::endl; 182 } 183 else 184 { 185 COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl; 186 this->currentBinder_->setBinding(command_, keyName, bTemporary_); 187 } 167 188 InputManager::getInstance().leaveState("detector"); 168 189 // inform whatever was calling the command -
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
r6281 r6311 100 100 inline void tkeybind(const std::string& command) 101 101 { this->keybindInternal(command, true); } 102 void unbind(const std::string& binding); //tolua_export 103 void tunbind(const std::string& binding); 102 104 inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export 103 105
Note: See TracChangeset
for help on using the changeset viewer.