/trunk/Kui_Nameplates_Auras
local kui = LibStub('Kui-1.0') |
local mod = addon:NewModule('Auras', 'AceEvent-3.0') |
local currentFrame = nil |
-- combat log events to listen to for fading auras |
local auraEvents = { |
-- ['SPELL_DISPEL'] = true, |
['SPELL_AURA_REMOVED'] = true, |
['SPELL_AURA_BROKEN'] = true, |
['SPELL_AURA_BROKEN_SPELL'] = true, |
} |
--[[ TODO |
Make work on mouseover |
If only two containers are ever displayed, just make two containers and |
move them around rather than making 1 container for every nameplate |
]] |
local function ArrangeButtons(self) |
local pv, pc |
self.visible = 0 |
end |
if timeLeft <= 0 then |
self:Hide() |
self.time:SetText('0') |
end |
self.elapsed = .5 |
end |
-------------------------------------------------------------- event handlers -- |
function mod:PLAYER_TARGET_CHANGED() |
local frame = addon:GetNameplate(UnitGUID('target'), nil) |
function mod:COMBAT_LOG_EVENT_UNFILTERED(event, ...) |
local castTime, event, _, guid, name, _, _, targetGUID, targetName = ... |
if not guid then return end |
if not auraEvents[event] then return end |
if guid ~= UnitGUID('player') then return end |
if currentFrame and (not frame or frame ~= currentFrame) then |
-- hide auras on the previous target |
currentFrame.auras:Hide() |
end |
--print(event..' from '..name..' on '..targetName) |
if frame ~= currentFrame then |
currentFrame = frame |
end |
-- fetch the subject's nameplate |
local f = addon:GetNameplate(targetGUID, targetName) |
if not f or not f.auras then return end |
if frame then |
-- scan auras on the new target |
self:UNIT_AURA('UNIT_AURA', 'target') |
--print('(frame for guid: '..targetGUID..')') |
local spId = select(12, ...) |
if f.auras.spellIds[spId] then |
f.auras.spellIds[spId]:Hide() |
end |
end |
function mod:PLAYER_TARGET_CHANGED() |
self:UNIT_AURA('UNIT_AURA', 'target') |
end |
function mod:UPDATE_MOUSEOVER_UNIT() |
self:UNIT_AURA('UNIT_AURA', 'mouseover') |
end |
function mod:UNIT_AURA(event, unit) |
if unit ~= 'target' then return end |
-- select the targeted nameplate |
local frame = addon:GetNameplate(UnitGUID(unit), nil) |
if not frame or not frame.auras then return end |
if not frame or not frame.auras or frame.trivial then return end |
--print('Scan auras on unit: '..unit) |
local filter = 'PLAYER ' |
if UnitIsFriend(unit, 'player') then |
filter = filter..'HELPFUL' |
filter = filter..'HARMFUL' |
end |
-- hide currently displayed auras |
local _,button |
for _,button in pairs(frame.auras.spellIds) do |
button:Hide() |
end |
for i = 0,40 do |
-- TODO optimise |
-- TODO find auras which are no longer present |
local name, _, icon, count, _, duration, expirationTime, _, _, _, spellId = UnitAura('target', i, filter) |
local name, _, icon, count, _, duration, expirationTime, _, _, _, spellId = UnitAura(unit, i, filter) |
if name and |
(not self.db.profile.display.useWhitelist or |
(not self.db.profile.behav.useWhitelist or |
whitelist[spellId]) and |
(duration >= self.db.profile.display.lengthMin) and |
(self.db.profile.display.lengthMax == -1 or |
button:Show() |
end |
end |
if frame ~= currentFrame then |
if currentFrame then |
currentFrame.auras:Hide() |
end |
currentFrame = frame |
end |
end |
---------------------------------------------------- Post db change functions -- |
name = 'Timer threshold (s)', |
desc = 'Timer text will be displayed on auras when their remaining length is less than or equal to this value. -1 to always display timer.', |
type = 'range', |
order = 10, |
min = -1, |
softMax = 180, |
step = 1 |
name = 'Effect length minimum (s)', |
desc = 'Auras with a total duration of less than this value will never be displayed. 0 to disable.', |
type = 'range', |
order = 20, |
min = 0, |
softMax = 60, |
step = 1 |
name = 'Effect length maximum (s)', |
desc = 'Auras with a total duration greater than this value will never be displayed. -1 to disable.', |
type = 'range', |
order = 30, |
min = -1, |
softMax= 1800, |
step = 1 |
}, |
} |
}, |
behav = { |
name = 'Behaviour', |
type = 'group', |
inline = true, |
disabled = function() |
return not self.db.profile.enabled |
end, |
args = { |
useWhitelist = { |
name = 'Use whitelist', |
desc = 'Only display spells which your class needs to keep track of for PVP or an effective DPS rotation. Most passive effects are excluded.', |
type = 'toggle' |
type = 'toggle', |
order = 0, |
}, |
} |
} |
timerThreshold = 20, |
lengthMin = 0, |
lengthMax = -1, |
}, |
behav = { |
useWhitelist = true, |
} |
} |
self:RegisterEvent('UNIT_AURA') |
self:RegisterEvent('PLAYER_TARGET_CHANGED') |
self:RegisterEvent('UPDATE_MOUSEOVER_UNIT') |
self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED') |
local _, frame |
for _, frame in pairs(addon.frameList) do |
function mod:OnDisable() |
self:UnregisterEvent('UNIT_AURA') |
self:UnregisterEvent('PLAYER_TARGET_CHANGED') |
self:UnregisterEvent('UPDATE_MOUSEOVER_UNIT') |
self:UnregisterEvent('COMBAT_LOG_EVENT_UNFILTERED') |
local _, frame |
for _, frame in pairs(addon.frameList) do |