80 lines
2.2 KiB
Lua
80 lines
2.2 KiB
Lua
-- WA_NAMEPLATE_CLOSED NAME_PLATE_UNIT_ADDED NAME_PLATE_UNIT_REMOVED NAME_PLATE_AURA_NAMES FRAME_UPDATE
|
|
function(states, event, unit, ...)
|
|
if event == "WA_NAMEPLATE_CLOSED" then
|
|
for i = 1, 40 do
|
|
local unit = "nameplate" .. i
|
|
if UnitExists(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
|
|
print(string.format("%s: %s", event, unit))
|
|
aura_env.stored[GUID] = unit
|
|
local unitTarget = unit .. "-target"
|
|
if UnitExists(unitTarget) then
|
|
local targetname = UnitName(unitTarget)
|
|
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
|
|
|
|
states[GUID] = {
|
|
name = targetname,
|
|
GUID = GUID,
|
|
unit = unit,
|
|
frame = nameplate,
|
|
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
|