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
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_")
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_")
[7006]36    table.insert(P.commandList, "ChatOverlay displayTime_")
[8079]37    table.insert(P.commandList, "Core bDevMode_")
[9016]38    table.insert(P.commandList, "HUDNavigation MarkerLimit_")
39    table.insert(P.commandList, "HUDNavigation showDistance")
[9904]40    table.insert(P.commandList, "HUDRadar RadarMode_")
[7006]41
42    P.nameList = {}
[7013]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")
[7403]57    table.insert(P.nameList, "TeamDeathmatch: Number of teams")
[7013]58    table.insert(P.nameList, "Playername")
59    table.insert(P.nameList, "Chat: display time")
[8079]60    table.insert(P.nameList, "Developer's Mode")
[9016]61    table.insert(P.nameList, "Marker Limit")
62    table.insert(P.nameList, "Show Distance next to cursor")
[9904]63    table.insert(P.nameList, "Set Radar on 3D mode")
[7006]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
[9016]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
[7006]92
93    P.createLines()
94
[8079]95    P:setButton(1, 1, {
[9016]96            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"),
97            ["callback"]  = P.MiscConfigCancelButton_clicked
[8079]98    })
[9016]99   
100    P:setButton(1, 2, {
101            ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"),
102            ["callback"]  = P.MiscConfigOKButton_clicked
103    })
[7006]104end
105
106function P.createLine(k)
107    local offset = 0
[9016]108    -- content window for the entire line
[7006]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
[9016]113    -- config name
[7006]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
[9016]121    -- config value (editable)
[7006]122    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
123    configvalue:setProperty("ReadOnly", "set:False")
[7284]124    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k])
[7006]125    configvalue:setText(value)
[9016]126    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0)))
[7006]127    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
[9016]128    -- enable the reset button if the value changed
129    orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted")
[7006]130    line:addChildWindow(configvalue)
[9016]131    offset = offset + P.editboxWidth + P.spaceWidth
[7006]132
[9016]133    -- reset button (only available when value changed)
[7006]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")
[9016]138    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked")
[7006]139    line:addChildWindow(reset)
[7013]140    reset:setEnabled(false)
[7006]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
[9016]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)
[7006]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
[9016]184    local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset")
185    resetButton:setEnabled(true)
[7006]186end
187
[9016]188function P.MiscConfigResetButton_clicked(e)
[7006]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
[9016]195    -- reload the old value
196    local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
[7284]197    local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr])
[9016]198    editbox:setText(value)
199   
200    we.window:setEnabled(false)
[7006]201end
202
203return P
Note: See TracBrowser for help on using the repository browser.