Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/data/gui/scripts/MiscConfigMenu.lua @ 9692

Last change on this file since 9692 was 9016, checked in by jo, 13 years ago

Merging presentation2011 branch to trunk. Please check for possible bugs.

  • 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, "HumanPlayer nick_")
36    table.insert(P.commandList, "ChatOverlay displayTime_")
37    table.insert(P.commandList, "Core bDevMode_")
38    table.insert(P.commandList, "HUDNavigation MarkerLimit_")
39    table.insert(P.commandList, "HUDNavigation showDistance")
40
41    P.nameList = {}
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")
56    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
57    table.insert(P.nameList, "Playername")
58    table.insert(P.nameList, "Chat: display time")
59    table.insert(P.nameList, "Developer's Mode")
60    table.insert(P.nameList, "Marker Limit")
61    table.insert(P.nameList, "Show Distance next to cursor")
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("reset")
82    size = getMinTextSize(P.sampleWindow)
83    P.resetWidth = size[2]+20
84
85    P.spaceWidth = 10
86   
87    local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane")
88    size = pane:getViewableArea()
89    P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth
90
91    P.createLines()
92
93    P:setButton(1, 1, {
94            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"),
95            ["callback"]  = P.MiscConfigCancelButton_clicked
96    })
97   
98    P:setButton(1, 2, {
99            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"),
100            ["callback"]  = P.MiscConfigOKButton_clicked
101    })
102end
103
104function P.createLine(k)
105    local offset = 0
106    -- content window for the entire line
107    local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
108    line:setHeight(CEGUI.UDim(0, P.lineHeight))
109    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
110
111    -- config name
112    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
113    command:setText(P.nameList[k])
114    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
115    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
116    line:addChildWindow(command)
117    offset = offset + P.commandWidth + P.spaceWidth
118
119    -- config value (editable)
120    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
121    configvalue:setProperty("ReadOnly", "set:False")
122    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
123    configvalue:setText(value)
124    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
125    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
126    -- enable the reset button if the value changed
127    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted")
128    line:addChildWindow(configvalue)
129    offset = offset + P.editboxWidth + P.spaceWidth
130
131    -- reset button (only available when value changed)
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 .. ".MiscConfigResetButton_clicked")
137    line:addChildWindow(reset)
138    reset:setEnabled(false)
139    offset = offset + P.resetWidth + P.spaceWidth
140
141    line:setWidth(CEGUI.UDim(0, offset))
142
143    return line
144end
145
146function 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))
157end
158
159function P.MiscConfigOKButton_clicked(e)
160    for k,v in pairs(P.commandList) do
161        -- save the changes
162        local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
163        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
164        local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
165        resetButton:setEnabled(false)
166    end
167   
168    hideMenuSheet("MiscConfigMenu")
169end
170
171function P.MiscConfigCancelButton_clicked(e)
172    hideMenuSheet("MiscConfigMenu")
173end
174
175function P.MiscConfigEditbox_textAccepted(e)
176    local we = CEGUI.toWindowEventArgs(e)
177    local name = we.window:getName()
178
179    local match = string.gmatch(name, "%d+")
180    local commandNr = tonumber(match())
181
182    local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
183    resetButton:setEnabled(true)
184end
185
186function P.MiscConfigResetButton_clicked(e)
187    local we = CEGUI.toWindowEventArgs(e)
188    local name = we.window:getName()
189
190    local match = string.gmatch(name, "%d+")
191    local commandNr = tonumber(match())
192
193    -- reload the old value
194    local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
195    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
196    editbox:setText(value)
197   
198    we.window:setEnabled(false)
199end
200
201return P
Note: See TracBrowser for help on using the repository browser.