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 moveRightLeft") |
---|
20 | table.insert(commandList, "scale -1 moveRightLeft") |
---|
21 | table.insert(commandList, "scale 1 moveFrontBack") |
---|
22 | table.insert(commandList, "boost") |
---|
23 | table.insert(commandList, "scale -1 moveFrontBack") |
---|
24 | table.insert(commandList, "scale 1 rotateRoll") |
---|
25 | table.insert(commandList, "scale -1 rotateRoll") |
---|
26 | table.insert(commandList, "scale 1 moveUpDown") |
---|
27 | table.insert(commandList, "scale -1 moveUpDown") |
---|
28 | table.insert(commandList, "openConsole") |
---|
29 | table.insert(commandList, "OverlayGroup toggleVisibility Debug") |
---|
30 | table.insert(commandList, "OverlayGroup toggleVisibility Stats") |
---|
31 | table.insert(commandList, "mouseLook") |
---|
32 | table.insert(commandList, "pause") |
---|
33 | |
---|
34 | nameList = {} |
---|
35 | table.insert(nameList, "Primary Fire") |
---|
36 | table.insert(nameList, "Secondary Fire") |
---|
37 | table.insert(nameList, "Fire Rocket") |
---|
38 | table.insert(nameList, "Steer Right") |
---|
39 | table.insert(nameList, "Steer Left") |
---|
40 | table.insert(nameList, "Give Thrust") |
---|
41 | table.insert(nameList, "Boost") |
---|
42 | table.insert(nameList, "Hit Breaks") |
---|
43 | table.insert(nameList, "Roll Right") |
---|
44 | table.insert(nameList, "Roll Left") |
---|
45 | table.insert(nameList, "Up") |
---|
46 | table.insert(nameList, "Down") |
---|
47 | table.insert(nameList, "Open Console") |
---|
48 | table.insert(nameList, "Show Debug") |
---|
49 | table.insert(nameList, "Show Stats") |
---|
50 | table.insert(nameList, "mouseLook") |
---|
51 | table.insert(nameList, "Pause") |
---|
52 | |
---|
53 | local lineHeight = 30 |
---|
54 | |
---|
55 | local window = winMgr:getWindow("orxonox/KeyBindPane") |
---|
56 | |
---|
57 | for k,v in pairs(commandList) do |
---|
58 | local button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button") |
---|
59 | local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") |
---|
60 | local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) |
---|
61 | |
---|
62 | line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight))) |
---|
63 | button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0))) |
---|
64 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(1, 0))) |
---|
65 | |
---|
66 | button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0),CEGUI.UDim(0, 0))) |
---|
67 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0))) |
---|
68 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1)))) |
---|
69 | |
---|
70 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) |
---|
71 | command:setText(nameList[k]) |
---|
72 | |
---|
73 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") |
---|
74 | --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") |
---|
75 | |
---|
76 | line:addChildWindow(command) |
---|
77 | line:addChildWindow(button) |
---|
78 | window:addChildWindow(line) |
---|
79 | end |
---|
80 | end |
---|
81 | |
---|
82 | function P.KeyBindButton_clicked(e) |
---|
83 | local we = CEGUI.toWindowEventArgs(e) |
---|
84 | local name = we.window:getName() |
---|
85 | commandNr = tonumber(string.match(name, "%d+")) |
---|
86 | |
---|
87 | openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) |
---|
88 | |
---|
89 | end |
---|
90 | |
---|
91 | function P.keybind() |
---|
92 | orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr]) |
---|
93 | end |
---|
94 | |
---|
95 | function P.KeyBindBackButton_clicked(e) |
---|
96 | hideGUI("KeyBindMenu") |
---|
97 | debug("event: back") |
---|
98 | end |
---|
99 | |
---|
100 | return P |
---|
101 | |
---|