[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_") |
---|
[9376] | 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") |
---|
[7006] | 41 | |
---|
[9376] | 42 | |
---|
[7006] | 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") |
---|
[9376] | 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") |
---|
[7006] | 64 | |
---|
[9376] | 65 | |
---|
[7006] | 66 | P.linesList = {} |
---|
| 67 | |
---|
| 68 | --Calculate design parameters: |
---|
| 69 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
| 70 | P.sampleWindow:setText("SampleText") |
---|
| 71 | |
---|
| 72 | local size = getMinTextSize(P.sampleWindow) |
---|
| 73 | P.lineHeight = size[1] |
---|
| 74 | |
---|
| 75 | P.commandWidth = 0 |
---|
| 76 | for k,v in pairs(P.commandList) do |
---|
| 77 | P.sampleWindow:setText(P.nameList[k]) |
---|
| 78 | size = getMinTextSize(P.sampleWindow) |
---|
| 79 | if size[2] > P.commandWidth then |
---|
| 80 | P.commandWidth = size[2] |
---|
| 81 | end |
---|
| 82 | end |
---|
| 83 | |
---|
| 84 | P.sampleWindow:setText("reset") |
---|
| 85 | size = getMinTextSize(P.sampleWindow) |
---|
| 86 | P.resetWidth = size[2]+20 |
---|
| 87 | |
---|
[9016] | 88 | P.spaceWidth = 10 |
---|
| 89 | |
---|
| 90 | local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane") |
---|
| 91 | size = pane:getViewableArea() |
---|
| 92 | P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth |
---|
[7006] | 93 | |
---|
| 94 | P.createLines() |
---|
| 95 | |
---|
[8079] | 96 | P:setButton(1, 1, { |
---|
[9016] | 97 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"), |
---|
| 98 | ["callback"] = P.MiscConfigCancelButton_clicked |
---|
[8079] | 99 | }) |
---|
[9016] | 100 | |
---|
| 101 | P:setButton(1, 2, { |
---|
| 102 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"), |
---|
| 103 | ["callback"] = P.MiscConfigOKButton_clicked |
---|
| 104 | }) |
---|
[7006] | 105 | end |
---|
| 106 | |
---|
| 107 | function P.createLine(k) |
---|
| 108 | local offset = 0 |
---|
[9016] | 109 | -- content window for the entire line |
---|
[7006] | 110 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
| 111 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
| 112 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
| 113 | |
---|
[9016] | 114 | -- config name |
---|
[7006] | 115 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
| 116 | command:setText(P.nameList[k]) |
---|
| 117 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
| 118 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
| 119 | line:addChildWindow(command) |
---|
| 120 | offset = offset + P.commandWidth + P.spaceWidth |
---|
| 121 | |
---|
[9016] | 122 | -- config value (editable) |
---|
[7006] | 123 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 124 | configvalue:setProperty("ReadOnly", "set:False") |
---|
[7284] | 125 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
[7006] | 126 | configvalue:setText(value) |
---|
[9016] | 127 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0))) |
---|
[7006] | 128 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
[9016] | 129 | -- enable the reset button if the value changed |
---|
| 130 | orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") |
---|
[7006] | 131 | line:addChildWindow(configvalue) |
---|
[9016] | 132 | offset = offset + P.editboxWidth + P.spaceWidth |
---|
[7006] | 133 | |
---|
[9016] | 134 | -- reset button (only available when value changed) |
---|
[7006] | 135 | local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
| 136 | reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) |
---|
| 137 | reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 138 | reset:setText("reset") |
---|
[9016] | 139 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked") |
---|
[7006] | 140 | line:addChildWindow(reset) |
---|
[7013] | 141 | reset:setEnabled(false) |
---|
[7006] | 142 | offset = offset + P.resetWidth + P.spaceWidth |
---|
| 143 | |
---|
| 144 | line:setWidth(CEGUI.UDim(0, offset)) |
---|
| 145 | |
---|
| 146 | return line |
---|
| 147 | end |
---|
| 148 | |
---|
| 149 | function P.createLines() |
---|
| 150 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane") |
---|
| 151 | |
---|
| 152 | for k,v in pairs(P.commandList) do |
---|
| 153 | local line = P.createLine(k) |
---|
| 154 | table.insert(P.linesList, line) |
---|
| 155 | window:addChildWindow(line) |
---|
| 156 | end |
---|
| 157 | |
---|
| 158 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
| 159 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
| 160 | end |
---|
| 161 | |
---|
[9016] | 162 | function P.MiscConfigOKButton_clicked(e) |
---|
| 163 | for k,v in pairs(P.commandList) do |
---|
| 164 | -- save the changes |
---|
| 165 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 166 | orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText()) |
---|
| 167 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
| 168 | resetButton:setEnabled(false) |
---|
| 169 | end |
---|
| 170 | |
---|
| 171 | hideMenuSheet("MiscConfigMenu") |
---|
| 172 | end |
---|
| 173 | |
---|
| 174 | function P.MiscConfigCancelButton_clicked(e) |
---|
| 175 | hideMenuSheet("MiscConfigMenu") |
---|
| 176 | end |
---|
| 177 | |
---|
| 178 | function P.MiscConfigEditbox_textAccepted(e) |
---|
[7006] | 179 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 180 | local name = we.window:getName() |
---|
| 181 | |
---|
| 182 | local match = string.gmatch(name, "%d+") |
---|
| 183 | local commandNr = tonumber(match()) |
---|
| 184 | |
---|
[9016] | 185 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset") |
---|
| 186 | resetButton:setEnabled(true) |
---|
[7006] | 187 | end |
---|
| 188 | |
---|
[9016] | 189 | function P.MiscConfigResetButton_clicked(e) |
---|
[7006] | 190 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 191 | local name = we.window:getName() |
---|
| 192 | |
---|
| 193 | local match = string.gmatch(name, "%d+") |
---|
| 194 | local commandNr = tonumber(match()) |
---|
| 195 | |
---|
[9016] | 196 | -- reload the old value |
---|
| 197 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
[7284] | 198 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
[9016] | 199 | editbox:setText(value) |
---|
| 200 | |
---|
| 201 | we.window:setEnabled(false) |
---|
[7006] | 202 | end |
---|
| 203 | |
---|
| 204 | return P |
---|