View Single Post
Unread 06-29-13, 11:36 AM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,391
I cleaned up my testcode aswell. I will use it as a start for my new nameplate addon.



Lua Code:
  1. --RDP3
  2.     local RDP = CreateFrame("Frame", nil, WorldFrame)
  3.     RDP.nameplates = {}
  4.  
  5.     local function NameplateOnShow(...)
  6.       local self = ...
  7.       --print(...)
  8.       print(self:GetName().. "NameplateOnShow")
  9.     end
  10.  
  11.     local function NameplateOnHide(...)
  12.       local self = ...
  13.       --print(...)
  14.       print(self:GetName().. "NameplateOnHide")
  15.     end
  16.  
  17.     local function CastbarOnValueChanged(...)
  18.       local self = ...
  19.       --print(...)
  20.       print(self:GetParent():GetParent():GetName().. "CastbarOnValueChanged")
  21.     end
  22.  
  23.     local function HealthbarOnValueChanged(...)
  24.       local self = ...
  25.       --print(...)
  26.       print(self:GetParent():GetParent():GetName().."HealthbarOnValueChanged")
  27.     end
  28.  
  29.     local function IsNamePlateFrame(obj)
  30.       local name = obj:GetName()
  31.       if name and name:find("NamePlate") then
  32.         return true
  33.       end
  34.       obj.rdp_checked = true --don't touch this frame again
  35.       return false
  36.     end
  37.  
  38.     local function AddNamePlateToList(plate)
  39.       plate.barFrame, plate.nameFrame = plate:GetChildren()
  40.       plate.healthbar, plate.castbar = plate.barFrame:GetChildren()
  41.       plate.threat, plate.border, plate.highlight, plate.level, plate.boss, plate.raid, plate.dragon = plate.barFrame:GetRegions()
  42.       plate.name = plate.nameFrame:GetRegions()
  43.       plate.healthbar.texture = plate.healthbar:GetRegions()
  44.       plate.castbar.texture, plate.castbar.border, plate.castbar.shield, plate.castbar.icon, plate.castbar.name, plate.castbar.nameShadow = plate.castbar:GetRegions()
  45.       plate.rdp_checked = true
  46.  
  47.       RDP.nameplates[plate] = CreateFrame("Frame", nil, RDP)
  48.       RDP.nameplates[plate]:SetSize(128,32)
  49.       local t = RDP.nameplates[plate]:CreateTexture()
  50.       t:SetAllPoints()
  51.       t:SetTexture(1,0,1,0.3)
  52.  
  53.       --keep the frame reference for later
  54.       --RDP.nameplates[plate].blizzPlate = plate
  55.       --plate.newPlate = RDP.nameplates[plate]
  56.  
  57.       --plate:Hide()
  58.       --plate.barFrame:SetParent(Nameplates[plate])
  59.       plate.nameFrame:SetParent(RDP.nameplates[plate])
  60.       plate.barFrame:Hide()
  61.       --plate.nameFrame:Hide()
  62.       plate:HookScript("OnShow", NameplateOnShow)
  63.       plate:HookScript("OnHide", NameplateOnHide)
  64.       plate.healthbar:HookScript("OnValueChanged", HealthbarOnValueChanged)
  65.       plate.castbar:HookScript("OnValueChanged", CastbarOnValueChanged)
  66.  
  67.       local t = plate:CreateTexture()
  68.       t:SetAllPoints()
  69.       t:SetTexture(1,1,0,0.3)
  70.  
  71.     end
  72.  
  73.     local function SearchForNamePlates(self)
  74.       local currentChildren = self:GetNumChildren()
  75.       if not currentChildren or currentChildren == 0 then return end
  76.       for _, obj in pairs({self:GetChildren()}) do
  77.         if not obj.rdp_checked and IsNamePlateFrame(obj) then
  78.           AddNamePlateToList(obj)
  79.         end
  80.       end
  81.     end
  82.  
  83.     local function OnUpdate(self)
  84.       SearchForNamePlates(self)
  85.       RDP:Hide()
  86.       for blizzPlate, plate in pairs(RDP.nameplates) do
  87.           plate:Hide()
  88.           if blizzPlate:IsShown() then
  89.             plate:SetPoint("CENTER", WorldFrame, "BOTTOMLEFT", blizzPlate:GetCenter())
  90.             plate:Show()
  91.           end
  92.       end
  93.       RDP:Show()
  94.     end
  95.  
  96.     WorldFrame:HookScript("OnUpdate", OnUpdate)
__________________
| Simple is beautiful.
| Roth UI | Roth UI FAQ | GoogleCode | Zork | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
zork is offline   Reply With Quote