|
|
|
package mightypork.gamecore.gui.screens.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import mightypork.gamecore.gui.screens.Screen;
|
|
|
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
|
|
|
import mightypork.gamecore.util.annot.DefaultImpl;
|
|
|
|
import mightypork.gamecore.util.math.Easing;
|
|
|
|
import mightypork.gamecore.util.math.constraints.num.mutable.NumAnimated;
|
|
|
|
import mightypork.gamecore.util.math.timing.TimedTask;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Layer that smoothly appears/disappears when shown/hidden
|
|
|
|
*
|
|
|
|
* @author Ondřej Hruška
|
|
|
|
*/
|
|
|
|
public abstract class FadingLayer extends ScreenLayer {
|
|
|
|
|
|
|
|
private final NumAnimated numa;
|
|
|
|
private final TimedTask hideTimer = new TimedTask() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
FadingLayer.super.hide();
|
|
|
|
fadingOut = false;
|
|
|
|
onHideFinished();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private final TimedTask showTimer = new TimedTask() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
fadingIn = false;
|
|
|
|
onShowFinished();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private boolean fadingIn = false;
|
|
|
|
private boolean fadingOut = false;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create with default fading time and effect
|
|
|
|
*
|
|
|
|
* @param screen
|
|
|
|
*/
|
|
|
|
public FadingLayer(Screen screen)
|
|
|
|
{
|
|
|
|
this(screen, new NumAnimated(1, Easing.QUADRATIC_OUT, 0.3));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param screen
|
|
|
|
* @param easingAnim the animation num
|
|
|
|
*/
|
|
|
|
public FadingLayer(Screen screen, NumAnimated easingAnim)
|
|
|
|
{
|
|
|
|
super(screen);
|
|
|
|
|
|
|
|
numa = easingAnim;
|
|
|
|
|
|
|
|
updated.add(numa);
|
|
|
|
updated.add(hideTimer);
|
|
|
|
updated.add(showTimer);
|
|
|
|
|
|
|
|
setAlpha(numa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after the fade-out was completed
|
|
|
|
*/
|
|
|
|
@DefaultImpl
|
|
|
|
protected void onHideFinished()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after the fade-in was completed
|
|
|
|
*/
|
|
|
|
@DefaultImpl
|
|
|
|
protected void onShowFinished()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show with fading
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void show()
|
|
|
|
{
|
|
|
|
if (fadingIn) return;
|
|
|
|
|
|
|
|
if (!isVisible() || fadingOut) {
|
|
|
|
super.show();
|
|
|
|
numa.fadeIn();
|
|
|
|
hideTimer.stop();
|
|
|
|
showTimer.start(numa.getDefaultDuration());
|
|
|
|
|
|
|
|
fadingOut = false;
|
|
|
|
fadingIn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide without fading
|
|
|
|
*/
|
|
|
|
public void hideImmediate()
|
|
|
|
{
|
|
|
|
hideTimer.stop();
|
|
|
|
numa.setTo(0);
|
|
|
|
super.hide();
|
|
|
|
onHideFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show without fading
|
|
|
|
*/
|
|
|
|
public void showImmediate()
|
|
|
|
{
|
|
|
|
hideTimer.stop();
|
|
|
|
numa.setTo(1);
|
|
|
|
super.show();
|
|
|
|
onShowFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide with fading
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void hide()
|
|
|
|
{
|
|
|
|
if (fadingOut) return;
|
|
|
|
|
|
|
|
if (isVisible()) {
|
|
|
|
numa.fadeOut();
|
|
|
|
hideTimer.start(numa.getDefaultDuration());
|
|
|
|
|
|
|
|
fadingOut = true;
|
|
|
|
fadingIn = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|