Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/data/gui/scripts/MiscConfigMenu.lua @ 7007

Last change on this file since 7007 was 7006, checked in by dafrick, 15 years ago

Added Menu to display and edit config values.
But the list of available config values has still to be populated and editing doesn't work yet.

File size: 5.1 KB
Line 
1-- MiscConfigMenu.lua
2
3local P = createMenuSheet("MiscConfigMenu")
4
5P.commandList = {}
6P.nameList = {}
7P.linesList = {}
8
9P.sampleWindow = nil
10
11P.lineHeight = 0
12P.commandWidth = 0
13P.configWidth = 0
14P.resetWidth = 0
15P.spaceWidth = 0
16
17function P.onLoad()
18
19    P.commandList = {}
20    table.insert(P.commandList, "ChatOverlay displayTime_")
21
22    P.nameList = {}
23    table.insert(P.nameList, "ChatOverlay: display time")
24
25    P.linesList = {}
26
27    --Calculate design parameters:
28    P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow")
29    P.sampleWindow:setText("SampleText")
30
31    local size = getMinTextSize(P.sampleWindow)
32    P.lineHeight = size[1]
33
34    P.commandWidth = 0
35    for k,v in pairs(P.commandList) do
36        P.sampleWindow:setText(P.nameList[k])
37        size = getMinTextSize(P.sampleWindow)
38        if size[2] > P.commandWidth then
39            P.commandWidth = size[2]
40        end
41    end
42
43    P.sampleWindow:setText("configure")
44    size = getMinTextSize(P.sampleWindow)
45    P.configWidth = size[2]+20
46
47    P.sampleWindow:setText("reset")
48    size = getMinTextSize(P.sampleWindow)
49    P.resetWidth = size[2]+20
50
51    P.spaceWidth = math.floor(1/8*P.configWidth)
52
53    P.createLines()
54
55end
56
57function P.createLine(k)
58    local offset = 0
59    local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k)
60    line:setHeight(CEGUI.UDim(0, P.lineHeight))
61    line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1))))
62
63    local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command")
64    command:setText(P.nameList[k])
65    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0)))
66    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
67    line:addChildWindow(command)
68    offset = offset + P.commandWidth + P.spaceWidth
69
70    local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue")
71    configvalue:setProperty("ReadOnly", "set:False")
72    orxonox.CommandExecutor:execute("getConfig " .. P.commandList[k])
73    local value = orxonox.CommandExecutor:getReturnValueString()
74    configvalue:setText(value)
75    P.sampleWindow:setText(value)
76    local size = getMinTextSize(P.sampleWindow)
77    local configvalueWidth = 2*size[2]
78    configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0)))
79    configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
80    line:addChildWindow(configvalue)
81    offset = offset + configvalueWidth + P.spaceWidth
82
83    local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config")
84    config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0)))
85    config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
86    config:setText("configure")
87    orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked")
88    line:addChildWindow(config)
89    offset = offset + P.configWidth + P.spaceWidth
90
91    local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset")
92    reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0)))
93    reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0)))
94    reset:setText("reset")
95    orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked")
96    line:addChildWindow(reset)
97    offset = offset + P.resetWidth + P.spaceWidth
98
99    line:setWidth(CEGUI.UDim(0, offset))
100
101    return line
102end
103
104function P.createLines()
105    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane")
106
107    for k,v in pairs(P.commandList) do
108        local line = P.createLine(k)
109        table.insert(P.linesList, line)
110        window:addChildWindow(line)
111    end
112
113    local pane = tolua.cast(window, "CEGUI::ScrollablePane")
114    pane:setVerticalStepSize(getScrollingStepSize(window))
115end
116
117function P.MiscConfigReset_clicked(e)
118    local we = CEGUI.toWindowEventArgs(e)
119    local name = we.window:getName()
120
121    local match = string.gmatch(name, "%d+")
122    local commandNr = tonumber(match())
123
124    -- TODO: Implement reset.
125end
126
127function P.MiscConfigConfigure_clicked(e)
128    local we = CEGUI.toWindowEventArgs(e)
129    local name = we.window:getName()
130
131    local match = string.gmatch(name, "%d+")
132    local commandNr = tonumber(match())
133
134    local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue")
135
136    -- TODO: tconfig or permanent?
137    orxonox.CommandExecutor:execute("tconfig " .. P.commandList[commandNr] .. " " .. window:getText())
138    orxonox.CommandExecutor:execute("getConfig " .. P.commandList[commandNr])
139    local value = orxonox.CommandExecutor:getReturnValueString()
140    window:setText(value)
141end
142
143function P.MiscConfigBackButton_clicked(e)
144    hideMenuSheet("MiscConfigMenu")
145end
146
147return P
Note: See TracBrowser for help on using the repository browser.