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