Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6346 was 6346, checked in by scheusso, 14 years ago

added additional keybinds (which i find usefull)

  • Property svn:executable set to *
File size: 8.1 KB
Line 
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
8else
9    _G[_REQUIREDNAME] = P
10end
11
12P.filename = "KeyBindMenu"
13P.layoutString = "KeyBindMenu.layout"
14
15function P:init()
16
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")
28    table.insert(commandList, "scale -1 rotateRoll")
29    table.insert(commandList, "scale 1 rotateRoll")
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")
35    table.insert(commandList, "switchCamera")
36    table.insert(commandList, "openConsole")
37    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
38    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
39    table.insert(commandList, "mouseLook")
40    table.insert(commandList, "pause")
41
42    nameList = {}
43    table.insert(nameList, "Primary Fire")
44    table.insert(nameList, "Secondary Fire")
45    table.insert(nameList, "Fire Rocket")
46    table.insert(nameList, "Accelerate")
47    table.insert(nameList, "Break")
48    table.insert(nameList, "Boost")
49    table.insert(nameList, "Move Right")
50    table.insert(nameList, "Move Left")
51    table.insert(nameList, "Move Up")
52    table.insert(nameList, "Move Down")
53    table.insert(nameList, "Roll Right")
54    table.insert(nameList, "Roll Left")
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")
60    table.insert(nameList, "Switch Camera")
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")
66
67    linesList = {}
68
69    lineHeight = 30
70    commandWidth = 125
71    buttonWidth = 145
72    clearWidth = 20
73    addWidth = 30
74    spaceWidth = 10
75
76    P.createLines()
77
78    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
79    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
80end
81
82function P.KeyNameNiceifier(key)
83    local name = string.sub(key, string.find(key, '%.(.*)')+1)
84    local group = string.sub(key, string.find(key, '(.*)%.'))
85    group = string.sub(group,1,string.len(group)-1)
86    if( group == "Keys") then
87        return "Key " .. string.sub(name, string.find(name, 'Key(.*)')+3)
88    elseif( group == "MouseButtons") then
89        return "Mouse " .. name
90    end
91    return key
92end
93
94function P.createLine(k)
95    local offset = 0
96    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
97    line:setHeight(CEGUI.UDim(0, lineHeight))
98    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
99
100    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
101    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
102    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
103    command:setText(nameList[k])
104    line:addChildWindow(command)
105    offset = offset + commandWidth + spaceWidth
106
107    local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
108    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
109    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
110    plus:setText("add")
111    orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
112    line:addChildWindow(plus)
113    offset = offset + addWidth + spaceWidth
114
115    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
116    for i=0,(numButtons-1) do
117        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
118        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
119        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
120        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
121        name = P.KeyNameNiceifier(name)
122        button:setText(name)
123        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
124        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
125        line:addChildWindow(button)
126        offset = offset + buttonWidth
127
128        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
129        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
130        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
131        clear:setText("X")
132        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
133        line:addChildWindow(clear)
134        offset = offset + clearWidth + spaceWidth
135    end
136
137    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
138   
139    return line
140end
141
142function P.createLines()
143    local window = winMgr:getWindow("orxonox/KeyBindPane")
144
145    for k,v in pairs(commandList) do
146        local line = P.createLine(k)
147        table.insert(linesList, line)
148        window:addChildWindow(line)
149    end
150end
151
152function P.KeyBindButton_clicked(e)
153    local we = CEGUI.toWindowEventArgs(e)
154    local name = we.window:getName()
155
156    local match = string.gmatch(name, "%d+")
157    local commandNr = tonumber(match())
158    local buttonNr = tonumber(match())
159
160    local arguments = {}
161    arguments[1] = commandNr
162    arguments[2] = buttonNr
163    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
164end
165
166function P.KeyBindPlus_clicked(e)
167    local we = CEGUI.toWindowEventArgs(e)
168    local name = we.window:getName()
169
170    local match = string.gmatch(name, "%d+")
171    local commandNr = tonumber(match())
172
173    local arguments = {}
174    arguments[1] = commandNr
175    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
176end
177
178function P.KeyBindClear_clicked(e)
179    local we = CEGUI.toWindowEventArgs(e)
180    local name = we.window:getName()
181
182    local match = string.gmatch(name, "%d+")
183    local commandNr = tonumber(match())
184    local buttonNr = tonumber(match())
185 
186    orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
187
188    P.callback()
189end
190
191function P.keybind(arguments)
192    local commandNr = arguments[1]
193    local buttonNr = arguments[2]
194    if buttonNr ~= nil then
195        orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
196    end
197
198    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
199end
200
201function P.callback()
202    while table.getn(linesList) ~= 0 do
203        if linesList[1] ~= nil then
204            winMgr:destroyWindow(linesList[1]:getName())
205        end
206        table.remove(linesList, 1)
207    end
208
209    linesList = {}
210
211    P.createLines()
212    if(InfoPopup ~= nil) then
213        InfoPopup.close()
214    end
215end
216
217function P.KeyBindBackButton_clicked(e)
218    hideGUI("KeyBindMenu")
219end
220
221return P
Note: See TracBrowser for help on using the repository browser.