From 338da1e8b65813ca78fae42707cc2b3fe009eeea Mon Sep 17 00:00:00 2001 From: p3lim-52096 Date: Sun, 21 Dec 2008 03:43:56 +0000 Subject: [PATCH] Rewrite to reflect changes in oUF git-svn-id: svn://svn.wowinterface.com/oUF_BarFader-229/trunk@13 cbe42a47-3b53-4817-a5a9-47e79666164c --- oUF_BarFader/oUF_BarFader.lua | 118 ++++++++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 43 deletions(-) diff --git a/oUF_BarFader/oUF_BarFader.lua b/oUF_BarFader/oUF_BarFader.lua index 50b8124..46c5074 100644 --- a/oUF_BarFader/oUF_BarFader.lua +++ b/oUF_BarFader/oUF_BarFader.lua @@ -6,65 +6,97 @@ - BarFadeMaxAlpha [value] default: 1 --]] -local function NotFull(unit) - if(UnitHealth(unit) ~= UnitHealthMax(unit)) then - return true +local function Regenerating(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 + if(UnitMana(unit) > 0) then return true end else - if(UnitMana(unit) ~= UnitManaMax(unit)) then - return true - else - return false - end + if(UnitMana(unit) ~= UnitManaMax(unit)) then return true end end end + + return false end -local function UpdateElement(self) +local function Update(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(self.unit)) then + if(self.Castbar.casting or self.Castbar.channeling) then self:SetAlpha(self.BarFadeMaxAlpha or 1) elseif(UnitAffectingCombat(self.unit)) then self:SetAlpha(self.BarFadeMaxAlpha or 1) - elseif(UnitExists(self.unit..'target')) then - self:SetAlpha(self.BarFadeMaxAlpha or 1) - elseif(self.Castbar) then - self:SetAlpha((self.Castbar.casting or self.Castbar.channeling) 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)) + elseif(UnitExists(self.unit..'target')) then + self:SetAlpha(self.BarFadeMaxAlpha or 1) + elseif(Regenerating(self.unit)) then + self:SetAlpha(self.BarFadeMaxAlpha or 1) else self:SetAlpha(self.BarFadeMinAlpha or 0.25) end end end -oUF:RegisterInitCallback(function(obj) - local addon = CreateFrame('Frame') - addon:SetScript('OnEvent', function() UpdateElement(obj) end) - addon:RegisterEvent('PLAYER_LOGIN') - addon:RegisterEvent('PLAYER_REGEN_ENABLED') - addon:RegisterEvent('PLAYER_REGEN_DISABLED') - addon:RegisterEvent('PLAYER_TARGET_CHANGED') - addon:RegisterEvent('PLAYER_FOCUS_CHANGED') - addon:RegisterEvent('UNIT_HAPPINESS') - addon:RegisterEvent('UNIT_HEALTH') - addon:RegisterEvent('UNIT_MANA') - addon:RegisterEvent('UNIT_ENERGY') - 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') - addon:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START') - addon:RegisterEvent('UNIT_SPELLCAST_CHANNEL_STOP') -end) \ No newline at end of file +local function Enable(self) + if(self.BarFade) then + self:RegisterEvent('PLAYER_LOGIN', Update) + self:RegisterEvent('PLAYER_REGEN_ENABLED', Update) + self:RegisterEvent('PLAYER_REGEN_DISABLED', Update) + self:RegisterEvent('PLAYER_TARGET_CHANGED', Update) + self:RegisterEvent('PLAYER_FOCUS_CHANGED', Update) + self:RegisterEvent('UNIT_HAPPINESS', Update) + self:RegisterEvent('UNIT_HEALTH', Update) + self:RegisterEvent('UNIT_MANA', Update) + self:RegisterEvent('UNIT_ENERGY', Update) + self:RegisterEvent('UNIT_FOCUS', Update) + self:RegisterEvent('UNIT_RAGE', Update) + self:RegisterEvent('UNIT_RUNIC_POWER', Update) + self:RegisterEvent('UNIT_POWER', Update) + self:RegisterEvent('UNIT_TARGET', Update) + + if(self.Castbar) then + self.PostCastStart = Update + self.PostCastFailed = Update + self.PostCastInterrupted = Update + self.PostCastDelayed = Update + self.PostCastStop = Update + self.PostChannelStart = Update + self.PostChannelUpdate = Update + self.PostChannelStop = Update + end + + return true + end +end + +local function Disable(self) + if(self.BarFade) then + self:UnregisterEvent('PLAYER_LOGIN', Update) + self:UnregisterEvent('PLAYER_REGEN_ENABLED', Update) + self:UnregisterEvent('PLAYER_REGEN_DISABLED', Update) + self:UnregisterEvent('PLAYER_TARGET_CHANGED', Update) + self:UnregisterEvent('PLAYER_FOCUS_CHANGED', Update) + self:UnregisterEvent('UNIT_HAPPINESS', Update) + self:UnregisterEvent('UNIT_HEALTH', Update) + self:UnregisterEvent('UNIT_MANA', Update) + self:UnregisterEvent('UNIT_ENERGY', Update) + self:UnregisterEvent('UNIT_FOCUS', Update) + self:UnregisterEvent('UNIT_RAGE', Update) + self:UnregisterEvent('UNIT_RUNIC_POWER', Update) + self:UnregisterEvent('UNIT_POWER', Update) + self:UnregisterEvent('UNIT_TARGET', Update) + + if(self.Castbar) then + self.PostCastStart = nil + self.PostCastFailed = nil + self.PostCastInterrupted = nil + self.PostCastDelayed = nil + self.PostCastStop = nil + self.PostChannelStart = nil + self.PostChannelUpdate = nil + self.PostChannelStop = nil + end + end +end + +oUF:AddElement('BarFader', Update, Enable, Disable) \ No newline at end of file -- 1.7.9.5