Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6336 was 6336, checked in by dafrick, 15 years ago

Forgot to remove debug output…

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