Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6311 was 6311, checked in by dafrick, 15 years ago

The KeyBindMenu now shows all Keybindings and allows for various manipulations.
For this the bookkeeping in KeyBinder has ben improved.
Also KeyEscape now can't be bound to other commands.

  • Property svn:executable set to *
File size: 7.0 KB
RevLine 
[6311]1-- KeyBindMenu.lua
2
3BasicGUI = require("BasicGUI")
4local P = BasicGUI:new() --inherit everything from the gui package
5if _REQUIREDNAME == nil then
6    KeyBindMenu = P
7else
8    _G[_REQUIREDNAME] = P
9end
10
11P.filename = "KeyBindMenu"
12P.layoutString = "KeyBindMenu.layout"
13
14function 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    linesList = {}
56
57    lineHeight = 35
58    buttonWidth = 170
59    clearWidth = 20
60   
61    local window = winMgr:getWindow("orxonox/KeyBindPane")
62
63    for k,v in pairs(commandList) do
64        local line = P.createLine(k)
65        table.insert(linesList, line)
66        window:addChildWindow(line)
67    end
68   
69    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
70    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
71end
72
73function P.createLine(k)
74    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
75    line:setHeight(CEGUI.UDim(0, lineHeight))
76    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
77   
78    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
79    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(1, 0)))
80    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
81    command:setText(nameList[k])
82    line:addChildWindow(command)
83   
84    local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
85    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(1, 0)))
86    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(0, 0)))
87    plus:setText("+")
88    orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked")
89    line:addChildWindow(plus)
90   
91    numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
92    for i=0,(numButtons-1) do
93        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
94        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.8, 0)))
95        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth))+200+clearWidth), CEGUI.UDim(0.1, 0)))
96        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i))
97        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
98        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
99        line:addChildWindow(button)
100       
101        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
102        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.8, 0)))
103        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth)+buttonWidth)+200+clearWidth), CEGUI.UDim(0.1, 0)))
104        clear:setText("X")
105        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
106        line:addChildWindow(clear)
107    end
108   
109    line:setWidth(CEGUI.UDim(0, 200+numButtons*(buttonWidth+clearWidth)+clearWidth))
110   
111    return line
112end
113
114function P.KeyBindButton_clicked(e)
115    local we = CEGUI.toWindowEventArgs(e)
116    local name = we.window:getName()
117
118    local match = string.gmatch(name, "%d+")
119    local commandNr = tonumber(match())
120    local buttonNr = tonumber(match())
121   
122    local arguments = {}
123    arguments[1] = commandNr
124    arguments[2] = buttonNr
125    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
126end
127
128function P.KeyBindPlus_clicked(e)
129    local we = CEGUI.toWindowEventArgs(e)
130    local name = we.window:getName()
131   
132    local match = string.gmatch(name, "%d+")
133    local commandNr = tonumber(match())
134   
135    local arguments = {}
136    arguments[1] = commandNr
137    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
138end
139
140function P.KeyBindClear_clicked(e)
141    local we = CEGUI.toWindowEventArgs(e)
142    local name = we.window:getName()
143   
144    local match = string.gmatch(name, "%d+")
145    local commandNr = tonumber(match())
146    local buttonNr = tonumber(match())
147   
148    orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
149   
150    P.callback()
151end
152
153function P.keybind(arguments)
154    local commandNr = arguments[1]
155    local buttonNr = arguments[2]
156    if buttonNr ~= nil then
157        orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr))
158    end
159    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
160end
161
162function P.callback()
163    while table.getn(linesList) ~= 0 do
164        if linesList[1] ~= nil then
165            winMgr:destroyWindow(linesList[1]:getName())
166        end
167        table.remove(linesList, 1)
168    end
169   
170    linesList = {}
171
172    window = winMgr:getWindow("orxonox/KeyBindPane")
173    for q,w in pairs(commandList) do
174        local line = P.createLine(q)
175        table.insert(linesList, line)
176        window:addChildWindow(line)
177    end
178   
179    if(InfoPopup ~= nil) then
180        InfoPopup.close()
181    end
182end
183
184function P.KeyBindBackButton_clicked(e)
185    hideGUI("KeyBindMenu")
186end
187
188return P
189
Note: See TracBrowser for help on using the repository browser.