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