From 7c2cd5092e4b30c5f7bd23ca9c8d1bd66b8e5383 Mon Sep 17 00:00:00 2001 From: Sumsebrum Date: Sun, 31 Jul 2022 06:05:33 +0200 Subject: [PATCH] diminish track on SPELL_AURA_APPLIED --- Modules/Diminishings.lua | 168 ++++++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 45 deletions(-) diff --git a/Modules/Diminishings.lua b/Modules/Diminishings.lua index b5c919c..4e8b941 100644 --- a/Modules/Diminishings.lua +++ b/Modules/Diminishings.lua @@ -95,6 +95,7 @@ function Diminishings:CreateFrame(unit) for i = 1, 16 do local icon = CreateFrame("Frame", "GladdyDr" .. unit .. "Icon" .. i, drFrame) + icon.drFrame = drFrame icon:Hide() icon:EnableMouse(false) icon:SetFrameStrata(Gladdy.db.drFrameStrata) @@ -103,13 +104,11 @@ function Diminishings:CreateFrame(unit) icon.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask") icon.texture:SetAllPoints(icon) icon:SetScript("OnUpdate", function(self, elapsed) - if (self.active) then + if (self.running) then if (self.timeLeft <= 0) then - if (self.factor == drFrame.tracked[self.dr]) then - drFrame.tracked[self.dr] = 0 - end - + self.drFrame.tracked[self.dr] = nil self.active = false + self.running = false self.dr = nil self.diminishing = 1.0 self.texture:SetTexture("") @@ -303,6 +302,7 @@ function Diminishings:ResetUnit(unit) for i = 1, 16 do local icon = drFrame["icon" .. i] icon.active = false + icon.running = false icon.timeLeft = 0 icon.texture:SetTexture("") icon.timeText:SetText("") @@ -341,12 +341,123 @@ function Diminishings:Test(unit) amount = rand(1,3) index = rand(1, #enabledCategories[i].spellIDs) for _=1, amount do + self:AuraGain(unit, enabledCategories[i].spellIDs[index]) self:AuraFade(unit, enabledCategories[i].spellIDs[index]) end end end end +--[[ testcases for show icon with icon.active = true and icon.running = false and no cooldown. Only when AuraFade start set icon.running = true and start cooldown + SPELL_AURA_APPLIED + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 2637) + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) a:AuraGain("arena1", 2637) + expected: stale icon AND 1/2 dr + SPELL_AURA_REMOVED + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraFade("arena1", 10890) + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraFade("arena1", 2637) + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraFade("arena1", 2637) a:AuraFade("arena1", 10890) + expected: icon 1/2 AND 1/2 dr + SPELL_AURA_REFRESH + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) a:AuraGain("arena1", 10890) + expected: icon 1/4 AND 1/4 dr + two different spells with same DR applied and one fades + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) a:AuraGain("arena1", 2094) a:AuraFade("arena1", 10890) + expected: icon 1/4 AND 1/4 dr + two different spells with same DR applied and both fade + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) a:AuraGain("arena1", 2094) a:AuraFade("arena1", 10890) a:AuraFade("arena1", 2094) + expected: icon 1/4 AND 1/4 dr + three different spells with same DR applied and two fade + Script: /run local a=LibStub("Gladdy").modules["Diminishings"] a:AuraGain("arena1", 10890) a:AuraGain("arena1", 2094) a:AuraGain("arena1", 5484) a:AuraFade("arena1", 10890) a:AuraFade("arena1", 2094) + expected: icon 0 AND 0 dr +--]] + +function Diminishings:FindLastIcon(unit, drCat) + local drFrame = self.frames[unit] + if (not drFrame or not drCat) then + return + end + if not Gladdy.db.drCategories[drCat].enabled then + return + end + local lastIcon + for i = 1, 16 do + local icon = drFrame["icon" .. i] + if ((icon.active) and icon.dr and icon.dr == drCat) then + lastIcon = icon + break + elseif not icon.active and not lastIcon then + lastIcon = icon + end + end + return lastIcon +end + +function Diminishings:PrepareIcon(unit, lastIcon, drCat, spellID) + local drFrame = self.frames[unit] + + lastIcon.dr = drCat + lastIcon.diminishing = drFrame.tracked[drCat] + if Gladdy.db.drBorderColorsEnabled then + lastIcon.border:SetVertexColor(getDiminishColor(lastIcon.diminishing)) + else + lastIcon.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.drBorderColor)) + end + + if Gladdy.db.drCategories[drCat].forceIcon then + lastIcon.texture:SetTexture(Gladdy.db.drCategories[drCat].icon) + else + lastIcon.texture:SetTexture(select(3, GetSpellInfo(spellID))) + end + + if Gladdy.db.drFontColorsEnabled then + lastIcon.timeText:SetTextColor(getDiminishColor(lastIcon.diminishing)) + else + lastIcon.timeText:SetTextColor(Gladdy:SetColor(Gladdy.db.drFontColor)) + end + lastIcon.drLevelText:SetText("") + if Gladdy.db.drLevelTextColorsEnabled then + lastIcon.drLevelText:SetTextColor(getDiminishColor(lastIcon.diminishing)) + else + lastIcon.drLevelText:SetTextColor(Gladdy:SetColor(Gladdy.db.drLevelTextColor)) + end + lastIcon.drLevelText:SetText(getDiminishText(lastIcon.diminishing)) + lastIcon.active = true + self:Positionate(unit) + lastIcon:Show() +end + +function Diminishings:AuraGain(unit, spellID) + local drFrame = self.frames[unit] + local drCat = DRData:GetSpellCategory(spellID) + if (not drFrame or not drCat) then + return + end + if not Gladdy.db.drCategories[drCat].enabled then + return + end + + -- due to dynamic DR we reset the DR here if dr == 0 + if not drFrame.tracked[drCat] or drFrame.tracked[drCat] == 0 then + drFrame.tracked[drCat] = DRData:NextDR(1) + else + drFrame.tracked[drCat] = DRData:NextDR(drFrame.tracked[drCat] == 1.0 and 1 or drFrame.tracked[drCat] == 0.5 and 2 or 3) + end + + -- add icon with no timer + local lastIcon = Diminishings:FindLastIcon(unit, drCat) + if not lastIcon then return end + + Diminishings:PrepareIcon(unit, lastIcon, drCat, spellID) + + + lastIcon.running = false + lastIcon.cooldown:Hide() + lastIcon.cooldown:SetCooldown(0, 0) + lastIcon.timeText:SetText("") +end + function Diminishings:AuraFade(unit, spellID) local drFrame = self.frames[unit] local drCat = DRData:GetSpellCategory(spellID) @@ -357,49 +468,16 @@ function Diminishings:AuraFade(unit, spellID) return end - local lastIcon - for i = 1, 16 do - local icon = drFrame["icon" .. i] - if (icon.active and icon.dr and icon.dr == drCat) then - lastIcon = icon - break - elseif not icon.active and not lastIcon then - lastIcon = icon - lastIcon.diminishing = 1.0 - end - end + -- find icon and start timer + local lastIcon = Diminishings:FindLastIcon(unit, drCat) if not lastIcon then return end - lastIcon.dr = drCat + + Diminishings:PrepareIcon(unit, lastIcon, drCat, spellID) + lastIcon.timeLeft = Gladdy.db.drDuration - lastIcon.diminishing = DRData:NextDR(lastIcon.diminishing) - if Gladdy.db.drBorderColorsEnabled then - lastIcon.border:SetVertexColor(getDiminishColor(lastIcon.diminishing)) - else - lastIcon.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.drBorderColor)) - end + lastIcon.cooldown:Show() lastIcon.cooldown:SetCooldown(GetTime(), Gladdy.db.drDuration) - if Gladdy.db.drCategories[drCat].forceIcon then - lastIcon.texture:SetTexture(Gladdy.db.drCategories[drCat].icon) - else - lastIcon.texture:SetTexture(select(3, GetSpellInfo(spellID))) - end - - if Gladdy.db.drFontColorsEnabled then - lastIcon.timeText:SetTextColor(getDiminishColor(lastIcon.diminishing)) - else - lastIcon.timeText:SetTextColor(Gladdy:SetColor(Gladdy.db.drFontColor)) - end - - lastIcon.drLevelText:SetText(getDiminishText(lastIcon.diminishing)) - if Gladdy.db.drLevelTextColorsEnabled then - lastIcon.drLevelText:SetTextColor(getDiminishColor(lastIcon.diminishing)) - else - lastIcon.drLevelText:SetTextColor(Gladdy:SetColor(Gladdy.db.drLevelTextColor)) - end - - lastIcon.active = true - self:Positionate(unit) - lastIcon:Show() + lastIcon.running = true end function Diminishings:Positionate(unit)