splash screen no longer dependent on asset loading; desktop platform

interface improved
This commit is contained in:
Harrison Deng 2018-08-31 18:34:32 -05:00
parent 6773abe942
commit d6b39c8d73
5 changed files with 41 additions and 44 deletions

View File

@ -26,8 +26,5 @@ public interface ScreenConfiguration {
public void setWindowLocation(int x, int y); public void setWindowLocation(int x, int y);
/** public void setWindowBorderless(boolean borderless);
* Restarts the application.
*/
public void restart();
} }

View File

@ -21,8 +21,6 @@ public class DesktopLauncher {
core = new RhythmBullet(); core = new RhythmBullet();
core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig); core.setup(new SplashScreen(), new DesktopAssetPack(), screenConfig);
while (screenConfig.shouldStart()) {
LwjglApplication app = new LwjglApplication(core, config); LwjglApplication app = new LwjglApplication(core, config);
} }
} }
}

View File

@ -2,16 +2,17 @@ package zero1hd.rhythmbullet.desktop;
import org.lwjgl.opengl.Display; import org.lwjgl.opengl.Display;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import zero1hd.rhythmbullet.util.ScreenConfiguration; import zero1hd.rhythmbullet.util.ScreenConfiguration;
public class DesktopScreenConfiguration implements ScreenConfiguration { public class DesktopScreenConfiguration implements ScreenConfiguration {
private LwjglApplicationConfiguration configuration; private LwjglApplicationConfiguration configuration;
private boolean start = true; private boolean vSync;
public DesktopScreenConfiguration(LwjglApplicationConfiguration configuration) { public DesktopScreenConfiguration(LwjglApplicationConfiguration configuration) {
this.configuration = configuration; this.configuration = configuration;
vSync = configuration.vSyncEnabled;
} }
@Override @Override
@ -25,17 +26,15 @@ public class DesktopScreenConfiguration implements ScreenConfiguration {
return configuration.foregroundFPS; return configuration.foregroundFPS;
} }
/**
* Requires restart. Can be done by calling {@link #restart()}
*/
@Override @Override
public void setVsync(boolean useVsync) { public void setVsync(boolean useVsync) {
configuration.vSyncEnabled = useVsync; configuration.vSyncEnabled = useVsync;
Display.setVSyncEnabled(useVsync);
} }
@Override @Override
public boolean getVsync() { public boolean getVsync() {
return configuration.vSyncEnabled; return vSync;
} }
@Override @Override
@ -74,14 +73,9 @@ public class DesktopScreenConfiguration implements ScreenConfiguration {
} }
@Override @Override
public void restart() { public void setWindowBorderless(boolean borderless) {
Gdx.app.exit(); if (borderless) {
start = true; System.setProperty("org.lwjgl.opengl.Window.undecorated", String.valueOf(borderless));
} }
public boolean shouldStart() {
boolean should = start;
start = false;
return should;
} }
} }

View File

@ -6,39 +6,45 @@ import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import zero1hd.rhythmbullet.RhythmBullet; import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.screens.main.MainScreen; import zero1hd.rhythmbullet.desktop.screens.main.MainScreen;
import zero1hd.rhythmbullet.util.InitialScreen; import zero1hd.rhythmbullet.util.InitialScreen;
public class SplashScreen extends ScreenAdapter implements InitialScreen { public class SplashScreen extends ScreenAdapter implements InitialScreen {
private Stage stage; private Sprite splashSprite;
private Texture splash; private SpriteBatch batch;
private Image zero1HD; private Color color = new Color(1f, 1f, 1f, 1f);
private float fadeTime = 1.5f;
@Override @Override
public void init() { public void init() {
stage = new Stage(new ScreenViewport()); batch = new SpriteBatch();
splash = new Texture(Gdx.files.internal("splashlogo.png")); splashSprite = new Sprite(new Texture(Gdx.files.internal("splashlogo.png")));
zero1HD = new Image(splash); float scale = (Gdx.graphics.getHeight()/3f)/splashSprite.getHeight();
splashSprite.setSize(scale*splashSprite.getWidth(), scale*splashSprite.getHeight());
splashSprite.setPosition((Gdx.graphics.getWidth()-splashSprite.getWidth())/2f, (Gdx.graphics.getHeight()-splashSprite.getHeight())/2f);
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f); Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta); batch.begin();
stage.draw(); float change = delta/fadeTime;
color.a -= change;
splashSprite.setColor(color);
splashSprite.draw(batch);
batch.end();
super.render(delta); super.render(delta);
} }
@Override @Override
public void hide() { public void hide() {
splash.dispose(); splashSprite.getTexture().dispose();
super.hide(); super.hide();
} }
@ -48,16 +54,10 @@ public class SplashScreen extends ScreenAdapter implements InitialScreen {
@Override @Override
public void postAssetLoad() { public void postAssetLoad() {
zero1HD.setScale((stage.getHeight()*0.8f)/(zero1HD.getHeight()));
zero1HD.setColor(0f,1f,1f,0f);
zero1HD.setPosition((stage.getWidth() - (zero1HD.getWidth()*zero1HD.getScaleX()))/2f, (stage.getHeight() - (zero1HD.getHeight()*zero1HD.getScaleY()))/2f);
stage.addActor(zero1HD);
zero1HD.addAction(Actions.sequence(Actions.color(Color.WHITE, 1f), Actions.fadeOut(0.5f)));
} }
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
stage.getViewport().update(width, height);
super.resize(width, height); super.resize(width, height);
} }

View File

@ -1,5 +1,9 @@
package zero1hd.rhythmbullet.desktop.screens.main; package zero1hd.rhythmbullet.desktop.screens.main;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Formatter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences; import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
@ -23,10 +27,13 @@ public class OptionsPage extends Page {
private TextField directoryField; private TextField directoryField;
private float musicSearchTimer; private float musicSearchTimer;
private Preferences prefs; private Preferences prefs;
private NumberFormat formatter;
public OptionsPage(MusicController musicController, Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener graphicsButtonListener, ChangeListener controlsButtonListener) { public OptionsPage(MusicController musicController, Skin skin, Preferences preferences, ChangeListener backButtonListener, ChangeListener graphicsButtonListener, ChangeListener controlsButtonListener) {
super(-1, 0, "General", skin); super(-1, 0, "General", skin);
this.prefs = preferences; this.prefs = preferences;
formatter = NumberFormat.getPercentInstance();
formatter.setMaximumFractionDigits(1);
//Back button //Back button
TextButton backButton = new TextButton("Back", skin); TextButton backButton = new TextButton("Back", skin);
@ -126,14 +133,15 @@ public class OptionsPage extends Page {
optionsTable.row(); optionsTable.row();
Label usageLabel = new Label("Current usage (lower the better): " + 100f*((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()) + "%", skin) { Label usageLabel = new Label("Current Usage (JVM): ", skin) {
float refreshTime = 20; float refreshTime = 20;
@Override @Override
public void act(float delta) { public void act(float delta) {
refreshTime -= delta; refreshTime -= delta;
if (refreshTime <= 0) { if (refreshTime <= 0) {
refreshTime = 20; refreshTime = 4;
setText("Current usage (lower the better): " + 100f*((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()) + "%"); String formatted = formatter.format(((float)(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(float)Runtime.getRuntime().totalMemory()));
setText("Current usage (JVM): " + formatted);
} }
super.act(delta); super.act(delta);
} }