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