-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMCTrackerRotationHighlight.lua
More file actions
298 lines (257 loc) · 7.53 KB
/
Copy pathCMCTrackerRotationHighlight.lua
File metadata and controls
298 lines (257 loc) · 7.53 KB
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
local ADDON_NAME = ...
local UPDATE_INTERVAL_SECONDS = 0.08
local PROC_COLOR = { 1, 210 / 255, 0, 1 }
local SUGGESTED_COLOR = { 0.2, 0.6, 1, 1 }
local state = {
cmcNS = nil,
hooksInstalled = false,
updatePending = true,
elapsed = 0,
overlays = setmetatable({}, { __mode = "k" }),
}
local updateFrame = CreateFrame("Frame")
local function GetCMCNS()
if state.cmcNS and state.cmcNS.TrackerItemViewer then
return state.cmcNS
end
if CooldownManagerCentered and CooldownManagerCentered.ns then
state.cmcNS = CooldownManagerCentered.ns
return state.cmcNS
end
return nil
end
local function NormalizeSpellID(spellID)
local id = tonumber(spellID)
if not id or id <= 0 then
return nil
end
return id
end
local function BuildSpellCandidates(spellID)
local numericSpellID = NormalizeSpellID(spellID)
if not numericSpellID then
return nil
end
local candidates = { numericSpellID }
local overrideSpellID = NormalizeSpellID(C_Spell.GetOverrideSpell(numericSpellID))
if overrideSpellID and overrideSpellID ~= numericSpellID then
candidates[#candidates + 1] = overrideSpellID
end
local baseSpellID = NormalizeSpellID(C_Spell.GetBaseSpell(numericSpellID))
if baseSpellID and baseSpellID ~= numericSpellID and baseSpellID ~= overrideSpellID then
candidates[#candidates + 1] = baseSpellID
end
return candidates
end
local function SpellIDsMatch(leftSpellID, rightSpellID)
local leftCandidates = BuildSpellCandidates(leftSpellID)
local rightCandidates = BuildSpellCandidates(rightSpellID)
if not leftCandidates or not rightCandidates then
return false
end
for _, left in ipairs(leftCandidates) do
for _, right in ipairs(rightCandidates) do
if left == right then
return true
end
end
end
return false
end
local function IsSpellProcActive(spellID)
if not C_SpellActivationOverlay or not C_SpellActivationOverlay.IsSpellOverlayed then
return false
end
local candidates = BuildSpellCandidates(spellID)
if not candidates then
return false
end
for _, candidateID in ipairs(candidates) do
if C_SpellActivationOverlay.IsSpellOverlayed(candidateID) then
return true
end
end
return false
end
local function GetSuggestedSpellID()
if not C_AssistedCombat or not C_AssistedCombat.GetNextCastSpell then
return nil
end
return NormalizeSpellID(C_AssistedCombat.GetNextCastSpell(false))
end
local function ResolveEntry(cmcNS, frame)
local affectedFn = cmcNS and cmcNS.API and cmcNS.API.Affected
local affected = affectedFn and affectedFn(frame) or nil
if not affected then
return nil, nil
end
return affected.resolvedTrackerEntryKind or affected.trackerEntryKind, affected.resolvedTrackerEntryId or affected.trackerEntryId
end
local function ResolveSpellID(cmcNS, frame, kind, id)
local directSpellID = NormalizeSpellID(frame and frame.spellID)
if directSpellID then
return directSpellID
end
if kind == "spell" then
return NormalizeSpellID(id)
end
if kind == "item" and C_Item and C_Item.GetItemSpell then
local _, itemSpellID = C_Item.GetItemSpell(id)
return NormalizeSpellID(itemSpellID)
end
return nil
end
local function GetOrCreateOverlay(icon)
if not icon then
return nil
end
local overlay = state.overlays[icon]
if overlay then
return overlay
end
local parent = icon:GetParent()
if not parent then
return nil
end
overlay = CreateFrame("Frame", nil, parent, BackdropTemplateMixin and "BackdropTemplate")
overlay:SetPoint("TOPLEFT", icon, "TOPLEFT", -1, 1)
overlay:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", 1, -1)
overlay:SetFrameLevel((parent:GetFrameLevel() or 1) + 30)
overlay:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 2,
})
overlay:Hide()
state.overlays[icon] = overlay
return overlay
end
local function HideOverlay(icon)
local overlay = state.overlays[icon]
if overlay then
overlay:Hide()
end
end
local function ShowOverlay(icon, color)
local overlay = GetOrCreateOverlay(icon)
if not overlay then
return
end
overlay:SetBackdropBorderColor(color[1], color[2], color[3], color[4] or 1)
overlay:Show()
end
local function ShouldShowSuggested(cmcNS, kind, id, spellID, suggestedSpellID)
if kind ~= "spell" or not id or not spellID or not suggestedSpellID then
return false
end
if not (cmcNS.TrackerDB and cmcNS.TrackerDB.GetGlowFlag) then
return false
end
if not cmcNS.TrackerDB.GetGlowFlag(kind, id, "glowWhenSuggested") then
return false
end
return SpellIDsMatch(spellID, suggestedSpellID)
end
local function ShouldShowProc(cmcNS, kind, id, spellID)
if kind ~= "spell" or not id or not spellID then
return false
end
if not (cmcNS.TrackerDB and cmcNS.TrackerDB.GetProcGlowEnabled) then
return false
end
if not cmcNS.TrackerDB.GetProcGlowEnabled(id) then
return false
end
return IsSpellProcActive(spellID)
end
local function GetActiveTrackerFrames(cmcNS)
if not (cmcNS and cmcNS.TrackerItemViewer and cmcNS.TrackerItemViewer.GetActiveItemFrames) then
return nil
end
local ok, frames = pcall(cmcNS.TrackerItemViewer.GetActiveItemFrames, cmcNS.TrackerItemViewer)
if not ok or type(frames) ~= "table" then
return nil
end
return frames
end
local function RefreshOverlays()
local cmcNS = GetCMCNS()
if not cmcNS then
return
end
local frames = GetActiveTrackerFrames(cmcNS)
if not frames then
return
end
local suggestedSpellID = GetSuggestedSpellID()
local touched = {}
for _, frame in ipairs(frames) do
local icon = frame and frame.Icon
if icon and frame:IsShown() then
touched[icon] = true
local kind, id = ResolveEntry(cmcNS, frame)
local spellID = ResolveSpellID(cmcNS, frame, kind, id)
local suggestedActive = ShouldShowSuggested(cmcNS, kind, id, spellID, suggestedSpellID)
local procActive = ShouldShowProc(cmcNS, kind, id, spellID)
if suggestedActive then
ShowOverlay(icon, SUGGESTED_COLOR)
elseif procActive then
ShowOverlay(icon, PROC_COLOR)
else
HideOverlay(icon)
end
end
end
for icon, _ in pairs(state.overlays) do
if not touched[icon] then
HideOverlay(icon)
end
end
end
local function RequestUpdate()
state.updatePending = true
end
local function InstallHooks()
if state.hooksInstalled then
return
end
local cmcNS = GetCMCNS()
if not cmcNS then
return
end
state.hooksInstalled = true
if AssistedCombatManager and AssistedCombatManager.UpdateAllAssistedHighlightFramesForSpell then
hooksecurefunc(AssistedCombatManager, "UpdateAllAssistedHighlightFramesForSpell", RequestUpdate)
end
if cmcNS.TrackerItemViewer then
if cmcNS.TrackerItemViewer.RefreshSuggestedGlows then
hooksecurefunc(cmcNS.TrackerItemViewer, "RefreshSuggestedGlows", RequestUpdate)
end
if cmcNS.TrackerItemViewer.RefreshProcGlows then
hooksecurefunc(cmcNS.TrackerItemViewer, "RefreshProcGlows", RequestUpdate)
end
if cmcNS.TrackerItemViewer.RefreshAll then
hooksecurefunc(cmcNS.TrackerItemViewer, "RefreshAll", RequestUpdate)
end
end
end
updateFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
updateFrame:RegisterEvent("SPELLS_CHANGED")
updateFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_SHOW")
updateFrame:RegisterEvent("SPELL_ACTIVATION_OVERLAY_GLOW_HIDE")
updateFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
updateFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
updateFrame:RegisterEvent("ACTIVE_PLAYER_SPECIALIZATION_CHANGED")
updateFrame:SetScript("OnEvent", function()
RequestUpdate()
end)
updateFrame:SetScript("OnUpdate", function(_, elapsed)
state.elapsed = state.elapsed + elapsed
if state.elapsed < UPDATE_INTERVAL_SECONDS and not state.updatePending then
return
end
state.elapsed = 0
state.updatePending = false
InstallHooks()
RefreshOverlays()
end)
_G[ADDON_NAME] = _G[ADDON_NAME] or {}