Show cost payment prompts during ability resolve using Prompt pane instead of a dialog

This commit is contained in:
drdev
2013-12-13 06:17:03 +00:00
parent 90ff1abab8
commit 38344027ca
2 changed files with 72 additions and 53 deletions

View File

@@ -31,13 +31,13 @@ public class Lang {
return position + sufixes[position % 10]; return position + sufixes[position % 10];
} }
} }
public static <T> String joinHomogenous(String s1, String s2) { public static <T> String joinHomogenous(String s1, String s2) {
boolean has1 = StringUtils.isNotBlank(s1); boolean has1 = StringUtils.isNotBlank(s1);
boolean has2 = StringUtils.isNotBlank(s2); boolean has2 = StringUtils.isNotBlank(s2);
return has1 ? (has2 ? s1 + " and " + s2 : s1) : (has2 ? s2 : ""); return has1 ? (has2 ? s1 + " and " + s2 : s1) : (has2 ? s2 : "");
} }
public static <T> String joinHomogenous(Iterable<T> objects) { return joinHomogenous(Lists.newArrayList(objects)); } public static <T> String joinHomogenous(Iterable<T> objects) { return joinHomogenous(Lists.newArrayList(objects)); }
public static <T> String joinHomogenous(Collection<T> objects) { return joinHomogenous(objects, null, "and"); } public static <T> String joinHomogenous(Collection<T> objects) { return joinHomogenous(objects, null, "and"); }
public static <T> String joinHomogenous(Collection<T> objects, Function<T, String> accessor) { public static <T> String joinHomogenous(Collection<T> objects, Function<T, String> accessor) {
@@ -46,85 +46,92 @@ public class Lang {
public static <T> String joinHomogenous(Collection<T> objects, Function<T, String> accessor, String lastUnion) { public static <T> String joinHomogenous(Collection<T> objects, Function<T, String> accessor, String lastUnion) {
int remaining = objects.size(); int remaining = objects.size();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(T obj : objects) { for (T obj : objects) {
remaining--; remaining--;
if( accessor != null ) if (accessor != null) {
sb.append(accessor.apply(obj)); sb.append(accessor.apply(obj));
else }
else {
sb.append(obj); sb.append(obj);
if( remaining > 1 ) sb.append(", "); }
if( remaining == 1 ) sb.append(" ").append(lastUnion).append(" "); if (remaining > 1) {
sb.append(", ");
}
else if (remaining == 1) {
sb.append(" ").append(lastUnion).append(" ");
}
} }
return sb.toString(); return sb.toString();
} }
public static <T> String joinVerb(List<T> subjects, String verb) { public static <T> String joinVerb(List<T> subjects, String verb) {
return subjects.size() > 1 || !subjectIsSingle3rdPerson(Iterables.getFirst(subjects, "it").toString()) ? verb : verbs3rdPersonSingular(verb); return subjects.size() > 1 || !subjectIsSingle3rdPerson(Iterables.getFirst(subjects, "it").toString()) ? verb : verbs3rdPersonSingular(verb);
} }
public static String joinVerb(String subject, String verb) { public static String joinVerb(String subject, String verb) {
return !Lang.subjectIsSingle3rdPerson(subject) ? verb : verbs3rdPersonSingular(verb); return !Lang.subjectIsSingle3rdPerson(subject) ? verb : verbs3rdPersonSingular(verb);
} }
public static boolean subjectIsSingle3rdPerson(String subject) { public static boolean subjectIsSingle3rdPerson(String subject) {
// Will be most simple // Will be most simple
return !"You".equalsIgnoreCase(subject); return !"You".equalsIgnoreCase(subject);
} }
public static String verbs3rdPersonSingular(String verb) { public static String verbs3rdPersonSingular(String verb) {
// English is simple - just add (s) for multiple objects. // English is simple - just add (s) for multiple objects.
return verb + "s"; return verb + "s";
} }
public static String getPlural(String noun) { public static String getPlural(String noun) {
return noun + ( noun.endsWith("s") || noun.endsWith("x") ? "es" : "s"); return noun + (noun.endsWith("s") || noun.endsWith("x") ? "es" : "s");
} }
public static <T> String nounWithAmount(int cnt, String noun) { public static <T> String nounWithAmount(int cnt, String noun) {
String countedForm = cnt <= 1 ? noun : getPlural(noun); String countedForm = cnt == 1 ? noun : getPlural(noun);
final String strCount; final String strCount;
if( cnt == 1 ) if (cnt == 1) {
strCount = startsWithVowel(noun) ? "an " : "a "; strCount = startsWithVowel(noun) ? "an " : "a ";
else }
strCount = String.valueOf(cnt) + " "; else {
strCount = String.valueOf(cnt) + " ";
}
return strCount + countedForm; return strCount + countedForm;
} }
public static <T> String nounWithNumeral(int cnt, String noun) { public static <T> String nounWithNumeral(int cnt, String noun) {
String countedForm = cnt <= 1 ? noun : getPlural(noun); String countedForm = cnt <= 1 ? noun : getPlural(noun);
return getNumeral(cnt) + " " + countedForm; return getNumeral(cnt) + " " + countedForm;
} }
public static String getPossesive(String name) { public static String getPossesive(String name) {
if ("You".equalsIgnoreCase(name)) return name + "r"; // to get "your" if ("You".equalsIgnoreCase(name)) return name + "r"; // to get "your"
return name.endsWith("s") ? name + "'" : name + "'s"; return name.endsWith("s") ? name + "'" : name + "'s";
} }
public static boolean startsWithVowel(String word) { public static boolean startsWithVowel(String word) {
return isVowel(word.trim().charAt(0)); return isVowel(word.trim().charAt(0));
} }
private static final char[] vowels = { 'a', 'i', 'e', 'o', 'u' }; private static final char[] vowels = { 'a', 'i', 'e', 'o', 'u' };
public static boolean isVowel(char letter) { public static boolean isVowel(char letter) {
char l = Character.toLowerCase(letter); char l = Character.toLowerCase(letter);
for(char c : vowels) for (char c : vowels) {
if ( c == l ) return true; if (c == l) return true;
}
return false; return false;
} }
public final static String[] numbers0 = new String[] { public final static String[] numbers0 = new String[] {
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen" }; "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eightteen", "nineteen" };
public final static String[] numbers20 = new String[] {"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" }; public final static String[] numbers20 = new String[] {"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
public static String getNumeral(int n) { public static String getNumeral(int n) {
String prefix = n < 0 ? "minus " : ""; String prefix = n < 0 ? "minus " : "";
n = Math.abs(n); n = Math.abs(n);
if ( n >= 0 && n < 20 ) if (n >= 0 && n < 20)
return prefix + numbers0[n]; return prefix + numbers0[n];
if ( n < 100 ) { if (n < 100) {
int n1 = n % 10; int n1 = n % 10;
String ones = n1 == 0 ? "" : numbers0[n1]; String ones = n1 == 0 ? "" : numbers0[n1];
return prefix + numbers20[(n / 10) - 2] + " " + ones; return prefix + numbers20[(n / 10) - 2] + " " + ones;

View File

@@ -54,12 +54,12 @@ import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions; import forge.game.spellability.TargetRestrictions;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;
import forge.gui.GuiDialog;
import forge.gui.input.InputPayMana; import forge.gui.input.InputPayMana;
import forge.gui.input.InputPayManaExecuteCommands; import forge.gui.input.InputPayManaExecuteCommands;
import forge.gui.input.InputPayManaSimple; import forge.gui.input.InputPayManaSimple;
import forge.gui.input.InputSelectCards; import forge.gui.input.InputSelectCards;
import forge.gui.input.InputSelectCardsFromList; import forge.gui.input.InputSelectCardsFromList;
import forge.gui.input.InputYesOrNo;
import forge.util.Lang; import forge.util.Lang;
/** /**
@@ -300,15 +300,18 @@ public class HumanPlay {
if (!parts.isEmpty()) { if (!parts.isEmpty()) {
costPart = parts.get(0); costPart = parts.get(0);
} }
final String orString = prompt != null ? "" : " (or: " + sourceAbility.getStackDescription() + ")"; String orString = prompt == null ? sourceAbility.getStackDescription().trim() : "";
if (!orString.isEmpty()) {
orString = " (or: " + orString + ")";
}
if (parts.isEmpty() || (costPart.getAmount().equals("0") && parts.size() < 2)) { if (parts.isEmpty() || (costPart.getAmount().equals("0") && parts.size() < 2)) {
return GuiDialog.confirm(source, "Do you want to pay 0?" + orString); return InputYesOrNo.ask("Do you want to pay {0}?" + orString);
} }
// 0 mana costs were slipping through because CostPart.getAmount returns 1 // 0 mana costs were slipping through because CostPart.getAmount returns 1
else if (costPart instanceof CostPartMana && parts.size() < 2) { else if (costPart instanceof CostPartMana && parts.size() < 2) {
if (((CostPartMana) costPart).getManaToPay().isZero()) { if (((CostPartMana) costPart).getManaToPay().isZero()) {
return GuiDialog.confirm(source, "Do you want to pay 0?" + orString); return InputYesOrNo.ask("Do you want to pay {0}?" + orString);
} }
} }
@@ -318,11 +321,13 @@ public class HumanPlay {
if (part instanceof CostPayLife) { if (part instanceof CostPayLife) {
final int amount = getAmountFromPart(part, source, sourceAbility); final int amount = getAmountFromPart(part, source, sourceAbility);
if (!p.canPayLife(amount)) if (!p.canPayLife(amount)) {
return false; return false;
}
if (false == GuiDialog.confirm(source, "Do you want to pay " + amount + " life?" + orString)) if (!InputYesOrNo.ask("Do you want to pay " + amount + " life?" + orString)) {
return false; return false;
}
p.payLife(amount, null); p.payLife(amount, null);
} }
@@ -345,9 +350,13 @@ public class HumanPlay {
sb.append("Do you want to "); sb.append("Do you want to ");
sb.append(res.contains(p) ? "" : "let that player "); sb.append(res.contains(p) ? "" : "let that player ");
sb.append("draw " + amount); sb.append("draw " + amount);
sb.append(" card(s)?" + orString); sb.append(" card");
if (amount != 1) {
sb.append("s");
}
sb.append("?" + orString);
if (!GuiDialog.confirm(source, sb.toString())) { if (!InputYesOrNo.ask(sb.toString())) {
return false; return false;
} }
@@ -361,7 +370,7 @@ public class HumanPlay {
} }
} }
else if (part instanceof CostAddMana) { else if (part instanceof CostAddMana) {
if (!GuiDialog.confirm(source, "Do you want to add " if (!InputYesOrNo.ask("Do you want to add "
+ ((CostAddMana) part).toString() + ((CostAddMana) part).toString()
+ " to your mana pool?" + orString)) { + " to your mana pool?" + orString)) {
return false; return false;
@@ -374,7 +383,8 @@ public class HumanPlay {
final int amount = getAmountFromPart(part, source, sourceAbility); final int amount = getAmountFromPart(part, source, sourceAbility);
final List<Card> list = p.getCardsIn(ZoneType.Library); final List<Card> list = p.getCardsIn(ZoneType.Library);
if (list.size() < amount) { return false; } if (list.size() < amount) { return false; }
if (!GuiDialog.confirm(source, "Do you want to mill " + amount + " card(s)?" + orString)) { if (!InputYesOrNo.ask("Do you want to mill " + amount +
" card" + (amount == 1 ? "" : "s") + "?" + orString)) {
return false; return false;
} }
List<Card> listmill = p.getCardsIn(ZoneType.Library, amount); List<Card> listmill = p.getCardsIn(ZoneType.Library, amount);
@@ -382,7 +392,8 @@ public class HumanPlay {
} }
else if (part instanceof CostFlipCoin) { else if (part instanceof CostFlipCoin) {
final int amount = getAmountFromPart(part, source, sourceAbility); final int amount = getAmountFromPart(part, source, sourceAbility);
if (!GuiDialog.confirm(source, "Do you want to flip " + amount + " coin(s)?" + orString)) { if (!InputYesOrNo.ask("Do you want to flip " + amount +
" coin" + (amount == 1 ? "" : "s") + "?" + orString)) {
return false; return false;
} }
final int n = FlipCoinEffect.getFilpMultiplier(p); final int n = FlipCoinEffect.getFilpMultiplier(p);
@@ -396,7 +407,7 @@ public class HumanPlay {
return false; return false;
} }
if (false == GuiDialog.confirm(source, "Do you want " + source + " to deal " + amount + " damage to you?")) { if (!InputYesOrNo.ask("Do you want " + source + " to deal " + amount + " damage to you?")) {
return false; return false;
} }
@@ -412,7 +423,7 @@ public class HumanPlay {
return false; return false;
} }
if (!GuiDialog.confirm(source, "Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + source + "?")) { if (!InputYesOrNo.ask("Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + source + "?")) {
return false; return false;
} }
@@ -422,12 +433,12 @@ public class HumanPlay {
List<Card> list = p.getGame().getCardsIn(ZoneType.Battlefield); List<Card> list = p.getGame().getCardsIn(ZoneType.Battlefield);
list = CardLists.getValidCards(list, part.getType().split(";"), p, source); list = CardLists.getValidCards(list, part.getType().split(";"), p, source);
if (list.isEmpty()) { return false; } if (list.isEmpty()) { return false; }
if (!GuiDialog.confirm(source, "Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + part.getTypeDescription() + "?")) { if (!InputYesOrNo.ask("Do you want to put " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " on " + part.getTypeDescription() + "?")) {
return false; return false;
} }
while (amount > 0) { while (amount > 0) {
InputSelectCards inp = new InputSelectCardsFromList(1, 1, list); InputSelectCards inp = new InputSelectCardsFromList(1, 1, list);
inp.setMessage("Select a card to add a counter"); inp.setMessage("Select a card to add a counter to");
inp.setCancelAllowed(true); inp.setCancelAllowed(true);
Singletons.getControl().getInputQueue().setInputAndWait(inp); Singletons.getControl().getInputQueue().setInputAndWait(inp);
if (inp.hasCancelled()) { if (inp.hasCancelled()) {
@@ -447,7 +458,7 @@ public class HumanPlay {
return false; return false;
} }
if (false == GuiDialog.confirm(source, "Do you want to remove " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " from " + source + "?")) { if (!InputYesOrNo.ask("Do you want to remove " + Lang.nounWithAmount(amount, counterType.getName() + " counter") + " from " + source + "?")) {
return false; return false;
} }
@@ -463,8 +474,8 @@ public class HumanPlay {
allCounters += value; allCounters += value;
} }
} }
if (allCounters < amount) return false; if (allCounters < amount) { return false; }
if (!GuiDialog.confirm(source, "Do you want to remove counters from " + part.getDescriptiveType() + " ?")) { if (!InputYesOrNo.ask("Do you want to remove counters from " + part.getDescriptiveType() + " ?")) {
return false; return false;
} }
@@ -506,7 +517,7 @@ public class HumanPlay {
} }
else if (part instanceof CostExile) { else if (part instanceof CostExile) {
if ("All".equals(part.getType())) { if ("All".equals(part.getType())) {
if (false == GuiDialog.confirm(source, "Do you want to exile all cards in your graveyard?")) { if (!InputYesOrNo.ask("Do you want to exile all cards in your graveyard?")) {
return false; return false;
} }
@@ -524,7 +535,8 @@ public class HumanPlay {
return false; return false;
} }
if (from == ZoneType.Library) { if (from == ZoneType.Library) {
if (!GuiDialog.confirm(source, "Do you want to exile card(s) from you library?")) { if (!InputYesOrNo.ask("Do you want to exile " + nNeeded +
" card" + (nNeeded == 1 ? "" : "s") + " from your library?")) {
return false; return false;
} }
list = list.subList(0, nNeeded); list = list.subList(0, nNeeded);