From 11f9cd848b5a8c8591b36a58718a8ab586772429 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 21 May 2026 17:27:19 -0500 Subject: [PATCH] tooltip:GetUnit via HasUnit + UnitTokenFromGUID GameTooltip:HasUnit() / GameTooltip:GetUnitGUID() ask the tooltip directly what unit it's displaying (returns the GUID), and UnitTokenFromGUID resolves that to a unit token. So instead of iterating mouseover/player/pet/target plus party1..4, partypet1..4, raid1..40, raidpet1..40 and string-matching each against GameTooltipTextLeft1:GetText(), this is now a three-line lookup. Bonus: drops the UnitName / UnitPVPName fallback string match (which broke on duplicate names across the realm and on tooltips showing PVP titles that didn't exactly match a token's UnitPVPName output). GUID is canonical. --- modules/tooltip.lua | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/modules/tooltip.lua b/modules/tooltip.lua index becefa51..c4cba770 100644 --- a/modules/tooltip.lua +++ b/modules/tooltip.lua @@ -58,31 +58,12 @@ pfUI:RegisterModule("tooltip", "vanilla", function () end end - local units = { "mouseover", "player", "pet", "target", "party", "partypet", "raid", "raidpet" } function pfUI.tooltip:GetUnit() pfUI.tooltip.unit = "none" - - for i, unit in pairs(units) do - if unit == "party" or unit == "partypet" then - for i=1,4 do - if UnitExists(unit .. i) and ( UnitName(unit .. i) == GameTooltipTextLeft1:GetText() or UnitPVPName(unit .. i) == GameTooltipTextLeft1:GetText() ) then - pfUI.tooltip.unit = unit .. i - return pfUI.tooltip.unit - end - end - elseif unit == "raid" or unit == "raidpet" then - for i=1,40 do - if UnitExists(unit .. i) and ( UnitName(unit .. i) == GameTooltipTextLeft1:GetText() or UnitPVPName(unit .. i) == GameTooltipTextLeft1:GetText() ) then - pfUI.tooltip.unit = unit .. i - return pfUI.tooltip.unit - end - end - else - if UnitExists(unit) and ( UnitName(unit) == GameTooltipTextLeft1:GetText() or UnitPVPName(unit) == GameTooltipTextLeft1:GetText() ) then - pfUI.tooltip.unit = unit - return pfUI.tooltip.unit - end - end + if GameTooltip:HasUnit() then + local _, guid = GameTooltip:GetUnitGUID() + local token = guid and UnitTokenFromGUID(guid) + if token then pfUI.tooltip.unit = token end end return pfUI.tooltip.unit end