Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Removed empty lines.
Adjusted size of boxes in KeyBindMenu so that the text is displayed properly.
Regarding the bug: Found the reason why this happens. The problem is, that apparently CEGUI doesn't allow for windows bigger than the displayed screen, which means, that any window that is bigger than the scrren size isn'f fully displayed. I have no idea how to circumvent this, but I'll keep looking.

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