[7006] | 1 | -- MiscConfigMenu.lua |
---|
| 2 | |
---|
[8729] | 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 |
---|
[8964] | 13 | P.editboxWidth = 0 |
---|
[7006] | 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_") |
---|
[8079] | 37 | table.insert(P.commandList, "Core bDevMode_") |
---|
[7006] | 38 | |
---|
| 39 | P.nameList = {} |
---|
[7013] | 40 | table.insert(P.nameList, "Mouse sensitivity") |
---|
| 41 | table.insert(P.nameList, "Mouse acceleration") |
---|
| 42 | table.insert(P.nameList, "Derive mouse input") |
---|
| 43 | table.insert(P.nameList, "Mouse wheel stepsize") |
---|
| 44 | table.insert(P.nameList, "Shell: max. History length") |
---|
| 45 | table.insert(P.nameList, "Start IOConsole") |
---|
| 46 | table.insert(P.nameList, "FPS limit") |
---|
| 47 | table.insert(P.nameList, "Spectator speed") |
---|
| 48 | table.insert(P.nameList, "Invert Y-axis") |
---|
| 49 | table.insert(P.nameList, "Default level") |
---|
| 50 | table.insert(P.nameList, "Start countdown") |
---|
| 51 | table.insert(P.nameList, "Autostart") |
---|
| 52 | table.insert(P.nameList, "Number of Bots") |
---|
| 53 | table.insert(P.nameList, "UnderAttack: game time") |
---|
[7403] | 54 | table.insert(P.nameList, "TeamDeathmatch: Number of teams") |
---|
[7013] | 55 | table.insert(P.nameList, "Playername") |
---|
| 56 | table.insert(P.nameList, "Chat: display time") |
---|
[8079] | 57 | table.insert(P.nameList, "Developer's Mode") |
---|
[7006] | 58 | |
---|
| 59 | P.linesList = {} |
---|
| 60 | |
---|
| 61 | --Calculate design parameters: |
---|
| 62 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
| 63 | P.sampleWindow:setText("SampleText") |
---|
| 64 | |
---|
| 65 | local size = getMinTextSize(P.sampleWindow) |
---|
| 66 | P.lineHeight = size[1] |
---|
| 67 | |
---|
| 68 | P.commandWidth = 0 |
---|
| 69 | for k,v in pairs(P.commandList) do |
---|
| 70 | P.sampleWindow:setText(P.nameList[k]) |
---|
| 71 | size = getMinTextSize(P.sampleWindow) |
---|
| 72 | if size[2] > P.commandWidth then |
---|
| 73 | P.commandWidth = size[2] |
---|
| 74 | end |
---|
| 75 | end |
---|
| 76 | |
---|
| 77 | P.sampleWindow:setText("reset") |
---|
| 78 | size = getMinTextSize(P.sampleWindow) |
---|
| 79 | P.resetWidth = size[2]+20 |
---|
| 80 | |
---|
[8964] | 81 | P.spaceWidth = 10 |
---|
| 82 | |
---|
| 83 | local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane") |
---|
| 84 | size = pane:getViewableArea() |
---|
| 85 | P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth |
---|
[7006] | 86 | |
---|
| 87 | P.createLines() |
---|
| 88 | |
---|
[8079] | 89 | P:setButton(1, 1, { |
---|
[8964] | 90 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"), |
---|
| 91 | ["callback"] = P.MiscConfigCancelButton_clicked |
---|
[8079] | 92 | }) |
---|
[8964] | 93 | |
---|
| 94 | P:setButton(1, 2, { |
---|
| 95 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"), |
---|
| 96 | ["callback"] = P.MiscConfigOKButton_clicked |
---|
| 97 | }) |
---|
[7006] | 98 | end |
---|
| 99 | |
---|
| 100 | function P.createLine(k) |
---|
| 101 | local offset = 0 |
---|
[8964] | 102 | -- content window for the entire line |
---|
[7006] | 103 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
| 104 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
| 105 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
| 106 | |
---|
[8964] | 107 | -- config name |
---|
[7006] | 108 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
| 109 | command:setText(P.nameList[k]) |
---|
| 110 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
| 111 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
| 112 | line:addChildWindow(command) |
---|
| 113 | offset = offset + P.commandWidth + P.spaceWidth |
---|
| 114 | |
---|
[8964] | 115 | -- config value (editable) |
---|
[7006] | 116 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 117 | configvalue:setProperty("ReadOnly", "set:False") |
---|
[7284] | 118 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
[7006] | 119 | configvalue:setText(value) |
---|
[8964] | 120 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0))) |
---|
[7006] | 121 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
[8964] | 122 | -- enable the reset button if the value changed |
---|
| 123 | orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") |
---|
[7006] | 124 | line:addChildWindow(configvalue) |
---|
[8964] | 125 | offset = offset + P.editboxWidth + P.spaceWidth |
---|
[7006] | 126 | |
---|
[8964] | 127 | -- reset button (only available when value changed) |
---|
[7006] | 128 | local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
| 129 | reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) |
---|
| 130 | reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 131 | reset:setText("reset") |
---|
[8964] | 132 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked") |
---|
[7006] | 133 | line:addChildWindow(reset) |
---|
[7013] | 134 | reset:setEnabled(false) |
---|
[7006] | 135 | offset = offset + P.resetWidth + P.spaceWidth |
---|
| 136 | |
---|
| 137 | line:setWidth(CEGUI.UDim(0, offset)) |
---|
| 138 | |
---|
| 139 | return line |
---|
| 140 | end |
---|
| 141 | |
---|
| 142 | function P.createLines() |
---|
| 143 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane") |
---|
| 144 | |
---|
| 145 | for k,v in pairs(P.commandList) do |
---|
| 146 | local line = P.createLine(k) |
---|
| 147 | table.insert(P.linesList, line) |
---|
| 148 | window:addChildWindow(line) |
---|
| 149 | end |
---|
| 150 | |
---|
| 151 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
| 152 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
| 153 | end |
---|
| 154 | |
---|
[8964] | 155 | function P.MiscConfigOKButton_clicked(e) |
---|
| 156 | for k,v in pairs(P.commandList) do |
---|
| 157 | -- save the changes |
---|
| 158 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 159 | orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText()) |
---|
| 160 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
| 161 | resetButton:setEnabled(false) |
---|
| 162 | end |
---|
| 163 | |
---|
| 164 | hideMenuSheet("MiscConfigMenu") |
---|
| 165 | end |
---|
| 166 | |
---|
| 167 | function P.MiscConfigCancelButton_clicked(e) |
---|
| 168 | hideMenuSheet("MiscConfigMenu") |
---|
| 169 | end |
---|
| 170 | |
---|
| 171 | function P.MiscConfigEditbox_textAccepted(e) |
---|
[7006] | 172 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 173 | local name = we.window:getName() |
---|
| 174 | |
---|
| 175 | local match = string.gmatch(name, "%d+") |
---|
| 176 | local commandNr = tonumber(match()) |
---|
| 177 | |
---|
[8964] | 178 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset") |
---|
| 179 | resetButton:setEnabled(true) |
---|
[7006] | 180 | end |
---|
| 181 | |
---|
[8964] | 182 | function P.MiscConfigResetButton_clicked(e) |
---|
[7006] | 183 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 184 | local name = we.window:getName() |
---|
| 185 | |
---|
| 186 | local match = string.gmatch(name, "%d+") |
---|
| 187 | local commandNr = tonumber(match()) |
---|
| 188 | |
---|
[8964] | 189 | -- reload the old value |
---|
| 190 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
[7284] | 191 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
[8964] | 192 | editbox:setText(value) |
---|
| 193 | |
---|
| 194 | we.window:setEnabled(false) |
---|
[7006] | 195 | end |
---|
| 196 | |
---|
| 197 | return P |
---|