flickerstreak@24
|
1 --[[
|
flickerstreak@24
|
2 ReAction Action-button module.
|
flickerstreak@24
|
3
|
flickerstreak@24
|
4 The button module implements standard action button functionality by wrapping Blizzard's
|
flickerstreak@24
|
5 ActionButton frame and associated functions. It also provides some button layout
|
flickerstreak@24
|
6 modification tools.
|
flickerstreak@24
|
7
|
flickerstreak@24
|
8 --]]
|
flickerstreak@24
|
9
|
flickerstreak@24
|
10 -- local imports
|
flickerstreak@24
|
11 local ReAction = ReAction
|
flickerstreak@24
|
12 local L = ReAction.L
|
flickerstreak@24
|
13 local _G = _G
|
flickerstreak@24
|
14 local AceOO = AceLibrary("AceOO-2.0")
|
flickerstreak@24
|
15 local CreateFrame = CreateFrame
|
flickerstreak@24
|
16 local print = ReAction.print
|
flickerstreak@24
|
17
|
flickerstreak@24
|
18 -- module declaration
|
flickerstreak@24
|
19 local moduleID = "Action"
|
flickerstreak@24
|
20 local module = ReAction:NewModule( moduleID,
|
flickerstreak@24
|
21 "AceEvent-2.0"
|
flickerstreak@24
|
22 )
|
flickerstreak@24
|
23
|
flickerstreak@24
|
24 --
|
flickerstreak@24
|
25 -- action button class declaration
|
flickerstreak@24
|
26 --
|
flickerstreak@24
|
27 local BtnClass = AceOO.Class()
|
flickerstreak@24
|
28 local Button = BtnClass.prototype
|
flickerstreak@24
|
29 module.BtnClass = BtnClass
|
flickerstreak@24
|
30
|
flickerstreak@24
|
31
|
flickerstreak@24
|
32
|
flickerstreak@24
|
33 -- module methods
|
flickerstreak@24
|
34 function module:OnInitialize()
|
flickerstreak@24
|
35 self.db = ReAction:AcquireDBNamespace(moduleID)
|
flickerstreak@24
|
36 ReAction:RegisterDefaults(moduleID,"profile",
|
flickerstreak@24
|
37 {
|
flickerstreak@24
|
38 buttons = { }
|
flickerstreak@24
|
39 }
|
flickerstreak@24
|
40 )
|
flickerstreak@24
|
41
|
flickerstreak@24
|
42 self.buttons = { }
|
flickerstreak@24
|
43 end
|
flickerstreak@24
|
44
|
flickerstreak@24
|
45 function module:OnEnable()
|
flickerstreak@24
|
46 end
|
flickerstreak@24
|
47
|
flickerstreak@24
|
48 function module:OnDisable()
|
flickerstreak@24
|
49 end
|
flickerstreak@24
|
50
|
flickerstreak@24
|
51 function module:OnProfileEnable()
|
flickerstreak@24
|
52 end
|
flickerstreak@24
|
53
|
flickerstreak@24
|
54 function module:ApplyToBar(bar)
|
flickerstreak@24
|
55 self:RefreshBar(bar)
|
flickerstreak@24
|
56 end
|
flickerstreak@24
|
57
|
flickerstreak@24
|
58 function module:RefreshBar(bar)
|
flickerstreak@24
|
59 if self.buttons[bar] == nil then
|
flickerstreak@24
|
60 self.buttons[bar] = { }
|
flickerstreak@24
|
61 end
|
flickerstreak@24
|
62 local btns = self.buttons[bar]
|
flickerstreak@24
|
63 local profile = self.db.profile
|
flickerstreak@24
|
64 local barName = bar:GetName()
|
flickerstreak@24
|
65 if profile.buttons[barName] == nil then
|
flickerstreak@24
|
66 profile.buttons[barName] = {}
|
flickerstreak@24
|
67 end
|
flickerstreak@24
|
68 local btnCfg = profile.buttons[barName]
|
flickerstreak@24
|
69
|
flickerstreak@24
|
70 local r, c = bar:GetButtonGrid()
|
flickerstreak@24
|
71 local n = r*c
|
flickerstreak@24
|
72 for i = 1, n do
|
flickerstreak@24
|
73 if btnCfg[i] == nil then
|
flickerstreak@24
|
74 btnCfg[i] = {}
|
flickerstreak@24
|
75 end
|
flickerstreak@24
|
76 if btns[i] == nil then
|
flickerstreak@24
|
77 btns[i] = self.BtnClass:new(bar,i,btnCfg[i])
|
flickerstreak@24
|
78 else
|
flickerstreak@24
|
79 btns[i]:Refresh(bar,i)
|
flickerstreak@24
|
80 end
|
flickerstreak@24
|
81 end
|
flickerstreak@24
|
82 for i = n+1, #btns do
|
flickerstreak@24
|
83 btns[i] = btns[i]:Destroy()
|
flickerstreak@24
|
84 if btnCfg[i] then
|
flickerstreak@24
|
85 btnCfg[i] = nil
|
flickerstreak@24
|
86 end
|
flickerstreak@24
|
87 end
|
flickerstreak@24
|
88 end
|
flickerstreak@24
|
89
|
flickerstreak@24
|
90 function module:RemoveFromBar(bar)
|
flickerstreak@24
|
91 if self.buttons[bar] then
|
flickerstreak@24
|
92 local btns = self.buttons[bar]
|
flickerstreak@24
|
93 for _,b in pairs(btns) do
|
flickerstreak@24
|
94 if b then
|
flickerstreak@24
|
95 b:Destroy()
|
flickerstreak@24
|
96 end
|
flickerstreak@24
|
97 end
|
flickerstreak@24
|
98 self.buttons[bar] = nil
|
flickerstreak@24
|
99 end
|
flickerstreak@24
|
100 end
|
flickerstreak@24
|
101
|
flickerstreak@24
|
102 function module:EraseBarConfig(barName)
|
flickerstreak@24
|
103 self.db.profile.buttons[barName] = nil
|
flickerstreak@24
|
104 end
|
flickerstreak@24
|
105
|
flickerstreak@24
|
106 function module:ApplyConfigMode(mode,bars)
|
flickerstreak@24
|
107 for _, btns in pairs(self.buttons) do
|
flickerstreak@24
|
108 if btn then
|
flickerstreak@24
|
109 for _, b in pairs(btns) do
|
flickerstreak@24
|
110 if b then
|
flickerstreak@24
|
111 if mode then
|
flickerstreak@24
|
112 if not b.actionIDLabel then
|
flickerstreak@24
|
113 local label = b:GetFrame():CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@24
|
114 label:SetAllPoints()
|
flickerstreak@24
|
115 label:SetJustifyH("CENTER")
|
flickerstreak@24
|
116 label:SetShadowColor(0,0,0,1)
|
flickerstreak@24
|
117 label:SetShadowOffset(2,-2)
|
flickerstreak@24
|
118 label:SetText(tostring(b:GetActionID()))
|
flickerstreak@24
|
119 b.actionIDLabel = label
|
flickerstreak@24
|
120 end
|
flickerstreak@24
|
121 b.actionIDLabel:Show()
|
flickerstreak@24
|
122 elseif b.actionIDLabel then
|
flickerstreak@24
|
123 b.actionIDLabel:Hide()
|
flickerstreak@24
|
124 end
|
flickerstreak@24
|
125 end
|
flickerstreak@24
|
126 end
|
flickerstreak@24
|
127 end
|
flickerstreak@24
|
128 end
|
flickerstreak@24
|
129 end
|
flickerstreak@24
|
130
|
flickerstreak@24
|
131 function module:GetGlobalBarOptions(opts)
|
flickerstreak@24
|
132 if self.globalBarOpts == nil then
|
flickerstreak@24
|
133 self.globalBarOpts = {
|
flickerstreak@24
|
134 newActionBar = {
|
flickerstreak@24
|
135 type = "execute",
|
flickerstreak@24
|
136 name = L["New Action Bar"],
|
flickerstreak@24
|
137 desc = L["Create a new bar of standard action buttons"],
|
flickerstreak@24
|
138 func = function()
|
flickerstreak@24
|
139 ReAction:GetModule("Bar"):CreateBar()
|
flickerstreak@24
|
140 end,
|
flickerstreak@24
|
141 disabled = InCombatLockdown,
|
flickerstreak@24
|
142 }
|
flickerstreak@24
|
143 }
|
flickerstreak@24
|
144 end
|
flickerstreak@24
|
145 return self.globalBarOpts
|
flickerstreak@24
|
146 end
|
flickerstreak@24
|
147
|
flickerstreak@24
|
148 function module:GetBarMenuOptions(bar)
|
flickerstreak@24
|
149 if not bar.modMenuOpts[moduleID] then
|
flickerstreak@24
|
150 bar.modMenuOpts[moduleID] = {
|
flickerstreak@24
|
151 }
|
flickerstreak@24
|
152 end
|
flickerstreak@24
|
153 return bar.modMenuOpts[moduleID]
|
flickerstreak@24
|
154 end
|
flickerstreak@24
|
155
|
flickerstreak@24
|
156 function module:GetBarConfigOptions(bar)
|
flickerstreak@24
|
157 if not bar.modConfigOpts[moduleID] then
|
flickerstreak@24
|
158 bar.modConfigOpts[moduleID] = {
|
flickerstreak@24
|
159 }
|
flickerstreak@24
|
160 end
|
flickerstreak@24
|
161 return bar.modConfigOpts[moduleID]
|
flickerstreak@24
|
162 end
|
flickerstreak@24
|
163
|
flickerstreak@24
|
164
|
flickerstreak@24
|
165
|
flickerstreak@24
|
166 -- use-count of action IDs
|
flickerstreak@24
|
167 local ActionIDList = setmetatable( {}, {
|
flickerstreak@24
|
168 __index = function(self, idx)
|
flickerstreak@24
|
169 if idx == nil then
|
flickerstreak@24
|
170 for i = 1, 120 do
|
flickerstreak@24
|
171 if rawget(self,i) == nil then
|
flickerstreak@24
|
172 rawset(self,i,1)
|
flickerstreak@24
|
173 return i
|
flickerstreak@24
|
174 end
|
flickerstreak@24
|
175 end
|
flickerstreak@24
|
176 else
|
flickerstreak@24
|
177 local c = rawget(self,idx) or 0
|
flickerstreak@24
|
178 rawset(self,idx,c+1)
|
flickerstreak@24
|
179 return idx
|
flickerstreak@24
|
180 end
|
flickerstreak@24
|
181 end,
|
flickerstreak@24
|
182 __newindex = function(self,idx,value)
|
flickerstreak@24
|
183 if value == nil then
|
flickerstreak@24
|
184 value = rawget(self,idx)
|
flickerstreak@24
|
185 if value == 1 then
|
flickerstreak@24
|
186 value = nil
|
flickerstreak@24
|
187 elseif value then
|
flickerstreak@24
|
188 value = value - 1
|
flickerstreak@24
|
189 end
|
flickerstreak@24
|
190 end
|
flickerstreak@24
|
191 rawset(self,idx,value)
|
flickerstreak@24
|
192 end
|
flickerstreak@24
|
193 })
|
flickerstreak@24
|
194
|
flickerstreak@24
|
195
|
flickerstreak@24
|
196
|
flickerstreak@24
|
197 -- button class methods
|
flickerstreak@24
|
198 function Button:init( bar, idx, config )
|
flickerstreak@24
|
199 BtnClass.super.prototype.init(self)
|
flickerstreak@24
|
200 self.bar, self.idx, self.config = bar, idx, config
|
flickerstreak@24
|
201
|
flickerstreak@24
|
202 local barFrame = bar:GetFrame()
|
flickerstreak@24
|
203
|
flickerstreak@24
|
204 self.name = config.name or "ReAction_"..bar:GetName().."_"..idx
|
flickerstreak@24
|
205 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
|
flickerstreak@24
|
206
|
flickerstreak@24
|
207 local f = CreateFrame("CheckButton", self.name, barFrame, "ActionBarButtonTemplate")
|
flickerstreak@24
|
208 -- TODO: re-implement ActionButton event handlers that don't do secure stuff
|
flickerstreak@24
|
209
|
flickerstreak@24
|
210 -- this will probably cause taint, using right now for display/debugging purposes
|
flickerstreak@24
|
211 f:SetScript("OnAttributeChanged",
|
flickerstreak@24
|
212 function()
|
flickerstreak@24
|
213 ActionButton_UpdateAction()
|
flickerstreak@24
|
214 end
|
flickerstreak@24
|
215 )
|
flickerstreak@24
|
216 f:SetAttribute("action", config.actionID)
|
flickerstreak@24
|
217 barFrame:SetAttribute("addchild",f)
|
flickerstreak@24
|
218 self.frame = f
|
flickerstreak@24
|
219 self:Refresh(bar,idx)
|
flickerstreak@24
|
220 end
|
flickerstreak@24
|
221
|
flickerstreak@24
|
222 function Button:Destroy()
|
flickerstreak@24
|
223 local f = self.frame
|
flickerstreak@24
|
224 f:UnregisterAllEvents()
|
flickerstreak@24
|
225 f:Hide()
|
flickerstreak@24
|
226 f:SetParent(UIParent)
|
flickerstreak@24
|
227 f:ClearAllPoints()
|
flickerstreak@24
|
228 if self.config.name then
|
flickerstreak@24
|
229 _G[self.config.name] = nil
|
flickerstreak@24
|
230 end
|
flickerstreak@24
|
231 ActionIDList[self.config.actionID] = nil
|
flickerstreak@24
|
232 self.frame = nil
|
flickerstreak@24
|
233 self.config = nil
|
flickerstreak@24
|
234 self.bar = nil
|
flickerstreak@24
|
235 end
|
flickerstreak@24
|
236
|
flickerstreak@24
|
237 function Button:Refresh(bar,idx)
|
flickerstreak@24
|
238 bar:PlaceButton(self.frame, idx, 36, 36)
|
flickerstreak@24
|
239 end
|
flickerstreak@24
|
240
|
flickerstreak@24
|
241 function Button:GetFrame()
|
flickerstreak@24
|
242 return self.frame
|
flickerstreak@24
|
243 end
|
flickerstreak@24
|
244
|
flickerstreak@24
|
245 function Button:GetName()
|
flickerstreak@24
|
246 return self.name
|
flickerstreak@24
|
247 end
|
flickerstreak@24
|
248
|
flickerstreak@24
|
249 function Button:GetActionID()
|
flickerstreak@24
|
250 return self.config.actionID
|
flickerstreak@24
|
251 end
|