Mercurial > wow > reaction
view modules/LBF.lua @ 161:d0a41fc7b0d7
Totem bar support
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 21 Aug 2009 04:15:09 +0000 |
parents | 410d036c43b2 |
children | df68b5a40490 |
line wrap: on
line source
-- 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