WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   UIFrameFadeIn finishFunc? (https://www.wowinterface.com/forums/showthread.php?t=36264)

suicidalkatt 10-26-10 08:38 AM

UIFrameFadeIn finishFunc?
 
So can someone show me a working example of how to use UIFrameFadeIn with a function call at the end of the function?

From what the wiki is showing me I'm assuming it's something like this?

Code:

local f = CreateFrame("frame")
f.finishedFunc = function()
        --do things
end

UIFrameFadeIn(f, 3, 0, 1)


Duugu 10-26-10 10:51 AM

You're mixing up the UIFrameFade and UIFrameFadeIn functions.

finishedFunc is not an attribute of the frame object. Its a value within an additional fadeInfo table that is build inside the UIFrameFadeIn and UIFrameFadeOut functions or has to be passed as an argument with UIFrameFade.


Example for UIFrameFade:

Code:

function VoiceChatShineFadeIn()
        -- Fade in the shine and then fade it out with the ComboPointShineFadeOut function
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = 0.5;
        fadeInfo.finishedFunc = VoiceChatShineFadeOut;
        UIFrameFade(VoiceChatShine, fadeInfo);
end

function VoiceChatTalkers_FadeOut()
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = .35;
        fadeInfo.startAlpha = 1;
        fadeInfo.endAlpha = 0;
        fadeInfo.finishedFunc = function() if ( #VOICECHAT_TALKERS > 0 ) then return end VoiceChatTalkers.buttons[1].button:SetAttribute("name", nil); VoiceChatTalkers.buttons[1]:Hide() VoiceChatTalkersSpeaker:Show() end;
        UIFrameFade(VoiceChatTalkers, fadeInfo);
        VoiceChatTalkers.visible = 0;
end

The UIFrameFade, UIFrameFadeIn, and UIFrameFadeOut implementations to clarify this:

Code:

-- Generic fade function
function 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 in
function UIFrameFadeIn(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end

-- Convenience function to do a simple fade out
function UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end


suicidalkatt 10-26-10 01:48 PM

Quote:

Originally Posted by Duugu (Post 214263)
You're mixing up the UIFrameFade and UIFrameFadeIn functions.

finishedFunc is not an attribute of the frame object. Its a value within an additional fadeInfo table that is build inside the UIFrameFadeIn and UIFrameFadeOut functions or has to be passed as an argument with UIFrameFade.


Example for UIFrameFade:

Code:

function VoiceChatShineFadeIn()
        -- Fade in the shine and then fade it out with the ComboPointShineFadeOut function
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = 0.5;
        fadeInfo.finishedFunc = VoiceChatShineFadeOut;
        UIFrameFade(VoiceChatShine, fadeInfo);
end

function VoiceChatTalkers_FadeOut()
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = .35;
        fadeInfo.startAlpha = 1;
        fadeInfo.endAlpha = 0;
        fadeInfo.finishedFunc = function() if ( #VOICECHAT_TALKERS > 0 ) then return end VoiceChatTalkers.buttons[1].button:SetAttribute("name", nil); VoiceChatTalkers.buttons[1]:Hide() VoiceChatTalkersSpeaker:Show() end;
        UIFrameFade(VoiceChatTalkers, fadeInfo);
        VoiceChatTalkers.visible = 0;
end

The UIFrameFade, UIFrameFadeIn, and UIFrameFadeOut implementations to clarify this:

Code:

-- Generic fade function
function 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 in
function UIFrameFadeIn(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end

-- Convenience function to do a simple fade out
function UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end


I see, that makes more sense.

samishii23 10-28-10 08:42 PM

Quote:

Originally Posted by Duugu (Post 214263)
You're mixing up the UIFrameFade and UIFrameFadeIn functions.

finishedFunc is not an attribute of the frame object. Its a value within an additional fadeInfo table that is build inside the UIFrameFadeIn and UIFrameFadeOut functions or has to be passed as an argument with UIFrameFade.


Example for UIFrameFade:

Code:

function VoiceChatShineFadeIn()
        -- Fade in the shine and then fade it out with the ComboPointShineFadeOut function
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = 0.5;
        fadeInfo.finishedFunc = VoiceChatShineFadeOut;
        UIFrameFade(VoiceChatShine, fadeInfo);
end

function VoiceChatTalkers_FadeOut()
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = .35;
        fadeInfo.startAlpha = 1;
        fadeInfo.endAlpha = 0;
        fadeInfo.finishedFunc = function() if ( #VOICECHAT_TALKERS > 0 ) then return end VoiceChatTalkers.buttons[1].button:SetAttribute("name", nil); VoiceChatTalkers.buttons[1]:Hide() VoiceChatTalkersSpeaker:Show() end;
        UIFrameFade(VoiceChatTalkers, fadeInfo);
        VoiceChatTalkers.visible = 0;
end

The UIFrameFade, UIFrameFadeIn, and UIFrameFadeOut implementations to clarify this:

Code:

-- Generic fade function
function 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 in
function UIFrameFadeIn(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "IN";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end

-- Convenience function to do a simple fade out
function UIFrameFadeOut(frame, timeToFade, startAlpha, endAlpha)
        local fadeInfo = {};
        fadeInfo.mode = "OUT";
        fadeInfo.timeToFade = timeToFade;
        fadeInfo.startAlpha = startAlpha;
        fadeInfo.endAlpha = endAlpha;
        UIFrameFade(frame, fadeInfo);
end


Maybe I missed something... But whats the alpha variable used for?

Duugu 10-29-10 07:59 PM

Quote:

Originally Posted by samishii23 (Post 214943)
Maybe I missed something... But whats the alpha variable used for?

lol
Copied that snippet from the blizzard interface files.
Don't know. Must be magic. :D

samishii23 10-30-10 06:53 AM

Lol, yea, magic. Blizzard is full of that. :rolleyes:
I was just trying to combine all 3 of those functions into one since I want to be able to use it one day, and 3 functions that looked redundant.

Code:

function FrameFade(frame, mode, dur) -- Possible Params ( StartingAlpha, and EndingAlpha )
        -- If frame is nil false or otherwise. stop
        if ( not frame ) then
                return
        end
       
        -- Define a Default Fade Time
        if ( dur == 0 or not dur ) then
                dur = 0.5
        end
       
        local FadeOpt = {}
        FadeOpt.timeToFade = dur
        if ( mode:lower() == "in" ) then
                FadeOpt.startAlpha = 0
                FadeOpt.mode = "IN"
                FadeOpt.endAlpha = 1.0
        else
                FadeOpt.startAlpha = 1.0
                FadeOpt.mode = "OUT"
                FadeOpt.endAlpha = 0
        end
       
        frame:SetAlpha(FadeOpt.startAlpha);

        frame.fadeInfo = FadeOpt;
        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", FrameFade_OnUpdate);
end



All times are GMT -6. The time now is 01:20 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI