From d3ea235f61634e6dc1ff54dd1f5391c2f238a591 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Mon, 29 Jun 2015 00:10:00 -0400 Subject: [PATCH] v0.3.1: reworked UI scaling, now multiplier is user-selectable --- .../shatteredpixeldungeon/Preferences.java | 2 +- .../ShatteredPixelDungeon.java | 8 +++--- .../scenes/PixelScene.java | 28 +++++++++---------- .../windows/WndSettings.java | 22 ++++++++++++--- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java b/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java index 06d019bd0..1c4272ce6 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Preferences.java @@ -30,7 +30,7 @@ enum Preferences { public static final String KEY_LANDSCAPE = "landscape"; public static final String KEY_IMMERSIVE = "immersive"; - public static final String KEY_SCALE_UP = "scaleup"; + public static final String KEY_SCALE = "scale"; public static final String KEY_MUSIC = "music"; public static final String KEY_SOUND_FX = "soundfx"; public static final String KEY_ZOOM = "zoom"; diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java b/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java index 7af786b1e..6c26caf8a 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/ShatteredPixelDungeon.java @@ -200,8 +200,8 @@ public class ShatteredPixelDungeon extends Game { return width > height; } - public static void scaleUp( boolean value ) { - Preferences.INSTANCE.put( Preferences.KEY_SCALE_UP, value ); + public static void scale( int value ) { + Preferences.INSTANCE.put( Preferences.KEY_SCALE, value ); switchScene( TitleScene.class ); } @@ -259,8 +259,8 @@ public class ShatteredPixelDungeon extends Game { // ***************************** - public static boolean scaleUp() { - return Preferences.INSTANCE.getBoolean( Preferences.KEY_SCALE_UP, true ); + public static int scale() { + return Preferences.INSTANCE.getInt( Preferences.KEY_SCALE, 0 ); } public static void zoom( int value ) { diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index 4e04c53bc..5ad3b3511 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -49,7 +49,8 @@ public class PixelScene extends Scene { public static final float MIN_WIDTH_L = 224; public static final float MIN_HEIGHT_L = 160; - public static float defaultZoom = 0; + public static int defaultZoom = 0; + public static int maxDefaultZoom = 0; public static float minZoom; public static float maxZoom; @@ -77,25 +78,22 @@ public class PixelScene extends Scene { minHeight = MIN_HEIGHT_P; } - defaultZoom = (int)Math.ceil( Game.density * 2.5 ); - while (( - Game.width / defaultZoom < minWidth || - Game.height / defaultZoom < minHeight + defaultZoom = ShatteredPixelDungeon.scale(); + if (defaultZoom < Game.density){ + defaultZoom = (int)Math.ceil( Game.density * 2.5 ); + while (( + Game.width / defaultZoom < minWidth || + Game.height / defaultZoom < minHeight ) && defaultZoom > 1) { - - defaultZoom--; - } - - if (ShatteredPixelDungeon.scaleUp()) { - while ( - Game.width / (defaultZoom + 1) >= minWidth && - Game.height / (defaultZoom + 1) >= minHeight) { - defaultZoom++; + defaultZoom--; } + ShatteredPixelDungeon.scale(defaultZoom); } + + maxDefaultZoom = (int)Math.min(Game.width/minWidth, Game.height/minHeight); + minZoom = 1; maxZoom = defaultZoom * 2; - Camera.reset( new PixelCamera( defaultZoom ) ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index a62b91f20..1395ebd7c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -21,9 +21,11 @@ package com.shatteredpixel.shatteredpixeldungeon.windows; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; +import com.shatteredpixel.shatteredpixeldungeon.scenes.TitleScene; import com.shatteredpixel.shatteredpixeldungeon.ui.Toolbar; import com.shatteredpixel.shatteredpixeldungeon.utils.Utils; import com.watabou.noosa.Camera; +import com.watabou.noosa.Game; import com.watabou.noosa.audio.Sample; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene; @@ -37,7 +39,7 @@ public class WndSettings extends Window { private static final String TXT_ZOOM_OUT = "-"; private static final String TXT_ZOOM_DEFAULT = "Default Zoom"; - private static final String TXT_SCALE_UP = "Scale up UI"; + private static final String TXT_SCALE = "UI Scale: %dX"; private static final String TXT_IMMERSIVE = "Immersive mode"; private static final String TXT_MUSIC = "Music"; @@ -57,6 +59,8 @@ public class WndSettings extends Window { private RedButton btnZoomOut; private RedButton btnZoomIn; + + private int setScale = PixelScene.defaultZoom; public WndSettings( boolean inGame ) { super(); @@ -94,15 +98,16 @@ public class WndSettings extends Window { } else { - CheckBox btnScaleUp = new CheckBox( TXT_SCALE_UP ) { + RedButton btnScaleUp = new RedButton( Utils.format(TXT_SCALE, setScale) ) { @Override protected void onClick() { super.onClick(); - ShatteredPixelDungeon.scaleUp(checked()); + setScale++; + if (setScale > PixelScene.maxDefaultZoom) setScale = (int)Math.ceil(Game.density); + this.text(Utils.format(TXT_SCALE, setScale)); } }; btnScaleUp.setRect( 0, 0, WIDTH, BTN_HEIGHT ); - btnScaleUp.checked( ShatteredPixelDungeon.scaleUp() ); add( btnScaleUp ); btnImmersive = new CheckBox( TXT_IMMERSIVE ) { @@ -218,4 +223,13 @@ public class WndSettings extends Window { private String orientationText() { return ShatteredPixelDungeon.landscape() ? TXT_SWITCH_PORT : TXT_SWITCH_LAND; } + + @Override + public void hide() { + super.hide(); + if (setScale != PixelScene.defaultZoom) { + ShatteredPixelDungeon.scale(setScale); + ShatteredPixelDungeon.switchScene(TitleScene.class); + } + } }