beginning of slightly better resize system

This commit is contained in:
Harrison Deng 2017-08-18 14:02:25 -05:00
parent 16954280f2
commit 2649f07d89
3 changed files with 68 additions and 53 deletions

View File

@ -50,6 +50,7 @@ public class RhythmBullet extends Game {
private FreeTypeFontGenerator darktech_ldr_fontGenerator;
TextureAtlas skinAtlas;
private Preferences prefs;
private RoundingResolutionHandler rRHandler;
@Override
@ -57,12 +58,6 @@ public class RhythmBullet extends Game {
Gdx.app.setLogLevel(Application.LOG_DEBUG);
prefs = Gdx.app.getPreferences("PolyJet_Preferences");
if (prefs.getBoolean("fullscreen", true)) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(prefs.getInteger("screen-width"), prefs.getInteger("screen-height"));
}
Resolution[] resolution = {
new Resolution(800, 480, "800x480"),
new Resolution(1280, 720, "1280x720"),
@ -75,7 +70,7 @@ public class RhythmBullet extends Game {
};
InternalFileHandleResolver internalFileResolver = new InternalFileHandleResolver();
RoundingResolutionHandler rRHandler = new RoundingResolutionHandler(internalFileResolver, resolution);
rRHandler = new RoundingResolutionHandler(internalFileResolver, resolution);
GenericFileTypeHandler genericFileFinder = new GenericFileTypeHandler(internalFileResolver);
assetManager.setLoader(TextureAtlas.class, new TextureAtlasLoader(rRHandler));
assetManager.setLoader(Texture.class, new TextureLoader(rRHandler));
@ -86,14 +81,6 @@ public class RhythmBullet extends Game {
default_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Gasalt-Regular.ttf"));
darktech_ldr_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/darktech_ldr.ttf"));
if (prefs.getBoolean("fullscreen", true)) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(prefs.getInteger("screen-width"), prefs.getInteger("screen-height"));
}
Gdx.app.debug("Prelaunch Debug Info", "\ncurrent window size: "
+ Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() +"\n"
+ "Pixel density (PPI): " + Gdx.graphics.getDensity());
setScreen(new LoadingScreen(this));
}
@ -102,8 +89,9 @@ public class RhythmBullet extends Game {
public void render() {
if (resizing) {
if (assetManager.update()) {
Gdx.app.debug("Resize", "Post transition is happening");
resizing = false;
generateFonts();
generateFonts(Gdx.graphics.getHeight());
defineSkinStyles();
assetManager.get("standard_thrust.p", ParticleEffect.class).flipY();
((TransitionAdapter) getScreen()).postTransition();
@ -127,27 +115,22 @@ public class RhythmBullet extends Game {
@Override
public void resize(int width, int height) {
if (width != 0 && height != 0) {
if (initComplete) {
Gdx.app.debug("Resize", "Pre-transition is happening.");
rRHandler.setResolution(width, height);
((TransitionAdapter) getScreen()).preTransition();
assetManager.clear();
prefs.putInteger("screen-width", width);
prefs.putInteger("screen-height", height);
prefs.flush();
resizing = true;
}
queueAssets();
}
super.resize(width, height);
}
}
public int fontScale(float fontSize) {
Gdx.app.debug("Font pixel size", MathUtils.round(Gdx.graphics.getDensity()*(fontSize*Gdx.graphics.getHeight())) + "px");
if (Gdx.graphics.getHeight() != 0) {
return MathUtils.round(Gdx.graphics.getDensity()*(fontSize*Gdx.graphics.getHeight()));
} else {
return MathUtils.round(Gdx.graphics.getDensity()*(fontSize*480));
}
public int fontScale(float fontSize, int height) {
return MathUtils.round(Gdx.graphics.getDensity()*(fontSize*height));
}
public AssetManager getAssetManager() {
@ -193,7 +176,7 @@ public class RhythmBullet extends Game {
assetManager.load("tpSelector.png", Texture.class);
assetManager.load("magic1.png", Texture.class);
}
public void generateFonts() {
public void generateFonts(final int height) {
defaultSkin = new Skin();
Gdx.app.debug("Prelaunch Debug Info", "Generating fonts...");
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class);
@ -206,22 +189,22 @@ public class RhythmBullet extends Game {
}));
getDefaultSkin().add("sub-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
{
size = fontScale(0.04f);
size = fontScale(0.04f, height);
}
}));
getDefaultSkin().add("default-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
{
size = fontScale(0.07f);
size = fontScale(0.07f, height);
}
}));
getDefaultSkin().add("large-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
{
size = fontScale(0.085f);
size = fontScale(0.085f, height);
}
}));
getDefaultSkin().add("special-font", darktech_ldr_fontGenerator.generateFont(new FreeTypeFontParameter() {
{
size = fontScale(0.075f);
size = fontScale(0.075f, height);
}
}));
}
@ -307,4 +290,8 @@ public class RhythmBullet extends Game {
Gdx.app.debug("Prelaunch Debug Info", "UI Skin has been defined.");
}
public RoundingResolutionHandler getrRHandler() {
return rRHandler;
}
}

