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; private FreeTypeFontGenerator darktech_ldr_fontGenerator;
TextureAtlas skinAtlas; TextureAtlas skinAtlas;
private Preferences prefs; private Preferences prefs;
private RoundingResolutionHandler rRHandler;
@Override @Override
@ -57,12 +58,6 @@ public class RhythmBullet extends Game {
Gdx.app.setLogLevel(Application.LOG_DEBUG); Gdx.app.setLogLevel(Application.LOG_DEBUG);
prefs = Gdx.app.getPreferences("PolyJet_Preferences"); 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 = { Resolution[] resolution = {
new Resolution(800, 480, "800x480"), new Resolution(800, 480, "800x480"),
new Resolution(1280, 720, "1280x720"), new Resolution(1280, 720, "1280x720"),
@ -75,7 +70,7 @@ public class RhythmBullet extends Game {
}; };
InternalFileHandleResolver internalFileResolver = new InternalFileHandleResolver(); InternalFileHandleResolver internalFileResolver = new InternalFileHandleResolver();
RoundingResolutionHandler rRHandler = new RoundingResolutionHandler(internalFileResolver, resolution); rRHandler = new RoundingResolutionHandler(internalFileResolver, resolution);
GenericFileTypeHandler genericFileFinder = new GenericFileTypeHandler(internalFileResolver); GenericFileTypeHandler genericFileFinder = new GenericFileTypeHandler(internalFileResolver);
assetManager.setLoader(TextureAtlas.class, new TextureAtlasLoader(rRHandler)); assetManager.setLoader(TextureAtlas.class, new TextureAtlasLoader(rRHandler));
assetManager.setLoader(Texture.class, new TextureLoader(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")); default_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/Gasalt-Regular.ttf"));
darktech_ldr_fontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/darktech_ldr.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)); setScreen(new LoadingScreen(this));
} }
@ -102,8 +89,9 @@ public class RhythmBullet extends Game {
public void render() { public void render() {
if (resizing) { if (resizing) {
if (assetManager.update()) { if (assetManager.update()) {
Gdx.app.debug("Resize", "Post transition is happening");
resizing = false; resizing = false;
generateFonts(); generateFonts(Gdx.graphics.getHeight());
defineSkinStyles(); defineSkinStyles();
assetManager.get("standard_thrust.p", ParticleEffect.class).flipY(); assetManager.get("standard_thrust.p", ParticleEffect.class).flipY();
((TransitionAdapter) getScreen()).postTransition(); ((TransitionAdapter) getScreen()).postTransition();
@ -127,27 +115,22 @@ public class RhythmBullet extends Game {
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
if (width != 0 && height != 0) { if (initComplete) {
if (initComplete) { Gdx.app.debug("Resize", "Pre-transition is happening.");
((TransitionAdapter) getScreen()).preTransition(); rRHandler.setResolution(width, height);
assetManager.clear(); ((TransitionAdapter) getScreen()).preTransition();
prefs.putInteger("screen-width", width); assetManager.clear();
prefs.putInteger("screen-height", height); prefs.putInteger("screen-width", width);
prefs.flush(); prefs.putInteger("screen-height", height);
resizing = true; prefs.flush();
} resizing = true;
queueAssets(); queueAssets();
super.resize(width, height);
} }
super.resize(width, height);
} }
public int fontScale(float fontSize) { public int fontScale(float fontSize, int height) {
Gdx.app.debug("Font pixel size", MathUtils.round(Gdx.graphics.getDensity()*(fontSize*Gdx.graphics.getHeight())) + "px"); return MathUtils.round(Gdx.graphics.getDensity()*(fontSize*height));
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 AssetManager getAssetManager() { public AssetManager getAssetManager() {
@ -193,7 +176,7 @@ public class RhythmBullet extends Game {
assetManager.load("tpSelector.png", Texture.class); assetManager.load("tpSelector.png", Texture.class);
assetManager.load("magic1.png", Texture.class); assetManager.load("magic1.png", Texture.class);
} }
public void generateFonts() { public void generateFonts(final int height) {
defaultSkin = new Skin(); defaultSkin = new Skin();
Gdx.app.debug("Prelaunch Debug Info", "Generating fonts..."); Gdx.app.debug("Prelaunch Debug Info", "Generating fonts...");
skinAtlas = assetManager.get("uiskin.atlas", TextureAtlas.class); 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() { 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() { 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() { 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() { 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."); 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; private Stage stage;
RhythmBullet core; RhythmBullet core;
Image zero1HD; Image zero1HD;
private boolean done;
public LoadingScreen(RhythmBullet core) { public LoadingScreen(RhythmBullet core) {
this.core = core; this.core = core;
@ -32,7 +32,10 @@ public class LoadingScreen extends ScreenAdapter {
stage.addActor(zero1HD); stage.addActor(zero1HD);
zero1HD.setPosition(stage.getWidth()/2 - zero1HD.getWidth()/2, stage.getHeight()/2 - zero1HD.getHeight()/2); 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(); core.queueAssets();
} }
@ -49,21 +52,35 @@ public class LoadingScreen extends ScreenAdapter {
stage.act(delta); stage.act(delta);
if (!zero1HD.hasActions() & core.getAssetManager().update()) { if (!zero1HD.hasActions() & core.getAssetManager().update()) {
Gdx.app.debug("Loading Screen", "queue has all been loaded. Action is done playing."); moveOn();
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();
} }
stage.draw(); stage.draw();
super.render(delta); 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 @Override
public void resize(int width, int height) { public void resize(int width, int height) {
stage.getViewport().update(width, height, true); stage.getViewport().update(width, height, true);
@ -72,6 +89,7 @@ public class LoadingScreen extends ScreenAdapter {
@Override @Override
public void hide() { public void hide() {
core.setInitComplete();
super.hide(); super.hide();
} }
} }

View File

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