View Single Post
11-30-19, 09:40 AM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Changeing Chat Bubble Name Color

Hello I have been trying to figure this out for a while now, I have the names able to do RAID_CLASS_COLORS or a specific color but how do I get them to do the reaction color to me, so an enemy's NPC name will show up red.

Here is the current code im working with:
Lua Code:
  1. local events = {
  2.             CHAT_MSG_SAY = 'chatBubbles',
  3.             CHAT_MSG_YELL = 'chatBubbles',
  4.             CHAT_MSG_PARTY = 'chatBubblesParty',
  5.             CHAT_MSG_PARTY_LEADER = 'chatBubblesParty',
  6.             CHAT_MSG_MONSTER_SAY = 'chatBubbles',
  7.             CHAT_MSG_MONSTER_YELL = 'chatBubbles',
  8.             CHAT_MSG_MONSTER_PARTY = 'chatBubblesParty',
  9.         }
  10.  
  11.         local function SkinFrame(frame)
  12.             for i = 1, select('#', frame:GetRegions()) do
  13.                 local region = select(i, frame:GetRegions())
  14.                 if (region:GetObjectType() == 'FontString') then
  15.                     frame.text = region
  16.                 else
  17.                     region:Hide()
  18.                 end
  19.             end
  20.  
  21.             frame.text:SetFontObject('SystemFont_Tiny')
  22.             frame.text:SetJustifyH('LEFT')
  23.  
  24.             frame:ClearAllPoints()
  25.             frame:SetPoint('TOPLEFT', frame.text, -10, 25)
  26.             frame:SetPoint('BOTTOMRIGHT', frame.text, 10, -10)
  27.             frame:SetBackdrop({
  28.                 bgFile = [[Interface\DialogFrame\UI-DialogBox-Background-Dark]],
  29.                 edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
  30.                 tile = true, tileSize = 16, edgeSize = 18,
  31.                 insets = {left = 3, right = 3, top = 3, bottom = 3}
  32.             })
  33.             frame:SetBackdropColor(0, 0, 0, 1)
  34.             local r, g, b = frame.text:GetTextColor()
  35.             frame:SetBackdropBorderColor(r, g, b, .8)
  36.  
  37.             frame.sender = frame:CreateFontString(nil, 'OVERLAY', 'GameFontNormalSmall')
  38.             frame.sender:SetPoint('BOTTOMLEFT', frame.text, 'TOPLEFT', 0, 4)
  39.             frame.sender:SetJustifyH('LEFT')
  40.  
  41.             frame:HookScript('OnHide', function()
  42.                 frame.inUse = false
  43.             end)
  44.         end
  45.  
  46.         local function UpdateFrame(frame, guid, name)
  47.             if (not frame.text) then
  48.                 SkinFrame(frame)
  49.             end
  50.             frame.inUse = true
  51.  
  52.             local ccolor
  53.             if (guid ~= nil and guid ~= '') then
  54.                 _, ccolor, _, _, _, _ = GetPlayerInfoByGUID(guid)
  55.             end
  56.  
  57.             if (name) then
  58.                 local color = RAID_CLASS_COLORS[ccolor] or {r = 1, g = 1, b = 0}
  59.                 frame.sender:SetText(('|cFF%2x%2x%2x%s|r'):format(color.r * 255, color.g * 255, color.b * 255, name))
  60.                 if frame.text:GetWidth() < frame.sender:GetWidth() then
  61.                     frame.text:SetWidth(frame.sender:GetWidth())
  62.                 end
  63.             end
  64.         end
  65.  
  66.         local function FindFrame(msg)
  67.             for i = 1, WorldFrame:GetNumChildren() do
  68.                 local frame = select(i, WorldFrame:GetChildren())
  69.                 if (not frame:GetName() and not frame.inUse) then
  70.                     for i = 1, select('#', frame:GetRegions()) do
  71.                         local region = select(i, frame:GetRegions())
  72.                         if region:GetObjectType() == 'FontString' and region:GetText() == msg then
  73.                             return frame
  74.                         end
  75.                     end
  76.                 end
  77.             end
  78.         end
  79.  
  80.         local ChatBubbleFrame = CreateFrame('Frame')
  81.         for event, cvar in pairs(events) do
  82.             ChatBubbleFrame:RegisterEvent(event)
  83.         end
  84.  
  85.         ChatBubbleFrame:SetScript('OnEvent', function(self, event, msg, sender, _, _, _, _, _, _, _, _, _, guid)
  86.             if (GetCVarBool(events[event])) then
  87.                 ChatBubbleFrame.elapsed = 0
  88.                 ChatBubbleFrame:SetScript('OnUpdate', function(self, elapsed)
  89.                     self.elapsed = self.elapsed + elapsed
  90.                     local frame = FindFrame(msg)
  91.                     if (frame or self.elapsed > 0.3) then
  92.                         ChatBubbleFrame:SetScript('OnUpdate', nil)
  93.                         if (frame) then
  94.                             UpdateFrame(frame, guid, sender)
  95.                         end
  96.                     end
  97.                 end)
  98.             end
  99.         end)
  100.     end
I know its in the
Code:
if (name)
part of the code but I cant seem to figure out how to get it to use recation color.

Thanks for any help with this.
Coke
  Reply With Quote