View Single Post
09-06-14, 02:03 PM   #9
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Collecting the posted snippets I'd try it this way
Download: zz_ClassColor.zip

Lua Code:
  1. local ClassColorUnits = {
  2.     ["target"] = {
  3.         ["name"] = "TargetFrame",
  4.         ["back"] = "TargetFrame",
  5.         ["x-offset"] = -104,
  6.         ["y-offset"] = 60,
  7.         ["x-offset2"] = 6,
  8.         ["y-offset2"] = -22,
  9.     },
  10.     ["player"] = {
  11.         ["name"] = "PlayerFrame",
  12.         ["back"] = "PlayerFrameBackground",
  13.         ["x-offset"] = 0,
  14.         ["y-offset"] = 22,
  15.         ["x-offset2"] = 0,
  16.         ["y-offset2"] = 0,
  17.     },
  18.     ["focus"] = {
  19.         ["name"] = "FocusFrame",
  20.         ["back"] = "FocusFrame",
  21.         ["x-offset"] = -104,
  22.         ["y-offset"] = 60,
  23.         ["x-offset2"] = 6,
  24.         ["y-offset2"] = -22,
  25.     },
  26. }
  27. local function updateClassColor(unit)
  28.     if(unit and UnitExists(unit)) then
  29.         local _,class = UnitClass(unit)
  30.         if(class and RAID_CLASS_COLORS[class]) then
  31.             if(ClassColorUnits[unit]) then
  32.                 local uf = _G[ClassColorUnits[unit]['name']]
  33.                 local bg = _G[ClassColorUnits[unit]['back']]
  34.                 if(not uf['unitClassColorBack']) then
  35.                     uf['unitClassColorBack'] = uf:CreateTexture(nil, "ARTWORK")
  36.                     uf['unitClassColorBack']:SetPoint("TOPLEFT", bg, ClassColorUnits[unit]['x-offset2'], ClassColorUnits[unit]['y-offset2'])
  37.                     uf['unitClassColorBack']:SetPoint("BOTTOMRIGHT", bg, ClassColorUnits[unit]['x-offset'], ClassColorUnits[unit]['y-offset'])
  38.                     uf['unitClassColorBack']:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
  39.                 end
  40.                 local col = RAID_CLASS_COLORS[class]
  41.                 uf['unitClassColorBack']:SetVertexColor(col['r'], col['g'], col['b'])
  42.             end
  43.         end
  44.     end
  45. end
  46.  
  47. local frame = CreateFrame("Frame")
  48. frame:RegisterEvent("PLAYER_FOCUS_CHANGED")
  49. frame:RegisterEvent("PLAYER_TARGET_CHANGED")
  50. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  51. frame:SetScript("OnEvent", function(self, event)
  52.     if(event=="PLAYER_FOCUS_CHANGED") then
  53.         updateClassColor('focus')
  54.     elseif(event=="PLAYER_TARGET_CHANGED") then
  55.         updateClassColor('target')
  56.     elseif(event=="PLAYER_ENTERING_WORLD") then
  57.         updateClassColor('player')
  58.         self:UnregisterEvent(event)
  59.     end
  60. end)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote