-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
PetButton.lua
308 lines (263 loc) · 8.21 KB
/
PetButton.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
--[[
Copyright (c) 2009-2017, Hendrik "Nevcairiel" Leppkes < h.leppkes at gmail dot com >
All rights reserved.
]]
--[[
Pet Button template
]]
local _, Bartender4 = ...
local PetButtonPrototype = CreateFrame("CheckButton")
local PetButton_MT = {__index = PetButtonPrototype}
local Masque = LibStub("Masque", true)
local KeyBound = LibStub("LibKeyBound-1.0")
local WoWRetail = (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE)
-- upvalues
local _G = _G
local format, select, setmetatable = string.format, select, setmetatable
-- GLOBALS: InCombatLockdown, CreateFrame, SetDesaturation, IsModifiedClick, GetBindingKey, GetBindingText, SetBinding
-- GLOBALS: AutoCastShine_AutoCastStop, AutoCastShine_AutoCastStart, CooldownFrame_Set
-- GLOBALS: PickupPetAction, , GetPetActionInfo, GetPetActionsUsable, GetPetActionCooldown
local function onEnter(self, ...)
if not (Bartender4.db.profile.tooltip == "nocombat" and InCombatLockdown()) and Bartender4.db.profile.tooltip ~= "disabled" then
self:OnEnter(...)
end
KeyBound:Set(self)
end
local function onDragStart(self)
if InCombatLockdown() then return end
if not Bartender4.db.profile.buttonlock or IsModifiedClick("PICKUPACTION") then
self:SetChecked(false)
PickupPetAction(self.id)
self:Update()
end
end
local function onReceiveDrag(self)
if InCombatLockdown() then return end
if GetCursorInfo() == "petaction" then
self:SetChecked(false)
PickupPetAction(self.id)
self:Update()
end
end
Bartender4.PetButton = {}
Bartender4.PetButton.prototype = PetButtonPrototype
function Bartender4.PetButton:Create(id, parent)
local name = "BT4PetButton" .. id
local button = setmetatable(CreateFrame("CheckButton", name, parent, "PetActionButtonTemplate"), PetButton_MT)
button.showgrid = 0
button.id = id
button.parent = parent
button:SetFrameStrata("MEDIUM")
button:SetID(id)
button:UnregisterAllEvents()
button:SetScript("OnEvent", nil)
button.OnEnter = button:GetScript("OnEnter")
button:SetScript("OnEnter", onEnter)
button:SetScript("OnDragStart", onDragStart)
button:SetScript("OnReceiveDrag", onReceiveDrag)
if not WoWRetail then
button.NormalTexture = button:GetNormalTexture()
end
if Masque then
local group = parent.MasqueGroup
group:AddButton(button, nil, "Pet")
end
return button
end
function PetButtonPrototype:Update()
local name, texture, isToken, isActive, autoCastAllowed, autoCastEnabled, spellID = GetPetActionInfo(self.id)
if not isToken then
self.icon:SetTexture(texture)
self.tooltipName = name
else
self.icon:SetTexture(_G[texture])
self.tooltipName = _G[name]
end
self.isToken = isToken
if spellID then
local spell = Spell:CreateFromSpellID(spellID)
self.spellDataLoadedCancelFunc = spell:ContinueWithCancelOnSpellLoad(function()
self.tooltipSubtext = spell:GetSpellSubtext()
end)
end
if isActive then
if IsPetAttackAction(self.id) then
if self.StartFlash then
self:StartFlash()
end
-- the checked texture looks a little confusing at full alpha (looks like you have an extra ability selected)
self:GetCheckedTexture():SetAlpha(0.5)
else
if self.StopFlash then
self:StopFlash()
end
self:GetCheckedTexture():SetAlpha(1.0)
end
self:SetChecked(not self.parent.config.hideequipped)
else
if self.StopFlash then
self:StopFlash()
end
self:SetChecked(false)
end
if self.AutoCastOverlay then -- 11.0
self.AutoCastOverlay:SetShown(autoCastAllowed)
self.AutoCastOverlay:ShowAutoCastEnabled(autoCastEnabled)
else
if autoCastAllowed then
self.AutoCastable:Show()
if autoCastEnabled then
AutoCastShine_AutoCastStart(self.AutoCastShine)
else
AutoCastShine_AutoCastStop(self.AutoCastShine)
end
else
self.AutoCastable:Hide()
AutoCastShine_AutoCastStop(self.AutoCastShine)
end
end
if texture then
if GetPetActionsUsable() then
SetDesaturation(self.icon, nil)
else
SetDesaturation(self.icon, 1)
end
self.icon:Show()
if not self.parent.MasqueGroup then
if WoWRetail then
self.SlotBackground:Hide()
if self.parent.config.hideborder then
self.NormalTexture:SetTexture()
self.icon:RemoveMaskTexture(self.IconMask)
self.HighlightTexture:SetSize(34, 33)
self.HighlightTexture:SetPoint("TOPLEFT", self, "TOPLEFT", -1.5, 1.5)
self.CheckedTexture:SetSize(34, 33)
self.CheckedTexture:SetPoint("TOPLEFT", self, "TOPLEFT", -1.5, 1.5)
self.cooldown:ClearAllPoints()
self.cooldown:SetAllPoints()
else
self:SetNormalAtlas("UI-HUD-ActionBar-IconFrame-AddRow")
self.icon:AddMaskTexture(self.IconMask)
self.HighlightTexture:SetSize(31.6, 30.9)
self.HighlightTexture:SetPoint("TOPLEFT")
self.CheckedTexture:SetSize(31.6, 30.9)
self.CheckedTexture:SetPoint("TOPLEFT")
self.cooldown:ClearAllPoints()
self.cooldown:SetPoint("TOPLEFT", self, "TOPLEFT", 1.7, -1.7)
self.cooldown:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", -1, 1)
end
else
self.NormalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot2")
self.NormalTexture:SetTexCoord(0, 0, 0, 0)
end
end
self:ShowButton()
if self.overlay then
self.overlay:Show()
end
else
self.icon:Hide()
if not self.parent.MasqueGroup then
if WoWRetail then
self.SlotBackground:Show()
self:SetNormalAtlas("UI-HUD-ActionBar-IconFrame-AddRow")
else
self.NormalTexture:SetTexture("Interface\\Buttons\\UI-Quickslot")
self.NormalTexture:SetTexCoord(-0.1, 1.1, -0.1, 1.12)
end
end
self:HideButton()
if self.showgrid == 0 and not self.parent.config.showgrid then
if self.overlay then
self.overlay:Hide()
end
end
end
self:UpdateCooldown()
self:UpdateHotkeys()
end
function PetButtonPrototype:UpdateHotkeys()
local key = self:GetHotkey() or ""
local hotkey = self.HotKey
if key == "" or self.parent.config.hidehotkey then
hotkey:Hide()
else
hotkey:SetText(key)
hotkey:Show()
end
end
-- override the mixin hotkey function
PetButtonPrototype.SetHotkeys = PetButtonPrototype.UpdateHotkeys
function PetButtonPrototype:ShowButton()
self:SetAlpha(1.0)
end
function PetButtonPrototype:HideButton()
if self.showgrid == 0 and not self.parent.config.showgrid then
self:SetAlpha(0.0)
end
end
function PetButtonPrototype:ShowGrid()
self.showgrid = self.showgrid + 1
self:SetAlpha(1.0)
end
function PetButtonPrototype:HideGrid()
if self.showgrid > 0 then self.showgrid = self.showgrid - 1 end
if self.showgrid == 0 and not (GetPetActionInfo(self.id)) and not self.parent.config.showgrid then
self:SetAlpha(0.0)
end
end
function PetButtonPrototype:UpdateCooldown()
local start, duration, enable = GetPetActionCooldown(self.id)
CooldownFrame_Set(self.cooldown, start, duration, enable)
if not GameTooltip:IsForbidden() and GameTooltip:GetOwner() == self then
self:OnEnter()
end
end
function PetButtonPrototype:GetHotkey()
local key = GetBindingKey(format("BONUSACTIONBUTTON%d", self.id)) or GetBindingKey("CLICK "..self:GetName()..":LeftButton")
return key and KeyBound:ToShortKey(key)
end
function PetButtonPrototype:GetBindings()
local keys, binding = ""
binding = format("BONUSACTIONBUTTON%d", self.id)
for i = 1, select('#', GetBindingKey(binding)) do
local hotKey = select(i, GetBindingKey(binding))
if keys ~= "" then
keys = keys .. ', '
end
keys = keys .. GetBindingText(hotKey,'KEY_')
end
binding = "CLICK "..self:GetName()..":LeftButton"
for i = 1, select('#', GetBindingKey(binding)) do
local hotKey = select(i, GetBindingKey(binding))
if keys ~= "" then
keys = keys .. ', '
end
keys = keys.. GetBindingText(hotKey,'KEY_')
end
return keys
end
function PetButtonPrototype:SetKey(key)
SetBinding(key, format("BONUSACTIONBUTTON%d", self.id))
end
function PetButtonPrototype:ClearBindings()
local binding = format("BONUSACTIONBUTTON%d", self:GetID())
while GetBindingKey(binding) do
SetBinding(GetBindingKey(binding), nil)
end
binding = "CLICK "..self:GetName()..":LeftButton"
while GetBindingKey(binding) do
SetBinding(GetBindingKey(binding), nil)
end
end
local actionTmpl = "Pet Button %d (%s)"
function PetButtonPrototype:GetActionName()
local id = self.id
local name, _, _, token = GetPetActionInfo(id)
if token and name then name = _G[name] end
return format(actionTmpl, id, name or "empty")
end
function PetButtonPrototype:ClearSetPoint(...)
self:ClearAllPoints()
self:SetPoint(...)
end