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