diff --git a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java index 1753ba722..c8ca4df65 100644 --- a/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java +++ b/SPD-classes/src/main/java/com/watabou/utils/PlatformSupport.java @@ -43,6 +43,10 @@ public abstract class PlatformSupport { Gdx.input.vibrate( millis ); } + public void setHonorSilentSwitch( boolean value ){ + //does nothing by default + } + //TODO should consider spinning this into its own class, rather than platform support getting ever bigger protected static HashMap> fonts; diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java index 2dc5a4ce2..d5a8d17db 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/SPDSettings.java @@ -201,6 +201,7 @@ public class SPDSettings extends GameSettings { public static final String KEY_MUSIC_VOL = "music_vol"; public static final String KEY_SOUND_FX = "soundfx"; public static final String KEY_SFX_VOL = "sfx_vol"; + public static final String KEY_IGNORE_SILENT= "ignore_silent"; public static void music( boolean value ) { Music.INSTANCE.enable( value ); @@ -237,6 +238,15 @@ public class SPDSettings extends GameSettings { public static int SFXVol() { return getInt( KEY_SFX_VOL, 10, 0, 10 ); } + + public static void ignoreSilentMode( boolean value ){ + put( KEY_IGNORE_SILENT, value); + Game.platform.setHonorSilentSwitch(!value); + } + + public static boolean ignoreSilentMode(){ + return getBoolean( KEY_IGNORE_SILENT, false); + } //Languages and Font 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 6f4e650d0..346cb6a97 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndSettings.java @@ -634,6 +634,8 @@ public class WndSettings extends WndTabbed { ColorBlock sep2; OptionSlider optSFX; CheckBox chkMuteSFX; + ColorBlock sep3; + CheckBox chkIgnoreSilent; @Override protected void createChildren() { @@ -695,6 +697,23 @@ public class WndSettings extends WndTabbed { }; chkMuteSFX.checked(!SPDSettings.soundFx()); add( chkMuteSFX ); + + //TODO translate for v1.2.0! + if (DeviceCompat.isiOS() && Messages.lang() == Languages.ENGLISH){ + + sep3 = new ColorBlock(1, 1, 0xFF000000); + add(sep3); + + chkIgnoreSilent = new CheckBox( "Ignore Silent Mode" ){ + @Override + protected void onClick() { + super.onClick(); + SPDSettings.ignoreSilentMode(checked()); + } + }; + chkIgnoreSilent.checked(SPDSettings.ignoreSilentMode()); + add(chkIgnoreSilent); + } } @Override @@ -703,16 +722,36 @@ public class WndSettings extends WndTabbed { sep1.size(width, 1); sep1.y = title.bottom() + 2*GAP; - optMusic.setRect(0, sep1.y + 1 + GAP, width, SLIDER_HEIGHT); - chkMusicMute.setRect(0, optMusic.bottom() + GAP, width, BTN_HEIGHT); + if (width > 200) { + optMusic.setRect(0, sep1.y + 1 + GAP, width/2-1, SLIDER_HEIGHT); + chkMusicMute.setRect(0, optMusic.bottom() + GAP, width/2-1, BTN_HEIGHT); - sep2.size(width, 1); - sep2.y = chkMusicMute.bottom() + GAP; + sep2.size(width, 1); + sep2.y = sep1.y; //just have them overlap - optSFX.setRect(0, sep2.y + 1 + GAP, width, SLIDER_HEIGHT); - chkMuteSFX.setRect(0, optSFX.bottom() + GAP, width, BTN_HEIGHT); + optSFX.setRect(optMusic.right()+2, sep2.y + 1 + GAP, width/2-1, SLIDER_HEIGHT); + chkMuteSFX.setRect(chkMusicMute.right()+2, optSFX.bottom() + GAP, width/2-1, BTN_HEIGHT); + + } else { + optMusic.setRect(0, sep1.y + 1 + GAP, width, SLIDER_HEIGHT); + chkMusicMute.setRect(0, optMusic.bottom() + GAP, width, BTN_HEIGHT); + + sep2.size(width, 1); + sep2.y = chkMusicMute.bottom() + GAP; + + optSFX.setRect(0, sep2.y + 1 + GAP, width, SLIDER_HEIGHT); + chkMuteSFX.setRect(0, optSFX.bottom() + GAP, width, BTN_HEIGHT); + } height = chkMuteSFX.bottom(); + + if (chkIgnoreSilent != null){ + sep3.size(width, 1); + sep3.y = chkMuteSFX.bottom() + GAP; + + chkIgnoreSilent.setRect(0, sep3.y + 1 + GAP, width, BTN_HEIGHT); + height = chkIgnoreSilent.bottom(); + } } } diff --git a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSLauncher.java b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSLauncher.java index 823a71a33..41fa7c6a8 100644 --- a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSLauncher.java +++ b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSLauncher.java @@ -3,6 +3,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ios; import com.badlogic.gdx.Files; import com.badlogic.gdx.backends.iosrobovm.IOSApplication; import com.badlogic.gdx.backends.iosrobovm.IOSApplicationConfiguration; +import com.badlogic.gdx.backends.iosrobovm.IOSPreferences; import com.badlogic.gdx.graphics.glutils.HdpiMode; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; @@ -18,12 +19,17 @@ import org.robovm.apple.foundation.NSAutoreleasePool; import org.robovm.apple.foundation.NSBundle; import org.robovm.apple.foundation.NSDictionary; import org.robovm.apple.foundation.NSException; +import org.robovm.apple.foundation.NSMutableDictionary; +import org.robovm.apple.foundation.NSObject; import org.robovm.apple.foundation.NSProcessInfo; +import org.robovm.apple.foundation.NSString; import org.robovm.apple.glkit.GLKViewDrawableColorFormat; import org.robovm.apple.glkit.GLKViewDrawableDepthFormat; import org.robovm.apple.uikit.UIApplication; import org.robovm.apple.uikit.UIScreen; +import java.io.File; + public class IOSLauncher extends IOSApplication.Delegate { @Override protected IOSApplication createApplication() { @@ -55,12 +61,32 @@ public class IOSLauncher extends IOSApplication.Delegate { FileUtils.setDefaultFileProperties(Files.FileType.Local, ""); + //sets up preferences early so they can be read. + //this is mostly a copy-paste from IOSApplication.getPreferences + File libraryPath = new File(System.getenv("HOME"), "Library"); + File finalPath = new File(libraryPath, SPDSettings.DEFAULT_PREFS_FILE + ".plist"); + + @SuppressWarnings("unchecked") + NSMutableDictionary nsDictionary = (NSMutableDictionary)NSMutableDictionary + .read(finalPath); + + // if it fails to get an existing dictionary, create a new one. + if (nsDictionary == null) { + nsDictionary = new NSMutableDictionary(); + nsDictionary.write(finalPath, false); + } + SPDSettings.set(new IOSPreferences(nsDictionary, finalPath.getAbsolutePath())); + //end of prefs setup + IOSApplicationConfiguration config = new IOSApplicationConfiguration(); config.colorFormat = GLKViewDrawableColorFormat.RGBA8888; config.depthFormat = GLKViewDrawableDepthFormat.None; config.hdpiMode = HdpiMode.Pixels; + config.hideHomeIndicator = SPDSettings.fullscreen(); + config.overrideRingerSwitch = SPDSettings.ignoreSilentMode(); + if (NSProcessInfo.getSharedProcessInfo().getOperatingSystemVersion().getMajorVersion() >= 11) { config.preferredFramesPerSecond = (int)(UIScreen.getMainScreen().getMaximumFramesPerSecond()); } diff --git a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java index 97a16e0b8..50890e7c6 100644 --- a/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java +++ b/ios/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ios/IOSPlatformSupport.java @@ -2,6 +2,7 @@ package com.shatteredpixel.shatteredpixeldungeon.ios; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.iosrobovm.IOSGraphics; +import com.badlogic.gdx.backends.iosrobovm.objectal.OALSimpleAudio; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -66,6 +67,11 @@ public class IOSPlatformSupport extends PlatformSupport { AudioServices.playSystemSound(1520); } + @Override + public void setHonorSilentSwitch( boolean value ) { + OALSimpleAudio.sharedInstance().setHonorSilentSwitch(value); + } + /* FONT SUPPORT */ //custom pixel font, for use with Latin and Cyrillic languages