Enhance IconIndicator with tooltips, fix stacks/applications mixup

This commit is contained in:
omicron committed 2026-03-07 13:17:25 +01:00
1 parent 763bf0bdae
commit abeac379f3
1 file changed
+52 -10
+52 -10
View File
@@ -46,7 +46,8 @@ end
---@param showStacks boolean
---@param doFade nil|number
---@param doFlash nil|number
function IconIndicator:Init(unitframe, size, point, x, y, showStacks, fadeTime, flashTime)
---@param showTooltip nil|boolean
function IconIndicator:Init(unitframe, size, point, x, y, showStacks, fadeTime, flashTime, showTooltip)
self.unitframe = unitframe
self.frameParent = unitframe.overlays
self.size = size
@@ -57,13 +58,21 @@ function IconIndicator:Init(unitframe, size, point, x, y, showStacks, fadeTime,
self.showStacks = showStacks
self.fadeTime = fadeTime
self.flashTime = flashTime
self.showTooltip = showTooltip or false
self.instanceId = 0
self.spellId = 0
end
--- Show the square indicator
---@param data table
function IconIndicator:Show(data)
local frame, stacks = self:GetFrame()
local numStacks = data.stacks or 0
local numStacks = data.applications or 0
self.auraInstanceID = data.auraInstanceID
self.spellId = data.spellId
self.frame = frame
self.stacks = stacks
if self.showStacks and numStacks > 0 then
@@ -77,12 +86,23 @@ function IconIndicator:Show(data)
self.expirationTime = data.expirationTime
self.updateThrottle = 0
end
if self.showTooltip then
frame:SetScript("OnEnter", function()
GameTooltip:SetOwner(frame, "ANCHOR_RIGHT")
GameTooltip:SetSpellByID(self.spellId)
GameTooltip:Show()
end)
frame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
if data.icon then
self:SetIcon(data.icon)
else
self:SetIcon(self.icon)
end
frame:Show()
self:UpdateAlpha()
end
--- Set the icon of the Icon Indicator
@@ -131,22 +151,23 @@ function IconIndicator:Update(data)
if data.icon then
self:SetIcon(data.icon)
end
local numStacks = data.stacks or 0
local numStacks = data.applications or 0
if numStacks > 0 then
self.stacks:SetText(numStacks)
self.stacks:Show()
end
self.expirationTime = data.expirationTime
self.frame:SetAlpha(1)
self.auraInstanceID = data.auraInstanceID
self.spellId = data.spellId
self:UpdateAlpha()
end
function IconIndicator:OnUpdate(dt)
dt = self.updateThrottle + dt
if dt < 0.04 then
self.updateThrottle = dt
function IconIndicator:UpdateAlpha()
if self.expirationTime == 0 then
self.frame:SetAlpha(1)
return
else
self.updateThrottle = 0
end
local timeLeft = self.expirationTime - GetTime()
@@ -159,15 +180,36 @@ function IconIndicator:OnUpdate(dt)
elseif timeLeft < fadeTime then
local alpha = timeLeft / fadeTime
self.frame:SetAlpha(alpha)
else
self.frame:SetAlpha(1)
end
end
function IconIndicator:OnUpdate(dt)
dt = self.updateThrottle + dt
if dt < 0.04 then
self.updateThrottle = dt
return
else
self.updateThrottle = 0
end
self:UpdateAlpha()
end
--- Hide the square indicator.
function IconIndicator:Hide()
local frame = self.frame
if frame == nil then
return
end
self.stacks:Hide()
self.frame = nil
self.stacks = nil
self.instanceId = nil
self.spellId = nil
frame:SetScript("OnUpdate", nil)
frame:SetScript("OnLeave", nil)
frame:SetScript("OnEnter", nil)
iconPool:Release(frame)
end