WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Could someone add class colors to this addon for me? (https://www.wowinterface.com/forums/showthread.php?t=52783)

Lesteryoung 09-30-15 08:03 PM

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

Phanx 10-02-15 04:48 AM

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.

Lesteryoung 10-02-15 06:30 PM

Thanks a bunch.

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

Lesteryoung 10-04-15 01:38 AM

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.

semlar 10-04-15 02:11 AM

Quote:

Originally Posted by Lesteryoung (Post 311307)
The text keeps disappearing for some reason.

Try removing "or name == last"

Lesteryoung 10-04-15 09:40 PM

Thanks semlar, that fixed it.


All times are GMT -6. The time now is 11:54 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI