Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/SingleplayerConfigMenu.lua @ 12106

Last change on this file since 12106 was 11801, checked in by landauf, 7 years ago

fixed some config values; removed unused layout; renamed some background windows; removed unknown property

  • Property svn:eol-style set to native
File size: 7.5 KB
RevLine 
[8927]1-- SingleplayerMenu.lua
2
3local P = createMenuSheet("SingleplayerConfigMenu")
4
[8938]5P.commandList = {}
6P.nameList = {}
7P.linesList = {}
8
9P.sampleWindow = nil
10
11P.lineHeight = 0
12P.commandWidth = 0
13P.editboxWidth = 0
14P.resetWidth = 0
15P.spaceWidth = 0
16
17function P.onLoad()
[11799]18    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "ConfigWindow/Wrapper/MiscConfigPane/SampleWindow")
[8938]19    P.sampleWindow:setText("SampleText")
20
21    P:setButton(1, 1, {
[11799]22            ["button"] = P.window:getChild("CancelButton"),
[8938]23            ["callback"]  = P.SingleplayerConfigCancelButton_clicked
24    })
25   
26    P:setButton(1, 2, {
[11799]27            ["button"] = P.window:getChild("OKButton"),
[8938]28            ["callback"]  = P.SingleplayerConfigOKButton_clicked
29    })
30end
31
32function P.loadConfig(level)
33    P.commandList = {}
34    table.insert(P.commandList, "Gametype initialStartCountdown_")
35    table.insert(P.commandList, "Gametype bAutoStart_")
36    table.insert(P.commandList, "Gametype numberOfBots_")
[8945]37    table.insert(P.commandList, "Dynamicmatch gameTime_")
38    table.insert(P.commandList, "Dynamicmatch friendlyfire")
39    table.insert(P.commandList, "Dynamicmatch tutorial")
40    table.insert(P.commandList, "LastManStanding lives")
41    table.insert(P.commandList, "LastManStanding respawnDelay")
42    table.insert(P.commandList, "LastManStanding bNoPunishment")
43    table.insert(P.commandList, "LastManStanding bHardPunishment")
44    table.insert(P.commandList, "LastTeamStanding lives")
45    table.insert(P.commandList, "LastTeamStanding respawnDelay")
46    table.insert(P.commandList, "LastTeamStanding bNoPunishment")
47    table.insert(P.commandList, "LastTeamStanding bHardPunishment")
[11801]48    table.insert(P.commandList, "TeamGametype teams_")
[8938]49    table.insert(P.commandList, "UnderAttack gameTime_")
50
51    P.nameList = {}
52    table.insert(P.nameList, "Start countdown")
53    table.insert(P.nameList, "Autostart")
54    table.insert(P.nameList, "Number of Bots")
[8945]55    table.insert(P.nameList, "Dynamicmatch: game time")
56    table.insert(P.nameList, "Dynamicmatch: friendly fire")
57    table.insert(P.nameList, "Dynamicmatch: tutorial")
58    table.insert(P.nameList, "LastManStanding: lives")
59    table.insert(P.nameList, "LastManStanding: respawn delay")
60    table.insert(P.nameList, "LastManStanding: no punishment")
61    table.insert(P.nameList, "LastManStanding: hard punishment")
62    table.insert(P.nameList, "LastTeamStanding: lives")
63    table.insert(P.nameList, "LastTeamStanding: respawn delay")
64    table.insert(P.nameList, "LastTeamStanding: no punishment")
65    table.insert(P.nameList, "LastTeamStanding: hard punishment")
[11801]66    table.insert(P.nameList, "TeamGametype: Number of teams")
[8938]67    table.insert(P.nameList, "UnderAttack: game time")
68
69    P.linesList = {}
70   
71    --Calculate design parameters:
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
88    P.spaceWidth = 10
89   
[11799]90    local pane = tolua.cast(P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane"), "CEGUI::ScrollablePane")
[8938]91    size = pane:getViewableArea()
92    P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth
93
94    P.createLines()
95end
96
97function P.createLine(k)
98    local offset = 0
[8964]99    -- destroy config line, if it already exists (otherwise would cause an error)
[11799]100    local oldLine = P.window:getChildRecursive("ConfigCommand" .. k)
101    if oldLine ~= nil then
102        winMgr:destroyWindow(oldLine)
[8945]103    end
[8964]104    -- content window for the entire line
[11799]105    local line = winMgr:createWindow("DefaultWindow", "ConfigCommand" .. k)
[8938]106    line:setHeight(CEGUI.UDim(0, P.lineHeight))
107    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
108
[8964]109    -- config name
[11799]110    local command = winMgr:createWindow("MenuWidgets/StaticText", "Command")
[8938]111    command:setText(P.nameList[k])
[11799]112    command:setSize(CEGUI.USize(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
[8938]113    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
[11799]114    line:addChild(command)
[8938]115    offset = offset + P.commandWidth + P.spaceWidth
116
[8964]117    -- config value (editable)
[11799]118    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "Configvalue")
[8938]119    configvalue:setProperty("ReadOnly", "set:False")
120    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
121    configvalue:setText(value)
[11799]122    configvalue:setSize(CEGUI.USize(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
[8938]123    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
[8964]124    -- enable the reset button if the value changed
[8938]125    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".SingleplayerConfigEditbox_textAccepted")
[11799]126    line:addChild(configvalue)
[8938]127    offset = offset + P.editboxWidth + P.spaceWidth
128
[8964]129    -- reset button (only available when value changed)
[11799]130    local reset = winMgr:createWindow("MenuWidgets/Button", "Reset")
131    reset:setSize(CEGUI.USize(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
[8938]132    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
133    reset:setText("reset")
134    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".SingleplayerConfigResetButton_clicked")
[11799]135    line:addChild(reset)
[8938]136    reset:setEnabled(false)
137    offset = offset + P.resetWidth + P.spaceWidth
138
139    line:setWidth(CEGUI.UDim(0, offset))
140
141    return line
142end
143
144function P.createLines()
[11799]145    local window = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane")
[8938]146
147    for k,v in pairs(P.commandList) do
148        local line = P.createLine(k)
149        table.insert(P.linesList, line)
[11799]150        window:addChild(line)
[8938]151    end
152
153    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
154    pane:setVerticalStepSize(getScrollingStepSize(window))
155end
156
157function P.SingleplayerConfigOKButton_clicked(e)
158    for k,v in pairs(P.commandList) do
[8964]159        -- save the changes
[11799]160        local editbox = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
[8938]161        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
[11799]162        local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
[8938]163        resetButton:setEnabled(false)
164    end
165   
166    hideMenuSheet("SingleplayerConfigMenu")
167end
168
169function P.SingleplayerConfigCancelButton_clicked(e)
170    hideMenuSheet("SingleplayerConfigMenu")
171end
172
173function P.SingleplayerConfigEditbox_textAccepted(e)
174    local we = CEGUI.toWindowEventArgs(e)
[11799]175    local name = we.window:getNamePath()
[8938]176
177    local match = string.gmatch(name, "%d+")
178    local commandNr = tonumber(match())
179
[11799]180    local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
[8938]181    resetButton:setEnabled(true)
182end
183
184function P.SingleplayerConfigResetButton_clicked(e)
185    local we = CEGUI.toWindowEventArgs(e)
[11799]186    local name = we.window:getNamePath()
[8938]187
188    local match = string.gmatch(name, "%d+")
189    local commandNr = tonumber(match())
190
[8964]191    -- reload the old value
[11799]192    local editbox = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
[8938]193    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
194    editbox:setText(value)
195   
196    we.window:setEnabled(false)
197end
198
[8927]199return P
Note: See TracBrowser for help on using the repository browser.