Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Bug fix. 0 != nil in lua…

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1-- KeyBindMenu.lua
2
3BasicGUI = require("BasicGUI")
4local P = BasicGUI:new() --inherit everything from the gui package
5if _REQUIREDNAME == nil then
6    KeyBindMenu = P
7else
8    _G[_REQUIREDNAME] = P
9end
10
11P.filename = "KeyBindMenu"
12P.layoutString = "KeyBindMenu.layout"
13
14function P:init()
15    commandList = {}
16    table.insert(commandList, "fire 0")
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")
52
53    local lineHeight = 30
54   
55    local window = winMgr:getWindow("orxonox/KeyBindPane")
56
57    for k,v in pairs(commandList) do
58        local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
59        local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
60        local button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
61        local clear = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Clear")
62       
63        line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight)))
64        command:setSize(CEGUI.UVector2(CEGUI.UDim(0.55, 0), CEGUI.UDim(1, 0)))
65        button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0)))
66        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0),CEGUI.UDim(1,0)))
67       
68        line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1))))       
69        command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0)))
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)))
72       
73        command:setText(nameList[k])
74        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
75        clear:setText("X")
76
77        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
78        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
79        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
80       
81        line:addChildWindow(command)
82        line:addChildWindow(button)
83        line:addChildWindow(clear)
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()
91    buttonNr = tonumber(string.match(name, "%d+"))
92   
93    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
94end
95
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
104function P.keybind()
105    local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")")
106    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
107    orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr])
108end
109
110function P.callback(number)
111    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil)
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
118function P.KeyBindBackButton_clicked(e)
119    hideGUI("KeyBindMenu")
120    debug("event: back")
121end
122
123return P
124
Note: See TracBrowser for help on using the repository browser.