allow multiple color selections in AF_ChooseColor via a "OrColors$" parameter. Please note, the chioce dialog for colors is multi-select (like, pick one, ctrl+click to pick another, etc...)

This commit is contained in:
slapshot5
2011-10-14 12:02:59 +00:00
parent 2afcf6e8be
commit 32a70a1275
8 changed files with 162 additions and 33 deletions

View File

@@ -163,7 +163,8 @@ public class Card extends GameEntity implements Comparable<Card> {
private String echoCost = ""; private String echoCost = "";
private String madnessCost = ""; private String madnessCost = "";
private String chosenType = ""; private String chosenType = "";
private String chosenColor = ""; //private String chosenColor = "";
private ArrayList<String> chosenColor = new ArrayList<String>();
private String namedCard = ""; private String namedCard = "";
private int chosenNumber; private int chosenNumber;
private Player chosenPlayer; private Player chosenPlayer;
@@ -1427,18 +1428,18 @@ public class Card extends GameEntity implements Comparable<Card> {
/** /**
* <p>Getter for the field <code>chosenColor</code>.</p> * <p>Getter for the field <code>chosenColor</code>.</p>
* *
* @return a {@link java.lang.String} object. * @return an ArrayList<String> object.
*/ */
public final String getChosenColor() { public final ArrayList<String> getChosenColor() {
return chosenColor; return chosenColor;
} }
/** /**
* <p>Setter for the field <code>chosenColor</code>.</p> * <p>Setter for the field <code>chosenColor</code>.</p>
* *
* @param s a {@link java.lang.String} object. * @param s an ArrayList<String> object.
*/ */
public final void setChosenColor(final String s) { public final void setChosenColor(final ArrayList<String> s) {
chosenColor = s; chosenColor = s;
} }

View File

@@ -477,8 +477,8 @@ public final class AbilityFactory_Animate {
if (params.containsKey("Colors")) { if (params.containsKey("Colors")) {
String colors = params.get("Colors"); String colors = params.get("Colors");
if (colors.equals("ChosenColor")) { if (colors.equals("ChosenColor")) {
tmpDesc = CardUtil.getShortColorsString(
new ArrayList<String>(Arrays.asList(host.getChosenColor().split(",")))); tmpDesc = CardUtil.getShortColorsString(host.getChosenColor());
} else { } else {
tmpDesc = CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(",")))); tmpDesc = CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(","))));
} }
@@ -1012,8 +1012,7 @@ public final class AbilityFactory_Animate {
if (params.containsKey("Colors")) { if (params.containsKey("Colors")) {
String colors = params.get("Colors"); String colors = params.get("Colors");
if (colors.equals("ChosenColor")) { if (colors.equals("ChosenColor")) {
tmpDesc = CardUtil.getShortColorsString( tmpDesc = CardUtil.getShortColorsString(host.getChosenColor());
new ArrayList<String>(Arrays.asList(host.getChosenColor().split(","))));
} else { } else {
tmpDesc = CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(",")))); tmpDesc = CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(","))));
} }

View File

