From 7d37890a318378bfe659f8b938036407f01a7dc7 Mon Sep 17 00:00:00 2001 From: Parnic Date: Thu, 16 Apr 2009 13:39:37 +0000 Subject: [PATCH] - added some protection against error messages that were popping up related to SetTexCoord - added some protection against a nil access in the player's cast bar under certain circumstances --- IceBarElement.lua | 2 ++ IceCastBar.lua | 13 ++++++++----- IceHUD.lua | 10 ++++++++++ modules/CastBar.lua | 6 +++--- modules/PlayerHealth.lua | 2 ++ modules/SliceAndDice.lua | 2 +- modules/Threat.lua | 2 +- 7 files changed, 27 insertions(+), 10 deletions(-) diff --git a/IceBarElement.lua b/IceBarElement.lua index 3078b84..78cd6e2 100644 --- a/IceBarElement.lua +++ b/IceBarElement.lua @@ -695,6 +695,8 @@ end function IceBarElement.prototype:SetScale(texture, scale) local oldScale = self.CurrScale + scale = IceHUD:Clamp(scale, 0, 1) + self.CurrScale = self:LerpScale(scale) if oldScale ~= self.CurrScale then diff --git a/IceCastBar.lua b/IceCastBar.lua index 0ce773e..bd5d770 100644 --- a/IceCastBar.lua +++ b/IceCastBar.lua @@ -207,15 +207,18 @@ end function IceCastBar.prototype:StartBar(action, message) - self.action = action - self.actionStartTime = GetTime() - self.actionMessage = message - local spell, rank, displayName, icon, startTime, endTime, isTradeSkill = UnitCastingInfo(self.unit) if not (spell) then spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(self.unit) end - + + if not spell then + return + end + + self.action = action + self.actionStartTime = GetTime() + self.actionMessage = message if (startTime and endTime) then self.actionDuration = (endTime - startTime) / 1000 diff --git a/IceHUD.lua b/IceHUD.lua index 986d8b4..dd44542 100644 --- a/IceHUD.lua +++ b/IceHUD.lua @@ -805,3 +805,13 @@ function IceHUD:OnProfileEnable(oldName, oldData) self.IceCore:SetModuleDatabases() self.IceCore:Enable() end + +function IceHUD:Clamp(value, min, max) + if value < min then + value = min + elseif value > max then + value = max + end + + return value +end diff --git a/modules/CastBar.lua b/modules/CastBar.lua index 7fdedd8..5365a40 100644 --- a/modules/CastBar.lua +++ b/modules/CastBar.lua @@ -380,7 +380,7 @@ function CastBar.prototype:SpellCastStart(unit, spell, rank) local lag = GetTime() - (self.spellCastSent or 0) - local pos = lag / self.actionDuration + local pos = IceHUD:Clamp(lag / self.actionDuration, 0, 1) local y = self.settings.barHeight - (pos * self.settings.barHeight) if (self.moduleSettings.side == IceCore.Side.Left) then @@ -400,9 +400,9 @@ function CastBar.prototype:SpellCastChannelStart(unit) local lag = GetTime() - (self.spellCastSent or 0) - local pos = lag / self.actionDuration + local pos = IceHUD:Clamp(lag / self.actionDuration, 0, 1) local y = self.settings.barHeight - (pos * self.settings.barHeight) - + if (self.moduleSettings.side == IceCore.Side.Left) then self.lagBar.bar:SetTexCoord(1, 0, 1-pos, 1) else diff --git a/modules/PlayerHealth.lua b/modules/PlayerHealth.lua index 2c719d9..2fee53f 100644 --- a/modules/PlayerHealth.lua +++ b/modules/PlayerHealth.lua @@ -903,6 +903,8 @@ function PlayerHealth.prototype:Update(unit) barValue = 1 end + barValue = IceHUD:Clamp(barValue, 0, 1) + if (self.moduleSettings.side == IceCore.Side.Left) then self.healFrame.bar:SetTexCoord(1, 0, barValue, 1) else diff --git a/modules/SliceAndDice.lua b/modules/SliceAndDice.lua index 981b354..d1b9842 100644 --- a/modules/SliceAndDice.lua +++ b/modules/SliceAndDice.lua @@ -275,7 +275,7 @@ function SliceAndDice.prototype:UpdateDurationBar(unit) PotentialSnDDuration = self:GetMaxBuffTime(points) -- compute the scale from the current number of combo points - scale = PotentialSnDDuration / CurrMaxSnDDuration + scale = IceHUD:Clamp(PotentialSnDDuration / CurrMaxSnDDuration, 0, 1) -- sadly, animation uses bar-local variables so we can't use the animation for 2 bar textures on the same bar element if (self.moduleSettings.side == IceCore.Side.Left) then diff --git a/modules/Threat.lua b/modules/Threat.lua index 6889470..88262ce 100644 --- a/modules/Threat.lua +++ b/modules/Threat.lua @@ -271,7 +271,7 @@ function IHUD_Threat.prototype:Update(unit) if ( self.aggroBarMulti ~= threatMulti ) then self.aggroBarMulti = threatMulti - local pos = 1 - (1 / threatMulti) + local pos = IceHUD:Clamp(1 - (1 / threatMulti), 0, 1) local y = self.settings.barHeight - ( pos * self.settings.barHeight ) if ( self.moduleSettings.side == IceCore.Side.Left ) then