mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
cleanup for CardUtil
Removed T... syntax from GuiUtils chooseNNN functions (cause one might be called with cardlist parameter as a single choice option) Rmeoved SpellAbilityList.java - noone used it, and no special code in that class seen.
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -12147,7 +12147,6 @@ src/main/java/forge/card/spellability/AbilityTriggered.java svneol=native#text/p
|
||||
src/main/java/forge/card/spellability/Spell.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbility.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbilityCondition.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbilityList.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbilityRequirements.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbilityRestriction.java svneol=native#text/plain
|
||||
src/main/java/forge/card/spellability/SpellAbilityStackInstance.java svneol=native#text/plain
|
||||
|
||||
@@ -35,7 +35,6 @@ import forge.card.CardManaCost;
|
||||
import forge.card.EditionInfo;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.SpellAbilityList;
|
||||
import forge.control.input.InputPayManaCostUtil;
|
||||
import forge.game.zone.DefaultPlayerZone;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -86,23 +85,6 @@ public final class CardUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getRandomIndex.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.card.spellability.SpellAbilityList} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int getRandomIndex(final SpellAbilityList list) {
|
||||
if ((list == null) || (list.size() == 0)) {
|
||||
throw new RuntimeException("CardUtil : getRandomIndex(SpellAbilityList) argument is null or length is 0");
|
||||
}
|
||||
|
||||
return CardUtil.RANDOM.nextInt(list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getRandomIndex.
|
||||
@@ -366,77 +348,6 @@ public final class CardUtil {
|
||||
return cost.getConvertedManaCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addManaCosts.
|
||||
* </p>
|
||||
*
|
||||
* @param mc1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param mc2
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public static String addManaCosts(final String mc1, final String mc2) {
|
||||
String tMC = "";
|
||||
String xCost = "";
|
||||
if (mc1.startsWith("X")) {
|
||||
xCost = "X ";
|
||||
}
|
||||
|
||||
Integer cl1, cl2, tCL;
|
||||
String c1, c2, cc1, cc2;
|
||||
|
||||
c1 = mc1.replaceAll("[WUBRGSX]", "").trim();
|
||||
c2 = mc2.replaceAll("[WUBRGSX]", "").trim();
|
||||
|
||||
if (c1.length() > 0) {
|
||||
cl1 = Integer.valueOf(c1);
|
||||
} else {
|
||||
cl1 = 0;
|
||||
}
|
||||
|
||||
if (c2.length() > 0) {
|
||||
cl2 = Integer.valueOf(c2);
|
||||
} else {
|
||||
cl2 = 0;
|
||||
}
|
||||
|
||||
tCL = cl1 + cl2;
|
||||
|
||||
cc1 = mc1.replaceAll("[0-9]", "").replaceAll("X", "").trim();
|
||||
cc2 = mc2.replaceAll("[0-9]", "").trim();
|
||||
|
||||
tMC = xCost + tCL.toString() + " " + cc1 + " " + cc2;
|
||||
|
||||
//System.out.println("mc1:" + mc1 + "; TMC:" + tMC);
|
||||
return tMC.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getRelative.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
* @param relation
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.Card} object.
|
||||
*/
|
||||
public static Card getRelative(final Card c, final String relation) {
|
||||
if (relation.equals("CARDNAME")) {
|
||||
return c;
|
||||
} else if (relation.startsWith("enchanted ")) {
|
||||
return c.getEnchantingCard();
|
||||
} else if (relation.startsWith("equipped ")) {
|
||||
return c.getEquipping().get(0);
|
||||
// else if(relation.startsWith("target ")) return c.getTargetCard();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Error at CardUtil.getRelative: " + relation + "is not a valid relation");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* isACardType.
|
||||
@@ -471,29 +382,6 @@ public final class CardUtil {
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getCardTypes.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.util.ArrayList} object.
|
||||
*/
|
||||
public static ArrayList<String> getCardTypes() {
|
||||
final ArrayList<String> types = new ArrayList<String>();
|
||||
|
||||
// types.add("Artifact");
|
||||
// types.add("Creature");
|
||||
// types.add("Enchantment");
|
||||
// types.add("Instant");
|
||||
// types.add("Land");
|
||||
// types.add("Planeswalker");
|
||||
// types.add("Sorcery");
|
||||
// types.add("Tribal");
|
||||
|
||||
types.addAll(Constant.CardTypes.CARD_TYPES);
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -1698,20 +1698,19 @@ public class GameAction {
|
||||
if (spell.isSpell()) {
|
||||
if (spell.getIsDelve()) {
|
||||
final int cardsInGrave = originalCard.getController().getCardsIn(ZoneType.Graveyard).size();
|
||||
final ArrayList<Integer> choiceList = new ArrayList<Integer>();
|
||||
for (int i = 0; i <= cardsInGrave; i++) {
|
||||
choiceList.add(i);
|
||||
}
|
||||
|
||||
if (originalCard.getController().isHuman()) {
|
||||
|
||||
final int chosenAmount = (Integer) GuiUtils
|
||||
.chooseOne("Exile how many cards?", choiceList.toArray());
|
||||
final Integer[] cntChoice = new Integer[cardsInGrave+1];
|
||||
for (int i = 0; i <= cardsInGrave; i++) {
|
||||
cntChoice[i] = Integer.valueOf(i);
|
||||
}
|
||||
|
||||
final Integer chosenAmount = (Integer) GuiUtils.chooseOne("Exile how many cards?", cntChoice);
|
||||
System.out.println("Delve for " + chosenAmount);
|
||||
final CardList choices = AllZone.getHumanPlayer().getCardsIn(ZoneType.Graveyard);
|
||||
final CardList chosen = new CardList();
|
||||
for (int i = 0; i < chosenAmount; i++) {
|
||||
final Card nowChosen = GuiUtils.chooseOneOrNone("Exile which card?", choices.toArray());
|
||||
final Card nowChosen = GuiUtils.chooseOneOrNone("Exile which card?", choices);
|
||||
|
||||
if (nowChosen == null) {
|
||||
// User canceled,abort delving.
|
||||
|
||||
@@ -681,8 +681,8 @@ public final class GameActionUtil {
|
||||
public void resolve() {
|
||||
String color = "";
|
||||
|
||||
final Object o = GuiUtils.chooseOne("Choose mana color", Constant.Color.ONLY_COLORS);
|
||||
color = InputPayManaCostUtil.getShortColorString((String) o);
|
||||
final String o = GuiUtils.chooseOne("Choose mana color", Constant.Color.ONLY_COLORS);
|
||||
color = InputPayManaCostUtil.getShortColorString(o);
|
||||
|
||||
final AbilityMana abMana = new AbilityMana(c, "0", color) {
|
||||
private static final long serialVersionUID = -2182129023960978132L;
|
||||
|
||||
@@ -1305,7 +1305,7 @@ public class AbilityFactoryAttach {
|
||||
CardList list = AllZoneUtil.getCardsIn(tgt.getZone());
|
||||
list = list.getValidCards(tgt.getValidTgts(), aura.getActivatingPlayer(), source);
|
||||
|
||||
final Object o = GuiUtils.chooseOne(source + " - Select a card to attach to.", list.toArray());
|
||||
final Object o = GuiUtils.chooseOne(source + " - Select a card to attach to.", list);
|
||||
if (o instanceof Card) {
|
||||
AbilityFactoryAttach.handleAura(source, (Card) o, gainControl);
|
||||
//source.enchantEntity((Card) o);
|
||||
|
||||
@@ -333,7 +333,7 @@ public final class AbilityFactoryBond {
|
||||
if (cards.size() == 1) {
|
||||
partner = cards.get(0);
|
||||
} else if (sa.getActivatingPlayer().isHuman()) {
|
||||
Object o = GuiUtils.chooseOne("Select a card to pair with", cards.toArray());
|
||||
Object o = GuiUtils.chooseOne("Select a card to pair with", cards);
|
||||
|
||||
if (o != null) {
|
||||
partner = (Card) o;
|
||||
|
||||
@@ -990,11 +990,11 @@ public final class AbilityFactoryChangeZone {
|
||||
if (params.containsKey("AtRandom")) {
|
||||
o = CardUtil.getRandom(fetchList.toArray());
|
||||
} else if (params.containsKey("Mandatory")) {
|
||||
o = GuiUtils.chooseOne("Select a card", fetchList.toArray());
|
||||
o = GuiUtils.chooseOne("Select a card", fetchList);
|
||||
} else if (params.containsKey("Defined")) {
|
||||
o = fetchList.get(0);
|
||||
} else {
|
||||
o = GuiUtils.chooseOneOrNone("Select a card", fetchList.toArray());
|
||||
o = GuiUtils.chooseOneOrNone("Select a card", fetchList);
|
||||
}
|
||||
|
||||
if (o != null) {
|
||||
@@ -1328,7 +1328,7 @@ public final class AbilityFactoryChangeZone {
|
||||
if (!ZoneType.Battlefield.equals(destination) && !"Card".equals(type) && !defined) {
|
||||
final String picked = sa.getSourceCard().getName() + " - Computer picked:";
|
||||
if (fetched.size() > 0) {
|
||||
GuiUtils.chooseOne(picked, fetched.toArray());
|
||||
GuiUtils.chooseOne(picked, fetched);
|
||||
} else {
|
||||
GuiUtils.chooseOne(picked, new String[] { "<Nothing>" });
|
||||
}
|
||||
|
||||
@@ -246,9 +246,9 @@ public final class AbilityFactoryCharm {
|
||||
for (int i = 0; i < num; i++) {
|
||||
Object o;
|
||||
if (i < min) {
|
||||
o = GuiUtils.chooseOne("Choose a mode", choices.toArray());
|
||||
o = GuiUtils.chooseOne("Choose a mode", choices);
|
||||
} else {
|
||||
o = GuiUtils.chooseOneOrNone("Choose a mode", choices.toArray());
|
||||
o = GuiUtils.chooseOneOrNone("Choose a mode", choices);
|
||||
}
|
||||
if (null == o) {
|
||||
return sa;
|
||||
|
||||
@@ -335,8 +335,7 @@ public final class AbilityFactoryChoose {
|
||||
boolean valid = false;
|
||||
while (!valid) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final Object o = GuiUtils
|
||||
.chooseOne("Choose a card type", CardUtil.getCardTypes().toArray());
|
||||
final Object o = GuiUtils.chooseOne("Choose a card type", Constant.CardTypes.CARD_TYPES);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
@@ -362,7 +361,7 @@ public final class AbilityFactoryChoose {
|
||||
for (final String s : invalidTypes) {
|
||||
validChoices.remove(s);
|
||||
}
|
||||
final Object o = GuiUtils.chooseOne("Choose a creature type", validChoices.toArray());
|
||||
final Object o = GuiUtils.chooseOne("Choose a creature type", validChoices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
@@ -403,7 +402,7 @@ public final class AbilityFactoryChoose {
|
||||
if (!CardUtil.isACreatureType(chosen) || invalidTypes.contains(chosen)) {
|
||||
chosen = "Sliver";
|
||||
}
|
||||
GuiUtils.chooseOne("Computer picked: ", chosen);
|
||||
GuiUtils.chooseOne("Computer picked: ", new String[]{chosen});
|
||||
chosenType = chosen;
|
||||
}
|
||||
if (CardUtil.isACreatureType(chosenType) && !invalidTypes.contains(chosenType)) {
|
||||
@@ -415,12 +414,10 @@ public final class AbilityFactoryChoose {
|
||||
boolean valid = false;
|
||||
while (!valid) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final Object o = GuiUtils.chooseOne("Choose a basic land type", CardUtil.getBasicTypes()
|
||||
.toArray());
|
||||
if (null == o) {
|
||||
final String choice = GuiUtils.chooseOne("Choose a basic land type", CardUtil.getBasicTypes());
|
||||
if (null == choice) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
if (CardUtil.isABasicLandType(choice) && !invalidTypes.contains(choice)) {
|
||||
valid = true;
|
||||
card.setChosenType(choice);
|
||||
@@ -434,12 +431,11 @@ public final class AbilityFactoryChoose {
|
||||
boolean valid = false;
|
||||
while (!valid) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final Object o = GuiUtils
|
||||
.chooseOne("Choose a land type", CardUtil.getLandTypes().toArray());
|
||||
if (null == o) {
|
||||
final String choice = GuiUtils
|
||||
.chooseOne("Choose a land type", CardUtil.getLandTypes());
|
||||
if (null == choice) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
if (!invalidTypes.contains(choice)) {
|
||||
valid = true;
|
||||
card.setChosenType(choice);
|
||||
@@ -760,7 +756,7 @@ public final class AbilityFactoryChoose {
|
||||
if (chosen.equals("")) {
|
||||
chosen = Constant.Color.GREEN;
|
||||
}
|
||||
GuiUtils.chooseOne("Computer picked: ", chosen);
|
||||
GuiUtils.chooseOne("Computer picked: ", new String[]{chosen});
|
||||
final ArrayList<String> colorTemp = new ArrayList<String>();
|
||||
colorTemp.add(chosen);
|
||||
card.setChosenColor(colorTemp);
|
||||
@@ -1021,7 +1017,7 @@ public final class AbilityFactoryChoose {
|
||||
if (!random) {
|
||||
// initialize the array
|
||||
for (int i = min; i <= max; i++) {
|
||||
choices[i] = "" + i;
|
||||
choices[i] = Integer.toString(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1313,7 +1309,7 @@ public final class AbilityFactoryChoose {
|
||||
// Was if (sa.getActivatingPlayer().isHuman()) but defined player was being
|
||||
// overwritten by activatingPlayer (or controller if no activator was set).
|
||||
// Revert if it causes issues and remove Goblin Festival from card database.
|
||||
final Object o = GuiUtils.chooseOne(choiceDesc, choices.toArray());
|
||||
final Object o = GuiUtils.chooseOne(choiceDesc, choices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
@@ -1659,7 +1655,7 @@ public final class AbilityFactoryChoose {
|
||||
if (chosen.equals("")) {
|
||||
chosen = "Morphling";
|
||||
}
|
||||
GuiUtils.chooseOne("Computer picked: ", chosen);
|
||||
GuiUtils.chooseOne("Computer picked: ", new String[]{chosen});
|
||||
host.setNamedCard(chosen);
|
||||
ok = true;
|
||||
}
|
||||
@@ -1959,7 +1955,7 @@ public final class AbilityFactoryChoose {
|
||||
final CardList cl = land.getType(type);
|
||||
if (cl.size() > 0) {
|
||||
final String prompt = "Choose a" + (type.equals("Island") ? "n " : " ") + type;
|
||||
final Object o = GuiUtils.chooseOne(prompt, cl.toArray());
|
||||
final Object o = GuiUtils.chooseOne(prompt, cl);
|
||||
if (null != o) {
|
||||
final Card c = (Card) o;
|
||||
chosen.add(c);
|
||||
@@ -2237,7 +2233,7 @@ public final class AbilityFactoryChoose {
|
||||
SpellAbility chosenSA = null;
|
||||
AbilityFactory afChoice = new AbilityFactory();
|
||||
if (p.isHuman()) {
|
||||
String choice = (String) GuiUtils.chooseOne("Choose one", choices.values().toArray());
|
||||
String choice = (String) GuiUtils.chooseOne("Choose one", choices.values());
|
||||
chosenSA = afChoice.getAbility(host.getSVar(choices.inverse().get(choice)), host);
|
||||
} else { //Computer AI
|
||||
chosenSA = afChoice.getAbility(host.getSVar(params.get("Choices").split(",")[0]), host);
|
||||
|
||||
@@ -816,7 +816,7 @@ public final class AbilityFactoryCopy {
|
||||
} else {
|
||||
num = Integer.toString(multi - 1) + "th";
|
||||
}
|
||||
chosenSAtmp = (SpellAbility) GuiUtils.chooseOne("Select " + num + " spell to copy to stack", tgtSpells.toArray());
|
||||
chosenSAtmp = GuiUtils.chooseOne("Select " + num + " spell to copy to stack", tgtSpells);
|
||||
chosenSAs.add(chosenSAtmp);
|
||||
tgtSpells.remove(chosenSAtmp);
|
||||
} else {
|
||||
@@ -836,7 +836,7 @@ public final class AbilityFactoryCopy {
|
||||
if (tgtSpells.size() == 1) {
|
||||
chosenSA = tgtSpells.get(0);
|
||||
} else if (sa.getActivatingPlayer().isHuman()) {
|
||||
chosenSA = (SpellAbility) GuiUtils.chooseOne("Select a spell to copy", tgtSpells.toArray());
|
||||
chosenSA = (SpellAbility) GuiUtils.chooseOne("Select a spell to copy", tgtSpells);
|
||||
} else {
|
||||
chosenSA = tgtSpells.get(0);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package forge.card.abilityfactory;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
@@ -1182,35 +1183,33 @@ public class AbilityFactoryCounters {
|
||||
Counters chosenType = null;
|
||||
int chosenAmount;
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final ArrayList<String> choices = new ArrayList<String>();
|
||||
final ArrayList<Object> typeChoices = new ArrayList<Object>();
|
||||
final ArrayList<Counters> typeChoices = new ArrayList<Counters>();
|
||||
// get types of counters
|
||||
Object o;
|
||||
for (Object key : tgtCounters.keySet().toArray()) {
|
||||
for (Counters key : tgtCounters.keySet()) {
|
||||
if (tgtCounters.get(key) > 0) {
|
||||
typeChoices.add(key);
|
||||
}
|
||||
}
|
||||
if (typeChoices.size() > 1) {
|
||||
String prompt = "Select type counters to remove";
|
||||
o = GuiUtils.chooseOne(prompt, typeChoices.toArray());
|
||||
chosenType = GuiUtils.chooseOne(prompt, typeChoices);
|
||||
}
|
||||
else {
|
||||
o = typeChoices.get(0);
|
||||
chosenType = typeChoices.get(0);
|
||||
}
|
||||
chosenType = (Counters) o;
|
||||
chosenAmount = tgtCounters.get(chosenType);
|
||||
if (chosenAmount > counterAmount) {
|
||||
chosenAmount = counterAmount;
|
||||
}
|
||||
// make list of amount choices
|
||||
|
||||
if (chosenAmount > 1) {
|
||||
final List<Integer> choices = new ArrayList<Integer>();
|
||||
for (int i = 1; i <= chosenAmount; i++) {
|
||||
choices.add("" + i);
|
||||
choices.add(Integer.valueOf(i));
|
||||
}
|
||||
String prompt = "Select the number of " + chosenType.getName() + " counters to remove";
|
||||
o = GuiUtils.chooseOne(prompt, choices.toArray());
|
||||
chosenAmount = Integer.parseInt((String) o);
|
||||
chosenAmount = GuiUtils.chooseOne(prompt, choices);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1550,7 +1549,7 @@ public class AbilityFactoryCounters {
|
||||
if (choices.size() > 0) {
|
||||
card.addCounter(
|
||||
Counters.getType((choices.size() == 1 ? choices.get(0) : GuiUtils.chooseOne(
|
||||
"Select counter type", choices.toArray()).toString())), 1);
|
||||
"Select counter type", choices).toString())), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -350,14 +350,14 @@ public class AbilityFactoryMana {
|
||||
else {
|
||||
colorMenu = Constant.Color.ONLY_COLORS;
|
||||
}
|
||||
Object o = GuiUtils.chooseOne("Select Mana to Produce", colorMenu);
|
||||
if (o == null) {
|
||||
String s = GuiUtils.chooseOne("Select Mana to Produce", colorMenu);
|
||||
if (s == null) {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append("AbilityFactoryMana::manaResolve() - Human color mana choice is empty for ");
|
||||
sb.append(sa.getSourceCard().getName());
|
||||
throw new RuntimeException(sb.toString());
|
||||
} else {
|
||||
choice = InputPayManaCostUtil.getShortColorString((String) o);
|
||||
choice = InputPayManaCostUtil.getShortColorString(s);
|
||||
}
|
||||
}
|
||||
abMana.setExpressChoice(choice);
|
||||
@@ -370,7 +370,7 @@ public class AbilityFactoryMana {
|
||||
chosen = CardFactoryUtil.getMostProminentColor(AllZone.getComputerPlayer().getCardsIn(
|
||||
ZoneType.Hand));
|
||||
}
|
||||
GuiUtils.chooseOne("Computer picked: ", chosen);
|
||||
GuiUtils.chooseOne("Computer picked: ", new String[]{chosen});
|
||||
abMana.setExpressChoice(InputPayManaCostUtil.getShortColorString(chosen));
|
||||
}
|
||||
if (abMana.getExpressChoice().isEmpty()) {
|
||||
|
||||
@@ -390,7 +390,7 @@ public final class AbilityFactoryPlay {
|
||||
Card tgtCard = tgtCards.get(0);
|
||||
if (tgtCards.size() > 1) {
|
||||
if (controller.isHuman()) {
|
||||
tgtCard = GuiUtils.chooseOne("Select a card to play", tgtCards.toArray());
|
||||
tgtCard = GuiUtils.chooseOne("Select a card to play", tgtCards);
|
||||
} else {
|
||||
// AI
|
||||
tgtCards = tgtCards.filter(new CardListFilter() {
|
||||
|
||||
@@ -729,12 +729,10 @@ public final class AbilityFactoryProtection {
|
||||
final ArrayList<String> gains = new ArrayList<String>();
|
||||
if (isChoice) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final Object o = GuiUtils.chooseOne("Choose a protection", choices.toArray());
|
||||
|
||||
if (null == o) {
|
||||
final String choice = GuiUtils.chooseOne("Choose a protection", choices);
|
||||
if (null == choice) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
gains.add(choice);
|
||||
} else {
|
||||
String choice = choices.get(0);
|
||||
@@ -1161,12 +1159,10 @@ public final class AbilityFactoryProtection {
|
||||
final ArrayList<String> gains = new ArrayList<String>();
|
||||
if (isChoice) {
|
||||
if (sa.getActivatingPlayer().isHuman()) {
|
||||
final Object o = GuiUtils.chooseOne("Choose a protection", choices.toArray());
|
||||
|
||||
if (null == o) {
|
||||
final String choice = GuiUtils.chooseOne("Choose a protection", choices);
|
||||
if (null == choice) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
gains.add(choice);
|
||||
} else {
|
||||
// TODO - needs improvement
|
||||
|
||||
@@ -437,7 +437,7 @@ public final class AbilityFactoryReveal {
|
||||
boolean cardsRevealed = false;
|
||||
|
||||
if (params.containsKey("Reveal")) {
|
||||
GuiUtils.chooseOne("Revealing cards from library", top.toArray());
|
||||
GuiUtils.chooseOne("Revealing cards from library", top);
|
||||
cardsRevealed = true;
|
||||
// Singletons.getModel().getGameAction().revealToCopmuter(top.toArray());
|
||||
// - for when it exists
|
||||
@@ -447,18 +447,18 @@ public final class AbilityFactoryReveal {
|
||||
question += c + " ";
|
||||
}
|
||||
if (p.isHuman() && GameActionUtil.showYesNoDialog(host, question)) {
|
||||
GuiUtils.chooseOne(host + "Revealing cards from library", top.toArray());
|
||||
GuiUtils.chooseOne(host + "Revealing cards from library", top);
|
||||
// Singletons.getModel().getGameAction().revealToCopmuter(top.toArray());
|
||||
cardsRevealed = true;
|
||||
} else if (p.isComputer() && (top.get(0).isInstant() || top.get(0).isSorcery())) {
|
||||
GuiUtils.chooseOne(host + "Revealing cards from library", top.toArray());
|
||||
GuiUtils.chooseOne(host + "Revealing cards from library", top);
|
||||
cardsRevealed = true;
|
||||
}
|
||||
} else if (params.containsKey("RevealValid")) {
|
||||
final String revealValid = params.get("RevealValid");
|
||||
final CardList toReveal = top.getValidCards(revealValid, host.getController(), host);
|
||||
if (!toReveal.isEmpty()) {
|
||||
GuiUtils.chooseOne("Revealing cards from library", toReveal.toArray());
|
||||
GuiUtils.chooseOne("Revealing cards from library", toReveal);
|
||||
if (params.containsKey("RememberRevealed")) {
|
||||
for (final Card one : toReveal) {
|
||||
host.addRemembered(one);
|
||||
@@ -469,7 +469,7 @@ public final class AbilityFactoryReveal {
|
||||
// - for when it exists
|
||||
} else if (choser.isHuman()) {
|
||||
// show the user the revealed cards
|
||||
GuiUtils.chooseOne("Looking at cards from library", top.toArray());
|
||||
GuiUtils.chooseOne("Looking at cards from library", top);
|
||||
cardsRevealed = true;
|
||||
}
|
||||
|
||||
@@ -523,9 +523,9 @@ public final class AbilityFactoryReveal {
|
||||
prompt = "Chose a card to put on top of the ";
|
||||
}
|
||||
if (anyNumber || optional) {
|
||||
chosen = GuiUtils.chooseOneOrNone(prompt + destZone1, valid.toArray());
|
||||
chosen = GuiUtils.chooseOneOrNone(prompt + destZone1, valid);
|
||||
} else {
|
||||
chosen = GuiUtils.chooseOne(prompt + destZone1, valid.toArray());
|
||||
chosen = GuiUtils.chooseOne(prompt + destZone1, valid);
|
||||
}
|
||||
if ((chosen == null) || chosen.getName().equals("[No valid cards]")) {
|
||||
break;
|
||||
@@ -2423,10 +2423,10 @@ public final class AbilityFactoryReveal {
|
||||
} else {
|
||||
for (int i = 0; i < validamount; i++) {
|
||||
if (player.isHuman()) {
|
||||
final Object o = GuiUtils.chooseOne("Choose card(s) to reveal", valid.toArray());
|
||||
final Card o = GuiUtils.chooseOne("Choose card(s) to reveal", valid);
|
||||
if (o != null) {
|
||||
chosen.add((Card) o);
|
||||
valid.remove((Card) o);
|
||||
chosen.add(o);
|
||||
valid.remove(o);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -622,7 +622,7 @@ public class AbilityFactoryZoneAffecting {
|
||||
} else {
|
||||
final CardList drawn = p.drawCards(numCards);
|
||||
if (params.containsKey("Reveal")) {
|
||||
GuiUtils.chooseOne("Revealing drawn cards", drawn.toArray());
|
||||
GuiUtils.chooseOne("Revealing drawn cards", drawn);
|
||||
}
|
||||
if (params.containsKey("RememberDrawn")) {
|
||||
for (final Card c : drawn) {
|
||||
@@ -1430,11 +1430,9 @@ public class AbilityFactoryZoneAffecting {
|
||||
if (dPChHand.size() > 0) {
|
||||
Card dC = null;
|
||||
if (params.containsKey("Optional")) {
|
||||
dC = GuiUtils.chooseOneOrNone("Choose a card to be discarded",
|
||||
dPChHand.toArray());
|
||||
dC = GuiUtils.chooseOneOrNone("Choose a card to be discarded", dPChHand);
|
||||
} else {
|
||||
dC = GuiUtils.chooseOne("Choose a card to be discarded",
|
||||
dPChHand.toArray());
|
||||
dC = GuiUtils.chooseOne("Choose a card to be discarded", dPChHand);
|
||||
} if (dC != null) {
|
||||
dPChHand.remove(dC);
|
||||
discarded.add(dC);
|
||||
|
||||
@@ -598,9 +598,7 @@ class CardFactoryArtifacts {
|
||||
// Then look at the exiled cards and put them on
|
||||
// top of your library in any order.
|
||||
while (this.exiled.size() > 0) {
|
||||
final Object o = GuiUtils.chooseOne("Put a card on top of your library.",
|
||||
this.exiled.toArray());
|
||||
final Card c1 = (Card) o;
|
||||
final Card c1 = GuiUtils.chooseOne("Put a card on top of your library.", this.exiled);
|
||||
Singletons.getModel().getGameAction().moveToLibrary(c1);
|
||||
this.exiled.remove(c1);
|
||||
}
|
||||
|
||||
@@ -124,8 +124,7 @@ class CardFactoryAuras {
|
||||
public void resolve() {
|
||||
// Only query player, AI will have decided already.
|
||||
if (card.getController().isHuman()) {
|
||||
newType[0] = GuiUtils.chooseOne("Select land type.", "Plains", "Island", "Swamp", "Mountain",
|
||||
"Forest");
|
||||
newType[0] = GuiUtils.chooseOne("Select land type.", CardUtil.getLandTypes());
|
||||
}
|
||||
Singletons.getModel().getGameAction().moveToPlay(card);
|
||||
|
||||
|
||||
@@ -214,10 +214,8 @@ public class CardFactoryCreatures {
|
||||
.getType("Artifact");
|
||||
|
||||
if (artifacts.size() != 0) {
|
||||
Object o;
|
||||
o = GuiUtils.chooseOne("Select an artifact put a phylactery counter on", artifacts.toArray());
|
||||
if (o != null) {
|
||||
final Card c = (Card) o;
|
||||
final Card c = GuiUtils.chooseOne("Select an artifact put a phylactery counter on", artifacts);
|
||||
if (c != null) {
|
||||
c.addCounter(Counters.PHYLACTERY, 1);
|
||||
}
|
||||
}
|
||||
@@ -1355,7 +1353,7 @@ public class CardFactoryCreatures {
|
||||
hand.remove(random);
|
||||
}
|
||||
if (!revealed.isEmpty()) {
|
||||
GuiUtils.chooseOne("Revealed at random", revealed.toArray());
|
||||
GuiUtils.chooseOne("Revealed at random", revealed);
|
||||
} else {
|
||||
GuiUtils.chooseOne("Revealed at random", new String[] { "Nothing to reveal" });
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class CardFactoryEnchantments {
|
||||
chooseGrave.addAll(grave);
|
||||
}
|
||||
|
||||
final Object o = GuiUtils.chooseOne("Choose first creature to exile", chooseGrave.toArray());
|
||||
final Object o = GuiUtils.chooseOne("Choose first creature to exile", chooseGrave);
|
||||
if (o != null) {
|
||||
CardList newGrave;
|
||||
final Card c = (Card) o;
|
||||
@@ -111,7 +111,7 @@ class CardFactoryEnchantments {
|
||||
newGrave = newGrave.getType("Creature");
|
||||
newGrave.remove(c);
|
||||
|
||||
final Object o2 = GuiUtils.chooseOne("Choose second creature to exile", newGrave.toArray());
|
||||
final Object o2 = GuiUtils.chooseOne("Choose second creature to exile", newGrave);
|
||||
if (o2 != null) {
|
||||
final Card c2 = (Card) o2;
|
||||
newGrave.remove(c2);
|
||||
|
||||
@@ -188,9 +188,7 @@ public class CardFactoryInstants {
|
||||
|
||||
// NOTE: Using getChoiceOptional() results in a null error
|
||||
// when you click on Cancel.
|
||||
final Object o = GuiUtils.chooseOne("Select card to give to computer", selectedCards.toArray());
|
||||
|
||||
final Card choice = (Card) o;
|
||||
final Card choice = GuiUtils.chooseOne("Select card to give to computer", selectedCards);
|
||||
|
||||
selectedCards.remove(choice);
|
||||
Singletons.getModel().getGameAction().moveToHand(choice);
|
||||
@@ -235,7 +233,7 @@ public class CardFactoryInstants {
|
||||
|
||||
if (player.isHuman()) {
|
||||
for (int i = 0; i < x; i++) {
|
||||
final Object o = GuiUtils.chooseOne("Remove from game", graveList.toArray());
|
||||
final Object o = GuiUtils.chooseOne("Remove from game", graveList);
|
||||
if (o == null) {
|
||||
break;
|
||||
}
|
||||
@@ -387,7 +385,7 @@ public class CardFactoryInstants {
|
||||
}
|
||||
|
||||
for (int i = 0; (i < 3) && !choices.isEmpty(); i++) {
|
||||
final Object o = GuiUtils.chooseOne(this.prompt[i], choices.toArray());
|
||||
final Object o = GuiUtils.chooseOne(this.prompt[i], choices);
|
||||
final Card c1 = (Card) o;
|
||||
if (i == 0) {
|
||||
Singletons.getModel().getGameAction().moveToHand(c1);
|
||||
|
||||
@@ -113,13 +113,13 @@ public class CardFactorySorceries {
|
||||
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("Revealing top ").append(count).append(" cards of library: ");
|
||||
GuiUtils.chooseOne(msg.toString(), cards.toArray());
|
||||
GuiUtils.chooseOne(msg.toString(), cards);
|
||||
// Human chooses
|
||||
if (card.getController().isComputer()) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!stop) {
|
||||
choice = GuiUtils.chooseOneOrNone("Choose cards to put into the first pile: ",
|
||||
cards.toArray());
|
||||
cards);
|
||||
if (choice != null) {
|
||||
pile1.add(choice);
|
||||
cards.remove(choice);
|
||||
@@ -1492,20 +1492,18 @@ public class CardFactorySorceries {
|
||||
"Something in if(isCopiedSpell()) in Profane Command selection is FUBAR.");
|
||||
}
|
||||
} else {
|
||||
final ArrayList<String> choices = new ArrayList<String>();
|
||||
for (int i = 0; i <= card.getController().getLife(); i++) {
|
||||
choices.add("" + i);
|
||||
final int max = card.getController().getLife();
|
||||
final Integer[] choices = new Integer[max+1];
|
||||
for (int i = 0; i <= max; i++) {
|
||||
choices[i] = Integer.valueOf(i);
|
||||
}
|
||||
final Object o = GuiUtils.chooseOne("Choose X", choices.toArray());
|
||||
final Integer answer = GuiUtils.chooseOne("Choose X", choices);
|
||||
// everything stops here if user cancelled
|
||||
if (o == null) {
|
||||
if (answer == null) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
final String answer = (String) o;
|
||||
|
||||
x[0] = Integer.parseInt(answer);
|
||||
x[0] = answer;
|
||||
spell.setManaCost(x[0] + " B B");
|
||||
spell.setIsXCost(false);
|
||||
|
||||
|
||||
@@ -3352,11 +3352,8 @@ public class CardFactoryUtil {
|
||||
|
||||
for (final Card c : list) {
|
||||
final String name = c.getName();
|
||||
if (!map.containsKey(name)) {
|
||||
map.put(name, 1);
|
||||
} else {
|
||||
map.put(name, map.get(name) + 1);
|
||||
}
|
||||
Integer currentCnt = map.get(name);
|
||||
map.put(name, currentCnt == null ? Integer.valueOf(1) : Integer.valueOf(1 + currentCnt));
|
||||
} // for
|
||||
|
||||
int max = 0;
|
||||
|
||||
@@ -401,8 +401,7 @@ public class CostUtil {
|
||||
for (int i = 0; i < choiceArray.length; i++) {
|
||||
choiceArray[i] = i;
|
||||
}
|
||||
final Object o = GuiUtils.chooseOne(card.toString() + " - Choose a Value for X", choiceArray);
|
||||
final int chosenX = (Integer) o;
|
||||
final Integer chosenX = GuiUtils.chooseOne(card.toString() + " - Choose a Value for X", choiceArray);
|
||||
sa.setSVar("ChosenX", "Number$" + Integer.toString(chosenX));
|
||||
card.setSVar("ChosenX", "Number$" + Integer.toString(chosenX));
|
||||
|
||||
@@ -428,10 +427,9 @@ public class CostUtil {
|
||||
|
||||
final Integer[] choiceArray = new Integer[maxValue + 1];
|
||||
for (int i = 0; i < choiceArray.length; i++) {
|
||||
choiceArray[i] = i;
|
||||
choiceArray[i] = Integer.valueOf(i);
|
||||
}
|
||||
final Object o = GuiUtils.chooseOne(card.toString() + " - Choose a Value for Y", choiceArray);
|
||||
final int chosenY = (Integer) o;
|
||||
final Integer chosenY = GuiUtils.chooseOne(card.toString() + " - Choose a Value for Y", choiceArray);
|
||||
sa.setSVar("ChosenY", "Number$" + Integer.toString(chosenY));
|
||||
card.setSVar("ChosenY", "Number$" + Integer.toString(chosenY));
|
||||
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.card.spellability;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* SpellAbilityList class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SpellAbilityList {
|
||||
private final ArrayList<SpellAbility> list = new ArrayList<SpellAbility>();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SpellAbilityList.
|
||||
* </p>
|
||||
*/
|
||||
public SpellAbilityList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SpellAbilityList.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public SpellAbilityList(final SpellAbility s) {
|
||||
this.add(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for SpellAbilityList.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* an array of {@link forge.card.spellability.SpellAbility}
|
||||
* objects.
|
||||
*/
|
||||
public SpellAbilityList(final SpellAbility[] s) {
|
||||
for (final SpellAbility element : s) {
|
||||
this.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* remove.
|
||||
* </p>
|
||||
*
|
||||
* @param n
|
||||
* a int.
|
||||
*/
|
||||
public final void remove(final int n) {
|
||||
this.list.remove(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* add.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final void add(final SpellAbility s) {
|
||||
this.list.add(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* size.
|
||||
* </p>
|
||||
*
|
||||
* @return a int.
|
||||
*/
|
||||
public final int size() {
|
||||
return this.list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* get.
|
||||
* </p>
|
||||
*
|
||||
* @param n
|
||||
* a int.
|
||||
* @return a {@link forge.card.spellability.SpellAbility} object.
|
||||
*/
|
||||
public final SpellAbility get(final int n) {
|
||||
return this.list.get(n);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addAll.
|
||||
* </p>
|
||||
*
|
||||
* @param s
|
||||
* a {@link forge.card.spellability.SpellAbilityList} object.
|
||||
*/
|
||||
public final void addAll(final SpellAbilityList s) {
|
||||
for (int i = 0; i < s.size(); i++) {
|
||||
this.add(s.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Move1.getMax() uses this
|
||||
/**
|
||||
* <p>
|
||||
* execute.
|
||||
* </p>
|
||||
*/
|
||||
/*public final void execute() {
|
||||
for (int i = 0; i < this.size(); i++) {
|
||||
if (!ComputerUtil.canPayCost(this.get(i))) {
|
||||
throw new RuntimeException("SpellAbilityList : execute() error, cannot pay for the spell "
|
||||
+ this.get(i).getSourceCard() + " - " + this.get(i).getStackDescription());
|
||||
}
|
||||
|
||||
ComputerUtil.playNoStack(this.get(i));
|
||||
}
|
||||
}*/ // execute()
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < this.size(); i++) {
|
||||
sb.append(this.get(i).getSourceCard().toString());
|
||||
sb.append(" - ");
|
||||
sb.append(this.get(i).getStackDescription());
|
||||
sb.append("\r\n");
|
||||
}
|
||||
return sb.toString();
|
||||
} // toString()
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final boolean equals(final Object o) {
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
return this.toString().equals(o.toString());
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (41 * (41 + this.toString().hashCode()));
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public final class BoosterDraft implements IBoosterDraft {
|
||||
}
|
||||
|
||||
if (sets.length > 1) {
|
||||
final Object p = GuiUtils.chooseOne("Choose Set Combination", setCombos.toArray());
|
||||
final Object p = GuiUtils.chooseOne("Choose Set Combination", setCombos);
|
||||
final String[] pp = p.toString().split("/");
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
this.product.add(new UnOpenedProduct(Singletons.getModel().getBoosters().get(pp[i])));
|
||||
|
||||
@@ -120,7 +120,7 @@ public class SealedDeckFormat {
|
||||
}
|
||||
|
||||
if (sets.length > 1) {
|
||||
final Object p = GuiUtils.chooseOne("Choose Set Combination", setCombos.toArray());
|
||||
final Object p = GuiUtils.chooseOne("Choose Set Combination", setCombos);
|
||||
|
||||
final String[] pp = p.toString().split("/");
|
||||
|
||||
@@ -176,7 +176,7 @@ public class SealedDeckFormat {
|
||||
starterPacks.add(String.format("Two packs (%s, %s)", pp[starter1idx], pp[starter2idx]));
|
||||
}
|
||||
|
||||
final Object starterResult = GuiUtils.chooseOne("Choose starter pack(s):", starterPacks.toArray());
|
||||
final Object starterResult = GuiUtils.chooseOne("Choose starter pack(s):", starterPacks);
|
||||
|
||||
// Analyze the choice
|
||||
final String starters = starterResult.toString();
|
||||
@@ -250,7 +250,7 @@ public class SealedDeckFormat {
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final CustomLimited draft = (CustomLimited) GuiUtils.chooseOne("Choose Custom Sealed Pool",
|
||||
customs.toArray());
|
||||
customs);
|
||||
|
||||
final BoosterGenerator bpCustom = new BoosterGenerator(draft.getCardPool());
|
||||
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
|
||||
@@ -1982,7 +1982,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
|
||||
}
|
||||
} // for loop
|
||||
if (cardsToReveal.size() > 0) {
|
||||
GuiUtils.chooseOne("Revealed cards", cardsToReveal.toArray());
|
||||
GuiUtils.chooseOne("Revealed cards", cardsToReveal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public class HumanPlayer extends Player {
|
||||
final String[] choices = { "Yes", "No" };
|
||||
final Object o = GuiUtils.chooseOne("Do you want to dredge?", choices);
|
||||
if (o.equals("Yes")) {
|
||||
final Card c = GuiUtils.chooseOne("Select card to dredge", this.getDredge().toArray());
|
||||
final Card c = GuiUtils.chooseOne("Select card to dredge", this.getDredge());
|
||||
// rule 702.49a
|
||||
if (this.getDredgeNumber(c) <= AllZone.getHumanPlayer().getZone(ZoneType.Library).size()) {
|
||||
|
||||
@@ -181,9 +181,8 @@ public class HumanPlayer extends Player {
|
||||
protected final void doScry(final CardList topN, final int n) {
|
||||
int num = n;
|
||||
for (int i = 0; i < num; i++) {
|
||||
final Object o = GuiUtils.chooseOneOrNone("Put on bottom of library.", topN.toArray());
|
||||
if (o != null) {
|
||||
final Card c = (Card) o;
|
||||
final Card c = GuiUtils.chooseOneOrNone("Put on bottom of library.", topN.toArray());
|
||||
if (c != null) {
|
||||
topN.remove(c);
|
||||
Singletons.getModel().getGameAction().moveToBottomOfLibrary(c);
|
||||
} else {
|
||||
@@ -193,10 +192,8 @@ public class HumanPlayer extends Player {
|
||||
}
|
||||
num = topN.size();
|
||||
for (int i = 0; i < num; i++) {
|
||||
Object o;
|
||||
o = GuiUtils.chooseOne("Put on top of library.", topN.toArray());
|
||||
if (o != null) {
|
||||
final Card c = (Card) o;
|
||||
final Card c = GuiUtils.chooseOne("Put on top of library.", topN);
|
||||
if (c != null) {
|
||||
topN.remove(c);
|
||||
Singletons.getModel().getGameAction().moveToLibrary(c);
|
||||
}
|
||||
|
||||
@@ -1277,7 +1277,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
}
|
||||
}
|
||||
if (reveal) {
|
||||
GuiUtils.chooseOne("Revealing the first card drawn", drawn.toArray());
|
||||
GuiUtils.chooseOne("Revealing the first card drawn", drawn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.awt.Window;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -43,6 +44,7 @@ import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
import forge.gui.match.CMatchUI;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -242,7 +244,7 @@ public final class GuiUtils {
|
||||
* getChoices.
|
||||
* @see #getChoices(String, int, int, Object...)
|
||||
*/
|
||||
public static <T> T chooseOneOrNone(final String message, final T... choices) {
|
||||
public static <T> T chooseOneOrNone(final String message, final T[] choices) {
|
||||
if ((choices == null) || (choices.length == 0)) {
|
||||
return null;
|
||||
}
|
||||
@@ -250,6 +252,18 @@ public final class GuiUtils {
|
||||
return choice.isEmpty() ? null : choice.get(0);
|
||||
} // getChoiceOptional(String,T...)
|
||||
|
||||
public static <T> T chooseOneOrNone(final String message, final Collection<T> choices) {
|
||||
if ((choices == null) || (choices.size() == 0)) {
|
||||
return null;
|
||||
}
|
||||
final List<T> choice = GuiUtils.getChoices(message, 0, 1, choices);
|
||||
return choice.isEmpty() ? null : choice.get(0);
|
||||
} // getChoiceOptional(String,T...)
|
||||
|
||||
public static Card chooseOneOrNone(final String message, final CardList choices) {
|
||||
return chooseOneOrNone(message, choices.toArray());
|
||||
} // getChoiceOptional(String,T...)
|
||||
|
||||
// returned Object will never be null
|
||||
/**
|
||||
* <p>
|
||||
@@ -264,13 +278,24 @@ public final class GuiUtils {
|
||||
* a T object.
|
||||
* @return a T object.
|
||||
*/
|
||||
public static <T> T chooseOne(final String message, final T... choices) {
|
||||
public static <T> T chooseOne(final String message, final T[] choices) {
|
||||
final List<T> choice = GuiUtils.getChoices(message, 1, 1, choices);
|
||||
assert choice.size() == 1;
|
||||
return choice.get(0);
|
||||
} // getChoice()
|
||||
|
||||
public static <T> T chooseOne(final String message, final List<T> choices) {
|
||||
// Nothing to choose here. Code uses this to just show a card.
|
||||
public static Card chooseOne(final String message, final Card singleChoice) {
|
||||
List<Card> choices = new ArrayList<Card>();
|
||||
choices.add(singleChoice);
|
||||
return chooseOne(message, choices);
|
||||
}
|
||||
|
||||
public static Card chooseOne(final String message, final CardList cardList) {
|
||||
return chooseOne(message, cardList);
|
||||
}
|
||||
|
||||
public static <T> T chooseOne(final String message, final Collection<T> choices) {
|
||||
final List<T> choice = GuiUtils.getChoices(message, 1, 1, choices);
|
||||
assert choice.size() == 1;
|
||||
return choice.get(0);
|
||||
@@ -290,7 +315,7 @@ public final class GuiUtils {
|
||||
* a T object.
|
||||
* @return a {@link java.util.List} object.
|
||||
*/
|
||||
public static <T> List<T> chooseNoneOrMany(final String message, final T... choices) {
|
||||
public static <T> List<T> chooseNoneOrMany(final String message, final T[] choices) {
|
||||
return GuiUtils.getChoices(message, 0, choices.length, choices);
|
||||
} // getChoice()
|
||||
|
||||
@@ -308,7 +333,7 @@ public final class GuiUtils {
|
||||
* a T object.
|
||||
* @return a {@link java.util.List} object.
|
||||
*/
|
||||
public static <T> List<T> chooseOneOrMany(final String message, final T... choices) {
|
||||
public static <T> List<T> chooseOneOrMany(final String message, final T[] choices) {
|
||||
return GuiUtils.getChoices(message, 1, choices.length, choices);
|
||||
} // getChoice()
|
||||
|
||||
@@ -330,12 +355,12 @@ public final class GuiUtils {
|
||||
* a T object.
|
||||
* @return a {@link java.util.List} object.
|
||||
*/
|
||||
private static <T> List<T> getChoices(final String message, final int min, final int max, final T... choices) {
|
||||
private static <T> List<T> getChoices(final String message, final int min, final int max, final T[] choices) {
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
}
|
||||
|
||||
private static <T> List<T> getChoices(final String message, final int min, final int max, final List<T> choices) {
|
||||
private static <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices) {
|
||||
final ListChooser<T> c = new ListChooser<T>(message, min, max, choices);
|
||||
return getChoices(c);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,9 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowFocusListener;
|
||||
import java.util.AbstractList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
@@ -92,7 +93,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final T... list) {
|
||||
public ListChooser(final String title, final T[] list) {
|
||||
this(title, 1, list);
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final int numChoices, final T... list) {
|
||||
public ListChooser(final String title, final int numChoices, final T[] list) {
|
||||
this(title, numChoices, numChoices, list);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final int minChoices, final int maxChoices, final T... list) {
|
||||
public ListChooser(final String title, final int minChoices, final int maxChoices, final T[] list) {
|
||||
this(title, null, minChoices, maxChoices, list);
|
||||
}
|
||||
|
||||
@@ -142,7 +143,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final T... list) {
|
||||
public ListChooser(final String title, final String message, final T[] list) {
|
||||
this(title, message, 1, list);
|
||||
}
|
||||
|
||||
@@ -160,7 +161,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final int numChoices, final T... list) {
|
||||
public ListChooser(final String title, final String message, final int numChoices, final T[] list) {
|
||||
this(title, message, numChoices, numChoices, list);
|
||||
}
|
||||
|
||||
@@ -181,7 +182,7 @@ public class ListChooser<T> {
|
||||
* a T object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final int minChoices, final int maxChoices,
|
||||
final T... list) {
|
||||
final T[] list) {
|
||||
this(title, message, minChoices, maxChoices, Arrays.asList(list));
|
||||
}
|
||||
|
||||
@@ -211,7 +212,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a {@link java.util.List} object.
|
||||
*/
|
||||
public ListChooser(final String title, final int numChoices, final List<T> list) {
|
||||
public ListChooser(final String title, final int numChoices, final Collection<T> list) {
|
||||
this(title, numChoices, numChoices, list);
|
||||
}
|
||||
|
||||
@@ -229,7 +230,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a {@link java.util.List} object.
|
||||
*/
|
||||
public ListChooser(final String title, final int minChoices, final int maxChoices, final List<T> list) {
|
||||
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list) {
|
||||
this(title, null, minChoices, maxChoices, list);
|
||||
}
|
||||
|
||||
@@ -245,7 +246,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a {@link java.util.List} object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final List<T> list) {
|
||||
public ListChooser(final String title, final String message, final Collection<T> list) {
|
||||
this(title, message, 1, list);
|
||||
}
|
||||
|
||||
@@ -263,7 +264,7 @@ public class ListChooser<T> {
|
||||
* @param list
|
||||
* a {@link java.util.List} object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final int numChoices, final List<T> list) {
|
||||
public ListChooser(final String title, final String message, final int numChoices, final Collection<T> list) {
|
||||
this(title, message, numChoices, numChoices, list);
|
||||
}
|
||||
|
||||
@@ -284,11 +285,11 @@ public class ListChooser<T> {
|
||||
* a {@link java.util.List} object.
|
||||
*/
|
||||
public ListChooser(final String title, final String message, final int minChoices, final int maxChoices,
|
||||
final List<T> list) {
|
||||
final Collection<T> list) {
|
||||
this.title = title;
|
||||
this.minChoices = minChoices;
|
||||
this.maxChoices = maxChoices;
|
||||
this.list = Collections.unmodifiableList(list);
|
||||
this.list = new ArrayList<T>(list);
|
||||
this.jList = new JList(new ChooserListModel());
|
||||
this.ok = new CloseAction(JOptionPane.OK_OPTION, "OK");
|
||||
this.ok.setEnabled(minChoices == 0);
|
||||
|
||||
@@ -211,7 +211,7 @@ public enum CSubmenuDraft implements ICDoc {
|
||||
draftTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Draft Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, draftTypes.toArray());
|
||||
final Object o = GuiUtils.chooseOne(prompt, draftTypes);
|
||||
|
||||
if (o.toString().equals(draftTypes.get(0))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Full));
|
||||
|
||||
@@ -136,14 +136,14 @@ public enum CSubmenuSealed implements ICDoc {
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends DeckBase> void setupSealed() {
|
||||
|
||||
final ArrayList<String> sealedTypes = new ArrayList<String>();
|
||||
final List<String> sealedTypes = new ArrayList<String>();
|
||||
sealedTypes.add("Full Cardpool");
|
||||
sealedTypes.add("Block / Set");
|
||||
sealedTypes.add("Fantasy Block");
|
||||
sealedTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Sealed Deck Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, sealedTypes.toArray());
|
||||
final Object o = GuiUtils.chooseOne(prompt, sealedTypes);
|
||||
|
||||
SealedDeckFormat sd = null;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class ListChooserTest {
|
||||
*/
|
||||
@Test(groups = { "UnitTest", "fast" }, timeOut = 1000, enabled = false)
|
||||
public void listChooserTest1() {
|
||||
final ListChooser<String> c = new ListChooser<String>("test", "choose a or b", 0, 2, "a", "b");
|
||||
final ListChooser<String> c = new ListChooser<String>("test", "choose a or b", 0, 2, new String[] {"a", "b"});
|
||||
System.out.println(c.show());
|
||||
for (final String s : c.getSelectedValues()) {
|
||||
System.out.println(s);
|
||||
|
||||
Reference in New Issue
Block a user