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.configWidth = 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 | |
---|
38 | P.nameList = {} |
---|
39 | table.insert(P.nameList, "Mouse sensitivity") |
---|
40 | table.insert(P.nameList, "Mouse acceleration") |
---|
41 | table.insert(P.nameList, "Derive mouse input") |
---|
42 | table.insert(P.nameList, "Mouse wheel stepsize") |
---|
43 | table.insert(P.nameList, "Shell: max. History length") |
---|
44 | table.insert(P.nameList, "Start IOConsole") |
---|
45 | table.insert(P.nameList, "FPS limit") |
---|
46 | table.insert(P.nameList, "Spectator speed") |
---|
47 | table.insert(P.nameList, "Invert Y-axis") |
---|
48 | table.insert(P.nameList, "Default level") |
---|
49 | table.insert(P.nameList, "Start countdown") |
---|
50 | table.insert(P.nameList, "Autostart") |
---|
51 | table.insert(P.nameList, "Number of Bots") |
---|
52 | table.insert(P.nameList, "UnderAttack: game time") |
---|
53 | table.insert(P.nameList, "TeamDeathmatch: Number of teams") |
---|
54 | table.insert(P.nameList, "Playername") |
---|
55 | table.insert(P.nameList, "Chat: display time") |
---|
56 | |
---|
57 | P.linesList = {} |
---|
58 | |
---|
59 | --Calculate design parameters: |
---|
60 | P.sampleWindow = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/SampleWindow") |
---|
61 | P.sampleWindow:setText("SampleText") |
---|
62 | |
---|
63 | local size = getMinTextSize(P.sampleWindow) |
---|
64 | P.lineHeight = size[1] |
---|
65 | |
---|
66 | P.commandWidth = 0 |
---|
67 | for k,v in pairs(P.commandList) do |
---|
68 | P.sampleWindow:setText(P.nameList[k]) |
---|
69 | size = getMinTextSize(P.sampleWindow) |
---|
70 | if size[2] > P.commandWidth then |
---|
71 | P.commandWidth = size[2] |
---|
72 | end |
---|
73 | end |
---|
74 | |
---|
75 | P.sampleWindow:setText("configure") |
---|
76 | size = getMinTextSize(P.sampleWindow) |
---|
77 | P.configWidth = size[2]+20 |
---|
78 | |
---|
79 | P.sampleWindow:setText("reset") |
---|
80 | size = getMinTextSize(P.sampleWindow) |
---|
81 | P.resetWidth = size[2]+20 |
---|
82 | |
---|
83 | P.spaceWidth = math.floor(1/8*P.configWidth) |
---|
84 | |
---|
85 | P.createLines() |
---|
86 | |
---|
87 | P:setButton(1, 1, { |
---|
88 | ["button"] = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigBackButton"), |
---|
89 | ["callback"] = P.MiscConfigBackButton_clicked |
---|
90 | }) |
---|
91 | end |
---|
92 | |
---|
93 | function P.createLine(k) |
---|
94 | local offset = 0 |
---|
95 | local line = winMgr:createWindow("DefaultWindow", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k) |
---|
96 | line:setHeight(CEGUI.UDim(0, P.lineHeight)) |
---|
97 | line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, P.lineHeight*(k-1)))) |
---|
98 | |
---|
99 | local command = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Command") |
---|
100 | command:setText(P.nameList[k]) |
---|
101 | command:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.commandWidth), CEGUI.UDim(1, 0))) |
---|
102 | command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0))) |
---|
103 | line:addChildWindow(command) |
---|
104 | offset = offset + P.commandWidth + P.spaceWidth |
---|
105 | |
---|
106 | local configvalue = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Configvalue") |
---|
107 | configvalue:setProperty("ReadOnly", "set:False") |
---|
108 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[k]) |
---|
109 | configvalue:setText(value) |
---|
110 | P.sampleWindow:setText(value) |
---|
111 | local size = getMinTextSize(P.sampleWindow) |
---|
112 | local configvalueWidth = 2*size[2] |
---|
113 | configvalue:setSize(CEGUI.UVector2(CEGUI.UDim(0, configvalueWidth), CEGUI.UDim(0.9, 0))) |
---|
114 | configvalue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
115 | line:addChildWindow(configvalue) |
---|
116 | offset = offset + configvalueWidth + P.spaceWidth |
---|
117 | |
---|
118 | local config = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Config") |
---|
119 | config:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.configWidth), CEGUI.UDim(0.9, 0))) |
---|
120 | config:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
121 | config:setText("configure") |
---|
122 | orxonox.GUIManager:subscribeEventHelper(config, "Clicked", P.name .. ".MiscConfigConfigure_clicked") |
---|
123 | line:addChildWindow(config) |
---|
124 | offset = offset + P.configWidth + P.spaceWidth |
---|
125 | |
---|
126 | local reset = winMgr:createWindow("MenuWidgets/Button", "orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. k .. "/Reset") |
---|
127 | reset:setSize(CEGUI.UVector2(CEGUI.UDim(0, P.resetWidth), CEGUI.UDim(0.9, 0))) |
---|
128 | reset:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.05, 0))) |
---|
129 | reset:setText("reset") |
---|
130 | orxonox.GUIManager:subscribeEventHelper(reset, "Clicked", P.name .. ".MiscConfigReset_clicked") |
---|
131 | line:addChildWindow(reset) |
---|
132 | reset:setEnabled(false) |
---|
133 | offset = offset + P.resetWidth + P.spaceWidth |
---|
134 | |
---|
135 | line:setWidth(CEGUI.UDim(0, offset)) |
---|
136 | |
---|
137 | return line |
---|
138 | end |
---|
139 | |
---|
140 | function P.createLines() |
---|
141 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane") |
---|
142 | |
---|
143 | for k,v in pairs(P.commandList) do |
---|
144 | local line = P.createLine(k) |
---|
145 | table.insert(P.linesList, line) |
---|
146 | window:addChildWindow(line) |
---|
147 | end |
---|
148 | |
---|
149 | local pane = tolua.cast(window, "CEGUI::ScrollablePane") |
---|
150 | pane:setVerticalStepSize(getScrollingStepSize(window)) |
---|
151 | end |
---|
152 | |
---|
153 | function P.MiscConfigReset_clicked(e) |
---|
154 | local we = CEGUI.toWindowEventArgs(e) |
---|
155 | local name = we.window:getName() |
---|
156 | |
---|
157 | local match = string.gmatch(name, "%d+") |
---|
158 | local commandNr = tonumber(match()) |
---|
159 | |
---|
160 | -- TODO: Implement reset. |
---|
161 | end |
---|
162 | |
---|
163 | function P.MiscConfigConfigure_clicked(e) |
---|
164 | local we = CEGUI.toWindowEventArgs(e) |
---|
165 | local name = we.window:getName() |
---|
166 | |
---|
167 | local match = string.gmatch(name, "%d+") |
---|
168 | local commandNr = tonumber(match()) |
---|
169 | |
---|
170 | local window = winMgr:getWindow("orxonox/MiscConfigMenu/MiscConfigPane/ConfigCommand" .. commandNr .. "/Configvalue") |
---|
171 | |
---|
172 | orxonox.CommandExecutor:execute("config " .. P.commandList[commandNr] .. " " .. window:getText()) |
---|
173 | local value = orxonox.CommandExecutor:query("getConfig " .. P.commandList[commandNr]) |
---|
174 | window:setText(value) |
---|
175 | end |
---|
176 | |
---|
177 | function P.MiscConfigBackButton_clicked(e) |
---|
178 | hideMenuSheet("MiscConfigMenu") |
---|
179 | end |
---|
180 | |
---|
181 | return P |
---|