flickerstreak@28
|
1 --[[
|
flickerstreak@53
|
2 ReAction Pet Action button module
|
flickerstreak@53
|
3
|
flickerstreak@53
|
4 The button module implements standard action button functionality by wrapping Blizzard's
|
flickerstreak@77
|
5 PetActionButton frame and associated functions.
|
flickerstreak@28
|
6
|
flickerstreak@28
|
7 --]]
|
flickerstreak@28
|
8
|
flickerstreak@28
|
9 -- local imports
|
flickerstreak@28
|
10 local ReAction = ReAction
|
flickerstreak@28
|
11 local L = ReAction.L
|
flickerstreak@28
|
12 local _G = _G
|
flickerstreak@53
|
13 local CreateFrame = CreateFrame
|
flickerstreak@28
|
14
|
flickerstreak@80
|
15 ReAction:UpdateRevision("$Revision$")
|
flickerstreak@77
|
16
|
flickerstreak@93
|
17 -- libraries
|
flickerstreak@93
|
18 local KB = LibStub("LibKeyBound-1.0")
|
flickerstreak@93
|
19
|
flickerstreak@28
|
20 -- module declaration
|
flickerstreak@28
|
21 local moduleID = "PetAction"
|
flickerstreak@28
|
22 local module = ReAction:NewModule( moduleID )
|
flickerstreak@28
|
23
|
flickerstreak@77
|
24 -- Button class declaration
|
flickerstreak@77
|
25 local Button = { }
|
flickerstreak@77
|
26
|
flickerstreak@28
|
27 -- module methods
|
flickerstreak@28
|
28 function module:OnInitialize()
|
flickerstreak@53
|
29 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@28
|
30 {
|
flickerstreak@28
|
31 profile = {
|
flickerstreak@28
|
32 buttons = { }
|
flickerstreak@28
|
33 }
|
flickerstreak@28
|
34 }
|
flickerstreak@28
|
35 )
|
flickerstreak@53
|
36 self.buttons = { }
|
flickerstreak@63
|
37
|
flickerstreak@63
|
38 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@63
|
39
|
flickerstreak@63
|
40 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@63
|
41 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@63
|
42 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@63
|
43 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@63
|
44 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@63
|
45 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@93
|
46
|
flickerstreak@93
|
47 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
|
flickerstreak@93
|
48 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
|
flickerstreak@93
|
49 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@28
|
50 end
|
flickerstreak@28
|
51
|
flickerstreak@28
|
52 function module:OnEnable()
|
flickerstreak@53
|
53 ReAction:RegisterBarType(L["Pet Action Bar"],
|
flickerstreak@53
|
54 {
|
flickerstreak@53
|
55 type = moduleID ,
|
flickerstreak@53
|
56 defaultButtonSize = 30,
|
flickerstreak@53
|
57 defaultBarRows = 1,
|
flickerstreak@53
|
58 defaultBarCols = 10,
|
flickerstreak@53
|
59 defaultBarSpacing = 8
|
flickerstreak@53
|
60 })
|
flickerstreak@28
|
61 end
|
flickerstreak@28
|
62
|
flickerstreak@28
|
63 function module:OnDisable()
|
flickerstreak@53
|
64 ReAction:UnregisterBarType(L["Pet Action Bar"])
|
flickerstreak@28
|
65 end
|
flickerstreak@28
|
66
|
flickerstreak@63
|
67 function module:OnCreateBar(event, bar, name)
|
flickerstreak@53
|
68 if bar.config.type == moduleID then
|
flickerstreak@53
|
69 -- auto show/hide when pet exists
|
flickerstreak@53
|
70 bar:GetFrame():SetAttribute("unit","pet")
|
flickerstreak@90
|
71 if not ReAction:GetConfigMode() then
|
flickerstreak@90
|
72 RegisterUnitWatch(bar:GetFrame())
|
flickerstreak@90
|
73 end
|
flickerstreak@63
|
74 self:OnRefreshBar(event, bar, name)
|
flickerstreak@28
|
75 end
|
flickerstreak@28
|
76 end
|
flickerstreak@28
|
77
|
flickerstreak@63
|
78 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@53
|
79 if bar.config.type == moduleID then
|
flickerstreak@53
|
80 if self.buttons[bar] == nil then
|
flickerstreak@53
|
81 self.buttons[bar] = { }
|
flickerstreak@53
|
82 end
|
flickerstreak@53
|
83 local btns = self.buttons[bar]
|
flickerstreak@53
|
84 local profile = self.db.profile
|
flickerstreak@63
|
85 if profile.buttons[name] == nil then
|
flickerstreak@63
|
86 profile.buttons[name] = {}
|
flickerstreak@53
|
87 end
|
flickerstreak@63
|
88 local btnCfg = profile.buttons[name]
|
flickerstreak@53
|
89
|
flickerstreak@53
|
90 local r, c = bar:GetButtonGrid()
|
flickerstreak@53
|
91 local n = r*c
|
flickerstreak@53
|
92 for i = 1, n do
|
flickerstreak@53
|
93 if btnCfg[i] == nil then
|
flickerstreak@53
|
94 btnCfg[i] = {}
|
flickerstreak@53
|
95 end
|
flickerstreak@53
|
96 if btns[i] == nil then
|
flickerstreak@77
|
97 local b = Button:New(bar,i,btnCfg[i])
|
flickerstreak@77
|
98 btns[i] = b
|
flickerstreak@77
|
99 bar:AddButton(i,b)
|
flickerstreak@53
|
100 end
|
flickerstreak@77
|
101 btns[i]:Refresh()
|
flickerstreak@53
|
102 end
|
flickerstreak@53
|
103 for i = n+1, #btns do
|
flickerstreak@53
|
104 if btns[i] then
|
flickerstreak@77
|
105 bar:RemoveButton(btns[i])
|
flickerstreak@53
|
106 btns[i] = btns[i]:Destroy()
|
flickerstreak@53
|
107 if btnCfg[i] then
|
flickerstreak@53
|
108 btnCfg[i] = nil
|
flickerstreak@53
|
109 end
|
flickerstreak@53
|
110 end
|
flickerstreak@53
|
111 end
|
flickerstreak@53
|
112 end
|
flickerstreak@53
|
113 end
|
flickerstreak@53
|
114
|
flickerstreak@63
|
115 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@53
|
116 if self.buttons[bar] then
|
flickerstreak@53
|
117 local btns = self.buttons[bar]
|
flickerstreak@53
|
118 for _,b in pairs(btns) do
|
flickerstreak@53
|
119 if b then
|
flickerstreak@53
|
120 b:Destroy()
|
flickerstreak@53
|
121 end
|
flickerstreak@53
|
122 end
|
flickerstreak@53
|
123 self.buttons[bar] = nil
|
flickerstreak@53
|
124 end
|
flickerstreak@53
|
125 end
|
flickerstreak@53
|
126
|
flickerstreak@63
|
127 function module:OnEraseBar(event, bar, name)
|
flickerstreak@63
|
128 self.db.profile.buttons[name] = nil
|
flickerstreak@53
|
129 end
|
flickerstreak@53
|
130
|
flickerstreak@63
|
131 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@53
|
132 local b = self.db.profile.buttons
|
flickerstreak@53
|
133 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@53
|
134 end
|
flickerstreak@53
|
135
|
flickerstreak@53
|
136
|
flickerstreak@63
|
137 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@77
|
138 for _, buttons in pairs(self.buttons) do
|
flickerstreak@77
|
139 for _, b in pairs(buttons) do
|
flickerstreak@77
|
140 b:ShowActionIDLabel(mode)
|
flickerstreak@77
|
141 end
|
flickerstreak@77
|
142 end
|
flickerstreak@63
|
143 for _, bar in ReAction:IterateBars() do
|
flickerstreak@53
|
144 if bar and self.buttons[bar] then
|
flickerstreak@53
|
145 local f = bar:GetFrame()
|
flickerstreak@53
|
146 if mode then
|
flickerstreak@53
|
147 UnregisterUnitWatch(f)
|
flickerstreak@53
|
148 f:Show()
|
flickerstreak@53
|
149 else
|
flickerstreak@53
|
150 RegisterUnitWatch(f)
|
flickerstreak@53
|
151 end
|
flickerstreak@53
|
152 end
|
flickerstreak@53
|
153 end
|
flickerstreak@53
|
154 end
|
flickerstreak@53
|
155
|
flickerstreak@93
|
156 function module:LIBKEYBOUND_ENABLED(evt)
|
flickerstreak@93
|
157 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
158 for _, b in pairs(buttons) do
|
flickerstreak@93
|
159 b:SetKeybindMode(true)
|
flickerstreak@93
|
160 end
|
flickerstreak@93
|
161 end
|
flickerstreak@93
|
162 end
|
flickerstreak@93
|
163
|
flickerstreak@93
|
164 function module:LIBKEYBOUND_DISABLED(evt)
|
flickerstreak@93
|
165 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
166 for _, b in pairs(buttons) do
|
flickerstreak@93
|
167 b:SetKeybindMode(false)
|
flickerstreak@93
|
168 end
|
flickerstreak@93
|
169 end
|
flickerstreak@93
|
170 end
|
flickerstreak@93
|
171
|
flickerstreak@53
|
172
|
flickerstreak@60
|
173 ---- Options ----
|
flickerstreak@60
|
174 function module:GetBarOptions(bar)
|
flickerstreak@91
|
175 if bar.config.type == moduleID then
|
flickerstreak@91
|
176 return {
|
flickerstreak@91
|
177 type = "group",
|
flickerstreak@91
|
178 name = L["Pet Buttons"],
|
flickerstreak@91
|
179 args = {
|
flickerstreak@91
|
180 }
|
flickerstreak@60
|
181 }
|
flickerstreak@91
|
182 end
|
flickerstreak@59
|
183 end
|
flickerstreak@59
|
184
|
flickerstreak@53
|
185
|
flickerstreak@28
|
186
|
flickerstreak@77
|
187 ------ Button class ------
|
flickerstreak@77
|
188
|
flickerstreak@28
|
189 -- use-count of action IDs
|
flickerstreak@53
|
190 local nActionIDs = NUM_PET_ACTION_SLOTS
|
flickerstreak@28
|
191 local ActionIDList = setmetatable( {}, {
|
flickerstreak@28
|
192 __index = function(self, idx)
|
flickerstreak@28
|
193 if idx == nil then
|
flickerstreak@53
|
194 for i = 1, nActionIDs do
|
flickerstreak@28
|
195 if rawget(self,i) == nil then
|
flickerstreak@28
|
196 rawset(self,i,1)
|
flickerstreak@28
|
197 return i
|
flickerstreak@28
|
198 end
|
flickerstreak@28
|
199 end
|
flickerstreak@53
|
200 error("ran out of pet action IDs")
|
flickerstreak@28
|
201 else
|
flickerstreak@28
|
202 local c = rawget(self,idx) or 0
|
flickerstreak@28
|
203 rawset(self,idx,c+1)
|
flickerstreak@28
|
204 return idx
|
flickerstreak@28
|
205 end
|
flickerstreak@28
|
206 end,
|
flickerstreak@28
|
207 __newindex = function(self,idx,value)
|
flickerstreak@28
|
208 if value == nil then
|
flickerstreak@28
|
209 value = rawget(self,idx)
|
flickerstreak@28
|
210 if value == 1 then
|
flickerstreak@28
|
211 value = nil
|
flickerstreak@28
|
212 elseif value then
|
flickerstreak@28
|
213 value = value - 1
|
flickerstreak@28
|
214 end
|
flickerstreak@28
|
215 end
|
flickerstreak@28
|
216 rawset(self,idx,value)
|
flickerstreak@28
|
217 end
|
flickerstreak@28
|
218 })
|
flickerstreak@28
|
219
|
flickerstreak@53
|
220 local frameRecycler = {}
|
flickerstreak@93
|
221 local trash = CreateFrame("Frame")
|
flickerstreak@93
|
222 local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings
|
flickerstreak@93
|
223 do
|
flickerstreak@93
|
224 local buttonLookup = setmetatable({},{__mode="kv"})
|
flickerstreak@93
|
225
|
flickerstreak@93
|
226 -- Use KeyBound-1.0 for binding, but use Override bindings instead of
|
flickerstreak@93
|
227 -- regular bindings to support multiple profile use. This is a little
|
flickerstreak@93
|
228 -- weird with the KeyBound dialog box (which has per-char selector as well
|
flickerstreak@93
|
229 -- as an OK/Cancel box) but it's the least amount of effort to implement.
|
flickerstreak@93
|
230 function GetActionName(f)
|
flickerstreak@93
|
231 local b = buttonLookup[f]
|
flickerstreak@93
|
232 if b then
|
flickerstreak@93
|
233 return format("%s:%s", b.bar:GetName(), b.idx)
|
flickerstreak@93
|
234 end
|
flickerstreak@93
|
235 end
|
flickerstreak@93
|
236
|
flickerstreak@93
|
237 function GetHotkey(f)
|
flickerstreak@93
|
238 local b = buttonLookup[f]
|
flickerstreak@93
|
239 if b then
|
flickerstreak@93
|
240 return KB:ToShortKey(b:GetConfig().hotkey)
|
flickerstreak@93
|
241 end
|
flickerstreak@93
|
242 end
|
flickerstreak@93
|
243
|
flickerstreak@93
|
244 function SetKey(f, key)
|
flickerstreak@93
|
245 local b = buttonLookup[f]
|
flickerstreak@93
|
246 if b then
|
flickerstreak@93
|
247 local c = b:GetConfig()
|
flickerstreak@93
|
248 if c.hotkey then
|
flickerstreak@93
|
249 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@93
|
250 end
|
flickerstreak@93
|
251 if key then
|
flickerstreak@93
|
252 SetOverrideBindingClick(f, false, key, f:GetName(), nil)
|
flickerstreak@93
|
253 end
|
flickerstreak@93
|
254 c.hotkey = key
|
flickerstreak@93
|
255 b:DisplayHotkey(GetHotkey(f))
|
flickerstreak@93
|
256 end
|
flickerstreak@93
|
257 end
|
flickerstreak@93
|
258
|
flickerstreak@93
|
259 function FreeKey(f, key)
|
flickerstreak@93
|
260 local b = buttonLookup[f]
|
flickerstreak@93
|
261 if b then
|
flickerstreak@93
|
262 local c = b:GetConfig()
|
flickerstreak@93
|
263 if c.hotkey == key then
|
flickerstreak@93
|
264 local action = f:GetActionName()
|
flickerstreak@93
|
265 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@93
|
266 c.hotkey = nil
|
flickerstreak@93
|
267 b:DisplayHotkey(nil)
|
flickerstreak@93
|
268 return action
|
flickerstreak@93
|
269 end
|
flickerstreak@93
|
270 end
|
flickerstreak@93
|
271 return ReAction:FreeOverrideHotkey(key)
|
flickerstreak@93
|
272 end
|
flickerstreak@93
|
273
|
flickerstreak@93
|
274 function ClearBindings(f)
|
flickerstreak@93
|
275 SetKey(f, nil)
|
flickerstreak@93
|
276 end
|
flickerstreak@93
|
277
|
flickerstreak@93
|
278 function GetBindings(f)
|
flickerstreak@93
|
279 local b = buttonLookup[f]
|
flickerstreak@93
|
280 if b then
|
flickerstreak@93
|
281 return b:GetConfig().hotkey
|
flickerstreak@93
|
282 end
|
flickerstreak@93
|
283 end
|
flickerstreak@93
|
284
|
flickerstreak@93
|
285 function KBAttach( button )
|
flickerstreak@93
|
286 local f = button:GetFrame()
|
flickerstreak@93
|
287 f.GetActionName = GetActionName
|
flickerstreak@93
|
288 f.GetHotkey = GetHotkey
|
flickerstreak@93
|
289 f.SetKey = SetKey
|
flickerstreak@93
|
290 f.FreeKey = FreeKey
|
flickerstreak@93
|
291 f.ClearBindings = ClearBindings
|
flickerstreak@93
|
292 f.GetBindings = GetBindings
|
flickerstreak@93
|
293 buttonLookup[f] = button
|
flickerstreak@93
|
294 f:SetKey(button:GetConfig().hotkey)
|
flickerstreak@93
|
295 ReAction:RegisterKeybindFrame(f)
|
flickerstreak@93
|
296 if ReAction:GetKeybindMode() then
|
flickerstreak@93
|
297 button.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@93
|
298 button.border:Show()
|
flickerstreak@93
|
299 end
|
flickerstreak@93
|
300 end
|
flickerstreak@93
|
301 end
|
flickerstreak@93
|
302
|
flickerstreak@90
|
303 local meta = { __index = Button }
|
flickerstreak@28
|
304
|
flickerstreak@77
|
305 function Button:New( bar, idx, config )
|
flickerstreak@77
|
306 -- create new self
|
flickerstreak@90
|
307 self = setmetatable(
|
flickerstreak@90
|
308 {
|
flickerstreak@90
|
309 bar = bar,
|
flickerstreak@90
|
310 idx = idx,
|
flickerstreak@90
|
311 config = config,
|
flickerstreak@90
|
312 }, meta )
|
flickerstreak@28
|
313
|
flickerstreak@85
|
314 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx)
|
flickerstreak@53
|
315 config.name = name
|
flickerstreak@77
|
316 self.name = name
|
flickerstreak@28
|
317 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
|
flickerstreak@28
|
318
|
flickerstreak@53
|
319 -- have to recycle frames with the same name:
|
flickerstreak@53
|
320 -- otherwise you either get references to old textures because named CreateFrame()
|
flickerstreak@90
|
321 -- doesn't overwrite existing globals. Can't set them to nil in the global table,
|
flickerstreak@90
|
322 -- as it causes taint.
|
flickerstreak@90
|
323 local parent = bar:GetFrame()
|
flickerstreak@53
|
324 local f = frameRecycler[name]
|
flickerstreak@53
|
325 if f then
|
flickerstreak@77
|
326 f:SetParent(parent)
|
flickerstreak@53
|
327 else
|
flickerstreak@77
|
328 f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate")
|
flickerstreak@93
|
329 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the
|
flickerstreak@93
|
330 -- standard binding. We use override bindings.
|
flickerstreak@93
|
331 local hotkey = _G[name.."HotKey"]
|
flickerstreak@93
|
332 hotkey:SetParent(trash)
|
flickerstreak@93
|
333 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray")
|
flickerstreak@93
|
334 hotkey:SetWidth(36)
|
flickerstreak@93
|
335 hotkey:SetHeight(18)
|
flickerstreak@93
|
336 hotkey:SetJustifyH("RIGHT")
|
flickerstreak@93
|
337 hotkey:SetJustifyV("TOP")
|
flickerstreak@93
|
338 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2)
|
flickerstreak@93
|
339 f.hotkey = hotkey
|
flickerstreak@93
|
340 f:HookScript("OnDragStart", function() self:Update() end)
|
flickerstreak@93
|
341 f:HookScript("OnReceiveDrag", function() self:Update() end)
|
flickerstreak@53
|
342 end
|
flickerstreak@53
|
343 if config.actionID then
|
flickerstreak@53
|
344 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton
|
flickerstreak@53
|
345 end
|
flickerstreak@53
|
346 f:SetFrameStrata("MEDIUM")
|
flickerstreak@93
|
347 self.frame = f
|
flickerstreak@93
|
348 self.icon = _G[("%sIcon"):format(name)]
|
flickerstreak@93
|
349 self.acTex = _G[("%sAutoCastable"):format(name)]
|
flickerstreak@93
|
350 self.acModel = _G[("%sShine"):format(name)]
|
flickerstreak@53
|
351 self.cooldown = _G[("%sCooldown"):format(name)]
|
flickerstreak@93
|
352 self.hotkey = f.hotkey
|
flickerstreak@93
|
353 self.border = _G[("%sBorder"):format(name)]
|
flickerstreak@53
|
354
|
flickerstreak@53
|
355
|
flickerstreak@77
|
356 f:RegisterEvent("PLAYER_CONTROL_LOST");
|
flickerstreak@53
|
357 f:RegisterEvent("PLAYER_CONTROL_GAINED");
|
flickerstreak@53
|
358 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED");
|
flickerstreak@53
|
359 f:RegisterEvent("UNIT_PET");
|
flickerstreak@53
|
360 f:RegisterEvent("UNIT_FLAGS");
|
flickerstreak@53
|
361 f:RegisterEvent("UNIT_AURA");
|
flickerstreak@53
|
362 f:RegisterEvent("PET_BAR_UPDATE");
|
flickerstreak@53
|
363 f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN");
|
flickerstreak@53
|
364
|
flickerstreak@53
|
365 f:SetScript("OnEvent",
|
flickerstreak@53
|
366 function(event,arg1)
|
flickerstreak@53
|
367 if event =="PET_BAR_UPDATE_COOLDOWN" then
|
flickerstreak@53
|
368 self:UpdateCooldown()
|
flickerstreak@53
|
369 elseif event == "UPDATE_BINDINGS" then
|
flickerstreak@53
|
370 self:UpdateHotkey()
|
flickerstreak@53
|
371 else
|
flickerstreak@53
|
372 self:Update()
|
flickerstreak@53
|
373 end
|
flickerstreak@53
|
374 end)
|
flickerstreak@28
|
375
|
flickerstreak@93
|
376 KBAttach(self)
|
flickerstreak@88
|
377
|
flickerstreak@77
|
378 self:Refresh()
|
flickerstreak@93
|
379 self:SetKeybindMode(ReAction:GetKeybindMode())
|
flickerstreak@93
|
380
|
flickerstreak@77
|
381 return self
|
flickerstreak@28
|
382 end
|
flickerstreak@28
|
383
|
flickerstreak@28
|
384 function Button:Destroy()
|
flickerstreak@28
|
385 local f = self.frame
|
flickerstreak@28
|
386 f:UnregisterAllEvents()
|
flickerstreak@28
|
387 f:Hide()
|
flickerstreak@28
|
388 f:SetParent(UIParent)
|
flickerstreak@28
|
389 f:ClearAllPoints()
|
flickerstreak@28
|
390 if self.name then
|
flickerstreak@53
|
391 frameRecycler[self.name] = f
|
flickerstreak@28
|
392 _G[self.name] = nil
|
flickerstreak@28
|
393 end
|
flickerstreak@53
|
394 if self.config.actionID then
|
flickerstreak@53
|
395 ActionIDList[self.config.actionID] = nil
|
flickerstreak@53
|
396 end
|
flickerstreak@28
|
397 self.frame = nil
|
flickerstreak@28
|
398 self.config = nil
|
flickerstreak@28
|
399 self.bar = nil
|
flickerstreak@28
|
400 end
|
flickerstreak@28
|
401
|
flickerstreak@77
|
402 function Button:Refresh()
|
flickerstreak@77
|
403 self.bar:PlaceButton(self, 30, 30)
|
flickerstreak@53
|
404 self:Update()
|
flickerstreak@53
|
405 self:UpdateHotkey()
|
flickerstreak@53
|
406 end
|
flickerstreak@53
|
407
|
flickerstreak@53
|
408 function Button:GetFrame()
|
flickerstreak@53
|
409 return self.frame
|
flickerstreak@53
|
410 end
|
flickerstreak@53
|
411
|
flickerstreak@53
|
412 function Button:GetName()
|
flickerstreak@53
|
413 return self.name
|
flickerstreak@53
|
414 end
|
flickerstreak@53
|
415
|
flickerstreak@88
|
416 function Button:GetConfig()
|
flickerstreak@88
|
417 return self.config
|
flickerstreak@88
|
418 end
|
flickerstreak@88
|
419
|
flickerstreak@53
|
420 function Button:GetActionID()
|
flickerstreak@53
|
421 return self.config.actionID
|
flickerstreak@53
|
422 end
|
flickerstreak@53
|
423
|
flickerstreak@53
|
424 function Button:Update()
|
flickerstreak@53
|
425 local id = self.frame:GetID()
|
flickerstreak@53
|
426 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id);
|
flickerstreak@53
|
427 local f = self.frame
|
flickerstreak@53
|
428 --ReAction:Print(("id %d: '%s', '%s', '%s', '%s', '%s', '%s', '%s'"):format(tostring(id), tostring(name),tostring(subtext),tostring(texture),tostring(isToken),tostring(isActive),tostring(autoCastAllowed),tostring(autoCastEnabled)))
|
flickerstreak@53
|
429
|
flickerstreak@53
|
430 if isToken then
|
flickerstreak@53
|
431 self.icon:SetTexture(_G[texture]);
|
flickerstreak@53
|
432 f.tooltipName = _G[name];
|
flickerstreak@53
|
433 else
|
flickerstreak@53
|
434 self.icon:SetTexture(texture);
|
flickerstreak@53
|
435 f.tooltipName = name;
|
flickerstreak@53
|
436 end
|
flickerstreak@53
|
437
|
flickerstreak@53
|
438 f.isToken = isToken;
|
flickerstreak@53
|
439 f.tooltipSubtext = subtext;
|
flickerstreak@53
|
440 f:SetChecked( isActive and 1 or 0);
|
flickerstreak@53
|
441
|
flickerstreak@53
|
442 if autoCastAllowed then
|
flickerstreak@53
|
443 self.acTex:Show();
|
flickerstreak@53
|
444 else
|
flickerstreak@53
|
445 self.acTex:Hide();
|
flickerstreak@53
|
446 end
|
flickerstreak@53
|
447
|
flickerstreak@53
|
448 if autoCastEnabled then
|
flickerstreak@91
|
449 AutoCastShine_AutoCastStart(self.acModel)
|
flickerstreak@53
|
450 else
|
flickerstreak@91
|
451 AutoCastShine_AutoCastStop(self.acModel)
|
flickerstreak@53
|
452 end
|
flickerstreak@53
|
453
|
flickerstreak@53
|
454 if texture then
|
flickerstreak@91
|
455 if GetPetActionSlotUsable(id) then
|
flickerstreak@53
|
456 SetDesaturation(self.icon,nil)
|
flickerstreak@53
|
457 else
|
flickerstreak@53
|
458 SetDesaturation(self.icon,1)
|
flickerstreak@53
|
459 end
|
flickerstreak@53
|
460 self.icon:Show();
|
flickerstreak@53
|
461 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
|
flickerstreak@53
|
462 else
|
flickerstreak@53
|
463 self.icon:Hide();
|
flickerstreak@53
|
464 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot");
|
flickerstreak@53
|
465 end
|
flickerstreak@53
|
466
|
flickerstreak@53
|
467 self:UpdateCooldown()
|
flickerstreak@53
|
468 end
|
flickerstreak@53
|
469
|
flickerstreak@53
|
470 function Button:UpdateCooldown()
|
flickerstreak@53
|
471 local start, duration, enable = GetPetActionCooldown(self.frame:GetID());
|
flickerstreak@53
|
472 CooldownFrame_SetTimer(self.cooldown, start, duration, enable);
|
flickerstreak@53
|
473 end
|
flickerstreak@53
|
474
|
flickerstreak@53
|
475 function Button:UpdateHotkey()
|
flickerstreak@93
|
476 self:DisplayHotkey(GetHotkey(self.frame))
|
flickerstreak@53
|
477 end
|
flickerstreak@28
|
478
|
flickerstreak@77
|
479 function Button:ShowActionIDLabel(show)
|
flickerstreak@77
|
480 if show then
|
flickerstreak@77
|
481 -- store the action ID label in the frame due to frame recycling
|
flickerstreak@77
|
482 if not self.actionIDLabel and self:GetActionID() then
|
flickerstreak@77
|
483 local label = self.frame:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@77
|
484 label:SetAllPoints()
|
flickerstreak@77
|
485 label:SetJustifyH("CENTER")
|
flickerstreak@77
|
486 label:SetShadowColor(0,0,0,1)
|
flickerstreak@77
|
487 label:SetShadowOffset(2,-2)
|
flickerstreak@77
|
488 label:SetText(tostring(self:GetActionID()))
|
flickerstreak@77
|
489 self.actionIDLabel = label
|
flickerstreak@28
|
490 end
|
flickerstreak@77
|
491 self.actionIDLabel:Show()
|
flickerstreak@77
|
492 elseif self.actionIDLabel then
|
flickerstreak@77
|
493 self.actionIDLabel:Hide()
|
flickerstreak@28
|
494 end
|
flickerstreak@77
|
495 end
|
flickerstreak@93
|
496
|
flickerstreak@93
|
497
|
flickerstreak@93
|
498 function Button:SetKeybindMode(mode)
|
flickerstreak@93
|
499 if mode then
|
flickerstreak@93
|
500 self.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@93
|
501 self.border:Show()
|
flickerstreak@93
|
502 else
|
flickerstreak@93
|
503 self.border:Hide()
|
flickerstreak@93
|
504 end
|
flickerstreak@93
|
505 end
|
flickerstreak@93
|
506
|
flickerstreak@93
|
507 function Button:DisplayHotkey( key )
|
flickerstreak@93
|
508 self.hotkey:SetText(key or "")
|
flickerstreak@93
|
509 end
|