From abeac379f388711d2b042b791dde1519d04c8e7f Mon Sep 17 00:00:00 2001 From: omicron Date: Sat, 7 Mar 2026 13:14:38 +0100 Subject: [PATCH] Enhance IconIndicator with tooltips, fix stacks/applications mixup --- src/types/indicators/iconindicator.lua | 62 +++++++++++++++++++++----- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/src/types/indicators/iconindicator.lua b/src/types/indicators/iconindicator.lua index 042f1b2..78e6d81 100644 --- a/src/types/indicators/iconindicator.lua +++ b/src/types/indicators/iconindicator.lua @@ -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