Mercurial > wow > reaction
comparison modules/Totem.lua @ 161:d0a41fc7b0d7
Totem bar support
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 21 Aug 2009 04:15:09 +0000 |
parents | |
children | fc08372f0c7a |
comparison
equal
deleted
inserted
replaced
160:caec78119a17 | 161:d0a41fc7b0d7 |
---|---|
1 --[[ | |
2 ReAction Totem button module | |
3 | |
4 --]] | |
5 | |
6 -- local imports | |
7 local ReAction = ReAction | |
8 local L = ReAction.L | |
9 local _G = _G | |
10 | |
11 -- button | |
12 local Button = ReAction.Button.MultiCast | |
13 | |
14 -- module declaration | |
15 local moduleID = "Totem" | |
16 local module = ReAction:NewModule( moduleID, | |
17 "AceEvent-3.0" | |
18 -- mixins go here | |
19 ) | |
20 | |
21 -- handlers | |
22 function module:OnInitialize() | |
23 self.db = ReAction.db:RegisterNamespace( moduleID, | |
24 { | |
25 profile = { | |
26 buttons = { } | |
27 } | |
28 } | |
29 ) | |
30 | |
31 self.buttons = { } | |
32 | |
33 ReAction:RegisterOptions(self, self:GetOptions()) | |
34 | |
35 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") | |
36 ReAction.RegisterCallback(self, "OnDestroyBar") | |
37 ReAction.RegisterCallback(self, "OnRefreshBar") | |
38 ReAction.RegisterCallback(self, "OnEraseBar") | |
39 ReAction.RegisterCallback(self, "OnRenameBar") | |
40 | |
41 -- TODO: register for learning new spells | |
42 end | |
43 | |
44 function module:OnEnable() | |
45 ReAction:RegisterBarType(L["Totem Bar"], | |
46 { | |
47 type = moduleID , | |
48 defaultButtonSize = 36, | |
49 defaultBarRows = 1, | |
50 defaultBarCols = 6, | |
51 defaultBarSpacing = 3 | |
52 }) | |
53 | |
54 end | |
55 | |
56 function module:OnDisable() | |
57 ReAction:UnregisterBarType(L["Totem Bar"]) | |
58 end | |
59 | |
60 function module:OnDestroyBar(event, bar, name) | |
61 local btns = self.buttons[bar] | |
62 if btns then | |
63 for _,b in pairs(btns) do | |
64 if b then | |
65 b:Destroy() | |
66 end | |
67 end | |
68 self.buttons[bar] = nil | |
69 end | |
70 end | |
71 | |
72 function module:OnRefreshBar(event, bar, name) | |
73 if bar.config.type == moduleID then | |
74 local btns = self.buttons[bar] | |
75 if btns == nil then | |
76 btns = { } | |
77 self.buttons[bar] = btns | |
78 end | |
79 local profile = self.db.profile | |
80 if profile.buttons[name] == nil then | |
81 profile.buttons[name] = {} | |
82 end | |
83 local btnCfg = profile.buttons[name] | |
84 | |
85 local r, c = bar:GetButtonGrid() | |
86 local n = r*c | |
87 n = min(n,Button.SetupBarHeader(bar)) | |
88 for i = 1, n do | |
89 if btnCfg[i] == nil then | |
90 btnCfg[i] = {} | |
91 end | |
92 if btns[i] == nil then | |
93 local success, r = pcall(Button.New,Button,i,btnCfg,bar) | |
94 if success and r then | |
95 btns[i] = r | |
96 bar:AddButton(i,r) | |
97 else | |
98 geterrorhandler()(r) | |
99 n = i - 1 | |
100 bar:ClipNButtons(n) | |
101 break | |
102 end | |
103 end | |
104 btns[i]:Refresh() | |
105 end | |
106 for i = n+1, #btns do | |
107 if btns[i] then | |
108 bar:RemoveButton(btns[i]) | |
109 btns[i] = btns[i]:Destroy() | |
110 if btnCfg[i] then | |
111 btnCfg[i] = nil | |
112 end | |
113 end | |
114 end | |
115 end | |
116 | |
117 end | |
118 | |
119 function module:OnEraseBar(event, bar, name) | |
120 self.db.profile.buttons[name] = nil | |
121 end | |
122 | |
123 function module:OnRenameBar(event, bar, oldName, newName) | |
124 local b = self.db.profile.buttons | |
125 b[newname], b[oldname] = b[oldname], nil | |
126 end | |
127 | |
128 function module:RefreshAll() | |
129 for bar in pairs(self.buttons) do | |
130 self:OnRefreshBar(nil,bar,bar:GetName()) | |
131 end | |
132 end | |
133 | |
134 | |
135 ---- options ---- | |
136 function module:GetOptions() | |
137 return { | |
138 stance = | |
139 { | |
140 name = L["Totem Buttons"], | |
141 type = "group", | |
142 args = { | |
143 -- TODO | |
144 } | |
145 } | |
146 } | |
147 end |