View File

@ -17,7 +17,7 @@ public class LoadingScreen extends ScreenAdapter {
private Stage stage;
RhythmBullet core;
Image zero1HD;
private boolean done;
public LoadingScreen(RhythmBullet core) {
this.core = core;
@ -32,7 +32,10 @@ public class LoadingScreen extends ScreenAdapter {
stage.addActor(zero1HD);
zero1HD.setPosition(stage.getWidth()/2 - zero1HD.getWidth()/2, stage.getHeight()/2 - zero1HD.getHeight()/2);
zero1HD.addAction(Actions.sequence(Actions.color(Color.WHITE, 1f)));
zero1HD.addAction(Actions.sequence(Actions.color(Color.WHITE, 1f), Actions.fadeOut(0.5f)));
core.getrRHandler().setResolution(core.getPrefs().getInteger("screen-width"), core.getPrefs().getInteger("screen-height"));
core.queueAssets();
}
@ -49,21 +52,35 @@ public class LoadingScreen extends ScreenAdapter {
stage.act(delta);
if (!zero1HD.hasActions() & core.getAssetManager().update()) {
Gdx.app.debug("Loading Screen", "queue has all been loaded. Action is done playing.");
zero1HD.remove();
core.generateFonts();
core.defineSkinStyles();
core.setScreen(new MainMenu(core));
core.setInitComplete();
core.getAssetManager().unload("splashlogo.png");
core.getAssetManager().get("standard_thrust.p", ParticleEffect.class).flipY();
moveOn();
}
stage.draw();
super.render(delta);
}
private void moveOn() {
if (!done) {
Gdx.app.debug("Loading Screen", "queue has all been loaded. Action is done playing.");
done = true;
core.generateFonts(core.getPrefs().getInteger("screen-height"));
core.defineSkinStyles();
if (core.getPrefs().getBoolean("fullscreen", true)) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
} else {
Gdx.graphics.setWindowedMode(core.getPrefs().getInteger("screen-width"), core.getPrefs().getInteger("screen-height"));
}
Gdx.app.debug("Prelaunch Debug Info", "\ncurrent window size: "
+ Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() +"\n"
+ "Pixel density (PPI): " + Gdx.graphics.getDensity());
core.setScreen(new MainMenu(core));
zero1HD.remove();
core.getAssetManager().unload("splashlogo.png");
core.getAssetManager().get("standard_thrust.p", ParticleEffect.class).flipY();
}
}
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
@ -72,6 +89,7 @@ public class LoadingScreen extends ScreenAdapter {
@Override
public void hide() {
core.setInitComplete();
super.hide();
}
}

View File

@ -9,19 +9,29 @@ public class RoundingResolutionHandler implements FileHandleResolver {
private final Resolution[] descriptors;
private final FileHandleResolver resolver;
private int width, height;
public RoundingResolutionHandler(FileHandleResolver fileResolver, Resolution... descriptors) {
if (descriptors.length == 0) throw new IllegalArgumentException("At least one Resolution needs to be supplied.");
this.descriptors = descriptors;
this.resolver = fileResolver;
}
public void setResolution(int width, int height) {
this.width = width;
this.height = height;
}
public void resetResolution() {
width = Gdx.graphics.getWidth();
height = Gdx.graphics.getHeight();
}
public Resolution chooseRounded(Resolution... descriptors) {
Resolution best = descriptors[0];
int leastDifference = -1;
int w = Gdx.graphics.getWidth(), h = Gdx.graphics.getHeight();
int w = width, h = height;
if (w > h) {
for (int i = 0; i < descriptors.length; i++) {
@ -55,7 +65,7 @@ public class RoundingResolutionHandler implements FileHandleResolver {
@Override
public FileHandle resolve(String fileName) {
Gdx.app.debug("RResolution Handler", "Finding best match for resolution: " + Gdx.graphics.getWidth() + "x" + Gdx.graphics.getHeight() + " for file: " + fileName);
Gdx.app.debug("RResolution Handler", "Finding best match for resolution: " + width + "x" + height + " for file: " + fileName);
Resolution bestRes = chooseRounded(descriptors);
Gdx.app.debug("RResolution Handler", "Selected folder: " + bestRes.folder);
FileHandle resSpecificFile = resolver.resolve(bestRes.folder + "/" + fileName);