diff Init.lua @ 38:1f8f9cc3d956

- module integration brought up to speed with current frame management structure
author Nenue
date Thu, 21 Apr 2016 11:36:41 -0400
parents e84d645c8ab8
children 756e8aeb040b
line wrap: on
line diff
--- a/Init.lua	Mon Apr 18 07:56:23 2016 -0400
+++ b/Init.lua	Thu Apr 21 11:36:41 2016 -0400
@@ -287,7 +287,7 @@
     local queuedFrame = tremove(checkForConfig)
     while queuedFrame do
       B.SetConfigLayers(queuedFrame)
-      B.InitXMLFrame(queuedFrame)
+      B.UpdateXMLFrame(queuedFrame)
       queuedFrame = tremove(checkForConfig)
     end
   end
@@ -421,7 +421,7 @@
   print('['..func..'] updated', #layers, 'regions,', numAnchors, 'frames')
 end
 
-local XMLFrame_SetEnabled = function(self, value)
+local XMLFrame_Enable = function(self, value)
   local name = self:GetName()
 
 
@@ -469,47 +469,10 @@
       self:OnDisable()
     end
   end
-
-
 end
 --- Generic handlers for keeping track of XML-defined frames
-B.OnLoad = function(self)
-  tinsert(checkForConfig, self)
-  self.SetEnabled = XMLFrame_SetEnabled
-end
 
-B.InitXMLFrame = function(self)
-  local name = self:GetName()
-  print('|cFF00FF00hello from '.. name)
-
-  if self.drag then
-    self:RegisterForDrag('LeftButton')
-  else
-    self:EnableMouse(false)
-  end
-
-  if not B.Conf[name] then
-    B.Conf[name] = {
-      enabled = true,
-    }
-  end
-  local c = B.Conf[name]
-
-  if c.position then
-    print('restoring frame position', unpack(c.position))
-    self:ClearAllPoints()
-    local anchorTo, relativePoint, x, y = unpack(c.position)
-    self:SetPoint(anchorTo, UIParent, relativePoint, x, y)
-  else
-    local a, _, b, c, d = self:GetPoint(1)
-    print('seeding default position', a, b, c, d)
-    c.position = {a, b, c, d}
-  end
-  local state = c.enabled
-  self:SetEnabled(state)
-end
-
-B.OnDragStart = function(self)
+local XMLFrame_OnDragStart = function(self)
   self.xA = self:GetLeft()
   self.yA = self:GetBottom()
   self.anchorTo, self.relativeTo, self.relativePoint, self.x, self.y = self:GetPoint(1)
@@ -518,7 +481,7 @@
   self:StartMoving()
 end
 
-B.OnDragStop = function(self)
+local XMLFrame_OnDragStop = function(self)
   local name = self:GetName()
   print(name, 'stop moving ('..self:GetLeft()..', '..self:GetBottom()..')')
   local xB = self:GetLeft() - self.xA
@@ -527,5 +490,55 @@
 
   self:StopMovingOrSizing()
   B.Conf[name].position = {self.anchorTo, self.relativePoint, self.x + xB, self.y + yB}
-  B.InitXMLFrame(self)
-end
\ No newline at end of file
+  B.UpdateXMLFrame(self)
+end
+
+B.RegisterModuleFrame = function(self, moduleName)
+  tinsert(checkForConfig, self)
+  self.Enable = XMLFrame_Enable
+  self.moduleName = moduleName
+  print('|cFF00FF00XML stuff related to '.. tostring(moduleName) .. ':', name)
+end
+
+B.UpdateXMLFrame = function(self)
+
+  local name = self:GetName()
+
+
+  if self.drag then
+    self:RegisterForDrag('LeftButton')
+    self:SetScript('OnDragStart', XMLFrame_OnDragStart)
+    if self.OnDragStop then
+      self:SetScript('OnDragStop', function(self, ...)
+        self:OnDragStop(self, ...)
+        XMLFrame_OnDragStop(self, ...)
+      end)
+    else
+      self:SetScript('OnDragStop', XMLFrame_OnDragStop)
+    end
+  else
+    self:EnableMouse(false)
+  end
+
+  if not B.Conf[name] then
+    B.Conf[name] = {
+      enabled = self.enabled,
+    }
+  end
+  local c = B.Conf[name]
+
+  if not c.position then
+    local a, _, b, c, d = self:GetPoint(1)
+    print('seeding default position', a, b, c, d)
+    c.position = {a, b, c, d }
+  else
+
+    print('restoring frame position', unpack(c.position))
+    self:ClearAllPoints()
+    local anchorTo, relativePoint, x, y = unpack(c.position)
+    self:SetPoint(anchorTo, UIParent, relativePoint, x, y)
+  end
+  self:Enable(c.enabled)
+
+
+end