Mercurial > wow > buffalo2
comparison Veneer.lua @ 88:b107b4df7eb6
- core:DynamicReanchor
- top-down evaluation of clustered frames
- core:InternalReanchor(module)
- bottom-up evaluation of target and frames anchored to it
author | Nenue |
---|---|
date | Thu, 20 Oct 2016 04:08:11 -0400 |
parents | 27db212af783 |
children | 74e714637d6a |
comparison
equal
deleted
inserted
replaced
87:27db212af783 | 88:b107b4df7eb6 |
---|---|
1 -- Veneer | 1 -- Veneer Custom Interface Framework |
2 -- Base framework for making things draggable. | 2 -- 1. vn OnLoad |
3 | 3 -- 2. OnEvent where IsLoggedIn() == true |
4 | 4 -- 3. Setup() where (not self.initialized) |
5 | 5 -- 4. Update() |
6 -- 5. Reanchor() | |
6 | 7 |
7 SLASH_VENEER1 = "/veneer" | 8 SLASH_VENEER1 = "/veneer" |
8 SLASH_VENEER2 = "/vn" | 9 SLASH_VENEER2 = "/vn" |
9 | 10 |
10 SlashCmdList.VENEER = function(cmd) | 11 SlashCmdList.VENEER = function(cmd) |
11 end | 12 end |
13 | |
12 VeneerCore = { | 14 VeneerCore = { |
13 Frames = {}, | 15 Frames = {}, |
14 ConfigLayers = {}, | 16 ConfigLayers = {}, |
15 FrameClusters = {}, | 17 FrameClusters = {}, |
16 parserDepth = 0, | 18 parserDepth = 0, |
17 pendingCalls = {}, | 19 pendingCalls = {}, |
18 } | 20 } |
19 VeneerHandlerMixin = { | 21 VeneerHandlerMixin = { |
20 Reanchor = nop, | 22 |
21 anchorPoint = 'CENTER', -- indicates the initial cluster group point | 23 anchorPoint = 'CENTER', -- indicates the initial cluster group point |
22 --anchorPath = 'BOTTOM', -- indicates the point from which the frame is anchored in a cluster arrangement | 24 --anchorPath = 'BOTTOM', -- indicates the point from which the frame is anchored in a cluster arrangement |
25 OnHide = function() | |
26 Veneer:DynamicReanchor() | |
27 end, | |
28 OnShow = function(self) | |
29 self:Reanchor() | |
30 Veneer:StaticReanchor(self) | |
31 end | |
23 } | 32 } |
33 VeneerAnimationMixin = {} | |
24 local print = DEVIAN_WORKSPACE and function(...) print('Veneer', ...) end or nop | 34 local print = DEVIAN_WORKSPACE and function(...) print('Veneer', ...) end or nop |
25 local wipe = table.wipe | 35 local wipe = table.wipe |
26 | 36 |
27 local defaults = { | 37 local defaults = { |
28 enableAll = true, | 38 enableAll = true, |
93 self:RegisterEvent('ADDON_LOADED') | 103 self:RegisterEvent('ADDON_LOADED') |
94 self:RegisterEvent('PLAYER_LOGIN') | 104 self:RegisterEvent('PLAYER_LOGIN') |
95 | 105 |
96 self.DEVIAN_PNAME = 'Veneer' | 106 self.DEVIAN_PNAME = 'Veneer' |
97 self:RegisterForDrag('LeftButton') | 107 self:RegisterForDrag('LeftButton') |
108 | |
109 | |
98 end | 110 end |
99 | 111 |
100 function VeneerCore:OnEvent(event, ...) | 112 function VeneerCore:OnEvent(event, ...) |
101 if event == 'ADDON_LOADED' or event == 'PLAYER_LOGIN' then | 113 if event == 'ADDON_LOADED' or event == 'PLAYER_LOGIN' then |
102 if IsLoggedIn() and not self.intialized then | 114 if IsLoggedIn() and not self.intialized then |
182 print(' -- doing initialization') | 194 print(' -- doing initialization') |
183 if handler.Setup and not handler.initialized then | 195 if handler.Setup and not handler.initialized then |
184 handler:Setup() | 196 handler:Setup() |
185 handler.initialized = true | 197 handler.initialized = true |
186 end | 198 end |
187 if handler.Update then | |
188 handler:Update() | |
189 end | |
190 self:InternalReanchor(handler) | 199 self:InternalReanchor(handler) |
191 | 200 |
192 end | 201 end |
193 end | 202 end |
194 | 203 |
195 function VeneerCore:Reanchor() | 204 function VeneerCore:Reanchor() |
196 self:ExecuteOnClusters(nil, 'Reanchor') | 205 self:ExecuteOnClusters(nil, 'Reanchor') |
206 self:DynamicReanchor(self) | |
197 end | 207 end |
198 | 208 |
199 function VeneerCore:Update() | 209 function VeneerCore:Update() |
200 self:ExecuteOnClusters(nil, 'Update') | 210 self:ExecuteOnClusters(nil, 'Update') |
211 self:Reanchor() | |
201 end | 212 end |
202 | 213 |
203 -- updates anchor relations to and from the target handler | 214 -- updates anchor relations to and from the target handler |
204 function VeneerCore:GetAnchor(...) | 215 function VeneerCore:GetAnchor(...) |
205 | 216 |
206 end | 217 end |
207 | 218 |
219 -- Evaluates frames visibility and chains them accordingly | |
220 | |
221 function VeneerCore:DynamicReanchor(parent) | |
222 parent = parent or self | |
223 print('|cFF88FF00DynamicReanchor()') | |
224 for anchorPoint, cluster in pairs(parent.FrameClusters) do | |
225 local lastFrame | |
226 for index, frame in ipairs(cluster) do | |
227 print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible()) | |
228 if frame:IsVisible() then | |
229 anchorPoint = frame.anchorPoint | |
230 | |
231 | |
232 frame:ClearAllPoints() | |
233 if lastFrame then | |
234 frame:SetPoint(anchorPoint, lastFrame, ANCHOR_OFFSET_POINT[anchorPoint], 0, 0) | |
235 else | |
236 frame:SetPoint(anchorPoint, UIParent, anchorPoint, 0, 0) | |
237 end | |
238 lastFrame = frame | |
239 end | |
240 | |
241 end | |
242 end | |
243 end | |
244 | |
245 -- Evaluates the current visibility state and re-anchors adjacent blocks accordingly | |
208 function VeneerCore:InternalReanchor(handler, printFunc) | 246 function VeneerCore:InternalReanchor(handler, printFunc) |
209 print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')') | 247 print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')') |
210 local anchorPoint = handler.anchorPath or handler.anchorPoint | 248 local anchorPoint = handler.anchorPath or handler.anchorPoint |
211 local anchorParent, anchorTo = UIParent, anchorPoint | 249 local anchorParent, anchorTo = UIParent, anchorPoint |
212 for i, frame in ipairs(handler.anchorCluster) do | 250 local subPoint, subTo |
213 if frame ~= handler then | 251 local nextFrame |
214 anchorParent = frame | 252 for index, frame in ipairs(handler.anchorCluster) do |
215 anchorTo = ANCHOR_OFFSET_POINT[anchorPoint] | 253 |
216 | 254 print(' |cFF00FF00'..index, frame:GetName(), frame:IsVisible()) |
217 else | 255 if frame:IsVisible() then |
218 local nextFrame = handler.anchorCluster[i+1] | 256 if frame ~= handler then |
219 if nextFrame then | 257 anchorParent = frame |
220 | 258 anchorTo = ANCHOR_OFFSET_POINT[anchorPoint] |
221 local subPoint = nextFrame.anchorPath or nextFrame.anchorPoint | 259 |
222 local subTo = ANCHOR_OFFSET_POINT[subPoint] | 260 else |
223 nextFrame:ClearAllPoints() | 261 nextFrame = handler.anchorCluster[index+1] |
224 nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) | 262 if nextFrame then |
225 print(' -- pushing '..nextFrame:GetName()..' down the anchor chain', subPoint, subTo) | 263 |
264 subPoint = nextFrame.anchorPath or nextFrame.anchorPoint | |
265 subTo = ANCHOR_OFFSET_POINT[subPoint] | |
266 nextFrame:ClearAllPoints() | |
267 nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) | |
268 print(' -- pushing '..nextFrame:GetName()..' down the anchor chain', subPoint, subTo) | |
269 end | |
270 break | |
226 end | 271 end |
227 break | 272 end |
228 end | 273 end |
229 end | 274 |
230 | 275 if handler:IsVisible() then |
231 handler:ClearAllPoints() | 276 handler:SetPoint(anchorPoint, anchorParent, anchorTo, 0, 0) |
232 handler:SetPoint(anchorPoint, anchorParent, anchorTo, 0, 0) | 277 else |
278 if anchorParent and nextFrame then | |
279 nextFrame:SetPoint(subPoint, handler, subTo, 0, 0) | |
280 end | |
281 end | |
282 | |
233 | 283 |
234 print(handler.anchorPoint, anchorParent, anchorTo) | 284 print(handler.anchorPoint, anchorParent, anchorTo) |
235 if printFunc then | 285 if printFunc then |
236 printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo) | 286 printFunc('|cFF88FF00'..handler:GetName()..':SetPoint(', handler.anchorPoint, anchorParent, anchorTo) |
237 end | 287 end |
238 | 288 end |
239 end | 289 |
290 function VeneerCore:SlideBlock(frame, ...) | |
291 | |
292 local anchorPoint, parent, anchorTo, pX,pY = ... | |
293 print(' |cFF0088FFSlide:|r', frame, 'to', parent, pX,pY) | |
294 local qX, qY = pX, pY | |
295 local bX, bY | |
296 local dX, dY = 0, 0 | |
297 local aX, aY = frame:GetLeft(), frame:GetTop() | |
298 local str = '' | |
299 if not aX then | |
300 dY = ((anchorPoint == 'TOP') and frame:GetHeight()) or (((anchorPoint == 'BOTTOM') and -frame:GetHeight()) or 0) | |
301 dX = ((anchorPoint == 'LEFT') and -frame:GetWidth()) or (((anchorPoint == 'RIGHT') and frame:GetWidth()) or 0) | |
302 qX = pX + dX | |
303 qY = pY + dY | |
304 aX, aY = qX, qY | |
305 bX, bY = pX, pY | |
306 str = '|cFFFFFF00relative|r' | |
307 else | |
308 frame:ClearAllPoints() | |
309 | |
310 bX, bY = frame:GetLeft(), frame:GetTop() | |
311 dX, dY = (bX-aX), (bY-aY) | |
312 | |
313 str = '|cFFFFFF00existing|r' | |
314 end | |
315 | |
316 if ((dX ~= 0) or (dY ~= 0)) and frame.BlockSlide then | |
317 print(' |cFF00FF88Slide result:|r',str, dX, dY) | |
318 | |
319 frame:ClearAllPoints() | |
320 frame:SetPoint(anchorPoint, parent, anchorTo, qX, qY) | |
321 frame.BlockSlide.dX = dX | |
322 frame.BlockSlide.dY = dY | |
323 frame.BlockSlide.sourcePoint = {anchorPoint, parent, anchorTo, qX, qY} | |
324 frame.BlockSlide.destPoint = {anchorPoint, parent, anchorTo, pX,pY} | |
325 frame.BlockSlide.translation:SetOffset(dX, dY) | |
326 frame.BlockSlide:Play() | |
327 return | |
328 end | |
329 end | |
330 | |
240 | 331 |
241 function VeneerCore:ExecuteOnClusters(layer, method) | 332 function VeneerCore:ExecuteOnClusters(layer, method) |
242 self.parserDepth = self.parserDepth + 1 | 333 self.parserDepth = self.parserDepth + 1 |
243 if not layer then | 334 if not layer then |
244 if self.parserDepth > 1 then | 335 if self.parserDepth > 1 then |
368 | 459 |
369 local VeneerButton_OnShow = function(self) | 460 local VeneerButton_OnShow = function(self) |
370 VeneerButton_Update(self) | 461 VeneerButton_Update(self) |
371 end | 462 end |
372 | 463 |
464 -- Takes frame handle and assigns a block to it | |
373 function VeneerCore:Acquire (frame, template) | 465 function VeneerCore:Acquire (frame, template) |
374 if not frame then | 466 if not frame then |
375 print('|cFFFF4400Unable to acquire frame...|r') | 467 print('|cFFFF4400Unable to acquire frame...|r') |
376 return | 468 return |
377 end | 469 end |
397 end | 489 end |
398 | 490 |
399 return veneer | 491 return veneer |
400 end | 492 end |
401 | 493 |
402 local mixin_probe = { | 494 function VeneerHandlerMixin:Reanchor (anchorAll) |
403 'ArtifactFrame', | 495 if not anchorAll then |
404 'ArtifactFrameUnderlay', | 496 Veneer:InternalReanchor(self) |
405 } | 497 end |
406 | 498 |
407 | 499 end |
500 | |
501 function VeneerAnimationMixin:OnPlay() | |
502 PlaySoundKitID(229) | |
503 print('|cFF00FF00Anim:OnPlay|r @', unpack(self.sourcePoint)) | |
504 end | |
505 function VeneerAnimationMixin:OnStop() | |
506 PlaySoundKitID(229) | |
507 end | |
508 function VeneerAnimationMixin:OnFinished() | |
509 PlaySoundKitID(229) | |
510 print('|cFF00FF00Anim:OnFinish|r @', unpack(self.destPoint)) | |
511 self:GetParent():ClearAllPoints() | |
512 self:GetParent():SetPoint(unpack(self.destPoint)) | |
513 end |