Optimized the bar animation code significantly.
This commit is contained in:
@@ -1013,35 +1013,36 @@ end
|
||||
-- Omen bar stuff
|
||||
|
||||
do
|
||||
-- OnUpdate function for bar animation
|
||||
-- OnUpdate function for bar animation, lasts 0.25 seconds
|
||||
local function animate(self, elapsed)
|
||||
self.animationCursor = self.animationCursor + elapsed
|
||||
if self.animationCursor > self.animationTime then
|
||||
self.texture:SetWidth(self.animations[1])
|
||||
tremove(self.animations, 1)
|
||||
tremove(self.animations, 1)
|
||||
tremove(self.animations, 1)
|
||||
self.animationCursor = self.animationCursor - self.animationTime
|
||||
if #self.animations == 0 then
|
||||
self:SetScript("OnUpdate", nil)
|
||||
end
|
||||
local t = self.animationCursor + elapsed
|
||||
local animData = self.animData
|
||||
if t >= 0.25 then
|
||||
self.texture:SetWidth(animData[1])
|
||||
animData[3] = nil
|
||||
animData[2] = nil
|
||||
animData[1] = nil
|
||||
t = 0
|
||||
self:SetScript("OnUpdate", nil)
|
||||
else
|
||||
self.texture:SetWidth(self.animations[2] + (self.animations[3] * (self.animationCursor / self.animationTime)))
|
||||
self.texture:SetWidth(animData[2] + animData[3] * t / 0.25)
|
||||
end
|
||||
self.animationCursor = t
|
||||
end
|
||||
|
||||
-- function to start/queue bar animations
|
||||
-- function to start bar animations
|
||||
local function AnimateTo(self, val)
|
||||
if val == 1/0 or val == -1/0 then return end
|
||||
if val == 0 then val = 1 end
|
||||
if #self.animations > 0 and self.animations[#self.animations-2] == val then
|
||||
return
|
||||
end
|
||||
if val == 1/0 or val == -1/0 then return end -- infinity, do nothing
|
||||
if val == 0 then val = 1 end -- at least 1 pixel width
|
||||
local animData = self.animData
|
||||
if animData[1] == val then return end -- there is already an animation to the target width
|
||||
local currentWidth = self.texture:GetWidth()
|
||||
local diff = (val - currentWidth)
|
||||
tinsert(self.animations, val)
|
||||
tinsert(self.animations, currentWidth)
|
||||
tinsert(self.animations, diff)
|
||||
--if currentWidth > self:GetWidth() then currentWidth = self:GetWidth() end
|
||||
if val == currentWidth then return end -- the current width is already the target width
|
||||
animData[1] = val
|
||||
animData[2] = currentWidth
|
||||
animData[3] = val - currentWidth
|
||||
self.animationCursor = 0
|
||||
self:SetScript("OnUpdate", animate)
|
||||
end
|
||||
|
||||
@@ -1101,9 +1102,8 @@ do
|
||||
color = db.Bar.InvertColors and db.Bar.FontColor or db.Bar.BarColor
|
||||
bar.texture:SetVertexColor(color.r, color.g, color.b, color.a)
|
||||
|
||||
bar.animations = {}
|
||||
bar.animData = {}
|
||||
bar.animationCursor = 0
|
||||
bar.animationTime = 0.25
|
||||
bar.AnimateTo = AnimateTo
|
||||
|
||||
if barID == 0 then
|
||||
|
||||
Reference in New Issue
Block a user