WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   kgPanels FadeIn/Out (OnClick) (https://www.wowinterface.com/forums/showthread.php?t=44486)

Be3f. 09-24-12 03:36 AM

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?

Ekaterina 09-24-12 04:30 AM

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

suicidalkatt 09-24-12 06:21 AM

Quote:

Originally Posted by Ekaterina (Post 264939)
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() **

Ekaterina 09-24-12 06:49 AM

Fixed! Thanks suicidalkatt

suicidalkatt 09-24-12 07:27 AM

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

Be3f. 09-24-12 07:59 AM

Quote:

Originally Posted by Ekaterina (Post 264939)
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?

suicidalkatt 09-24-12 02:38 PM

Quote:

Originally Posted by Be3f. (Post 264955)
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

Be3f. 01-22-13 05:07 PM

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"



All times are GMT -6. The time now is 10:53 AM.

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