From 2806b5202625001cfe0953d5f4a4faa4920627e1 Mon Sep 17 00:00:00 2001 From: wardz Date: Wed, 11 Dec 2019 19:10:07 +0100 Subject: [PATCH] fix StaticPopup being tainted by UIFrameFade usage (#29) --- ClassicCastbars/ClassicCastbars.toc | 1 + ClassicCastbars/core/Frames.lua | 7 +- ClassicCastbars/core/UIFrameFade.lua | 134 +++++++++++++++++++++++++++ 3 files changed, 138 insertions(+), 4 deletions(-) create mode 100644 ClassicCastbars/core/UIFrameFade.lua diff --git a/ClassicCastbars/ClassicCastbars.toc b/ClassicCastbars/ClassicCastbars.toc index bfbf6ff..c590ffb 100644 --- a/ClassicCastbars/ClassicCastbars.toc +++ b/ClassicCastbars/ClassicCastbars.toc @@ -7,6 +7,7 @@ ## X-Curse-Project-ID: 322865 ## X-WoWI-ID: 24925 +core/UIFrameFade.lua core/PoolManager.lua core/AnchorManager.lua core/Data.lua diff --git a/ClassicCastbars/core/Frames.lua b/ClassicCastbars/core/Frames.lua index e1add8f..0a8eec8 100644 --- a/ClassicCastbars/core/Frames.lua +++ b/ClassicCastbars/core/Frames.lua @@ -11,8 +11,6 @@ local min = _G.math.min local max = _G.math.max local ceil = _G.math.ceil local UnitExists = _G.UnitExists -local UIFrameFadeOut = _G.UIFrameFadeOut -local UIFrameFadeRemoveFrame = _G.UIFrameFadeRemoveFrame function addon:GetCastbarFrame(unitID) -- PoolManager:DebugInfo() @@ -176,7 +174,7 @@ function addon:DisplayCastbar(castbar, unitID) if castbar.fadeInfo then -- need to remove frame if it's currently fading so alpha doesn't get changed after re-displaying castbar - UIFrameFadeRemoveFrame(castbar) + namespace:UIFrameFadeRemoveFrame(castbar) castbar.fadeInfo.finishedFunc = nil end @@ -254,7 +252,7 @@ function addon:HideCastbar(castbar, noFadeOut) end if castbar:GetAlpha() > 0 then - UIFrameFadeOut(castbar, cast and cast.isInterrupted and 1.5 or 0.2, 1, 0) + namespace:UIFrameFadeOut(castbar, cast and cast.isInterrupted and 1.5 or 0.2, 1, 0) end end @@ -300,6 +298,7 @@ function addon:SkinPlayerCastbar() CastingBarFrame.Flash:SetSize(db.width + 61, db.height + 51) CastingBarFrame.Flash:SetPoint("TOP", 0, 26) else + -- TODO: no longer works? CastingBarFrame.Flash:SetSize(0.01, 0.01) -- hide it using size, SetAlpha() or Hide() wont work without messing with blizz code end diff --git a/ClassicCastbars/core/UIFrameFade.lua b/ClassicCastbars/core/UIFrameFade.lua new file mode 100644 index 0000000..dbb12b7 --- /dev/null +++ b/ClassicCastbars/core/UIFrameFade.lua @@ -0,0 +1,134 @@ +local _, namespace = ... +local tinsert = _G.table.insert +local tremove = _G.table.remove + +--[[ + Copy paste of UIFrameFade from FrameXML/UIParent.lua. + Blizzard's version causes UI taint so this is a temp work around. (see issue #29) +]] + +local FADEFRAMES = {}; + +-- Frame fading and flashing -- + +local frameFadeManager = CreateFrame("FRAME"); + +-- Function that actually performs the alpha change +--[[ +Fading frame attribute listing +============================================================ +frame.timeToFade [Num] Time it takes to fade the frame in or out +frame.mode ["IN", "OUT"] Fade mode +frame.finishedFunc [func()] Function that is called when fading is finished +frame.finishedArg1 [ANYTHING] Argument to the finishedFunc +frame.finishedArg2 [ANYTHING] Argument to the finishedFunc +frame.finishedArg3 [ANYTHING] Argument to the finishedFunc +frame.finishedArg4 [ANYTHING] Argument to the finishedFunc +frame.fadeHoldTime [Num] Time to hold the faded state + ]] + + local function UIFrameFade_OnUpdate(self, elapsed) + local index = 1; + local frame, fadeInfo; + while FADEFRAMES[index] do + frame = FADEFRAMES[index]; + fadeInfo = FADEFRAMES[index].fadeInfo; + -- Reset the timer if there isn't one, this is just an internal counter + if ( not fadeInfo.fadeTimer ) then + fadeInfo.fadeTimer = 0; + end + fadeInfo.fadeTimer = fadeInfo.fadeTimer + elapsed; + + -- If the fadeTimer is less then the desired fade time then set the alpha otherwise hold the fade state, call the finished function, or just finish the fade + if ( fadeInfo.fadeTimer < fadeInfo.timeToFade ) then + if ( fadeInfo.mode == "IN" ) then + frame:SetAlpha((fadeInfo.fadeTimer / fadeInfo.timeToFade) * (fadeInfo.endAlpha - fadeInfo.startAlpha) + fadeInfo.startAlpha); + elseif ( fadeInfo.mode == "OUT" ) then + frame:SetAlpha(((fadeInfo.timeToFade - fadeInfo.fadeTimer) / fadeInfo.timeToFade) * (fadeInfo.startAlpha - fadeInfo.endAlpha) + fadeInfo.endAlpha); + end + else + frame:SetAlpha(fadeInfo.endAlpha); + -- If there is a fadeHoldTime then wait until its passed to continue on + if ( fadeInfo.fadeHoldTime and fadeInfo.fadeHoldTime > 0 ) then + fadeInfo.fadeHoldTime = fadeInfo.fadeHoldTime - elapsed; + else + -- Complete the fade and call the finished function if there is one + namespace:UIFrameFadeRemoveFrame(frame); + if ( fadeInfo.finishedFunc ) then + fadeInfo.finishedFunc(fadeInfo.finishedArg1, fadeInfo.finishedArg2, fadeInfo.finishedArg3, fadeInfo.finishedArg4); + fadeInfo.finishedFunc = nil; + end + end + end + + index = index + 1; + end + + if ( #FADEFRAMES == 0 ) then + self:SetScript("OnUpdate", nil); + end +end + +-- Generic fade function +function namespace:UIFrameFade(frame, fadeInfo) + if (not frame) then + return; + end + if ( not fadeInfo.mode ) then + fadeInfo.mode = "IN"; + end + --local alpha; + if ( fadeInfo.mode == "IN" ) then + if ( not fadeInfo.startAlpha ) then + fadeInfo.startAlpha = 0; + end + if ( not fadeInfo.endAlpha ) then + fadeInfo.endAlpha = 1.0; + end + --alpha = 0; + elseif ( fadeInfo.mode == "OUT" ) then + if ( not fadeInfo.startAlpha ) then + fadeInfo.startAlpha = 1.0; + end + if ( not fadeInfo.endAlpha ) then + fadeInfo.endAlpha = 0; + end + --alpha = 1.0; + end + frame:SetAlpha(fadeInfo.startAlpha); + + frame.fadeInfo = fadeInfo; + frame:Show(); + + local index = 1; + while FADEFRAMES[index] do + -- If frame is already set to fade then return + if ( FADEFRAMES[index] == frame ) then + return; + end + index = index + 1; + end + tinsert(FADEFRAMES, frame); + frameFadeManager:SetScript("OnUpdate", UIFrameFade_OnUpdate); +end + +-- Convenience function to do a simple fade out +function namespace:UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha) + local fadeInfo = {}; + fadeInfo.mode = "OUT"; + fadeInfo.timeToFade = timeToFade; + fadeInfo.startAlpha = startAlpha; + fadeInfo.endAlpha = endAlpha; + namespace:UIFrameFade(frame, fadeInfo); +end + +function namespace:UIFrameFadeRemoveFrame(frame) + local index = 1; + while FADEFRAMES[index] do + if ( frame == FADEFRAMES[index] ) then + tremove(FADEFRAMES, index); + else + index = index + 1; + end + end +end