Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Some enhancements in KeyBindMenu.lua and InfoPopup, clear doesn't work, yet.

  • Property svn:executable set to *
File size: 4.8 KB
RevLine 
[6266]1-- KeyBindMenu.lua
[6224]2
3BasicGUI = require("BasicGUI")
4local P = BasicGUI:new() --inherit everything from the gui package
5if _REQUIREDNAME == nil then
[6266]6    KeyBindMenu = P
[6224]7else
8    _G[_REQUIREDNAME] = P
9end
10
[6266]11P.filename = "KeyBindMenu"
12P.layoutString = "KeyBindMenu.layout"
[6224]13
[6266]14function P:init()
15    commandList = {}
16    table.insert(commandList, "fire 0")
[6268]17    table.insert(commandList, "fire 1 | unfire")
18    table.insert(commandList, "onpress fire 2")
19    table.insert(commandList, "scale 1 moveRightLeft")
20    table.insert(commandList, "scale -1 moveRightLeft")
21    table.insert(commandList, "scale 1 moveFrontBack")
22    table.insert(commandList, "boost")
23    table.insert(commandList, "scale -1 moveFrontBack")
24    table.insert(commandList, "scale 1 rotateRoll")
25    table.insert(commandList, "scale -1 rotateRoll")
26    table.insert(commandList, "scale 1 moveUpDown")
27    table.insert(commandList, "scale -1 moveUpDown")
28    table.insert(commandList, "openConsole")
29    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
30    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
31    table.insert(commandList, "mouseLook")
32    table.insert(commandList, "pause")
33   
34    nameList = {}
35    table.insert(nameList, "Primary Fire")
36    table.insert(nameList, "Secondary Fire")
37    table.insert(nameList, "Fire Rocket")
38    table.insert(nameList, "Steer Right")
39    table.insert(nameList, "Steer Left")
40    table.insert(nameList, "Give Thrust")
41    table.insert(nameList, "Boost")
42    table.insert(nameList, "Hit Breaks")
43    table.insert(nameList, "Roll Right")
44    table.insert(nameList, "Roll Left")
45    table.insert(nameList, "Up")
46    table.insert(nameList, "Down")
47    table.insert(nameList, "Open Console")
48    table.insert(nameList, "Show Debug")
49    table.insert(nameList, "Show Stats")
50    table.insert(nameList, "mouseLook")
51    table.insert(nameList, "Pause")
[6266]52
53    local lineHeight = 30
54   
55    local window = winMgr:getWindow("orxonox/KeyBindPane")
56
57    for k,v in pairs(commandList) do
[6283]58        local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
59        local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
[6266]60        local button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
[6283]61        local clear = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Clear")
[6266]62       
63        line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight)))
[6283]64        command:setSize(CEGUI.UVector2(CEGUI.UDim(0.55, 0), CEGUI.UDim(1, 0)))
[6266]65        button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0)))
[6283]66        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0),CEGUI.UDim(1,0)))
[6266]67       
[6283]68        line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1))))       
[6266]69        command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0)))
[6283]70        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.55, 0),CEGUI.UDim(0, 0)))
71        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.95, 0),CEGUI.UDim(0, 0)))
[6266]72       
[6283]73        command:setText(nameList[k])
[6266]74        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
[6283]75        clear:setText("X")
76
[6266]77        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
[6283]78        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
[6266]79        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
80       
81        line:addChildWindow(command)
82        line:addChildWindow(button)
[6283]83        line:addChildWindow(clear)
[6266]84        window:addChildWindow(line)
85    end
86end
87
88function P.KeyBindButton_clicked(e)
89    local we = CEGUI.toWindowEventArgs(e)
90    local name = we.window:getName()
[6283]91    buttonNr = tonumber(string.match(name, "%d+"))
[6266]92   
93    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
94end
95
[6283]96function P.KeyBindClear_clicked(e)
97    local we = CEGUI.toWindowEventArgs(e)
98    local name = we.window:getName()
99    clearNr = tonumber(string.match(name, "%d+"))
100   
101   
102end
103
[6266]104function P.keybind()
[6283]105    local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")")
[6281]106    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
[6283]107    orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr])
[6266]108end
109
[6283]110function P.callback(number)
111    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(0)
112    local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button")
113    button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number]))
114   
115    InfoPopup.close()
116end
117
[6224]118function P.KeyBindBackButton_clicked(e)
[6266]119    hideGUI("KeyBindMenu")
[6224]120    debug("event: back")
121end
122
123return P
124
Note: See TracBrowser for help on using the repository browser.