From dbae03db95bb841fb3913691c46d88a760b72f76 Mon Sep 17 00:00:00 2001 From: drdev Date: Sun, 22 Mar 2015 17:50:10 +0000 Subject: [PATCH] Prevent card zoom crash --- forge-gui-mobile/src/forge/Forge.java | 16 +++++----------- forge-gui-mobile/src/forge/GuiMobile.java | 3 +-- forge-gui-mobile/src/forge/card/CardZoom.java | 3 +-- .../src/forge/screens/match/MatchController.java | 12 +++++++++++- .../src/forge/screens/match/views/VGameMenu.java | 3 +-- .../screens/match/winlose/ControlWinLose.java | 7 +++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index 21c8db1a7d5..6ac71b8a6e8 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -16,9 +16,7 @@ import forge.assets.FSkinFont; import forge.assets.ImageCache; import forge.error.BugReporter; import forge.error.ExceptionHandler; -import forge.game.GameView; import forge.interfaces.IDeviceAdapter; -import forge.match.HostedMatch; import forge.model.FModel; import forge.properties.ForgeConstants; import forge.properties.ForgePreferences; @@ -26,6 +24,7 @@ import forge.properties.ForgePreferences.FPref; import forge.screens.FScreen; import forge.screens.SplashScreen; import forge.screens.home.HomeScreen; +import forge.screens.match.MatchController; import forge.sound.MusicPlaylist; import forge.sound.SoundSystem; import forge.toolbox.FContainer; @@ -52,7 +51,6 @@ public class Forge implements ApplicationListener { private static boolean exited; private static int continuousRenderingCount = 1; //initialize to 1 since continuous rendering is the default private static final Stack screens = new Stack(); - public static HostedMatch hostedMatch; public static ApplicationListener getApp(Clipboard clipboard0, IDeviceAdapter deviceAdapter0, String assetDir0) { if (GuiBase.getInterface() == null) { @@ -302,15 +300,15 @@ public class Forge implements ApplicationListener { @Override public void pause() { - if (hostedMatch != null) { - hostedMatch.pause(); + if (MatchController.getHostedMatch() != null) { + MatchController.getHostedMatch().pause(); } } @Override public void resume() { - if (hostedMatch != null) { - hostedMatch.resume(); + if (MatchController.getHostedMatch() != null) { + MatchController.getHostedMatch().resume(); } } @@ -651,8 +649,4 @@ public class Forge implements ApplicationListener { return handled; } } - - public static GameView getGameView() { - return hostedMatch == null ? null : hostedMatch.getGameView(); - } } diff --git a/forge-gui-mobile/src/forge/GuiMobile.java b/forge-gui-mobile/src/forge/GuiMobile.java index 74aa9398f0e..6794f774fdd 100644 --- a/forge-gui-mobile/src/forge/GuiMobile.java +++ b/forge-gui-mobile/src/forge/GuiMobile.java @@ -280,7 +280,6 @@ public class GuiMobile implements IGuiBase { @Override public HostedMatch hostMatch() { - return Forge.hostedMatch = new HostedMatch(); + return MatchController.hostMatch(); } - } diff --git a/forge-gui-mobile/src/forge/card/CardZoom.java b/forge-gui-mobile/src/forge/card/CardZoom.java index aaadadcf050..0b1bf9aa059 100644 --- a/forge-gui-mobile/src/forge/card/CardZoom.java +++ b/forge-gui-mobile/src/forge/card/CardZoom.java @@ -7,7 +7,6 @@ import java.util.Map.Entry; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.math.Rectangle; -import forge.Forge; import forge.Graphics; import forge.ImageKeys; import forge.assets.FSkinImage; @@ -168,7 +167,7 @@ public class CardZoom extends FOverlay { @Override public void drawOverlay(Graphics g) { - final GameView gameView = Forge.getGameView(); + final GameView gameView = MatchController.instance.getGameView(); float w = getWidth(); float h = getHeight(); diff --git a/forge-gui-mobile/src/forge/screens/match/MatchController.java b/forge-gui-mobile/src/forge/screens/match/MatchController.java index eb57cc3fe07..bcc5e6d4558 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchController.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchController.java @@ -38,6 +38,7 @@ import forge.game.zone.ZoneType; import forge.interfaces.IButton; import forge.item.PaperCard; import forge.match.AbstractGuiGame; +import forge.match.HostedMatch; import forge.match.MatchButtonType; import forge.model.FModel; import forge.properties.ForgePreferences; @@ -65,6 +66,7 @@ public class MatchController extends AbstractGuiGame { private static final Map avatarImages = new HashMap(); + private static HostedMatch hostedMatch; private static MatchScreen view; public static MatchScreen getView() { @@ -128,7 +130,7 @@ public class MatchController extends AbstractGuiGame { @Override public void buildTouchListeners(float screenX, float screenY, ArrayList listeners) { if (screenY < view.getHeight() - VPrompt.HEIGHT) { - Forge.hostedMatch.pause(); + hostedMatch.pause(); } } }); @@ -501,4 +503,12 @@ public class MatchController extends AbstractGuiGame { return !view.stopAtPhase(playerTurn, phase); } + public static HostedMatch hostMatch() { + hostedMatch = new HostedMatch(); + return hostedMatch; + } + + public static HostedMatch getHostedMatch() { + return hostedMatch; + } } diff --git a/forge-gui-mobile/src/forge/screens/match/views/VGameMenu.java b/forge-gui-mobile/src/forge/screens/match/views/VGameMenu.java index 3887b46866f..543e0a67b73 100644 --- a/forge-gui-mobile/src/forge/screens/match/views/VGameMenu.java +++ b/forge-gui-mobile/src/forge/screens/match/views/VGameMenu.java @@ -1,6 +1,5 @@ package forge.screens.match.views; -import forge.Forge; import forge.assets.FSkinImage; import forge.deck.Deck; import forge.deck.FDeckViewer; @@ -46,7 +45,7 @@ public class VGameMenu extends FDropDownMenu { addItem(new FMenuItem("Deck List", FSkinImage.DECKLIST, new FEventHandler() { @Override public void handleEvent(FEvent e) { - final Deck deck = Forge.hostedMatch.getGame().getPhaseHandler().getPlayerTurn().getRegisteredPlayer().getDeck(); + final Deck deck = MatchController.getHostedMatch().getGame().getPhaseHandler().getPlayerTurn().getRegisteredPlayer().getDeck(); if (deck != null) { FDeckViewer.show(deck); } 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 6aa1241e426..c21bd7dc5a3 100644 --- a/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java +++ b/forge-gui-mobile/src/forge/screens/match/winlose/ControlWinLose.java @@ -1,6 +1,5 @@ package forge.screens.match.winlose; -import forge.Forge; import forge.game.GameView; import forge.screens.match.MatchController; import forge.toolbox.FEvent; @@ -54,21 +53,21 @@ public class ControlWinLose { view.hide(); saveOptions(); - Forge.hostedMatch.continueMatch(); + MatchController.getHostedMatch().continueMatch(); } /** Action performed when "restart" button is pressed in default win/lose UI. */ public void actionOnRestart() { view.hide(); saveOptions(); - Forge.hostedMatch.restartMatch(); + MatchController.getHostedMatch().restartMatch(); } /** Action performed when "quit" button is pressed in default win/lose UI. */ public void actionOnQuit() { // Reset other stuff saveOptions(); - Forge.hostedMatch.endCurrentGame(); + MatchController.getHostedMatch().endCurrentGame(); view.hide(); }