- Timestamp:
- Dec 9, 2009, 11:17:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
r6292 r6311 52 52 table.insert(nameList, "Look Around") 53 53 table.insert(nameList, "Pause") 54 55 linesList = {} 54 56 55 local lineHeight = 30 57 lineHeight = 35 58 buttonWidth = 170 59 clearWidth = 20 56 60 57 61 local window = winMgr:getWindow("orxonox/KeyBindPane") 58 62 59 63 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) 64 local line = P.createLine(k) 65 table.insert(linesList, line) 102 66 window:addChildWindow(line) 103 67 end 68 69 local funct = luaState:createLuaFunctor("KeyBindMenu.callback()") 70 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 71 end 72 73 function P.createLine(k) 74 local line = winMgr:createWindow("DefaultWindow", "orxonox/KeyBindPane/Binding" .. k) 75 line:setHeight(CEGUI.UDim(0, lineHeight)) 76 line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1)))) 77 78 local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command") 79 command:setSize(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(1, 0))) 80 command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 81 command:setText(nameList[k]) 82 line:addChildWindow(command) 83 84 local plus = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Plus") 85 plus:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(1, 0))) 86 plus:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 200), CEGUI.UDim(0, 0))) 87 plus:setText("+") 88 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(plus, "Clicked", P.filename .. ".KeyBindPlus_clicked") 89 line:addChildWindow(plus) 90 91 numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]); 92 for i=0,(numButtons-1) do 93 local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i) 94 button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.8, 0))) 95 button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth))+200+clearWidth), CEGUI.UDim(0.1, 0))) 96 button:setText(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)) 97 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked") 98 --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked") 99 line:addChildWindow(button) 100 101 local clear = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Clear" .. i) 102 clear:setSize(CEGUI.UVector2(CEGUI.UDim(0, clearWidth), CEGUI.UDim(0.8, 0))) 103 clear:setPosition(CEGUI.UVector2(CEGUI.UDim(0, (i*(buttonWidth+clearWidth)+buttonWidth)+200+clearWidth), CEGUI.UDim(0.1, 0))) 104 clear:setText("X") 105 orxonox.KeyBinderManager:getInstance():subscribeEventHelper(clear, "Clicked", P.filename .. ".KeyBindClear_clicked") 106 line:addChildWindow(clear) 107 end 108 109 line:setWidth(CEGUI.UDim(0, 200+numButtons*(buttonWidth+clearWidth)+clearWidth)) 110 111 return line 104 112 end 105 113 … … 107 115 local we = CEGUI.toWindowEventArgs(e) 108 116 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) 117 118 local match = string.gmatch(name, "%d+") 119 local commandNr = tonumber(match()) 120 local buttonNr = tonumber(match()) 121 122 local arguments = {} 123 arguments[1] = commandNr 124 arguments[2] = buttonNr 125 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments) 126 end 127 128 function P.KeyBindPlus_clicked(e) 129 local we = CEGUI.toWindowEventArgs(e) 130 local name = we.window:getName() 131 132 local match = string.gmatch(name, "%d+") 133 local commandNr = tonumber(match()) 134 135 local arguments = {} 136 arguments[1] = commandNr 137 openInfoPopup("Press any button/key or move a mouse/joystick axis.", KeyBindMenu.keybind, false, arguments) 111 138 end 112 139 … … 114 141 local we = CEGUI.toWindowEventArgs(e) 115 142 local name = we.window:getName() 116 clearNr = tonumber(string.match(name, "%d+")) 143 144 local match = string.gmatch(name, "%d+") 145 local commandNr = tonumber(match()) 146 local buttonNr = tonumber(match()) 147 148 orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)) 149 150 P.callback() 117 151 end 118 152 119 function P.KeyBindAdd_clicked(e) 120 153 function P.keybind(arguments) 154 local commandNr = arguments[1] 155 local buttonNr = arguments[2] 156 if buttonNr ~= nil then 157 orxonox.KeyBinderManager:getInstance():unbind(orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[commandNr], buttonNr)) 158 end 159 orxonox.KeyBinderManager:getInstance():keybind(commandList[commandNr]) 121 160 end 122 161 123 function P.keybind() 124 local funct = luaState:createLuaFunctor("KeyBindMenu.callback(" .. buttonNr ..")") 125 orxonox.KeyBinderManager:getInstance():registerKeybindCallback(funct) 126 orxonox.KeyBinderManager:getInstance():keybind(commandList[buttonNr]) 127 end 162 function P.callback() 163 while table.getn(linesList) ~= 0 do 164 if linesList[1] ~= nil then 165 winMgr:destroyWindow(linesList[1]:getName()) 166 end 167 table.remove(linesList, 1) 168 end 169 170 linesList = {} 128 171 129 function 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])) 172 window = winMgr:getWindow("orxonox/KeyBindPane") 173 for q,w in pairs(commandList) do 174 local line = P.createLine(q) 175 table.insert(linesList, line) 176 window:addChildWindow(line) 177 end 133 178 134 InfoPopup.close() 179 if(InfoPopup ~= nil) then 180 InfoPopup.close() 181 end 135 182 end 136 183
Note: See TracChangeset
for help on using the changeset viewer.