From 061a28dd4b8c5c5bfa3f3665cdb8a3d3d09f3551 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Thu, 31 Mar 2022 01:32:44 -0400 Subject: [PATCH] v1.2.1: added a new game and menu button after game over --- .../actors/hero/Hero.java | 8 ++- .../scenes/GameScene.java | 61 ++++++++++++++++++- .../scenes/PixelScene.java | 3 +- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java index 927f03425..1c5e52ede 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/actors/hero/Hero.java @@ -1758,7 +1758,13 @@ public class Hero extends Char { } } - GameScene.gameOver(); + Game.runOnRenderThread(new Callback() { + @Override + public void call() { + GameScene.gameOver(); + Sample.INSTANCE.play( Assets.Sounds.DEATH ); + } + }); if (cause instanceof Hero.Doom) { ((Hero.Doom)cause).onDeath(); diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java index 19f46fdd5..a6a36fa95 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/GameScene.java @@ -24,7 +24,9 @@ package com.shatteredpixel.shatteredpixeldungeon.scenes; import com.shatteredpixel.shatteredpixeldungeon.Assets; import com.shatteredpixel.shatteredpixeldungeon.Badges; import com.shatteredpixel.shatteredpixeldungeon.Challenges; +import com.shatteredpixel.shatteredpixeldungeon.Chrome; import com.shatteredpixel.shatteredpixeldungeon.Dungeon; +import com.shatteredpixel.shatteredpixeldungeon.GamesInProgress; import com.shatteredpixel.shatteredpixeldungeon.Rankings; import com.shatteredpixel.shatteredpixeldungeon.SPDSettings; import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; @@ -90,6 +92,7 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.ResumeIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.RightClickMenu; import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane; +import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton; import com.shatteredpixel.shatteredpixeldungeon.ui.Tag; import com.shatteredpixel.shatteredpixeldungeon.ui.TargetHealthIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.Toast; @@ -104,6 +107,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoMob; import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoPlant; import com.shatteredpixel.shatteredpixeldungeon.windows.WndInfoTrap; +import com.shatteredpixel.shatteredpixeldungeon.windows.WndKeyBindings; import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage; import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.shatteredpixel.shatteredpixeldungeon.windows.WndResurrect; @@ -583,6 +587,8 @@ public class GameScene extends PixelScene { } if (ankh != null) { add(new WndResurrect(ankh)); + } else { + gameOver(); } } @@ -884,8 +890,11 @@ public class GameScene extends PixelScene { private void showBanner( Banner banner ) { banner.camera = uiCamera; + + float offset = Camera.main.centerOffset.y; banner.x = align( uiCamera, (uiCamera.width - banner.width) / 2 ); - banner.y = align( uiCamera, (uiCamera.height - banner.height) / 3 ); + banner.y = align( uiCamera, (uiCamera.height - banner.height) / 2 - banner.height/2 - 16 - offset ); + addToFront( banner ); } @@ -1183,8 +1192,54 @@ public class GameScene extends PixelScene { Banner gameOver = new Banner( BannerSprites.get( BannerSprites.Type.GAME_OVER ) ); gameOver.show( 0x000000, 1f ); scene.showBanner( gameOver ); - - Sample.INSTANCE.play( Assets.Sounds.DEATH ); + + StyledButton restart = new StyledButton(Chrome.Type.GREY_BUTTON_TR, Messages.get(StartScene.class, "new"), 9){ + @Override + protected void onClick() { + InterlevelScene.noStory = true; + GamesInProgress.selectedClass = Dungeon.hero.heroClass; + GamesInProgress.curSlot = GamesInProgress.firstEmpty(); + ShatteredPixelDungeon.switchScene(HeroSelectScene.class); + } + + @Override + public void update() { + bg.alpha(gameOver.am); + icon.alpha(gameOver.am); + text.alpha(gameOver.am); + } + }; + restart.camera = uiCamera; + restart.icon(Icons.get(Icons.ENTER)); + float offset = Camera.main.centerOffset.y; + restart.setSize(Math.max(80, restart.reqWidth()), 20); + restart.setPos( + align(uiCamera, (restart.camera.width - restart.width()) / 2), + align(uiCamera, (restart.camera.height - restart.height()) / 2 + restart.height()/2 + 16 - offset) + ); + scene.add(restart); + + StyledButton menu = new StyledButton(Chrome.Type.GREY_BUTTON_TR, Messages.get(WndKeyBindings.class, "menu"), 9){ + @Override + protected void onClick() { + GameScene.show(new WndGame()); + } + + @Override + public void update() { + bg.alpha(gameOver.am); + icon.alpha(gameOver.am); + text.alpha(gameOver.am); + } + }; + menu.camera = uiCamera; + menu.icon(Icons.get(Icons.PREFS)); + menu.setSize(Math.max(80, menu.reqWidth()), 20); + menu.setPos( + align(uiCamera, (menu.camera.width - menu.width()) / 2), + restart.bottom() + 2 + ); + scene.add(menu); } public static void bossSlain() { diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java index a6b2ebd60..52f738114 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/PixelScene.java @@ -295,8 +295,9 @@ public class PixelScene extends Scene { public void call() { BadgeBanner banner = BadgeBanner.show( badge.image ); banner.camera = uiCamera; + float offset = Camera.main.centerOffset.y; banner.x = align( banner.camera, (banner.camera.width - banner.width) / 2 ); - banner.y = align( banner.camera, (banner.camera.height - banner.height) / 3 ); + banner.y = align( uiCamera, (uiCamera.height - banner.height) / 2 - banner.height/2 - 16 - offset ); Scene s = Game.scene(); if (s != null) s.add( banner ); }