View Single Post
10-02-16, 11:10 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
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:
  1. --UFM:UnitAdded
  2. function UFM:UnitAdded(nameplate,unit)
  3.   self.unit = unit
  4.   self.inVehicle = UnitInVehicle(unit)
  5.   self:SetAttribute("unit", unit)
  6.   self:UpdateAllElements("NAME_PLATE_UNIT_ADDED")
  7. end
  8.  
  9. --UFM:UnitRemoved
  10. function UFM:UnitRemoved(nameplate,unit)
  11.   self.unit = nil
  12.   self.inVehicle = nil
  13.   self:SetAttribute("unit", unit)
  14.   self:UpdateAllElements("NAME_PLATE_UNIT_REMOVED")
  15. end

Full solution (all you need is your own style function)

Lua Code:
  1. ------------------------------------------------------------------------------
  2. ------------------------------------------------------------------------------
  3. ------------------------------------------------------------------------------
  4. -- NAMEPLATE TEST
  5. ------------------------------------------------------------------------------
  6. ------------------------------------------------------------------------------
  7. ------------------------------------------------------------------------------
  8.  
  9. --register focus
  10. oUF:RegisterStyle(A.."NamePlateStyle", CreateNamePlateStyle)
  11. oUF:SetActiveStyle(A.."NamePlateStyle")
  12.  
  13. local W = CreateFrame("Frame") --worker
  14. local UFM = {} --unit frame mixin
  15. local C_NamePlate = C_NamePlate
  16.  
  17. -----------------------------
  18. -- Hide Blizzard
  19. -----------------------------
  20.  
  21. function W:UpdateNamePlateOptions(...)
  22.   print("UpdateNamePlateOptions",...)
  23. end
  24.  
  25. --disable blizzard nameplates
  26. NamePlateDriverFrame:UnregisterAllEvents()
  27. NamePlateDriverFrame:Hide()
  28. NamePlateDriverFrame.UpdateNamePlateOptions = W.UpdateNamePlateOptions
  29.  
  30. -----------------------------
  31. -- Worker
  32. -----------------------------
  33.  
  34. function W:NAME_PLATE_UNIT_ADDED(unit)
  35.   local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
  36.   if not nameplate.unitFrame then
  37.     local unitFrame = oUF:Spawn(unit, A..nameplate:GetName())
  38.     unitFrame:SetParent(nameplate)
  39.     unitFrame:ClearAllPoints()
  40.     unitFrame:SetPoint("CENTER")
  41.     nameplate.unitFrame = unitFrame
  42.     Mixin(unitFrame, UFM)
  43.   end
  44.   nameplate.unitFrame:UnitAdded(nameplate,unit)
  45. end
  46.  
  47. function W:NAME_PLATE_UNIT_REMOVED(unit)
  48.   local nameplate = C_NamePlate.GetNamePlateForUnit(unit)
  49.   nameplate.unitFrame:UnitRemoved(nameplate,unit)
  50. end
  51.  
  52. function W:OnEvent(event,...)
  53.   self[event](event,...)
  54. end
  55.  
  56. W:SetScript("OnEvent", W.OnEvent)
  57.  
  58. W:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  59. W:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
  60.  
  61. -----------------------------
  62. -- Unit Frame Mixin
  63. -----------------------------
  64.  
  65. function UFM:UnitAdded(nameplate,unit)
  66.   self.unit = unit
  67.   self.inVehicle = UnitInVehicle(unit)
  68.   self:SetAttribute("unit", unit)
  69.   self:UpdateAllElements("NAME_PLATE_UNIT_ADDED")
  70. end
  71.  
  72. function UFM:UnitRemoved(nameplate,unit)
  73.   self.unit = nil
  74.   self.inVehicle = nil
  75.   self:SetAttribute("unit", unit)
  76.   self:UpdateAllElements("NAME_PLATE_UNIT_REMOVED")
  77. end

I either need a spawn that does not need secure environment or I need a way to spawn/change the unit attribute securely.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 10-02-16 at 11:48 AM.
  Reply With Quote