Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6292 was 6292, checked in by cmueri, 14 years ago

New layout of the keybind menu.

  • Property svn:executable set to *
File size: 6.3 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 moveFrontBack")
20    table.insert(commandList, "scale -1 moveFrontBack")
21    table.insert(commandList, "boost")
22    table.insert(commandList, "scale 1 moveRightLeft")
23    table.insert(commandList, "scale -1 moveRightLeft")
24    table.insert(commandList, "scale 1 moveUpDown")
25    table.insert(commandList, "scale -1 moveUpDown")
26    table.insert(commandList, "scale 1 rotateRoll")
27    table.insert(commandList, "scale -1 rotateRoll")
28    table.insert(commandList, "switchCamera")
29    table.insert(commandList, "openConsole")
30    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
31    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
32    table.insert(commandList, "mouseLook")
33    table.insert(commandList, "pause")
34   
35    nameList = {}
36    table.insert(nameList, "Primary Fire")
37    table.insert(nameList, "Secondary Fire")
38    table.insert(nameList, "Fire Rocket")
39    table.insert(nameList, "Accelerate")
40    table.insert(nameList, "Break")
41    table.insert(nameList, "Boost")
42    table.insert(nameList, "Move Right")
43    table.insert(nameList, "Move Left")
44    table.insert(nameList, "Move Up")
45    table.insert(nameList, "Move Down")
46    table.insert(nameList, "Roll Right")
47    table.insert(nameList, "Roll Left")
48    table.insert(nameList, "Switch Camera")
49    table.insert(nameList, "Open Console")
50    table.insert(nameList, "Show Debug")
51    table.insert(nameList, "Show Stats")
52    table.insert(nameList, "Look Around")
53    table.insert(nameList, "Pause")
54
55    local lineHeight = 30
56   
57    local window = winMgr:getWindow("orxonox/KeyBindPane")
58
59    for k,v in pairs(commandList) do
60        local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
61        local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
62        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
63        local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear")
64        local button2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button2")
65        local clear2 = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear2")
66        local add = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Add")
67       
68        line:setSize(CEGUI.UVector2(CEGUI.UDim(1, -13), CEGUI.UDim(0, lineHeight)))
69        command:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
70        button:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
71        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
72        button2:setSize(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.6, 0)))
73        clear2:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
74        add:setSize(CEGUI.UVector2(CEGUI.UDim(0.05, 0), CEGUI.UDim(0.6, 0)))
75       
76        line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))       
77        command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
78        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.25, 0), CEGUI.UDim(0.2, 0)))
79        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0.5, 0), CEGUI.UDim(0.2, 0)))
80        button2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(0.2, 0)))
81        clear2:setPosition(CEGUI.UVector2(CEGUI.UDim(0.85, 0), CEGUI.UDim(0.2, 0)))
82        add:setPosition(CEGUI.UVector2(CEGUI.UDim(0.925, 0), CEGUI.UDim(0.2, 0)))
83       
84        command:setText(nameList[k])
85        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
86        clear:setText("X")
87        button2:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
88        clear2:setText("X")
89        add:setText("+")
90
91        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
92        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked")
93        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(add, "Clicked", P.filename .. ".KeyBindAdd_clicked")
94        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
95       
96        line:addChildWindow(command)
97        line:addChildWindow(button)
98        line:addChildWindow(clear)
99        line:addChildWindow(button2)
100        line:addChildWindow(clear2)
101        line:addChildWindow(add)
102        window:addChildWindow(line)
103    end
104end
105
106function P.KeyBindButton_clicked(e)
107    local we = CEGUI.toWindowEventArgs(e)
108    local name = we.window:getName()
109    buttonNr = tonumber(string.match(name, "%d+"))
110    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
111end
112
113function P.KeyBindClear_clicked(e)
114    local we = CEGUI.toWindowEventArgs(e)
115    local name = we.window:getName()
116    clearNr = tonumber(string.match(name, "%d+"))
117end
118
119function P.KeyBindAdd_clicked(e)
120   
121end
122
123function P.keybind()
124    local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")")
125    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
126    orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr])
127end
128
129function P.callback(number)
130    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(nil)
131    local button = winMgr:getWindow("orxonox/KeyBindPane/Binding" .. number .. "/Button")
132    button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[number]))
133   
134    InfoPopup.close()
135end
136
137function P.KeyBindBackButton_clicked(e)
138    hideGUI("KeyBindMenu")
139end
140
141return P
142
Note: See TracBrowser for help on using the repository browser.