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@95
|
14 local format = string.format
|
flickerstreak@28
|
15
|
flickerstreak@80
|
16 ReAction:UpdateRevision("$Revision$")
|
flickerstreak@77
|
17
|
flickerstreak@93
|
18 -- libraries
|
flickerstreak@93
|
19 local KB = LibStub("LibKeyBound-1.0")
|
flickerstreak@93
|
20
|
flickerstreak@28
|
21 -- module declaration
|
flickerstreak@28
|
22 local moduleID = "PetAction"
|
flickerstreak@28
|
23 local module = ReAction:NewModule( moduleID )
|
flickerstreak@28
|
24
|
flickerstreak@77
|
25 -- Button class declaration
|
flickerstreak@77
|
26 local Button = { }
|
flickerstreak@77
|
27
|
flickerstreak@102
|
28 -- private
|
flickerstreak@102
|
29 local function UpdateButtonLock(bar)
|
flickerstreak@102
|
30 local f = bar:GetFrame()
|
flickerstreak@102
|
31 f:SetAttribute("lockbuttons",bar.config.lockButtons)
|
flickerstreak@102
|
32 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
|
flickerstreak@102
|
33 f:Execute(
|
flickerstreak@102
|
34 [[
|
flickerstreak@102
|
35 lockButtons = self:GetAttribute("lockbuttons")
|
flickerstreak@102
|
36 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
|
flickerstreak@102
|
37 ]])
|
flickerstreak@102
|
38 end
|
flickerstreak@102
|
39
|
flickerstreak@28
|
40 -- module methods
|
flickerstreak@28
|
41 function module:OnInitialize()
|
flickerstreak@53
|
42 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@28
|
43 {
|
flickerstreak@28
|
44 profile = {
|
flickerstreak@28
|
45 buttons = { }
|
flickerstreak@28
|
46 }
|
flickerstreak@28
|
47 }
|
flickerstreak@28
|
48 )
|
flickerstreak@53
|
49 self.buttons = { }
|
flickerstreak@63
|
50
|
flickerstreak@63
|
51 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
|
flickerstreak@63
|
52
|
flickerstreak@63
|
53 ReAction.RegisterCallback(self, "OnCreateBar")
|
flickerstreak@63
|
54 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@63
|
55 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@63
|
56 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@63
|
57 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@63
|
58 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@93
|
59
|
flickerstreak@93
|
60 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
|
flickerstreak@93
|
61 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
|
flickerstreak@93
|
62 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@28
|
63 end
|
flickerstreak@28
|
64
|
flickerstreak@28
|
65 function module:OnEnable()
|
flickerstreak@53
|
66 ReAction:RegisterBarType(L["Pet Action Bar"],
|
flickerstreak@53
|
67 {
|
flickerstreak@53
|
68 type = moduleID ,
|
flickerstreak@53
|
69 defaultButtonSize = 30,
|
flickerstreak@53
|
70 defaultBarRows = 1,
|
flickerstreak@53
|
71 defaultBarCols = 10,
|
flickerstreak@53
|
72 defaultBarSpacing = 8
|
flickerstreak@53
|
73 })
|
flickerstreak@28
|
74 end
|
flickerstreak@28
|
75
|
flickerstreak@28
|
76 function module:OnDisable()
|
flickerstreak@53
|
77 ReAction:UnregisterBarType(L["Pet Action Bar"])
|
flickerstreak@28
|
78 end
|
flickerstreak@28
|
79
|
flickerstreak@63
|
80 function module:OnCreateBar(event, bar, name)
|
flickerstreak@53
|
81 if bar.config.type == moduleID then
|
flickerstreak@53
|
82 -- auto show/hide when pet exists
|
flickerstreak@53
|
83 bar:GetFrame():SetAttribute("unit","pet")
|
flickerstreak@90
|
84 if not ReAction:GetConfigMode() then
|
flickerstreak@90
|
85 RegisterUnitWatch(bar:GetFrame())
|
flickerstreak@90
|
86 end
|
flickerstreak@63
|
87 self:OnRefreshBar(event, bar, name)
|
flickerstreak@28
|
88 end
|
flickerstreak@28
|
89 end
|
flickerstreak@28
|
90
|
flickerstreak@63
|
91 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@53
|
92 if bar.config.type == moduleID then
|
flickerstreak@53
|
93 if self.buttons[bar] == nil then
|
flickerstreak@53
|
94 self.buttons[bar] = { }
|
flickerstreak@53
|
95 end
|
flickerstreak@53
|
96 local btns = self.buttons[bar]
|
flickerstreak@53
|
97 local profile = self.db.profile
|
flickerstreak@63
|
98 if profile.buttons[name] == nil then
|
flickerstreak@63
|
99 profile.buttons[name] = {}
|
flickerstreak@53
|
100 end
|
flickerstreak@63
|
101 local btnCfg = profile.buttons[name]
|
flickerstreak@53
|
102
|
flickerstreak@53
|
103 local r, c = bar:GetButtonGrid()
|
flickerstreak@53
|
104 local n = r*c
|
flickerstreak@53
|
105 for i = 1, n do
|
flickerstreak@53
|
106 if btnCfg[i] == nil then
|
flickerstreak@53
|
107 btnCfg[i] = {}
|
flickerstreak@53
|
108 end
|
flickerstreak@53
|
109 if btns[i] == nil then
|
flickerstreak@94
|
110 local success, r = pcall(Button.New,Button,bar,i,btnCfg[i])
|
flickerstreak@94
|
111 if success and r then
|
flickerstreak@94
|
112 btns[i] = r
|
flickerstreak@94
|
113 bar:AddButton(i,r)
|
flickerstreak@94
|
114 else
|
flickerstreak@94
|
115 n = i - 1
|
flickerstreak@94
|
116 bar:ClipNButtons(n)
|
flickerstreak@94
|
117 break
|
flickerstreak@94
|
118 end
|
flickerstreak@53
|
119 end
|
flickerstreak@77
|
120 btns[i]:Refresh()
|
flickerstreak@53
|
121 end
|
flickerstreak@53
|
122 for i = n+1, #btns do
|
flickerstreak@53
|
123 if btns[i] then
|
flickerstreak@77
|
124 bar:RemoveButton(btns[i])
|
flickerstreak@53
|
125 btns[i] = btns[i]:Destroy()
|
flickerstreak@53
|
126 if btnCfg[i] then
|
flickerstreak@53
|
127 btnCfg[i] = nil
|
flickerstreak@53
|
128 end
|
flickerstreak@53
|
129 end
|
flickerstreak@53
|
130 end
|
flickerstreak@102
|
131 UpdateButtonLock(bar)
|
flickerstreak@53
|
132 end
|
flickerstreak@53
|
133 end
|
flickerstreak@53
|
134
|
flickerstreak@63
|
135 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@53
|
136 if self.buttons[bar] then
|
flickerstreak@53
|
137 local btns = self.buttons[bar]
|
flickerstreak@53
|
138 for _,b in pairs(btns) do
|
flickerstreak@53
|
139 if b then
|
flickerstreak@53
|
140 b:Destroy()
|
flickerstreak@53
|
141 end
|
flickerstreak@53
|
142 end
|
flickerstreak@53
|
143 self.buttons[bar] = nil
|
flickerstreak@53
|
144 end
|
flickerstreak@53
|
145 end
|
flickerstreak@53
|
146
|
flickerstreak@63
|
147 function module:OnEraseBar(event, bar, name)
|
flickerstreak@63
|
148 self.db.profile.buttons[name] = nil
|
flickerstreak@53
|
149 end
|
flickerstreak@53
|
150
|
flickerstreak@63
|
151 function module:OnRenameBar(event, bar, oldname, newname)
|
flickerstreak@53
|
152 local b = self.db.profile.buttons
|
flickerstreak@53
|
153 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@53
|
154 end
|
flickerstreak@53
|
155
|
flickerstreak@53
|
156
|
flickerstreak@63
|
157 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@77
|
158 for _, buttons in pairs(self.buttons) do
|
flickerstreak@77
|
159 for _, b in pairs(buttons) do
|
flickerstreak@77
|
160 b:ShowActionIDLabel(mode)
|
flickerstreak@77
|
161 end
|
flickerstreak@77
|
162 end
|
flickerstreak@63
|
163 for _, bar in ReAction:IterateBars() do
|
flickerstreak@53
|
164 if bar and self.buttons[bar] then
|
flickerstreak@53
|
165 local f = bar:GetFrame()
|
flickerstreak@53
|
166 if mode then
|
flickerstreak@53
|
167 UnregisterUnitWatch(f)
|
flickerstreak@53
|
168 f:Show()
|
flickerstreak@53
|
169 else
|
flickerstreak@53
|
170 RegisterUnitWatch(f)
|
flickerstreak@53
|
171 end
|
flickerstreak@53
|
172 end
|
flickerstreak@53
|
173 end
|
flickerstreak@53
|
174 end
|
flickerstreak@53
|
175
|
flickerstreak@93
|
176 function module:LIBKEYBOUND_ENABLED(evt)
|
flickerstreak@93
|
177 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
178 for _, b in pairs(buttons) do
|
flickerstreak@93
|
179 b:SetKeybindMode(true)
|
flickerstreak@93
|
180 end
|
flickerstreak@93
|
181 end
|
flickerstreak@93
|
182 end
|
flickerstreak@93
|
183
|
flickerstreak@93
|
184 function module:LIBKEYBOUND_DISABLED(evt)
|
flickerstreak@93
|
185 for _, buttons in pairs(self.buttons) do
|
flickerstreak@93
|
186 for _, b in pairs(buttons) do
|
flickerstreak@93
|
187 b:SetKeybindMode(false)
|
flickerstreak@93
|
188 end
|
flickerstreak@93
|
189 end
|
flickerstreak@93
|
190 end
|
flickerstreak@93
|
191
|
flickerstreak@53
|
192
|
flickerstreak@60
|
193 ---- Options ----
|
flickerstreak@102
|
194 local Handler = { }
|
flickerstreak@102
|
195 local meta = { __index = Handler }
|
flickerstreak@102
|
196
|
flickerstreak@102
|
197 function Handler:New(bar)
|
flickerstreak@102
|
198 return setmetatable(
|
flickerstreak@102
|
199 {
|
flickerstreak@102
|
200 bar = bar,
|
flickerstreak@102
|
201 config = bar.config
|
flickerstreak@102
|
202 }, meta)
|
flickerstreak@102
|
203 end
|
flickerstreak@102
|
204
|
flickerstreak@102
|
205 function Handler:GetLockButtons()
|
flickerstreak@102
|
206 return LOCK_ACTIONBAR == "1" or self.config.lockButtons
|
flickerstreak@102
|
207 end
|
flickerstreak@102
|
208
|
flickerstreak@102
|
209 function Handler:SetLockButtons(info, value)
|
flickerstreak@102
|
210 self.config.lockButtons = value
|
flickerstreak@102
|
211 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
212 end
|
flickerstreak@102
|
213
|
flickerstreak@102
|
214 function Handler:LockButtonsDisabled()
|
flickerstreak@102
|
215 return LOCK_ACTIONBAR == "1"
|
flickerstreak@102
|
216 end
|
flickerstreak@102
|
217
|
flickerstreak@102
|
218 function Handler:GetLockButtonsCombat()
|
flickerstreak@102
|
219 return self.config.lockButtonsCombat
|
flickerstreak@102
|
220 end
|
flickerstreak@102
|
221
|
flickerstreak@102
|
222 function Handler:SetLockButtonsCombat(info, value)
|
flickerstreak@102
|
223 self.config.lockButtonsCombat = value
|
flickerstreak@102
|
224 UpdateButtonLock(self.bar)
|
flickerstreak@102
|
225 end
|
flickerstreak@102
|
226
|
flickerstreak@102
|
227 function Handler:LockButtonsCombatDisabled()
|
flickerstreak@102
|
228 return LOCK_ACTIONBAR == "1" or not self.config.lockButtons
|
flickerstreak@102
|
229 end
|
flickerstreak@102
|
230
|
flickerstreak@102
|
231
|
flickerstreak@60
|
232 function module:GetBarOptions(bar)
|
flickerstreak@91
|
233 if bar.config.type == moduleID then
|
flickerstreak@91
|
234 return {
|
flickerstreak@91
|
235 type = "group",
|
flickerstreak@91
|
236 name = L["Pet Buttons"],
|
flickerstreak@102
|
237 handler = Handler:New(bar),
|
flickerstreak@91
|
238 args = {
|
flickerstreak@102
|
239 lockButtons = {
|
flickerstreak@102
|
240 name = L["Lock Buttons"],
|
flickerstreak@102
|
241 desc = L["Prevents picking up/dragging actions.|nNOTE: This setting is overridden by the global setting in Blizzard's Action Buttons tab"],
|
flickerstreak@102
|
242 order = 2,
|
flickerstreak@102
|
243 type = "toggle",
|
flickerstreak@102
|
244 disabled = "LockButtonsDisabled",
|
flickerstreak@102
|
245 get = "GetLockButtons",
|
flickerstreak@102
|
246 set = "SetLockButtons",
|
flickerstreak@102
|
247 },
|
flickerstreak@102
|
248 lockOnlyCombat = {
|
flickerstreak@102
|
249 name = L["Only in Combat"],
|
flickerstreak@102
|
250 desc = L["Only lock the buttons when in combat"],
|
flickerstreak@102
|
251 order = 3,
|
flickerstreak@102
|
252 type = "toggle",
|
flickerstreak@102
|
253 disabled = "LockButtonsCombatDisabled",
|
flickerstreak@102
|
254 get = "GetLockButtonsCombat",
|
flickerstreak@102
|
255 set = "SetLockButtonsCombat",
|
flickerstreak@102
|
256 },
|
flickerstreak@91
|
257 }
|
flickerstreak@60
|
258 }
|
flickerstreak@91
|
259 end
|
flickerstreak@59
|
260 end
|
flickerstreak@59
|
261
|
flickerstreak@53
|
262
|
flickerstreak@28
|
263
|
flickerstreak@77
|
264 ------ Button class ------
|
flickerstreak@77
|
265
|
flickerstreak@28
|
266 -- use-count of action IDs
|
flickerstreak@53
|
267 local nActionIDs = NUM_PET_ACTION_SLOTS
|
flickerstreak@28
|
268 local ActionIDList = setmetatable( {}, {
|
flickerstreak@28
|
269 __index = function(self, idx)
|
flickerstreak@28
|
270 if idx == nil then
|
flickerstreak@53
|
271 for i = 1, nActionIDs do
|
flickerstreak@28
|
272 if rawget(self,i) == nil then
|
flickerstreak@28
|
273 rawset(self,i,1)
|
flickerstreak@28
|
274 return i
|
flickerstreak@28
|
275 end
|
flickerstreak@28
|
276 end
|
flickerstreak@53
|
277 error("ran out of pet action IDs")
|
flickerstreak@28
|
278 else
|
flickerstreak@28
|
279 local c = rawget(self,idx) or 0
|
flickerstreak@28
|
280 rawset(self,idx,c+1)
|
flickerstreak@28
|
281 return idx
|
flickerstreak@28
|
282 end
|
flickerstreak@28
|
283 end,
|
flickerstreak@28
|
284 __newindex = function(self,idx,value)
|
flickerstreak@28
|
285 if value == nil then
|
flickerstreak@28
|
286 value = rawget(self,idx)
|
flickerstreak@28
|
287 if value == 1 then
|
flickerstreak@28
|
288 value = nil
|
flickerstreak@28
|
289 elseif value then
|
flickerstreak@28
|
290 value = value - 1
|
flickerstreak@28
|
291 end
|
flickerstreak@28
|
292 end
|
flickerstreak@28
|
293 rawset(self,idx,value)
|
flickerstreak@28
|
294 end
|
flickerstreak@28
|
295 })
|
flickerstreak@28
|
296
|
flickerstreak@53
|
297 local frameRecycler = {}
|
flickerstreak@93
|
298 local trash = CreateFrame("Frame")
|
flickerstreak@95
|
299 local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings, OnEnter, OnLeave
|
flickerstreak@93
|
300 do
|
flickerstreak@93
|
301 local buttonLookup = setmetatable({},{__mode="kv"})
|
flickerstreak@93
|
302
|
flickerstreak@93
|
303 -- Use KeyBound-1.0 for binding, but use Override bindings instead of
|
flickerstreak@93
|
304 -- regular bindings to support multiple profile use. This is a little
|
flickerstreak@93
|
305 -- weird with the KeyBound dialog box (which has per-char selector as well
|
flickerstreak@93
|
306 -- as an OK/Cancel box) but it's the least amount of effort to implement.
|
flickerstreak@93
|
307 function GetActionName(f)
|
flickerstreak@93
|
308 local b = buttonLookup[f]
|
flickerstreak@93
|
309 if b then
|
flickerstreak@93
|
310 return format("%s:%s", b.bar:GetName(), b.idx)
|
flickerstreak@93
|
311 end
|
flickerstreak@93
|
312 end
|
flickerstreak@93
|
313
|
flickerstreak@93
|
314 function GetHotkey(f)
|
flickerstreak@93
|
315 local b = buttonLookup[f]
|
flickerstreak@93
|
316 if b then
|
flickerstreak@93
|
317 return KB:ToShortKey(b:GetConfig().hotkey)
|
flickerstreak@93
|
318 end
|
flickerstreak@93
|
319 end
|
flickerstreak@93
|
320
|
flickerstreak@93
|
321 function SetKey(f, key)
|
flickerstreak@93
|
322 local b = buttonLookup[f]
|
flickerstreak@93
|
323 if b then
|
flickerstreak@93
|
324 local c = b:GetConfig()
|
flickerstreak@93
|
325 if c.hotkey then
|
flickerstreak@93
|
326 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@93
|
327 end
|
flickerstreak@93
|
328 if key then
|
flickerstreak@93
|
329 SetOverrideBindingClick(f, false, key, f:GetName(), nil)
|
flickerstreak@93
|
330 end
|
flickerstreak@93
|
331 c.hotkey = key
|
flickerstreak@93
|
332 b:DisplayHotkey(GetHotkey(f))
|
flickerstreak@93
|
333 end
|
flickerstreak@93
|
334 end
|
flickerstreak@93
|
335
|
flickerstreak@93
|
336 function FreeKey(f, key)
|
flickerstreak@93
|
337 local b = buttonLookup[f]
|
flickerstreak@93
|
338 if b then
|
flickerstreak@93
|
339 local c = b:GetConfig()
|
flickerstreak@93
|
340 if c.hotkey == key then
|
flickerstreak@93
|
341 local action = f:GetActionName()
|
flickerstreak@93
|
342 SetOverrideBinding(f, false, c.hotkey, nil)
|
flickerstreak@93
|
343 c.hotkey = nil
|
flickerstreak@93
|
344 b:DisplayHotkey(nil)
|
flickerstreak@93
|
345 return action
|
flickerstreak@93
|
346 end
|
flickerstreak@93
|
347 end
|
flickerstreak@93
|
348 return ReAction:FreeOverrideHotkey(key)
|
flickerstreak@93
|
349 end
|
flickerstreak@93
|
350
|
flickerstreak@93
|
351 function ClearBindings(f)
|
flickerstreak@93
|
352 SetKey(f, nil)
|
flickerstreak@93
|
353 end
|
flickerstreak@93
|
354
|
flickerstreak@93
|
355 function GetBindings(f)
|
flickerstreak@93
|
356 local b = buttonLookup[f]
|
flickerstreak@93
|
357 if b then
|
flickerstreak@93
|
358 return b:GetConfig().hotkey
|
flickerstreak@93
|
359 end
|
flickerstreak@93
|
360 end
|
flickerstreak@93
|
361
|
flickerstreak@93
|
362 function KBAttach( button )
|
flickerstreak@93
|
363 local f = button:GetFrame()
|
flickerstreak@93
|
364 f.GetActionName = GetActionName
|
flickerstreak@93
|
365 f.GetHotkey = GetHotkey
|
flickerstreak@93
|
366 f.SetKey = SetKey
|
flickerstreak@93
|
367 f.FreeKey = FreeKey
|
flickerstreak@93
|
368 f.ClearBindings = ClearBindings
|
flickerstreak@93
|
369 f.GetBindings = GetBindings
|
flickerstreak@93
|
370 buttonLookup[f] = button
|
flickerstreak@93
|
371 f:SetKey(button:GetConfig().hotkey)
|
flickerstreak@93
|
372 ReAction:RegisterKeybindFrame(f)
|
flickerstreak@93
|
373 if ReAction:GetKeybindMode() then
|
flickerstreak@93
|
374 button.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@93
|
375 button.border:Show()
|
flickerstreak@93
|
376 end
|
flickerstreak@93
|
377 end
|
flickerstreak@95
|
378
|
flickerstreak@95
|
379 function OnEnter( self )
|
flickerstreak@95
|
380 if not self.tooltipName then
|
flickerstreak@95
|
381 return;
|
flickerstreak@95
|
382 end
|
flickerstreak@95
|
383 local uber = GetCVar("UberTooltips")
|
flickerstreak@95
|
384 if self.isToken or (uber == "0") then
|
flickerstreak@95
|
385 if uber == "0" then
|
flickerstreak@95
|
386 GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
flickerstreak@95
|
387 else
|
flickerstreak@95
|
388 GameTooltip_SetDefaultAnchor(GameTooltip, self)
|
flickerstreak@95
|
389 end
|
flickerstreak@95
|
390 local tooltip = self.tooltipName
|
flickerstreak@95
|
391 local k = GetBindings(self)
|
flickerstreak@95
|
392 if k then
|
flickerstreak@95
|
393 tooltip = tooltip .. format(" %s(%s)%s", NORMAL_FONT_COLOR_CODE, k, FONT_COLOR_CODE_CLOSE)
|
flickerstreak@95
|
394 end
|
flickerstreak@95
|
395 GameTooltip:SetText(tooltip)
|
flickerstreak@95
|
396 if self.tooltipSubtext then
|
flickerstreak@95
|
397 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5)
|
flickerstreak@95
|
398 end
|
flickerstreak@95
|
399 GameTooltip:Show()
|
flickerstreak@95
|
400 else
|
flickerstreak@95
|
401 GameTooltip_SetDefaultAnchor(GameTooltip, self)
|
flickerstreak@95
|
402 GameTooltip:SetPetAction(self:GetID())
|
flickerstreak@95
|
403 end
|
flickerstreak@95
|
404 end
|
flickerstreak@95
|
405
|
flickerstreak@95
|
406 function OnLeave()
|
flickerstreak@95
|
407 GameTooltip:Hide()
|
flickerstreak@95
|
408 end
|
flickerstreak@95
|
409
|
flickerstreak@93
|
410 end
|
flickerstreak@93
|
411
|
flickerstreak@90
|
412 local meta = { __index = Button }
|
flickerstreak@28
|
413
|
flickerstreak@77
|
414 function Button:New( bar, idx, config )
|
flickerstreak@77
|
415 -- create new self
|
flickerstreak@90
|
416 self = setmetatable(
|
flickerstreak@90
|
417 {
|
flickerstreak@90
|
418 bar = bar,
|
flickerstreak@90
|
419 idx = idx,
|
flickerstreak@90
|
420 config = config,
|
flickerstreak@90
|
421 }, meta )
|
flickerstreak@28
|
422
|
flickerstreak@85
|
423 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx)
|
flickerstreak@53
|
424 config.name = name
|
flickerstreak@77
|
425 self.name = name
|
flickerstreak@28
|
426 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
|
flickerstreak@28
|
427
|
flickerstreak@53
|
428 -- have to recycle frames with the same name:
|
flickerstreak@53
|
429 -- otherwise you either get references to old textures because named CreateFrame()
|
flickerstreak@90
|
430 -- doesn't overwrite existing globals. Can't set them to nil in the global table,
|
flickerstreak@90
|
431 -- as it causes taint.
|
flickerstreak@90
|
432 local parent = bar:GetFrame()
|
flickerstreak@53
|
433 local f = frameRecycler[name]
|
flickerstreak@53
|
434 if f then
|
flickerstreak@77
|
435 f:SetParent(parent)
|
flickerstreak@53
|
436 else
|
flickerstreak@77
|
437 f = CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate")
|
flickerstreak@93
|
438 -- ditch the old hotkey text because it's tied in ActionButton_Update() to the
|
flickerstreak@93
|
439 -- standard binding. We use override bindings.
|
flickerstreak@93
|
440 local hotkey = _G[name.."HotKey"]
|
flickerstreak@93
|
441 hotkey:SetParent(trash)
|
flickerstreak@93
|
442 hotkey = f:CreateFontString(nil, "ARTWORK", "NumberFontNormalSmallGray")
|
flickerstreak@93
|
443 hotkey:SetWidth(36)
|
flickerstreak@93
|
444 hotkey:SetHeight(18)
|
flickerstreak@93
|
445 hotkey:SetJustifyH("RIGHT")
|
flickerstreak@93
|
446 hotkey:SetJustifyV("TOP")
|
flickerstreak@93
|
447 hotkey:SetPoint("TOPLEFT",f,"TOPLEFT",-2,-2)
|
flickerstreak@93
|
448 f.hotkey = hotkey
|
flickerstreak@93
|
449 f:HookScript("OnDragStart", function() self:Update() end)
|
flickerstreak@93
|
450 f:HookScript("OnReceiveDrag", function() self:Update() end)
|
flickerstreak@95
|
451 f:SetScript("OnEnter", OnEnter)
|
flickerstreak@95
|
452 f:SetScript("OnLeave", OnLeave)
|
flickerstreak@53
|
453 end
|
flickerstreak@53
|
454 if config.actionID then
|
flickerstreak@53
|
455 f:SetID(config.actionID) -- PetActionButtonTemplate isn't a proper SecureActionButton
|
flickerstreak@53
|
456 end
|
flickerstreak@53
|
457 f:SetFrameStrata("MEDIUM")
|
flickerstreak@93
|
458 self.frame = f
|
flickerstreak@93
|
459 self.icon = _G[("%sIcon"):format(name)]
|
flickerstreak@93
|
460 self.acTex = _G[("%sAutoCastable"):format(name)]
|
flickerstreak@93
|
461 self.acModel = _G[("%sShine"):format(name)]
|
flickerstreak@53
|
462 self.cooldown = _G[("%sCooldown"):format(name)]
|
flickerstreak@93
|
463 self.hotkey = f.hotkey
|
flickerstreak@93
|
464 self.border = _G[("%sBorder"):format(name)]
|
flickerstreak@53
|
465
|
flickerstreak@53
|
466
|
flickerstreak@77
|
467 f:RegisterEvent("PLAYER_CONTROL_LOST");
|
flickerstreak@53
|
468 f:RegisterEvent("PLAYER_CONTROL_GAINED");
|
flickerstreak@53
|
469 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED");
|
flickerstreak@53
|
470 f:RegisterEvent("UNIT_PET");
|
flickerstreak@53
|
471 f:RegisterEvent("UNIT_FLAGS");
|
flickerstreak@53
|
472 f:RegisterEvent("UNIT_AURA");
|
flickerstreak@53
|
473 f:RegisterEvent("PET_BAR_UPDATE");
|
flickerstreak@53
|
474 f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN");
|
flickerstreak@53
|
475
|
flickerstreak@53
|
476 f:SetScript("OnEvent",
|
flickerstreak@53
|
477 function(event,arg1)
|
flickerstreak@53
|
478 if event =="PET_BAR_UPDATE_COOLDOWN" then
|
flickerstreak@53
|
479 self:UpdateCooldown()
|
flickerstreak@53
|
480 elseif event == "UPDATE_BINDINGS" then
|
flickerstreak@53
|
481 self:UpdateHotkey()
|
flickerstreak@53
|
482 else
|
flickerstreak@53
|
483 self:Update()
|
flickerstreak@53
|
484 end
|
flickerstreak@53
|
485 end)
|
flickerstreak@28
|
486
|
flickerstreak@102
|
487 -- install drag wrappers to lock buttons
|
flickerstreak@102
|
488 bar:GetFrame():WrapScript(f, "OnDragStart",
|
flickerstreak@102
|
489 -- OnDragStart(self, button, kind, value, ...)
|
flickerstreak@102
|
490 [[
|
flickerstreak@102
|
491 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then
|
flickerstreak@102
|
492 return "clear"
|
flickerstreak@102
|
493 end
|
flickerstreak@102
|
494 ]])
|
flickerstreak@102
|
495
|
flickerstreak@93
|
496 KBAttach(self)
|
flickerstreak@88
|
497
|
flickerstreak@108
|
498 -- attach to skinner
|
flickerstreak@108
|
499 bar:SkinButton(self,
|
flickerstreak@108
|
500 {
|
flickerstreak@108
|
501 HotKey = self.hotkey,
|
flickerstreak@108
|
502 }
|
flickerstreak@108
|
503 )
|
flickerstreak@108
|
504
|
flickerstreak@77
|
505 self:Refresh()
|
flickerstreak@93
|
506 self:SetKeybindMode(ReAction:GetKeybindMode())
|
flickerstreak@93
|
507
|
flickerstreak@77
|
508 return self
|
flickerstreak@28
|
509 end
|
flickerstreak@28
|
510
|
flickerstreak@28
|
511 function Button:Destroy()
|
flickerstreak@28
|
512 local f = self.frame
|
flickerstreak@28
|
513 f:UnregisterAllEvents()
|
flickerstreak@28
|
514 f:Hide()
|
flickerstreak@28
|
515 f:SetParent(UIParent)
|
flickerstreak@28
|
516 f:ClearAllPoints()
|
flickerstreak@28
|
517 if self.name then
|
flickerstreak@53
|
518 frameRecycler[self.name] = f
|
flickerstreak@28
|
519 _G[self.name] = nil
|
flickerstreak@28
|
520 end
|
flickerstreak@53
|
521 if self.config.actionID then
|
flickerstreak@53
|
522 ActionIDList[self.config.actionID] = nil
|
flickerstreak@53
|
523 end
|
flickerstreak@28
|
524 self.frame = nil
|
flickerstreak@28
|
525 self.config = nil
|
flickerstreak@28
|
526 self.bar = nil
|
flickerstreak@28
|
527 end
|
flickerstreak@28
|
528
|
flickerstreak@77
|
529 function Button:Refresh()
|
flickerstreak@77
|
530 self.bar:PlaceButton(self, 30, 30)
|
flickerstreak@53
|
531 self:Update()
|
flickerstreak@53
|
532 self:UpdateHotkey()
|
flickerstreak@94
|
533 self.frame:Show()
|
flickerstreak@53
|
534 end
|
flickerstreak@53
|
535
|
flickerstreak@53
|
536 function Button:GetFrame()
|
flickerstreak@53
|
537 return self.frame
|
flickerstreak@53
|
538 end
|
flickerstreak@53
|
539
|
flickerstreak@53
|
540 function Button:GetName()
|
flickerstreak@53
|
541 return self.name
|
flickerstreak@53
|
542 end
|
flickerstreak@53
|
543
|
flickerstreak@88
|
544 function Button:GetConfig()
|
flickerstreak@88
|
545 return self.config
|
flickerstreak@88
|
546 end
|
flickerstreak@88
|
547
|
flickerstreak@53
|
548 function Button:GetActionID()
|
flickerstreak@53
|
549 return self.config.actionID
|
flickerstreak@53
|
550 end
|
flickerstreak@53
|
551
|
flickerstreak@53
|
552 function Button:Update()
|
flickerstreak@53
|
553 local id = self.frame:GetID()
|
flickerstreak@53
|
554 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id);
|
flickerstreak@53
|
555 local f = self.frame
|
flickerstreak@53
|
556 --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
|
557
|
flickerstreak@53
|
558 if isToken then
|
flickerstreak@53
|
559 self.icon:SetTexture(_G[texture]);
|
flickerstreak@53
|
560 f.tooltipName = _G[name];
|
flickerstreak@53
|
561 else
|
flickerstreak@53
|
562 self.icon:SetTexture(texture);
|
flickerstreak@53
|
563 f.tooltipName = name;
|
flickerstreak@53
|
564 end
|
flickerstreak@53
|
565
|
flickerstreak@53
|
566 f.isToken = isToken;
|
flickerstreak@53
|
567 f.tooltipSubtext = subtext;
|
flickerstreak@53
|
568 f:SetChecked( isActive and 1 or 0);
|
flickerstreak@53
|
569
|
flickerstreak@53
|
570 if autoCastAllowed then
|
flickerstreak@53
|
571 self.acTex:Show();
|
flickerstreak@53
|
572 else
|
flickerstreak@53
|
573 self.acTex:Hide();
|
flickerstreak@53
|
574 end
|
flickerstreak@53
|
575
|
flickerstreak@53
|
576 if autoCastEnabled then
|
flickerstreak@91
|
577 AutoCastShine_AutoCastStart(self.acModel)
|
flickerstreak@53
|
578 else
|
flickerstreak@91
|
579 AutoCastShine_AutoCastStop(self.acModel)
|
flickerstreak@53
|
580 end
|
flickerstreak@53
|
581
|
flickerstreak@53
|
582 if texture then
|
flickerstreak@91
|
583 if GetPetActionSlotUsable(id) then
|
flickerstreak@53
|
584 SetDesaturation(self.icon,nil)
|
flickerstreak@53
|
585 else
|
flickerstreak@53
|
586 SetDesaturation(self.icon,1)
|
flickerstreak@53
|
587 end
|
flickerstreak@53
|
588 self.icon:Show();
|
flickerstreak@53
|
589 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
|
flickerstreak@53
|
590 else
|
flickerstreak@53
|
591 self.icon:Hide();
|
flickerstreak@53
|
592 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot");
|
flickerstreak@53
|
593 end
|
flickerstreak@53
|
594
|
flickerstreak@53
|
595 self:UpdateCooldown()
|
flickerstreak@53
|
596 end
|
flickerstreak@53
|
597
|
flickerstreak@53
|
598 function Button:UpdateCooldown()
|
flickerstreak@53
|
599 local start, duration, enable = GetPetActionCooldown(self.frame:GetID());
|
flickerstreak@53
|
600 CooldownFrame_SetTimer(self.cooldown, start, duration, enable);
|
flickerstreak@53
|
601 end
|
flickerstreak@53
|
602
|
flickerstreak@53
|
603 function Button:UpdateHotkey()
|
flickerstreak@93
|
604 self:DisplayHotkey(GetHotkey(self.frame))
|
flickerstreak@53
|
605 end
|
flickerstreak@28
|
606
|
flickerstreak@77
|
607 function Button:ShowActionIDLabel(show)
|
flickerstreak@77
|
608 if show then
|
flickerstreak@77
|
609 -- store the action ID label in the frame due to frame recycling
|
flickerstreak@77
|
610 if not self.actionIDLabel and self:GetActionID() then
|
flickerstreak@77
|
611 local label = self.frame:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
|
flickerstreak@77
|
612 label:SetAllPoints()
|
flickerstreak@77
|
613 label:SetJustifyH("CENTER")
|
flickerstreak@77
|
614 label:SetShadowColor(0,0,0,1)
|
flickerstreak@77
|
615 label:SetShadowOffset(2,-2)
|
flickerstreak@77
|
616 label:SetText(tostring(self:GetActionID()))
|
flickerstreak@77
|
617 self.actionIDLabel = label
|
flickerstreak@28
|
618 end
|
flickerstreak@77
|
619 self.actionIDLabel:Show()
|
flickerstreak@77
|
620 elseif self.actionIDLabel then
|
flickerstreak@77
|
621 self.actionIDLabel:Hide()
|
flickerstreak@28
|
622 end
|
flickerstreak@77
|
623 end
|
flickerstreak@93
|
624
|
flickerstreak@93
|
625
|
flickerstreak@93
|
626 function Button:SetKeybindMode(mode)
|
flickerstreak@93
|
627 if mode then
|
flickerstreak@93
|
628 self.border:SetVertexColor(KB:GetColorKeyBoundMode())
|
flickerstreak@93
|
629 self.border:Show()
|
flickerstreak@93
|
630 else
|
flickerstreak@93
|
631 self.border:Hide()
|
flickerstreak@93
|
632 end
|
flickerstreak@93
|
633 end
|
flickerstreak@93
|
634
|
flickerstreak@93
|
635 function Button:DisplayHotkey( key )
|
flickerstreak@93
|
636 self.hotkey:SetText(key or "")
|
flickerstreak@93
|
637 end
|