WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Sliding Panel (https://www.wowinterface.com/forums/showthread.php?t=43103)

Kendian 03-25-12 07:04 PM

Sliding Panel
 
Is it at all possible to script a kgpanel, that would 'slide', for want fo a better word, when you clicked or moused over it? Say I wanted to hide a panel under minimap, or off the side of the screen, but have it slide into view when I moused over or clicked it?

Waky 03-25-12 07:29 PM

Are you asking for it to appear/disappear instantly, or to actually "slide" as in an animation?

If you're looking for it to actually animate, I'd look at the Translation Animation provided in the default UI.

Kendian 03-25-12 07:38 PM

Actually slide in...the Lightheaded panel gave me the idea. But looking at that link lets me know that it's waaaay over my head, lol. My thanks~

Waky 03-25-12 07:44 PM

I just whipped this little bit of code up in game:

Code:

f = f or CreateFrame("Frame","animTest",UIParent);
f:SetSize(100,100);
f:SetBackdrop(GameTooltip:GetBackdrop());
f:SetPoint("CENTER",UIParent);

local g = f:CreateAnimationGroup("AnimationTest"); -- Create the group holding our animations

local t = g:CreateAnimation("Translation"); -- Create a new animation, "Translation" for a sliding effect
t:SetOrder(1); -- Set when it's played (not necessary in this case since there's only 1 animation)
t:SetOffset(50,0); -- Set how far to slide
t:SetDuration(3); -- Set how long it takes to slide

g:Play(); -- Tell animation to start

Basically all this does it creates a 100x100 frame in the middle of the screen, then moves it over 50 pixels over 3 seconds.

Kendian 03-25-12 07:54 PM

That's pretty spectacular..but how would I apply that to a kgpanel? I know making just the frame like that is easier, in some ways, but I'm extremely lua illiterate. My basic idea was to have a panel parented to an action bar ( I use Bartender) and have it slide into view when I moused over or clicked a certain region. Thank you, by the way, for taking the time to answer my questions~

Waky 03-25-12 08:38 PM

I threw this together real quick

Create a frame like you normally would, then put this in it's OnLoad script. Make sure you enable mouse clicks.

OnLoad:
Code:

local open = false; -- Don't change this
local xOffset = 50; -- How far to move left
local yOffset = 0; -- How far to move up
local animDuration = 2; -- How long should it take (in seconds)
local point, relTo, relPt, xOff, yOff; -- Don't change these

self.animGroup = self:CreateAnimationGroup("SlidingFrame");
self.anim = self.animGroup:CreateAnimation("Translation");
self.anim:SetDuration(animDuration);
self.animGroup:SetScript("OnFinished",function()
  point, relTo, relPt, xOff, yOff = self:GetPoint();
if (open==false) then
  self:ClearAllPoints();
  self:SetPoint(point, relTo, relPt, xOff+xOffset, yOff);
else
  self:ClearAllPoints();
  self:SetPoint(point, relTo, relPt, xOff-xOffset, yOff);
end
end)
self:SetScript("OnMouseDown",function(self)
if open==false then
  open = true;
  self.anim:SetOffset(-xOffset,0);
  self.animGroup:Play();
else
  open = false;
  self.anim:SetOffset(xOffset,0);
  self.animGroup:Play();
end
end)

Currently it jitters at the end of the animation, but the frame ends up in the right spot.

I've gotta go to bed for now, I'll look further into this tomorrow!

Kendian 03-25-12 09:13 PM

Sweet, thank you VERY much, Waky. :banana:

Wow. Just..wow. For all it's simplicity (what it does, not how it's written) that has got to be one of the coolest things I've seen. I just sat there and clicked it non-stop, for like 20 minutes. Even WITH the jitter.

Waky 03-26-12 11:44 AM

Remade the code here:

OnLoad:
Code:


local open = false;
local active = false;
local xOffset = 100;
local yOffset = 0;
local animDuration = 2;
local point, relTo, relPt, xOff, yOff;

self.animGroup = self:CreateAnimationGroup("SlidingFrame");
self.animOpen = self.animGroup:CreateAnimation("Translation");
self.animOpen:SetDuration(animDuration);
self.animOpen:SetOrder(1);
self.animOpen:SetOffset(-xOffset,yOffset);
self.animOpen:SetScript("OnFinished",function()
  self.animGroup:Pause();
  active = false;
end)
self.animClose = self.animGroup:CreateAnimation("Translation");
self.animClose:SetDuration(animDuration);
self.animClose:SetOrder(2);
self.animClose:SetOffset(xOffset,yOffset);
self.animClose:SetScript("OnFinished",function() active = false; end)
self:SetScript("OnMouseDown",function(self)
if active==false then
  if open==false then
    active = true;
    open = true;
    self.animGroup:Play();
  else
    active = true;
    open = false;
    self.animGroup:Play();
  end
end
end)

This manner prevents the frame from having to be positioned at all, and can tell if it's currently opening/closing to prevent errors.

Hope this works!

Xrystal 03-26-12 02:08 PM

Cool, thanks Waky. Might have to see how that works. Was thinking of something similar for some of my plugin addons.

Kendian 03-27-12 12:58 PM

Waky, this worked PERFECTLY. My thanks, very much~


:D :banana: :eek:


All times are GMT -6. The time now is 08:59 PM.

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