diff Veneer.lua @ 113:2105b6e5095f

- Added Blood of Sargeras to currency list - Fixed panel ordering issues when a module is loaded on the fly.
author Nick@Zahhak
date Sun, 26 Mar 2017 06:25:18 -0400
parents 7c77fde36287
children 8c94bee4fdfc
line wrap: on
line diff
--- a/Veneer.lua	Thu Mar 23 05:29:03 2017 -0400
+++ b/Veneer.lua	Sun Mar 26 06:25:18 2017 -0400
@@ -10,6 +10,7 @@
 local type, strrep, ipairs, tinsert, tostring, select = type, string.rep, ipairs, tinsert, tostring, select
 local pairs, tremove = pairs, tremove
 local print = DEVIAN_WORKSPACE and function(...) _G.print('Veneer', ...) end or nop
+local eprint = DEVIAN_WORKSPACE and function(...) _G.print('VeneerEvent', ...) end or nop
 local wipe = table.wipe
 
 SLASH_VENEER1 = "/veneer"
@@ -103,6 +104,7 @@
 local select, IsAddOnLoaded, IsLoggedIn = select, IsAddOnLoaded, IsLoggedIn
 
 function Veneer:OnEvent(event, ...)
+  local print = eprint
   print('|cFFFF0088OnEvent()|r',event, ...)
   if (event == 'PLAYER_LOGIN') or (event == 'ADDON_LOADED') then
     print(IsLoggedIn(), self.initialized)
@@ -205,57 +207,6 @@
 
 
 function Veneer:GetClusterFromArgs (...)
-  local primaryAnchor
-  local insertPosition
-  local insertPriority
-
-
-  local clusterTable = self.FrameClusters
-  for i = 1, select('#', ...) do
-    local arg = select(i, ...)
-    local argType = type(arg)
-    if argType == 'string' then
-      if not primaryAnchor then
-        primaryAnchor = arg
-      end
-      clusterTable[arg] = clusterTable[arg] or {}
-      clusterTable = clusterTable[arg]
-      print(strrep(' ', i)..'anchor cluster', i, arg)
-    elseif argType == 'boolean' then
-      if arg == true then
-        print('force top position')
-        insertPosition = 1
-        insertPriority = nil
-      end
-    elseif argType == 'number' then
-      insertPriority = arg
-    end
-  end
-
-  if insertPriority then
-    for i = 1, #clusterTable do
-      if clusterTable[i].anchorPriority and (clusterTable[i].anchorPriority > insertPriority) then
-        print('prioritized insert position:', insertPriority, insertPosition)
-        break
-      else
-        print('passing lower priority frame:', clusterTable[i]:GetName())
-      end
-      insertPosition = i
-    end
-  end
-
-
-  if not primaryAnchor then
-    primaryAnchor = 'CENTER'
-    clusterTable[primaryAnchor] = clusterTable[primaryAnchor] or {}
-    clusterTable = clusterTable[primaryAnchor]
-    print('using default anchor')
-  end
-
-  if not insertPosition then
-    insertPosition = #clusterTable + 1
-    print('using default position')
-  end
   return primaryAnchor, clusterTable, insertPosition
 end
 
@@ -272,14 +223,71 @@
   end
 
   if not handler.anchorFrame then
-    local anchorGroup, clusterTable, clusterIndex, clusterPriority = self:GetClusterFromArgs(...)
-    if clusterIndex == 1 then
-      for i, frame in ipairs(clusterTable) do
-        frame.clusterIndex = i + 1
+
+    local primaryAnchor
+    local clusterIndex
+    local clusterPriority = handler.anchorPriority
+    local clusterDepth = 0
+
+    local clusterTable = self.FrameClusters
+    for i = 1, select('#', ...) do
+      local arg = select(i, ...)
+      local argType = type(arg)
+      if argType == 'string' then
+
+        if not primaryAnchor then
+          primaryAnchor = arg
+        end
+        clusterDepth = clusterDepth + 1
+        clusterTable[arg] = clusterTable[arg] or {}
+        clusterTable = clusterTable[arg]
+        print('clusterGroup =', clusterDepth ..'.'.. arg)
+      elseif argType == 'boolean' then
+        if arg == true then
+          print('anchorFirst =', arg)
+          clusterPriority = nil
+        end
+      elseif argType == 'number' then
+        if arg ~= clusterPriority then
+          print('anchorPriority =', arg)
+          clusterPriority = arg
+        end
+
       end
     end
+
+    if clusterPriority then
+      for i = 1, #clusterTable do
+        clusterIndex = i
+        if clusterTable[i].anchorPriority and (clusterTable[i].anchorPriority > clusterPriority) then
+          print('|cFF00BB00insert position:', clusterPriority, clusterIndex)
+          break
+        else
+          print('passing lower priority frame:', clusterTable[i]:GetName())
+        end
+      end
+    else
+      print('|cFF00BB00inserting at front')
+      clusterIndex = 1
+    end
+
+
+    if not primaryAnchor then
+      primaryAnchor = 'CENTER'
+      clusterTable[primaryAnchor] = clusterTable[primaryAnchor] or {}
+      clusterTable = clusterTable[primaryAnchor]
+    end
+
+    if not clusterPriority then
+      clusterIndex = #clusterTable + 1
+    end
+    if not clusterIndex then
+      clusterIndex = #clusterTable + 1
+    end
+
+
     tinsert(clusterTable, clusterIndex, handler)
-    print(' cluster', anchorGroup, 'table', clusterTable, 'position', clusterIndex)
+    print(' cluster', primaryAnchor, 'table', clusterTable, 'priority', clusterPriority, 'position', clusterIndex)
 
     handler.anchorCluster = clusterTable
     handler.anchorIndex = clusterIndex
@@ -334,10 +342,10 @@
 
 end
 
--- Evaluates frames visibility and chains them accordingly
-
-function Veneer:DynamicReanchor(parent)
+-- Recursives updates frame group anchors
+function Veneer:EvaluateAnchors(parent)
   parent = parent or self
+  local print = eprint
   print('|cFF88FF00DynamicReanchor()')
   for anchorPoint, cluster in pairs(parent.FrameClusters) do
     if anchorPoint ~= LE_FREE_FRAMES_GROUP then
@@ -372,8 +380,11 @@
   end
 end
 
+Veneer.DynamicReanchor = Veneer.EvaluateAnchors
+
 -- Evaluates the current visibility state and re-anchors adjacent blocks accordingly
 function Veneer:InternalReanchor(handler, printFunc)
+  local print = eprint
   print('|cFF00FFFFVeneer:InternalReanchor('..handler:GetName()..')')
   if handler.anchorFrame then
     handler:SetPoint(handler.anchorPoint, handler.anchorFrame, handler.anchorFrom, handler.anchorX, handler.anchorY)
@@ -423,6 +434,7 @@
 end
 
 function Veneer:SlideBlock(frame, ...)
+  local print = eprint
   local aX, aY = frame:GetLeft(), frame:GetTop()
 
   frame:SetPoint('TOPLEFT', frame, 'BOTTOMLEFT', aX, aY)
@@ -440,6 +452,7 @@
 
 
 function Veneer:ExecuteOnClusters(layer, method)
+  local print = eprint
   self.parserDepth = self.parserDepth + 1
   if not layer then
     if self.parserDepth > 1 then
@@ -480,6 +493,7 @@
 
 -- Takes frame handle and assigns a block to it
 function Veneer:Acquire (frame, template)
+  local print = eprint
   if not frame then
     print('|cFFFF4400Unable to acquire frame...|r')
     return