Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/KeyBindMenu.lua @ 8649

Last change on this file since 8649 was 8232, checked in by dafrick, 14 years ago

Extending and reorganizing ScreenshotManager and SkyboxGenerator.
The SkyboxGenerator now takes HD screenshots, thus the size of the faces generated by the SkyboxGenerator can now be specified freely (through a config value).

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