diff modules/ReAction_ButtonFacade/ReAction_ButtonFacade.lua @ 108:b2fb8f7dc780

ButtonFacade support
author Flick <flickerstreak@gmail.com>
date Wed, 07 Jan 2009 00:57:02 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/ReAction_ButtonFacade/ReAction_ButtonFacade.lua	Wed Jan 07 00:57:02 2009 +0000
@@ -0,0 +1,115 @@
+-- local imports
+local ReAction = ReAction
+local L = ReAction.L
+local _G = _G
+
+-- module declaration
+local moduleID = "ButtonFacade"
+local module = ReAction:NewModule( moduleID )
+
+-- handlers
+function module:OnInitialize()
+  self.db = ReAction.db:RegisterNamespace( moduleID,
+    {
+      profile = {
+        -- default profile goes here
+      }
+    }
+  )
+
+  local LBF = LibStub("LibButtonFacade",true)
+
+  if not LBF then -- no more initialization
+    return
+  end
+
+  self.LBF = LBF
+  self.groups = { }
+
+  -- override a method of ReAction.Bar
+  -- note that 'self' in this context refers to the bar
+  function ReAction.Bar:SkinButton( button, data )
+    module:GetGroup(self:GetName()):AddButton(button:GetFrame(), data)
+  end
+
+  -- register some common events
+  ReAction.RegisterCallback(self, "OnCreateBar")
+  ReAction.RegisterCallback(self, "OnDestroyBar")
+  ReAction.RegisterCallback(self, "OnRefreshBar")
+  ReAction.RegisterCallback(self, "OnEraseBar")
+  ReAction.RegisterCallback(self, "OnRenameBar")
+
+  self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self)
+end
+
+function module:OnEnable()
+
+end
+
+function module:OnDisable()
+
+end
+
+function module:OnCreateBar(event, bar, name)
+  local c = self.db.profile[name]
+  if not c then
+     c = { 
+      skinID = "Blizzard",
+      backdrop = true,
+      gloss = 0,
+      colors = {},
+    }
+    self.db.profile[name] = c
+  end
+
+  local g = self:GetGroup(name)
+  g.SkinID   = c.skinID or "Blizzard"
+  g.Backdrop = c.backdrop
+  g.Gloss    = c.gloss
+  g.Colors   = c.colors
+end
+
+function module:OnDestroyBar(event, bar, name)
+  if self.groups[name] then
+    self.groups[name]:Delete()
+    self.groups[name] = nil
+  end
+end
+
+function module:OnRefreshBar(event, bar, name)
+  local c = self.db.profile[name]
+  local g = self.groups[name]
+  if c and g then
+    g:Skin(c.skinID, c.gloss, c.backdrop, c.colors)
+  end
+end
+
+function module:OnEraseBar(event, bar, name)
+  self:OnDestroyBar(event, bar, name)
+  self.db.profile[name] = nil
+end
+
+function module:OnRenameBar(event, bar, oldName, newName)
+  if self.groups[name] then
+    self.groups[name]:Delete(true)
+    self.db.profile[oldName], self.db.profile[newName] = nil, self.db.profile[oldName]
+    self:OnCreateBar(event, bar, newName)
+  end
+end
+
+function module:OnSkinChanged( skinID, gloss, backdrop, group, button, colors )
+  local c = self.db.profile[group]
+  if c then
+    c.skinID   = skinID
+    c.gloss    = gloss
+    c.backdrop = backdrop
+    c.colors   = colors
+  end  
+end
+
+function module:GetGroup( name )
+  if not self.groups[name] then
+    self.groups[name] = self.LBF:Group("ReAction", name)
+  end
+  return self.groups[name]
+end