Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/data/gui/scripts/MiscConfigMenu.lua @ 12176

Last change on this file since 12176 was 11800, checked in by landauf, 7 years ago

updated Settings.lua and all sub-menus to cegui 0.8

  • Property svn:eol-style set to native
File size: 7.8 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_")
[11800]25    table.insert(P.commandList, "CoreConfig bStartIOConsole_")
26    table.insert(P.commandList, "GraphicsSettings fpsLimit")
[7013]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_")
[11800]35    table.insert(P.commandList, "TeamGametype 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_")
[11800]39    table.insert(P.commandList, "CoreConfig bDevMode_")
[9016]40    table.insert(P.commandList, "HUDNavigation MarkerLimit_")
[11800]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")
[11800]60    table.insert(P.nameList, "TeamGametype: 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:
[11800]72    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "MiscConfigMenu/MiscConfigPane/SampleWindow")
[7006]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   
[11800]93    local pane = tolua.cast(P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane"), "CEGUI::ScrollablePane")
[9016]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, {
[11800]100            ["button"] = P.window:getChild("CancelButton"),
[9016]101            ["callback"]  = P.MiscConfigCancelButton_clicked
[8079]102    })
[9016]103   
104    P:setButton(1, 2, {
[11800]105            ["button"] = P.window:getChild("OKButton"),
[9016]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
[11800]113    local line = winMgr:createWindow("DefaultWindow", "ConfigCommand" .. k)
[7006]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
[11800]118    local command = winMgr:createWindow("MenuWidgets/StaticText", "Command")
[7006]119    command:setText(P.nameList[k])
[11800]120    command:setSize(CEGUI.USize(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
[7006]121    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
[11800]122    line:addChild(command)
[7006]123    offset = offset + P.commandWidth + P.spaceWidth
124
[9016]125    -- config value (editable)
[11800]126    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "Configvalue")
[7006]127    configvalue:setProperty("ReadOnly", "set:False")
[7284]128    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
[7006]129    configvalue:setText(value)
[11800]130    configvalue:setSize(CEGUI.USize(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")
[11800]134    line:addChild(configvalue)
[9016]135    offset = offset + P.editboxWidth + P.spaceWidth
[7006]136
[9016]137    -- reset button (only available when value changed)
[11800]138    local reset = winMgr:createWindow("MenuWidgets/Button", "Reset")
139    reset:setSize(CEGUI.USize(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
[7006]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")
[11800]143    line:addChild(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()
[11800]153    local window = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane")
[7006]154
155    for k,v in pairs(P.commandList) do
156        local line = P.createLine(k)
157        table.insert(P.linesList, line)
[11800]158        window:addChild(line)
[7006]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
[11800]168        local editbox = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
[9016]169        orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText())
[11800]170        local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
[9016]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)
[11800]183    local name = we.window:getNamePath()
[7006]184
185    local match = string.gmatch(name, "%d+")
186    local commandNr = tonumber(match())
187
[11800]188    local resetButton = P.window:getChild("ConfigWindow/Wrapper/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
[9016]189    resetButton:setEnabled(true)
[7006]190end
191
[9016]192function P.MiscConfigResetButton_clicked(e)
[7006]193    local we = CEGUI.toWindowEventArgs(e)
[11800]194    local name = we.window:getNamePath()
[7006]195
196    local match = string.gmatch(name, "%d+")
197    local commandNr = tonumber(match())
198
[9016]199    -- reload the old value
[11800]200    local editbox = P.window:getChild("ConfigWindow/Wrapper/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.