I think I got it!!! (But it works only out of combat atm. I need a secure way to apply the unit attribute (I think...))
Lua Code:
--UFM:UnitAdded
function UFM:UnitAdded(nameplate,unit)
self.unit = unit
self.inVehicle = UnitInVehicle(unit)
self:SetAttribute("unit", unit)
self:UpdateAllElements("NAME_PLATE_UNIT_ADDED")
end
--UFM:UnitRemoved
function UFM:UnitRemoved(nameplate,unit)
self.unit = nil
self.inVehicle = nil
self:SetAttribute("unit", unit)
self:UpdateAllElements("NAME_PLATE_UNIT_REMOVED")
end
Full solution (all you need is your own style function)
Lua Code:
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- NAMEPLATE TEST
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--register focus
oUF:RegisterStyle(A.."NamePlateStyle", CreateNamePlateStyle)
oUF:SetActiveStyle(A.."NamePlateStyle")
local W = CreateFrame("Frame") --worker
local UFM = {} --unit frame mixin
local C_NamePlate = C_NamePlate
-----------------------------
-- Hide Blizzard
-----------------------------
function W:UpdateNamePlateOptions(...)
print("UpdateNamePlateOptions",...)
end
--disable blizzard nameplates
NamePlateDriverFrame:UnregisterAllEvents()
NamePlateDriverFrame:Hide()
NamePlateDriverFrame.UpdateNamePlateOptions = W.UpdateNamePlateOptions
-----------------------------
-- Worker
-----------------------------
function W:NAME_PLATE_UNIT_ADDED(unit)
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
if not nameplate.unitFrame then
local unitFrame = oUF:Spawn(unit, A..nameplate:GetName())
unitFrame:SetParent(nameplate)
unitFrame:ClearAllPoints()
unitFrame:SetPoint("CENTER")
nameplate.unitFrame = unitFrame
Mixin(unitFrame, UFM)
end
nameplate.unitFrame:UnitAdded(nameplate,unit)
end
function W:NAME_PLATE_UNIT_REMOVED(unit)
local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
nameplate.unitFrame:UnitRemoved(nameplate,unit)
end
function W:OnEvent(event,...)
self[event](event,...)
end
W:SetScript("OnEvent", W.OnEvent)
W:RegisterEvent("NAME_PLATE_UNIT_ADDED")
W:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
-----------------------------
-- Unit Frame Mixin
-----------------------------
function UFM:UnitAdded(nameplate,unit)
self.unit = unit
self.inVehicle = UnitInVehicle(unit)
self:SetAttribute("unit", unit)
self:UpdateAllElements("NAME_PLATE_UNIT_ADDED")
end
function UFM:UnitRemoved(nameplate,unit)
self.unit = nil
self.inVehicle = nil
self:SetAttribute("unit", unit)
self:UpdateAllElements("NAME_PLATE_UNIT_REMOVED")
end
I either need a spawn that does not need secure environment or I need a way to spawn/change the unit attribute securely.