diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Game.java b/SPD-classes/src/main/java/com/watabou/noosa/Game.java index 8cf2180d6..6d6a425aa 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Game.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Game.java @@ -142,26 +142,54 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou view.setRenderer( this ); view.setOnTouchListener( this ); setContentView( view ); + + //so first call to onstart/onresume calls correct logic. + paused = true; } - private boolean paused = false; + private boolean paused; + + //Checks for gingerbread are here due to minor activity lifecycle differences @Override public void onStart() { super.onStart(); - now = 0; - paused = false; - view.onResume(); - - Music.INSTANCE.resume(); - Sample.INSTANCE.resume(); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1){ + resumeGame(); + } } @Override public void onStop() { super.onStop(); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1){ + pauseGame(); + } + } + + @Override + protected void onResume() { + super.onResume(); + + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1){ + resumeGame(); + } + } + + @Override + protected void onPause() { + super.onPause(); + + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1){ + pauseGame(); + } + } + + public void pauseGame(){ + if (paused) return; + if (scene != null) { scene.pause(); } @@ -174,6 +202,22 @@ public class Game extends Activity implements GLSurfaceView.Renderer, View.OnTou Sample.INSTANCE.pause(); } + public void resumeGame(){ + if (!paused) return; + + now = 0; + paused = false; + view.onResume(); + + Music.INSTANCE.resume(); + Sample.INSTANCE.resume(); + } + + public static void quitGame(){ + Game.instance.finish(); + System.exit(0); + } + public boolean isPaused(){ return paused; } diff --git a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java index c34e25620..a166a5c17 100644 --- a/SPD-classes/src/main/java/com/watabou/noosa/Scene.java +++ b/SPD-classes/src/main/java/com/watabou/noosa/Scene.java @@ -71,7 +71,7 @@ public class Scene extends Group { } protected void onBackPressed() { - Game.instance.finish(); + Game.quitGame(); } protected void onMenuPressed() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java index e11ffdad0..6ce2c2dff 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/items/wands/CursedWand.java @@ -416,7 +416,7 @@ public class CursedWand { @Override protected void onSelect(int index) { - Game.instance.finish(); + ShatteredPixelDungeon.quitGame(); } @Override diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java index 28eef5aef..686c1a4f1 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/ui/ExitButton.java @@ -70,7 +70,7 @@ public class ExitButton extends Button { @Override protected void onClick() { if (Game.scene() instanceof TitleScene) { - Game.instance.finish(); + ShatteredPixelDungeon.quitGame(); } else { ShatteredPixelDungeon.switchNoFade( TitleScene.class ); } diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGame.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGame.java index 6e9f59663..f7513bb25 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGame.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/windows/WndGame.java @@ -108,7 +108,12 @@ public class WndGame extends Window { new RedButton( Messages.get(this, "exit") ) { @Override protected void onClick() { - Game.instance.finish(); + try { + Dungeon.saveAll(); + } catch (IOException e) { + ShatteredPixelDungeon.reportException(e); + } + ShatteredPixelDungeon.quitGame(); } } );