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/rogue/screens/CrossfadeOverlay.java

83 lines
1.7 KiB

package mightypork.rogue.screens;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.events.ScreenRequestEvent;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.util.constraints.num.mutable.NumAnimated;
import mightypork.util.control.timing.TimedTask;
import mightypork.util.math.Easing;
import mightypork.util.math.color.Color;
public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listener {
private static final double T_IN = 0.5;
private static final double T_OUT = 0.7;
NumAnimated level = new NumAnimated(0);
Color color = Color.dark(level);
String requestedScreenName;
TimedTask tt = new TimedTask() {
@Override
public void run()
{
if (requestedScreenName == null) {
getEventBus().send(new ActionRequest(RequestType.SHUTDOWN));
} else {
getEventBus().send(new ScreenRequestEvent(requestedScreenName));
}
}
};
TimedTask tt2 = new TimedTask() {
@Override
public void run()
{
level.setEasing(Easing.SINE_OUT);
level.fadeOut(T_OUT);
}
};
public CrossfadeOverlay(AppAccess app) {
super(app);
final QuadPainter qp = new QuadPainter(color);
qp.setRect(root);
root.add(qp);
updated.add(level);
updated.add(tt);
updated.add(tt2);
}
@Override
public int getPriority()
{
return Integer.MAX_VALUE - 1; // let FPS go on top
}
@Override
public void goToScreen(String screen)
{
tt.start(T_IN);
tt2.start(T_IN);
level.setEasing(Easing.SINE_IN);
level.fadeIn(T_IN);
requestedScreenName = screen;
}
}