| flickerstreak@108 | 1 -- local imports | 
| flickerstreak@108 | 2 local ReAction = ReAction | 
| flickerstreak@108 | 3 local L = ReAction.L | 
| flickerstreak@108 | 4 local _G = _G | 
| flickerstreak@108 | 5 | 
| flickerstreak@108 | 6 -- module declaration | 
| flickerstreak@108 | 7 local moduleID = "ButtonFacade" | 
| flickerstreak@108 | 8 local module = ReAction:NewModule( moduleID ) | 
| flickerstreak@108 | 9 | 
| flickerstreak@108 | 10 -- handlers | 
| flickerstreak@108 | 11 function module:OnInitialize() | 
| flickerstreak@108 | 12   self.db = ReAction.db:RegisterNamespace( moduleID, | 
| flickerstreak@108 | 13     { | 
| flickerstreak@108 | 14       profile = { | 
| flickerstreak@108 | 15         -- default profile goes here | 
| flickerstreak@108 | 16       } | 
| flickerstreak@108 | 17     } | 
| flickerstreak@108 | 18   ) | 
| flickerstreak@108 | 19 | 
| flickerstreak@108 | 20   local LBF = LibStub("LibButtonFacade",true) | 
| flickerstreak@108 | 21 | 
| flickerstreak@108 | 22   if not LBF then -- no more initialization | 
| flickerstreak@108 | 23     return | 
| flickerstreak@108 | 24   end | 
| flickerstreak@108 | 25 | 
| flickerstreak@108 | 26   self.LBF = LBF | 
| flickerstreak@108 | 27   self.groups = { } | 
| flickerstreak@108 | 28 | 
| flickerstreak@108 | 29   -- override a method of ReAction.Bar | 
| flickerstreak@108 | 30   -- note that 'self' in this context refers to the bar | 
| flickerstreak@108 | 31   function ReAction.Bar:SkinButton( button, data ) | 
| flickerstreak@108 | 32     module:GetGroup(self:GetName()):AddButton(button:GetFrame(), data) | 
| flickerstreak@108 | 33   end | 
| flickerstreak@108 | 34 | 
| flickerstreak@108 | 35   -- register some common events | 
| flickerstreak@108 | 36   ReAction.RegisterCallback(self, "OnCreateBar") | 
| flickerstreak@108 | 37   ReAction.RegisterCallback(self, "OnDestroyBar") | 
| flickerstreak@108 | 38   ReAction.RegisterCallback(self, "OnRefreshBar") | 
| flickerstreak@108 | 39   ReAction.RegisterCallback(self, "OnEraseBar") | 
| flickerstreak@108 | 40   ReAction.RegisterCallback(self, "OnRenameBar") | 
| flickerstreak@108 | 41 | 
| flickerstreak@108 | 42   self.LBF:RegisterSkinCallback("ReAction", self.OnSkinChanged, self) | 
| flickerstreak@108 | 43 end | 
| flickerstreak@108 | 44 | 
| flickerstreak@108 | 45 function module:OnEnable() | 
| flickerstreak@108 | 46 | 
| flickerstreak@108 | 47 end | 
| flickerstreak@108 | 48 | 
| flickerstreak@108 | 49 function module:OnDisable() | 
| flickerstreak@108 | 50 | 
| flickerstreak@108 | 51 end | 
| flickerstreak@108 | 52 | 
| flickerstreak@108 | 53 function module:OnCreateBar(event, bar, name) | 
| flickerstreak@108 | 54   local c = self.db.profile[name] | 
| flickerstreak@108 | 55   if not c then | 
| flickerstreak@108 | 56      c = { | 
| flickerstreak@108 | 57       skinID = "Blizzard", | 
| flickerstreak@108 | 58       backdrop = true, | 
| flickerstreak@108 | 59       gloss = 0, | 
| flickerstreak@108 | 60       colors = {}, | 
| flickerstreak@108 | 61     } | 
| flickerstreak@108 | 62     self.db.profile[name] = c | 
| flickerstreak@108 | 63   end | 
| flickerstreak@108 | 64 | 
| flickerstreak@108 | 65   local g = self:GetGroup(name) | 
| flickerstreak@108 | 66   g.SkinID   = c.skinID or "Blizzard" | 
| flickerstreak@108 | 67   g.Backdrop = c.backdrop | 
| flickerstreak@108 | 68   g.Gloss    = c.gloss | 
| flickerstreak@108 | 69   g.Colors   = c.colors | 
| flickerstreak@108 | 70 end | 
| flickerstreak@108 | 71 | 
| flickerstreak@108 | 72 function module:OnDestroyBar(event, bar, name) | 
| flickerstreak@108 | 73   if self.groups[name] then | 
| flickerstreak@108 | 74     self.groups[name]:Delete() | 
| flickerstreak@108 | 75     self.groups[name] = nil | 
| flickerstreak@108 | 76   end | 
| flickerstreak@108 | 77 end | 
| flickerstreak@108 | 78 | 
| flickerstreak@108 | 79 function module:OnRefreshBar(event, bar, name) | 
| flickerstreak@108 | 80   local c = self.db.profile[name] | 
| flickerstreak@108 | 81   local g = self.groups[name] | 
| flickerstreak@108 | 82   if c and g then | 
| flickerstreak@108 | 83     g:Skin(c.skinID, c.gloss, c.backdrop, c.colors) | 
| flickerstreak@108 | 84   end | 
| flickerstreak@108 | 85 end | 
| flickerstreak@108 | 86 | 
| flickerstreak@108 | 87 function module:OnEraseBar(event, bar, name) | 
| flickerstreak@108 | 88   self:OnDestroyBar(event, bar, name) | 
| flickerstreak@108 | 89   self.db.profile[name] = nil | 
| flickerstreak@108 | 90 end | 
| flickerstreak@108 | 91 | 
| flickerstreak@108 | 92 function module:OnRenameBar(event, bar, oldName, newName) | 
| flickerstreak@108 | 93   if self.groups[name] then | 
| flickerstreak@108 | 94     self.groups[name]:Delete(true) | 
| flickerstreak@108 | 95     self.db.profile[oldName], self.db.profile[newName] = nil, self.db.profile[oldName] | 
| flickerstreak@108 | 96     self:OnCreateBar(event, bar, newName) | 
| flickerstreak@108 | 97   end | 
| flickerstreak@108 | 98 end | 
| flickerstreak@108 | 99 | 
| flickerstreak@108 | 100 function module:OnSkinChanged( skinID, gloss, backdrop, group, button, colors ) | 
| flickerstreak@108 | 101   local c = self.db.profile[group] | 
| flickerstreak@108 | 102   if c then | 
| flickerstreak@108 | 103     c.skinID   = skinID | 
| flickerstreak@108 | 104     c.gloss    = gloss | 
| flickerstreak@108 | 105     c.backdrop = backdrop | 
| flickerstreak@108 | 106     c.colors   = colors | 
| flickerstreak@108 | 107   end | 
| flickerstreak@108 | 108 end | 
| flickerstreak@108 | 109 | 
| flickerstreak@108 | 110 function module:GetGroup( name ) | 
| flickerstreak@108 | 111   if not self.groups[name] then | 
| flickerstreak@108 | 112     self.groups[name] = self.LBF:Group("ReAction", name) | 
| flickerstreak@108 | 113   end | 
| flickerstreak@108 | 114   return self.groups[name] | 
| flickerstreak@108 | 115 end |