From b8c3e0cf1cec87fa4b2fdd225a45632e43d8046c Mon Sep 17 00:00:00 2001 From: Parnic Date: Thu, 7 Feb 2008 06:59:29 +0000 Subject: [PATCH] - added an option to animate the lost/gained amounts on each individual bar with a tweak-able speed --- IceBarElement.lua | 88 ++++++++++++++++++++++++++++++++++++++---- modules/CastBar.lua | 8 ++++ modules/TargetCast.lua | 15 +++++++ 3 files changed, 104 insertions(+), 7 deletions(-) diff --git a/IceBarElement.lua b/IceBarElement.lua index 7455360..fed6898 100644 --- a/IceBarElement.lua +++ b/IceBarElement.lua @@ -13,6 +13,11 @@ IceBarElement.prototype.backroundAlpha = nil IceBarElement.prototype.combat = nil IceBarElement.prototype.target = nil +IceBarElement.prototype.CurrLerpTime = 0 +IceBarElement.prototype.LastScale = 1 +IceBarElement.prototype.DesiredScale = 1 +IceBarElement.prototype.CurrScale = 1 + -- Constructor -- function IceBarElement.prototype:init(name) @@ -52,6 +57,8 @@ function IceBarElement.prototype:GetDefaultSettings() settings["lowerText"] = '' settings["textVerticalOffset"] = -1 settings["textHorizontalOffset"] = 0 + settings["shouldAnimate"] = false + settings["desiredLerpTime"] = 0.2 return settings end @@ -131,6 +138,41 @@ function IceBarElement.prototype:GetOptions() order = 32 } + opts["shouldAnimate"] = + { + type = 'toggle', + name = '|c' .. self.configColor .. 'Animate amount changes|r', + desc = 'Whether or not to animate the bar falloffs/gains', + get = function() + return self.moduleSettings.shouldAnimate + end, + set = function(value) + self.moduleSettings.shouldAnimate = value + self:Redraw() + end, + disabled = function() + return not self.moduleSettings.enabled + end + } + + opts["desiredLerpTime"] = + { + type = 'range', + name = '|c' .. self.configColor .. 'Animation Duration|r', + min = 0, + max = 2, + step = 0.05, + get = function() + return self.moduleSettings.desiredLerpTime + end, + set = function(value) + self.moduleSettings.desiredLerpTime = value + end, + disabled = function() + return not self.moduleSettings.enabled or not self.moduleSettings.shouldAnimate + end + } + opts["textSettings"] = { type = 'group', @@ -318,6 +360,7 @@ function IceBarElement.prototype:CreateFrame() self:CreateTexts() self.frame:SetScale(self.moduleSettings.scale) + self.frame:SetScript("OnUpdate", function() self:MyOnUpdate() end) end @@ -472,10 +515,33 @@ end function IceBarElement.prototype:SetScale(texture, scale) + self.CurrScale = self:LerpScale(scale) + if (self.moduleSettings.side == IceCore.Side.Left) then - texture:SetTexCoord(1, 0, 1-scale, 1) + texture:SetTexCoord(1, 0, 1-self.CurrScale, 1) else - texture:SetTexCoord(0, 1, 1-scale, 1) + texture:SetTexCoord(0, 1, 1-self.CurrScale, 1) + end +end + + +function IceBarElement.prototype:LerpScale(scale) + if not self.moduleSettings.shouldAnimate then + return scale + end + + if self.CurrLerpTime < self.moduleSettings.desiredLerpTime then + self.CurrLerpTime = self.CurrLerpTime + (1 / GetFramerate()); + end + + if self.CurrLerpTime > self.moduleSettings.desiredLerpTime then + self.CurrLerpTime = self.moduleSettings.desiredLerpTime + end + + if self.CurrLerpTime < self.moduleSettings.desiredLerpTime then + return self.LastScale + ((self.DesiredScale - self.LastScale) * (self.CurrLerpTime / self.moduleSettings.desiredLerpTime)) + else + return scale end end @@ -483,12 +549,12 @@ end function IceBarElement.prototype:UpdateBar(scale, color, alpha) alpha = alpha or 1 self.frame:SetAlpha(alpha) - + local r, g, b = self.settings.backgroundColor.r, self.settings.backgroundColor.g, self.settings.backgroundColor.b if (self.settings.backgroundToggle) then r, g, b = self:GetColor(color) end - + if (self.combat) then self.alpha = self.settings.alphaic self.backgroundAlpha = self.settings.alphaicbg @@ -502,8 +568,14 @@ function IceBarElement.prototype:UpdateBar(scale, color, alpha) self.frame:SetStatusBarColor(r, g, b, self.backgroundAlpha) self.barFrame:SetStatusBarColor(self:GetColor(color)) - - self:SetScale(self.barFrame.bar, scale) + + if self.DesiredScale ~= scale then + self.DesiredScale = scale + self.CurrLerpTime = 0 + self.LastScale = self.CurrScale + end + + self:SetScale(self.barFrame.bar, self.DesiredScale) end @@ -590,7 +662,9 @@ end function IceBarElement.prototype:Update() end - +function IceBarElement.prototype:MyOnUpdate() + self:SetScale(self.barFrame.bar, self.DesiredScale) +end -- Combat event handlers ------------------------------------------------------ diff --git a/modules/CastBar.lua b/modules/CastBar.lua index aaefa19..f48504b 100644 --- a/modules/CastBar.lua +++ b/modules/CastBar.lua @@ -110,6 +110,14 @@ function CastBar.prototype:GetOptions() order = 43 } + opts["shouldAnimate"] = + { + } + + opts["desiredLerpTime"] = + { + } + opts["textSettings"] = { type = 'group', diff --git a/modules/TargetCast.lua b/modules/TargetCast.lua index 3d70a30..1bd9246 100644 --- a/modules/TargetCast.lua +++ b/modules/TargetCast.lua @@ -52,6 +52,21 @@ function TargetCast.prototype:TargetChanged(unit) self:StopBar() end + +function TargetCast.prototype:GetOptions() + local opts = TargetCast.super.prototype.GetOptions(self) + + opts["shouldAnimate"] = + { + } + + opts["desiredLerpTime"] = + { + } + + return opts +end + -------------------------------------------------------------------------------