-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NugKeyFeedback.lua
359 lines (309 loc) · 11.6 KB
/
NugKeyFeedback.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
local addonName, ns = ...
local NugKeyFeedback = CreateFrame("Frame", "NugKeyFeedback", UIParent)
NugKeyFeedback:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
end)
NugKeyFeedback:RegisterEvent("PLAYER_LOGIN")
NugKeyFeedback:RegisterEvent("PLAYER_LOGOUT")
local defaults = {
point = "CENTER",
x = 0, y = 0,
enableCastLine = true,
enableCooldown = true,
enablePushEffect = true,
enableCast = true,
enableCastFlash = true,
lineIconSize = 38,
mirrorSize = 50,
lineDirection = "LEFT",
forceUseActionHook = false,
}
if C_Spell.GetSpellInfo then
local C_Spell_GetSpellInfo = C_Spell.GetSpellInfo
ns.GetSpellInfo = function(spellId)
local info = C_Spell_GetSpellInfo(spellId)
if info then
return info.name, nil, info.iconID
end
end
ns.GetSpellTexture = C_Spell.GetSpellTexture
else
ns.GetSpellInfo = _G.GetSpellInfo
ns.GetSpellTexture = _G.GetSpellTexture
end
local GetSpellInfo = ns.GetSpellInfo
local APILevel = math.floor(select(4,GetBuildInfo())/10000)
local isClassic = APILevel < 5 --WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local dummy = function() end
local IsInPetBattle = isClassic and dummy or C_PetBattles.IsInBattle
local UnitCastingInfo = UnitCastingInfo
local UnitChannelInfo = UnitChannelInfo
if isClassic then
UnitCastingInfo = CastingInfo
UnitChannelInfo = ChannelInfo
end
local IsAddOnLoaded = IsAddOnLoaded or C_AddOns.IsAddOnLoaded
local firstTimeUse = false
function NugKeyFeedback:PLAYER_LOGIN(event)
if not _G.NugKeyFeedbackDB then
_G.NugKeyFeedbackDB = {}
firstTimeUse = true
end
-- Create a DB using defaults and using a shared default profile
-- self.db = LibStub("AceDB-3.0"):New("NugKeyFeedbackDB", defaults, true)
self.db = _G.NugKeyFeedbackDB
ns.SetupDefaults(self.db, defaults)
local usingActionBarAddons = IsAddOnLoaded("Bartender4") or
IsAddOnLoaded("Neuron") or
IsAddOnLoaded("ElvUI") or
IsAddOnLoaded("TukUI")
if self.db.forceUseActionHook or usingActionBarAddons then
self.mirror = self:CreateFeedbackButton(true)
self:HookUseAction()
NugKeyFeedback.autoDetectHookMode = usingActionBarAddons
else
self.mirror = self:CreateFeedbackButton()
self:HookDefaultBindings()
end
local GetActionSpellID = function(action)
local actionType, id, subType = GetActionInfo(action)
if actionType == "spell" then
return id
elseif actionType == "macro" then
return GetMacroSpell(id)
end
end
self.mirror.UpdateAction = function(self, fullUpdate)
local action = self.action
if not action then return end
local tex = GetActionTexture(action)
if not tex then return end
self.icon:SetTexture(tex)
if fullUpdate then
self:UpdateCooldownOrCast()
end
end
self.mirror.UpdateCooldownOrCast = function(self)
local action = self.action
if not action then return end
local isCastingLastSpell = self.castSpellID == GetActionSpellID(action)
local cooldownStartTime, cooldownDuration, enable, modRate = GetActionCooldown(action);
local cooldownFrame = self.cooldown
local castDuration = self.castDuration or 0
if NugKeyFeedback.db.enableCast and self.castSpellID and self.castSpellID == GetActionSpellID(action) and castDuration > cooldownDuration then
cooldownFrame:SetDrawEdge(true)
cooldownFrame:SetReverse(self.castInverted)
CooldownFrame_Set(cooldownFrame, self.castStartTime, castDuration, true, true, 1);
elseif NugKeyFeedback.db.enableCooldown then
cooldownFrame:SetDrawEdge(false)
cooldownFrame:SetReverse(false)
local charges, maxCharges, chargeStart, chargeDuration, chargeModRate = GetActionCharges(action);
CooldownFrame_Set(cooldownFrame, cooldownStartTime, cooldownDuration, enable, false, modRate);
else
cooldownFrame:Hide()
end
end
self:SetSize(30, 30)
self.anchor = self:CreateAnchor()
self:SetPoint("BOTTOMLEFT", self.anchor, "TOPRIGHT", 0, 0)
if firstTimeUse then self.anchor:Show() end
self:RefreshSettings()
self:HookOptionsFrame()
SLASH_NUGKEYFEEDBACK1= "/nugkeyfeedback"
SLASH_NUGKEYFEEDBACK2= "/nkf"
SlashCmdList["NUGKEYFEEDBACK"] = self.SlashCmd
end
function NugKeyFeedback:PLAYER_LOGOUT(event)
ns.RemoveDefaults(self.db, defaults)
end
function NugKeyFeedback.UNIT_SPELLCAST_START(self,event, unit, _castID, spellID)
local name, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitCastingInfo(unit)
if not startTime then return end -- With heavy lags it's nil sometimes
local mirror = self.mirror
mirror.castInverted = false
mirror.castID = castID
mirror.castSpellID = spellID
mirror.castStartTime = startTime /1000
mirror.castDuration = (endTime - startTime) /1000
mirror:BumpFadeOut(mirror.castDuration)
mirror:UpdateCooldownOrCast()
-- self:UpdateCastingInfo(name,texture,startTime,endTime)
end
NugKeyFeedback.UNIT_SPELLCAST_DELAYED = NugKeyFeedback.UNIT_SPELLCAST_START
function NugKeyFeedback.UNIT_SPELLCAST_CHANNEL_START(self,event, unit, _castID, spellID)
local name, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible = UnitChannelInfo(unit)
local mirror = self.mirror
mirror.castInverted = true
mirror.castID = castID
mirror.castSpellID = spellID
mirror.castStartTime = startTime /1000
mirror.castDuration = (endTime - startTime) /1000
mirror:BumpFadeOut(mirror.castDuration)
mirror:UpdateCooldownOrCast()
-- self:UpdateCastingInfo(name,texture,startTime,endTime)
end
NugKeyFeedback.UNIT_SPELLCAST_CHANNEL_UPDATE = NugKeyFeedback.UNIT_SPELLCAST_CHANNEL_START
function NugKeyFeedback.UNIT_SPELLCAST_STOP(self,event, unit, castID, spellID)
local mirror = self.mirror
mirror.castSpellID = nil
mirror.castDuration = nil
mirror:UpdateCooldownOrCast()
end
function NugKeyFeedback.UNIT_SPELLCAST_FAILED(self, event, unit,castID)
if self.mirror.castID == castID then
NugKeyFeedback.UNIT_SPELLCAST_STOP(self, event, unit, nil)
end
end
NugKeyFeedback.UNIT_SPELLCAST_INTERRUPTED = NugKeyFeedback.UNIT_SPELLCAST_STOP
NugKeyFeedback.UNIT_SPELLCAST_CHANNEL_STOP = NugKeyFeedback.UNIT_SPELLCAST_STOP
function NugKeyFeedback:SPELL_UPDATE_COOLDOWN(event)
self.mirror:UpdateAction(true)
end
local MirrorActionButtonDown = function(action)
if not HasAction(action) then return end
if IsInPetBattle() then return end
local mirror = NugKeyFeedback.mirror
if mirror.action ~= action then
mirror.action = action
mirror:UpdateAction(true)
else
mirror:UpdateAction()
end
mirror:Show()
mirror._elapsed = 0
mirror:SetAlpha(1)
mirror:BumpFadeOut()
mirror.pushed = true
if mirror:GetButtonState() == "NORMAL" then
if mirror.pushedCircle then
if mirror.pushedCircle.grow:IsPlaying() then
mirror.pushedCircle.grow:Stop()
end
mirror.pushedCircle:Show()
mirror.pushedCircle.grow:Play()
end
mirror:SetButtonState("PUSHED");
end
end
local MirrorActionButtonUp = function(action)
local mirror = NugKeyFeedback.mirror
if mirror:GetButtonState() == "PUSHED" then
mirror:SetButtonState("NORMAL");
end
end
function NugKeyFeedback:HookDefaultBindings()
local GetActionButtonForID = _G.GetActionButtonForID
hooksecurefunc("ActionButtonDown", function(id)
local button = GetActionButtonForID(id)
if button then
return MirrorActionButtonDown(button.action)
end
end)
hooksecurefunc("ActionButtonUp", MirrorActionButtonUp)
hooksecurefunc("MultiActionButtonDown", function(bar,id)
local button = _G[bar.."Button"..id];
return MirrorActionButtonDown(button.action)
end)
hooksecurefunc("MultiActionButtonUp", MirrorActionButtonUp)
end
function NugKeyFeedback:HookUseAction()
hooksecurefunc("UseAction", function(action)
return MirrorActionButtonDown(action)
end)
end
function NugKeyFeedback:UNIT_SPELLCAST_SUCCEEDED(event, unit, lineID, spellID)
if IsPlayerSpell(spellID) then
if spellID == 75 then return end -- Autoshot
if self.db.enableCastLine then
local frame, isNew = self.iconPool:Acquire()
local texture = select(3,GetSpellInfo(spellID))
frame.icon:SetTexture(texture)
frame:Show()
frame.ag:Play()
end
if self.db.enableCastFlash then
self.mirror.glow:Show()
self.mirror.glow.blink:Play()
end
end
end
function NugKeyFeedback:RefreshSettings()
local db = self.db
self.mirror:SetSize(db.mirrorSize, db.mirrorSize)
if self.mirror.masqueGroup then
self.mirror.masqueGroup:ReSkin()
end
self:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
if db.enableCastLine then
if not self.iconPool then
self.iconPool = self:CreateLastSpellIconLine(self.mirror)
end
local pool = self.iconPool
pool:ReleaseAll()
for i,f in ipairs(pool.inactiveObjects) do
-- f:SetHeight(db.lineIconSize)
-- f:SetWidth(db.lineIconSize)
pool:resetterFunc(f)
end
if pool.masqueGroup then
pool.masqueGroup:ReSkin()
end
end
if db.enableCooldown then
self:RegisterEvent("SPELL_UPDATE_COOLDOWN")
else
self:UnregisterEvent("SPELL_UPDATE_COOLDOWN")
end
if db.enableCast then
self:RegisterUnitEvent("UNIT_SPELLCAST_START", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_DELAYED", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_STOP", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_FAILED", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_INTERRUPTED", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_START", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", "player")
self:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", "player")
else
self:UnregisterEvent("UNIT_SPELLCAST_START")
self:UnregisterEvent("UNIT_SPELLCAST_DELAYED")
self:UnregisterEvent("UNIT_SPELLCAST_STOP")
self:UnregisterEvent("UNIT_SPELLCAST_FAILED")
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
end
end
function NugKeyFeedback.SlashCmd(msg)
if not NugKeyFeedback.optionsPanel then
NugKeyFeedback.optionsPanel = NugKeyFeedback:CreateGUI()
end
InterfaceOptionsFrame_OpenToCategory("NugKeyFeedback")
InterfaceOptionsFrame_OpenToCategory("NugKeyFeedback")
end
function ns.SetupDefaults(t, defaults)
for k,v in pairs(defaults) do
if type(v) == "table" then
if t[k] == nil then
t[k] = CopyTable(v)
else
ns.SetupDefaults(t[k], v)
end
else
if t[k] == nil then t[k] = v end
end
end
end
function ns.RemoveDefaults(t, defaults)
for k, v in pairs(defaults) do
if type(t[k]) == 'table' and type(v) == 'table' then
ns.RemoveDefaults(t[k], v)
if next(t[k]) == nil then
t[k] = nil
end
elseif t[k] == v then
t[k] = nil
end
end
return t
end