[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 |
---|
| 13 | P.configWidth = 0 |
---|
| 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_") |
---|
[8929] | 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") |
---|
[8929] | 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("configure") |
---|
| 82 | size = getMinTextSize(P.sampleWindow) |
---|
| 83 | P.configWidth = size[2]+20 |
---|
| 84 | |
---|
| 85 | P.sampleWindow:setText("reset") |
---|
| 86 | size = getMinTextSize(P.sampleWindow) |
---|
| 87 | P.resetWidth = size[2]+20 |
---|
| 88 | |
---|
| 89 | P.spaceWidth = math.floor(1/8*P.configWidth) |
---|
| 90 | |
---|
| 91 | P.createLines() |
---|
| 92 | |
---|
[8079] | 93 | P:setButton(1, 1, { |
---|
| 94 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"), |
---|
| 95 | ["callback"] = P.MiscConfigBackButton_clicked |
---|
| 96 | }) |
---|
[7006] | 97 | end |
---|
| 98 | |
---|
| 99 | function P.createLine(k) |
---|
| 100 | local offset = 0 |
---|
| 101 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
| 102 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
| 103 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
| 104 | |
---|
| 105 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
| 106 | command:setText(P.nameList[k]) |
---|
| 107 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
| 108 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
| 109 | line:addChildWindow(command) |
---|
| 110 | offset = offset + P.commandWidth + P.spaceWidth |
---|
| 111 | |
---|
| 112 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
| 113 | configvalue:setProperty("ReadOnly", "set:False") |
---|
[7284] | 114 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
[7006] | 115 | configvalue:setText(value) |
---|
| 116 | P.sampleWindow:setText(value) |
---|
| 117 | local size = getMinTextSize(P.sampleWindow) |
---|
| 118 | local configvalueWidth = 2*size[2] |
---|
| 119 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0))) |
---|
| 120 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 121 | line:addChildWindow(configvalue) |
---|
| 122 | offset = offset + configvalueWidth + P.spaceWidth |
---|
| 123 | |
---|
| 124 | local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config") |
---|
| 125 | config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0))) |
---|
| 126 | config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
| 127 | config:setText("configure") |
---|
| 128 | orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked") |
---|
| 129 | line:addChildWindow(config) |
---|
| 130 | offset = offset + P.configWidth + P.spaceWidth |
---|
| 131 | |
---|
| 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") |
---|
| 136 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked") |
---|
| 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 | |
---|
| 159 | function P.MiscConfigReset_clicked(e) |
---|
| 160 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 161 | local name = we.window:getName() |
---|
| 162 | |
---|
| 163 | local match = string.gmatch(name, "%d+") |
---|
| 164 | local commandNr = tonumber(match()) |
---|
| 165 | |
---|
| 166 | -- TODO: Implement reset. |
---|
| 167 | end |
---|
| 168 | |
---|
| 169 | function P.MiscConfigConfigure_clicked(e) |
---|
| 170 | local we = CEGUI.toWindowEventArgs(e) |
---|
| 171 | local name = we.window:getName() |
---|
| 172 | |
---|
| 173 | local match = string.gmatch(name, "%d+") |
---|
| 174 | local commandNr = tonumber(match()) |
---|
| 175 | |
---|
| 176 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
| 177 | |
---|
[7013] | 178 | orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText()) |
---|
[7284] | 179 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
[7006] | 180 | window:setText(value) |
---|
| 181 | end |
---|
| 182 | |
---|
| 183 | function P.MiscConfigBackButton_clicked(e) |
---|
| 184 | hideMenuSheet("MiscConfigMenu") |
---|
| 185 | end |
---|
| 186 | |
---|
| 187 | return P |
---|