diminish track on SPELL_AURA_APPLIED

This commit is contained in:
Sumsebrum 2022-07-31 06:05:33 +02:00
parent b9f696675b
commit 7c2cd5092e

View File

@ -95,6 +95,7 @@ function Diminishings:CreateFrame(unit)
for i = 1, 16 do for i = 1, 16 do
local icon = CreateFrame("Frame", "GladdyDr" .. unit .. "Icon" .. i, drFrame) local icon = CreateFrame("Frame", "GladdyDr" .. unit .. "Icon" .. i, drFrame)
icon.drFrame = drFrame
icon:Hide() icon:Hide()
icon:EnableMouse(false) icon:EnableMouse(false)
icon:SetFrameStrata(Gladdy.db.drFrameStrata) icon:SetFrameStrata(Gladdy.db.drFrameStrata)
@ -103,13 +104,11 @@ function Diminishings:CreateFrame(unit)
icon.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask") icon.texture:SetMask("Interface\\AddOns\\Gladdy\\Images\\mask")
icon.texture:SetAllPoints(icon) icon.texture:SetAllPoints(icon)
icon:SetScript("OnUpdate", function(self, elapsed) icon:SetScript("OnUpdate", function(self, elapsed)
if (self.active) then if (self.running) then
if (self.timeLeft <= 0) then if (self.timeLeft <= 0) then
if (self.factor == drFrame.tracked[self.dr]) then self.drFrame.tracked[self.dr] = nil
drFrame.tracked[self.dr] = 0
end
self.active = false self.active = false
self.running = false
self.dr = nil self.dr = nil
self.diminishing = 1.0 self.diminishing = 1.0
self.texture:SetTexture("") self.texture:SetTexture("")
@ -303,6 +302,7 @@ function Diminishings:ResetUnit(unit)
for i = 1, 16 do for i = 1, 16 do
local icon = drFrame["icon" .. i] local icon = drFrame["icon" .. i]
icon.active = false icon.active = false
icon.running = false
icon.timeLeft = 0 icon.timeLeft = 0
icon.texture:SetTexture("") icon.texture:SetTexture("")
icon.timeText:SetText("") icon.timeText:SetText("")
@ -341,12 +341,123 @@ function Diminishings:Test(unit)
amount = rand(1,3) amount = rand(1,3)
index = rand(1, #enabledCategories[i].spellIDs) index = rand(1, #enabledCategories[i].spellIDs)
for _=1, amount do for _=1, amount do
self:AuraGain(unit, enabledCategories[i].spellIDs[index])
self:AuraFade(unit, enabledCategories[i].spellIDs[index]) self:AuraFade(unit, enabledCategories[i].spellIDs[index])
end end
end end
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) function Diminishings:AuraFade(unit, spellID)
local drFrame = self.frames[unit] local drFrame = self.frames[unit]
local drCat = DRData:GetSpellCategory(spellID) local drCat = DRData:GetSpellCategory(spellID)
@ -357,49 +468,16 @@ function Diminishings:AuraFade(unit, spellID)
return return
end end
local lastIcon -- find icon and start timer
for i = 1, 16 do local lastIcon = Diminishings:FindLastIcon(unit, drCat)
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
if not lastIcon then return end if not lastIcon then return end
lastIcon.dr = drCat
Diminishings:PrepareIcon(unit, lastIcon, drCat, spellID)
lastIcon.timeLeft = Gladdy.db.drDuration lastIcon.timeLeft = Gladdy.db.drDuration
lastIcon.diminishing = DRData:NextDR(lastIcon.diminishing) lastIcon.cooldown:Show()
if Gladdy.db.drBorderColorsEnabled then
lastIcon.border:SetVertexColor(getDiminishColor(lastIcon.diminishing))
else
lastIcon.border:SetVertexColor(Gladdy:SetColor(Gladdy.db.drBorderColor))
end
lastIcon.cooldown:SetCooldown(GetTime(), Gladdy.db.drDuration) lastIcon.cooldown:SetCooldown(GetTime(), Gladdy.db.drDuration)
if Gladdy.db.drCategories[drCat].forceIcon then lastIcon.running = true
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()
end end
function Diminishings:Positionate(unit) function Diminishings:Positionate(unit)