Reduce class portrait work and use GUID changes for ToT
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local _G = ShaguTweaks.GetGlobalEnv()
|
||||
local T = ShaguTweaks.T
|
||||
local API = ShaguTweaks.API or {}
|
||||
|
||||
local addonpath
|
||||
local tocs = { "", "-master", "-tbc", "-wotlk" }
|
||||
@@ -34,16 +35,24 @@ local module = ShaguTweaks:register({
|
||||
})
|
||||
|
||||
local function UpdatePortraits(frame)
|
||||
if not frame or not frame.unit or not frame.portrait then return end
|
||||
|
||||
-- detect unit class or remove for non-player units
|
||||
local _, class = UnitClass(frame.unit)
|
||||
class = UnitIsPlayer(frame.unit) and class or nil
|
||||
|
||||
-- update class icon if possible
|
||||
if class and frame.portrait then
|
||||
-- Don't reapply the exact same class texture on every UnitFrame_Update.
|
||||
local state = class or false
|
||||
if frame.ShaguTweaksPortraitClass == state then return end
|
||||
frame.ShaguTweaksPortraitClass = state
|
||||
|
||||
if class then
|
||||
local iconCoords = CLASS_ICON_TCOORDS[class]
|
||||
frame.portrait:SetTexture(addonpath .. "\\img\\UI-Classes-Circles")
|
||||
frame.portrait:SetTexCoord(unpack(iconCoords))
|
||||
elseif not class and frame.portrait then
|
||||
if iconCoords then
|
||||
frame.portrait:SetTexture(addonpath .. "\\img\\UI-Classes-Circles")
|
||||
frame.portrait:SetTexCoord(unpack(iconCoords))
|
||||
end
|
||||
else
|
||||
frame.portrait:SetTexCoord(0, 1, 0, 1)
|
||||
end
|
||||
end
|
||||
@@ -61,20 +70,38 @@ module.enable = function(self)
|
||||
events:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||
events:RegisterEvent("UNIT_PORTRAIT_UPDATE")
|
||||
events:SetScript("OnEvent", function()
|
||||
-- reload player portrait
|
||||
-- force a state refresh because Blizzard may have replaced the texture
|
||||
PlayerFrame.ShaguTweaksPortraitClass = nil
|
||||
TargetFrame.ShaguTweaksPortraitClass = nil
|
||||
PartyMemberFrame1.ShaguTweaksPortraitClass = nil
|
||||
PartyMemberFrame2.ShaguTweaksPortraitClass = nil
|
||||
PartyMemberFrame3.ShaguTweaksPortraitClass = nil
|
||||
PartyMemberFrame4.ShaguTweaksPortraitClass = nil
|
||||
|
||||
UpdatePortraits(PlayerFrame)
|
||||
UpdatePortraits(TargetFrame)
|
||||
|
||||
-- reload party portraits
|
||||
UpdatePortraits(PartyMemberFrame1)
|
||||
UpdatePortraits(PartyMemberFrame2)
|
||||
UpdatePortraits(PartyMemberFrame3)
|
||||
UpdatePortraits(PartyMemberFrame4)
|
||||
end)
|
||||
|
||||
-- update target of target
|
||||
-- Target-of-target has no reliable vanilla portrait event. The old module
|
||||
-- refreshed it every rendered frame. With ClassicAPI we can cheaply watch
|
||||
-- its GUID and only touch the portrait when the unit actually changes.
|
||||
local tot = CreateFrame("Frame", nil, TargetFrame)
|
||||
tot.elapsed = 0
|
||||
tot.lastguid = nil
|
||||
tot:SetScript("OnUpdate", function()
|
||||
UpdatePortraits(TargetofTargetFrame)
|
||||
this.elapsed = this.elapsed + arg1
|
||||
if this.elapsed < .2 then return end
|
||||
this.elapsed = 0
|
||||
|
||||
local guid = API.UnitGUID and API.UnitGUID("targettarget") or UnitName("targettarget")
|
||||
if guid ~= this.lastguid then
|
||||
this.lastguid = guid
|
||||
TargetofTargetFrame.ShaguTweaksPortraitClass = nil
|
||||
UpdatePortraits(TargetofTargetFrame)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user