WarpPI/core/src/main/java/it/cavallium/warppi/gui/screens/LoadingScreen.java

87 lines
2.8 KiB
Java
Raw Normal View History

package it.cavallium.warppi.gui.screens;
2016-10-02 16:01:41 +02:00
2019-02-27 23:29:03 +01:00
import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.StaticVars;
2019-11-01 18:04:01 +01:00
import it.cavallium.warppi.extra.mario.MarioScreen;
import it.cavallium.warppi.gui.GraphicUtils;
2018-10-05 16:00:15 +02:00
import it.cavallium.warppi.gui.HistoryBehavior;
2019-11-01 18:04:01 +01:00
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
2016-10-02 16:01:41 +02:00
public class LoadingScreen extends Screen {
public float endLoading;
boolean mustRefresh = true;
public float loadingTextTranslation = 0.0f;
2017-12-23 15:20:42 +01:00
public boolean loaded = false;
2018-03-31 18:02:36 +02:00
private float previousZoomValue = 1;
2018-10-04 12:38:54 +02:00
private volatile boolean ended = false;
2016-10-02 16:01:41 +02:00
public LoadingScreen() {
super();
2018-10-05 16:00:15 +02:00
historyBehavior = HistoryBehavior.DONT_KEEP_IN_HISTORY;
2016-10-02 16:01:41 +02:00
}
2016-10-02 16:01:41 +02:00
@Override
public void created() throws InterruptedException {
2019-02-27 23:29:03 +01:00
WarpPI.INSTANCE.isLoaded().subscribe((loaded) -> {
this.loaded = loaded;
});
2016-10-02 16:01:41 +02:00
endLoading = 0;
}
@Override
2018-03-31 18:02:36 +02:00
public void initialized() throws InterruptedException {
previousZoomValue = StaticVars.windowZoomFunction.apply(StaticVars.windowZoom.getLastValue());
2019-02-27 23:29:03 +01:00
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().hide();
2019-11-01 15:23:34 +01:00
StaticVars.windowZoom.submit(1f);
2018-03-31 18:02:36 +02:00
}
@Override
2019-11-01 18:04:01 +01:00
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
2016-10-02 16:01:41 +02:00
@Override
2019-11-01 18:04:01 +01:00
public void beforeRender(ScreenContext ctx, final float dt) {
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
2016-10-02 16:01:41 +02:00
endLoading += dt;
2019-11-01 18:04:01 +01:00
if (!ended && loaded && ((WarpPI.getPlatform().getSettings().isDebugEnabled() && endLoading >= 1.5f) || endLoading >= 3.5f)) {
2018-10-04 12:38:54 +02:00
ended = true;
2019-11-01 15:23:34 +01:00
StaticVars.windowZoom.submit(previousZoomValue);
2019-02-27 23:29:03 +01:00
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
2019-11-02 23:13:19 +01:00
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
2016-10-02 16:01:41 +02:00
}
mustRefresh = true;
}
@Override
2019-11-01 18:04:01 +01:00
public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display;
2019-11-02 23:13:19 +01:00
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(display);
2019-11-01 18:04:01 +01:00
ctx.getRenderer().glColor3i(255, 255, 255);
ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 80, ctx.getHeight() / 2f - 64, 160, 48, 0, 32, 160, 48);
ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 24, ctx.getHeight() / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
2019-11-01 18:04:01 +01:00
ctx.getRenderer().glFillRect(ctx.getWidth() - 224, ctx.getHeight() - 48, 224, 48, 0, 80, 224, 48);
ctx.getRenderer().glFillRect(ctx.getWidth() - 160 - 24 - 224, ctx.getHeight() - 48, 160, 48, 224, 80, 160, 48);
2016-10-02 16:01:41 +02:00
}
@Override
public boolean mustBeRefreshed() {
if (mustRefresh) {
mustRefresh = false;
return true;
2018-09-28 11:39:28 +02:00
} else {
2016-10-02 16:01:41 +02:00
return false;
2018-09-28 11:39:28 +02:00
}
2016-10-02 16:01:41 +02:00
}
2018-10-04 12:38:54 +02:00
@Override
public String getSessionTitle() {
return "Loading...";
}
2016-10-02 16:01:41 +02:00
}