Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11356 was 11356, checked in by patricwi, 7 years ago

merged space race with trunk

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