From 04d8278950676043588e4bdeed448fbb19062d22 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Fri, 9 Jul 2021 18:39:09 -0400 Subject: [PATCH] v0.9.4: reverted removal of orientation control from Android version --- android/src/main/AndroidManifest.xml | 2 +- .../android/AndroidGame.java | 7 +++++++ .../android/AndroidPlatformSupport.java | 13 +++++++++++++ .../assets/messages/windows/windows.properties | 2 ++ .../windows/WndSettings.java | 18 ++++++++++++++++++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 070af02bb..1b84111b4 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -39,7 +39,7 @@ diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java index 2da3b8c94..eb081effc 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidGame.java @@ -89,6 +89,13 @@ public class AndroidGame extends AndroidApplication { instance = this; } + //set desired orientation (if it exists) before initializing the app. + if (SPDSettings.landscape() != null) { + instance.setRequestedOrientation( SPDSettings.landscape() ? + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); + } + AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); config.depth = 0; if (DeviceCompat.legacyDevice()) { diff --git a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java index 35ff10492..c6ce0bc45 100644 --- a/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java +++ b/android/src/main/java/com/shatteredpixel/shatteredpixeldungeon/android/AndroidPlatformSupport.java @@ -55,6 +55,12 @@ import java.util.regex.Pattern; public class AndroidPlatformSupport extends PlatformSupport { public void updateDisplaySize(){ + if (SPDSettings.landscape() != null) { + AndroidGame.instance.setRequestedOrientation( SPDSettings.landscape() ? + ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : + ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT ); + } + GLSurfaceView view = (GLSurfaceView) ((AndroidGraphics)Gdx.graphics).getView(); if (view.getMeasuredWidth() == 0 || view.getMeasuredHeight() == 0) @@ -66,6 +72,13 @@ public class AndroidPlatformSupport extends PlatformSupport { boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !AndroidGame.instance.isInMultiWindowMode(); + if (fullscreen && SPDSettings.landscape() != null + && (Game.dispWidth >= Game.dispHeight) != SPDSettings.landscape()){ + int tmp = Game.dispWidth; + Game.dispWidth = Game.dispHeight; + Game.dispHeight = tmp; + } + float dispRatio = Game.dispWidth / (float)Game.dispHeight; float renderWidth = dispRatio > 1 ? PixelScene.MIN_WIDTH_L : PixelScene.MIN_WIDTH_P; diff --git a/core/src/main/assets/messages/windows/windows.properties b/core/src/main/assets/messages/windows/windows.properties index 60dfcdf9a..7d1dbce33 100644 --- a/core/src/main/assets/messages/windows/windows.properties +++ b/core/src/main/assets/messages/windows/windows.properties @@ -164,6 +164,8 @@ windows.wndsettings$displaytab.saver=Power Saver windows.wndsettings$displaytab.saver_desc=Power Saver mode draws the game at a reduced size and scales it up to fit your screen.\n\nThis will make graphics less crisp and enlarge the UI slightly, but will also improve performance and battery life.\n\nYou may need to restart the game for changes to take effect. windows.wndsettings$displaytab.okay=Okay windows.wndsettings$displaytab.cancel=Cancel +windows.wndsettings$displaytab.portrait=Switch to portrait +windows.wndsettings$displaytab.landscape=Switch to landscape windows.wndsettings$displaytab.scale=Display Scale windows.wndsettings$displaytab.brightness=Brightness windows.wndsettings$displaytab.dark=Dark diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java index 5fd95424c..a2afadd8b 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -192,6 +192,7 @@ public class WndSettings extends WndTabbed { CheckBox chkFullscreen; OptionSlider optScale; CheckBox chkSaver; + RedButton btnOrientation; ColorBlock sep2; OptionSlider optBrightness; OptionSlider optVisGrid; @@ -267,6 +268,18 @@ public class WndSettings extends WndTabbed { add( chkSaver ); } + if (DeviceCompat.isAndroid()) { + btnOrientation = new RedButton(PixelScene.landscape() ? + Messages.get(this, "portrait") + : Messages.get(this, "landscape")) { + @Override + protected void onClick() { + SPDSettings.landscape(!PixelScene.landscape()); + } + }; + add(btnOrientation); + } + sep2 = new ColorBlock(1, 1, 0xFF000000); add(sep2); @@ -317,6 +330,11 @@ public class WndSettings extends WndTabbed { } } + if (btnOrientation != null) { + btnOrientation.setRect(0, bottom + GAP, width, BTN_HEIGHT); + bottom = btnOrientation.bottom(); + } + if (optScale != null){ optScale.setRect(0, bottom + GAP, width, SLIDER_HEIGHT); bottom = optScale.bottom();