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