Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/release2012/data/gui/scripts/MiscConfigMenu.lua @ 11772

Last change on this file since 11772 was 9376, checked in by jo, 12 years ago

I added the new configValue from TeamDeathmatch to the Miscellaneous menu.

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