[6292] | 1 | -- KeyBindMenu.lua |
---|
| 2 | |
---|
| 3 | BasicGUI = require("BasicGUI") |
---|
| 4 | local P = BasicGUI:new() --inherit everything from the gui package |
---|
| 5 | if _REQUIREDNAME == nil then |
---|
| 6 | KeyBindMenu = P |
---|
| 7 | else |
---|
| 8 | _G[_REQUIREDNAME] = P |
---|
| 9 | end |
---|
| 10 | |
---|
| 11 | P.filename = "KeyBindMenu" |
---|
| 12 | P.layoutString = "KeyBindMenu.layout" |
---|
| 13 | |
---|
| 14 | function P:init() |
---|
| 15 | commandList = {} |
---|
| 16 | table.insert(commandList, "fire 0") |
---|
| 17 | table.insert(commandList, "fire 1 | unfire") |
---|
| 18 | table.insert(commandList, "onpress fire 2") |
---|
| 19 | table.insert(commandList, "scale 1 moveFrontBack") |
---|
| 20 | table.insert(commandList, "scale -1 moveFrontBack") |
---|
| 21 | table.insert(commandList, "boost") |
---|
| 22 | table.insert(commandList, "scale 1 moveRightLeft") |
---|
| 23 | table.insert(commandList, "scale -1 moveRightLeft") |
---|
| 24 | table.insert(commandList, "scale 1 moveUpDown") |
---|
| 25 | table.insert(commandList, "scale -1 moveUpDown") |
---|
| 26 | table.insert(commandList, "scale 1 rotateRoll") |
---|
| 27 | table.insert(commandList, "scale -1 rotateRoll") |
---|
| 28 | table.insert(commandList, "switchCamera") |
---|
| 29 | table.insert(commandList, "openConsole") |
---|
| 30 | table.insert(commandList, "OverlayGroup toggleVisibility Debug") |
---|
| 31 | table.insert(commandList, "OverlayGroup toggleVisibility Stats") |
---|
| 32 | table.insert(commandList, "mouseLook") |
---|
| 33 | table.insert(commandList, "pause") |
---|
| 34 | |
---|
| 35 | nameList = {} |
---|
| 36 | table.insert(nameList, "Primary Fire") |
---|
| 37 | table.insert(nameList, "Secondary Fire") |
---|
| 38 | table.insert(nameList, "Fire Rocket") |
---|
| 39 | table.insert(nameList, "Accelerate") |
---|
| 40 | table.insert(nameList, "Break") |
---|
| 41 | table.insert(nameList, "Boost") |
---|
| 42 | table.insert(nameList, "Move Right") |
---|
| 43 | table.insert(nameList, "Move Left") |
---|
| 44 | table.insert(nameList, "Move Up") |
---|
| 45 | table.insert(nameList, "Move Down") |
---|
| 46 | table.insert(nameList, "Roll Right") |
---|
| 47 | table.insert(nameList, "Roll Left") |
---|
| 48 | table.insert(nameList, "Switch Camera") |
---|
| 49 | table.insert(nameList, "Open Console") |
---|
| 50 | table.insert(nameList, "Show Debug") |
---|
| 51 | table.insert(nameList, "Show Stats") |
---|
| 52 | table.insert(nameList, "Look Around") |
---|
| 53 | table.insert(nameList, "Pause") |
---|
| 54 | |
---|
| 55 | local lineHeight = 30 |
---|
| 56 | |
---|
| 57 | local window = winMgr:getWindow("orxonox/KeyBindPane") |
---|
| 58 | |
---|
| 59 | for k,v in pairs(commandList) do |
---|
| 60 | local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) |
---|
| 61 | local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") |
---|
| 62 | local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button") |
---|
| 63 | local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear") |
---|
| 64 | local button2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button2") |
---|
| 65 | local clear2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear2") |
---|
| 66 | local add = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Add") |
---|
| 67 | |
---|
| 68 | line:setSize(CEGUI.UVector2(CEGUI.UDim(1, -13), CEGUI.UDim(0, lineHeight))) |
---|
| 69 | command:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0))) |
---|
| 70 | button:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0))) |
---|
| 71 | clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) |
---|
| 72 | button2:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0))) |
---|
| 73 | clear2:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) |
---|
| 74 | add:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0))) |
---|
| 75 | |
---|
| 76 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1)))) |
---|
| 77 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) |
---|
| 78 | button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.2, 0))) |
---|
| 79 | clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.2, 0))) |
---|
| 80 | button2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(0.2, 0))) |
---|
| 81 | clear2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.85, 0), CEGUI.UDim(0.2, 0))) |
---|
| 82 | add:setPosition(CEGUI.UVector2(CEGUI.UDim(0.925, 0), CEGUI.UDim(0.2, 0))) |
---|
| 83 | |
---|
| 84 | command:setText(nameList[k]) |
---|
| 85 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) |
---|
| 86 | clear:setText("X") |
---|
| 87 | button2:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) |
---|
| 88 | clear2:setText("X") |
---|
| 89 | add:setText("+") |
---|
| 90 | |
---|
| 91 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") |
---|
| 92 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked") |
---|
| 93 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(add, "Clicked", P.filename .. ".KeyBindAdd_clicked") |
---|
| 94 | --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") |
---|
| 95 | |
---|
| 96 | line:addChildWindow(command) |
---|
| 97 | line:addChildWindow(button) |
---|
| 98 | line:addChildWindow(clear) |
---|
| 99 | line:addChildWindow(button2) |
---|
| 100 | line:addChildWindow(clear2) |
---|
| 101 | line:addChildWindow(add) |
---|
| 102 | window:addChildWindow(line) |
---|
| 103 | end |
---|
| 104 | end |
---|
| 105 | |
---|
| 106 | function P.KeyBindButton_clicked(e) |
---|
| 107 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 108 | local name = we.window:getName() |
---|
| 109 | buttonNr = tonumber(string.match(name, "%d+")) |
---|
| 110 | openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) |
---|
| 111 | end |
---|
| 112 | |
---|
| 113 | function P.KeyBindClear_clicked(e) |
---|
| 114 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 115 | local name = we.window:getName() |
---|
| 116 | clearNr = tonumber(string.match(name, "%d+")) |
---|
| 117 | end |
---|
| 118 | |
---|
| 119 | function P.KeyBindAdd_clicked(e) |
---|
| 120 | |
---|
| 121 | end |
---|
| 122 | |
---|
| 123 | function P.keybind() |
---|
| 124 | local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")") |
---|
| 125 | orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) |
---|
| 126 | orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr]) |
---|
| 127 | end |
---|
| 128 | |
---|
| 129 | function P.callback(number) |
---|
| 130 | orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil) |
---|
| 131 | local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button") |
---|
| 132 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number])) |
---|
| 133 | |
---|
| 134 | InfoPopup.close() |
---|
| 135 | end |
---|
| 136 | |
---|
| 137 | function P.KeyBindBackButton_clicked(e) |
---|
| 138 | hideGUI("KeyBindMenu") |
---|
| 139 | end |
---|
| 140 | |
---|
| 141 | return P |
---|
| 142 | |
---|