Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/fabienHS15/data/gui/scripts/SingleplayerConfigMenu.lua @ 10724

Last change on this file since 10724 was 9665, checked in by landauf, 11 years ago

removed svn:executable property

  • Property svn:eol-style set to native
File size: 8.0 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", "orxonox/SingleplayerConfigMenu/MiscConfigPane/SampleWindow")
19    P.sampleWindow:setText("SampleText")
20
21    P:setButton(1, 1, {
22            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigMenu/CancelButton"),
23            ["callback"]  = P.SingleplayerConfigCancelButton_clicked
24    })
25   
26    P:setButton(1, 2, {
27            ["button"] = winMgr:getWindow("orxonox/SingleplayerConfigMenu/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, "TeamDeathmatch 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, "TeamDeathmatch: 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(winMgr:getWindow("orxonox/SingleplayerConfigMenu/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    if winMgr:isWindowPresent("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k) then
101        winMgr:destroyWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k)
102    end
103    -- content window for the entire line
104    local line = winMgr:createWindow("DefaultWindow", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k)
105    line:setHeight(CEGUI.UDim(0, P.lineHeight))
106    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
107
108    -- config name
109    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
110    command:setText(P.nameList[k])
111    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
112    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
113    line:addChildWindow(command)
114    offset = offset + P.commandWidth + P.spaceWidth
115
116    -- config value (editable)
117    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
118    configvalue:setProperty("ReadOnly", "set:False")
119    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
120    configvalue:setText(value)
121    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
122    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
123    -- enable the reset button if the value changed
124    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".SingleplayerConfigEditbox_textAccepted")
125    line:addChildWindow(configvalue)
126    offset = offset + P.editboxWidth + P.spaceWidth
127
128    -- reset button (only available when value changed)
129    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
130    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
131    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
132    reset:setText("reset")
133    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".SingleplayerConfigResetButton_clicked")
134    line:addChildWindow(reset)
135    reset:setEnabled(false)
136    offset = offset + P.resetWidth + P.spaceWidth
137
138    line:setWidth(CEGUI.UDim(0, offset))
139
140    return line
141end
142
143function P.createLines()
144    local window = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane")
145
146    for k,v in pairs(P.commandList) do
147        local line = P.createLine(k)
148        table.insert(P.linesList, line)
149        window:addChildWindow(line)
150    end
151
152    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
153    pane:setVerticalStepSize(getScrollingStepSize(window))
154end
155
156function P.SingleplayerConfigOKButton_clicked(e)
157    for k,v in pairs(P.commandList) do
158        -- save the changes
159        local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
160        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
161        local resetButton = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
162        resetButton:setEnabled(false)
163    end
164   
165    hideMenuSheet("SingleplayerConfigMenu")
166end
167
168function P.SingleplayerConfigCancelButton_clicked(e)
169    hideMenuSheet("SingleplayerConfigMenu")
170end
171
172function P.SingleplayerConfigEditbox_textAccepted(e)
173    local we = CEGUI.toWindowEventArgs(e)
174    local name = we.window:getName()
175
176    local match = string.gmatch(name, "%d+")
177    local commandNr = tonumber(match())
178
179    local resetButton = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
180    resetButton:setEnabled(true)
181end
182
183function P.SingleplayerConfigResetButton_clicked(e)
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
190    -- reload the old value
191    local editbox = winMgr:getWindow("orxonox/SingleplayerConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
192    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
193    editbox:setText(value)
194   
195    we.window:setEnabled(false)
196end
197
198return P
Note: See TracBrowser for help on using the repository browser.