Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua @ 6351

Last change on this file since 6351 was 6351, checked in by scheusso, 15 years ago

keybinding now possible without scrolling again and again

  • Property svn:executable set to *
File size: 8.3 KB
RevLine 
[6334]1-- KeyBindMenu.lua
2
3BasicGUI = require("BasicGUI")
4local P = BasicGUI:new() --inherit everything from the gui package
5
6if _REQUIREDNAME == nil then
7    KeyBindMenu = P
[6335]8else
[6334]9    _G[_REQUIREDNAME] = P
10end
11
12P.filename = "KeyBindMenu"
13P.layoutString = "KeyBindMenu.layout"
14
15function P:init()
[6335]16
[6334]17    commandList = {}
18    table.insert(commandList, "fire 0")
19    table.insert(commandList, "fire 1 | unfire")
20    table.insert(commandList, "onpress fire 2")
21    table.insert(commandList, "scale 1 moveFrontBack")
22    table.insert(commandList, "scale -1 moveFrontBack")
23    table.insert(commandList, "boost")
24    table.insert(commandList, "scale 1 moveRightLeft")
25    table.insert(commandList, "scale -1 moveRightLeft")
26    table.insert(commandList, "scale 1 moveUpDown")
27    table.insert(commandList, "scale -1 moveUpDown")
[6346]28    table.insert(commandList, "scale -1 rotateRoll")
[6335]29    table.insert(commandList, "scale 1 rotateRoll")
[6346]30    table.insert(commandList, "scale 1 rotateYaw")
31    table.insert(commandList, "scale -1 rotateYaw")
32    table.insert(commandList, "scale 1 rotatePitch")
33    table.insert(commandList, "scale -1 rotatePitch")
34    table.insert(commandList, "NewHumanController changeMode")
[6334]35    table.insert(commandList, "switchCamera")
[6335]36    table.insert(commandList, "openConsole")
[6334]37    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
38    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
39    table.insert(commandList, "mouseLook")
40    table.insert(commandList, "pause")
[6335]41
[6334]42    nameList = {}
43    table.insert(nameList, "Primary Fire")
[6335]44    table.insert(nameList, "Secondary Fire")
[6334]45    table.insert(nameList, "Fire Rocket")
46    table.insert(nameList, "Accelerate")
47    table.insert(nameList, "Break")
[6335]48    table.insert(nameList, "Boost")
[6334]49    table.insert(nameList, "Move Right")
[6335]50    table.insert(nameList, "Move Left")
51    table.insert(nameList, "Move Up")
[6334]52    table.insert(nameList, "Move Down")
[6335]53    table.insert(nameList, "Roll Right")
54    table.insert(nameList, "Roll Left")
[6346]55    table.insert(nameList, "Yaw Left")
56    table.insert(nameList, "Yaw Right")
57    table.insert(nameList, "Pitch Up")
58    table.insert(nameList, "Pitch Down")
59    table.insert(nameList, "Switch Input Mode")
[6335]60    table.insert(nameList, "Switch Camera")
[6334]61    table.insert(nameList, "Open Console")
62    table.insert(nameList, "Show Debug")
63    table.insert(nameList, "Show Stats")
64    table.insert(nameList, "Look Around")
65    table.insert(nameList, "Pause")
[6335]66
[6334]67    linesList = {}
[6335]68
69    lineHeight = 30
[6334]70    commandWidth = 125
[6335]71    buttonWidth = 145
[6334]72    clearWidth = 20
[6335]73    addWidth = 30
74    spaceWidth = 10
[6334]75
76    P.createLines()
[6335]77
[6334]78    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
[6335]79    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
[6334]80end
81
82function P.KeyNameNiceifier(key)
83    local name = string.sub(key, string.find(key, '%.(.*)')+1)
[6335]84    local group = string.sub(key, string.find(key, '(.*)%.'))
[6334]85    group = string.sub(group,1,string.len(group)-1)
[6335]86    if( group == "Keys") then
[6334]87        return "Key " .. string.sub(name, string.find(name, 'Key(.*)')+3)
[6335]88    elseif( group == "MouseButtons") then
[6334]89        return "Mouse " .. name
90    end
[6335]91    return key
[6334]92end
93
94function P.createLine(k)
95    local offset = 0
96    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
97    line:setHeight(CEGUI.UDim(0, lineHeight))
[6335]98    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
[6334]99
[6335]100    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
[6334]101    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
[6335]102    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
[6334]103    command:setText(nameList[k])
104    line:addChildWindow(command)
105    offset = offset + commandWidth + spaceWidth
[6335]106
[6334]107    local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
108    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
109    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
110    plus:setText("add")
111    orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
112    line:addChildWindow(plus)
[6335]113    offset = offset + addWidth + spaceWidth
[6334]114
115    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
116    for i=0,(numButtons-1) do
[6335]117        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
[6334]118        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
[6335]119        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
[6334]120        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
121        name = P.KeyNameNiceifier(name)
[6335]122        button:setText(name)
123        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
124        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
125        line:addChildWindow(button)
126        offset = offset + buttonWidth
[6334]127
128        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
129        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
[6339]130        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
[6334]131        clear:setText("X")
132        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
133        line:addChildWindow(clear)
134        offset = offset + clearWidth + spaceWidth
[6335]135    end
[6334]136
[6335]137    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
[6334]138   
[6335]139    return line
[6334]140end
141
142function P.createLines()
143    local window = winMgr:getWindow("orxonox/KeyBindPane")
144
[6335]145    for k,v in pairs(commandList) do
[6334]146        local line = P.createLine(k)
[6335]147        table.insert(linesList, line)
[6334]148        window:addChildWindow(line)
149    end
150end
151
152function P.KeyBindButton_clicked(e)
153    local we = CEGUI.toWindowEventArgs(e)
154    local name = we.window:getName()
155
[6335]156    local match = string.gmatch(name, "%d+")
[6334]157    local commandNr = tonumber(match())
[6335]158    local buttonNr = tonumber(match())
[6334]159
160    local arguments = {}
161    arguments[1] = commandNr
162    arguments[2] = buttonNr
[6335]163    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
164end
[6334]165
[6335]166function P.KeyBindPlus_clicked(e)
[6334]167    local we = CEGUI.toWindowEventArgs(e)
168    local name = we.window:getName()
[6335]169
[6334]170    local match = string.gmatch(name, "%d+")
171    local commandNr = tonumber(match())
[6335]172
[6334]173    local arguments = {}
174    arguments[1] = commandNr
[6335]175    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
176end
177
[6334]178function P.KeyBindClear_clicked(e)
179    local we = CEGUI.toWindowEventArgs(e)
180    local name = we.window:getName()
[6335]181
[6334]182    local match = string.gmatch(name, "%d+")
183    local commandNr = tonumber(match())
184    local buttonNr = tonumber(match())
185 
186    orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
[6335]187
[6334]188    P.callback()
189end
190
191function P.keybind(arguments)
192    local commandNr = arguments[1]
193    local buttonNr = arguments[2]
194    if buttonNr ~= nil then
195        orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
196    end
197
198    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
199end
200
201function P.callback()
[6351]202    local pane = tolua.cast(winMgr:getWindow("orxonox/KeyBindPane"), "CEGUI::ScrollablePane")
203    local position = pane:getVerticalScrollPosition()
[6335]204    while table.getn(linesList) ~= 0 do
205        if linesList[1] ~= nil then
[6334]206            winMgr:destroyWindow(linesList[1]:getName())
207        end
208        table.remove(linesList, 1)
209    end
210
[6335]211    linesList = {}
212
[6334]213    P.createLines()
214    if(InfoPopup ~= nil) then
215        InfoPopup.close()
[6335]216    end
[6351]217    pane:setVerticalScrollPosition( position )
[6335]218end
[6334]219
[6335]220function P.KeyBindBackButton_clicked(e)
221    hideGUI("KeyBindMenu")
222end
[6334]223
[6335]224return P
Note: See TracBrowser for help on using the repository browser.