From d938cbeaf6c354d4b462e10848a25a9aec97ab14 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Fri, 2 Mar 2012 11:12:55 +0100 Subject: [PATCH] Update and fix everything for oUF 1.5.x --- oUF_Fader.lua | 171 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 69 deletions(-) diff --git a/oUF_Fader.lua b/oUF_Fader.lua index afa0d34..010884a 100644 --- a/oUF_Fader.lua +++ b/oUF_Fader.lua @@ -1,89 +1,122 @@ ---[[ +local _, ns = ... +local oUF = ns.oUF or oUF +assert(oUF, 'oUF Fader was unable to locate oUF install') - Shared: - - BarFade [boolean] - - BarFadeMinAlpha [value] default: 0.25 - - BarFadeMaxAlpha [value] default: 1 +local function Update(self) + local unit = self.unit ---]] + local _, powerType = UnitPowerType(unit) + local power = UnitPower(unit) -local function pending(self, unit) - local num, str = UnitPowerType(unit) - if(self.Castbar and (self.Castbar.casting or self.Castbar.channeling)) then return true end - if(UnitAffectingCombat(unit)) then return true end - if(unit == 'pet' and GetPetHappiness() and GetPetHappiness() < 3) then return true end - if(UnitExists(unit..'target')) then return true end - if(UnitHealth(unit) < UnitHealthMax(unit)) then return true end - if((str == 'RAGE' or str == 'RUNIC_POWER') and UnitPower(unit) > 0) then return true end - if((str ~= 'RAGE' and str ~= 'RUNIC_POWER') and UnitMana(unit) < UnitManaMax(unit)) then return true end -end - -local function update(self, event, unit) - if(unit and unit ~= self.unit) then return end - - if(not pending(self, self.unit)) then - self:SetAlpha(self.BarFaderMinAlpha or 0.25) + if + (self.FadeCasting and (UnitCastingInfo(unit) or UnitChannelInfo(unit))) or + (self.FadeCombat and UnitAffectingCombat(unit)) or + (self.FadeTarget and (unit:find('target') and UnitExists(unit))) or + (self.FadeTarget and UnitExists(unit .. 'target')) or + (self.FadeHealth and UnitHealth(unit) < UnitHealthMax(unit)) or + (self.FadePower and ((powerType == 'RAGE' or powerType == 'RUNIC_POWER') and power > 0)) or + (self.FadePower and ((powerType ~= 'RAGE' and powerType ~= 'RUNIC_POWER') and power < UnitPowerMax(unit))) or + (self.FadeHover and GetMouseFocus() == self) + then + if(self.FadeSmooth) then + UIFrameFadeIn(self, self.FadeSmooth, self:GetAlpha(), self.FadeMaxAlpha or 1) + else + self:SetAlpha(self.FadeMaxAlpha or 1) + end else - self:SetAlpha(self.BarFaderMaxAlpha or 1) + if(self.FadeSmooth) then + UIFrameFadeOut(self, self.FadeSmooth, self:GetAlpha(), self.FadeMinAlpha or 0.3) + else + self:SetAlpha(self.FadeMinAlpha or 0.3) + end end end -local function enable(self, unit) - if(unit and self.BarFade) then - update(self) +local function ForceUpdate(element) + return Update(element.__owner) +end - self:RegisterEvent('UNIT_COMBAT', update) - self:RegisterEvent('UNIT_HAPPINESS', update) - self:RegisterEvent('UNIT_TARGET', update) - self:RegisterEvent('UNIT_FOCUS', update) - self:RegisterEvent('UNIT_HEALTH', update) - self:RegisterEvent('UNIT_POWER', update) - self:RegisterEvent('UNIT_ENERGY', update) - self:RegisterEvent('UNIT_RAGE', update) - self:RegisterEvent('UNIT_MANA', update) - self:RegisterEvent('UNIT_RUNIC_POWER', update) +local function Enable(self, unit) + if + unit == 'player' or + unit == 'target' or + unit == 'targettarget' or + unit == 'focus' or + unit == 'pet' + then + if(self.FadeHover) then + self:HookScript('OnEnter', Update) + self:HookScript('OnLeave', Update) + end + if(self.FadeCombat) then + self:RegisterEvent('PLAYER_REGEN_ENABLED', Update) + self:RegisterEvent('PLAYER_REGEN_DISABLED', Update) + end + if(self.FadeTarget) then + self:HookScript('OnShow', Update) + self:RegisterEvent('UNIT_TARGET', Update) + self:RegisterEvent('PLAYER_TARGET_CHANGED', Update) + end + if(self.FadeHealth) then + self:RegisterEvent('UNIT_HEALTH', Update) + self:RegisterEvent('UNIT_HEALTHMAX', Update) + end + if(self.FadePower) then + self:RegisterEvent('UNIT_POWER', Update) + self:RegisterEvent('UNIT_POWERMAX', Update) + end - if(self.Castbar) then - self:RegisterEvent('UNIT_SPELLCAST_START', update) - self:RegisterEvent('UNIT_SPELLCAST_FAILED', update) - self:RegisterEvent('UNIT_SPELLCAST_STOP', update) - self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED', update) - self:RegisterEvent('UNIT_SPELLCAST_DELAYED', update) - self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START', update) - self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', update) - self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_INTERRUPTED', update) - self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', update) + if(self.FadeCasting) then + self:RegisterEvent('UNIT_SPELLCAST_START', Update) + self:RegisterEvent('UNIT_SPELLCAST_FAILED', Update) + self:RegisterEvent('UNIT_SPELLCAST_STOP', Update) + self:RegisterEvent('UNIT_SPELLCAST_INTERRUPTED', Update) + self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_START', Update) + self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_INTERRUPTED', Update) + self:RegisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', Update) end + Update(self) + return true end end -local function disable(self) - if(self.BarFade) then - self:UnregisterEvent('UNIT_COMBAT', update) - self:UnregisterEvent('UNIT_HAPPINESS', update) - self:UnregisterEvent('UNIT_TARGET', update) - self:UnregisterEvent('UNIT_FOCUS', update) - self:UnregisterEvent('UNIT_HEALTH', update) - self:UnregisterEvent('UNIT_POWER', update) - self:UnregisterEvent('UNIT_ENERGY', update) - self:UnregisterEvent('UNIT_RAGE', update) - self:UnregisterEvent('UNIT_MANA', update) - self:UnregisterEvent('UNIT_RUNIC_POWER', update) +local function Disable(self, unit) + if + unit == 'player' or + unit == 'target' or + unit == 'targettarget' or + unit == 'focus' or + unit == 'pet' + then + if(self.FadeCombat) then + self:UnregisterEvent('PLAYER_REGEN_ENABLED', Update) + self:UnregisterEvent('PLAYER_REGEN_DISABLED', Update) + end + if(self.FadeTarget) then + self:UnregisterEvent('UNIT_TARGET', Update) + self:UnregisterEvent('PLAYER_TARGET_CHANGED', Update) + end + if(self.FadeHealth) then + self:UnregisterEvent('UNIT_HEALTH', Update) + self:UnregisterEvent('UNIT_HEALTHMAX', Update) + end + if(self.FadePower) then + self:UnregisterEvent('UNIT_POWER', Update) + self:UnregisterEvent('UNIT_POWERMAX', Update) + end - if(self.Castbar) then - self:UnregisterEvent('UNIT_SPELLCAST_START', update) - self:UnregisterEvent('UNIT_SPELLCAST_FAILED', update) - self:UnregisterEvent('UNIT_SPELLCAST_STOP', update) - self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTED', update) - self:UnregisterEvent('UNIT_SPELLCAST_DELAYED', update) - self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_START', update) - self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_UPDATE', update) - self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_INTERRUPTED', update) - self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', update) + if(self.FadeCasting) then + self:UnregisterEvent('UNIT_SPELLCAST_START', Update) + self:UnregisterEvent('UNIT_SPELLCAST_FAILED', Update) + self:UnregisterEvent('UNIT_SPELLCAST_STOP', Update) + self:UnregisterEvent('UNIT_SPELLCAST_INTERRUPTED', Update) + self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_START', Update) + self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_INTERRUPTED', Update) + self:UnregisterEvent('UNIT_SPELLCAST_CHANNEL_STOP', Update) end end end -oUF:AddElement('BarFader', update, enable, disable) \ No newline at end of file +oUF:AddElement('Fader', Path, Enable, Disable) -- 1.7.9.5