View Single Post
12-30-13, 09:04 PM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,943
Thanks Phanx, will do.

Edit: Okay, gonna take me a while to figure this out ... Any time I try to adjust AddMessage function it crashes wow, so I guess I am doing something wrong somewhere rofl.

Edit2: Good News is it now color codes the Names and shows the Toon Name and Server based on toggle setting to do so. Bad News is that it currently crashes if you log in / reload and you don't have any realID friends online or seems to go into an infinite loop and crashes if your realID friend logs off. Phanx or anyone else, is there anything you can see in this code that may cause that as I can't seem to see anything that I am not covering myself for so that it simply returns an unformatted message string.

Removed the toast test since the crashing/hanging etc as it isn't really need in this instance so will see if that might be the cause of the issue but just in case it isn't the cause, here is the code in its entirety and a download version if you prefer.

Lua Code:
  1. local addonName, addonData = ...
  2.  
  3. local showToonName = true
  4. local showRealmName = showToonName and true
  5. local debugMessages = true
  6.  
  7. local bnNameFormat = "%s"
  8. local playerBNFormat = "|HBNplayer:%s|h" .. bnNameFormat .. "%s|h"
  9. local playerBNPattern = "|HBNplayer:(.-)|h%[(|Kf(%d+).-)%](.*)|h"
  10.  
  11. local function RGB_TO_HEX(rgb)
  12.     return string.format("%02x%02x%02x", rgb.r*255, rgb.g*255, rgb.b*255)
  13. end
  14.  
  15. local function ColorToonName(chatFrame,message,...)
  16.     local bnData, bnName, bnID, bnExtra = string.match(message, playerBNPattern)
  17.  
  18.     if bnData then
  19.         local toonInfo = { BNGetToonInfo(bnID) }
  20.         local link = string.format(playerBNFormat, bnData, bnName, bnExtra or "")
  21.  
  22.         if toonInfo[3] ~= "WoW" or toonInfo[3] == nil then
  23.             message = string.gsub(message, playerBNPattern, link)
  24.         else
  25.             local toonName = toonInfo[2]
  26.             local realmName = toonInfo[4]
  27.             local class = toonInfo[8]
  28.  
  29.             local color = RAID_CLASS_COLORS[class]
  30.             local classToken = addonData.ClassNames[class]
  31.             if not color then
  32.                 color = RAID_CLASS_COLORS[classToken]
  33.             end
  34.             local colorHex = RGB_TO_HEX(color)
  35.  
  36.             if showToonName then
  37.                 if showRealmName then
  38.                     coloredSender = string.format("|cff%s %s (%s-%s)|r",colorHex,bnName,toonName,realmName)
  39.                 else
  40.                     coloredSender = string.format("|cff%s %s (%s)|r",colorHex,bnName,toonName)
  41.                 end
  42.             else
  43.                 coloredSender = string.format("|cff%s %s|r",colorHex,bnName)
  44.             end
  45.  
  46.             link = string.format(playerBNFormat, bnData, coloredSender, bnExtra or "")
  47.             message = string.gsub(message, playerBNPattern, link)
  48.  
  49.         end
  50.     end
  51.     return message
  52. end
  53.  
  54. local function AddMessage(chatFrame, message, ...)
  55.     if type(message) == "string" then
  56.         local bnData, bnName, bnID, bnExtra = strmatch(message, playerBNPattern)
  57.         if bnData then
  58.             message = ColorToonName(chatFrame,message,...)
  59.         end
  60.     end
  61.     addonData[chatFrame].AddMessage(chatFrame,message, ...)
  62. end
  63.  
  64. addonData.XRICEvents = CreateFrame("Frame")
  65. addonData.XRICEvents:RegisterEvent("ADDON_LOADED")
  66. addonData.XRICEvents:SetScript("OnEvent",function(self,event,...)
  67.  
  68.     local args = { ... }
  69.  
  70.     if event == "ADDON_LOADED" and args[1] == addonName then
  71.         addonData.ClassNames = {}
  72.         for k, v in pairs(LOCALIZED_CLASS_NAMES_MALE) do
  73.                 addonData.ClassNames[v] = k
  74.         end
  75.         for k, v in pairs(LOCALIZED_CLASS_NAMES_FEMALE) do
  76.                 addonData.ClassNames[v] = k
  77.         end
  78.  
  79.         for i = 1, NUM_CHAT_WINDOWS do
  80.             local chatFrame = _G["ChatFrame" .. i]
  81.             addonData[chatFrame] = addonData[chatFrame] or {}
  82.             if ( not addonData[chatFrame].AddMessage ) then
  83.                 addonData[chatFrame].AddMessage = chatFrame.AddMessage
  84.                 chatFrame.AddMessage = AddMessage
  85.             end
  86.         end
  87.     end
  88.  
  89. end)
Attached Files
File Type: zip XRealIDColors.zip (1.4 KB, 284 views)
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818

Last edited by Xrystal : 12-30-13 at 11:19 PM.
  Reply With Quote