Skip to content

Commit

Permalink
fix StaticPopup being tainted by UIFrameFade usage (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardz committed Dec 11, 2019
1 parent c4e7459 commit 2806b52
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 4 deletions.
1 change: 1 addition & 0 deletions ClassicCastbars/ClassicCastbars.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions ClassicCastbars/core/Frames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
134 changes: 134 additions & 0 deletions ClassicCastbars/core/UIFrameFade.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2806b52

Please sign in to comment.