Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6352 was 6352, checked in by dafrick, 14 years ago

Adjusted commandButton size to fit the new commands.
Expanded KeyNameNiceifier to MouseAxes-type keys.

  • Property svn:executable set to *
File size: 8.5 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
[6352]70    commandWidth = 150
[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
[6352]90    elseif( group == "MouseAxes" ) then
91        return "Mouse " .. string.sub(name, string.find(name, '.(.*)')+1) .. " " .. string.sub(name, 1, 1) .. "-Axes"
[6334]92    end
[6335]93    return key
[6334]94end
95
96function P.createLine(k)
97    local offset = 0
98    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
99    line:setHeight(CEGUI.UDim(0, lineHeight))
[6335]100    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
[6334]101
[6335]102    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
[6334]103    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
[6335]104    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
[6334]105    command:setText(nameList[k])
106    line:addChildWindow(command)
107    offset = offset + commandWidth + spaceWidth
[6335]108
[6334]109    local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
110    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
111    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
112    plus:setText("add")
113    orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
114    line:addChildWindow(plus)
[6335]115    offset = offset + addWidth + spaceWidth
[6334]116
117    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
118    for i=0,(numButtons-1) do
[6335]119        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
[6334]120        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
[6335]121        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
[6334]122        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
123        name = P.KeyNameNiceifier(name)
[6335]124        button:setText(name)
125        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
126        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
127        line:addChildWindow(button)
128        offset = offset + buttonWidth
[6334]129
130        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
131        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
[6339]132        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
[6334]133        clear:setText("X")
134        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
135        line:addChildWindow(clear)
136        offset = offset + clearWidth + spaceWidth
[6335]137    end
[6334]138
[6335]139    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
[6334]140   
[6335]141    return line
[6334]142end
143
144function P.createLines()
145    local window = winMgr:getWindow("orxonox/KeyBindPane")
146
[6335]147    for k,v in pairs(commandList) do
[6334]148        local line = P.createLine(k)
[6335]149        table.insert(linesList, line)
[6334]150        window:addChildWindow(line)
151    end
152end
153
154function P.KeyBindButton_clicked(e)
155    local we = CEGUI.toWindowEventArgs(e)
156    local name = we.window:getName()
157
[6335]158    local match = string.gmatch(name, "%d+")
[6334]159    local commandNr = tonumber(match())
[6335]160    local buttonNr = tonumber(match())
[6334]161
162    local arguments = {}
163    arguments[1] = commandNr
164    arguments[2] = buttonNr
[6335]165    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
166end
[6334]167
[6335]168function P.KeyBindPlus_clicked(e)
[6334]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())
[6335]174
[6334]175    local arguments = {}
176    arguments[1] = commandNr
[6335]177    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
178end
179
[6334]180function P.KeyBindClear_clicked(e)
181    local we = CEGUI.toWindowEventArgs(e)
182    local name = we.window:getName()
[6335]183
[6334]184    local match = string.gmatch(name, "%d+")
185    local commandNr = tonumber(match())
186    local buttonNr = tonumber(match())
187 
188    orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
[6335]189
[6334]190    P.callback()
191end
192
193function P.keybind(arguments)
194    local commandNr = arguments[1]
195    local buttonNr = arguments[2]
196    if buttonNr ~= nil then
197        orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
198    end
199
200    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
201end
202
203function P.callback()
[6351]204    local pane = tolua.cast(winMgr:getWindow("orxonox/KeyBindPane"), "CEGUI::ScrollablePane")
205    local position = pane:getVerticalScrollPosition()
[6335]206    while table.getn(linesList) ~= 0 do
207        if linesList[1] ~= nil then
[6334]208            winMgr:destroyWindow(linesList[1]:getName())
209        end
210        table.remove(linesList, 1)
211    end
212
[6335]213    linesList = {}
214
[6334]215    P.createLines()
216    if(InfoPopup ~= nil) then
217        InfoPopup.close()
[6335]218    end
[6351]219    pane:setVerticalScrollPosition( position )
[6335]220end
[6334]221
[6335]222function P.KeyBindBackButton_clicked(e)
223    hideGUI("KeyBindMenu")
224end
[6334]225
[6335]226return P
Note: See TracBrowser for help on using the repository browser.