Implement fade and flash behavior for square indicators

This commit is contained in:
2023-07-28 14:15:50 +02:00
parent 877560cb58
commit e20887d46b
4 changed files with 298 additions and 124 deletions

View File

@@ -1,7 +1,7 @@
-- Copyright 2023 <omicron.me@protonmail.com>
--
-- This file is part of Omicron Frames
--
--
-- Omicron Frames is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option)
@@ -13,7 +13,7 @@
-- more details.
--
-- You should have received a copy of the GNU General Public License along with
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
local omi = select(2, ...)
local types = omi.GetModule("types")
@@ -45,7 +45,9 @@ end
---@param y number
---@param color number[]
---@param showStacks boolean
function SquareIndicator:Init(unitframe, size, point, x, y, color, showStacks)
---@param doFade nil|number
---@param doFlash nil|number
function SquareIndicator:Init(unitframe, size, point, x, y, color, showStacks, fadeTime, flashTime)
self.unitframe = unitframe
self.frameParent = unitframe.overlays
self.size = size
@@ -54,6 +56,8 @@ function SquareIndicator:Init(unitframe, size, point, x, y, color, showStacks)
self.y = y
self.color = color
self.showStacks = showStacks
self.fadeTime = fadeTime
self.flashTime = flashTime
end
--- Set the color of the Square Indicator
@@ -61,7 +65,7 @@ end
function SquareIndicator:SetColor(color)
self.color = color
local frame = self.frame
if frame then
if frame then
frame:SetBackdropColor(unpack(color))
end
end
@@ -77,6 +81,13 @@ function SquareIndicator:Show(data)
stacks:SetText(numStacks)
stacks:Show()
end
if self.flashTime or self.fadeTime then
self.frame:SetScript("OnUpdate", function(frame, dt)
self:OnUpdate(dt)
end)
self.expirationTime = data.expirationTime
self.updateThrottle = 0
end
if data.color then
self:SetColor(data.color)
else
@@ -93,7 +104,7 @@ function SquareIndicator:GetFrame()
bgFile = "Interface\\Addons\\OmicronFrames\\media\\textures\\square_white",
edgeFile = "Interface\\Addons\\OmicronFrames\\media\\textures\\pixel_edge",
edgeSize = 2,
insets = {left=0, right=0, top=0, bottom=0},
insets = { left = 0, right = 0, top = 0, bottom = 0 },
}
frame:ApplyBackdrop()
@@ -108,6 +119,7 @@ function SquareIndicator:GetFrame()
frame:SetParent(self.frameParent)
frame:SetPoint(self.point, self.x, self.y)
frame:SetBackdropBorderColor(0, 0, 0, 1)
frame:SetAlpha(1)
stacks = frame.stacks
return frame, stacks
end
@@ -122,6 +134,30 @@ function SquareIndicator:Update(data)
self.stacks:SetText(numStacks)
self.stacks:Show()
end
self.expirationTime = data.expirationTime
self.frame:SetAlpha(1)
end
function SquareIndicator:OnUpdate(dt)
dt = self.updateThrottle + dt
if dt < 0.04 then
self.updateThrottle = dt
return
else
self.updateThrottle = 0
end
local timeLeft = self.expirationTime - GetTime()
local fadeTime = self.fadeTime or 0
local flashTime = self.flashTime or 0
if timeLeft < flashTime then
local alpha = ((timeLeft * 4) % 1)
self.frame:SetAlpha(alpha)
elseif timeLeft < fadeTime then
local alpha = timeLeft / fadeTime
self.frame:SetAlpha(alpha)
end
end
--- Hide the square indicator.
@@ -130,5 +166,6 @@ function SquareIndicator:Hide()
self.stacks:Hide()
self.frame = nil
self.stacks = nil
frame:SetScript("OnUpdate", nil)
squarePool:Release(frame)
end

View File

@@ -1,7 +1,7 @@
-- Copyright 2023 <omicron.me@protonmail.com>
--
-- This file is part of Omicron Frames
--
--
-- Omicron Frames is free software: you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the Free
-- Software Foundation, either version 3 of the License, or (at your option)
@@ -13,7 +13,7 @@
-- more details.
--
-- You should have received a copy of the GNU General Public License along with
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
-- Omicron Frames. If not, see <https://www.gnu.org/licenses/>.
local omi = select(2, ...)
local types = omi.GetModule("types")
---@class Trigger
@@ -92,7 +92,7 @@ function AuraTrigger:AddAura(aura)
return
end
self.count = self.count + 1
self:SetData({stacks=aura.applications})
self:SetData({ stacks = aura.applications, duration = aura.duration, expirationTime = aura.expirationTime })
self:SetState(self.count >= self.requiredCount, false)
end
@@ -100,7 +100,7 @@ end
---@param before UnitAuraInfo
---@param after UnitAuraInfo
function AuraTrigger:UpdateAura(before, after)
self:SetData({stacks=after.applications})
self:SetData({ stacks = after.applications, duration = after.duration, expirationTime = after.expirationTime })
if self.active then
self.indicator:Update(self.data)
end

View File

@@ -125,7 +125,9 @@ function UnitFrame:CreateIndicator(indicator)
indicator.x,
indicator.y,
indicator.color,
indicator.showStacks
indicator.showStacks,
indicator.fadeTime,
indicator.flashTime
)
elseif kind == "BorderIndicator" then
return BorderIndicator:new(