v0.9.4: added main code module support for iOS

This commit is contained in:
Evan Debenham 2021-06-25 15:54:04 -04:00
parent 9b63eb5e09
commit d610383717
6 changed files with 39 additions and 8 deletions

View File

@ -53,6 +53,9 @@ public class Game implements ApplicationListener {
public static int width; public static int width;
public static int height; public static int height;
//number of pixels from bottom of view before rendering starts
public static int bottomInset;
// Density: mdpi=1, hdpi=1.5, xhdpi=2... // Density: mdpi=1, hdpi=1.5, xhdpi=2...
public static float density = 1; public static float density = 1;
@ -299,7 +302,7 @@ public class Game implements ApplicationListener {
} }
public static void vibrate( int milliseconds ) { public static void vibrate( int milliseconds ) {
Gdx.input.vibrate(milliseconds); platform.vibrate( milliseconds );
} }
public interface SceneChangeCallback{ public interface SceneChangeCallback{

View File

@ -167,11 +167,11 @@ public class NoosaScript extends Script {
// because for some reason all other openGL operations work on virtual pixels // because for some reason all other openGL operations work on virtual pixels
// but glScissor operations work on real pixels // but glScissor operations work on real pixels
float xScale = (Gdx.graphics.getBackBufferWidth() / (float)Game.width ); float xScale = (Gdx.graphics.getBackBufferWidth() / (float)Game.width );
float yScale = (Gdx.graphics.getBackBufferHeight() / (float)Game.height ); float yScale = ((Gdx.graphics.getBackBufferHeight()-Game.bottomInset) / (float)Game.height );
Gdx.gl20.glScissor( Gdx.gl20.glScissor(
Math.round(camera.x * xScale), Math.round(camera.x * xScale),
Math.round((Game.height - camera.screenHeight - camera.y) * yScale), Math.round((Game.height - camera.screenHeight - camera.y) * yScale) + Game.bottomInset,
Math.round(camera.screenWidth * xScale), Math.round(camera.screenWidth * xScale),
Math.round(camera.screenHeight * yScale)); Math.round(camera.screenHeight * yScale));
} else { } else {

View File

@ -32,14 +32,25 @@ public class DeviceCompat {
public static boolean supportsFullScreen(){ public static boolean supportsFullScreen(){
switch (Gdx.app.getType()){ switch (Gdx.app.getType()){
case Android: case Android:
//Android 4.4 KitKat and later, this is for immersive mode //Android 4.4+ supports hiding UI via immersive mode
return Gdx.app.getVersion() >= 19; return Gdx.app.getVersion() >= 19;
case iOS:
//iOS supports hiding UI via drawing into the gesture safe area
return Gdx.graphics.getSafeInsetBottom() != 0;
default: default:
//TODO implement functionality for other platforms here //TODO implement functionality for other platforms here
return true; return true;
} }
} }
public static boolean isAndroid(){
return Gdx.app.getType() == Application.ApplicationType.Android;
}
public static boolean isiOS(){
return Gdx.app.getType() == Application.ApplicationType.iOS;
}
public static boolean isDesktop(){ public static boolean isDesktop(){
return Gdx.app.getType() == Application.ApplicationType.Desktop; return Gdx.app.getType() == Application.ApplicationType.Desktop;
} }

View File

@ -21,6 +21,7 @@
package com.watabou.utils; package com.watabou.utils;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
public abstract class PlatformSupport { public abstract class PlatformSupport {
@ -40,6 +41,11 @@ public abstract class PlatformSupport {
public abstract void onSelect( boolean positive, String text ); public abstract void onSelect( boolean positive, String text );
} }
public void vibrate( int millis ){
//regular GDX vibration by default
Gdx.input.vibrate( millis );
}
//TODO should consider spinning this into its own class, rather than platform support getting ever bigger //TODO should consider spinning this into its own class, rather than platform support getting ever bigger
public abstract void setupFontGenerators(int pageSize, boolean systemFont ); public abstract void setupFontGenerators(int pageSize, boolean systemFont );

View File

@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.WelcomeScene;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.DeviceCompat;
import com.watabou.utils.PlatformSupport; import com.watabou.utils.PlatformSupport;
public class ShatteredPixelDungeon extends Game { public class ShatteredPixelDungeon extends Game {
@ -122,6 +123,16 @@ public class ShatteredPixelDungeon extends Game {
} }
@Override
public void finish() {
if (!DeviceCompat.isiOS()) {
super.finish();
} else {
//can't exit on iOS (Apple guidelines), so just go to title screen
switchScene(TitleScene.class);
}
}
public static void switchNoFade(Class<? extends PixelScene> c){ public static void switchNoFade(Class<? extends PixelScene> c){
switchNoFade(c, null); switchNoFade(c, null);
} }

View File

@ -223,7 +223,7 @@ public class WndSettings extends WndTabbed {
add(optScale); add(optScale);
} }
if (!DeviceCompat.isDesktop() && PixelScene.maxScreenZoom >= 2) { if (DeviceCompat.isAndroid() && PixelScene.maxScreenZoom >= 2) {
chkSaver = new CheckBox(Messages.get(this, "saver")) { chkSaver = new CheckBox(Messages.get(this, "saver")) {
@Override @Override
protected void onClick() { protected void onClick() {