-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathProcs.lua
277 lines (231 loc) · 7.89 KB
/
Procs.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
if select(2,UnitClass("player")) ~= "SHAMAN" then return end
local _, TotemTimers = ...
local eventFrame = CreateFrame("Frame")
local isSOD = C_Seasons.GetActiveSeason() == 2
local SpellNames = TotemTimers.SpellNames
local Procs = {}
TotemTimers.Procs = Procs
local centerFrame = CreateFrame("Frame", "TotemTimers_CenterProcFrame", UIParent)
centerFrame:Hide()
centerFrame:SetSize(130,65)
centerFrame:SetFrameLevel(3)
local centerTexture = centerFrame:CreateTexture(nil, "BACKGROUND")
centerTexture:SetAllPoints(centerFrame)
centerFrame.pulseAnimation = XiTimersAnimations:new(centerFrame)
centerFrame.pulseAnimation.button:SetSize(72,36)
local leftFrame = CreateFrame("Frame", "TotemTimers_LeftProcFrame", UIParent)
leftFrame:Hide()
leftFrame:SetFrameLevel(100)
leftFrame:SetSize(65,130)
leftFrame:SetFrameLevel(3)
local leftTexture = leftFrame:CreateTexture(nil, "BACKGROUND")
leftTexture:SetAllPoints(leftFrame)
leftFrame.pulseAnimation = XiTimersAnimations:new(leftFrame)
leftFrame.pulseAnimation.button:SetSize(36,72)
local rightFrame = CreateFrame("Frame", "TotemTimers_RightProcFrame", UIParent)
rightFrame:Hide()
rightFrame:SetFrameLevel(100)
rightFrame:SetSize(65,130)
rightFrame:SetFrameLevel(3)
local rightTexture = rightFrame:CreateTexture(nil, "BACKGROUND")
rightTexture:SetAllPoints(rightFrame)
rightTexture:SetTexCoord(1,0,0,1)
rightFrame.pulseAnimation = XiTimersAnimations:new(rightFrame)
rightFrame.pulseAnimation.button:SetSize(36,72)
rightFrame.pulseAnimation.icon:SetTexCoord(1,0,0,1)
local centerProc = nil
local sideProc = nil
for _, icon in pairs({centerTexture, leftTexture, rightTexture}) do
icon.AnimGroup = icon:CreateAnimationGroup()
icon.AnimGroup:SetLooping("REPEAT")
local scale = icon.AnimGroup:CreateAnimation("Scale")
scale:SetDuration(0.4)
scale:SetScale(1.05,1.05)
scale:SetOrder(1)
scale:SetSmoothing("IN_OUT")
scale = icon.AnimGroup:CreateAnimation("Scale")
scale:SetDuration(0.4)
scale:SetScale(0.95,0.95)
scale:SetOrder(2)
scale:SetSmoothing("IN_OUT")
end
local function GetSpellFromAction(action)
local spell = nil
if action then
local actionType, id = GetActionInfo(action)
if actionType == "spell" then
spell = id
elseif actionType == "macro" then
spell = GetMacroSpell(id)
end
end
if spell then
return TotemTimers.GetBaseSpellID(spell)
end
end
function TotemTimers.CreateProcs()
TotemTimers.LayoutProcs()
eventFrame:SetScript("OnEvent", TotemTimers.ProcEvent)
eventFrame:RegisterUnitEvent("UNIT_AURA", "player")
end
table.insert(TotemTimers.Modules, TotemTimers.CreateProcs)
function TotemTimers.LayoutProcs()
centerFrame:SetAllPoints(TotemTimers.EnhanceCDsCenterProcAnchor)
leftFrame:SetAllPoints(TotemTimers.EnhanceCDsLeftProcAnchor)
rightFrame:SetAllPoints(TotemTimers.EnhanceCDsRightProcAnchor)
end
function TotemTimers.ToggleProcs(enable)
if enable then
eventFrame:Show()
else
eventFrame:Hide()
centerFrame:Hide()
leftFrame:Hide()
rightFrame:Hide()
end
end
function TotemTimers.ProcEvent(self, event, ...)
for _, proc in pairs(Procs) do
proc:Check()
end
end
TotemTimersProcs = {}
TotemTimersProcs.__index = TotemTimersProcs
function TotemTimersProcs:new(isCenter, buff, textures, flashSpells, animateOn, glow)
local self = {}
setmetatable(self, TotemTimersProcs)
self.isCenter = isCenter
self.textures = textures
self.buff = TotemTimers.SpellNames[buff]
self.flashSpells = {}
if flashSpells and type(flashSpells) == "table" then
for _, spell in pairs(flashSpells) do
self.flashSpells[spell] = true
end
end
self.animateOn = animateOn or 1
self.glow = glow
self.buttons = {}
return self
end
function TotemTimersProcs:Check()
-- check for buff
local _,_, count = AuraUtil.FindAuraByName(self.buff, "player", "HELPFUL")
if count then
self:Show(count)
else
self:Hide()
end
end
function TotemTimersProcs:Show(count)
local texture = self.textures[count] or self.textures[1]
if self.isCenter then
centerTexture:SetTexture(texture)
centerFrame:Show()
centerProc = self
if count >= self.animateOn and (not self.lastCount or self.lastCount < count) then
centerTexture.AnimGroup:Play()
centerFrame.pulseAnimation.icon:SetTexture(texture)
centerFrame.pulseAnimation:Play()
elseif count < self.animateOn then
centerTexture.AnimGroup:Stop()
end
else
leftTexture:SetTexture(self.textures[1])
leftFrame:Show()
if self.animateOn == 1 or count >= self.animateOn then
rightTexture:SetTexture(self.textures[1])
rightFrame:Show()
else
rightFrame:Hide()
end
sideProc = self
if count >= self.animateOn and (not self.lastCount or self.lastCount < count) then
leftTexture.AnimGroup:Play()
rightTexture.AnimGroup:Play()
leftFrame.pulseAnimation.icon:SetTexture(texture)
leftFrame.pulseAnimation:Play()
rightFrame.pulseAnimation.icon:SetTexture(texture)
rightFrame.pulseAnimation:Play()
elseif count < self.animateOn then
leftTexture.AnimGroup:Stop()
rightTexture.AnimGroup:Stop()
end
end
self:ToggleGlow(count)
self.lastCount = count;
end
function TotemTimersProcs:Hide()
if self.isCenter and centerProc == self then
centerFrame:Hide()
centerProc = nil
elseif not self.isCenter and sideProc == self then
leftFrame:Hide()
rightFrame:Hide()
sideProc = nil
end
self:ToggleGlow(0)
end
function TotemTimersProcs:CheckButton(button, spell)
self.buttons[button] = (spell and self.flashSpells[spell]) or nil
end
function TotemTimersProcs:ToggleGlow(count)
if not self.glow then return end
if count >= self.glow then
self.glowing = true
for button in pairs(self.buttons) do
ActionButton_ShowOverlayGlow(button)
end
elseif self.glowing then
self.glowing = false
for button in pairs(self.buttons) do
ActionButton_HideOverlayGlow(button)
end
end
end
-- create procs and hook buttons
if TotemTimers.ProcData then
for _, proc in pairs(TotemTimers.ProcData) do
table.insert(Procs, TotemTimersProcs:new(proc.isCenter, proc.buff, proc.textures, proc.flashSpells, proc.animateOn, proc.glow))
end
end
local function ActionButton_UpdateHook(self)
local actionType, action
if self.action and HasAction(self.action) then
action = self.action
else
if self.HasAction and self.GetAction and self:HasAction() then
actionType, action = self:GetAction()
end
end
local spell = GetSpellFromAction(action)
for _, proc in pairs(Procs) do
proc:CheckButton(self, spell)
end
ActionButton_HideOverlayGlow(self)
end
hooksecurefunc("ActionButton_Update", ActionButton_UpdateHook)
local function XiTimersButtonUpdate()
for t = 1, #TotemTimers.EnhanceCDs do
for _, proc in pairs(Procs) do
local button = TotemTimers.EnhanceCDs[t].button
proc:CheckButton(button, button.cdspell)
end
end
end
hooksecurefunc(TotemTimers, "ConfigEnhanceCDs", XiTimersButtonUpdate)
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:SetScript("OnEvent", function(self, event, ...)
eventFrame:UnregisterEvent("PLAYER_LOGIN")
local lab = LibStub("LibActionButton-1.0", true);
local labelvui = LibStub("LibActionButton-1.0-ElvUI", true);
local function buttonUpdate(event, button)
ActionButton_UpdateHook(button)
end
if lab then
lab:RegisterCallback("OnButtonUpdate", buttonUpdate)
end
if labelvui then
labelvui:RegisterCallback("OnButtonUpdate", buttonUpdate)
end
end)