renamed input classes, used a common branch in modular

This commit is contained in:
Maxmtg
2013-03-29 06:21:51 +00:00
parent 8a20bafd67
commit 97b418c9de
7 changed files with 32 additions and 41 deletions

4
.gitattributes vendored
View File

@@ -13832,8 +13832,8 @@ src/main/java/forge/control/input/InputPayManaX.java -text
src/main/java/forge/control/input/InputPayment.java -text
src/main/java/forge/control/input/InputSelectCards.java -text
src/main/java/forge/control/input/InputSelectCardsFromList.java -text
src/main/java/forge/control/input/InputSelectList.java -text
src/main/java/forge/control/input/InputSelectListBase.java -text
src/main/java/forge/control/input/InputSelectMany.java -text
src/main/java/forge/control/input/InputSelectManyBase.java -text
src/main/java/forge/control/input/InputSynchronized.java -text
src/main/java/forge/control/input/InputSyncronizedBase.java -text
src/main/java/forge/control/input/package-info.java svneol=native#text/plain

View File

@@ -65,6 +65,7 @@ import forge.card.trigger.TriggerHandler;
import forge.card.trigger.TriggerType;
import forge.control.input.InputBase;
import forge.control.input.InputSelectCards;
import forge.control.input.InputSelectCardsFromList;
import forge.game.GameState;
import forge.game.ai.ComputerUtil;
import forge.game.ai.ComputerUtilCard;
@@ -3555,43 +3556,34 @@ public class CardFactoryUtil {
@Override
public void execute() {
final Player modularPlayer = card.getController();
final List<Card> choices = Lists.newArrayList();
for(Card c : modularPlayer.getGame().getCardsIn(ZoneType.Battlefield)) {
if( c.isCreature() && c.isArtifact() && c.canBeTargetedBy(ability))
choices.add(c);
}
Card card2 = null;
// Target as Modular is Destroyed
if (card.getController().isComputer()) {
List<Card> choices =
CardLists.filter(card.getController().getCardsIn(ZoneType.Battlefield), new Predicate<Card>() {
@Override
public boolean apply(final Card c) {
return c.isCreature() && c.isArtifact();
}
});
if (choices.size() != 0) {
ability.setTargetCard(ComputerUtilCard.getBestCreatureAI(choices));
if (ability.getTargetCard() != null) {
ability.setStackDescription("Put " + card.getCounters(CounterType.P1P1)
+ " +1/+1 counter/s from " + card + " on " + ability.getTargetCard());
Singletons.getModel().getGame().getStack().addSimultaneousStackEntry(ability);
}
if (modularPlayer.isComputer()) {
final List<Card> aiChoices = CardLists.filterControlledBy(choices, modularPlayer);
if (!aiChoices.isEmpty()) {
card2 = ComputerUtilCard.getBestCreatureAI(aiChoices);
}
} else {
InputSelectCards inp = new InputSelectCards(1,1) {
private static final long serialVersionUID = -7895723996302990127L;
@Override
protected boolean isValidChoice(Card card2) {
return card2.isCreature() && card2.isArtifact() && card.isInPlay() && card.canBeTargetedBy(ability);
}
};
InputSelectCards inp = new InputSelectCardsFromList(0, 1, choices);
inp.setMessage("Select target artifact creature to put +1/+1 counter on it");
FThreads.setInputAndWait(inp);
if( !inp.hasCancelled() ) {
Card card2 = inp.getSelected().get(0);
ability.setTargetCard(card2);
String desc = String.format("Put %d +1/+1 counter/s from %s on %s", card.getCounters(CounterType.P1P1), card, card2);
ability.setStackDescription(desc);
Singletons.getModel().getGame().getStack().add(ability);
card2 = inp.getSelected().get(0);
}
}
ability.setTargetCard(card2);
if ( null != card2 ) {
String desc = String.format("Put %d +1/+1 counter/s from %s on %s", card.getCounters(CounterType.P1P1), card, card2);
ability.setStackDescription(desc);
modularPlayer.getGame().getStack().addSimultaneousStackEntry(ability);
}
}
});
}

View File

@@ -91,7 +91,7 @@ public class TargetSelection {
sb.append("\n");
sb.append(tgt.getVTSelection());
CMatchUI.SINGLETON_INSTANCE.showMessage(sb.toString());
showMessage(sb.toString());
// If reached Minimum targets, enable OK button
if (!tgt.isMinTargetsChosen(sa.getSourceCard(), sa) || tgt.isDividedAsYouChoose()) {

View File

@@ -2,7 +2,7 @@ package forge.control.input;
import forge.Card;
public abstract class InputSelectCards extends InputSelectListBase<Card> {
public abstract class InputSelectCards extends InputSelectManyBase<Card> {
private static final long serialVersionUID = -6609493252672573139L;
protected InputSelectCards(int min, int max) {

View File

@@ -12,6 +12,9 @@ public class InputSelectCardsFromList extends InputSelectCards {
public InputSelectCardsFromList(int min, int max, List<Card> validCards) {
super(min, Math.min(max, validCards.size())); // to avoid hangs
this.validChoices = validCards;
if ( min > validCards.size() )
throw new RuntimeException(String.format("Trying to choose at least %d cards from a list with only %d cards!", min, validCards.size()));
}
@Override

View File

@@ -6,7 +6,7 @@ import java.util.List;
* TODO: Write javadoc for this type.
*
*/
public interface InputSelectList<T> extends InputSynchronized {
public interface InputSelectMany<T> extends InputSynchronized {
boolean hasCancelled();
List<T> getSelected();
}

View File

@@ -7,7 +7,7 @@ import forge.GameEntity;
import forge.gui.match.CMatchUI;
import forge.view.ButtonUtil;
public abstract class InputSelectListBase<T extends GameEntity> extends InputSyncronizedBase implements InputSelectList<T> {
public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyncronizedBase implements InputSelectMany<T> {
private static final long serialVersionUID = -2305549394512889450L;
@@ -22,7 +22,7 @@ public abstract class InputSelectListBase<T extends GameEntity> extends InputSyn
protected InputSelectListBase(int min, int max) {
protected InputSelectManyBase(int min, int max) {
selected = new ArrayList<T>();
if (min > max) {
throw new IllegalArgumentException("Min must not be greater than Max");
@@ -82,10 +82,6 @@ public abstract class InputSelectListBase<T extends GameEntity> extends InputSyn
@Override
public final void selectButtonOK() {
// should check here if it still gets into an infinite loop
// 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
this.stop();
}