Thread Tools Display Modes
01-26-16, 02:14 AM   #1
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Tooltip code displaying on unwanted tooltips.

The following code was written by Phanx and I found it here on the forums. It does two things, adds class color to the name of the player on the default tooltip, and adds a "Target:" line at the bottom.

The issue I have is that the "Target:" is showing up on all tooltips, and I only want to modify the tooltip you get on player/npc mouseover.

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 == "" 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)
  29.  
  30. GameTooltip:HookScript("OnTooltipSetUnit", function(GameTooltip)
  31.     local _, unit = GameTooltip:GetUnit()
  32.     if UnitIsPlayer(unit) then
  33.         local _, class = UnitClass(unit)
  34.         local color = class and (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  35.         if color then
  36.             local text = GameTooltipTextLeft1:GetText()
  37.             GameTooltipTextLeft1:SetFormattedText("|cff%02x%02x%02x%s|r", color.r * 255, color.g * 255, color.b * 255, text:match("|cff\x\x\x\x\x\x(.+)|r") or text)
  38.         end
  39.     end
  40. end)
  Reply With Quote
01-30-16, 11:27 PM   #2
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
BUMP - I guess "GameTooltip:HookScript" applies to all tooltips? Anyone know how to keep it localized to the mouseover target tooltip in the bottom corner.

Last edited by Lesteryoung : 01-31-16 at 04:47 AM.
  Reply With Quote
01-31-16, 08:00 AM   #3
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Check that the unit == "mouseover" and return if it's not.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
01-31-16, 12:06 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
There seems to be a bug where your "mouseover" can get locked as a valid unit even when you stop mousing over them (UnitName("mouseovertarget") continues returning your old mouseover's target until you mouse over the world frame).

You can see how to reproduce it here.

The script can be "fixed" by changing
Lua Code:
  1. if not name or name == "" then return end
to
Lua Code:
  1. if not name or name == "" or not self:GetUnit() then return end

Last edited by semlar : 01-31-16 at 12:18 PM.
  Reply With Quote
02-01-16, 12:04 AM   #5
Lesteryoung
A Black Drake
Join Date: Aug 2015
Posts: 81
Originally Posted by semlar View Post
There seems to be a bug where your "mouseover" can get locked as a valid unit even when you stop mousing over them (UnitName("mouseovertarget") continues returning your old mouseover's target until you mouse over the world frame).

You can see how to reproduce it here.

The script can be "fixed" by changing
Lua Code:
  1. if not name or name == "" then return end
to
Lua Code:
  1. if not name or name == "" or not self:GetUnit() then return end
Thank you very much, your edit fixed the issue for me.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Tooltip code displaying on unwanted tooltips.


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