Thread Tools Display Modes
09-30-15, 08:03 PM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Could someone add class colors to this addon for me?

I found a target of target tooltip addon a while back and it works fine, but I wish the ToT text showed class color as well as friendly/enemy npc color.

Could someone add that for me? I'd do it if I knew how, and I couldn't find any other ToT on tooltip addons that show class color.

Oh, and could you remove the fade out animation and just make the tooltip fade instantly instead of the default 2-3 seconds.

Lua Code:
  1. local targetting = ""
  2. local TARGET_PREFIX = TARGET..":|cffffffff ";
  3. local ToTTT = {}
  4.  
  5. GameTooltip:HookScript("OnUpdate", function(self, ...) 
  6.     ToTTT:AddTargetToTT()                  
  7. end)
  8.  
  9. function ToTTT:AddTargetToTT()
  10.  
  11.     if ( not UnitExists('mouseovertarget')) then return end
  12.    
  13.     local targetLine
  14.     local useExisting = false
  15.    
  16.     for i = 2, GameTooltip:NumLines() do
  17.         targetLine = _G["GameTooltipTextLeft"..i];
  18.         if (targetLine:GetText():find(TARGET)) then
  19.            
  20.             useExisting = true
  21.             break;
  22.         end
  23.     end
  24.  
  25.     targetting = UnitName("mouseovertarget")
  26.     if (targetting ~= nil and targetting ~= "") then
  27.        
  28.         if useExisting then
  29.             targetLine:SetText(string.format("%s %s |r", TARGET_PREFIX, targetting ) )
  30.         else
  31.             GameTooltip:AddLine( string.format("%s %s |r", TARGET_PREFIX, targetting ) )
  32.         end
  33.        
  34.         GameTooltip:Show()
  35.     end
  36. end

Last edited by Lesteryoung : 09-30-15 at 08:18 PM.
  Reply With Quote
10-02-15, 04:48 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Lua Code:
  1. local SET_TEXT = TARGET .. ": |cff%02x%02x%02x%s|r"
  2. local MATCH_TEXT = "^" .. TARGET
  3.  
  4. local last
  5. GameTooltip:HookScript("OnUpdate", function(self)
  6.     local name = UnitName("mouseovertarget")
  7.     if not name or name == "" or name == last then return end
  8.     last = name
  9.  
  10.     local r, g, b
  11.     if UnitIsPlayer("mouseovertarget") then
  12.         local _, class = UnitClass("mouseovertarget")
  13.         local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  14.         r, g, b = color.r, color.g, color.b
  15.     else
  16.         r, g, b = GameTooltip_UnitColor("mouseovertarget")
  17.     end
  18.  
  19.     for i = 2, self:NumLines() do
  20.         local line = _G["GameTooltipTextLeft"..i]
  21.         if strfind(line:GetText() or "", MATCH_TEXT) then
  22.             line:SetFormattedText(SET_TEXT, r * 255, g * 255, b * 255, name)
  23.             return self:Show()
  24.         end
  25.     end
  26.     self:AddLine(format(SET_TEXT, r * 255, g * 255, b * 255, name))
  27.     self:Show()
  28. end)

I'll have to get back to you on the fading thing; I don't remember offhand the method name that needs to be overwritten for that.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
10-02-15, 06:30 PM   #3
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Thanks a bunch.

Don't worry about the fade thing, I'll tinker around until I figure it out.

Last edited by Lesteryoung : 10-04-15 at 01:36 AM.
  Reply With Quote
10-04-15, 01:38 AM   #4
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Hey Phanx, just letting you know that the code you gave doesn't really work. The text keeps disappearing for some reason. Not sure why.
  Reply With Quote
10-04-15, 02:11 AM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Lesteryoung View Post
The text keeps disappearing for some reason.
Try removing "or name == last"
  Reply With Quote
10-04-15, 09:40 PM   #6
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Thanks semlar, that fixed it.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Could someone add class colors to this addon for me?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off