changeset 148:de1da46dadb3

moved unitwatch handling into bar
author Flick <flickerstreak@gmail.com>
date Fri, 08 May 2009 00:06:53 +0000
parents 901c91dc1bf2
children 61d89f0918ca
files classes/Bar.lua modules/PetAction.lua
diffstat 2 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/classes/Bar.lua	Thu May 07 23:55:00 2009 +0000
+++ b/classes/Bar.lua	Fri May 08 00:06:53 2009 +0000
@@ -269,6 +269,14 @@
 
 function Bar:SetConfigMode(mode)
   self:ShowControls(mode)
+  if self.unitwatch then
+    if mode then
+      UnregisterUnitWatch(self:GetFrame())
+      self:GetFrame():Show()
+    else
+      RegisterUnitWatch(self:GetFrame())
+    end
+  end
   for b in self:IterateButtons() do
     b:ShowGridTemp(mode)
     b:UpdateActionIDLabel(mode)
@@ -276,6 +284,14 @@
 end
 
 function Bar:SetKeybindMode(mode)
+  if self.unitwatch then
+    if mode then
+      UnregisterUnitWatch(self:GetFrame())
+      self:GetFrame():Show()
+    else
+      RegisterUnitWatch(self:GetFrame())
+    end
+  end
   for b in self:IterateButtons() do
     b:SetKeybindMode(mode)
   end
@@ -300,3 +316,20 @@
 function Bar:SkinButton()
   -- does nothing by default
 end
+
+-- pass unit=nil to set up the unit elsewhere, if you want something more complex
+function Bar:RegisterUnitWatch( unit, enable )
+  local f = self:GetFrame()
+  if unit then
+    f:SetAttribute("unit",unit)
+  end
+  if not ReAction:GetConfigMode() then
+    if enable then
+      RegisterUnitWatch(f)
+    elseif self.unitwatch then
+      UnregisterUnitWatch(f)
+    end
+  end
+  self.unitwatch = enable
+end
+
--- a/modules/PetAction.lua	Thu May 07 23:55:00 2009 +0000
+++ b/modules/PetAction.lua	Fri May 08 00:06:53 2009 +0000
@@ -52,7 +52,6 @@
   ReAction.RegisterCallback(self, "OnRefreshBar")
   ReAction.RegisterCallback(self, "OnEraseBar")
   ReAction.RegisterCallback(self, "OnRenameBar")
-  ReAction.RegisterCallback(self, "OnConfigModeChanged")
 end
 
 function module:OnEnable()
@@ -73,10 +72,7 @@
 function module:OnCreateBar(event, bar, name)
   if bar.config.type == moduleID then
     -- auto show/hide when pet exists
-    bar:GetFrame():SetAttribute("unit","pet")
-    if not ReAction:GetConfigMode() then
-      RegisterUnitWatch(bar:GetFrame())
-    end
+    bar:RegisterUnitWatch("pet",true)
     self:OnRefreshBar(event, bar, name)
   end
 end
@@ -147,23 +143,6 @@
 end
 
 
-function module:OnConfigModeChanged(event, mode)
-  for _, bar in ReAction:IterateBars() do
-    if bar and self.buttons[bar] then
-      for b in bar:IterateButtons() do
-        b:UpdateActionIDLabel(mode)
-      end
-      local f = bar:GetFrame()
-      if mode then
-        UnregisterUnitWatch(f)
-        f:Show()
-      else
-        RegisterUnitWatch(f)
-      end
-    end
-  end
-end
-
 ---- Options ----
 local Handler = { }
 local meta = { __index = Handler }