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 java.util.List;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardLists;
|
import forge.CardLists;
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.FThreads;
|
import forge.FThreads;
|
||||||
import forge.Singletons;
|
|
||||||
import forge.control.input.InputSelectCards;
|
import forge.control.input.InputSelectCards;
|
||||||
|
import forge.control.input.InputSelectCardsFromList;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.Zone;
|
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiDialog;
|
import forge.gui.GuiDialog;
|
||||||
|
|
||||||
@@ -42,40 +39,6 @@ import forge.gui.GuiDialog;
|
|||||||
*/
|
*/
|
||||||
class CardFactoryLands {
|
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>
|
* <p>
|
||||||
* getCard.
|
* getCard.
|
||||||
@@ -195,39 +158,26 @@ class CardFactoryLands {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
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);
|
List<Card> hand = CardLists.getType(card.getController().getCardsIn(ZoneType.Hand), type);
|
||||||
if (hand.size() > 0) {
|
List<Card> toReveal = null;
|
||||||
this.revealCard(hand.get(0));
|
if (!hand.isEmpty()) {
|
||||||
} else {
|
if (card.getController().isHuman()) {
|
||||||
card.setTapped(true);
|
InputSelectCards inp = new InputSelectCardsFromList(1, 1, hand);
|
||||||
}
|
inp.setCancelAllowed(true);
|
||||||
}
|
inp.setMessage("Reveal a " + type + " card.");
|
||||||
|
FThreads.setInputAndWait(inp);
|
||||||
public void humanExecute() {
|
toReveal = inp.hasCancelled() ? null : inp.getSelected();
|
||||||
InputSelectCards inp = new InputRevealCardType(0, 1, type, card);
|
} else {
|
||||||
FThreads.setInputAndWait(inp);
|
// 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() ) {
|
if (toReveal != null && !toReveal.isEmpty()) {
|
||||||
card.setTapped(true);
|
card.getController().getGame().getAction().reveal(toReveal, card.getController());
|
||||||
} else {
|
} else {
|
||||||
String cardName = inp.getSelected().get(0).getName();
|
card.setTapped(true);
|
||||||
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 **************************
|
} // *************** END ************ END **************************
|
||||||
|
|||||||
Reference in New Issue
Block a user