Quantcast

Fixed for Death Knights

p3lim-52096 [11-23-08 - 18:28]
Fixed for Death Knights
Removed useless code

git-svn-id: svn://svn.wowinterface.com/oUF_BarFader-229/trunk@11 cbe42a47-3b53-4817-a5a9-47e79666164c
Filename
oUF_BarFader/oUF_BarFader.lua
diff --git a/oUF_BarFader/oUF_BarFader.lua b/oUF_BarFader/oUF_BarFader.lua
index 492765a..4640658 100644
--- a/oUF_BarFader/oUF_BarFader.lua
+++ b/oUF_BarFader/oUF_BarFader.lua
@@ -6,100 +6,49 @@
 	 - BarFadeMaxAlpha [value] default: 1

 --]]
-local function UpdateElement(self, unit)
-	if(unit == 'player' and self.BarFade) then
-		local _, class = UnitClass('player')
-		local notFull = (UnitHealth('player') ~= UnitHealthMax('player')) or
-			(UnitPowerType('player') ~= 1 and UnitMana('player') ~= UnitManaMax('player')) or
-			(UnitPowerType('player') == 1 and UnitMana('player') > 0)
-
-		if(notFull) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitAffectingCombat('player')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitExists('target')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(self.Castbar) then
-			self:SetAlpha(self.Castbar.casting and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
+local function NotFull(unit)
+	if(UnitHealth(unit) ~= UnitHealthMax(unit)) then
+		return true
+	else
+		if(UnitPowerType(unit) == 6 or UnitPowerType(unit) == 1) then
+			if(UnitMana(unit) > 0) then
+				return true
+			else
+				return false
+			end
 		else
-			self:SetAlpha(self.BarFadeMinAlpha or 0.25)
+			if(UnitMana(unit) ~= UnitManaMax(unit)) then
+				return true
+			else
+				return false
+			end
 		end
 	end
-	if(unit == 'pet' and self.BarFade) then
-		local happiness = GetPetHappiness()
-		local notFull = (UnitHealth('pet') ~= UnitHealthMax('pet')) or
-			(UnitMana('pet') ~= UnitManaMax('pet'))
-
-		if(notFull) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitAffectingCombat('pet')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitExists('pettarget')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(self.Castbar) then
-			self:SetAlpha(self.Castbar.casting and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
-		elseif(happiness) then
-			self:SetAlpha((happiness < 3) and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
-		else
-			self:SetAlpha(self.BarFadeMinAlpha or 0.25)
-		end
-	end
-	if(unit == 'focus' and self.BarFade) then
-		local notFull = (UnitHealth('focus') ~= UnitHealthMax('focus')) or
-			(UnitPowerType('focus') ~= 1 and UnitMana('focus') ~= UnitManaMax('focus')) or
-			(UnitPowerType('focus') == 1 and UnitMana('focus') > 0)
-
-		if(notFull) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitAffectingCombat('focus')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitExists('focustarget')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(self.Castbar) then
-			self:SetAlpha(self.Castbar.casting and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
-		else
-			self:SetAlpha(self.BarFadeMinAlpha or 0.25)
-		end
-	end
-	if(unit == 'focustarget' and self.BarFade) then
-		local notFull = (UnitHealth('focustarget') ~= UnitHealthMax('focustarget')) or
-			(UnitPowerType('focustarget') ~= 1 and UnitMana('focustarget') ~= UnitManaMax('focustarget')) or
-			(UnitPowerType('focustarget') == 1 and UnitMana('focustarget') > 0)
+end

-		if(notFull) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitAffectingCombat('focustarget')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitExists('focustargettarget')) then
-			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(self.Castbar) then
-			self:SetAlpha(self.Castbar.casting and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
-		else
-			self:SetAlpha(self.BarFadeMinAlpha or 0.25)
-		end
-	end
-	if(unit == 'targettarget' and self.BarFade) then
-		local notFull = (UnitHealth('targettarget') ~= UnitHealthMax('targettarget')) or
-			(UnitPowerType('targettarget') ~= 1 and UnitMana('targettarget') ~= UnitManaMax('targettarget')) or
-			(UnitPowerType('targettarget') == 1 and UnitMana('targettarget') > 0)
+local function UpdateElement(self)
+	if(self.unit == 'player' or self.unit == 'pet' or self.unit == 'focus' or self.unit == 'focustarget' or self.unit == 'targettarget') then
+		if(not self.BarFade) then return end

-		if(notFull) then
+		if(NotFull(self.unit)) then
 			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitAffectingCombat('targettarget')) then
+		elseif(UnitAffectingCombat(self.unit)) then
 			self:SetAlpha(self.BarFadeMaxAlpha or 1)
-		elseif(UnitExists('targettargettarget')) then
+		elseif(UnitExists(self.unit..'target')) then
 			self:SetAlpha(self.BarFadeMaxAlpha or 1)
 		elseif(self.Castbar) then
 			self:SetAlpha(self.Castbar.casting and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
+		elseif(self.unit == 'pet' and GetPetHappiness()) then
+			self:SetAlpha((GetPetHappiness() < 3) and (self.BarFadeMaxAlpha or 1) or (self.BarFadeMinAlpha or 0.25))
 		else
 			self:SetAlpha(self.BarFadeMinAlpha or 0.25)
 		end
 	end
 end

-oUF:RegisterInitCallback(function(self)
+oUF:RegisterInitCallback(function(obj)
 	local addon = CreateFrame('Frame')
-	addon:SetScript('OnEvent', function() UpdateElement(self, self.unit) end)
+	addon:SetScript('OnEvent', function() UpdateElement(obj) end)
 	addon:RegisterEvent('PLAYER_LOGIN')
 	addon:RegisterEvent('PLAYER_REGEN_ENABLED')
 	addon:RegisterEvent('PLAYER_REGEN_DISABLED')
@@ -112,6 +61,7 @@ oUF:RegisterInitCallback(function(self)
 	addon:RegisterEvent('UNIT_FOCUS')
 	addon:RegisterEvent('UNIT_RAGE')
 	addon:RegisterEvent('UNIT_RUNIC_POWER')
+	addon:RegisterEvent('UNIT_POWER')
 	addon:RegisterEvent('UNIT_TARGET')
 	addon:RegisterEvent('UNIT_SPELLCAST_START')
 	addon:RegisterEvent('UNIT_SPELLCAST_STOP')