Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6281 was 6281, checked in by rgrieder, 14 years ago

Added LuaFunctor that can execute arbitrary lua code.
Also added LuaState::createLuaFunctor(std::string) and implemented that for the keybindings menu.

  • Property svn:executable set to *
File size: 3.9 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 button = winMgr:createWindow("TaharezLook/Button", "orxonox/KeyBindPane/Binding" .. k .. "/Button")
59        local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
60        local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
61       
62        line:setSize(CEGUI.UVector2(CEGUI.UDim(1,-13),CEGUI.UDim(0, lineHeight)))
63        button:setSize(CEGUI.UVector2(CEGUI.UDim(0.4, 0), CEGUI.UDim(1, 0)))
64        command:setSize(CEGUI.UVector2(CEGUI.UDim(0.6, 0), CEGUI.UDim(1, 0)))
65       
66        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0.6, 0),CEGUI.UDim(0, 0)))
67        command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, 0)))
68        line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0),CEGUI.UDim(0, lineHeight*(k-1))))
69       
70        button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(v))
71        command:setText(nameList[k])
72       
73        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
74        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
75       
76        line:addChildWindow(command)
77        line:addChildWindow(button)
78        window:addChildWindow(line)
79    end
80end
81
82function P.KeyBindButton_clicked(e)
83    local we = CEGUI.toWindowEventArgs(e)
84    local name = we.window:getName()
85    commandNr = tonumber(string.match(name, "%d+"))
86   
87    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind)
88end
89
90function P.keybind()
91    local funct = luaState:createLuaFunctor("InfoPopup:close()")
92    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
93    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
94end
95
96function P.KeyBindBackButton_clicked(e)
97    hideGUI("KeyBindMenu")
98    debug("event: back")
99end
100
101return P
102
Note: See TracBrowser for help on using the repository browser.