Mercurial > wow > buffalo2
comparison Init.lua @ 24:66b927b46776
Refine the XML data logic, and sort out some EnableMouse inconsistencies.
author | Nenue |
---|---|
date | Mon, 11 Apr 2016 09:07:40 -0400 |
parents | d5ee940de273 |
children | e84d645c8ab8 |
comparison
equal
deleted
inserted
replaced
23:e837384ac363 | 24:66b927b46776 |
---|---|
123 | 123 |
124 | 124 |
125 --- localize for speed | 125 --- localize for speed |
126 local layers, refs, displays = B.configLayers, B.configLayersRef, B.displays | 126 local layers, refs, displays = B.configLayers, B.configLayersRef, B.displays |
127 | 127 |
128 local ModulesCall = function(func) | 128 local ModulesCall = function(func, flag) |
129 | 129 |
130 local n = 0 | 130 local n = 0 |
131 for i = 1, #moduleStack do | 131 for i = 1, #moduleStack do |
132 print('calling level '..i) | 132 print('calling level '..i) |
133 local stackset = moduleStack[i] | 133 local stackset = moduleStack[i] |
134 | 134 |
135 for name, module in pairs(stackset) do | 135 for name, module in pairs(stackset) do |
136 n = n + 1 | 136 n = n + 1 |
137 print(n..' '..name..'.'..func..'()') | |
138 | 137 |
139 | 138 |
140 if module[func] then | 139 if module[func] then |
141 module[func](module) | 140 -- nil = pass |
141 if not flag or module.Conf[flag] then | |
142 if (flag) then | |
143 print(' check', flag, '=', module.Conf[flag]) | |
144 end | |
145 | |
146 print(' ',n..' '..name..'.'..func..'()') | |
147 module[func](module, module.Conf) | |
148 end | |
149 | |
142 end | 150 end |
143 end | 151 end |
144 end | 152 end |
145 end | 153 end |
146 | 154 |
159 local defaults = B.ConfDefaults | 167 local defaults = B.ConfDefaults |
160 print('|cFFFFFF00Veneer|r') | 168 print('|cFFFFFF00Veneer|r') |
161 if not VeneerData then | 169 if not VeneerData then |
162 VeneerData = {} | 170 VeneerData = {} |
163 for k,v in pairs(defaults) do | 171 for k,v in pairs(defaults) do |
172 | |
173 | |
164 VeneerData[k] = v | 174 VeneerData[k] = v |
165 end | 175 end |
166 print('Veneer defaults being used.') | 176 print('Veneer defaults being used.') |
167 end | 177 end |
168 | 178 |
236 | 246 |
237 | 247 |
238 for level, batch in ipairs(moduleStack) do | 248 for level, batch in ipairs(moduleStack) do |
239 print('config level', level) | 249 print('config level', level) |
240 for name, module in pairs(batch) do | 250 for name, module in pairs(batch) do |
251 if not VeneerData[name] then | |
252 VeneerData[name] = {} | |
253 end | |
254 | |
241 if module.defaults then | 255 if module.defaults then |
242 print('setting defaults for module', name) | 256 print('setting defaults for module', name) |
243 --[===[@non-debug@ | 257 --[===[@non-debug@ |
244 if not VeneerData[name] then | 258 if not VeneerData[name] then |
245 --@end-non-debug@]===] | 259 --@end-non-debug@]===] |
251 VeneerData[name][k] = v | 265 VeneerData[name][k] = v |
252 end | 266 end |
253 module.Conf = VeneerData[name] | 267 module.Conf = VeneerData[name] |
254 end | 268 end |
255 | 269 |
270 if VeneerData[name].enabled == nil then | |
271 VeneerData[name].enabled = true | |
272 end | |
273 | |
256 end | 274 end |
257 end | 275 end |
258 | 276 |
259 | 277 |
260 if #checkForConfig >= 1 then | 278 if #checkForConfig >= 1 then |
270 | 288 |
271 --- Fires an update to all modules | 289 --- Fires an update to all modules |
272 local lastUpdate | 290 local lastUpdate |
273 function B.UpdateAll(...) | 291 function B.UpdateAll(...) |
274 lastUpdate = GetTime() | 292 lastUpdate = GetTime() |
275 ModulesCall('OnUpdate', lastUpdate) | 293 ModulesCall('OnUpdate') |
276 end | 294 end |
277 | 295 |
278 B:RegisterEvent('PLAYER_ENTERING_WORLD') | 296 B:RegisterEvent('PLAYER_ENTERING_WORLD') |
279 B:SetScript('OnEvent', function(self, event) | 297 B:SetScript('OnEvent', function(self, event) |
280 if event == 'PLAYER_ENTERING_WORLD' then | 298 if event == 'PLAYER_ENTERING_WORLD' then |
283 ModulesCall('OnInitialize') | 301 ModulesCall('OnInitialize') |
284 initOnced = true | 302 initOnced = true |
285 C_Timer.After(1, function() | 303 C_Timer.After(1, function() |
286 if GetSpecialization() then | 304 if GetSpecialization() then |
287 print(GetSpecialization(), 'enabling') | 305 print(GetSpecialization(), 'enabling') |
288 ModulesCall('OnEnable') | 306 |
307 ModulesCall('OnEnable', 'enabled') | |
289 B:SetScript('OnUpdate', nil) | 308 B:SetScript('OnUpdate', nil) |
290 end | 309 end |
291 | |
292 end) | 310 end) |
293 end | 311 end |
294 | |
295 end | 312 end |
296 | 313 |
297 B.UpdateAll() | 314 B.UpdateAll() |
315 | |
316 if event == 'PLAYER_ENTERING_WORLD' then | |
317 B.UpdateConfigLayers() | |
318 end | |
319 | |
298 end) | 320 end) |
299 | 321 |
300 --- Modulizer method | 322 --- Modulizer method |
301 -- | 323 -- |
302 function B:RegisterModule (name, module, ...) | 324 function B:RegisterModule (name, module, ...) |
331 | 353 |
332 | 354 |
333 B.SetConfigLayers = function(frame) | 355 B.SetConfigLayers = function(frame) |
334 local print = B.fprint() | 356 local print = B.fprint() |
335 if not frame.config then | 357 if not frame.config then |
336 print(frame:GetName(), 'has no config layers') | 358 --print(frame:GetName(), 'has no config layers') |
337 return | 359 return |
338 end | 360 end |
339 print('Registering config layers from', frame:GetName()) | 361 --print('Registering config layers from', frame:GetName()) |
340 | 362 |
341 for i, subframe in ipairs(frame.config) do | 363 for i, subframe in ipairs(frame.config) do |
342 -- make sure there are no duplicates | 364 -- make sure there are no duplicates |
343 if not refs[subframe] then | 365 if not refs[subframe] then |
344 local key = #layers+1 | 366 local key = #layers+1 |
345 layers[key] = subframe | 367 layers[key] = subframe |
346 refs[subframe] = key | 368 refs[subframe] = key |
347 end | 369 end |
348 print(' ', i, subframe:GetName()) | 370 --print(' ', i, subframe:GetName()) |
349 end | 371 end |
350 end | 372 end |
351 | 373 |
352 B.RemoveConfigLayers = function(frame) | 374 B.RemoveConfigLayers = function(frame) |
353 | 375 |
378 for i, anchorButton in ipairs(display.anchor.anchorButton) do | 400 for i, anchorButton in ipairs(display.anchor.anchorButton) do |
379 anchorButton:Hide() | 401 anchorButton:Hide() |
380 end | 402 end |
381 | 403 |
382 end | 404 end |
383 | 405 print(B.Conf.ConfigMode) |
406 display.anchor:EnableMouse(B.Conf.ConfigMode) | |
384 end | 407 end |
385 for id, region in pairs(layers) do | 408 for id, region in pairs(layers) do |
386 print(id, region:GetName(), func) | 409 print(id, region:GetName(), func) |
387 region[func](region) | 410 region[func](region) |
388 end | 411 end |
389 | 412 |
390 print('['..func..'] updated', #layers, 'regions,', numAnchors, 'frames') | 413 print('['..func..'] updated', #layers, 'regions,', numAnchors, 'frames') |
391 end | 414 end |
392 | 415 |
416 local XMLFrame_SetEnabled = function(self, value) | |
417 local name = self:GetName() | |
418 | |
419 | |
420 if not B.Conf[name] then | |
421 B.Conf[name] = { | |
422 enabled = true | |
423 } | |
424 end | |
425 | |
426 print() | |
427 local enabled | |
428 if value == nil then | |
429 if B.Conf[name].enabled == nil then | |
430 print('toggle based on visibility') | |
431 enabled = (not self:IsVisible()) and true or false | |
432 else | |
433 print('toggle a config value =', B.Conf[name].enabled) | |
434 enabled = B.Conf[name].enabled | |
435 end | |
436 | |
437 enabled = (enabled ~= true) and true or false | |
438 else | |
439 print('use argument value', value) | |
440 enabled = value | |
441 end | |
442 | |
443 print('arg =', value, 'conf =', B.Conf[name].enabled, 'result=', enabled) | |
444 | |
445 B.Conf[name].enabled = enabled | |
446 | |
447 local stateFunc = enabled and 'Show' or 'Hide' | |
448 local eventFunc = enabled and 'OnToggle' or 'OnToggle' | |
449 for i, region in pairs(self.toggled) do | |
450 region[stateFunc](region) | |
451 end | |
452 if self.OnToggle then | |
453 self:OnToggle(B.Conf[name].enabled) | |
454 end | |
455 if B.Conf[name].enabled then | |
456 if self.OnEnable then | |
457 self:OnEnable() | |
458 end | |
459 else | |
460 if self.OnDisable then | |
461 self:OnDisable() | |
462 end | |
463 end | |
464 | |
465 | |
466 end | |
393 --- Generic handlers for keeping track of XML-defined frames | 467 --- Generic handlers for keeping track of XML-defined frames |
394 B.OnLoad = function(self) | 468 B.OnLoad = function(self) |
395 tinsert(checkForConfig, self) | 469 tinsert(checkForConfig, self) |
396 self.Minimize = function(self, forceDown) | 470 self.SetEnabled = XMLFrame_SetEnabled |
397 if not self:IsVisible() then | |
398 return | |
399 end | |
400 local state = (forceDown and 1 or (B.Conf.FrameState[self:GetName()] == 1 and 2 or 1)) | |
401 local stateFunc = (state == 1) and 'Hide' or 'Show' | |
402 for i, region in pairs(self.minimizeFrames) do | |
403 region[stateFunc](region) | |
404 end | |
405 B.Conf.FrameState[self:GetName()] = state | |
406 end | |
407 end | 471 end |
408 | 472 |
409 B.InitXMLFrame = function(self) | 473 B.InitXMLFrame = function(self) |
410 print('|cFF00FF00hello from '..self:GetName()) | 474 local name = self:GetName() |
475 print('|cFF00FF00hello from '.. name) | |
411 | 476 |
412 if self.drag then | 477 if self.drag then |
413 self:RegisterForDrag('LeftButton') | 478 self:RegisterForDrag('LeftButton') |
414 else | 479 else |
415 self:EnableMouse(false) | 480 self:EnableMouse(false) |
416 end | 481 end |
417 | 482 |
418 if not B.Conf.FramePosition then | 483 if not B.Conf[name] then |
419 B.Conf.FramePosition = {} | 484 B.Conf[name] = { |
420 end | 485 enabled = true, |
421 if not B.Conf.FrameState then | 486 } |
422 B.Conf.FrameState = {} | 487 end |
423 end | 488 local c = B.Conf[name] |
424 | 489 |
425 if B.Conf.FramePosition[self:GetName()] then | 490 if c.position then |
426 print('restoring frame position', unpack(B.Conf.FramePosition[self:GetName()])) | 491 print('restoring frame position', unpack(c.position)) |
427 self:ClearAllPoints() | 492 self:ClearAllPoints() |
428 local anchorTo, relativePoint, x, y = unpack(B.Conf.FramePosition[self:GetName()]) | 493 local anchorTo, relativePoint, x, y = unpack(c.position) |
429 self:SetPoint(anchorTo, UIParent, relativePoint, x, y) | 494 self:SetPoint(anchorTo, UIParent, relativePoint, x, y) |
430 end | 495 else |
431 local state = B.Conf.FrameState[self:GetName()] and B.Conf.FrameState[self:GetName()] or 2 | 496 local a, _, b, c, d = self:GetPoint(1) |
432 if state == 0 then | 497 print('seeding default position', a, b, c, d) |
433 self:Hide() | 498 c.position = {a, b, c, d} |
434 elseif state == 1 then | 499 end |
435 self.Minimize(self, true) | 500 local state = c.enabled |
436 elseif state == 2 then | 501 self:SetEnabled(state) |
437 self:Show() | |
438 end | |
439 B.Conf.FrameState[self:GetName()] = state | |
440 end | 502 end |
441 | 503 |
442 B.OnDragStart = function(self) | 504 B.OnDragStart = function(self) |
443 self.xA = self:GetLeft() | 505 self.xA = self:GetLeft() |
444 self.yA = self:GetBottom() | 506 self.yA = self:GetBottom() |
447 print(self:GetName(), 'start moving ('..self.x..', '..self.y..')') | 509 print(self:GetName(), 'start moving ('..self.x..', '..self.y..')') |
448 self:StartMoving() | 510 self:StartMoving() |
449 end | 511 end |
450 | 512 |
451 B.OnDragStop = function(self) | 513 B.OnDragStop = function(self) |
452 print(self:GetName(), 'stop moving ('..self:GetLeft()..', '..self:GetBottom()..')') | 514 local name = self:GetName() |
515 print(name, 'stop moving ('..self:GetLeft()..', '..self:GetBottom()..')') | |
453 local xB = self:GetLeft() - self.xA | 516 local xB = self:GetLeft() - self.xA |
454 local yB = self:GetBottom() - self.yA | 517 local yB = self:GetBottom() - self.yA |
455 print('storing anchor point', self.anchorTo, self.relativePoint, self.x + xB, self.y + yB) | 518 print('storing anchor point', self.anchorTo, self.relativePoint, self.x + xB, self.y + yB) |
456 | 519 |
457 self:StopMovingOrSizing() | 520 self:StopMovingOrSizing() |
458 B.Conf.FramePosition[self:GetName()] = {self.anchorTo, self.relativePoint, self.x + xB, self.y + yB} | 521 B.Conf[name].position = {self.anchorTo, self.relativePoint, self.x + xB, self.y + yB} |
459 B.InitXMLFrame(self) | 522 B.InitXMLFrame(self) |
460 | 523 end |
461 end |