mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Removed bare call to JOptionPane from code executed outside of EDT, also used a common input instead of a special one
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getCard.
|
||||
@@ -195,40 +158,27 @@ class CardFactoryLands {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
if (card.getController().isHuman()) {
|
||||
this.humanExecute();
|
||||
} else {
|
||||
this.computerExecute();
|
||||
}
|
||||
}
|
||||
|
||||
public void computerExecute() {
|
||||
List<Card> hand = CardLists.getType(card.getController().getCardsIn(ZoneType.Hand), type);
|
||||
if (hand.size() > 0) {
|
||||
this.revealCard(hand.get(0));
|
||||
List<Card> 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 (toReveal != null && !toReveal.isEmpty()) {
|
||||
card.getController().getGame().getAction().reveal(toReveal, card.getController());
|
||||
} else {
|
||||
card.setTapped(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void humanExecute() {
|
||||
InputSelectCards inp = new InputRevealCardType(0, 1, type, card);
|
||||
FThreads.setInputAndWait(inp);
|
||||
|
||||
if ( inp.hasCancelled() || inp.getSelected().isEmpty() ) {
|
||||
card.setTapped(true);
|
||||
} else {
|
||||
String cardName = inp.getSelected().get(0).getName();
|
||||
JOptionPane.showMessageDialog(null, "Revealed card: " + cardName, cardName, JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
|
||||
} // 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 **************************
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user