Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/data/gui/scripts/KeyBindMenu.lua @ 11787

Last change on this file since 11787 was 11704, checked in by landauf, 6 years ago

[HUD_HS16] fixed wrong dependency between overlays and pickup module: pickup should NOT depend on overlays; instead overlays should use pickup.

also reverted all changes from HUD_HS16 in PickupManager for several reasons:

  • calling HUDPickupSystem is not necessary anymore due to the fixed dependencies
  • adding a console command is not necessary because there is already a full GUI for this purpose (press F4)
  • limiting the number of pickups to 10 is a bad idea because PickupManager manages pickups for ALL players in the game
  • Property svn:eol-style set to native
File size: 10.2 KB
Line 
1-- KeyBindMenu.lua
2
3local P = createMenuSheet("KeyBindMenu")
4P.loadAlong = { "InfoPopup" }
5
6function P.onLoad()
7
8    commandList = {}
9    table.insert(commandList, "fire 0")
10    table.insert(commandList, "fire 1 | unfire")
11    table.insert(commandList, "onpress fire 2")
12    table.insert(commandList, "onpress fire 3")
13    table.insert(commandList, "scale 1 moveFrontBack")
14    table.insert(commandList, "scale -1 moveFrontBack")
15    table.insert(commandList, "boost")
16    table.insert(commandList, "scale 1 moveRightLeft")
17    table.insert(commandList, "scale -1 moveRightLeft")
18    table.insert(commandList, "scale 1 moveUpDown")
19    table.insert(commandList, "scale -1 moveUpDown")
20    table.insert(commandList, "scale -1 rotateRoll")
21    table.insert(commandList, "scale 1 rotateRoll")
22    table.insert(commandList, "scale 1 rotateYaw")
23    table.insert(commandList, "scale -1 rotateYaw")
24    table.insert(commandList, "scale 1 rotatePitch")
25    table.insert(commandList, "scale -1 rotatePitch")
26    table.insert(commandList, "NewHumanController changeMode")
27    table.insert(commandList, "switchCamera")
28    table.insert(commandList, "InGameConsole openConsole")
29    table.insert(commandList, "OverlayGroup toggleVisibility Debug")
30    table.insert(commandList, "OverlayGroup toggleVisibility Stats")
31    table.insert(commandList, "OrxonoxOverlay toggleVisibility QuestGUI")
32    table.insert(commandList, "OrxonoxOverlay toggleVisibility PickupInventory")
33    table.insert(commandList, "startchat")
34    table.insert(commandList, "startchat_small")
35    table.insert(commandList, "mouseLook")
36    table.insert(commandList, "pause")
37    table.insert(commandList, "printScreen")
38    if orxonox.GUIManager:inDevMode() then
39        table.insert(commandList, "printScreenHD")
40        table.insert(commandList, "createSkybox")
41    end
42
43    nameList = {}
44    table.insert(nameList, "Primary Fire")
45    table.insert(nameList, "Secondary Fire")
46    table.insert(nameList, "Fire Rocket")
47    table.insert(nameList, "Fire Alternative Rocket")
48    table.insert(nameList, "Accelerate")
49    table.insert(nameList, "Break")
50    table.insert(nameList, "Boost")
51    table.insert(nameList, "Move Right")
52    table.insert(nameList, "Move Left")
53    table.insert(nameList, "Move Up")
54    table.insert(nameList, "Move Down")
55    table.insert(nameList, "Roll Right")
56    table.insert(nameList, "Roll Left")
57    table.insert(nameList, "Yaw Left")
58    table.insert(nameList, "Yaw Right")
59    table.insert(nameList, "Pitch Up")
60    table.insert(nameList, "Pitch Down")
61    table.insert(nameList, "Switch Input Mode")
62    table.insert(nameList, "Switch Camera")
63    table.insert(nameList, "Open Console")
64    table.insert(nameList, "Show Debug")
65    table.insert(nameList, "Show Stats")
66    table.insert(nameList, "Show Quests")
67    table.insert(nameList, "Show Pickups")
68    table.insert(nameList, "Show Chat")
69    table.insert(nameList, "Show small Chat")
70    table.insert(nameList, "Look Around")
71    table.insert(nameList, "Pause")
72    table.insert(nameList, "Screenshot")
73    if orxonox.GUIManager:inDevMode() then
74        table.insert(nameList, "HD screenshot")
75        table.insert(nameList, "Create Skybox")
76    end
77
78    linesList = {}
79
80    --Calculate design parameters:
81    sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/SampleWindow")
82    sampleWindow:setText("SampleText")
83
84    local size = getMinTextSize(sampleWindow)
85    lineHeight = size[1]
86
87    commandWidth = 0
88    for k,v in pairs(commandList) do
89        sampleWindow:setText(nameList[k])
90        size = getMinTextSize(sampleWindow)
91        if size[2] > commandWidth then
92            commandWidth = size[2]
93        end
94    end
95
96    sampleWindow:setText("add")
97    size = getMinTextSize(sampleWindow)
98    addWidth = size[2]
99
100    sampleWindow:setText("X")
101    size = getMinTextSize(sampleWindow)
102    clearWidth = size[2]
103
104    spaceWidth = math.floor(1/14*commandWidth)
105
106    buttonWidth = 145
107
108    P.createLines()
109
110    local funct = luaState:createLuaFunctor("KeyBindMenu.callback()")
111    orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct)
112
113    P:setButton(1, 1, {
114            ["button"] = winMgr:getWindow("orxonox/KeyBindBackButton"),
115            ["callback"]  = P.KeyBindBackButton_clicked
116    })
117end
118
119function P.KeyNameNiceifier(key)
120    local name = string.sub(key, string.find(key, '%.(.*)')+1)
121    local group = string.sub(key, string.find(key, '(.*)%.'))
122    group = string.sub(group,1,string.len(group)-1)
123    if( group == "Keys") then
124        return "Key " .. string.sub(name, string.find(name, 'Key(.*)')+3)
125    elseif( group == "MouseButtons") then
126        return "Mouse " .. name
127    elseif( string.find(group, "JoyStickButtons") ~= nil ) then
128        return "Joystick " .. name
129    elseif( string.find(group, "JoyStickAxes") ~= nil ) then
130        return "Joystick Axis " .. string.sub(name, 5, 6) .. string.sub(name, string.find(name, 'Axis%d%d(.*)')+6)
131    elseif( group == "MouseAxes" ) then
132        return "Mouse " .. string.sub(name, string.find(name, '.(.*)')+1) .. " " .. string.sub(name, 1, 1) .. "-Axis"
133    end
134    return key
135end
136
137function P.createLine(k)
138    local offset = 0
139    local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k)
140    line:setHeight(CEGUI.UDim(0, lineHeight))
141    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
142
143    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
144    command:setText(nameList[k])
145    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
146    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
147    line:addChildWindow(command)
148    offset = offset + commandWidth + spaceWidth
149
150    local plus = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus")
151    plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, addWidth), CEGUI.UDim(0.7, 0)))
152    plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
153    plus:setText("add")
154    orxonox.GUIManager:subscribeEventHelper(plus, "Clicked", P.name .. ".KeyBindPlus_clicked")
155    line:addChildWindow(plus)
156    offset = offset + addWidth + spaceWidth
157
158    local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
159    for i=0,(numButtons-1) do
160        local button = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
161        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
162        name = P.KeyNameNiceifier(name)
163        button:setText(name)
164        sampleWindow:setText(name)
165        local size = getMinTextSize(sampleWindow)
166        local buttonWidth = size[2]
167        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
168        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
169        orxonox.GUIManager:subscribeEventHelper(button, "Clicked", P.name .. ".KeyBindButton_clicked")
170        --button:subscribeScriptedEvent("EventClicked", P.name .. ".KeyBindButton_clicked")
171        line:addChildWindow(button)
172        offset = offset + buttonWidth
173
174        local clear = winMgr:createWindow("MenuWidgets/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i)
175        clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.7, 0)))
176        clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
177        clear:setText("X")
178        orxonox.GUIManager:subscribeEventHelper(clear, "Clicked", P.name .. ".KeyBindClear_clicked")
179        line:addChildWindow(clear)
180        offset = offset + clearWidth + spaceWidth
181    end
182
183    line:setWidth(CEGUI.UDim(0, offset+clearWidth))
184
185    return line
186end
187
188function P.createLines()
189    local window = winMgr:getWindow("orxonox/KeyBindPane")
190
191    for k,v in pairs(commandList) do
192        local line = P.createLine(k)
193        table.insert(linesList, line)
194        window:addChildWindow(line)
195    end
196
197    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
198    pane:setVerticalStepSize(getScrollingStepSize(window))
199end
200
201function P.KeyBindButton_clicked(e)
202    local we = CEGUI.toWindowEventArgs(e)
203    local name = we.window:getName()
204
205    local match = string.gmatch(name, "%d+")
206    local commandNr = tonumber(match())
207    local buttonNr = tonumber(match())
208
209    local arguments = {}
210    arguments[1] = commandNr
211    arguments[2] = buttonNr
212    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
213end
214
215function P.KeyBindPlus_clicked(e)
216    local we = CEGUI.toWindowEventArgs(e)
217    local name = we.window:getName()
218
219    local match = string.gmatch(name, "%d+")
220    local commandNr = tonumber(match())
221
222    local arguments = {}
223    arguments[1] = commandNr
224    openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments)
225end
226
227function P.KeyBindClear_clicked(e)
228    local we = CEGUI.toWindowEventArgs(e)
229    local name = we.window:getName()
230
231    local match = string.gmatch(name, "%d+")
232    local commandNr = tonumber(match())
233    local buttonNr = tonumber(match())
234
235    local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
236    orxonox.KeyBinderManager:getInstance():unbind(str)
237
238    P.callback()
239end
240
241function P.keybind(arguments)
242    local commandNr = arguments[1]
243    local buttonNr = arguments[2]
244    if buttonNr ~= nil then
245        local str = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)
246        orxonox.KeyBinderManager:getInstance():unbind(str)
247    end
248
249    orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr])
250end
251
252function P.callback()
253    local pane = tolua.cast(winMgr:getWindow("orxonox/KeyBindPane"), "CEGUI::ScrollablePane")
254    local position = pane:getVerticalScrollPosition()
255    while table.getn(linesList) ~= 0 do
256        if linesList[1] ~= nil then
257            winMgr:destroyWindow(linesList[1]:getName())
258        end
259        table.remove(linesList, 1)
260    end
261
262    linesList = {}
263
264    P.createLines()
265    if(InfoPopup ~= nil) then
266        InfoPopup.close()
267    end
268    pane:setVerticalScrollPosition( position )
269end
270
271function P.KeyBindBackButton_clicked(e)
272    hideMenuSheet("KeyBindMenu")
273end
274
275return P
Note: See TracBrowser for help on using the repository browser.