mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-06 05:30:00 +00:00
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.
This commit is contained in:
+4
-23
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user