Rogue: Savage Rats, a retro-themed dungeon crawler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
rogue-savage-rats/src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java

86 lines
1.8 KiB

package mightypork.gamecore.gui.screens.impl;
import mightypork.gamecore.core.events.ShudownRequest;
import mightypork.gamecore.core.modules.AppAccess;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.events.ScreenRequest;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.animation.NumAnimated;
import mightypork.utils.math.color.pal.RGB;
import mightypork.utils.math.timing.TimedTask;
/**
* Overlay used for cross-fading between screens
*
* @author Ondřej Hruška (MightyPork)
*/
public class CrossfadeOverlay extends Overlay {
private static final double T_IN = 0.4;
private static final double T_OUT = 0.6;
NumAnimated alpha = new NumAnimated(0);
String requestedScreenName;
TimedTask revealTask = new TimedTask() {
@Override
public void run()
{
if (requestedScreenName == null) {
getEventBus().send(new ShudownRequest());
} else {
getEventBus().send(new ScreenRequest(requestedScreenName));
}
alpha.setEasing(Easing.SINE_OUT);
alpha.fadeOut(T_OUT);
}
};
public CrossfadeOverlay(AppAccess app) {
super(app);
final QuadPainter qp = new QuadPainter(RGB.BLACK); // TODO allow custom colors
qp.setRect(root);
root.add(qp);
updated.add(alpha);
updated.add(revealTask);
setAlpha(alpha);
}
@Override
public int getZIndex()
{
return 10000; // not too high, so app can put something on top
}
public void goToScreen(String screen, boolean fromDark)
{
requestedScreenName = screen;
if (screen == null) {
// going for halt
getSoundSystem().fadeOutAllLoops();
}
if (fromDark) {
alpha.setTo(1);
revealTask.run();
} else {
revealTask.start(T_IN);
alpha.setEasing(Easing.SINE_IN);
alpha.fadeIn(T_IN);
}
}
}