78 lines
2.1 KiB
Lua
78 lines
2.1 KiB
Lua
function(states, event, unit, ...)
|
|
if event == "WA_NAMEPLATE_CLOSED" then
|
|
for i = 1, 40 do
|
|
local unit = "nameplate" .. i
|
|
if UnitExists(unit) and UnitCanAttack("player", unit) then
|
|
C_Timer.After(0.1, function() WeakAuras.ScanEvents("NAME_PLATE_AURA_NAMES", unit) end)
|
|
end
|
|
end
|
|
end
|
|
|
|
if event == "NAME_PLATE_UNIT_ADDED" and unit or event == "NAME_PLATE_AURA_NAMES" and unit then
|
|
local GUID = UnitGUID(unit)
|
|
if GUID then
|
|
aura_env.stored[GUID] = unit
|
|
local target = unit .. "-target"
|
|
if UnitExists(target) then
|
|
local name = ("[%s]"):format(UnitName(target))
|
|
if UnitIsPlayer(target) then name = ("[%s]"):format(target) end
|
|
|
|
states[GUID] = {
|
|
name = name,
|
|
GUID = GUID,
|
|
unit = unit,
|
|
frame = C_NamePlate.GetNamePlateForUnit(unit),
|
|
progressType = "static",
|
|
autoHide = true,
|
|
changed = true,
|
|
show = true,
|
|
}
|
|
end
|
|
end
|
|
elseif event == "NAME_PLATE_UNIT_REMOVED" and unit then
|
|
local GUID = UnitGUID(unit)
|
|
local state = states[GUID]
|
|
if state then
|
|
state.show = false
|
|
state.changed = true
|
|
end
|
|
if aura_env.stored[GUID] then aura_env.stored[GUID] = nil end
|
|
end
|
|
if event == "FRAME_UPDATE" then
|
|
local theTime = GetTime()
|
|
if not aura_env.last or aura_env.last < theTime - aura_env.config.throttle then
|
|
for GUID, unit in pairs(aura_env.stored) do
|
|
if GUID then
|
|
local state = states[GUID]
|
|
local target = unit .. "-target"
|
|
if UnitExists(target) then
|
|
if aura_env.config.self and UnitIsUnit("player", target) then return true end
|
|
local name = ("%s"):format(UnitName(target))
|
|
if UnitIsPlayer(target) then name = ("%s"):format(WA_ClassColorName(target)) end
|
|
|
|
if state then
|
|
state.name = name
|
|
state.changed = true
|
|
else
|
|
states[GUID] = {
|
|
name = name,
|
|
GUID = GUID,
|
|
unit = unit,
|
|
frame = C_NamePlate.GetNamePlateForUnit(unit),
|
|
progressType = "static",
|
|
autoHide = true,
|
|
changed = true,
|
|
show = true,
|
|
}
|
|
end
|
|
elseif state then
|
|
state.show = false
|
|
state.changed = true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
return true
|
|
end
|