- CheckStyle.

This commit is contained in:
Chris
2012-11-23 20:22:21 +00:00
parent df47bab393
commit cf4d65bf73
19 changed files with 156 additions and 133 deletions

View File

@@ -87,7 +87,7 @@ public enum FControl {
public static final int DRAFTING_PROCESS = 7; public static final int DRAFTING_PROCESS = 7;
private final SoundSystem soundSystem = new SoundSystem(); private final SoundSystem soundSystem = new SoundSystem();
/** /**
* <p> * <p>
* FControl. * FControl.
@@ -282,8 +282,9 @@ public enum FControl {
*/ */
private Lobby lobby = null; private Lobby lobby = null;
public Lobby getLobby() { public Lobby getLobby() {
if( lobby == null ) if (lobby == null) {
lobby = new Lobby(); lobby = new Lobby();
}
return lobby; return lobby;
} }

View File

@@ -53,16 +53,15 @@ public class Lobby {
"Roger", "Roland", "Ronald", "Roy", "Sam", "Sebastian", "Simon", "Stanley", "Stephen", "Roger", "Roland", "Ronald", "Roy", "Sam", "Sebastian", "Simon", "Stanley", "Stephen",
"Stuart", "Terence", "Thomas", "Tim", "Tom", "Tony", "Victor", "Vincent", "Wallace", "Stuart", "Terence", "Thomas", "Tim", "Tom", "Tony", "Victor", "Vincent", "Wallace",
"Walter", "Wilfred", "William", "Winston" "Walter", "Wilfred", "William", "Winston"
}; };
/** /**
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
* @param human * @param human
* @return * @return
*/ */
public LobbyPlayer findLocalPlayer(PlayerType type, String name) { public LobbyPlayer findLocalPlayer(PlayerType type, String name) {
return new LobbyPlayer(type, name); return new LobbyPlayer(type, name);
} }
@@ -72,10 +71,11 @@ public class Lobby {
* @return * @return
*/ */
public LobbyPlayer findLocalPlayer(PlayerType type) { public LobbyPlayer findLocalPlayer(PlayerType type) {
if ( type == PlayerType.HUMAN ) if (type == PlayerType.HUMAN) {
return new LobbyPlayer(type, "Human"); // need to get name! return new LobbyPlayer(type, "Human"); // need to get name!
}
LobbyPlayer player = findLocalPlayer(type, getRandomName());
LobbyPlayer player = findLocalPlayer(type, getRandomName());
player.setAvatarIndex(MyRandom.getRandom().nextInt(FSkin.getAvatars().size())); player.setAvatarIndex(MyRandom.getRandom().nextInt(FSkin.getAvatars().size()));
return player; return player;
} }
@@ -88,7 +88,7 @@ public class Lobby {
private String getRandomName() { private String getRandomName() {
Random my = MyRandom.getRandom(); Random my = MyRandom.getRandom();
return opponentNames[my.nextInt(opponentNames.length)]; return opponentNames[my.nextInt(opponentNames.length)];
} }
/** /**
@@ -99,6 +99,5 @@ public class Lobby {
return new LobbyPlayer(PlayerType.HUMAN, "Human"); // need to get name! return new LobbyPlayer(PlayerType.HUMAN, "Human"); // need to get name!
} }
} }

View File

@@ -116,12 +116,13 @@ public abstract class Input implements java.io.Serializable {
public String toString() { public String toString() {
return "blank"; return "blank";
} // returns the Input name like "EmptyStack" } // returns the Input name like "EmptyStack"
/** /**
* This method is used to mark old descendants of Input * This method is used to mark old descendants of Input
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
*/ */
public /*abstract */void isClassUpdated() {}//; public /*abstract */void isClassUpdated() {
} //;
} }

View File

