Skip to content

Commit

Permalink
Suppress user action prompt unless decision required by (human) user.…
Browse files Browse the repository at this point in the history
… DevMode only currently.
  • Loading branch information
lodici committed Mar 29, 2015
1 parent 8561adc commit 234ee1c
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions src/magic/ui/SwingGameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ private static void invokeAndWait(final Runnable task) {
/** Returns true when undo was clicked. */
private boolean waitForInputOrUndo() {
try {
return input.take();
final boolean isUndo = input.take();
clearUserActionPrompt();
return isUndo;
} catch (final InterruptedException ex) {
throw new RuntimeException(ex);
}
Expand Down Expand Up @@ -521,15 +523,52 @@ public static String getMessageWithSource(final MagicSource source,final String
}

@Override
public void showMessage(final MagicSource source,final String message) {
public void showMessage(final MagicSource source, final String message) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
userActionPanel.showMessage(getMessageWithSource(source,message));
if (isUserActionPromptHidden(message) && MagicSystem.isDevMode()) {
clearUserActionPrompt();
} else {
userActionPanel.showMessage(getMessageWithSource(source, message));
}
}
});
}

private boolean isUserActionPromptHidden(final String message) {

final boolean isAiPlayer = game.getPriorityPlayer().getPlayerDefinition().isArtificial();
final boolean isAiDefending = game.getDefendingPlayer().getPlayerDefinition().isArtificial();
final boolean isDeclareBlockers = game.getPhase().getType() == MagicPhaseType.DeclareBlockers;
final boolean isCleanUp = game.getPhase().getType() == MagicPhaseType.Cleanup;
final boolean isDeclareBlockerMessage = message.contains("declare as blocker");
final boolean isContinueMessage = message.equals("Press {f} to continue.");
final boolean isGameOver = game.isFinished();

// System.out.printf(
// "\nPhase=%s, Player=%s, Msg=%s\n" +
// "isAiPlayer=%b, isAiDefending=%b, isDeclareBlockers=%b, isCleanUp=%b, isDeclarBlockerMessage=%b, isContinueMessage=%b\n",
// game.getPhase().getType(),
// game.getPriorityPlayer().getName(),
// message,
// isAiPlayer,
// isAiDefending,
// isDeclareBlockers,
// isCleanUp,
// isDeclareBlockerMessage,
// isContinueMessage
// );

return isAiPlayer
&& !isGameOver
&& !isCleanUp
&& (!isDeclareBlockers
|| (isDeclareBlockers && !isDeclareBlockerMessage && !isContinueMessage)
|| (isDeclareBlockers && isAiDefending));

}

private <E extends JComponent> E waitForInput(final Callable<E> func) throws UndoClickedException {
final AtomicReference<E> ref = new AtomicReference<>();
final AtomicReference<Exception> except = new AtomicReference<>();
Expand Down Expand Up @@ -967,4 +1006,15 @@ public void doFlashPlayerHandZoneButton() {
gamePanel.doFlashPlayerHandZoneButton();
}

private void clearUserActionPrompt() {
if (game.getPhase().getType() != MagicPhaseType.DeclareAttackers) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
userActionPanel.showMessage("");
}
});
}
}

}

0 comments on commit 234ee1c

Please sign in to comment.