Quantcast
kgPanels FadeIn/Out (OnClick) - WoWInterface
Thread Tools Display Modes
09-24-12, 03:36 AM   #1
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 63
kgPanels FadeIn/Out (OnClick)

So until mop opens I thought I'd make my UI a little fancier, so I decided to try and make a kgpanel that, when clicked, fades in and out a frame. My extreme coding skills got me this:

OnClick:
Lua Code:
  1. if pressed then
  2.    if SLDT_Clock:IsShown then
  3.       UIFrameFadeOut(SLDT_Clock, 1, 1, 0)
  4.    else
  5.       UIFrameFadeIn(SLDT_Clock, 1, 0, 1)
  6.    end
  7. end

But this only makes "SLDT_Clock" fade out when clicked and not fade in when clicked again. So the question is: What am I missing?
__________________
-- Be3f.
  Reply With Quote
09-24-12, 04:30 AM   #2
Ekaterina
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 57
Hi,
I think that the problem is that the frame is still shown, it hasn't explicitly been hidden, just the alpha has changed.

Try this instead:

Lua Code:
  1. if pressed then
  2.       if SLDT_Clock:GetAlpha() > 0 then
  3.            UIFrameFadeOut(SLDT_Clock, 1, 1, 0)
  4.       else
  5.            UIFrameFadeIn(SLDT_Clock, 1, 0, 1)
  6.      end
  7. end

Ekat

Last edited by Ekaterina : 09-24-12 at 06:48 AM. Reason: to correct formatting and insert missed brackets.
  Reply With Quote
09-24-12, 06:21 AM   #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 Ekaterina View Post
Hi,
I think that the problem is that the frame is still shown, it hasn't explicitly been hidden, just the alpha has changed.

Try this instead:

Lua Code:
  1. if pressed then
  2.     if SLDT_Clock:GetAlpha > 0 then
  3.         UIFrameFadeOut(SLDT_Clock, 1, 1, 0)
  4.     else
  5.         UIFrameFadeIn(SLDT_Clock, 1, 0, 1)
  6.     end
  7. end

Ekat
SLDT_Clock:GetAlpha() **
  Reply With Quote
09-24-12, 06:49 AM   #4
Ekaterina
A Wyrmkin Dreamwalker
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 57
Fixed! Thanks suicidalkatt
  Reply With Quote
09-24-12, 07:27 AM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Just to make it clear, your sintax for 'IsShown' is that it's a function, meaning just as I showed above, IsShown() requires ()'s.

Lua Code:
  1. if pressed then
  2.    if SLDT_Clock:IsShown then
  3.       UIFrameFadeOut(SLDT_Clock, 1, 1, 0)
  4.    else
  5.       UIFrameFadeIn(SLDT_Clock, 1, 0, 1)
  6.    end
  7. end

should be..

Lua Code:
  1. if pressed then
  2.    if SLDT_Clock:IsShown() then
  3.       UIFrameFadeOut(SLDT_Clock, 1, 1, 0)
  4.    else
  5.       UIFrameFadeIn(SLDT_Clock, 1, 0, 1)
  6.    end
  7. end
  Reply With Quote
09-24-12, 07:59 AM   #6
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 63
Originally Posted by Ekaterina View Post
Hi,
I think that the problem is that the frame is still shown, it hasn't explicitly been hidden, just the alpha has changed.
Ekat
Thanks for both of your responses. So if I understand this correctly, would I have to do something like SLDT_Clock:Hide() / SLDT_Clock:Show() aswell?
__________________
-- Be3f.
  Reply With Quote
09-24-12, 02:38 PM   #7
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Be3f. View Post
Thanks for both of your responses. So if I understand this correctly, would I have to do something like SLDT_Clock:Hide() / SLDT_Clock:Show() aswell?
You'll have to either check for alpha, or use the 'fadeinfo' parameter that's available with UIFrameFadeIn(Out) and use its 'finishedFunc' to hide the frame after fading.

Example would be place with the OnLoad for that frame:
Lua Code:
  1. self.fadeIn = {
  2.     mode = "IN",
  3.     timeToFade = 1,
  4.     startAlpha = 0,
  5.     endAlpha = 1,
  6.     finishedFunc = function()
  7.         print("Fade in finished");
  8.     end
  9. }
  10.  
  11. self.fadeOut = {
  12.     mode = "OUT",
  13.     timeToFade = 1,
  14.     startAlpha = 1,
  15.     endAlpha = 0,
  16.     finishedFunc = function()
  17.         SLDT_Clock:Hide(); -- Hide the frame after fading out.
  18.     end
  19. }

Then OnClick would be:
Lua Code:
  1. if pressed then
  2.    if SLDT_Clock:IsShown() then
  3.       UIFrameFadeOut(SLDT_Clock, self.fadeOut)
  4.    else
  5.       UIFrameFadeIn(SLDT_Clock, self.fadeIn)
  6.    end
  7. end

Last edited by suicidalkatt : 09-24-12 at 02:52 PM. Reason: I derped a lil
  Reply With Quote
01-22-13, 05:07 PM   #8
Be3f.
A Theradrim Guardian
 
Be3f.'s Avatar
Join Date: Jan 2011
Posts: 63
Error

This error pops up:

Code:
Message: Interface\FrameXML\UIParent.lua:2720: attempt to compare number with table
Time: 01/23/13 00:04:37
Count: 1477
Stack: Interface\FrameXML\UIParent.lua:2720: in function <Interface\FrameXML\UIParent.lua:2707>

Locals: self = <unnamed> {
 0 = <userdata>
}
elapsed = 0.032999999821186
index = 1
frame = SLDT_Clock {
 0 = <userdata>
 fadeInfo = <table> {
 }
}
fadeInfo = <table> {
 startAlpha = 1
 endAlpha = 0
 mode = "OUT"
 fadeTimer = 48.63100083638
 timeToFade = <table> {
 }
}
(*temporary) = 48.63100083638
(*temporary) = <table> {
 startAlpha = 1
 finishedFunc = <function> defined ButtonTest_OnLoad:16
 timeToFade = 1
 mode = "OUT"
 endAlpha = 0
}
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to compare number with table"
__________________
-- Be3f.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » kgPanels FadeIn/Out (OnClick)

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