From aac8e6945b757aca22bf4f285dfa5e4eb773a27e Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Fri, 5 Apr 2013 09:45:37 +0000 Subject: [PATCH] Removed bare call to JOptionPane from code executed outside of EDT, also used a common input instead of a special one --- .../card/cardfactory/CardFactoryLands.java | 84 ++++--------------- 1 file changed, 17 insertions(+), 67 deletions(-) diff --git a/src/main/java/forge/card/cardfactory/CardFactoryLands.java b/src/main/java/forge/card/cardfactory/CardFactoryLands.java index 3e55363d4b1..377e2a88492 100644 --- a/src/main/java/forge/card/cardfactory/CardFactoryLands.java +++ b/src/main/java/forge/card/cardfactory/CardFactoryLands.java @@ -19,16 +19,13 @@ package forge.card.cardfactory; import java.util.List; -import javax.swing.JOptionPane; - import forge.Card; import forge.CardLists; import forge.Command; import forge.FThreads; -import forge.Singletons; import forge.control.input.InputSelectCards; +import forge.control.input.InputSelectCardsFromList; import forge.game.player.Player; -import forge.game.zone.Zone; import forge.game.zone.ZoneType; import forge.gui.GuiDialog; @@ -42,40 +39,6 @@ import forge.gui.GuiDialog; */ class CardFactoryLands { - /** - * TODO: Write javadoc for this type. - * - */ - private static final class InputRevealCardType extends InputSelectCards { - private final String type; - private final Card card; - private static final long serialVersionUID = -2774066137824255680L; - - /** - * TODO: Write javadoc for Constructor. - * @param min - * @param max - * @param type - * @param card - */ - private InputRevealCardType(int min, int max, String type, Card card) { - super(min, max); - this.type = type; - this.card = card; - } - - @Override - public String getMessage() { - return card.getName() + " - Reveal a card."; - } - - @Override - protected boolean isValidChoice(Card c) { - Zone zone = Singletons.getModel().getGame().getZoneOf(c); - return zone.is(ZoneType.Hand) && c.isType(type) && c.getController() == card.getController(); - } - } - /** *

* getCard. @@ -195,39 +158,26 @@ class CardFactoryLands { @Override public void execute() { - if (card.getController().isHuman()) { - this.humanExecute(); - } else { - this.computerExecute(); - } - } - - public void computerExecute() { List hand = CardLists.getType(card.getController().getCardsIn(ZoneType.Hand), type); - if (hand.size() > 0) { - this.revealCard(hand.get(0)); - } else { - card.setTapped(true); - } - } - - public void humanExecute() { - InputSelectCards inp = new InputRevealCardType(0, 1, type, card); - FThreads.setInputAndWait(inp); + List toReveal = null; + if (!hand.isEmpty()) { + if (card.getController().isHuman()) { + InputSelectCards inp = new InputSelectCardsFromList(1, 1, hand); + inp.setCancelAllowed(true); + inp.setMessage("Reveal a " + type + " card."); + FThreads.setInputAndWait(inp); + toReveal = inp.hasCancelled() ? null : inp.getSelected(); + } else { + // Ai wants to reveal the first card out of a list + toReveal = hand.subList(0, 0); + } + } else toReveal = null; - if ( inp.hasCancelled() || inp.getSelected().isEmpty() ) { - card.setTapped(true); + if (toReveal != null && !toReveal.isEmpty()) { + card.getController().getGame().getAction().reveal(toReveal, card.getController()); } else { - String cardName = inp.getSelected().get(0).getName(); - JOptionPane.showMessageDialog(null, "Revealed card: " + cardName, cardName, JOptionPane.PLAIN_MESSAGE); + card.setTapped(true); } - - } // execute() - - private void revealCard(final Card c) { - final StringBuilder sb = new StringBuilder(); - sb.append(c.getController()).append(" reveals ").append(c.getName()); - JOptionPane.showMessageDialog(null, sb.toString(), card.getName(), JOptionPane.PLAIN_MESSAGE); } }); } // *************** END ************ END **************************