From 4deb71226acee29a06dd5440cd3fdaad36ba4543 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 21 Sep 2025 15:24:48 -0400 Subject: [PATCH] v3.2.5: added a button to hide the UI in the main menu --- .../scenes/TitleScene.java | 151 +++++++++++++++--- 1 file changed, 128 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java index 3b1b91069..eaaa65623 100644 --- a/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java +++ b/core/src/main/java/com/shatteredpixel/shatteredpixeldungeon/scenes/TitleScene.java @@ -37,6 +37,7 @@ import com.shatteredpixel.shatteredpixeldungeon.services.updates.AvailableUpdate import com.shatteredpixel.shatteredpixeldungeon.services.updates.Updates; import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite; import com.shatteredpixel.shatteredpixeldungeon.ui.ExitButton; +import com.shatteredpixel.shatteredpixeldungeon.ui.IconButton; import com.shatteredpixel.shatteredpixeldungeon.ui.Icons; import com.shatteredpixel.shatteredpixeldungeon.ui.StyledButton; import com.shatteredpixel.shatteredpixeldungeon.ui.TitleBackground; @@ -45,19 +46,41 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions; import com.shatteredpixel.shatteredpixeldungeon.windows.WndSettings; import com.shatteredpixel.shatteredpixeldungeon.windows.WndVictoryCongrats; import com.watabou.glwrap.Blending; +import com.watabou.input.PointerEvent; import com.watabou.noosa.BitmapText; import com.watabou.noosa.Camera; import com.watabou.noosa.Game; import com.watabou.noosa.Image; +import com.watabou.noosa.PointerArea; import com.watabou.noosa.audio.Music; +import com.watabou.noosa.tweeners.Tweener; import com.watabou.utils.ColorMath; import com.watabou.utils.DeviceCompat; +import com.watabou.utils.GameMath; import com.watabou.utils.RectF; import java.util.Date; public class TitleScene extends PixelScene { - + + private Image title; + private Fireball leftFB; + private Fireball rightFB; + private Image signs; + + private StyledButton btnPlay; + private StyledButton btnSupport; + private StyledButton btnRankings; + private StyledButton btnJournal; + private StyledButton btnNews; + private StyledButton btnChanges; + private StyledButton btnSettings; + private StyledButton btnAbout; + + private BitmapText version; + private IconButton btnFade; + private ExitButton btnExit; + @Override public void create() { @@ -81,7 +104,7 @@ public class TitleScene extends PixelScene { w -= insets.left + insets.right; h -= insets.top + insets.bottom; - Image title = BannerSprites.get( landscape() ? BannerSprites.Type.TITLE_LAND : BannerSprites.Type.TITLE_PORT); + title = BannerSprites.get( landscape() ? BannerSprites.Type.TITLE_LAND : BannerSprites.Type.TITLE_PORT); add( title ); float topRegion = Math.max(title.height - 6, h*0.45f); @@ -92,19 +115,20 @@ public class TitleScene extends PixelScene { align(title); if (landscape()){ - placeTorch(title.x + 30, title.y + 35); - placeTorch(title.x + title.width - 30, title.y + 35); + leftFB = placeTorch(title.x + 30, title.y + 35); + rightFB = placeTorch(title.x + title.width - 30, title.y + 35); } else { - placeTorch(title.x + 16, title.y + 70); - placeTorch(title.x + title.width - 16, title.y + 70); + leftFB = placeTorch(title.x + 16, title.y + 70); + rightFB = placeTorch(title.x + title.width - 16, title.y + 70); } - Image signs = new Image(BannerSprites.get( landscape() ? BannerSprites.Type.TITLE_GLOW_LAND : BannerSprites.Type.TITLE_GLOW_PORT)){ + signs = new Image(BannerSprites.get( landscape() ? BannerSprites.Type.TITLE_GLOW_LAND : BannerSprites.Type.TITLE_GLOW_PORT)){ private float time = 0; @Override public void update() { super.update(); am = Math.max(0f, (float)Math.sin( time += Game.elapsed )); + am = Math.min(am, title.am); if (time >= 1.5f*Math.PI) time = 0; } @Override @@ -120,7 +144,7 @@ public class TitleScene extends PixelScene { final Chrome.Type GREY_TR = Chrome.Type.GREY_BUTTON_TR; - StyledButton btnPlay = new StyledButton(GREY_TR, Messages.get(this, "enter")){ + btnPlay = new StyledButton(GREY_TR, Messages.get(this, "enter")){ @Override protected void onClick() { if (GamesInProgress.checkAll().size() == 0){ @@ -147,10 +171,10 @@ public class TitleScene extends PixelScene { btnPlay.icon(Icons.get(Icons.ENTER)); add(btnPlay); - StyledButton btnSupport = new SupportButton(GREY_TR, Messages.get(this, "support")); + btnSupport = new SupportButton(GREY_TR, Messages.get(this, "support")); add(btnSupport); - StyledButton btnRankings = new StyledButton(GREY_TR,Messages.get(this, "rankings")){ + btnRankings = new StyledButton(GREY_TR,Messages.get(this, "rankings")){ @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade( RankingsScene.class ); @@ -160,27 +184,27 @@ public class TitleScene extends PixelScene { add(btnRankings); Dungeon.daily = Dungeon.dailyReplay = false; - StyledButton btnBadges = new StyledButton(GREY_TR, Messages.get(this, "journal")){ + btnJournal = new StyledButton(GREY_TR, Messages.get(this, "journal")){ @Override protected void onClick() { ShatteredPixelDungeon.switchNoFade( JournalScene.class ); } }; - btnBadges.icon(Icons.get(Icons.JOURNAL)); - add(btnBadges); + btnJournal.icon(Icons.get(Icons.JOURNAL)); + add(btnJournal); - StyledButton btnNews = new NewsButton(GREY_TR, Messages.get(this, "news")); + btnNews = new NewsButton(GREY_TR, Messages.get(this, "news")); btnNews.icon(Icons.get(Icons.NEWS)); add(btnNews); - StyledButton btnChanges = new ChangesButton(GREY_TR, Messages.get(this, "changes")); + btnChanges = new ChangesButton(GREY_TR, Messages.get(this, "changes")); btnChanges.icon(Icons.get(Icons.CHANGES)); add(btnChanges); - StyledButton btnSettings = new SettingsButton(GREY_TR, Messages.get(this, "settings")); + btnSettings = new SettingsButton(GREY_TR, Messages.get(this, "settings")); add(btnSettings); - StyledButton btnAbout = new StyledButton(GREY_TR, Messages.get(this, "about")){ + btnAbout = new StyledButton(GREY_TR, Messages.get(this, "about")){ @Override protected void onClick() { ShatteredPixelDungeon.switchScene( AboutScene.class ); @@ -201,8 +225,8 @@ public class TitleScene extends PixelScene { align(btnPlay); btnSupport.setRect(btnPlay.right()+2, btnPlay.top(), btnPlay.width(), BTN_HEIGHT); btnRankings.setRect(btnPlay.left(), btnPlay.bottom()+ GAP, (float) (Math.floor(buttonAreaWidth/3f)-1), BTN_HEIGHT); - btnBadges.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT); - btnNews.setRect(btnBadges.right()+2, btnBadges.top(), btnRankings.width(), BTN_HEIGHT); + btnJournal.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT); + btnNews.setRect(btnJournal.right()+2, btnJournal.top(), btnRankings.width(), BTN_HEIGHT); btnSettings.setRect(btnRankings.left(), btnRankings.bottom() + GAP, btnRankings.width(), BTN_HEIGHT); btnChanges.setRect(btnSettings.right()+2, btnSettings.top(), btnRankings.width(), BTN_HEIGHT); btnAbout.setRect(btnChanges.right()+2, btnSettings.top(), btnRankings.width(), BTN_HEIGHT); @@ -211,22 +235,65 @@ public class TitleScene extends PixelScene { align(btnPlay); btnSupport.setRect(btnPlay.left(), btnPlay.bottom()+ GAP, btnPlay.width(), BTN_HEIGHT); btnRankings.setRect(btnPlay.left(), btnSupport.bottom()+ GAP, (btnPlay.width()/2)-1, BTN_HEIGHT); - btnBadges.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT); + btnJournal.setRect(btnRankings.right()+2, btnRankings.top(), btnRankings.width(), BTN_HEIGHT); btnNews.setRect(btnRankings.left(), btnRankings.bottom()+ GAP, btnRankings.width(), BTN_HEIGHT); btnChanges.setRect(btnNews.right()+2, btnNews.top(), btnNews.width(), BTN_HEIGHT); btnSettings.setRect(btnNews.left(), btnNews.bottom()+GAP, btnRankings.width(), BTN_HEIGHT); btnAbout.setRect(btnSettings.right()+2, btnSettings.top(), btnSettings.width(), BTN_HEIGHT); } - BitmapText version = new BitmapText( "v" + Game.version, pixelFont); + version = new BitmapText( "v" + Game.version, pixelFont); version.measure(); version.hardlight( 0x888888 ); version.x = insets.left + w - version.width() - (DeviceCompat.isDesktop() ? 4 : 8); version.y = insets.top + h - version.height() - (DeviceCompat.isDesktop() ? 2 : 4); add( version ); + btnFade = new IconButton(Icons.CHEVRON.get()){ + @Override + protected void onClick() { + enable(false); + parent.add(new Tweener(parent, 0.5f) { + @Override + protected void updateValues(float progress) { + if (!btnFade.active) { + uiAlpha = 1 - progress; + updateFade(); + } + } + }); + } + }; + btnFade.icon().originToCenter(); + btnFade.icon().angle = 180f; + btnFade.setRect(btnAreaLeft + (buttonAreaWidth-16)/2, btnAbout.bottom() + GAP/2 + 2, 16, 10); + if (btnFade.bottom() > camera.main.height){ + btnFade.setPos(btnFade.left(), btnFade.top() - (btnFade.bottom()-camera.main.height)); + } + add(btnFade); + + PointerArea fadeResetter = new PointerArea(0, 0, Camera.main.width, Camera.main.height){ + @Override + public boolean onSignal(PointerEvent event) { + if (event != null && event.type == PointerEvent.Type.UP && !btnPlay.active){ + parent.add(new Tweener(parent, 0.5f) { + @Override + protected void updateValues(float progress) { + uiAlpha = progress; + updateFade(); + if (progress >= 1){ + btnFade.enable(true); + } + } + }); + } + return false; + } + }; + add(fadeResetter); + if (DeviceCompat.isDesktop()) { - ExitButton btnExit = new ExitButton(); + btnExit = new ExitButton(); btnExit.setPos( w - btnExit.width(), 0 ); add( btnExit ); } @@ -240,13 +307,51 @@ public class TitleScene extends PixelScene { fadeIn(); } - private void placeTorch( float x, float y ) { + private float uiAlpha; + + public void updateFade() { + float alpha = GameMath.gate(0f, uiAlpha, 1f); + + title.am = alpha; + leftFB.am = alpha; + rightFB.am = alpha; + //signs.am = alpha; handles this itself + + btnPlay.enable(alpha != 0); + btnSupport.enable(alpha != 0); + btnRankings.enable(alpha != 0); + btnJournal.enable(alpha != 0); + btnNews.enable(alpha != 0); + btnChanges.enable(alpha != 0); + btnSettings.enable(alpha != 0); + btnAbout.enable(alpha != 0); + + btnPlay.alpha(alpha); + btnSupport.alpha(alpha); + btnRankings.alpha(alpha); + btnJournal.alpha(alpha); + btnNews.alpha(alpha); + btnChanges.alpha(alpha); + btnSettings.alpha(alpha); + btnAbout.alpha(alpha); + + version.alpha(alpha); + btnFade.icon().alpha(alpha); + if (btnExit != null){ + btnExit.enable(alpha != 0); + btnExit.icon().alpha(alpha); + } + + } + + private Fireball placeTorch(float x, float y ) { Fireball fb = new Fireball(); fb.x = x - fb.width()/2f; fb.y = y - fb.height(); align(fb); add( fb ); + return fb; } private static class NewsButton extends StyledButton {