From 524ac3ae0cf57d5c596b2d56a0a15749e35beb98 Mon Sep 17 00:00:00 2001 From: Anthony Calosa Date: Wed, 3 Feb 2021 03:37:44 +0800 Subject: [PATCH] [Mobile] add Shahrazad support --- .../forge/game/event/GameEventSubgameStart.java | 1 - forge-gui-mobile/src/forge/Forge.java | 6 +++++- .../screens/match/winlose/ControlWinLose.java | 11 ++++++++++- .../forge/control/FControlGameEventHandler.java | 15 +++++++++++++++ .../main/java/forge/match/AbstractGuiGame.java | 2 +- .../src/main/java/forge/match/HostedMatch.java | 13 +++++++++++-- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/forge-game/src/main/java/forge/game/event/GameEventSubgameStart.java b/forge-game/src/main/java/forge/game/event/GameEventSubgameStart.java index 674427a6f91..8d9f733a52b 100644 --- a/forge-game/src/main/java/forge/game/event/GameEventSubgameStart.java +++ b/forge-game/src/main/java/forge/game/event/GameEventSubgameStart.java @@ -1,7 +1,6 @@ package forge.game.event; import forge.game.Game; -import forge.game.card.Card; public class GameEventSubgameStart extends GameEvent { public final Game subgame; diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index e667a157c97..c4a516cefea 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -202,6 +202,10 @@ public class Forge implements ApplicationListener { ImageCache.preloadCache(filteredkeys); } + public static void openHomeScreen() { + openScreen(HomeScreen.instance); + } + private void afterDbLoaded() { stopContinuousRendering(); //save power consumption by disabling continuous rendering once assets loaded @@ -210,7 +214,7 @@ public class Forge implements ApplicationListener { SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MENUS); //start background music destroyThis = false; //Allow back() Gdx.input.setCatchKey(Keys.MENU, true); - openScreen(HomeScreen.instance); + openHomeScreen(); splashScreen = null; boolean isLandscapeMode = isLandscapeMode(); diff --git a/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java b/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java index 9efa454a3d5..b829424e7c9 100644 --- a/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java +++ b/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java @@ -77,14 +77,23 @@ public class ControlWinLose { /** Action performed when "quit" button is pressed in default win/lose UI. */ public void actionOnQuit() { + boolean openHomeScreen = false; // Reset other stuff saveOptions(); - try { MatchController.getHostedMatch().endCurrentGame(); + try { + if(MatchController.getHostedMatch().subGameCount > 0) { + openHomeScreen = true; + MatchController.getHostedMatch().subGameCount--; + } + MatchController.getHostedMatch().endCurrentGame(); } catch (NullPointerException e) {} view.hide(); if(humancount == 0) { Forge.back(); } + //todo Refresh the layout + if (openHomeScreen) + Forge.openHomeScreen(); } /** diff --git a/forge-gui/src/main/java/forge/control/FControlGameEventHandler.java b/forge-gui/src/main/java/forge/control/FControlGameEventHandler.java index 0a28a6fea00..d9a8ba3be7c 100644 --- a/forge-gui/src/main/java/forge/control/FControlGameEventHandler.java +++ b/forge-gui/src/main/java/forge/control/FControlGameEventHandler.java @@ -280,6 +280,21 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base { return null; } + @Override + public Void visit(final GameEventSubgameEnd event) { + if (event.maingame != null) { + for (Player p : event.maingame.getPlayers()) { + updateZone(p, ZoneType.Battlefield); + updateZone(p, ZoneType.Hand); + updateZone(p, ZoneType.Graveyard); + updateZone(p, ZoneType.Exile); + updateZone(p, ZoneType.Command); + } + return processEvent(); + } + return null; + } + @Override public Void visit(final GameEventZone event) { if (event.player != null) { diff --git a/forge-gui/src/main/java/forge/match/AbstractGuiGame.java b/forge-gui/src/main/java/forge/match/AbstractGuiGame.java index 44a7a024ed8..4d90d993e5c 100644 --- a/forge-gui/src/main/java/forge/match/AbstractGuiGame.java +++ b/forge-gui/src/main/java/forge/match/AbstractGuiGame.java @@ -185,7 +185,7 @@ public abstract class AbstractGuiGame implements IGuiGame, IMayViewCards { return true; //if not in game, card can be shown } if(GuiBase.getInterface().isLibgdxPort()){ - if(gameView.isGameOver()) { + if(gameView != null && gameView.isGameOver()) { return true; } if(spectator!=null) { //workaround fix!! this is needed on above code or it will diff --git a/forge-gui/src/main/java/forge/match/HostedMatch.java b/forge-gui/src/main/java/forge/match/HostedMatch.java index 7c66b7ea1d0..ba2bd1f9c10 100644 --- a/forge-gui/src/main/java/forge/match/HostedMatch.java +++ b/forge-gui/src/main/java/forge/match/HostedMatch.java @@ -69,6 +69,7 @@ public class HostedMatch { private final MatchUiEventVisitor visitor = new MatchUiEventVisitor(); private final Map nextGameDecisions = Maps.newHashMap(); private boolean isMatchOver = false; + public int subGameCount = 0; public HostedMatch() {} @@ -362,6 +363,7 @@ public class HostedMatch { @Override public Void visit(final GameEventSubgameStart event) { + subGameCount++; event.subgame.subscribeToEvents(SoundSystem.instance); event.subgame.subscribeToEvents(visitor); @@ -387,7 +389,10 @@ public class HostedMatch { } } }; - GuiBase.getInterface().invokeInEdtAndWait(switchGameView); + if (GuiBase.getInterface().isLibgdxPort()) + GuiBase.getInterface().invokeInEdtNow(switchGameView); + else + GuiBase.getInterface().invokeInEdtAndWait(switchGameView); //ensure opponents set properly for (final Player p : event.subgame.getPlayers()) { @@ -419,7 +424,11 @@ public class HostedMatch { } } }; - GuiBase.getInterface().invokeInEdtAndWait(switchGameView); + if (GuiBase.getInterface().isLibgdxPort()) + GuiBase.getInterface().invokeInEdtNow(switchGameView); + else + GuiBase.getInterface().invokeInEdtAndWait(switchGameView); + return null; }