@@ -20,11 +20,10 @@ import forge.card.spellability.Spell;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Random; import java.util.Random;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@@ -488,6 +487,7 @@ public class AbilityFactory_Choose {
* @return a {@link java.lang.String} object. * @return a {@link java.lang.String} object.
*/ */
private static String chooseColorStackDescription(final AbilityFactory af, final SpellAbility sa) { private static String chooseColorStackDescription(final AbilityFactory af, final SpellAbility sa) {
HashMap<String, String> params = af.getMapParams();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (!(sa instanceof Ability_Sub)) { if (!(sa instanceof Ability_Sub)) {
@@ -510,7 +510,11 @@ public class AbilityFactory_Choose {
for (Player p : tgtPlayers) { for (Player p : tgtPlayers) {
sb.append(p).append(" "); sb.append(p).append(" ");
} }
sb.append("chooses a color."); sb.append("chooses a color");
if (params.containsKey("OrColors")) {
sb.append(" or colors");
}
sb.append(".");
Ability_Sub abSub = sa.getSubAbility(); Ability_Sub abSub = sa.getSubAbility();
if (abSub != null) { if (abSub != null) {
@@ -586,13 +590,36 @@ public class AbilityFactory_Choose {
for (Player p : tgtPlayers) { for (Player p : tgtPlayers) {
if (tgt == null || p.canTarget(sa)) { if (tgt == null || p.canTarget(sa)) {
List<String> colors = new ArrayList<String>(Arrays.asList(Constant.Color.onlyColors));
if (sa.getActivatingPlayer().isHuman()) { if (sa.getActivatingPlayer().isHuman()) {
Object o = GuiUtils.getChoice("Choose a color", Constant.Color.onlyColors); if (params.containsKey("OrColors")) {
if (null == o) { //ArrayList<String> chosenColors = new ArrayList<String>();
return; //boolean done = false;
//while (!done) {
List<String> o = GuiUtils.getChoices("Choose a color or colors", colors.toArray(new String[0]));
/*if (null == o) {
done = true;
}
else {
String thisColor = (String) o;
chosenColors.add(thisColor);
colors.remove(thisColor);
card.setChosenColor(chosenColors);
}
*/
card.setChosenColor(new ArrayList<String>(o));
//}
}
else {
Object o = GuiUtils.getChoice("Choose a color", Constant.Color.onlyColors);
if (null == o) {
return;
}
String choice = (String) o;
ArrayList<String> tmpColors = new ArrayList<String>();
tmpColors.add(choice);
card.setChosenColor(tmpColors);
} }
String choice = (String) o;
card.setChosenColor(choice);
} else { } else {
String chosen = ""; String chosen = "";
if (params.containsKey("AILogic")) { if (params.containsKey("AILogic")) {
@@ -615,7 +642,9 @@ public class AbilityFactory_Choose {
chosen = Constant.Color.Green; chosen = Constant.Color.Green;
} }
GuiUtils.getChoice("Computer picked: ", chosen); GuiUtils.getChoice("Computer picked: ", chosen);
card.setChosenColor(chosen); ArrayList<String> colorTemp = new ArrayList<String>();
colorTemp.add(chosen);
card.setChosenColor(colorTemp);
} }
} }
} }

View File

@@ -242,7 +242,8 @@ public class AbilityFactory_Mana {
String baseMana = abMana.mana(); String baseMana = abMana.mana();
if (baseMana.equals("Chosen")){ if (baseMana.equals("Chosen")){
baseMana = Input_PayManaCostUtil.getShortColorString(card.getChosenColor()); //this will only support 1 chosen color for now.
baseMana = Input_PayManaCostUtil.getShortColorString(card.getChosenColor().get(0));
} }
if (params.containsKey("Bonus")) { if (params.containsKey("Bonus")) {

View File

@@ -18,6 +18,7 @@ import forge.card.spellability.*;
import forge.gui.GuiUtils; import forge.gui.GuiUtils;
import javax.swing.*; import javax.swing.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -1811,7 +1812,13 @@ public final class AbilityFactory_Reveal {
} }
if (tgtPlayers.size() > 0) { if (tgtPlayers.size() > 0) {
sb.append(tgtPlayers.get(0)).append(" reveals a card "); sb.append(tgtPlayers.get(0)).append(" reveals ");
if (params.containsKey("AnyNumber")) {
sb.append("any number of cards ");
}
else {
sb.append("a card ");
}
if (params.containsKey("Random")) { if (params.containsKey("Random")) {
sb.append("at random "); sb.append("at random ");
} }
@@ -1930,15 +1937,92 @@ public final class AbilityFactory_Reveal {
if (tgt == null || p.canTarget(sa)) { if (tgt == null || p.canTarget(sa)) {
CardList handChoices = p.getCardsIn(Zone.Hand); CardList handChoices = p.getCardsIn(Zone.Hand);
if (handChoices.size() > 0) { if (handChoices.size() > 0) {
Card random = CardUtil.getRandom(handChoices.toArray()); CardList revealed = new CardList();
if (params.containsKey("RememberRevealed")) { if (params.containsKey("Random")) {
host.addRemembered(random); revealed.add(CardUtil.getRandom(handChoices.toArray()));
GuiUtils.getChoice("Revealed card(s)", revealed.toArray());
} }
GuiUtils.getChoice("Random card", new CardList(random).toArray()); else if (params.containsKey("AnyNumber")) {
CardList valid = new CardList(handChoices);
if (params.containsKey("RevealValid")) {
valid = valid.getValidCards(params.get("RevealValid"), p, host);
}
revealed.addAll(getRevealedList(host, sa, valid));
}
if (params.containsKey("RememberRevealed")) {
for(Card rem : revealed) {
host.addRemembered(rem);
}
}
} }
} }
} }
} }
private static CardList getRevealedList(final Card card, final SpellAbility sa, final CardList valid) {
final CardList revealed = new CardList();
if (sa.getActivatingPlayer().isComputer()) {
//not really implemented for computer
//would need GuiUtils.getChoice("Revealed card(s)", revealed.toArray());
}
else {
}
return revealed;
}
/*
private static CardList getRevealedList(final Card card, final SpellAbility sa, final CardList valid) {
final CardList revealed = new CardList();
if (sa.getActivatingPlayer().isComputer()) {
//not really implemented for computer
//would need GuiUtils.getChoice("Revealed card(s)", revealed.toArray());
}
else {
AllZone.getInputControl().setInput(new Input() {
private static final long serialVersionUID = 3851585340769670736L;
@Override
public void showMessage() {
//in case hand is empty, don't do anything
if (card.getController().getCardsIn(Zone.Hand).size() == 0) stop();
AllZone.getDisplay().showMessage(card.getName() + " - Reveal a card. Revealed " + revealed.size() + " so far. Click OK when done.");
ButtonUtil.enableOnlyOK();
}
@Override
public void selectCard(Card c, PlayerZone zone) {
if (zone.is(Constant.Zone.Hand) && valid.contains(c) && !revealed.contains(c)) {
revealed.add(c);
//in case no more cards in hand to reveal
if (revealed.size() == card.getController().getCardsIn(Zone.Hand).size()) {
done();
}
else {
showMessage();
}
}
}
@Override
public void selectButtonOK() {
done();
}
void done() {
stop();
GuiUtils.getChoice("Revealed card(s)", revealed.toArray());
}
});
}
return revealed;
}
*/
} //end class AbilityFactory_Reveal } //end class AbilityFactory_Reveal

View File

@@ -367,7 +367,8 @@ public class AbilityFactory_Token extends AbilityFactory {
String[] substitutedColors = Arrays.copyOf(tokenColors, tokenColors.length); String[] substitutedColors = Arrays.copyOf(tokenColors, tokenColors.length);
for (int i = 0; i < substitutedColors.length; i++) { for (int i = 0; i < substitutedColors.length; i++) {
if (substitutedColors[i].equals("ChosenColor")) { if (substitutedColors[i].equals("ChosenColor")) {
substitutedColors[i] = host.getChosenColor(); //this currently only supports 1 chosen color
substitutedColors[i] = host.getChosenColor().get(0);
} }
} }
String colorDesc = ""; String colorDesc = "";

View File

@@ -787,7 +787,9 @@ public class CardFactory_Creatures {
} }
} }
} }
card.setChosenColor(color[0]); ArrayList<String> colors = new ArrayList<String>();
colors.add(color[0]);
card.setChosenColor(colors);
String s = CardUtil.getShortColor(color[0]); String s = CardUtil.getShortColor(color[0]);
timeStamp[0] = AllZone.getColorChanger().addColorChanges(s, card, true, true); timeStamp[0] = AllZone.getColorChanger().addColorChanges(s, card, true, true);
@@ -1547,7 +1549,9 @@ public class CardFactory_Creatures {
Object o = GuiUtils.getChoice("Choose color", colors); Object o = GuiUtils.getChoice("Choose color", colors);
color = (String) o; color = (String) o;
card.setChosenColor(color); ArrayList<String> colorTemp = new ArrayList<String>();
colorTemp.add(color);
card.setChosenColor(colorTemp);
} else { } else {
CardList list = new CardList(); CardList list = new CardList();
list.addAll(AllZone.getHumanPlayer().getCardsIn(Zone.Library)); list.addAll(AllZone.getHumanPlayer().getCardsIn(Zone.Library));
@@ -1555,10 +1559,20 @@ public class CardFactory_Creatures {
if (list.size() > 0) { if (list.size() > 0) {
String color = CardFactoryUtil.getMostProminentColor(list); String color = CardFactoryUtil.getMostProminentColor(list);
if (!color.equals("")) card.setChosenColor(color); if (!color.equals("")) {
else card.setChosenColor("black"); ArrayList<String> colorTemp = new ArrayList<String>();
colorTemp.add(color);
card.setChosenColor(colorTemp);
}
else {
ArrayList<String> colorTemp = new ArrayList<String>();
colorTemp.add("black");
card.setChosenColor(colorTemp);
}
} else { } else {
card.setChosenColor("black"); ArrayList<String> colorTemp = new ArrayList<String>();
colorTemp.add("black");
card.setChosenColor(colorTemp);
} }
} }
} }

View File

@@ -237,9 +237,9 @@ public class CardDetailPanel extends JPanel implements CardContainer {
} }
//chosen color //chosen color
if (card.getChosenColor() != "") { if (!card.getChosenColor().isEmpty()) {
if (area.length() != 0) area.append("\n"); if (area.length() != 0) area.append("\n");
area.append("(chosen color: "); area.append("(chosen colors: ");
area.append(card.getChosenColor()); area.append(card.getChosenColor());
area.append(")"); area.append(")");
} }