Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10777 was 9977, checked in by jo, 11 years ago

So far so good. Unfortunately I did not figure out what is wrong with the timer.

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