[6266] | 1 | -- KeyBindMenu.lua |
---|
[6224] | 2 | |
---|
| 3 | BasicGUI = require("BasicGUI") |
---|
| 4 | local P = BasicGUI:new() --inherit everything from the gui package |
---|
| 5 | if _REQUIREDNAME == nil then |
---|
[6266] | 6 | KeyBindMenu = P |
---|
[6224] | 7 | else |
---|
| 8 | _G[_REQUIREDNAME] = P |
---|
| 9 | end |
---|
| 10 | |
---|
[6266] | 11 | P.filename = "KeyBindMenu" |
---|
| 12 | P.layoutString = "KeyBindMenu.layout" |
---|
[6224] | 13 | |
---|
[6266] | 14 | function P:init() |
---|
| 15 | commandList = {} |
---|
| 16 | table.insert(commandList, "fire 0") |
---|
| 17 | table.insert(commandList, "fire 1") |
---|
| 18 | table.insert(commandList, "fire 2") |
---|
| 19 | |
---|
| 20 | local lineHeight = 30 |
---|
| 21 | |
---|
| 22 | local window = winMgr:getWindow("orxonox/KeyBindPane") |
---|
| 23 | |
---|
| 24 | for k,v in pairs(commandList) do |
---|
| 25 | local button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button") |
---|
| 26 | local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") |
---|
| 27 | local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) |
---|
| 28 | |
---|
| 29 | line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight))) |
---|
| 30 | button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0))) |
---|
| 31 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(1, 0))) |
---|
| 32 | |
---|
| 33 | button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0),CEGUI.UDim(0, 0))) |
---|
| 34 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0))) |
---|
| 35 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1)))) |
---|
| 36 | |
---|
| 37 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) |
---|
| 38 | command:setText(v) |
---|
| 39 | |
---|
| 40 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") |
---|
| 41 | --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") |
---|
| 42 | |
---|
| 43 | line:addChildWindow(command) |
---|
| 44 | line:addChildWindow(button) |
---|
| 45 | window:addChildWindow(line) |
---|
| 46 | end |
---|
| 47 | end |
---|
| 48 | |
---|
| 49 | function P.KeyBindButton_clicked(e) |
---|
| 50 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 51 | local name = we.window:getName() |
---|
| 52 | commandNr = tonumber(string.match(name, "%d+")) |
---|
| 53 | |
---|
| 54 | openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) |
---|
| 55 | |
---|
| 56 | end |
---|
| 57 | |
---|
| 58 | function P.keybind() |
---|
| 59 | orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr]) |
---|
| 60 | end |
---|
| 61 | |
---|
[6224] | 62 | function P.KeyBindBackButton_clicked(e) |
---|
[6266] | 63 | hideGUI("KeyBindMenu") |
---|
[6224] | 64 | debug("event: back") |
---|
| 65 | end |
---|
| 66 | |
---|
| 67 | return P |
---|
| 68 | |
---|