@@ -46,9 +46,9 @@ public class InputBlock extends Input {
private static final long serialVersionUID = 6120743598368928128L; private static final long serialVersionUID = 6120743598368928128L;
private Card currentAttacker = null; private Card currentAttacker = null;
private final HashMap<Card,List<Card>> allBlocking = new HashMap<Card, List<Card>>(); private final HashMap<Card, List<Card>> allBlocking = new HashMap<Card, List<Card>>();
private final Player defender; private final Player defender;
/** /**
* TODO: Write javadoc for Constructor. * TODO: Write javadoc for Constructor.
* @param priority * @param priority
@@ -110,34 +110,34 @@ public class InputBlock extends Input {
public final void selectCard(final Card card) { public final void selectCard(final Card card) {
// is attacking? // is attacking?
boolean reminder = true; boolean reminder = true;
if (Singletons.getModel().getGame().getCombat().getAttackers().contains(card)) { if (Singletons.getModel().getGame().getCombat().getAttackers().contains(card)) {
this.currentAttacker = card; this.currentAttacker = card;
reminder = false; reminder = false;
} else { } else {
Zone zone = Singletons.getModel().getGame().getZoneOf(card); Zone zone = Singletons.getModel().getGame().getZoneOf(card);
// Make sure this card is valid to even be a blocker // Make sure this card is valid to even be a blocker
if (this.currentAttacker != null && card.isCreature() && card.getController().equals(defender) if (this.currentAttacker != null && card.isCreature() && card.getController().equals(defender)
&& zone.is(ZoneType.Battlefield, defender)) { && zone.is(ZoneType.Battlefield, defender)) {
// Create a new blockedBy list if it doesn't exist // Create a new blockedBy list if it doesn't exist
if (!this.allBlocking.containsKey(card)) { if (!this.allBlocking.containsKey(card)) {
this.allBlocking.put(card, new ArrayList<Card>()); this.allBlocking.put(card, new ArrayList<Card>());
} }
List<Card> attackersBlocked = this.allBlocking.get(card); List<Card> attackersBlocked = this.allBlocking.get(card);
if (!attackersBlocked.contains(this.currentAttacker) && if (!attackersBlocked.contains(this.currentAttacker)
CombatUtil.canBlock(this.currentAttacker, card, Singletons.getModel().getGame().getCombat())) { && CombatUtil.canBlock(this.currentAttacker, card, Singletons.getModel().getGame().getCombat())) {
attackersBlocked.add(this.currentAttacker); attackersBlocked.add(this.currentAttacker);
Singletons.getModel().getGame().getCombat().addBlocker(this.currentAttacker, card); Singletons.getModel().getGame().getCombat().addBlocker(this.currentAttacker, card);
reminder = false; reminder = false;
} }
} }
} }
if (reminder) { if (reminder) {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
} }
this.showMessage(); this.showMessage();
} // selectCard() } // selectCard()

View File

@@ -40,7 +40,7 @@ public class InputCleanup extends Input {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void showMessage() { public final void showMessage() {
final Player active = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn(); final Player active = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
if (active.isComputer()) { if (active.isComputer()) {
this.aiCleanupDiscard(active); this.aiCleanupDiscard(active);
Singletons.getModel().getGame().getPhaseHandler().passPriority(); Singletons.getModel().getGame().getPhaseHandler().passPriority();

View File

@@ -68,7 +68,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
if (!this.game.getStack().isResolving() && isInputEmpty) { if (!this.game.getStack().isResolving() && isInputEmpty) {
this.input = in; this.input = in;
} else { } else {
this.inputStack.add(in); this.inputStack.add(in);
} }
this.updateObservers(); this.updateObservers();
} }
@@ -202,7 +202,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
return new InputAttack(); return new InputAttack();
} }
break; break;
case COMBAT_DECLARE_BLOCKERS: case COMBAT_DECLARE_BLOCKERS:
stack.freezeStack(); stack.freezeStack();
boolean isUnderAttack = game.getCombat().isPlayerAttacked(priority); boolean isUnderAttack = game.getCombat().isPlayerAttacked(priority);
@@ -210,14 +210,15 @@ public class InputControl extends MyObservable implements java.io.Serializable {
handler.passPriority(); handler.passPriority();
return null; return null;
} }
if ( priority.isHuman() ) if (priority.isHuman()) {
return new InputBlock(priority); return new InputBlock(priority);
}
// ai is under attack // ai is under attack
priority.getController().getAiInput().getComputer().declareBlockers(); priority.getController().getAiInput().getComputer().declareBlockers();
return null; return null;
case CLEANUP: case CLEANUP:
// discard // discard
if (stack.isEmpty()) { if (stack.isEmpty()) {
@@ -236,9 +237,9 @@ public class InputControl extends MyObservable implements java.io.Serializable {
if (priority == null) { if (priority == null) {
return null; return null;
} else if (priority.isHuman()) { } else if (priority.isHuman()) {
boolean prioritySkip = priority.getController().mayAutoPass(phase) boolean prioritySkip = priority.getController().mayAutoPass(phase)
|| priority.getController().isUiSetToSkipPhase(playerTurn, phase); || priority.getController().isUiSetToSkipPhase(playerTurn, phase);
if (this.game.getStack().isEmpty() && prioritySkip ) { if (this.game.getStack().isEmpty() && prioritySkip) {
handler.passPriority(); handler.passPriority();
return null; return null;
} else { } else {

View File

@@ -80,7 +80,7 @@ public class InputMulligan extends Input {
@Override @Override
public final void selectButtonCancel() { public final void selectButtonCancel() {
final Player humanPlayer = Singletons.getControl().getPlayer(); final Player humanPlayer = Singletons.getControl().getPlayer();
final int newHand = humanPlayer.doMulligan(); final int newHand = humanPlayer.doMulligan();
@@ -90,22 +90,24 @@ public class InputMulligan extends Input {
} // selectButtonOK() } // selectButtonOK()
final void end() { final void end() {
GameState game = Singletons.getModel().getGame(); GameState game = Singletons.getModel().getGame();
// Computer mulligan // Computer mulligan
for (Player ai : game.getPlayers()) { for (Player ai : game.getPlayers()) {
if ( ai.isHuman() ) continue; if (ai.isHuman()) {
continue;
}
boolean aiTakesMulligan = true; boolean aiTakesMulligan = true;
// Computer mulligans if there are no cards with converted mana cost of // Computer mulligans if there are no cards with converted mana cost of
// 0 in its hand // 0 in its hand
while (aiTakesMulligan) { while (aiTakesMulligan) {
final List<Card> handList = ai.getCardsIn(ZoneType.Hand); final List<Card> handList = ai.getCardsIn(ZoneType.Hand);
final boolean hasLittleCmc0Cards = CardLists.getValidCards(handList, "Card.cmcEQ0", ai, null).size() < 2; final boolean hasLittleCmc0Cards = CardLists.getValidCards(handList, "Card.cmcEQ0", ai, null).size() < 2;
aiTakesMulligan = (handList.size() > InputMulligan.AI_MULLIGAN_THRESHOLD) && hasLittleCmc0Cards; aiTakesMulligan = (handList.size() > InputMulligan.AI_MULLIGAN_THRESHOLD) && hasLittleCmc0Cards;
if (aiTakesMulligan) { if (aiTakesMulligan) {
ai.doMulligan(); ai.doMulligan();
} }
@@ -119,16 +121,16 @@ public class InputMulligan extends Input {
final GameAction ga = game.getAction(); final GameAction ga = game.getAction();
for (Player p : game.getPlayers()) { for (Player p : game.getPlayers()) {
final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand)); final List<Card> openingHand = new ArrayList<Card>(p.getCardsIn(ZoneType.Hand));
for (final Card c : openingHand) { for (final Card c : openingHand) {
if ( p.isHuman() ) { if (p.isHuman()) {
final ArrayList<String> kws = c.getKeyword(); final ArrayList<String> kws = c.getKeyword();
for (int i = 0; i < kws.size(); i++) { for (int i = 0; i < kws.size(); i++) {
final String kw = kws.get(i); final String kw = kws.get(i);
if (kw.startsWith("MayEffectFromOpeningHand")) { if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1]; final String effName = kw.split(":")[1];
final SpellAbility effect = af.getAbility(c.getSVar(effName), c); final SpellAbility effect = af.getAbility(c.getSVar(effName), c);
if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) { if (GameActionUtil.showYesNoDialog(c, "Use this card's ability?")) {
// If we ever let the AI memorize cards in the players // If we ever let the AI memorize cards in the players
@@ -147,12 +149,12 @@ public class InputMulligan extends Input {
final ArrayList<String> kws = c.getKeyword(); final ArrayList<String> kws = c.getKeyword();
for (int i = 0; i < kws.size(); i++) { for (int i = 0; i < kws.size(); i++) {
final String kw = kws.get(i); final String kw = kws.get(i);
if (kw.startsWith("MayEffectFromOpeningHand")) { if (kw.startsWith("MayEffectFromOpeningHand")) {
final String effName = kw.split(":")[1]; final String effName = kw.split(":")[1];
final SpellAbility effect = af.getAbility(c.getSVar(effName), c); final SpellAbility effect = af.getAbility(c.getSVar(effName), c);
// Is there a better way for the AI to decide this? // Is there a better way for the AI to decide this?
if (effect.doTrigger(false)) { if (effect.doTrigger(false)) {
GameActionUtil.showInfoDialg("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ")."); GameActionUtil.showInfoDialg("Computer reveals " + c.getName() + "(" + c.getUniqueNumber() + ").");
@@ -161,8 +163,9 @@ public class InputMulligan extends Input {
} }
} }
} }
if (c.getName().startsWith("Leyline") && !(c.getName().startsWith("Leyline of Singularity") && if (c.getName().startsWith("Leyline")
(Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) { && !(c.getName().startsWith("Leyline of Singularity")
&& (Iterables.any(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals("Leyline of Singularity"))))) {
ga.moveToPlay(c); ga.moveToPlay(c);
//ga.checkStateEffects(); //ga.checkStateEffects();
} }
@@ -190,7 +193,7 @@ public class InputMulligan extends Input {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
} }
} }
@Override @Override
public void isClassUpdated() { public void isClassUpdated() {
} }

View File

@@ -85,6 +85,7 @@ public class InputPassPriority extends Input {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
} }
} // selectCard() } // selectCard()
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
}
} }

View File

@@ -186,5 +186,6 @@ public class InputPayDiscardCost extends Input {
this.unpaid.execute(); this.unpaid.execute();
} }
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
}
} }

View File

@@ -117,7 +117,7 @@ public class InputPayManaCost extends InputPayMana {
this.spell = sa; this.spell = sa;
if (Singletons.getModel().getGame() != null ) { if (Singletons.getModel().getGame() != null) {
if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) { if (sa.getSourceCard().isCopiedSpell() && sa.isSpell()) {
if (this.spell.getAfterPayMana() != null) { if (this.spell.getAfterPayMana() != null) {
this.stopSetNext(this.spell.getAfterPayMana()); this.stopSetNext(this.spell.getAfterPayMana());
@@ -290,6 +290,7 @@ public class InputPayManaCost extends InputPayMana {
this.done(); this.done();
} }
} }
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
}
} }

View File

@@ -12,15 +12,15 @@ import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil; import forge.view.ButtonUtil;
public class InputPayManaCost2 extends InputPayMana { public class InputPayManaCost2 extends InputPayMana {
private ManaCost manaCost; private ManaCost manaCost;
private final CostMana costMana; private final CostMana costMana;
// I would kill the one who made 2 classes like above // I would kill the one who made 2 classes like above
private final String originalManaCost; private final String originalManaCost;
private final SpellAbility sa; private final SpellAbility sa;
private final int manaToAdd; private final int manaToAdd;
private final CostPayment payment; private final CostPayment payment;
public InputPayManaCost2(CostMana costMana, SpellAbility spellAbility, final CostPayment payment, int toAdd) { public InputPayManaCost2(CostMana costMana, SpellAbility spellAbility, final CostPayment payment, int toAdd) {
manaCost = new ManaCost(costMana.getManaToPay()); manaCost = new ManaCost(costMana.getManaToPay());
manaCost.increaseColorlessMana(toAdd); manaCost.increaseColorlessMana(toAdd);
@@ -30,12 +30,12 @@ public class InputPayManaCost2 extends InputPayMana {
sa = spellAbility; sa = spellAbility;
manaToAdd = toAdd; manaToAdd = toAdd;
this.payment = payment; this.payment = payment;
} }
private static final long serialVersionUID = 3467312982164195091L; private static final long serialVersionUID = 3467312982164195091L;
private int phyLifeToLose = 0; private int phyLifeToLose = 0;
@@ -155,6 +155,7 @@ public class InputPayManaCost2 extends InputPayMana {
this.showMessage(); this.showMessage();
} }
} }
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
} }
}

View File

@@ -184,7 +184,7 @@ public class InputPayManaCostAbility extends InputPayMana {
this.showMessage(); this.showMessage();
} }
} }
private void done() { private void done() {
if (this.phyLifeToLose > 0) { if (this.phyLifeToLose > 0) {
Singletons.getControl().getPlayer().payLife(this.phyLifeToLose, null); Singletons.getControl().getPlayer().payLife(this.phyLifeToLose, null);
@@ -247,7 +247,8 @@ public class InputPayManaCostAbility extends InputPayMana {
this.showMessage(); this.showMessage();
} }
} }
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
}
} }

View File

@@ -62,7 +62,6 @@ public class InputPayManaCostUtil {
return manaCost; return manaCost;
} }
final StringBuilder cneeded = new StringBuilder(); final StringBuilder cneeded = new StringBuilder();
final StringBuilder colorRequired = new StringBuilder(); final StringBuilder colorRequired = new StringBuilder();
boolean choice = true; boolean choice = true;
@@ -80,8 +79,8 @@ public class InputPayManaCostUtil {
List<SpellAbility> abilities = new ArrayList<SpellAbility>(); List<SpellAbility> abilities = new ArrayList<SpellAbility>();
// you can't remove unneeded abilities inside a for(am:abilities) loop :( // you can't remove unneeded abilities inside a for(am:abilities) loop :(
for(SpellAbility ma : card.getManaAbility()) { for (SpellAbility ma : card.getManaAbility()) {
ma.setActivatingPlayer(Singletons.getControl().getPlayer()); ma.setActivatingPlayer(Singletons.getControl().getPlayer());
AbilityManaPart m = ma.getManaPart(); AbilityManaPart m = ma.getManaPart();
if (!ma.canPlay()) { if (!ma.canPlay()) {
@@ -95,7 +94,7 @@ public class InputPayManaCostUtil {
} }
abilities.add(ma); abilities.add(ma);
if (!skipExpress) { if (!skipExpress) {
// skip express mana if the ability is not undoable // skip express mana if the ability is not undoable
if (!ma.isUndoable()) { if (!ma.isUndoable()) {

View File

@@ -22,7 +22,7 @@ public class InputPayManaX extends InputPayMana {
private final SpellAbility sa; private final SpellAbility sa;
public InputPayManaX(final SpellAbility sa0, final CostPayment payment0, final CostMana costMana0) public InputPayManaX(final SpellAbility sa0, final CostPayment payment0, final CostMana costMana0)
{ {
sa = sa0; sa = sa0;
payment = payment0; payment = payment0;
@@ -110,5 +110,6 @@ public class InputPayManaX extends InputPayMana {
* @see forge.control.input.Input#isClassUpdated() * @see forge.control.input.Input#isClassUpdated()
*/ */
@Override @Override
public void isClassUpdated() {} public void isClassUpdated() {
} }
}

