[7006] | 1 | -- MiscConfigMenu.lua |
---|
| 2 | |
---|
[7012] | 3 | local P = createMenuSheet("MiscConfigMenu", true, TriBool.True, TriBool.True) |
---|
[7006] | 4 | |
---|
| 5 | P.commandList = {} |
---|
| 6 | P.nameList = {} |
---|
| 7 | P.linesList = {} |
---|
| 8 | |
---|
| 9 | P.sampleWindow = nil |
---|
| 10 | |
---|
| 11 | P.lineHeight = 0 |
---|
| 12 | P.commandWidth = 0 |
---|
| 13 | P.configWidth = 0 |
---|
| 14 | P.resetWidth = 0 |
---|
| 15 | P.spaceWidth = 0 |
---|
| 16 | |
---|
| 17 | function P.onLoad() |
---|
| 18 | |
---|
| 19 | P.commandList = {} |
---|
[7013] | 20 | table.insert(P.commandList, "KeyBinder mouseSensitivity_") |
---|
| 21 | table.insert(P.commandList, "KeyBinder mouseSensitivityDerived_") |
---|
| 22 | table.insert(P.commandList, "KeyBinder bDeriveMouseInput_") |
---|
| 23 | table.insert(P.commandList, "KeyBinder mouseWheelStepSize_") |
---|
| 24 | table.insert(P.commandList, "Shell maxHistoryLength_") |
---|
| 25 | table.insert(P.commandList, "Core bStartIOConsole_") |
---|
| 26 | table.insert(P.commandList, "Game fpsLimit_") |
---|
| 27 | table.insert(P.commandList, "Spectator speed_") |
---|
| 28 | table.insert(P.commandList, "SpaceShip bInvertYAxis_") |
---|
| 29 | table.insert(P.commandList, "LevelManager defaultLevelName_") |
---|
| 30 | table.insert(P.commandList, "Gametype initialStartCountdown_") |
---|
| 31 | table.insert(P.commandList, "Gametype bAutoStart_") |
---|
| 32 | table.insert(P.commandList, "Gametype numberOfBots_") |
---|
| 33 | table.insert(P.commandList, "UnderAttack gameTime_") |
---|
| 34 | table.insert(P.commandList, "TeamDeathmatch teams_") |
---|
| 35 | table.insert(P.commandList, "HumanPlayer nick_") |
---|
[7006] | 36 | table.insert(P.commandList, "ChatOverlay displayTime_") |
---|
| 37 | |
---|
| 38 | P.nameList = {} |
---|
[7013] | 39 | table.insert(P.nameList, "Mouse sensitivity") |
---|
| 40 | table.insert(P.nameList, "Mouse acceleration") |
---|
| 41 | table.insert(P.nameList, "Derive mouse input") |
---|
| 42 | table.insert(P.nameList, "Mouse wheel stepsize") |
---|
| 43 | table.insert(P.nameList, "Shell: max. History length") |
---|
| 44 | table.insert(P.nameList, "Start IOConsole") |
---|
| 45 | table.insert(P.nameList, "FPS limit") |
---|
| 46 | table.insert(P.nameList, "Spectator speed") |
---|
| 47 | table.insert(P.nameList, "Invert Y-axis") |
---|
| 48 | table.insert(P.nameList, "Default level") |
---|
| 49 | table.insert(P.nameList, "Start countdown") |
---|
| 50 | table.insert(P.nameList, "Autostart") |
---|
| 51 | table.insert(P.nameList, "Number of Bots") |
---|
| 52 | table.insert(P.nameList, "UnderAttack: game time") |
---|
| 53 | table.insert(P.nameList, "TeamDeathmatch: Numer of teams") |
---|
| 54 | table.insert(P.nameList, "Playername") |
---|
| 55 | table.insert(P.nameList, "Chat: display time") |
---|
[7006] | 56 | |
---|
| 57 | P.linesList = {} |
---|
| 58 | |
---|
| 59 | --Calculate design parameters: |
---|
| 60 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
| 61 | P.sampleWindow:setText("SampleText") |
---|
| 62 | |
---|
| 63 | local size = getMinTextSize(P.sampleWindow) |
---|
| 64 | P.lineHeight = size[1] |
---|
| 65 | |
---|
| 66 | P.commandWidth = 0 |
---|
| 67 | for k,v in pairs(P.commandList) do |
---|
| 68 | P.sampleWindow:setText(P.nameList[k]) |
---|
| 69 | size = getMinTextSize(P.sampleWindow) |
---|
| 70 | if size[2] > P.commandWidth then |
---|
| 71 | P.commandWidth = size[2] |
---|
| 72 | end |
---|
| 73 | end |
---|
| 74 | |
---|
| 75 | P.sampleWindow:setText("configure") |
---|
| 76 | size = getMinTextSize(P.sampleWindow) |
---|
| 77 | P.configWidth = size[2]+20 |
---|
| 78 | |
---|
| 79 | P.sampleWindow:setText("reset") |
---|
| 80 | size = getMinTextSize(P.sampleWindow) |
---|
| 81 | P.resetWidth = size[2]+20 |
---|
| 82 | |
---|
| 83 | P.spaceWidth = math.floor(1/8*P.configWidth) |
---|
| 84 | |
---|
| 85 | P.createLines() |
---|
| 86 | |
---|
| 87 | end |
---|
| 88 | |
---|
| 89 | function P.createLine(k) |
---|
| 90 | local offset = 0 |
---|
| 91 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
| 92 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
| 93 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
| 94 | |
---|
| 95 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
| 96 | command:setText(P.nameList[k]) |
---|
| 97 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
| 98 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
| 99 | line:addChildWindow(command) |
---|
| 100 | offset = offset + P.commandWidth + P.spaceWidth |
---|
| 101 | |
---|
| 102 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 103 | configvalue:setProperty("ReadOnly", "set:False") |
---|
[7211] | 104 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
[7006] | 105 | configvalue:setText(value) |
---|
| 106 | P.sampleWindow:setText(value) |
---|
| 107 | local size = getMinTextSize(P.sampleWindow) |
---|
| 108 | local configvalueWidth = 2*size[2] |
---|
| 109 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0))) |
---|
| 110 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 111 | line:addChildWindow(configvalue) |
---|
| 112 | offset = offset + configvalueWidth + P.spaceWidth |
---|
| 113 | |
---|
| 114 | local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config") |
---|
| 115 | config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0))) |
---|
| 116 | config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 117 | config:setText("configure") |
---|
| 118 | orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked") |
---|
| 119 | line:addChildWindow(config) |
---|
| 120 | offset = offset + P.configWidth + P.spaceWidth |
---|
| 121 | |
---|
| 122 | local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
| 123 | reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) |
---|
| 124 | reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 125 | reset:setText("reset") |
---|
| 126 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked") |
---|
| 127 | line:addChildWindow(reset) |
---|
[7013] | 128 | reset:setEnabled(false) |
---|
[7006] | 129 | offset = offset + P.resetWidth + P.spaceWidth |
---|
| 130 | |
---|
| 131 | line:setWidth(CEGUI.UDim(0, offset)) |
---|
| 132 | |
---|
| 133 | return line |
---|
| 134 | end |
---|
| 135 | |
---|
| 136 | function P.createLines() |
---|
| 137 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane") |
---|
| 138 | |
---|
| 139 | for k,v in pairs(P.commandList) do |
---|
| 140 | local line = P.createLine(k) |
---|
| 141 | table.insert(P.linesList, line) |
---|
| 142 | window:addChildWindow(line) |
---|
| 143 | end |
---|
| 144 | |
---|
| 145 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
| 146 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
| 147 | end |
---|
| 148 | |
---|
| 149 | function P.MiscConfigReset_clicked(e) |
---|
| 150 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 151 | local name = we.window:getName() |
---|
| 152 | |
---|
| 153 | local match = string.gmatch(name, "%d+") |
---|
| 154 | local commandNr = tonumber(match()) |
---|
| 155 | |
---|
| 156 | -- TODO: Implement reset. |
---|
| 157 | end |
---|
| 158 | |
---|
| 159 | function P.MiscConfigConfigure_clicked(e) |
---|
| 160 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 161 | local name = we.window:getName() |
---|
| 162 | |
---|
| 163 | local match = string.gmatch(name, "%d+") |
---|
| 164 | local commandNr = tonumber(match()) |
---|
| 165 | |
---|
| 166 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
| 167 | |
---|
[7013] | 168 | orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText()) |
---|
[7211] | 169 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
[7006] | 170 | window:setText(value) |
---|
| 171 | end |
---|
| 172 | |
---|
| 173 | function P.MiscConfigBackButton_clicked(e) |
---|
| 174 | hideMenuSheet("MiscConfigMenu") |
---|
| 175 | end |
---|
| 176 | |
---|
| 177 | return P |
---|