Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/data/gui/scripts/SingleplayerConfigMenu.lua @ 12128

Last change on this file since 12128 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
Line 
1-- SingleplayerMenu.lua
2
3local P = createMenuSheet("SingleplayerConfigMenu")
4
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()
18    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "ConfigWindow/Wrapper/MiscConfigPane/SampleWindow")
19    P.sampleWindow:setText("SampleText")
20
21    P:setButton(1, 1, {
22            ["button"] = P.window:getChild("CancelButton"),
23            ["callback"]  = P.SingleplayerConfigCancelButton_clicked
24    })
25   
26    P:setButton(1, 2, {
27            ["button"] = P.window:getChild("OKButton"),
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_")
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")
48    table.insert(P.commandList, "TeamGametype teams_")
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")
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")
66    table.insert(P.nameList, "TeamGametype: Number of teams")
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   
90    local pane = tolua.cast(P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane"), "CEGUI::ScrollablePane")
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
99    -- destroy config line, if it already exists (otherwise would cause an error)
100    local oldLine = P.window:getChildRecursive("ConfigCommand" .. k)
101    if oldLine ~= nil then
102        winMgr:destroyWindow(oldLine)
103    end
104    -- content window for the entire line
105    local line = winMgr:createWindow("DefaultWindow", "ConfigCommand" .. k)
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
109    -- config name
110    local command = winMgr:createWindow("MenuWidgets/StaticText", "Command")
111    command:setText(P.nameList[k])
112    command:setSize(CEGUI.USize(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
113    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
114    line:addChild(command)
115    offset = offset + P.commandWidth + P.spaceWidth
116
117    -- config value (editable)
118    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "Configvalue")
119    configvalue:setProperty("ReadOnly", "set:False")
120    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
121    configvalue:setText(value)
122    configvalue:setSize(CEGUI.USize(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
123    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
124    -- enable the reset button if the value changed
125    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".SingleplayerConfigEditbox_textAccepted")
126    line:addChild(configvalue)
127    offset = offset + P.editboxWidth + P.spaceWidth
128
129    -- reset button (only available when value changed)
130    local reset = winMgr:createWindow("MenuWidgets/Button", "Reset")
131    reset:setSize(CEGUI.USize(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
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")
135    line:addChild(reset)
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()
145    local window = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane")
146
147    for k,v in pairs(P.commandList) do
148        local line = P.createLine(k)
149        table.insert(P.linesList, line)
150        window:addChild(line)
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
159        -- save the changes
160        local editbox = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
161        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
162        local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
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)
175    local name = we.window:getNamePath()
176
177    local match = string.gmatch(name, "%d+")
178    local commandNr = tonumber(match())
179
180    local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
181    resetButton:setEnabled(true)
182end
183
184function P.SingleplayerConfigResetButton_clicked(e)
185    local we = CEGUI.toWindowEventArgs(e)
186    local name = we.window:getNamePath()
187
188    local match = string.gmatch(name, "%d+")
189    local commandNr = tonumber(match())
190
191    -- reload the old value
192    local editbox = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
193    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
194    editbox:setText(value)
195   
196    we.window:setEnabled(false)
197end
198
199return P
Note: See TracBrowser for help on using the repository browser.