View File

@@ -185,9 +185,8 @@ public class InputPayReturnCost extends Input {
} }
this.unpaid.execute(); this.unpaid.execute();
} }
@Override public void isClassUpdated() {}
@Override public void isClassUpdated() {
}
} }

View File

@@ -187,5 +187,6 @@ public class InputPaySacCost extends Input {
this.unpaid.execute(); this.unpaid.execute();
} }
@Override public void isClassUpdated() {} @Override public void isClassUpdated() {
}
} }

View File

@@ -14,42 +14,52 @@ import forge.view.ButtonUtil;
public abstract class InputSelectMany<T extends GameEntity> extends Input { public abstract class InputSelectMany<T extends GameEntity> extends Input {
private static final long serialVersionUID = -2305549394512889450L; private static final long serialVersionUID = -2305549394512889450L;
protected final List<T> selected = new ArrayList<T>(); protected final List<T> selected = new ArrayList<T>();
protected final int min; protected final int min;
protected final int max; protected final int max;
private String message = "Source-Card-Name - Select %d more card(s)"; private String message = "Source-Card-Name - Select %d more card(s)";
protected InputSelectMany(int min, int max) protected InputSelectMany(int min, int max) {
{
if( min > max ) throw new IllegalArgumentException("Min must not be greater than Max"); if (min > max) {
throw new IllegalArgumentException("Min must not be greater than Max");
}
this.min = min; this.min = min;
this.max = max; this.max = max;
} }
@Override @Override
public final void showMessage() { public final void showMessage() {
String msgToShow = getMessage(); String msgToShow = getMessage();
CMatchUI.SINGLETON_INSTANCE.showMessage(msgToShow); CMatchUI.SINGLETON_INSTANCE.showMessage(msgToShow);
boolean canCancel = (min == 0 && selected.isEmpty()) || canCancelWithSomethingSelected(); boolean canCancel = (min == 0 && selected.isEmpty()) || canCancelWithSomethingSelected();
boolean canOk = hasEnoughTargets(); boolean canOk = hasEnoughTargets();
if (canOk && canCancel) ButtonUtil.enableAll(); if (canOk && canCancel) {
if (!canOk && canCancel) ButtonUtil.enableOnlyCancel(); ButtonUtil.enableAll();
if (canOk && !canCancel) ButtonUtil.enableOnlyOK(); }
if (!canOk && !canCancel) ButtonUtil.disableAll(); if (!canOk && canCancel) {
ButtonUtil.enableOnlyCancel();
}
if (canOk && !canCancel) {
ButtonUtil.enableOnlyOK();
}
if (!canOk && !canCancel) {
ButtonUtil.disableAll();
}
} }
/** /**
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
* @return * @return
*/ */
protected String getMessage() { protected String getMessage() {
return max == Integer.MAX_VALUE return max == Integer.MAX_VALUE
? String.format(message, selected.size()) ? String.format(message, selected.size())
: String.format(message, max - selected.size()); : String.format(message, max - selected.size());
} }
@@ -60,68 +70,69 @@ public abstract class InputSelectMany<T extends GameEntity> extends Input {
// if ( next != null ) { // if ( next != null ) {
// Singletons.getModel().getMatch().getInput().setInput(next); // Singletons.getModel().getMatch().getInput().setInput(next);
// } // }
if ( null == next ) if (null == next) {
this.stop(); this.stop();
else } else {
this.stopSetNext(next); this.stopSetNext(next);
}
// for a next use // for a next use
selected.clear(); selected.clear();
} }
@Override @Override
public final void selectButtonOK() { public final void selectButtonOK() {
// should check here if it still gets into an infinite loop // should check here if it still gets into an infinite loop
// if an ability is put on stack before this input is stopped; // if an ability is put on stack before this input is stopped;
// if it does, uncomment the 5 lines below, use them as method body // if it does, uncomment the 5 lines below, use them as method body
// this.stop(); // this.stop();
Input next = onDone(); // might add ability to stack from here Input next = onDone(); // might add ability to stack from here
// if ( next != null ) { // if ( next != null ) {
// Singletons.getModel().getMatch().getInput().setInput(next); // Singletons.getModel().getMatch().getInput().setInput(next);
// } // }
if ( null == next ) if (null == next) {
this.stop(); this.stop();
else } else {
this.stopSetNext(next); this.stopSetNext(next);
}
// for a next use // for a next use
selected.clear(); selected.clear();
} }
@Override @Override
public void isClassUpdated() {} public void isClassUpdated() {
}
public void setMessage(String message0) { public void setMessage(String message0) {
this.message = message0; // TODO: Add 0 to parameter's name. this.message = message0; // TODO: Add 0 to parameter's name.
} }
// must define these // must define these
protected abstract Input onDone(); protected abstract Input onDone();
protected abstract boolean isValidChoice(T choice); protected abstract boolean isValidChoice(T choice);
// might re-define later // might re-define later
protected Input onCancel() { return null; } protected Input onCancel() { return null; }
protected boolean canCancelWithSomethingSelected() { return false; } protected boolean canCancelWithSomethingSelected() { return false; }
protected boolean hasEnoughTargets() { return selected.size() >= min; } protected boolean hasEnoughTargets() { return selected.size() >= min; }
protected boolean hasAllTargets() { return selected.size() >= max; } protected boolean hasAllTargets() { return selected.size() >= max; }
protected void selectEntity(T c) {
protected void selectEntity(T c)
{ if (selected.contains(c) || !isValidChoice(c)) {
if ( selected.contains(c) || !isValidChoice(c) ) return; return;
}
this.selected.add(c); this.selected.add(c);
this.showMessage(); this.showMessage();
if ( hasAllTargets() ) if (hasAllTargets()) {
selectButtonOK(); selectButtonOK();
}
} }
} }

