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