1 | -- MiscConfigMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("MiscConfigMenu") |
---|
4 | |
---|
5 | P.commandList = {} |
---|
6 | P.nameList = {} |
---|
7 | P.linesList = {} |
---|
8 | |
---|
9 | P.sampleWindow = nil |
---|
10 | |
---|
11 | P.lineHeight = 0 |
---|
12 | P.commandWidth = 0 |
---|
13 | P.configWidth = 0 |
---|
14 | P.resetWidth = 0 |
---|
15 | P.spaceWidth = 0 |
---|
16 | |
---|
17 | function 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 | |
---|
55 | end |
---|
56 | |
---|
57 | function 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 |
---|
102 | end |
---|
103 | |
---|
104 | function 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)) |
---|
115 | end |
---|
116 | |
---|
117 | function 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. |
---|
125 | end |
---|
126 | |
---|
127 | function 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) |
---|
141 | end |
---|
142 | |
---|
143 | function P.MiscConfigBackButton_clicked(e) |
---|
144 | hideMenuSheet("MiscConfigMenu") |
---|
145 | end |
---|
146 | |
---|
147 | return P |
---|