1 | -- MiscConfigMenu.lua |
---|
2 | |
---|
3 | local P = createMenuSheet("MiscConfigMenu", true, tribool(true), tribool(true)) |
---|
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.editboxWidth = 0 |
---|
14 | P.resetWidth = 0 |
---|
15 | P.spaceWidth = 0 |
---|
16 | |
---|
17 | function P.onLoad() |
---|
18 | |
---|
19 | P.commandList = {} |
---|
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_") |
---|
36 | table.insert(P.commandList, "ChatOverlay displayTime_") |
---|
37 | table.insert(P.commandList, "Core bDevMode_") |
---|
38 | |
---|
39 | P.nameList = {} |
---|
40 | table.insert(P.nameList, "Mouse sensitivity") |
---|
41 | table.insert(P.nameList, "Mouse acceleration") |
---|
42 | table.insert(P.nameList, "Derive mouse input") |
---|
43 | table.insert(P.nameList, "Mouse wheel stepsize") |
---|
44 | table.insert(P.nameList, "Shell: max. History length") |
---|
45 | table.insert(P.nameList, "Start IOConsole") |
---|
46 | table.insert(P.nameList, "FPS limit") |
---|
47 | table.insert(P.nameList, "Spectator speed") |
---|
48 | table.insert(P.nameList, "Invert Y-axis") |
---|
49 | table.insert(P.nameList, "Default level") |
---|
50 | table.insert(P.nameList, "Start countdown") |
---|
51 | table.insert(P.nameList, "Autostart") |
---|
52 | table.insert(P.nameList, "Number of Bots") |
---|
53 | table.insert(P.nameList, "UnderAttack: game time") |
---|
54 | table.insert(P.nameList, "TeamDeathmatch: Number of teams") |
---|
55 | table.insert(P.nameList, "Playername") |
---|
56 | table.insert(P.nameList, "Chat: display time") |
---|
57 | table.insert(P.nameList, "Developer's Mode") |
---|
58 | |
---|
59 | P.linesList = {} |
---|
60 | |
---|
61 | --Calculate design parameters: |
---|
62 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
63 | P.sampleWindow:setText("SampleText") |
---|
64 | |
---|
65 | local size = getMinTextSize(P.sampleWindow) |
---|
66 | P.lineHeight = size[1] |
---|
67 | |
---|
68 | P.commandWidth = 0 |
---|
69 | for k,v in pairs(P.commandList) do |
---|
70 | P.sampleWindow:setText(P.nameList[k]) |
---|
71 | size = getMinTextSize(P.sampleWindow) |
---|
72 | if size[2] > P.commandWidth then |
---|
73 | P.commandWidth = size[2] |
---|
74 | end |
---|
75 | end |
---|
76 | |
---|
77 | P.sampleWindow:setText("reset") |
---|
78 | size = getMinTextSize(P.sampleWindow) |
---|
79 | P.resetWidth = size[2]+20 |
---|
80 | |
---|
81 | P.spaceWidth = 10 |
---|
82 | |
---|
83 | local pane = tolua.cast(winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane"), "CEGUI::ScrollablePane") |
---|
84 | size = pane:getViewableArea() |
---|
85 | P.editboxWidth = size:getWidth() - P.commandWidth - P.resetWidth - 5*P.spaceWidth |
---|
86 | |
---|
87 | P.createLines() |
---|
88 | |
---|
89 | P:setButton(1, 1, { |
---|
90 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/CancelButton"), |
---|
91 | ["callback"] = P.MiscConfigCancelButton_clicked |
---|
92 | }) |
---|
93 | |
---|
94 | P:setButton(1, 2, { |
---|
95 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/OKButton"), |
---|
96 | ["callback"] = P.MiscConfigOKButton_clicked |
---|
97 | }) |
---|
98 | end |
---|
99 | |
---|
100 | function P.createLine(k) |
---|
101 | local offset = 0 |
---|
102 | -- content window for the entire line |
---|
103 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
104 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
105 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
106 | |
---|
107 | -- config name |
---|
108 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
109 | command:setText(P.nameList[k]) |
---|
110 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
111 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
112 | line:addChildWindow(command) |
---|
113 | offset = offset + P.commandWidth + P.spaceWidth |
---|
114 | |
---|
115 | -- config value (editable) |
---|
116 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
117 | configvalue:setProperty("ReadOnly", "set:False") |
---|
118 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
119 | configvalue:setText(value) |
---|
120 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.editboxWidth), CEGUI.UDim(0.9, 0))) |
---|
121 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
122 | -- enable the reset button if the value changed |
---|
123 | orxonox.GUIManager:subscribeEventHelper(configvalue, "TextAccepted", P.name .. ".MiscConfigEditbox_textAccepted") |
---|
124 | line:addChildWindow(configvalue) |
---|
125 | offset = offset + P.editboxWidth + P.spaceWidth |
---|
126 | |
---|
127 | -- reset button (only available when value changed) |
---|
128 | local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
129 | reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) |
---|
130 | reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
131 | reset:setText("reset") |
---|
132 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigResetButton_clicked") |
---|
133 | line:addChildWindow(reset) |
---|
134 | reset:setEnabled(false) |
---|
135 | offset = offset + P.resetWidth + P.spaceWidth |
---|
136 | |
---|
137 | line:setWidth(CEGUI.UDim(0, offset)) |
---|
138 | |
---|
139 | return line |
---|
140 | end |
---|
141 | |
---|
142 | function P.createLines() |
---|
143 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane") |
---|
144 | |
---|
145 | for k,v in pairs(P.commandList) do |
---|
146 | local line = P.createLine(k) |
---|
147 | table.insert(P.linesList, line) |
---|
148 | window:addChildWindow(line) |
---|
149 | end |
---|
150 | |
---|
151 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
152 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
153 | end |
---|
154 | |
---|
155 | function P.MiscConfigOKButton_clicked(e) |
---|
156 | for k,v in pairs(P.commandList) do |
---|
157 | -- save the changes |
---|
158 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
159 | orxonox.CommandExecutor:execute("config " .. P.commandList[k] .. " " .. editbox:getText()) |
---|
160 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
161 | resetButton:setEnabled(false) |
---|
162 | end |
---|
163 | |
---|
164 | hideMenuSheet("MiscConfigMenu") |
---|
165 | end |
---|
166 | |
---|
167 | function P.MiscConfigCancelButton_clicked(e) |
---|
168 | hideMenuSheet("MiscConfigMenu") |
---|
169 | end |
---|
170 | |
---|
171 | function P.MiscConfigEditbox_textAccepted(e) |
---|
172 | local we = CEGUI.toWindowEventArgs(e) |
---|
173 | local name = we.window:getName() |
---|
174 | |
---|
175 | local match = string.gmatch(name, "%d+") |
---|
176 | local commandNr = tonumber(match()) |
---|
177 | |
---|
178 | local resetButton = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Reset") |
---|
179 | resetButton:setEnabled(true) |
---|
180 | end |
---|
181 | |
---|
182 | function P.MiscConfigResetButton_clicked(e) |
---|
183 | local we = CEGUI.toWindowEventArgs(e) |
---|
184 | local name = we.window:getName() |
---|
185 | |
---|
186 | local match = string.gmatch(name, "%d+") |
---|
187 | local commandNr = tonumber(match()) |
---|
188 | |
---|
189 | -- reload the old value |
---|
190 | local editbox = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
191 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
192 | editbox:setText(value) |
---|
193 | |
---|
194 | we.window:setEnabled(false) |
---|
195 | end |
---|
196 | |
---|
197 | return P |
---|