Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/ppspickups4/data/gui/scripts/KeyBindMenu.lua @ 7060

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

Loads of changes.
1) PickupInventory should now be working even for extreme cases.
2) Added support for inactive Spawnpoints in Gametype.
3) Made Pickupable rewardble. meaning from now on any Pickupable can be given as a reward for completing Quests.
4) Added some keybinds to KeybindMenu, such as PickupInventory, QuestGUI and Chat.

  • Property svn:eol-style set to native
File size: 9.6 KB
Line 
1-- KeyBindMenu.lua
2
3local P = createMenuSheet("KeyBindMenu")
4P.loadAlong = { "InfoPopup" }
5
6function P.onLoad()
7
8    commandList = {}
9    table.insert(commandList, "fire 0")
10    table.insert(commandList, "fire 1 | unfire")
11    table.insert(commandList, "onpress fire 2")
12    table.insert(commandList, "scale 1 moveFrontBack")
13    table.insert(commandList, "scale -1 moveFrontBack")
14    table.insert(commandList, "boost")
15    table.insert(commandList, "scale 1 moveRightLeft")
16    table.insert(commandList, "scale -1 moveRightLeft")
17    table.insert(commandList, "scale 1 moveUpDown")
18    table.insert(commandList, "scale -1 moveUpDown")
19    table.insert(commandList, "scale -1 rotateRoll")
20    table.insert(commandList, "scale 1 rotateRoll")
21    table.insert(commandList, "scale 1 rotateYaw")
22    table.insert(commandList, "scale -1 rotateYaw")
23    table.insert(commandList, "scale 1 rotatePitch")
24    table.insert(commandList, "scale -1 rotatePitch")
25    table.insert(commandList, "NewHumanController changeMode")
26    table.insert(commandList, "switchCamera")
27    table.insert(commandList, "openConsole")
28    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
29    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
30    table.insert(commandList, "OrxonoxOverlay toggleVisibility QuestGUI")
31    table.insert(commandList, "OrxonoxOverlay toggleVisibility PickupInventory")
32    table.insert(commandList, "startchat")
33    table.insert(commandList, "startchat_small")
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, "Yaw Left")
51    table.insert(nameList, "Yaw Right")
52    table.insert(nameList, "Pitch Up")
53    table.insert(nameList, "Pitch Down")
54    table.insert(nameList, "Switch Input Mode")
55    table.insert(nameList, "Switch Camera")
56    table.insert(nameList, "Open Console")
57    table.insert(nameList, "Show Debug")
58    table.insert(nameList, "Show Stats")
59    table.insert(nameList, "Show Quests")
60    table.insert(nameList, "Show Pickups")
61    table.insert(nameList, "Show Chat")
62    table.insert(nameList, "Show small Chat")
63    table.insert(nameList, "Look Around")
64    table.insert(nameList, "Pause")
65
66    linesList = {}
67
68    --Calculate design parameters:
69    sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/SampleWindow")
70    sampleWindow:setText("SampleText")
71
72    local size = getMinTextSize(sampleWindow)
73    lineHeight = size[1]
74
75    commandWidth = 0
76    for k,v in pairs(commandList) do
77        sampleWindow:setText(nameList[k])
78        size = getMinTextSize(sampleWindow)
79        if size[2] > commandWidth then
80            commandWidth = size[2]
81        end
82    end
83
84    sampleWindow:setText("add")
85    size = getMinTextSize(sampleWindow)
86    addWidth = size[2]
87
88    sampleWindow:setText("X")
89    size = getMinTextSize(sampleWindow)
90    clearWidth = size[2]
91
92    spaceWidth = math.floor(1/14*commandWidth)
93
94    buttonWidth = 145
95
96    P.createLines()
97
98    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
99    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
100end
101
102function P.KeyNameNiceifier(key)
103    local name = string.sub(key, string.find(key, '%.(.*)')+1)
104    local group = string.sub(key, string.find(key, '(.*)%.'))
105    group = string.sub(group,1,string.len(group)-1)
106    if( group == "Keys") then
107        return "Key " .. string.sub(name, string.find(name, 'Key(.*)')+3)
108    elseif( group == "MouseButtons") then
109        return "Mouse " .. name
110    elseif( string.find(group, "JoyStickButtons") ~= nil ) then
111        return "Joystick " .. name
112    elseif( string.find(group, "JoyStickAxes") ~= nil ) then
113        return "Joystick Axis" .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
114    elseif( group == "MouseAxes" ) then
115        return "Mouse " .. string.sub(name, string.find(name, '.(.*)')+1) .. " " .. string.sub(name, 1, 1) .. "-Axis"
116    end
117    return key
118end
119
120function P.createLine(k)
121    local offset = 0
122    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
123    line:setHeight(CEGUI.UDim(0, lineHeight))
124    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
125
126    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
127    command:setText(nameList[k])
128    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
129    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
130    line:addChildWindow(command)
131    offset = offset + commandWidth + spaceWidth
132
133    local plus = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
134    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
135    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
136    plus:setText("add")
137    orxonox.GUIManager:subscribeEventHelper(plus, "Clicked", P.name .. ".KeyBindPlus_clicked")
138    line:addChildWindow(plus)
139    offset = offset + addWidth + spaceWidth
140
141    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
142    for i=0,(numButtons-1) do
143        local button = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
144        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
145        name = P.KeyNameNiceifier(name)
146        button:setText(name)
147        sampleWindow:setText(name)
148        local size = getMinTextSize(sampleWindow)
149        local buttonWidth = size[2]
150        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
151        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
152        orxonox.GUIManager:subscribeEventHelper(button, "Clicked", P.name .. ".KeyBindButton_clicked")
153        --button:subscribeScriptedEvent("EventClicked", P.name .. ".KeyBindButton_clicked")
154        line:addChildWindow(button)
155        offset = offset + buttonWidth
156
157        local clear = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
158        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
159        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
160        clear:setText("X")
161        orxonox.GUIManager:subscribeEventHelper(clear, "Clicked", P.name .. ".KeyBindClear_clicked")
162        line:addChildWindow(clear)
163        offset = offset + clearWidth + spaceWidth
164    end
165
166    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
167
168    return line
169end
170
171function P.createLines()
172    local window = winMgr:getWindow("orxonox/KeyBindPane")
173
174    for k,v in pairs(commandList) do
175        local line = P.createLine(k)
176        table.insert(linesList, line)
177        window:addChildWindow(line)
178    end
179
180    pane = tolua.cast(window, "CEGUI::ScrollablePane")
181    pane:setVerticalStepSize(getScrollingStepSize(window))
182end
183
184function P.KeyBindButton_clicked(e)
185    local we = CEGUI.toWindowEventArgs(e)
186    local name = we.window:getName()
187
188    local match = string.gmatch(name, "%d+")
189    local commandNr = tonumber(match())
190    local buttonNr = tonumber(match())
191
192    local arguments = {}
193    arguments[1] = commandNr
194    arguments[2] = buttonNr
195    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
196end
197
198function P.KeyBindPlus_clicked(e)
199    local we = CEGUI.toWindowEventArgs(e)
200    local name = we.window:getName()
201
202    local match = string.gmatch(name, "%d+")
203    local commandNr = tonumber(match())
204
205    local arguments = {}
206    arguments[1] = commandNr
207    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
208end
209
210function P.KeyBindClear_clicked(e)
211    local we = CEGUI.toWindowEventArgs(e)
212    local name = we.window:getName()
213
214    local match = string.gmatch(name, "%d+")
215    local commandNr = tonumber(match())
216    local buttonNr = tonumber(match())
217
218    local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
219    orxonox.KeyBinderManager:getInstance():unbind(str)
220
221    P.callback()
222end
223
224function P.keybind(arguments)
225    local commandNr = arguments[1]
226    local buttonNr = arguments[2]
227    if buttonNr ~= nil then
228        local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
229        orxonox.KeyBinderManager:getInstance():unbind(str)
230    end
231
232    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
233end
234
235function P.callback()
236    local pane = tolua.cast(winMgr:getWindow("orxonox/KeyBindPane"), "CEGUI::ScrollablePane")
237    local position = pane:getVerticalScrollPosition()
238    while table.getn(linesList) ~= 0 do
239        if linesList[1] ~= nil then
240            winMgr:destroyWindow(linesList[1]:getName())
241        end
242        table.remove(linesList, 1)
243    end
244
245    linesList = {}
246
247    P.createLines()
248    if(InfoPopup ~= nil) then
249        InfoPopup.close()
250    end
251    pane:setVerticalScrollPosition( position )
252end
253
254function P.KeyBindBackButton_clicked(e)
255    hideMenuSheet("KeyBindMenu")
256end
257
258return P
Note: See TracBrowser for help on using the repository browser.