-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.lua
More file actions
220 lines (188 loc) · 7.05 KB
/
Copy pathController.lua
File metadata and controls
220 lines (188 loc) · 7.05 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
--[[----------------------------------------------------------------------------
ActionBarInterruptHighlight
Copyright 2026 Mike "Xodiv" Battersby
----------------------------------------------------------------------------]]--
local _, addon = ...
-- Note about warlocks: the interrupt pet abilities are the override spell
-- for Command Demon (119898): not the spell the pet casts, but the spell the
-- player casts to make the pet cast their spell.
local Interrupts = {
[ 47528] = true, -- Mind Freeze (Death Knight)
[183752] = true, -- Disrupt (Demon Hunter)
[ 78675] = true, -- Solar Beam (Druid)
[106839] = true, -- Skull Bash (Druid)
[147362] = true, -- Counter Shot (Hunter)
[187707] = true, -- Muzzle (Hunter)
[ 2139] = true, -- Counterspell (Mage)
[116705] = true, -- Spear Hand Strike (Monk)
[ 96231] = true, -- Rebuke (Paladin)
[ 15487] = true, -- Silence (Priest)
[ 1766] = true, -- Kick (Rogue)
[ 57994] = true, -- Wind Shear (Shaman)
[119910] = true, -- Spell Lock (Warlock Felhunter Pet)
[132409] = true, -- Spell Lock (Warlock Fel Ravager)
[119914] = true, -- Axe Toss (Warlock Felguard Pet)
[ 6552] = true, -- Pummel (Warrior)
[351338] = true, -- Quell (Evoker)
}
local Events = {
'ACTIONBAR_SLOT_CHANGED',
'PLAYER_FOCUS_CHANGED',
'PLAYER_TARGET_CHANGED',
'UNIT_SPELLCAST_CHANNEL_START',
'UNIT_SPELLCAST_CHANNEL_STOP',
'UNIT_SPELLCAST_CHANNEL_UPDATE',
'UNIT_SPELLCAST_DELAYED',
'UNIT_SPELLCAST_FAILED',
'UNIT_SPELLCAST_INTERRUPTED',
'UNIT_SPELLCAST_INTERRUPTIBLE',
'UNIT_SPELLCAST_NOT_INTERRUPTIBLE',
'UNIT_SPELLCAST_START',
'UNIT_SPELLCAST_STOP',
}
local CooldownViewerNames = { "EssentialCooldownViewer", "UtilityCooldownViewer", }
--[[------------------------------------------------------------------------]]--
local function GetAllActionButtons()
local buttons = {}
-- Blizzard
for _, actionButton in pairs(ActionBarButtonEventsFrame.frames) do
local _, spellID = GetActionInfo(actionButton.action)
buttons[actionButton] = spellID
end
-- CDM
for _, viewerName in ipairs(CooldownViewerNames) do
local viewer = _G[viewerName]
for _, itemFrame in ipairs(viewer:GetItemFrames()) do
if itemFrame.cooldownID then
local info = C_CooldownViewer.GetCooldownViewerCooldownInfo(itemFrame.cooldownID)
if info then
buttons[itemFrame] = info.spellID
end
end
end
end
-- Dominos
if Dominos then
for actionButton in pairs(Dominos.ActionButtons.buttons) do
local _, spellID = GetActionInfo(actionButton.action)
buttons[actionButton] = spellID
end
end
-- LibActionButton variants
-- The %- here is a literal "-"
for name, lib in LibStub:IterateLibraries() do
if name:match('^LibActionButton%-1.0') then
for actionButton in pairs(lib:GetAllButtons()) do
local actionType, _action = actionButton:GetAction()
if actionType == "action" then
local _, spellID = GetActionInfo(actionButton.action)
buttons[actionButton] = spellID
end
end
end
end
return buttons
end
--[[------------------------------------------------------------------------]]--
ABIHControllerMixin = {}
function ABIHControllerMixin:OnLoad()
self:RegisterEvent('PLAYER_LOGIN')
end
function ABIHControllerMixin:Initialize()
addon.InitializeOptions()
addon.db.RegisterCallback(self, 'OnOptionsChanged', 'OnOptionsChanged')
self.overlayPool = CreateFramePool('Frame', nil, "ABIHOverlayTemplate")
self.state = {}
FrameUtil.RegisterFrameForEvents(self, Events)
-- This fires fairly often and causes a full rebuild of all the cooldown
-- viewer itemFrames. Very inefficient compared to the actionbars.
EventRegistry:RegisterCallback("CooldownViewerSettings.OnDataChanged",
function ()
self:CreateOverlays()
self:Update('target')
end)
end
function ABIHControllerMixin:IsRelevantActionID(actionID)
local _, spellID = GetActionInfo(actionID)
if Interrupts[spellID] then
return true
end
for overlay in self.overlayPool:EnumerateActive() do
if overlay.spellID == spellID then
return true
end
end
return false
end
function ABIHControllerMixin:CreateOverlays()
self.overlayPool:ReleaseAll()
for actionButton, spellID in pairs(GetAllActionButtons()) do
if Interrupts[spellID] then
local overlay = self.overlayPool:Acquire()
overlay.spellID = spellID
overlay:Attach(actionButton)
end
end
end
function ABIHControllerMixin:RefreshOverlays()
for overlay in self.overlayPool:EnumerateActive() do
local unit = overlay:GetCurrentUnit()
local state = self.state[unit]
if state then
overlay:Update(unpack(state))
end
end
end
function ABIHControllerMixin:UpdateUnitState(unit)
if UnitCanAttack('player', unit) then
local name, notInterruptible, _
name, _, _, _, _, _, _, notInterruptible = UnitCastingInfo(unit)
if name then
local duration = UnitCastingDuration(unit)
self.state[unit] = { true, notInterruptible, duration }
return
end
name, _, _, _, _, _, notInterruptible = UnitChannelInfo(unit)
if name then
local duration = UnitChannelDuration(unit)
-- or UnitEmpoweredChannelDuration(unit)
self.state[unit] = { true, notInterruptible, duration }
return
end
end
self.state[unit] = { false }
end
function ABIHControllerMixin:Update(...)
for i = 1, select('#', ...) do
local unit = select(i, ...)
self:UpdateUnitState(unit)
end
self:RefreshOverlays()
end
function ABIHControllerMixin:OnOptionsChanged()
self:CreateOverlays()
self:Update('focus', 'target')
end
function ABIHControllerMixin:OnEvent(event, ...)
if event == 'PLAYER_LOGIN' then
self:Initialize()
self:CreateOverlays()
self:Update('focus', 'target')
elseif event == 'ACTIONBAR_SLOT_CHANGED' then
-- This fires CONSTANTLY when assistedcombat is on a bar
local actionID = ...
if self:IsRelevantActionID(actionID) then
self:CreateOverlays()
self:Update('focus', 'target')
end
elseif event == 'PLAYER_TARGET_CHANGED' then
self:Update('target')
elseif event == 'PLAYER_FOCUS_CHANGED' then
self:Update('focus')
elseif event:sub(1, 14) == 'UNIT_SPELLCAST' then
local unit = ...
if unit == 'focus' or unit == 'target' then
self:Update(unit)
end
end
end