comparison Veneer.lua @ 109:26938ae258b7

- Re-use the basic addon table for core mixin - add /rl command
author Nick@Zahhak
date Mon, 06 Mar 2017 02:30:22 -0500
parents a41f6b74709a
children 7c77fde36287
comparison
equal deleted inserted replaced
108:a41f6b74709a 109:26938ae258b7
2 -- 1. vn OnLoad 2 -- 1. vn OnLoad
3 -- 2. OnEvent where IsLoggedIn() == true 3 -- 2. OnEvent where IsLoggedIn() == true
4 -- 3. Setup() where (not self.initialized) 4 -- 3. Setup() where (not self.initialized)
5 -- 4. Update() 5 -- 4. Update()
6 -- 5. Reanchor() 6 -- 5. Reanchor()
7 7 local ADDON, Veneer = ...
8 SLASH_VENEER1 = "/veneer"
9 SLASH_VENEER2 = "/vn"
10 local VENEER_VERSION = 703 8 local VENEER_VERSION = 703
11 local LE_FREE_FRAMES_GROUP = 1 9 local LE_FREE_FRAMES_GROUP = 1
12 local type, strrep, ipairs, tinsert, tostring, select = type, string.rep, ipairs, tinsert, tostring, select 10 local type, strrep, ipairs, tinsert, tostring, select = type, string.rep, ipairs, tinsert, tostring, select
13 local pairs, tremove = pairs, tremove 11 local pairs, tremove = pairs, tremove
14 12 local print = DEVIAN_WORKSPACE and function(...) _G.print('Veneer', ...) end or nop
13 local wipe = table.wipe
14
15 SLASH_VENEER1 = "/veneer"
16 SLASH_VENEER2 = "/vn"
15 SlashCmdList.VENEER = function(cmd) 17 SlashCmdList.VENEER = function(cmd)
16
17 if Veneer.ConfigMode then 18 if Veneer.ConfigMode then
18 Veneer.ConfigMode = false 19 Veneer.ConfigMode = false
19 else 20 else
20 Veneer.ConfigMode = true 21 Veneer.ConfigMode = true
21 end 22 end
22 Veneer:UpdateConfigLayers() 23 Veneer:UpdateConfigLayers()
23 end 24 end
24 25
25 VeneerCore = { 26 Veneer.Frames = {}
26 Frames = {}, 27 Veneer.ConfigLayers = {}
27 ConfigLayers = {}, 28 Veneer.FrameClusters = {
28 FrameClusters = { 29 [LE_FREE_FRAMES_GROUP] = {}
29 [LE_FREE_FRAMES_GROUP] = {}, 30 }
30 }, 31 Veneer.parserDepth = 0
31 parserDepth = 0, 32 Veneer.pendingCalls = {}
32 pendingCalls = {}, 33 Veneer.AddOnCheck = {}
33 AddOnCheck = {}
34 }
35
36 local print = DEVIAN_WORKSPACE and function(...) _G.print('Veneer', ...) end or nop
37 local wipe = table.wipe
38 34
39 local defaults = { 35 local defaults = {
40 enableAll = true, 36 enableAll = true,
41 ConfigMode = true 37 ConfigMode = true
42 } 38 }
82 BOTTOMRIGHT = {-1, 1}, 78 BOTTOMRIGHT = {-1, 1},
83 RIGHT = {-1, 0}, 79 RIGHT = {-1, 0},
84 CENTER = {0, 0}, 80 CENTER = {0, 0},
85 } 81 }
86 82
87 function VeneerCore:print(...) 83 function Veneer:print(...)
88 local txt = '|cFFFFFF00Veneer|r:' 84 local txt = '|cFFFFFF00Veneer|r:'
89 for i = 1, select('#', ...) do 85 for i = 1, select('#', ...) do
90 txt = txt .. ' '.. tostring(select(i, ...)) 86 txt = txt .. ' '.. tostring(select(i, ...))
91 end 87 end
92 88
93 DEFAULT_CHAT_FRAME:AddMessage(txt) 89 DEFAULT_CHAT_FRAME:AddMessage(txt)
94 end 90 end
95 91
96 function VeneerCore:OnLoad() 92 function Veneer:OnLoad()
97 print('|cFFFFFF00Veneer!|r') 93 print('|cFFFFFF00Veneer!|r')
98 self:RegisterEvent('ADDON_LOADED') 94 self:RegisterEvent('ADDON_LOADED')
99 self:RegisterEvent('PLAYER_LOGIN') 95 self:RegisterEvent('PLAYER_LOGIN')
100 96
101 self.DEVIAN_PNAME = 'Veneer' 97 self.DEVIAN_PNAME = 'Veneer'
104 100
105 end 101 end
106 102
107 local select, IsAddOnLoaded, IsLoggedIn = select, IsAddOnLoaded, IsLoggedIn 103 local select, IsAddOnLoaded, IsLoggedIn = select, IsAddOnLoaded, IsLoggedIn
108 104
109 function VeneerCore:OnEvent(event, ...) 105 function Veneer:OnEvent(event, ...)
110 print('|cFFFF0088OnEvent()|r',event, ...) 106 print('|cFFFF0088OnEvent()|r',event, ...)
111 if (event == 'PLAYER_LOGIN') or (event == 'ADDON_LOADED') then 107 if (event == 'PLAYER_LOGIN') or (event == 'ADDON_LOADED') then
112 print(IsLoggedIn(), self.initialized) 108 print(IsLoggedIn(), self.initialized)
113 if IsLoggedIn() and not self.intialized then 109 if IsLoggedIn() and not self.intialized then
114 self:Setup() 110 self:Setup()
136 end 132 end
137 end 133 end
138 end 134 end
139 end 135 end
140 136
141 function VeneerCore:OnDragStart() 137 function Veneer:OnDragStart()
142 self:StartMoving() 138 self:StartMoving()
143 end 139 end
144 140
145 function VeneerCore:OnDragStop() 141 function Veneer:OnDragStop()
146 self:StopMovingOrSizing() 142 self:StopMovingOrSizing()
147 end 143 end
148 144
149 local VeneerModule_Setup = function(frame) 145 local VeneerModule_Setup = function(frame)
150 if not frame.initialized then 146 if not frame.initialized then
152 print(' '..frame:GetName()..'.doSetup =', doSetup) 148 print(' '..frame:GetName()..'.doSetup =', doSetup)
153 if doSetup then 149 if doSetup then
154 frame:Setup() 150 frame:Setup()
155 frame.initialized = true 151 frame.initialized = true
156 else 152 else
157 Veneer:RegisterEvent('ADDON_LOADED') 153 frame:RegisterEvent('ADDON_LOADED')
158 end 154 end
159 155
160 end 156 end
161 end 157 end
162 158
163 function VeneerCore:Setup () 159 function Veneer:Setup ()
164 print('|cFFFF0088Setup()|r') 160 print('|cFFFF0088Setup()|r')
165 local resetConfig = (not VeneerData) 161 local resetConfig = (not VeneerData)
166 if (not VeneerData) then 162 if (not VeneerData) then
167 VeneerData = defaults 163 VeneerData = defaults
168 VeneerData.version = VENEER_VERSION 164 VeneerData.version = VENEER_VERSION
174 self:UpdateConfigLayers() 170 self:UpdateConfigLayers()
175 self:Reanchor() 171 self:Reanchor()
176 self:Update() 172 self:Update()
177 end 173 end
178 174
179 function VeneerCore:UpdateConfigLayers() 175 function Veneer:UpdateConfigLayers()
180 if VeneerData then 176 if VeneerData then
181 177
182 VeneerData.ConfigMode = self.ConfigMode 178 VeneerData.ConfigMode = self.ConfigMode
183 end 179 end
184 180
206 end 202 end
207 end) 203 end)
208 end 204 end
209 205
210 206
211 function VeneerCore:GetClusterFromArgs (...) 207 function Veneer:GetClusterFromArgs (...)
212 local primaryAnchor 208 local primaryAnchor
213 local insertPosition 209 local insertPosition
214 local insertPriority 210 local insertPriority
215 211
216 212
262 end 258 end
263 return primaryAnchor, clusterTable, insertPosition 259 return primaryAnchor, clusterTable, insertPosition
264 end 260 end
265 261
266 -- args: frame object, list of anchor groups, true for forced top, number for priority layer 262 -- args: frame object, list of anchor groups, true for forced top, number for priority layer
267 function VeneerCore:AddHandler(handler, ...) 263 function Veneer:AddHandler(handler, ...)
268 print('|cFFFFFF00*** Adding handler:', handler.moduleName or handler:GetName()) 264 print('|cFFFFFF00*** Adding handler:', handler.moduleName or handler:GetName())
269 265
270 266
271 for k,v in pairs(VeneerHandlerMixin) do 267 for k,v in pairs(VeneerHandlerMixin) do
272 if not handler[k] then 268 if not handler[k] then
317 end 313 end
318 end 314 end
319 end 315 end
320 end 316 end
321 317
322 function VeneerCore:Reanchor() 318 function Veneer:Reanchor()
323 self:ExecuteOnClusters(nil, 'Reanchor') 319 self:ExecuteOnClusters(nil, 'Reanchor')
324 self:DynamicReanchor(self) 320 self:DynamicReanchor(self)
325 end 321 end
326 322
327 function VeneerCore:Update() 323 function Veneer:Update()
328 self:ExecuteOnClusters(nil, function(frame) 324 self:ExecuteOnClusters(nil, function(frame)
329 if frame.initialized and frame.Update then 325 if frame.initialized and frame.Update then
330 frame:Update() 326 frame:Update()
331 end 327 end
332 end) 328 end)
333 self:Reanchor() 329 self:Reanchor()
334 end 330 end
335 331
336 -- updates anchor relations to and from the target handler 332 -- updates anchor relations to and from the target handler
337 function VeneerCore:GetAnchor(...) 333 function Veneer:GetAnchor(...)
338 334
339 end 335 end
340 336
341 -- Evaluates frames visibility and chains them accordingly 337 -- Evaluates frames visibility and chains them accordingly
342 338
343 function VeneerCore:DynamicReanchor(parent) 339 function Veneer:DynamicReanchor(parent)
344 parent = parent or self 340 parent = parent or self
345 print('|cFF88FF00DynamicReanchor()') 341 print('|cFF88FF00DynamicReanchor()')
346 for anchorPoint, cluster in pairs(parent.FrameClusters) do 342 for anchorPoint, cluster in pairs(parent.FrameClusters) do
347 if anchorPoint ~= LE_FREE_FRAMES_GROUP then 343 if anchorPoint ~= LE_FREE_FRAMES_GROUP then
348 local lastFrame 344 local lastFrame
373 369
374 end 370 end
375 end 371 end
376 372
377 -- Evaluates the current visibility state and re-anchors adjacent blocks accordingly 373 -- Evaluates the current visibility state and re-anchors adjacent blocks accordingly
378 function VeneerCore:InternalReanchor(handler, printFunc) 374 function Veneer:InternalReanchor(handler, printFunc)
379 print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')') 375 print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')')
380 if handler.anchorFrame then 376 if handler.anchorFrame then
381 handler:SetPoint(handler.anchorPoint, handler.anchorFrame, handler.anchorFrom, handler.anchorX, handler.anchorY) 377 handler:SetPoint(handler.anchorPoint, handler.anchorFrame, handler.anchorFrom, handler.anchorX, handler.anchorY)
382 return 378 return
383 end 379 end
422 if printFunc then 418 if printFunc then
423 printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo) 419 printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo)
424 end 420 end
425 end 421 end
426 422
427 function VeneerCore:SlideBlock(frame, ...) 423 function Veneer:SlideBlock(frame, ...)
428 local aX, aY = frame:GetLeft(), frame:GetTop() 424 local aX, aY = frame:GetLeft(), frame:GetTop()
429 425
430 frame:SetPoint('TOPLEFT', frame, 'BOTTOMLEFT', aX, aY) 426 frame:SetPoint('TOPLEFT', frame, 'BOTTOMLEFT', aX, aY)
431 frame.animation = frame.animation or {} 427 frame.animation = frame.animation or {}
432 frame.animation.startX = aX 428 frame.animation.startX = aX
439 end) 435 end)
440 436
441 end 437 end
442 438
443 439
444 function VeneerCore:ExecuteOnClusters(layer, method) 440 function Veneer:ExecuteOnClusters(layer, method)
445 self.parserDepth = self.parserDepth + 1 441 self.parserDepth = self.parserDepth + 1
446 if not layer then 442 if not layer then
447 if self.parserDepth > 1 then 443 if self.parserDepth > 1 then
448 tinsert(self.pendingCalls, method) 444 tinsert(self.pendingCalls, method)
449 print('delaying walk for', method) 445 print('delaying walk for', method)
479 end 475 end
480 476
481 477
482 478
483 -- Takes frame handle and assigns a block to it 479 -- Takes frame handle and assigns a block to it
484 function VeneerCore:Acquire (frame, template) 480 function Veneer:Acquire (frame, template)
485 if not frame then 481 if not frame then
486 print('|cFFFF4400Unable to acquire frame...|r') 482 print('|cFFFF4400Unable to acquire frame...|r')
487 return 483 return
488 end 484 end
489 local veneer = self.Frames[frame] 485 local veneer = self.Frames[frame]
503 veneer.currentTop = frame:GetTop() 499 veneer.currentTop = frame:GetTop()
504 self.Frames[frame] = veneer 500 self.Frames[frame] = veneer
505 end 501 end
506 return veneer 502 return veneer
507 end 503 end
504
505 VeneerCore = Veneer