File src/ChorusConfFrame.lua changed (mode: 100644) (index 334ce7a..dd83aaf) |
2 |
2 |
@submodule chorus |
@submodule chorus |
3 |
3 |
]] |
]] |
4 |
4 |
|
|
|
5 |
|
local strtrim = strtrim |
|
6 |
|
|
|
7 |
|
local InCombatLockdown = Chorus.test.InCombatLockdown or InCombatLockdown |
|
8 |
|
|
|
9 |
|
local Chorus = Chorus |
|
10 |
|
|
|
11 |
|
CHORUS_CONF_FRAME_SUB_TEXT = 'To drag and move Chorus frames with your mouse, ' .. |
|
12 |
|
'check the box labeled `Movable`, then click the `Okay` button. Then, drag and ' .. |
|
13 |
|
'move the frames as required. ' .. |
|
14 |
|
"\n\nWARNING: Configuration can only be done out of combat." |
|
15 |
|
|
|
16 |
|
local CHORUS_DEFAULT_PROFILE_NAME = 'main' |
|
17 |
|
|
5 |
18 |
local movableFrameList = { |
local movableFrameList = { |
6 |
19 |
ChorusSoloFrame, |
ChorusSoloFrame, |
7 |
20 |
ChorusPartyFrame, |
ChorusPartyFrame, |
|
... |
... |
local movableFrameList = { |
10 |
23 |
ChorusLargeRaidFrame, |
ChorusLargeRaidFrame, |
11 |
24 |
} |
} |
12 |
25 |
|
|
|
26 |
|
--[[-- |
|
27 |
|
Allow the position of the given frame to be set by the user clicking and |
|
28 |
|
dragging their mouse on the frame. |
|
29 |
|
|
|
30 |
|
@function movableEnable |
|
31 |
|
@tparam frame frame the frame to enable dragging on |
|
32 |
|
@return nothing, only produces side effects |
|
33 |
|
]] |
13 |
34 |
local function movableEnable(frame) |
local function movableEnable(frame) |
14 |
35 |
assert(frame ~= nil) |
assert(frame ~= nil) |
15 |
36 |
|
|
|
... |
... |
local function movableEnable(frame) |
34 |
55 |
end |
end |
35 |
56 |
end |
end |
36 |
57 |
|
|
|
58 |
|
--[[-- |
|
59 |
|
Lock the position of the given frame. User will not be able to click and drag |
|
60 |
|
it. |
|
61 |
|
|
|
62 |
|
@function movableDisable |
|
63 |
|
@tparam frame frame the frame to disable dragging on |
|
64 |
|
@return nothing, only produces side effects |
|
65 |
|
]] |
37 |
66 |
local function movableDisable(frame) |
local function movableDisable(frame) |
38 |
67 |
assert(frame ~= nil) |
assert(frame ~= nil) |
39 |
68 |
|
|
|
... |
... |
local function movableDisable(frame) |
58 |
87 |
end |
end |
59 |
88 |
end |
end |
60 |
89 |
|
|
61 |
|
local function savePoints(conf, profileName, frame) |
|
|
90 |
|
--[[-- |
|
91 |
|
Check if given string is a valid token. A valid token starts with a lower case |
|
92 |
|
letter, and contains only letters, numerals or underscores. |
|
93 |
|
|
|
94 |
|
There should be a similar validator for record names and currently isn't. |
|
95 |
|
Profile name does not allow for capital letters. Record names allow for capital |
|
96 |
|
letters, to map exactly to frame names. Additionally, profile name is input by |
|
97 |
|
user, and record names are programmed by developers. Therefore, there is less |
|
98 |
|
need for validation for the record names. |
|
99 |
|
|
|
100 |
|
@function isValidToken |
|
101 |
|
@tparam string someToken a string to validate |
|
102 |
|
@treturn boolean `true` if valid, `false` otherwise |
|
103 |
|
@treturn string error message, useful for `function assert` |
|
104 |
|
]] |
|
105 |
|
local function isValidToken(someToken) |
|
106 |
|
return someToken == string.match(someToken, '[a-z]+[a-z0-9_]'), |
|
107 |
|
'a token must begin with a lower case letter, and only contain lowercase letters, digits or underscores' |
|
108 |
|
end |
|
109 |
|
|
|
110 |
|
--[[-- |
|
111 |
|
Access a specific configuration profile from all existing profiles. |
|
112 |
|
|
|
113 |
|
If requested profile does not exist, fail with an error. |
|
114 |
|
|
|
115 |
|
This function is not explicitly aware of any persistency mechanisms. |
|
116 |
|
|
|
117 |
|
@function getConfProfile |
|
118 |
|
@tparam table conf a map of configuration profiles |
|
119 |
|
@tparam string profileName token, that is a table key, that is the name of the required configuration profile |
|
120 |
|
@treturn table the configuration profile, that is a map of frame records |
|
121 |
|
]] |
|
122 |
|
local function getConfProfile(conf, profileName) |
62 |
123 |
assert(conf ~= nil) |
assert(conf ~= nil) |
63 |
124 |
assert('table' == type(conf)) |
assert('table' == type(conf)) |
64 |
125 |
|
|
|
126 |
|
profileName = profileName or CHORUS_DEFAULT_PROFILE_NAME |
65 |
127 |
assert(profileName ~= nil) |
assert(profileName ~= nil) |
66 |
128 |
assert('string' == type(profileName)) |
assert('string' == type(profileName)) |
67 |
|
profileName = strtrim(profileName) |
|
68 |
|
assert(string.len(profileName) >= 1) |
|
69 |
|
assert(string.len(profileName) <= 256) |
|
|
129 |
|
assert(isValidToken(profileName)) |
70 |
130 |
|
|
|
131 |
|
local profile = conf[profileName] |
|
132 |
|
assert(profile ~= nil, |
|
133 |
|
'failed to find configuration profile "' .. tostring(profileName) .. '"') |
|
134 |
|
assert('table' == type(profile)) |
|
135 |
|
|
|
136 |
|
return profile |
|
137 |
|
end |
|
138 |
|
|
|
139 |
|
--[[-- |
|
140 |
|
Access a configuration record with context specific values. |
|
141 |
|
|
|
142 |
|
If requested record does not exist, create an empty record. |
|
143 |
|
|
|
144 |
|
This function is not explicitly aware of any persistency mechanisms. |
|
145 |
|
|
|
146 |
|
@function getConfRecord |
|
147 |
|
|
|
148 |
|
@tparam table conf a map of configuration profiles |
|
149 |
|
|
|
150 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
151 |
|
required configuration profile |
|
152 |
|
|
|
153 |
|
@tparam string recordName token, that is a table key, conventionally a valid |
|
154 |
|
frame name, that is the name of a configuration record |
|
155 |
|
|
|
156 |
|
@treturn table configuration record for the given name that is a key-value table |
|
157 |
|
]] |
|
158 |
|
local function getConfRecord(conf, profileName, recordName) |
|
159 |
|
local profile = getConfProfile(conf, profileName) |
|
160 |
|
if not profile[recordName] then |
|
161 |
|
profile[recordName] = {} |
|
162 |
|
end |
|
163 |
|
|
|
164 |
|
local record = profile[recordName] |
|
165 |
|
assert(record ~= nil) |
|
166 |
|
assert('table' == type(record)) |
|
167 |
|
|
|
168 |
|
return record |
|
169 |
|
end |
|
170 |
|
|
|
171 |
|
--[[-- |
|
172 |
|
Read the present position of the given frame and write it to the given |
|
173 |
|
configuration profile. |
|
174 |
|
|
|
175 |
|
@function savePoints |
|
176 |
|
|
|
177 |
|
@tparam table conf a map of configuration profiles |
|
178 |
|
|
|
179 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
180 |
|
required configuration profile |
|
181 |
|
|
|
182 |
|
@tparam frame frame given frame which position is to be saved |
|
183 |
|
|
|
184 |
|
@treturn nothing, all changes are written to the tables provided as arguments |
|
185 |
|
]] |
|
186 |
|
local function savePoints(conf, profileName, frame) |
71 |
187 |
assert(frame ~= nil) |
assert(frame ~= nil) |
72 |
188 |
|
|
73 |
189 |
local n = frame:GetName() |
local n = frame:GetName() |
|
... |
... |
local function savePoints(conf, profileName, frame) |
81 |
197 |
return |
return |
82 |
198 |
end |
end |
83 |
199 |
|
|
84 |
|
local confProfile = conf[profileName] |
|
85 |
|
assert(confProfile ~= nil) |
|
86 |
|
assert('table' == type(confProfile)) |
|
87 |
|
|
|
88 |
|
local frameSettings = confProfile[n] |
|
89 |
|
if not frameSettings then |
|
90 |
|
frameSettings = {} |
|
91 |
|
end |
|
92 |
|
assert(frameSettings ~= nil) |
|
93 |
|
assert('table' == type(frameSettings)) |
|
|
200 |
|
local frameSettings = getConfRecord(conf, profileName, n) |
94 |
201 |
|
|
95 |
202 |
local record = {} |
local record = {} |
96 |
203 |
local i = 0 |
local i = 0 |
97 |
|
while (i < 8) do |
|
|
204 |
|
local j = math.min(math.max(0, math.floor(frame:GetNumPoints())), 8) |
|
205 |
|
while (i < j) do |
98 |
206 |
i = i + 1 |
i = i + 1 |
99 |
207 |
local point = {frame:GetPoint(i)} |
local point = {frame:GetPoint(i)} |
100 |
208 |
if point[1] then |
if point[1] then |
|
209 |
|
local relativeFrame = point[2] |
|
210 |
|
if relativeFrame then |
|
211 |
|
point[2] = relativeFrame:GetName() |
|
212 |
|
end |
101 |
213 |
record[i] = point |
record[i] = point |
102 |
214 |
end |
end |
103 |
215 |
end |
end |
104 |
216 |
|
|
105 |
217 |
frameSettings.points = record |
frameSettings.points = record |
|
218 |
|
end |
|
219 |
|
|
|
220 |
|
--[[-- |
|
221 |
|
Set the position of the given frame. |
|
222 |
|
|
|
223 |
|
Configuration records that saved variables mechanism persist require some |
|
224 |
|
interpretation before they can be applied to the game state. Specifically, the |
|
225 |
|
saved variables do not persist frame handles, only primitive values. |
|
226 |
|
|
|
227 |
|
@function applyPoint |
|
228 |
|
@tparam frame frame given frame which position to set |
|
229 |
|
@tparam string anchor same as `FRAME:SetPoint` |
|
230 |
|
@tparam string relativeFrameName frame name or `nil`, will be interpreted |
|
231 |
|
@tparam string relativeAnchor same as `FRAME:SetPoint` |
|
232 |
|
@tparam number x same as `FRAME:SetPoint` |
|
233 |
|
@tparam number y same as `FRAME:SetPoint` |
|
234 |
|
@treturn nothing, changes are applied to the frame provided as argument |
|
235 |
|
]] |
|
236 |
|
local function applyPoint(frame, anchor, relativeFrameName, relativeAnchor, x, y) |
|
237 |
|
assert(frame ~= nil) |
|
238 |
|
|
|
239 |
|
assert(anchor ~= nil) |
|
240 |
|
assert('string' == type(anchor)) |
|
241 |
|
|
|
242 |
|
local relativeFrame = nil |
|
243 |
|
if relativeFrameName then |
|
244 |
|
assert('string' == type(relativeFrameName)) |
|
245 |
|
relativeFrameName = strtrim(relativeFrameName) |
|
246 |
|
relativeFrame = _G[relativeFrameName] |
|
247 |
|
end |
106 |
248 |
|
|
107 |
|
confProfile[n] = frameSettings |
|
|
249 |
|
assert(x ~= nil) |
|
250 |
|
assert('number' == type(x)) |
|
251 |
|
|
|
252 |
|
assert(y ~= nil) |
|
253 |
|
assert('number' == type(y)) |
|
254 |
|
|
|
255 |
|
if nil == relativeFrameName and tostring(anchor) == tostring(relativeAnchor) then |
|
256 |
|
frame:SetPoint(anchor, x, y) |
|
257 |
|
elseif relativeFrame and relativeAnchor then |
|
258 |
|
frame:SetPoint(anchor, relativeFrame, relativeAnchor, x, y) |
|
259 |
|
else |
|
260 |
|
error('unexpected point format') |
|
261 |
|
end |
108 |
262 |
end |
end |
109 |
263 |
|
|
110 |
|
local function loadPoints(conf, profileName, frame) |
|
111 |
|
assert(conf ~= nil) |
|
112 |
|
assert('table' == type(conf)) |
|
|
264 |
|
--[[-- |
|
265 |
|
Read the given configuration profile and apply it's position settings to the |
|
266 |
|
given frame. |
113 |
267 |
|
|
114 |
|
assert(profileName ~= nil) |
|
115 |
|
assert('string' == type(profileName)) |
|
116 |
|
profileName = strtrim(profileName) |
|
117 |
|
assert(string.len(profileName) >= 1) |
|
118 |
|
assert(string.len(profileName) <= 256) |
|
|
268 |
|
@function loadPoints |
|
269 |
|
|
|
270 |
|
@tparam table conf a map of configuration profiles |
|
271 |
|
|
|
272 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
273 |
|
required configuration profile |
119 |
274 |
|
|
|
275 |
|
@tparam frame frame given frame which position is to be set |
|
276 |
|
|
|
277 |
|
@treturn nothing, given frame current position will change |
|
278 |
|
]] |
|
279 |
|
local function loadPoints(conf, profileName, frame) |
120 |
280 |
assert(frame ~= nil) |
assert(frame ~= nil) |
121 |
281 |
|
|
122 |
282 |
local n = frame:GetName() |
local n = frame:GetName() |
|
... |
... |
local function loadPoints(conf, profileName, frame) |
130 |
290 |
return |
return |
131 |
291 |
end |
end |
132 |
292 |
|
|
133 |
|
local confProfile = conf[profileName] |
|
134 |
|
assert(confProfile ~= nil, |
|
135 |
|
'profile "' .. profileName .. '" does not exist') |
|
136 |
|
|
|
137 |
|
local frameSettings = confProfile[n] |
|
138 |
|
if not frameSettings then |
|
139 |
|
return |
|
140 |
|
end |
|
|
293 |
|
local frameSettings = getConfRecord(conf, profileName, n) |
141 |
294 |
|
|
142 |
295 |
local points = frameSettings.points |
local points = frameSettings.points |
143 |
296 |
assert(points ~= nil, 'no frame position saved') |
assert(points ~= nil, 'no frame position saved') |
144 |
297 |
assert('table' == type(points)) |
assert('table' == type(points)) |
|
298 |
|
frame:ClearAllPoints() |
145 |
299 |
local i = 0 |
local i = 0 |
146 |
300 |
while (i < math.min(#points, 8)) do |
while (i < math.min(#points, 8)) do |
147 |
301 |
i = i + 1 |
i = i + 1 |
148 |
302 |
local point = points[i] |
local point = points[i] |
149 |
303 |
assert(point ~= nil) |
assert(point ~= nil) |
150 |
304 |
assert('table' == type(point)) |
assert('table' == type(point)) |
151 |
|
if point[1] then |
|
152 |
|
frame:SetPoint(unpack(point)) |
|
153 |
|
end |
|
|
305 |
|
applyPoint(frame, unpack(point)) |
154 |
306 |
end |
end |
155 |
307 |
end |
end |
156 |
308 |
|
|
157 |
|
local function confApply(confFrame) |
|
158 |
|
assert(confFrame ~= nil) |
|
|
309 |
|
--[[-- |
|
310 |
|
Read the given configuration profile, then set the state of widgets and other |
|
311 |
|
frames accordingly. |
|
312 |
|
|
|
313 |
|
Note, this function does not deal with movable frame positions. |
|
314 |
|
|
|
315 |
|
@function confRead |
|
316 |
|
|
|
317 |
|
@tparam table conf a map of configuration profiles |
|
318 |
|
|
|
319 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
320 |
|
required configuration profile |
|
321 |
|
]] |
|
322 |
|
local function confRead(conf, profileName) |
|
323 |
|
local movableCheckbox = ChorusConfMovableCheckBox |
|
324 |
|
assert(movableCheckbox ~= nil) |
|
325 |
|
|
|
326 |
|
local n = movableCheckbox:GetName() |
|
327 |
|
assert(n ~= nil) |
|
328 |
|
|
|
329 |
|
local checkboxRecord = getConfRecord(conf, profileName, n) |
|
330 |
|
|
|
331 |
|
checkboxRecord.checkedFlag = 1 == movableCheckbox:GetChecked() |
|
332 |
|
end |
|
333 |
|
|
|
334 |
|
--[[-- |
|
335 |
|
Read the current state of relevant widgets and frames, and write to the given |
|
336 |
|
configuration profile. |
159 |
337 |
|
|
160 |
|
local flag = 1 == ChorusConfMovableCheckBox:GetChecked() |
|
|
338 |
|
Note, this function does not deal with movable frame positions. |
|
339 |
|
|
|
340 |
|
@function confWrite |
|
341 |
|
|
|
342 |
|
@tparam table conf a map of configuration profiles |
|
343 |
|
|
|
344 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
345 |
|
required configuration profile |
|
346 |
|
]] |
|
347 |
|
local function confWrite(conf, profileName) |
|
348 |
|
local movableCheckbox = ChorusConfMovableCheckBox |
|
349 |
|
assert(movableCheckbox ~= nil) |
|
350 |
|
|
|
351 |
|
local n = movableCheckbox:GetName() |
|
352 |
|
assert(n ~= nil) |
|
353 |
|
|
|
354 |
|
local checkboxRecord = getConfRecord(conf, profileName, n) |
|
355 |
|
movableCheckbox:SetChecked(checkboxRecord.checkedFlag) |
|
356 |
|
end |
|
357 |
|
|
|
358 |
|
--[[-- |
|
359 |
|
Read the current position of all movable frames, and write values to the |
|
360 |
|
configuration profile. |
|
361 |
|
|
|
362 |
|
@function movableRead |
|
363 |
|
|
|
364 |
|
@tparam table conf a map of configuration profiles |
|
365 |
|
|
|
366 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
367 |
|
required configuration profile |
|
368 |
|
]] |
|
369 |
|
local function movableRead(conf, profileName) |
|
370 |
|
local i = 0 |
|
371 |
|
while (i < #movableFrameList) do |
|
372 |
|
i = i + 1 |
|
373 |
|
local f = movableFrameList[i] |
|
374 |
|
assert(f ~= nil) |
|
375 |
|
savePoints(conf, profileName, f) |
|
376 |
|
end |
|
377 |
|
end |
|
378 |
|
|
|
379 |
|
--[[-- |
|
380 |
|
Read the given configuraiton profile, and set all movable frame positions |
|
381 |
|
accordingly. |
|
382 |
|
|
|
383 |
|
@function movableWrite |
|
384 |
|
|
|
385 |
|
@tparam table conf a map of configuration profiles |
|
386 |
|
|
|
387 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
388 |
|
required configuration profile |
|
389 |
|
]] |
|
390 |
|
local function movableWrite(conf, profileName) |
|
391 |
|
local i = 0 |
|
392 |
|
while (i < #movableFrameList) do |
|
393 |
|
i = i + 1 |
|
394 |
|
local f = movableFrameList[i] |
|
395 |
|
assert(f ~= nil) |
|
396 |
|
loadPoints(conf, profileName, f) |
|
397 |
|
end |
|
398 |
|
end |
|
399 |
|
|
|
400 |
|
--[[-- |
|
401 |
|
Lock or unlock movable frames for user to drag accordingly with current |
|
402 |
|
configuration profile. |
|
403 |
|
|
|
404 |
|
@function movableToggle |
|
405 |
|
|
|
406 |
|
@tparam table conf a map of configuration profiles |
|
407 |
|
|
|
408 |
|
@tparam string profileName token, that is a table key, that is the name of the |
|
409 |
|
required configuration profile |
|
410 |
|
]] |
|
411 |
|
local function movableToggle(conf, profileName) |
|
412 |
|
local checkboxRecord = getConfRecord(conf, profileName, 'ChorusConfMovableCheckBox') |
|
413 |
|
local flag = checkboxRecord.checkedFlag |
161 |
414 |
|
|
162 |
415 |
local i = 0 |
local i = 0 |
163 |
416 |
while (i < #movableFrameList) do |
while (i < #movableFrameList) do |
|
... |
... |
local function confApply(confFrame) |
169 |
422 |
else |
else |
170 |
423 |
movableDisable(f) |
movableDisable(f) |
171 |
424 |
end |
end |
172 |
|
savePoints(ChorusConf, ChorusConfProfileName, f) |
|
173 |
425 |
end |
end |
174 |
426 |
end |
end |
175 |
427 |
|
|
|
428 |
|
--[[-- |
|
429 |
|
Run every time user clicks `Okay` button in configuration frame. |
|
430 |
|
|
|
431 |
|
First it reads the state of configuration widgets, then persists the values |
|
432 |
|
with saved variables mechanism. |
|
433 |
|
|
|
434 |
|
@see confRead |
|
435 |
|
@see movableToggle |
|
436 |
|
@see movableRead |
|
437 |
|
|
|
438 |
|
@function confOkay |
|
439 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
440 |
|
]] |
|
441 |
|
local function confOkay(confFrame) |
|
442 |
|
assert(confFrame ~= nil) |
|
443 |
|
|
|
444 |
|
confRead(ChorusConf, ChorusConfProfileName) |
|
445 |
|
movableToggle(ChorusConf, ChorusConfProfileName) |
|
446 |
|
movableRead(ChorusConf, ChorusConfProfileName) |
|
447 |
|
end |
|
448 |
|
|
|
449 |
|
--[[-- |
|
450 |
|
Run every time user opens configuration frame. |
|
451 |
|
|
|
452 |
|
Sets the state of configuration widgets accordingly to current configuration |
|
453 |
|
profile. |
|
454 |
|
|
|
455 |
|
@see confWrite |
|
456 |
|
@see movableToggle |
|
457 |
|
@see movableRead |
|
458 |
|
|
|
459 |
|
@function confRefresh |
|
460 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
461 |
|
]] |
|
462 |
|
local function confRefresh(confFrame) |
|
463 |
|
assert(confFrame ~= nil) |
|
464 |
|
|
|
465 |
|
confWrite(ChorusConf, ChorusConfProfileName) |
|
466 |
|
end |
|
467 |
|
|
|
468 |
|
--[[-- |
|
469 |
|
Run every time user clicks `Cancel` button in the configuration frame, or |
|
470 |
|
otherwise exits configuration frame without confirming changes. |
|
471 |
|
|
|
472 |
|
Resets the state of configuration widgets accordingly to current configuration |
|
473 |
|
profile, without commiting partial changes. |
|
474 |
|
|
|
475 |
|
@see confWrite |
|
476 |
|
@see movableToggle |
|
477 |
|
@see movableWrite |
|
478 |
|
|
|
479 |
|
@function confCancel |
|
480 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
481 |
|
]] |
176 |
482 |
local function confCancel(confFrame) |
local function confCancel(confFrame) |
177 |
|
ChorusConfMovableCheckBox:SetChecked(false) |
|
|
483 |
|
assert(confFrame ~= nil) |
178 |
484 |
|
|
179 |
|
confApply(confFrame) |
|
|
485 |
|
confWrite(ChorusConf, ChorusConfProfileName) |
|
486 |
|
movableToggle(ChorusConf, ChorusConfProfileName) |
|
487 |
|
movableWrite(ChorusConf, ChorusConfProfileName) |
180 |
488 |
end |
end |
181 |
489 |
|
|
|
490 |
|
--[[-- |
|
491 |
|
Run every time user clicks `Defaults` button in the configuration frame. |
|
492 |
|
|
|
493 |
|
Sets the state of all movable frames and configuration widgets to sane |
|
494 |
|
defaults, resets current configuration profile and persists the changes. |
|
495 |
|
|
|
496 |
|
@see confRead |
|
497 |
|
@see movableToggle |
|
498 |
|
@see movableRead |
|
499 |
|
|
|
500 |
|
@function confDefault |
|
501 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
502 |
|
]] |
182 |
503 |
local function confDefault(confFrame) |
local function confDefault(confFrame) |
|
504 |
|
assert(confFrame ~= nil) |
|
505 |
|
|
183 |
506 |
ChorusConfMovableCheckBox:SetChecked(false) |
ChorusConfMovableCheckBox:SetChecked(false) |
184 |
507 |
|
|
185 |
508 |
local i = 0 |
local i = 0 |
|
... |
... |
local function confDefault(confFrame) |
202 |
525 |
ChorusSmallRaidFrame:SetPoint('TOPLEFT', 0, 0) |
ChorusSmallRaidFrame:SetPoint('TOPLEFT', 0, 0) |
203 |
526 |
ChorusLargeRaidFrame:SetPoint('TOPLEFT', 0, 0) |
ChorusLargeRaidFrame:SetPoint('TOPLEFT', 0, 0) |
204 |
527 |
|
|
205 |
|
confApply(confFrame) |
|
|
528 |
|
confRead(ChorusConf, ChorusConfProfileName) |
|
529 |
|
movableToggle(ChorusConf, ChorusConfProfileName) |
|
530 |
|
movableRead(ChorusConf, ChorusConfProfileName) |
206 |
531 |
end |
end |
207 |
532 |
|
|
|
533 |
|
--[[-- |
|
534 |
|
Should be run once after all saved variables are loaded. Applies current |
|
535 |
|
configuration profile to the game state. |
|
536 |
|
|
|
537 |
|
@function confFrameEventProcessor |
|
538 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
539 |
|
]] |
208 |
540 |
local function confFrameEventProcessor(confFrame) |
local function confFrameEventProcessor(confFrame) |
209 |
541 |
assert(confFrame ~= nil) |
assert(confFrame ~= nil) |
210 |
542 |
|
|
211 |
|
ChorusConf = ChorusConf or {['main'] = {}} |
|
212 |
|
ChorusConfProfileName = ChorusConfProfileName or 'main' |
|
|
543 |
|
ChorusConf = ChorusConf or {CHORUS_DEFAULT_PROFILE_NAME = {}} |
|
544 |
|
ChorusConfProfileName = ChorusConfProfileName or CHORUS_DEFAULT_PROFILE_NAME |
213 |
545 |
|
|
214 |
|
local i = 0 |
|
215 |
|
while (i < #movableFrameList) do |
|
216 |
|
i = i + 1 |
|
217 |
|
local f = movableFrameList[i] |
|
218 |
|
assert(f ~= nil) |
|
219 |
|
loadPoints(ChorusConf, ChorusConfProfileName, f) |
|
220 |
|
end |
|
|
546 |
|
confWrite(ChorusConf, ChorusConfProfileName) |
|
547 |
|
movableToggle(ChorusConf, ChorusConfProfileName) |
|
548 |
|
movableWrite(ChorusConf, ChorusConfProfileName) |
221 |
549 |
end |
end |
222 |
550 |
|
|
223 |
|
function Chorus.confFrameMain(confFrame) |
|
|
551 |
|
--[[-- |
|
552 |
|
Initialize configuration frame. |
|
553 |
|
|
|
554 |
|
User configuration feature heavily relies on saved variables mechanism. This |
|
555 |
|
mechanism persists Lua tables and primitives as plain text files, that are |
|
556 |
|
saved between game sessions. When user enters world, these files are loaded and |
|
557 |
|
drive the game user interface state. |
|
558 |
|
|
|
559 |
|
All user configuration options are persisted in a single key value table |
|
560 |
|
`ChorusConf`. Each key in configuration map is a profile name. By default, |
|
561 |
|
there is only one profile, `main`. |
|
562 |
|
|
|
563 |
|
The current configuration profile that is to be used by the script is set by |
|
564 |
|
`ChorusConfProfileName`, by default it is set to `main`. |
|
565 |
|
|
|
566 |
|
Each configuration profile is a key value table. Each key in the configuration |
|
567 |
|
profile is a record name, that is usually a valid frame name, and each value is |
|
568 |
|
a record. A record is a table with configuration values. |
|
569 |
|
|
|
570 |
|
@function confFrameMain |
|
571 |
|
@tparam frame confFrame configuration frame that holds configuration widgets |
|
572 |
|
]] |
|
573 |
|
local function confFrameMain(confFrame) |
224 |
574 |
assert(confFrame ~= nil) |
assert(confFrame ~= nil) |
225 |
575 |
|
|
226 |
576 |
local n = GetAddOnMetadata('chorus', 'Title') or 'chorus' |
local n = GetAddOnMetadata('chorus', 'Title') or 'chorus' |
|
... |
... |
function Chorus.confFrameMain(confFrame) |
230 |
580 |
|
|
231 |
581 |
confFrame.name = n |
confFrame.name = n |
232 |
582 |
|
|
233 |
|
confFrame.okay = confApply |
|
|
583 |
|
confFrame.okay = confOkay |
234 |
584 |
|
|
235 |
585 |
confFrame.cancel = confCancel |
confFrame.cancel = confCancel |
236 |
586 |
|
|
237 |
587 |
confFrame.default = confDefault |
confFrame.default = confDefault |
238 |
588 |
|
|
239 |
|
confFrame.refresh = confApply |
|
|
589 |
|
confFrame.refresh = confRefresh |
240 |
590 |
|
|
241 |
591 |
InterfaceOptions_AddCategory(confFrame) |
InterfaceOptions_AddCategory(confFrame) |
242 |
592 |
|
|
243 |
593 |
confFrame:RegisterEvent('VARIABLES_LOADED') |
confFrame:RegisterEvent('VARIABLES_LOADED') |
244 |
594 |
confFrame:SetScript('OnEvent', confFrameEventProcessor) |
confFrame:SetScript('OnEvent', confFrameEventProcessor) |
245 |
595 |
end |
end |
|
596 |
|
|
|
597 |
|
Chorus.confFrameMain = confFrameMain |