[Orxonox-commit 1593] r6311 - in code/branches/presentation2: data/gui/layouts data/gui/scripts src/libraries/core/input
dafrick at orxonox.net
dafrick at orxonox.net
Wed Dec 9 23:17:14 CET 2009
Author: dafrick
Date: 2009-12-09 23:17:14 +0100 (Wed, 09 Dec 2009)
New Revision: 6311
Modified:
code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout
code/branches/presentation2/data/gui/scripts/GUITools.lua
code/branches/presentation2/data/gui/scripts/InfoPopup.lua
code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
code/branches/presentation2/src/libraries/core/input/KeyBinder.cc
code/branches/presentation2/src/libraries/core/input/KeyBinder.h
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
Log:
The KeyBindMenu now shows all Keybindings and allows for various manipulations.
For this the bookkeeping in KeyBinder has ben improved.
Also KeyEscape now can't be bound to other commands.
Modified: code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout
===================================================================
--- code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/data/gui/layouts/KeyBindMenu.layout 2009-12-09 22:17:14 UTC (rev 6311)
@@ -1,74 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
-
-<GUILayout >
-
- <Window Type="DefaultWindow" Name="orxonox/KeyBindMenu/Background" >
-
- <Property Name="InheritsAlpha" Value="False" />
-
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
-
- <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
-
+<GUILayout >
+ <Window Type="DefaultWindow" Name="orxonox/KeyBindMenu/Background" >
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
<Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindWindow" >
-
- <Property Name="Text" Value="Keybindings" />
-
- <Property Name="Alpha" Value="0.8" />
-
- <Property Name="InheritsAlpha" Value="False" />
-
- <Property Name="HorzFormatting" Value="HorzCentred" />
-
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
-
- <Property Name="VertFormatting" Value="TopAligned" />
+ <Property Name="Text" Value="Keybindings" />
+ <Property Name="Alpha" Value="0.8" />
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="HorzFormatting" Value="HorzCentred" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="VertFormatting" Value="TopAligned" />
<Property Name="UnifiedAreaRect" Value="{{0.2,0},{0.25,0},{0.8,0},{0.6,0}}" />
-
- <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindText" >
- <Property Name="TextColours" Value="FF4444FF" />
- <Property Name="InheritsAlpha" Value="False" />
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="HorzFormatting" Value="HorzCentred" />
- <Property Name="VertFormatting" Value="TopAligned" />
- <Property Name="UnifiedAreaRect" Value="{{0.041666,0},{0.15,0},{0.958333,0},{0.92,0}}" />
- <Window Type="TaharezLook/ScrollablePane" Name="orxonox/KeyBindPane" >
-
- <Property Name="ContentArea" Value="l:0 t:0 r:0 b:0" />
-
- <Property Name="HorzStepSize" Value="0.1" />
-
+ <Window Type="TaharezLook/StaticText" Name="orxonox/KeyBindText" >
+ <Property Name="TextColours" Value="FF4444FF" />
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="HorzFormatting" Value="HorzCentred" />
+ <Property Name="VertFormatting" Value="TopAligned" />
+ <Property Name="UnifiedAreaRect" Value="{{0.041666,0},{0.15,0},{0.958333,0},{0.92,0}}" />
+ <Window Type="TaharezLook/ScrollablePane" Name="orxonox/KeyBindPane" >
+ <Property Name="ContentArea" Value="l:0 t:0 r:0 b:0" />
+ <Property Name="HorzStepSize" Value="0.1" />
<Property Name="VertStepSize" Value="0.1" />
-
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
- <Property Name="HorzOverlapSize" Value="0.01" />
-
- <Property Name="UnifiedAreaRect" Value="{{0.04,0},{0.005,0},{0.999,0},{0.99,0}}" />
-
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="HorzOverlapSize" Value="0.01" />
+ <Property Name="UnifiedAreaRect" Value="{{0.04,0},{0.005,0},{0.999,0},{0.99,0}}" />
<Property Name="VertOverlapSize" Value="0.01" />
-
- <Property Name="HorzScrollPosition" Value="0" />
-
- <Property Name="VertScrollPosition" Value="0" />
-
- </Window>
-
- </Window>
- </Window>
-
+ <Property Name="HorzScrollPosition" Value="0" />
+ <Property Name="VertScrollPosition" Value="0" />
+ </Window>
+ </Window>
+ </Window>
<Window Type="TaharezLook/Button" Name="orxonox/KeyBindBackButton" >
-
- <Property Name="Text" Value="Back" />
-
- <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
-
- <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.625,0},{0.6,0},{0.675,0}}" />
-
- <Event Name="Clicked" Function="KeyBindMenu.KeyBindBackButton_clicked"/>
-
- </Window>
-
- </Window>
-
+ <Property Name="Text" Value="Back" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0.4,0},{0.625,0},{0.6,0},{0.675,0}}" />
+ <Event Name="Clicked" Function="KeyBindMenu.KeyBindBackButton_clicked"/>
+ </Window>
+ </Window>
</GUILayout>
Modified: code/branches/presentation2/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/GUITools.lua 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/data/gui/scripts/GUITools.lua 2009-12-09 22:17:14 UTC (rev 6311)
@@ -4,9 +4,9 @@
DecisionPopup.setText(text)
end
-function openInfoPopup(text, functionPtr, closeButton)
+function openInfoPopup(text, functionPtr, closeButton, arguments)
showGUI("InfoPopup", false, true)
- InfoPopup.execute(functionPtr)
+ InfoPopup.execute(functionPtr, arguments)
InfoPopup.setText(text)
InfoPopup.setCloseButton(closeButton)
end
Modified: code/branches/presentation2/data/gui/scripts/InfoPopup.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/InfoPopup.lua 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/data/gui/scripts/InfoPopup.lua 2009-12-09 22:17:14 UTC (rev 6311)
@@ -14,9 +14,13 @@
function P:init()
end
-function P.execute(functionPtr)
+function P.execute(functionPtr, arguments)
if functionPtr ~= nil then
- functionPtr()
+ if arguments ~= nil then
+ functionPtr(arguments)
+ else
+ functionPtr()
+ end
end
end
Modified: code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua 2009-12-09 22:17:14 UTC (rev 6311)
@@ -1,142 +1,189 @@
--- KeyBindMenu.lua
-
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new() --inherit everything from the gui package
-if _REQUIREDNAME == nil then
- KeyBindMenu = P
-else
- _G[_REQUIREDNAME] = P
-end
-
-P.filename = "KeyBindMenu"
-P.layoutString = "KeyBindMenu.layout"
-
-function P:init()
- commandList = {}
- table.insert(commandList, "fire 0")
- table.insert(commandList, "fire 1 | unfire")
- table.insert(commandList, "onpress fire 2")
- table.insert(commandList, "scale 1 moveFrontBack")
- table.insert(commandList, "scale -1 moveFrontBack")
- table.insert(commandList, "boost")
- table.insert(commandList, "scale 1 moveRightLeft")
- table.insert(commandList, "scale -1 moveRightLeft")
- table.insert(commandList, "scale 1 moveUpDown")
- table.insert(commandList, "scale -1 moveUpDown")
- table.insert(commandList, "scale 1 rotateRoll")
- table.insert(commandList, "scale -1 rotateRoll")
- table.insert(commandList, "switchCamera")
- table.insert(commandList, "openConsole")
- table.insert(commandList, "OverlayGroup toggleVisibility Debug")
- table.insert(commandList, "OverlayGroup toggleVisibility Stats")
- table.insert(commandList, "mouseLook")
- table.insert(commandList, "pause")
-
- nameList = {}
- table.insert(nameList, "Primary Fire")
- table.insert(nameList, "Secondary Fire")
- table.insert(nameList, "Fire Rocket")
- table.insert(nameList, "Accelerate")
- table.insert(nameList, "Break")
- table.insert(nameList, "Boost")
- table.insert(nameList, "Move Right")
- table.insert(nameList, "Move Left")
- table.insert(nameList, "Move Up")
- table.insert(nameList, "Move Down")
- table.insert(nameList, "Roll Right")
- table.insert(nameList, "Roll Left")
- table.insert(nameList, "Switch Camera")
- table.insert(nameList, "Open Console")
- table.insert(nameList, "Show Debug")
- table.insert(nameList, "Show Stats")
- table.insert(nameList, "Look Around")
- table.insert(nameList, "Pause")
-
- local lineHeight = 30
-
- local window = winMgr:getWindow("orxonox/KeyBindPane")
-
- for k,v in pairs(commandList) do
- local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
- local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
- local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
- local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear")
- local button2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button2")
- local clear2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear2")
- local add = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Add")
-
- line:setSize(CEGUI.UVector2(CEGUI.UDim(1, -13), CEGUI.UDim(0, lineHeight)))
- command:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
- button:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
- clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
- button2:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
- clear2:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
- add:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
-
- line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
- command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.2, 0)))
- clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.2, 0)))
- button2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(0.2, 0)))
- clear2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.85, 0), CEGUI.UDim(0.2, 0)))
- add:setPosition(CEGUI.UVector2(CEGUI.UDim(0.925, 0), CEGUI.UDim(0.2, 0)))
-
- command:setText(nameList[k])
- button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
- clear:setText("X")
- button2:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
- clear2:setText("X")
- add:setText("+")
-
- orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
- orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
- orxonox.KeyBinderManager:getInstance():subscribeEventHelper(add, "Clicked", P.filename .. ".KeyBindAdd_clicked")
- --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
-
- line:addChildWindow(command)
- line:addChildWindow(button)
- line:addChildWindow(clear)
- line:addChildWindow(button2)
- line:addChildWindow(clear2)
- line:addChildWindow(add)
- window:addChildWindow(line)
- end
-end
-
-function P.KeyBindButton_clicked(e)
- local we = CEGUI.toWindowEventArgs(e)
- local name = we.window:getName()
- buttonNr = tonumber(string.match(name, "%d+"))
- openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
-end
-
-function P.KeyBindClear_clicked(e)
- local we = CEGUI.toWindowEventArgs(e)
- local name = we.window:getName()
- clearNr = tonumber(string.match(name, "%d+"))
-end
-
-function P.KeyBindAdd_clicked(e)
-
-end
-
-function P.keybind()
- local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")")
- orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
- orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr])
-end
-
-function P.callback(number)
- orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil)
- local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button")
- button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number]))
-
- InfoPopup.close()
-end
-
-function P.KeyBindBackButton_clicked(e)
- hideGUI("KeyBindMenu")
-end
-
-return P
-
+-- KeyBindMenu.lua
+
+BasicGUI = require("BasicGUI")
+local P = BasicGUI:new() --inherit everything from the gui package
+if _REQUIREDNAME == nil then
+ KeyBindMenu = P
+else
+ _G[_REQUIREDNAME] = P
+end
+
+P.filename = "KeyBindMenu"
+P.layoutString = "KeyBindMenu.layout"
+
+function P:init()
+ commandList = {}
+ table.insert(commandList, "fire 0")
+ table.insert(commandList, "fire 1 | unfire")
+ table.insert(commandList, "onpress fire 2")
+ table.insert(commandList, "scale 1 moveFrontBack")
+ table.insert(commandList, "scale -1 moveFrontBack")
+ table.insert(commandList, "boost")
+ table.insert(commandList, "scale 1 moveRightLeft")
+ table.insert(commandList, "scale -1 moveRightLeft")
+ table.insert(commandList, "scale 1 moveUpDown")
+ table.insert(commandList, "scale -1 moveUpDown")
+ table.insert(commandList, "scale 1 rotateRoll")
+ table.insert(commandList, "scale -1 rotateRoll")
+ table.insert(commandList, "switchCamera")
+ table.insert(commandList, "openConsole")
+ table.insert(commandList, "OverlayGroup toggleVisibility Debug")
+ table.insert(commandList, "OverlayGroup toggleVisibility Stats")
+ table.insert(commandList, "mouseLook")
+ table.insert(commandList, "pause")
+
+ nameList = {}
+ table.insert(nameList, "Primary Fire")
+ table.insert(nameList, "Secondary Fire")
+ table.insert(nameList, "Fire Rocket")
+ table.insert(nameList, "Accelerate")
+ table.insert(nameList, "Break")
+ table.insert(nameList, "Boost")
+ table.insert(nameList, "Move Right")
+ table.insert(nameList, "Move Left")
+ table.insert(nameList, "Move Up")
+ table.insert(nameList, "Move Down")
+ table.insert(nameList, "Roll Right")
+ table.insert(nameList, "Roll Left")
+ table.insert(nameList, "Switch Camera")
+ table.insert(nameList, "Open Console")
+ table.insert(nameList, "Show Debug")
+ table.insert(nameList, "Show Stats")
+ table.insert(nameList, "Look Around")
+ table.insert(nameList, "Pause")
+
+ linesList = {}
+
+ lineHeight = 35
+ buttonWidth = 170
+ clearWidth = 20
+
+ local window = winMgr:getWindow("orxonox/KeyBindPane")
+
+ for k,v in pairs(commandList) do
+ local line = P.createLine(k)
+ table.insert(linesList, line)
+ window:addChildWindow(line)
+ end
+
+ local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
+ orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
+end
+
+function P.createLine(k)
+ local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
+ line:setHeight(CEGUI.UDim(0, lineHeight))
+ line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
+
+ local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
+ command:setSize(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(1, 0)))
+ command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
+ command:setText(nameList[k])
+ line:addChildWindow(command)
+
+ local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
+ plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(1, 0)))
+ plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(0, 0)))
+ plus:setText("+")
+ orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
+ line:addChildWindow(plus)
+
+ numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
+ for i=0,(numButtons-1) do
+ local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
+ button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.8, 0)))
+ button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth))+200+clearWidth), CEGUI.UDim(0.1, 0)))
+ button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i))
+ orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
+ --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
+ line:addChildWindow(button)
+
+ local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
+ clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.8, 0)))
+ clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth)+buttonWidth)+200+clearWidth), CEGUI.UDim(0.1, 0)))
+ clear:setText("X")
+ orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
+ line:addChildWindow(clear)
+ end
+
+ line:setWidth(CEGUI.UDim(0, 200+numButtons*(buttonWidth+clearWidth)+clearWidth))
+
+ return line
+end
+
+function P.KeyBindButton_clicked(e)
+ local we = CEGUI.toWindowEventArgs(e)
+ local name = we.window:getName()
+
+ local match = string.gmatch(name, "%d+")
+ local commandNr = tonumber(match())
+ local buttonNr = tonumber(match())
+
+ local arguments = {}
+ arguments[1] = commandNr
+ arguments[2] = buttonNr
+ openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
+end
+
+function P.KeyBindPlus_clicked(e)
+ local we = CEGUI.toWindowEventArgs(e)
+ local name = we.window:getName()
+
+ local match = string.gmatch(name, "%d+")
+ local commandNr = tonumber(match())
+
+ local arguments = {}
+ arguments[1] = commandNr
+ openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
+end
+
+function P.KeyBindClear_clicked(e)
+ local we = CEGUI.toWindowEventArgs(e)
+ local name = we.window:getName()
+
+ local match = string.gmatch(name, "%d+")
+ local commandNr = tonumber(match())
+ local buttonNr = tonumber(match())
+
+ orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
+
+ P.callback()
+end
+
+function P.keybind(arguments)
+ local commandNr = arguments[1]
+ local buttonNr = arguments[2]
+ if buttonNr ~= nil then
+ orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
+ end
+ orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
+end
+
+function P.callback()
+ while table.getn(linesList) ~= 0 do
+ if linesList[1] ~= nil then
+ winMgr:destroyWindow(linesList[1]:getName())
+ end
+ table.remove(linesList, 1)
+ end
+
+ linesList = {}
+
+ window = winMgr:getWindow("orxonox/KeyBindPane")
+ for q,w in pairs(commandList) do
+ local line = P.createLine(q)
+ table.insert(linesList, line)
+ window:addChildWindow(line)
+ end
+
+ if(InfoPopup ~= nil) then
+ InfoPopup.close()
+ end
+end
+
+function P.KeyBindBackButton_clicked(e)
+ hideGUI("KeyBindMenu")
+end
+
+return P
+
Modified: code/branches/presentation2/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/input/KeyBinder.cc 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/src/libraries/core/input/KeyBinder.cc 2009-12-09 22:17:14 UTC (rev 6311)
@@ -28,6 +28,8 @@
#include "KeyBinder.h"
+#include <algorithm>
+#include <sstream>
#include "util/Convert.h"
#include "util/Debug.h"
#include "util/Exception.h"
@@ -255,7 +257,7 @@
for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
{
it->second->readConfigValue(this->configFile_);
- this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;
+ addButtonToCommand(it->second->bindingString_, it->second);
}
COUT(3) << "KeyBinder: Loading key bindings done." << std::endl;
@@ -266,12 +268,12 @@
std::map<std::string, Button*>::iterator it = allButtons_.find(name);
if (it != allButtons_.end())
{
+ addButtonToCommand(binding, it->second);
if (bTemporary)
it->second->configContainer_->tset(binding);
else
it->second->configContainer_->set(binding);
it->second->configContainer_->getValue(&(it->second->bindingString_), it->second);
- this->allCommands_[it->second->bindingString_] = it->second->groupName_ + " " + it->second->name_;
return true;
}
else
@@ -281,24 +283,83 @@
}
}
+ void KeyBinder::addButtonToCommand(std::string command, Button* button)
+ {
+ std::ostringstream stream;
+ stream << button->groupName_ << "." << button->name_;
+
+ std::vector<std::string>& oldKeynames = this->allCommands_[button->bindingString_];
+ std::vector<std::string>::iterator it = std::find(oldKeynames.begin(), oldKeynames.end(), stream.str());
+ if(it != oldKeynames.end())
+ {
+ oldKeynames.erase(it);
+ }
+
+ if(command != "")
+ {
+ std::vector<std::string>& keynames = this->allCommands_[command];
+ if( std::find(keynames.begin(), keynames.end(), stream.str()) == keynames.end())
+ {
+ this->allCommands_[command].push_back(stream.str());
+ }
+ }
+ }
+
/**
@brief
- Return the key name for a specific command
+ Return the first key name for a specific command
*/
std::string KeyBinder::getBinding(std::string commandName)
{
- COUT(0)<< commandName << endl;
if( this->allCommands_.find(commandName) != this->allCommands_.end())
{
- std::string keyname = this->allCommands_[commandName];
-// while(keyname.find(".")!=keyname.npos)
-// keyname.replace(1, keyname.find("."), " ");
- COUT(0) << keyname << endl;
- return keyname;
+ std::vector<std::string>& keynames = this->allCommands_[commandName];
+ return keynames.front();
}
- else
+
+ return "";
+ }
+
+ /**
+ @brief
+ Return the key name for a specific command at a given index.
+ @param commandName
+ The command name the key name is returned for.
+ @param index
+ The index at which the key name is returned for.
+ */
+ std::string KeyBinder::getBinding(std::string commandName, unsigned int index)
+ {
+ if( this->allCommands_.find(commandName) != this->allCommands_.end())
+ {
+ std::vector<std::string>& keynames = this->allCommands_[commandName];
+ if(index < keynames.size())
+ {
+ return keynames[index];
+ }
+
return "";
+ }
+
+ return "";
}
+
+ /**
+ @brief
+ Get the number of different key bindings of a specific command.
+ @param commandName
+ The command.
+ */
+ unsigned int KeyBinder::getNumberOfBindings(std::string commandName)
+ {
+ if( this->allCommands_.find(commandName) != this->allCommands_.end())
+ {
+ std::vector<std::string>& keynames = this->allCommands_[commandName];
+ return keynames.size();
+ }
+
+ return 0;
+ }
/**
@brief
Modified: code/branches/presentation2/src/libraries/core/input/KeyBinder.h
===================================================================
--- code/branches/presentation2/src/libraries/core/input/KeyBinder.h 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/src/libraries/core/input/KeyBinder.h 2009-12-09 22:17:14 UTC (rev 6311)
@@ -34,6 +34,7 @@
#include <cassert>
#include <string>
#include <vector>
+#include <map>
#include <boost/shared_ptr.hpp>
#include "InputHandler.h"
@@ -65,6 +66,9 @@
void clearBindings();
bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
std::string getBinding(std::string commandName); //tolua_export
+ std::string getBinding(std::string commandName, unsigned int index); //tolua_export
+ unsigned int getNumberOfBindings(std::string commandName); //tolua_export
+
const std::string& getBindingsFilename()
{ return this->filename_; }
void setConfigValues();
@@ -134,7 +138,7 @@
//! Pointer list with all half axes
std::vector<HalfAxis*> allHalfAxes_;
//! Maps input commands to all Button names, including half axes
- std::map<std::string, std::string> allCommands_;
+ std::map< std::string, std::vector<std::string> > allCommands_;
/**
@brief
@@ -155,6 +159,8 @@
ConfigFileType configFile_;
private:
+ void addButtonToCommand(std::string command, Button* button);
+
//##### ConfigValues #####
//! Whether to filter small value analog input
bool bFilterAnalogNoise_;
Modified: code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/src/libraries/core/input/KeyBinderManager.cc 2009-12-09 22:17:14 UTC (rev 6311)
@@ -56,6 +56,10 @@
.defaultValues("");
CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tkeybind, this), "tkeybind"))
.defaultValues("");
+ CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::unbind, this), "unbind"))
+ .defaultValues("");
+ CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyBinderManager::tunbind, this), "tunbind"))
+ .defaultValues("");
// Load default key binder
this->setCurrent(defaultFilename_);
@@ -90,6 +94,16 @@
this->bDefaultFileLoaded_ = false;
}
+ inline void KeyBinderManager::unbind(const std::string& binding)
+ {
+ this->currentBinder_->setBinding("", binding, false);
+ }
+
+ inline void KeyBinderManager::tunbind(const std::string& binding)
+ {
+ this->currentBinder_->setBinding("", binding, true);
+ }
+
void KeyBinderManager::subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function)
{
window->subscribeScriptedEvent(event, function);
@@ -162,8 +176,15 @@
{
if (this->bBinding_)
{
- COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
- this->currentBinder_->setBinding(command_, keyName, bTemporary_);
+ if (keyName == "Keys.KeyEscape")
+ {
+ COUT(0) << "Keybinding aborted." << std::endl;
+ }
+ else
+ {
+ COUT(0) << "Binding string \"" << command_ << "\" on key '" << keyName << "'" << std::endl;
+ this->currentBinder_->setBinding(command_, keyName, bTemporary_);
+ }
InputManager::getInstance().leaveState("detector");
// inform whatever was calling the command
if (this->callbackFunction_)
Modified: code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h
===================================================================
--- code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h 2009-12-09 21:58:26 UTC (rev 6310)
+++ code/branches/presentation2/src/libraries/core/input/KeyBinderManager.h 2009-12-09 22:17:14 UTC (rev 6311)
@@ -99,6 +99,8 @@
//! Bind 'command' to any key pressed after this call (use with care!), but temporarily (no file save)
inline void tkeybind(const std::string& command)
{ this->keybindInternal(command, true); }
+ void unbind(const std::string& binding); //tolua_export
+ void tunbind(const std::string& binding);
inline void registerKeybindCallback(Functor* function) { this->callbackFunction_.reset(function); } // tolua_export
private:
More information about the Orxonox-commit
mailing list