mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Fix crash when starting next game of match
This commit is contained in:
@@ -488,7 +488,7 @@ public class GuiDesktop implements IGuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endCurrentGame() {
|
public void endCurrentGame() {
|
||||||
FControl.instance.endCurrentGame();
|
FControl.instance.endCurrentGame(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -562,7 +562,7 @@ public class GuiDesktop implements IGuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void continueMatch(Match match) {
|
public void continueMatch(Match match) {
|
||||||
Singletons.getControl().endCurrentGame();
|
Singletons.getControl().endCurrentGame(false, false);
|
||||||
if (match == null) {
|
if (match == null) {
|
||||||
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -450,16 +450,6 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void startGameInSameMatch() {
|
|
||||||
startGameWithUi(game.getMatch());
|
|
||||||
}
|
|
||||||
public final void startGameAndClearMatch() {
|
|
||||||
if (game != null) {
|
|
||||||
game.getMatch().clearGamesPlayed();
|
|
||||||
}
|
|
||||||
startGameInSameMatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void startGameWithUi(final Match match) {
|
public final void startGameWithUi(final Match match) {
|
||||||
if (game != null) {
|
if (game != null) {
|
||||||
setCurrentScreen(FScreen.MATCH_SCREEN);
|
setCurrentScreen(FScreen.MATCH_SCREEN);
|
||||||
@@ -561,12 +551,21 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void endCurrentGame() {
|
public final void endCurrentGame(boolean nextGame, boolean restart) {
|
||||||
if (game == null) { return; }
|
if (game == null) { return; }
|
||||||
|
|
||||||
|
Match match = game.getMatch();
|
||||||
|
game = null;
|
||||||
|
|
||||||
Singletons.getView().getNavigationBar().closeTab(FScreen.MATCH_SCREEN);
|
Singletons.getView().getNavigationBar().closeTab(FScreen.MATCH_SCREEN);
|
||||||
|
|
||||||
game = null;
|
if (nextGame) {
|
||||||
|
startGameWithUi(match);
|
||||||
|
}
|
||||||
|
else if (restart) {
|
||||||
|
match.clearGamesPlayed();
|
||||||
|
startGameWithUi(match);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FControlGamePlayback playbackControl;
|
private FControlGamePlayback playbackControl;
|
||||||
|
|||||||
@@ -58,23 +58,21 @@ public class ControlWinLose {
|
|||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
saveOptions();
|
saveOptions();
|
||||||
|
|
||||||
Singletons.getControl().endCurrentGame();
|
Singletons.getControl().endCurrentGame(true, false);
|
||||||
Singletons.getControl().startGameInSameMatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Action performed when "restart" button is pressed in default win/lose UI. */
|
/** Action performed when "restart" button is pressed in default win/lose UI. */
|
||||||
public void actionOnRestart() {
|
public void actionOnRestart() {
|
||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
saveOptions();
|
saveOptions();
|
||||||
Singletons.getControl().endCurrentGame();
|
Singletons.getControl().endCurrentGame(false, true);
|
||||||
Singletons.getControl().startGameAndClearMatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Action performed when "quit" button is pressed in default win/lose UI. */
|
/** Action performed when "quit" button is pressed in default win/lose UI. */
|
||||||
public void actionOnQuit() {
|
public void actionOnQuit() {
|
||||||
// Reset other stuff
|
// Reset other stuff
|
||||||
saveOptions();
|
saveOptions();
|
||||||
Singletons.getControl().endCurrentGame();
|
Singletons.getControl().endCurrentGame(false, false);
|
||||||
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ public class QuestDraftWinLose extends ControlWinLose {
|
|||||||
FModel.getQuestPreferences().save();
|
FModel.getQuestPreferences().save();
|
||||||
Singletons.getControl().writeMatchPreferences();
|
Singletons.getControl().writeMatchPreferences();
|
||||||
|
|
||||||
Singletons.getControl().endCurrentGame();
|
Singletons.getControl().endCurrentGame(false, false);
|
||||||
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
Singletons.getControl().setCurrentScreen(FScreen.HOME_SCREEN);
|
||||||
|
|
||||||
SOverlayUtils.hideOverlay();
|
SOverlayUtils.hideOverlay();
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
|||||||
finished = true;
|
finished = true;
|
||||||
|
|
||||||
if (allowAwaitNextInput()) {
|
if (allowAwaitNextInput()) {
|
||||||
awaitNextInput(this);
|
awaitNextInput(getGameView());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,18 +78,17 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
|||||||
private static final Timer awaitNextInputTimer = new Timer();
|
private static final Timer awaitNextInputTimer = new Timer();
|
||||||
private static TimerTask awaitNextInputTask;
|
private static TimerTask awaitNextInputTask;
|
||||||
|
|
||||||
public static void awaitNextInput(final Input input) {
|
public static void awaitNextInput(final LocalGameView gameView) {
|
||||||
//delay updating prompt to await next input briefly so buttons don't flicker disabled then enabled
|
//delay updating prompt to await next input briefly so buttons don't flicker disabled then enabled
|
||||||
awaitNextInputTask = new TimerTask() {
|
awaitNextInputTask = new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FThreads.invokeInEdtLater(input.getGui(), new Runnable() {
|
FThreads.invokeInEdtLater(gameView.getGui(), new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
synchronized (awaitNextInputTimer) {
|
synchronized (awaitNextInputTimer) {
|
||||||
if (awaitNextInputTask != null) {
|
if (awaitNextInputTask != null) {
|
||||||
input.getGui().showPromptMessage(input.getOwner(), "Waiting for opponent...");
|
updatePromptForAwait(gameView);
|
||||||
ButtonUtil.update(input, false, false, false);
|
|
||||||
awaitNextInputTask = null;
|
awaitNextInputTask = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,6 +99,22 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
|||||||
awaitNextInputTimer.schedule(awaitNextInputTask, 250);
|
awaitNextInputTimer.schedule(awaitNextInputTask, 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void waitForHumanOpponent(final LocalGameView gameView) {
|
||||||
|
cancelAwaitNextInput();
|
||||||
|
FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updatePromptForAwait(gameView);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updatePromptForAwait(final LocalGameView gameView) {
|
||||||
|
InputNone inputNone = new InputNone(gameView);
|
||||||
|
inputNone.getGui().showPromptMessage(inputNone.getOwner(), "Waiting for opponent...");
|
||||||
|
ButtonUtil.update(inputNone, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
public static void cancelAwaitNextInput() {
|
public static void cancelAwaitNextInput() {
|
||||||
synchronized (awaitNextInputTimer) { //ensure task doesn't reset awaitNextInputTask during this block
|
synchronized (awaitNextInputTimer) { //ensure task doesn't reset awaitNextInputTask during this block
|
||||||
if (awaitNextInputTask != null) {
|
if (awaitNextInputTask != null) {
|
||||||
|
|||||||
@@ -819,7 +819,7 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
InputNone inputNone = new InputNone(gameView);
|
InputNone inputNone = new InputNone(gameView);
|
||||||
getGui().showPromptMessage(inputNone.getOwner(), "");
|
getGui().showPromptMessage(inputNone.getOwner(), "");
|
||||||
ButtonUtil.update(inputNone, false, false, false);
|
ButtonUtil.update(inputNone, false, false, false);
|
||||||
InputBase.awaitNextInput(inputNone);
|
InputBase.awaitNextInput(gameView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user