Make end turn button automatically pass priority if possible, and otherwise not end turn

This commit is contained in:
drdev
2014-01-08 01:33:02 +00:00
parent 764310e08b
commit 1c6ccbb20a
3 changed files with 41 additions and 19 deletions

View File

@@ -64,7 +64,7 @@ public abstract class PlayerController {
protected final Game game; protected final Game game;
private PhaseType autoPassUntil = null; private PhaseType autoPassUntilPhase = null;
protected final Player player; protected final Player player;
protected final LobbyPlayer lobbyPlayer; protected final LobbyPlayer lobbyPlayer;
@@ -75,21 +75,21 @@ public abstract class PlayerController {
} }
/** /**
* TODO: Write javadoc for this method. * Automatically pass priority until reaching the given phase of the current turn
* @param cleanup * @param phase
*/ */
public void autoPassTo(PhaseType cleanup) { public void autoPassUntil(PhaseType phase) {
autoPassUntil = cleanup; autoPassUntilPhase = phase;
} }
public void autoPassCancel() { public void autoPassCancel() {
autoPassUntil = null; autoPassUntilPhase = null;
} }
public boolean mayAutoPass(PhaseType phase) { public boolean mayAutoPass(PhaseType phase) {
return phase.isBefore(autoPassUntil); return phase.isBefore(autoPassUntilPhase);
} }
// Triggers preliminary choice: ask, decline or play // Triggers preliminary choice: ask, decline or play
private Map<Integer, Boolean> triggersAlwaysAccept = new HashMap<Integer, Boolean>(); private Map<Integer, Boolean> triggersAlwaysAccept = new HashMap<Integer, Boolean>();
@@ -214,8 +214,4 @@ public abstract class PlayerController {
// These 2 are for AI // These 2 are for AI
public List<Card> cheatShuffle(List<Card> list) { return list; } public List<Card> cheatShuffle(List<Card> list) { return list; }
public Collection<? extends PaperCard> complainCardsCantPlayWell(Deck myDeck) { return null; } public Collection<? extends PaperCard> complainCardsCantPlayWell(Deck myDeck) { return null; }
} }

View File

@@ -29,6 +29,8 @@ import forge.game.card.Card;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.gui.input.Input; import forge.gui.input.Input;
import forge.gui.input.InputPassPriority;
import forge.gui.toolbox.FOptionPane;
/** /**
* <p> * <p>
@@ -50,7 +52,23 @@ public class InputProxy implements Observer {
game = game0; game = game0;
Singletons.getControl().getInputQueue().addObserver(this); Singletons.getControl().getInputQueue().addObserver(this);
} }
public boolean passPriority() {
Input inp = getInput();
if (inp != null && inp instanceof InputPassPriority) {
inp.selectButtonOK();
return true;
}
FThreads.invokeInEdtNowOrLater(new Runnable() {
@Override
public void run() {
FOptionPane.showMessageDialog("Cannot pass priority at this time.");
}
});
return false;
}
@Override @Override
public final void update(final Observable observable, final Object obj) { public final void update(final Observable observable, final Object obj) {
final Input nextInput = Singletons.getControl().getInputQueue().getActualInput(game); final Input nextInput = Singletons.getControl().getInputQueue().getActualInput(game);
@@ -79,8 +97,9 @@ public class InputProxy implements Observer {
*/ */
public final void selectButtonOK() { public final void selectButtonOK() {
Input inp = getInput(); Input inp = getInput();
if ( null != inp ) if (inp != null) {
inp.selectButtonOK(); inp.selectButtonOK();
}
} }
/** /**
@@ -90,8 +109,9 @@ public class InputProxy implements Observer {
*/ */
public final void selectButtonCancel() { public final void selectButtonCancel() {
Input inp = getInput(); Input inp = getInput();
if ( null != inp ) if (inp != null) {
inp.selectButtonCancel(); inp.selectButtonCancel();
}
} }
/** /**
@@ -104,8 +124,9 @@ public class InputProxy implements Observer {
*/ */
public final void selectPlayer(final Player player, final MouseEvent triggerEvent) { public final void selectPlayer(final Player player, final MouseEvent triggerEvent) {
Input inp = getInput(); Input inp = getInput();
if ( null != inp ) if (inp != null) {
inp.selectPlayer(player, triggerEvent); inp.selectPlayer(player, triggerEvent);
}
} }
/** /**
@@ -119,14 +140,16 @@ public class InputProxy implements Observer {
*/ */
public final void selectCard(final Card card, final MouseEvent triggerEvent) { public final void selectCard(final Card card, final MouseEvent triggerEvent) {
Input inp = getInput(); Input inp = getInput();
if ( null != inp ) if (inp != null) {
inp.selectCard(card, triggerEvent); inp.selectCard(card, triggerEvent);
}
} }
public final void selectAbility(SpellAbility ab) { public final void selectAbility(SpellAbility ab) {
Input inp = getInput(); Input inp = getInput();
if ( null != inp ) if (inp != null) {
inp.selectAbility(ab); inp.selectAbility(ab);
}
} }
/** {@inheritDoc} */ /** {@inheritDoc} */

View File

@@ -80,7 +80,10 @@ public enum CDock implements ICDoc {
Player p = findAffectedPlayer(); Player p = findAffectedPlayer();
if (p != null) { if (p != null) {
p.getController().autoPassTo(PhaseType.CLEANUP); p.getController().autoPassUntil(PhaseType.CLEANUP);
if (!CPrompt.SINGLETON_INSTANCE.getInputControl().passPriority()) {
p.getController().autoPassCancel();
}
} }
} }