From 35bc80767fa1e3ad17a41d988e2a87641d3dac1f Mon Sep 17 00:00:00 2001 From: rwalters Date: Mon, 12 May 2025 23:28:00 -0400 Subject: [PATCH] Fix exit to world map edge cases (Adventure) (#7522) * Fixing an issue in which touching the space the map occupies outside of the world map does not allow the player to move (very relevant on maps with content in the top left corner) * Attempt to band-aid two problems relating to showing a dialog to return to the main map, one in which some patrolling enemies ignore the menu restriction and another in which such enemies touching a player who is transitioning out of a dungeon causing a soft lock upon returning to the map --- .../src/forge/adventure/scene/TileMapScene.java | 2 +- .../src/forge/adventure/stage/GameHUD.java | 8 +++++++- .../src/forge/adventure/stage/GameStage.java | 13 +++++++++---- .../src/forge/adventure/stage/MapStage.java | 10 +++++++++- .../src/forge/adventure/util/SaveFileContent.java | 2 +- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/forge-gui-mobile/src/forge/adventure/scene/TileMapScene.java b/forge-gui-mobile/src/forge/adventure/scene/TileMapScene.java index aba9adb902d..640e85523b3 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/TileMapScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/TileMapScene.java @@ -155,7 +155,7 @@ public class TileMapScene extends HudScene { @Override public boolean isInHudOnlyMode() { - return MapStage.getInstance().getDialogOnlyInput(); + return MapStage.getInstance().isDialogOnlyInput(); } public void loadNext(String targetMap, int entryTargetObject) { diff --git a/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java b/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java index c93bdcfb128..a63f6cc533c 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java +++ b/forge-gui-mobile/src/forge/adventure/stage/GameHUD.java @@ -313,7 +313,7 @@ public class GameHUD extends Stage { return true; } //auto follow touchpad - if (GuiBase.isAndroid() && !MapStage.getInstance().getDialogOnlyInput() && !console.isVisible()) { + if (GuiBase.isAndroid() && !MapStage.getInstance().isDialogOnlyInput() && !console.isVisible()) { if (!(Controls.actorContainsVector(avatar, touch)) // not inside avatar bounds && !(Controls.actorContainsVector(miniMap, touch)) // not inside map bounds && !(Controls.actorContainsVector(gamehud, touch)) //not inside gamehud bounds @@ -687,6 +687,7 @@ public class GameHUD extends Stage { } private void exitDungeonCallback() { + MapStage.getInstance().onBeginLeavingDungeon(); hideDialog(true); } @@ -874,6 +875,8 @@ public class GameHUD extends Stage { dialog.show(this, Actions.show()); dialog.setPosition((this.getWidth() - dialog.getWidth()) / 2, (this.getHeight() - dialog.getHeight()) / 2); dialogOnlyInput = true; + gameStage.hudIsShowingDialog(true); + MapStage.getInstance().hudIsShowingDialog(true); if (Forge.hasGamepad() && !dialogButtonMap.isEmpty()) this.setKeyboardFocus(dialogButtonMap.first()); } @@ -891,7 +894,10 @@ public class GameHUD extends Stage { return true; } })); + dialogOnlyInput = false; + gameStage.hudIsShowingDialog(false); + MapStage.getInstance().hudIsShowingDialog(false); } private void selectNextDialogButton() { diff --git a/forge-gui-mobile/src/forge/adventure/stage/GameStage.java b/forge-gui-mobile/src/forge/adventure/stage/GameStage.java index 22dc194fa79..e2f032b4423 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/GameStage.java +++ b/forge-gui-mobile/src/forge/adventure/stage/GameStage.java @@ -85,10 +85,6 @@ public abstract class GameStage extends Stage { protected final Array dialogButtonMap = new Array<>(); TextraButton selectedKey; - public boolean getDialogOnlyInput() { - return dialogOnlyInput; - } - public Dialog getDialog() { return dialog; } @@ -113,6 +109,7 @@ public abstract class GameStage extends Stage { dialog.show(dialogStage, Actions.show()); dialog.setPosition((dialogStage.getWidth() - dialog.getWidth()) / 2, (dialogStage.getHeight() - dialog.getHeight()) / 2); dialogOnlyInput = true; + if (Forge.hasGamepad() && !dialogButtonMap.isEmpty()) dialogStage.setKeyboardFocus(dialogButtonMap.first()); } @@ -124,6 +121,14 @@ public abstract class GameStage extends Stage { dialog.clearListeners(); } + /** + * Triggered when the hud is showing a dialog, which is tracked separately + * @param isShowing Whether a dialog is currently showing + */ + public void hudIsShowingDialog(boolean isShowing) { + dialogOnlyInput = isShowing; + } + public void effectDialog(EffectData effectData) { dialog.getButtonTable().clear(); dialog.getContentTable().clear(); diff --git a/forge-gui-mobile/src/forge/adventure/stage/MapStage.java b/forge-gui-mobile/src/forge/adventure/stage/MapStage.java index 7d762f4b7f8..e992eadbd75 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/MapStage.java +++ b/forge-gui-mobile/src/forge/adventure/stage/MapStage.java @@ -61,6 +61,7 @@ public class MapStage extends GameStage { private EnemySprite currentMob; Queue positions = new LinkedList<>(); private boolean isLoadingMatch = false; + private boolean isPlayerLeavingDungeon = false; //private HashMap mapFlags = new HashMap<>(); //Stores local map flags. These aren't available outside this map. @@ -758,6 +759,8 @@ public class MapStage extends GameStage { if (defeated) WorldStage.getInstance().resetPlayerLocation(); Forge.switchScene(GameScene.instance()); + isPlayerLeavingDungeon = false; + dialogOnlyInput = false; return true; } @@ -934,8 +937,9 @@ public class MapStage extends GameStage { @Override protected void onActing(float delta) { - if (isPaused() || isDialogOnlyInput() || Forge.advFreezePlayerControls) + if (isPaused() || isDialogOnlyInput() || Forge.advFreezePlayerControls || isPlayerLeavingDungeon) return; + Iterator it = enemies.iterator(); if (freezeAllEnemyBehaviors) { @@ -1110,6 +1114,10 @@ public class MapStage extends GameStage { return isInMap; } + public void onBeginLeavingDungeon() { + isPlayerLeavingDungeon = true; + } + @Override public void showDialog() { if (dialogStage == null){ diff --git a/forge-gui-mobile/src/forge/adventure/util/SaveFileContent.java b/forge-gui-mobile/src/forge/adventure/util/SaveFileContent.java index d52eed4c82c..dcf7dba5c99 100644 --- a/forge-gui-mobile/src/forge/adventure/util/SaveFileContent.java +++ b/forge-gui-mobile/src/forge/adventure/util/SaveFileContent.java @@ -1,7 +1,7 @@ package forge.adventure.util; /** - * Interface to save the content the the save game file + * Interface to save the content of the save game file */ public interface SaveFileContent { void load(SaveFileData data);