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 line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) |
---|
59 | local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") |
---|
60 | local button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button") |
---|
61 | local clear = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Clear") |
---|
62 | |
---|
63 | line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight))) |
---|
64 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0.55, 0), CEGUI.UDim(1, 0))) |
---|
65 | button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0))) |
---|
66 | clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0),CEGUI.UDim(1,0))) |
---|
67 | |
---|
68 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1)))) |
---|
69 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0))) |
---|
70 | button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.55, 0),CEGUI.UDim(0, 0))) |
---|
71 | clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.95, 0),CEGUI.UDim(0, 0))) |
---|
72 | |
---|
73 | command:setText(nameList[k]) |
---|
74 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v)) |
---|
75 | clear:setText("X") |
---|
76 | |
---|
77 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") |
---|
78 | orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked") |
---|
79 | --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") |
---|
80 | |
---|
81 | line:addChildWindow(command) |
---|
82 | line:addChildWindow(button) |
---|
83 | line:addChildWindow(clear) |
---|
84 | window:addChildWindow(line) |
---|
85 | end |
---|
86 | end |
---|
87 | |
---|
88 | function P.KeyBindButton_clicked(e) |
---|
89 | local we = CEGUI.toWindowEventArgs(e) |
---|
90 | local name = we.window:getName() |
---|
91 | buttonNr = tonumber(string.match(name, "%d+")) |
---|
92 | |
---|
93 | openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind) |
---|
94 | end |
---|
95 | |
---|
96 | function P.KeyBindClear_clicked(e) |
---|
97 | local we = CEGUI.toWindowEventArgs(e) |
---|
98 | local name = we.window:getName() |
---|
99 | clearNr = tonumber(string.match(name, "%d+")) |
---|
100 | |
---|
101 | |
---|
102 | end |
---|
103 | |
---|
104 | function P.keybind() |
---|
105 | local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")") |
---|
106 | orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) |
---|
107 | orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr]) |
---|
108 | end |
---|
109 | |
---|
110 | function P.callback(number) |
---|
111 | orxonox.KeyBinderManager:getInstance():registerKeybindCallback(0) |
---|
112 | local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button") |
---|
113 | button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number])) |
---|
114 | |
---|
115 | InfoPopup.close() |
---|
116 | end |
---|
117 | |
---|
118 | function P.KeyBindBackButton_clicked(e) |
---|
119 | hideGUI("KeyBindMenu") |
---|
120 | debug("event: back") |
---|
121 | end |
---|
122 | |
---|
123 | return P |
---|
124 | |
---|