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
RevLine 
[6334]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
[6335]8else
[6334]9    _G[_REQUIREDNAME] = P
10end
11
12P.filename = "KeyBindMenu"
13P.layoutString = "KeyBindMenu.layout"
14
15function P:init()
[6335]16
[6334]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")
[6335]28    table.insert(commandList, "scale 1 rotateRoll")
[6334]29    table.insert(commandList, "scale -1 rotateRoll")
30    table.insert(commandList, "switchCamera")
[6335]31    table.insert(commandList, "openConsole")
[6334]32    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
33    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
34    table.insert(commandList, "mouseLook")
35    table.insert(commandList, "pause")
[6335]36
[6334]37    nameList = {}
38    table.insert(nameList, "Primary Fire")
[6335]39    table.insert(nameList, "Secondary Fire")
[6334]40    table.insert(nameList, "Fire Rocket")
41    table.insert(nameList, "Accelerate")
42    table.insert(nameList, "Break")
[6335]43    table.insert(nameList, "Boost")
[6334]44    table.insert(nameList, "Move Right")
[6335]45    table.insert(nameList, "Move Left")
46    table.insert(nameList, "Move Up")
[6334]47    table.insert(nameList, "Move Down")
[6335]48    table.insert(nameList, "Roll Right")
49    table.insert(nameList, "Roll Left")
50    table.insert(nameList, "Switch Camera")
[6334]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")
[6335]56
[6334]57    linesList = {}
[6335]58
59    lineHeight = 30
[6334]60    commandWidth = 125
[6335]61    buttonWidth = 145
[6334]62    clearWidth = 20
[6335]63    addWidth = 30
64    spaceWidth = 10
[6334]65
66    P.createLines()
[6335]67
[6334]68    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
[6335]69    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
[6334]70end
71
72function P.KeyNameNiceifier(key)
73    local name = string.sub(key, string.find(key, '%.(.*)')+1)
[6335]74    local group = string.sub(key, string.find(key, '(.*)%.'))
[6334]75    group = string.sub(group,1,string.len(group)-1)
[6335]76    if( group == "Keys") then
[6334]77        return "Key " .. string.sub(name, string.find(name, 'Key(.*)')+3)
[6335]78    elseif( group == "MouseButtons") then
[6334]79        return "Mouse " .. name
80    end
[6335]81    return key
[6334]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))
[6335]88    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
[6334]89
[6335]90    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
[6334]91    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
[6335]92    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
[6334]93    command:setText(nameList[k])
94    line:addChildWindow(command)
95    offset = offset + commandWidth + spaceWidth
[6335]96
[6334]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)
[6335]103    offset = offset + addWidth + spaceWidth
[6334]104
105    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
106    for i=0,(numButtons-1) do
[6335]107        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
[6334]108        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
[6335]109        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
[6334]110        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
111        name = P.KeyNameNiceifier(name)
[6335]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
[6334]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)))
[6335]120        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth+spaceWidth)+buttonWidth)+commandWidth+clearWidth+2*spaceWidth), CEGUI.UDim(0.15, 0)))
[6334]121        clear:setText("X")
122        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
123        line:addChildWindow(clear)
124        offset = offset + clearWidth + spaceWidth
[6335]125    end
[6334]126   
[6335]127    debug(0, "OFFSET: " .. offset)
[6334]128
[6335]129    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
[6334]130   
[6335]131    return line
[6334]132end
133
134function P.createLines()
135    local window = winMgr:getWindow("orxonox/KeyBindPane")
136
[6335]137    for k,v in pairs(commandList) do
[6334]138        local line = P.createLine(k)
[6335]139        table.insert(linesList, line)
[6334]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
[6335]148    local match = string.gmatch(name, "%d+")
[6334]149    local commandNr = tonumber(match())
[6335]150    local buttonNr = tonumber(match())
[6334]151
152    local arguments = {}
153    arguments[1] = commandNr
154    arguments[2] = buttonNr
[6335]155    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
156end
[6334]157
[6335]158function P.KeyBindPlus_clicked(e)
[6334]159    local we = CEGUI.toWindowEventArgs(e)
160    local name = we.window:getName()
[6335]161
[6334]162    local match = string.gmatch(name, "%d+")
163    local commandNr = tonumber(match())
[6335]164
[6334]165    local arguments = {}
166    arguments[1] = commandNr
[6335]167    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
168end
169
[6334]170function P.KeyBindClear_clicked(e)
171    local we = CEGUI.toWindowEventArgs(e)
172    local name = we.window:getName()
[6335]173
[6334]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))
[6335]179
[6334]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()
[6335]194    while table.getn(linesList) ~= 0 do
195        if linesList[1] ~= nil then
[6334]196            winMgr:destroyWindow(linesList[1]:getName())
197        end
198        table.remove(linesList, 1)
199    end
200
[6335]201    linesList = {}
202
[6334]203    P.createLines()
204    if(InfoPopup ~= nil) then
205        InfoPopup.close()
[6335]206    end
207end
[6334]208
[6335]209function P.KeyBindBackButton_clicked(e)
210    hideGUI("KeyBindMenu")
211end
[6334]212
[6335]213return P
Note: See TracBrowser for help on using the repository browser.