View File

@@ -4,14 +4,14 @@ import forge.Card;
public abstract class InputSelectManyCards extends InputSelectMany<Card> { public abstract class InputSelectManyCards extends InputSelectMany<Card> {
private static final long serialVersionUID = -6609493252672573139L; private static final long serialVersionUID = -6609493252672573139L;
protected InputSelectManyCards(int min, int max) protected InputSelectManyCards(int min, int max) {
{
super(min, max); super(min, max);
} }
@Override @Override
public final void selectCard(final Card c) { public final void selectCard(final Card c) {
selectEntity(c); selectEntity(c);
} }
} }

View File

@@ -9,12 +9,12 @@ import forge.game.player.Player;
public class InputSelectManyPlayers extends InputSelectMany<Player> { public class InputSelectManyPlayers extends InputSelectMany<Player> {
private static final long serialVersionUID = -8209690791522735L; private static final long serialVersionUID = -8209690791522735L;
protected final Function<List<Player>, Input> onComplete; protected final Function<List<Player>, Input> onComplete;
private final Predicate<Player> allowedFilter; private final Predicate<Player> allowedFilter;
public InputSelectManyPlayers(final Predicate<Player> allowedRule, int min, int max, final Function<List<Player>, Input> onDone) public InputSelectManyPlayers(final Predicate<Player> allowedRule, int min, int max, final Function<List<Player>, Input> onDone) {
{
super(min, max); super(min, max);
allowedFilter = allowedRule; allowedFilter = allowedRule;
onComplete = onDone; onComplete = onDone;
@@ -25,9 +25,11 @@ public class InputSelectManyPlayers extends InputSelectMany<Player> {
public void selectPlayer(final Player p) { public void selectPlayer(final Player p) {
selectEntity(p); selectEntity(p);
} }
protected boolean isValidChoice(Player choice) { protected boolean isValidChoice(Player choice) {
if ( allowedFilter != null && !allowedFilter.apply(choice)) return false; if (allowedFilter != null && !allowedFilter.apply(choice)) {
return false;
}
return true; return true;
} }
@@ -35,4 +37,4 @@ public class InputSelectManyPlayers extends InputSelectMany<Player> {
protected Input onDone() { protected Input onDone() {
return onComplete.apply(selected); return onComplete.apply(selected);
} }
} }