Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentationHS13/data/gui/scripts/MiscConfigMenu.lua @ 10066

Last change on this file since 10066 was 9904, checked in by smerkli, 11 years ago

Merged branch radarDreiD into presentationbranch

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