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);
/**
* Restarts the application.
*/
public void restart();
public void setWindowBorderless(boolean borderless);
}

View File

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

View File

@ -6,39 +6,45 @@ import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.desktop.screens.main.MainScreen;
import zero1hd.rhythmbullet.util.InitialScreen;
public class SplashScreen extends ScreenAdapter implements InitialScreen {
private Stage stage;
private Texture splash;
private Image zero1HD;
private Sprite splashSprite;
private SpriteBatch batch;
private Color color = new Color(1f, 1f, 1f, 1f);
private float fadeTime = 1.5f;
@Override
public void init() {
stage = new Stage(new ScreenViewport());
splash = new Texture(Gdx.files.internal("splashlogo.png"));
zero1HD = new Image(splash);
batch = new SpriteBatch();
splashSprite = new Sprite(new Texture(Gdx.files.internal("splashlogo.png")));
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
public void render(float delta) {
Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
stage.draw();
batch.begin();
float change = delta/fadeTime;
color.a -= change;
splashSprite.setColor(color);
splashSprite.draw(batch);
batch.end();
super.render(delta);
}
@Override
public void hide() {
splash.dispose();
splashSprite.getTexture().dispose();
super.hide();
}
@ -48,16 +54,10 @@ public class SplashScreen extends ScreenAdapter implements InitialScreen {
@Override
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
public void resize(int width, int height) {
stage.getViewport().update(width, height);
super.resize(width, height);
}

View File

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