Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11269 was 9977, checked in by jo, 10 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
RevLine 
[7006]1-- MiscConfigMenu.lua
2
[8729]3local P = createMenuSheet("MiscConfigMenu", true, tribool(true), tribool(true))
[7006]4
5P.commandList = {}
6P.nameList = {}
7P.linesList = {}
8
9P.sampleWindow = nil
10
11P.lineHeight = 0
12P.commandWidth = 0
[9016]13P.editboxWidth = 0
[7006]14P.resetWidth = 0
15P.spaceWidth = 0
16
17function P.onLoad()
18
19    P.commandList = {}
[7013]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_")
[9977]32    table.insert(P.commandList, "Gametype bAutoEnd_")
[7013]33    table.insert(P.commandList, "Gametype numberOfBots_")
34    table.insert(P.commandList, "UnderAttack gameTime_")
35    table.insert(P.commandList, "TeamDeathmatch teams_")
[9941]36    table.insert(P.commandList, "TeamDeathmatch maxScore_")
[7013]37    table.insert(P.commandList, "HumanPlayer nick_")
[7006]38    table.insert(P.commandList, "ChatOverlay displayTime_")
[8079]39    table.insert(P.commandList, "Core bDevMode_")
[9016]40    table.insert(P.commandList, "HUDNavigation MarkerLimit_")
41    table.insert(P.commandList, "HUDNavigation showDistance")
[9939]42    table.insert(P.commandList, "HUDRadar RadarMode_")
[7006]43
44    P.nameList = {}
[7013]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")
[9977]57    table.insert(P.nameList, "Autoend")
[7013]58    table.insert(P.nameList, "Number of Bots")
59    table.insert(P.nameList, "UnderAttack: game time")
[7403]60    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
[9941]61    table.insert(P.nameList, "TeamDeathmatch: Score needed to end the game")
[7013]62    table.insert(P.nameList, "Playername")
63    table.insert(P.nameList, "Chat: display time")
[8079]64    table.insert(P.nameList, "Developer's Mode")
[9016]65    table.insert(P.nameList, "Marker Limit")
66    table.insert(P.nameList, "Show Distance next to cursor")
[9939]67    table.insert(P.nameList, "Set Radar on 3D mode")
[7006]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
[9016]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
[7006]96
97    P.createLines()
98
[8079]99    P:setButton(1, 1, {
[9016]100            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"),
101            ["callback"]  = P.MiscConfigCancelButton_clicked
[8079]102    })
[9016]103   
104    P:setButton(1, 2, {
105            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"),
106            ["callback"]  = P.MiscConfigOKButton_clicked
107    })
[7006]108end
109
110function P.createLine(k)
111    local offset = 0
[9016]112    -- content window for the entire line
[7006]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
[9016]117    -- config name
[7006]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
[9016]125    -- config value (editable)
[7006]126    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
127    configvalue:setProperty("ReadOnly", "set:False")
[7284]128    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
[7006]129    configvalue:setText(value)
[9016]130    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
[7006]131    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
[9016]132    -- enable the reset button if the value changed
133    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted")
[7006]134    line:addChildWindow(configvalue)
[9016]135    offset = offset + P.editboxWidth + P.spaceWidth
[7006]136
[9016]137    -- reset button (only available when value changed)
[7006]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")
[9016]142    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked")
[7006]143    line:addChildWindow(reset)
[7013]144    reset:setEnabled(false)
[7006]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
[9016]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)
[7006]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
[9016]188    local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
189    resetButton:setEnabled(true)
[7006]190end
191
[9016]192function P.MiscConfigResetButton_clicked(e)
[7006]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
[9016]199    -- reload the old value
200    local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
[7284]201    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
[9016]202    editbox:setText(value)
203   
204    we.window:setEnabled(false)
[7006]205end
206
207return P
Note: See TracBrowser for help on using the repository browser.