Thread Tools Display Modes
10-26-10, 08:38 AM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
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)
  Reply With Quote
10-26-10, 10:51 AM   #2
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
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
  Reply With Quote
10-26-10, 01:48 PM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Duugu View Post
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.
  Reply With Quote
10-28-10, 08:42 PM   #4
samishii23
An Aku'mai Servant
Join Date: Oct 2010
Posts: 33
Originally Posted by Duugu View Post
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?
  Reply With Quote
10-29-10, 07:59 PM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by samishii23 View Post
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.
  Reply With Quote
10-30-10, 06:53 AM   #6
samishii23
An Aku'mai Servant
Join Date: Oct 2010
Posts: 33
Lol, yea, magic. Blizzard is full of that.
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

Last edited by samishii23 : 10-30-10 at 07:22 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » UIFrameFadeIn finishFunc?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off