View Single Post
Unread 08-21-13, 02:04 AM   #17
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,353
I case anyone is interested. Here is my test addon using semlars approach.

I recycled as much frames as I could.

Lua Code:
  1. --if 1 == 1 then return end
  2.  
  3.     -----------------------------------------
  4.     -- CONFIG
  5.     -----------------------------------------
  6.  
  7.     local cfg = {}
  8.  
  9.     cfg.width = 100
  10.     cfg.height = 26
  11.  
  12.     -----------------------------------------
  13.     -- VARIABLES
  14.     -----------------------------------------
  15.  
  16.     --add a new global frame
  17.     local RDP = CreateFrame("Frame", "PlateCollector", WorldFrame)
  18.     RDP:SetAllPoints()
  19.     RDP.nameplates = {}
  20.  
  21.     local RAID_CLASS_COLORS = RAID_CLASS_COLORS
  22.     local FACTION_BAR_COLORS = FACTION_BAR_COLORS
  23.     local unpack = unpack
  24.  
  25.     -----------------------------------------
  26.     -- FUNCTIONS
  27.     -----------------------------------------
  28.  
  29.     local function RGBPercToHex(r, g, b)
  30.       r = r <= 1 and r >= 0 and r or 0
  31.       g = g <= 1 and g >= 0 and g or 0
  32.       b = b <= 1 and b >= 0 and b or 0
  33.       return string.format("%02x%02x%02x", r*255, g*255, b*255)
  34.     end
  35.  
  36.     local function FixColor(color)
  37.       color.r,color.g,color.b = floor(color.r*100+.5)/100, floor(color.g*100+.5)/100, floor(color.b*100+.5)/100
  38.     end
  39.  
  40.     --NamePlateOnShow func
  41.     local function NamePlateOnShow(self)
  42.       --new plate
  43.       local newPlate = self.healthbar:GetParent()
  44.       --hide level
  45.       self.level:Hide()
  46.       --healthbar
  47.       self.healthbar:ClearAllPoints()
  48.       self.healthbar:SetPoint("TOP", newPlate)
  49.       self.healthbar:SetPoint("LEFT", newPlate)
  50.       self.healthbar:SetPoint("RIGHT", newPlate)
  51.       self.healthbar:SetHeight(newPlate.height/2)
  52.       --name
  53.       self.name:ClearAllPoints()
  54.       self.name:SetPoint("BOTTOM", newPlate, "TOP")
  55.       self.name:SetPoint("LEFT", newPlate,-10,0)
  56.       self.name:SetPoint("RIGHT", newPlate,10,0)
  57.       self.name:SetFont(STANDARD_TEXT_FONT,11,"THINOUTLINE")
  58.       self.realName = self.name:GetText()
  59.     end
  60.  
  61.     --NamePlateCastbarOnShow func
  62.     local function NamePlateCastbarOnShow(self)
  63.         --new plate
  64.         local newPlate = self:GetParent()
  65.         --castbar
  66.         self:ClearAllPoints()
  67.         self:SetPoint("BOTTOM",newPlate)
  68.         self:SetPoint("LEFT",newPlate)
  69.         self:SetPoint("RIGHT",newPlate)
  70.         self:SetHeight(newPlate.height/2)
  71.         --castbar icon
  72.         self.icon:ClearAllPoints()
  73.         self.icon:SetPoint("RIGHT",newPlate, "LEFT")
  74.     end
  75.  
  76.     --NamePlateNameUpdate func
  77.     local function NamePlateNameUpdate(self)
  78.       if not self.realName then return end
  79.       local cs = RGBPercToHex(self.level:GetTextColor())
  80.       --name string
  81.       local name = self.realName
  82.       local level = self.level:GetText()
  83.       if self.boss:IsShown() == 1 then
  84.         level = "??"
  85.         cs = "ff6600"
  86.       elseif self.dragon:IsShown() == 1 then
  87.         level = level.."+"
  88.       end
  89.       self.name:SetText("|cff"..cs..""..level.."|r "..name)
  90.       self.level:Hide()
  91.     end
  92.  
  93.     --NamePlateHealthBarUpdate func
  94.     local function NamePlateHealthBarUpdate(self)
  95.       local color = {}
  96.       if self.threat:IsShown() then
  97.         color.r, color.g, color.b = self.threat:GetVertexColor()
  98.         FixColor(color)
  99.         if color.r+color.g+color.b < 3 then
  100.           self.healthbar:SetStatusBarColor(color.r,color.g,color.b)
  101.           return
  102.         end
  103.       end
  104.       color.r, color.g, color.b = self.healthbar:GetStatusBarColor()
  105.       FixColor(color)
  106.       for class, _ in pairs(RAID_CLASS_COLORS) do
  107.         if RAID_CLASS_COLORS[class].r == color.r and RAID_CLASS_COLORS[class].g == color.g and RAID_CLASS_COLORS[class].b == color.b then
  108.           self.healthbar:SetStatusBarColor(RAID_CLASS_COLORS[class].r,RAID_CLASS_COLORS[class].g,RAID_CLASS_COLORS[class].b)
  109.           return --no color change needed, bar is in class color
  110.         end
  111.       end
  112.       if color.g+color.b == 0 then -- hostile
  113.         self.healthbar:SetStatusBarColor(FACTION_BAR_COLORS[2].r,FACTION_BAR_COLORS[2].g,FACTION_BAR_COLORS[2].b)
  114.         return
  115.       elseif color.r+color.b == 0 then -- friendly npc
  116.         self.healthbar:SetStatusBarColor(FACTION_BAR_COLORS[6].r,FACTION_BAR_COLORS[6].g,FACTION_BAR_COLORS[6].b)
  117.         return
  118.       elseif color.r+color.g == 2 then -- neutral
  119.         self.healthbar:SetStatusBarColor(FACTION_BAR_COLORS[4].r,FACTION_BAR_COLORS[4].g,FACTION_BAR_COLORS[4].b)
  120.         return
  121.       elseif color.r+color.g == 0 then -- friendly player, we don't like 0,0,1 so we change it to a more likable color
  122.         self.healthbar:SetStatusBarColor(0/255, 100/255, 255/255)
  123.         return
  124.       else -- enemy player
  125.         --whatever is left
  126.         return
  127.       end
  128.     end
  129.  
  130.     --NamePlateInit func
  131.     local function NamePlateInit(plate)
  132.       --add some references
  133.       plate.barFrame, plate.nameFrame = plate:GetChildren()
  134.       plate.healthbar, plate.castbar = plate.barFrame:GetChildren()
  135.       plate.threat, plate.border, plate.highlight, plate.level, plate.boss, plate.raid, plate.dragon = plate.barFrame:GetRegions()
  136.       plate.name = plate.nameFrame:GetRegions()
  137.       plate.healthbar.texture = plate.healthbar:GetRegions()
  138.       plate.castbar.texture, plate.castbar.border, plate.castbar.shield, plate.castbar.icon, plate.castbar.name, plate.castbar.nameShadow = plate.castbar:GetRegions()
  139.       plate.rdp_checked = true
  140.       --create new plate and parent it to RDP
  141.       RDP.nameplates[plate] = CreateFrame("Frame", "New"..plate:GetName(), RDP)
  142.       RDP.nameplates[plate]:SetSize(cfg.width,cfg.height)
  143.       RDP.nameplates[plate].width, RDP.nameplates[plate].height = RDP.nameplates[plate]:GetSize()
  144.       --keep the frame reference for later
  145.       RDP.nameplates[plate].blizzPlate = plate
  146.       plate.newPlate = RDP.nameplates[plate]
  147.       --reparent
  148.       plate.raid:SetParent(RDP.nameplates[plate])
  149.       plate.nameFrame:SetParent(RDP.nameplates[plate])
  150.       plate.castbar:SetParent(RDP.nameplates[plate])
  151.       plate.healthbar:SetParent(RDP.nameplates[plate])
  152.       --reparent raid mark
  153.       plate.raid:ClearAllPoints()
  154.       plate.raid:SetPoint("BOTTOM",RDP.nameplates[plate],"TOP")
  155.       --hide level
  156.       plate.level:Hide()
  157.       --hide textures
  158.       plate.dragon:SetTexture(nil)
  159.       plate.border:SetTexture(nil)
  160.       plate.boss:SetTexture(nil)
  161.       plate.highlight:SetTexture(nil)
  162.       plate.castbar.border:SetTexture(nil)
  163.       plate.castbar.shield:SetTexture(nil)
  164.       plate.threat:SetTexture(nil)
  165.       --plate.castbar.nameShadow:SetTexture(nil)
  166.       --healthbar bg
  167.       plate.healthbar.bg = plate.healthbar:CreateTexture(nil,"BACKGROUND",nil,-8)
  168.       plate.healthbar.bg:SetTexture(0,0,0,1)
  169.       plate.healthbar.bg:SetAllPoints()
  170.       --name
  171.       plate.name:SetFont(STANDARD_TEXT_FONT,11,"THINOUTLINE")
  172.       plate.name:SetShadowColor(0,0,0,0)
  173.       --castbar icon
  174.       plate.castbar.icon:SetTexCoord(0.1,0.9,0.1,0.9)
  175.       plate.castbar.icon:SetSize(RDP.nameplates[plate].height,RDP.nameplates[plate].height)
  176.       --castbar bg
  177.       plate.castbar.bg = plate.castbar:CreateTexture(nil,"BACKGROUND",nil,-8)
  178.       plate.castbar.bg:SetTexture(0,0,0,1)
  179.       plate.castbar.bg:SetAllPoints()
  180.       --castbar spellname
  181.       plate.castbar.name:ClearAllPoints()
  182.       plate.castbar.name:SetPoint("BOTTOM",plate.castbar,0,-5)
  183.       plate.castbar.name:SetPoint("LEFT",plate.castbar,5,0)
  184.       plate.castbar.name:SetPoint("RIGHT",plate.castbar,-5,0)
  185.       plate.castbar.name:SetFont(STANDARD_TEXT_FONT,10,"THINOUTLINE")
  186.       plate.castbar.name:SetShadowColor(0,0,0,0)
  187.       --nameplate on show hook
  188.       plate:HookScript("OnShow", NamePlateOnShow)
  189.       --nameplate castbar on show hook
  190.       plate.castbar:HookScript("OnShow", NamePlateCastbarOnShow)
  191.       --i fix
  192.       NamePlateOnShow(plate)
  193.       --debug
  194.       --local t = plate:CreateTexture()
  195.       --t:SetTexture(1,0,0,0.3)
  196.       --t:SetAllPoints()
  197.     end
  198.  
  199.     --IsNamePlateFrame func
  200.     local function IsNamePlateFrame(obj)
  201.       local name = obj:GetName()
  202.       if name and name:find("NamePlate") then
  203.         return true
  204.       end
  205.       obj.rdp_checked = true
  206.       return false
  207.     end
  208.  
  209.     --SearchForNamePlates func
  210.     local function SearchForNamePlates(self)
  211.       local currentChildren = self:GetNumChildren()
  212.       if not currentChildren or currentChildren == 0 then return end
  213.       for _, obj in pairs({self:GetChildren()}) do
  214.         if not obj.rdp_checked and IsNamePlateFrame(obj) then
  215.           NamePlateInit(obj)
  216.         end
  217.       end
  218.     end
  219.  
  220.     --NamePlateOnUpdate func
  221.     local function NamePlateOnUpdate()
  222.       RDP:Hide()
  223.       for blizzPlate, newPlate in pairs(RDP.nameplates) do
  224.           newPlate:Hide()
  225.           if blizzPlate:IsShown() then
  226.             newPlate:SetPoint("CENTER", WorldFrame, "BOTTOMLEFT", blizzPlate:GetCenter())
  227.             newPlate:SetAlpha(blizzPlate:GetAlpha())
  228.             NamePlateNameUpdate(blizzPlate)
  229.             NamePlateHealthBarUpdate(blizzPlate)
  230.             newPlate:Show()
  231.           end
  232.       end
  233.       RDP:Show()
  234.     end
  235.  
  236.     --OnUpdate func
  237.     local function OnUpdate(self)
  238.       SearchForNamePlates(self)
  239.       NamePlateOnUpdate()
  240.     end
  241.  
  242.     -----------------------------------------
  243.     -- INIT
  244.     -----------------------------------------
  245.  
  246.     WorldFrame:HookScript("OnUpdate", OnUpdate)

SVN: http://code.google.com/p/rothui/sour...ePlateTest.lua

Maybe someone can check the code.

If you disable RDP:Show() at the bottom no nameplate will show up. This shows at all the reparenting and stuff has worked.

FPS-wise it works as intended.

I tried integrating the threat glow color into the healthbar color. This kind of works but I don't like it that much.
__________________
| 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)

Last edited by zork : 08-21-13 at 02:48 AM.
zork is offline   Reply With Quote