From 38344027ca789bf18c573736aba3190a01693a6d Mon Sep 17 00:00:00 2001 From: drdev Date: Fri, 13 Dec 2013 06:17:03 +0000 Subject: [PATCH] Show cost payment prompts during ability resolve using Prompt pane instead of a dialog --- forge-core/src/main/java/forge/util/Lang.java | 73 ++++++++++--------- .../java/forge/game/player/HumanPlay.java | 52 ++++++++----- 2 files changed, 72 insertions(+), 53 deletions(-) diff --git a/forge-core/src/main/java/forge/util/Lang.java b/forge-core/src/main/java/forge/util/Lang.java index 1aba93bfd15..183d509e413 100644 --- a/forge-core/src/main/java/forge/util/Lang.java +++ b/forge-core/src/main/java/forge/util/Lang.java @@ -31,13 +31,13 @@ public class Lang { return position + sufixes[position % 10]; } } - - public static String joinHomogenous(String s1, String s2) { + + public static String joinHomogenous(String s1, String s2) { boolean has1 = StringUtils.isNotBlank(s1); boolean has2 = StringUtils.isNotBlank(s2); return has1 ? (has2 ? s1 + " and " + s2 : s1) : (has2 ? s2 : ""); } - + public static String joinHomogenous(Iterable objects) { return joinHomogenous(Lists.newArrayList(objects)); } public static String joinHomogenous(Collection objects) { return joinHomogenous(objects, null, "and"); } public static String joinHomogenous(Collection objects, Function accessor) { @@ -46,85 +46,92 @@ public class Lang { public static String joinHomogenous(Collection objects, Function accessor, String lastUnion) { int remaining = objects.size(); StringBuilder sb = new StringBuilder(); - for(T obj : objects) { + for (T obj : objects) { remaining--; - if( accessor != null ) + if (accessor != null) { sb.append(accessor.apply(obj)); - else + } + else { 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(); } - - + public static String joinVerb(List subjects, String verb) { return subjects.size() > 1 || !subjectIsSingle3rdPerson(Iterables.getFirst(subjects, "it").toString()) ? verb : verbs3rdPersonSingular(verb); } - + public static String joinVerb(String subject, String verb) { return !Lang.subjectIsSingle3rdPerson(subject) ? verb : verbs3rdPersonSingular(verb); } - + public static boolean subjectIsSingle3rdPerson(String subject) { // Will be most simple return !"You".equalsIgnoreCase(subject); } public static String verbs3rdPersonSingular(String verb) { - // English is simple - just add (s) for multiple objects. - return verb + "s"; + // English is simple - just add (s) for multiple objects. + return verb + "s"; } 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 String nounWithAmount(int cnt, String noun) { - String countedForm = cnt <= 1 ? noun : getPlural(noun); + String countedForm = cnt == 1 ? noun : getPlural(noun); final String strCount; - if( cnt == 1 ) + if (cnt == 1) { strCount = startsWithVowel(noun) ? "an " : "a "; - else - strCount = String.valueOf(cnt) + " "; + } + else { + strCount = String.valueOf(cnt) + " "; + } return strCount + countedForm; } - + public static String nounWithNumeral(int cnt, String noun) { String countedForm = cnt <= 1 ? noun : getPlural(noun); return getNumeral(cnt) + " " + countedForm; - } + } public static String getPossesive(String name) { if ("You".equalsIgnoreCase(name)) return name + "r"; // to get "your" return name.endsWith("s") ? name + "'" : name + "'s"; } - + public static boolean startsWithVowel(String word) { 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) { char l = Character.toLowerCase(letter); - for(char c : vowels) - if ( c == l ) return true; + for (char c : vowels) { + if (c == l) return true; + } return false; - } - + 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" }; public final static String[] numbers20 = new String[] {"twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" }; - + public static String getNumeral(int n) { String prefix = n < 0 ? "minus " : ""; n = Math.abs(n); - if ( n >= 0 && n < 20 ) + if (n >= 0 && n < 20) return prefix + numbers0[n]; - if ( n < 100 ) { + if (n < 100) { int n1 = n % 10; String ones = n1 == 0 ? "" : numbers0[n1]; return prefix + numbers20[(n / 10) - 2] + " " + ones; diff --git a/forge-gui/src/main/java/forge/game/player/HumanPlay.java b/forge-gui/src/main/java/forge/game/player/HumanPlay.java index 8ea3b18de9d..492292578c6 100644 --- a/forge-gui/src/main/java/forge/game/player/HumanPlay.java +++ b/forge-gui/src/main/java/forge/game/player/HumanPlay.java @@ -54,12 +54,12 @@ import forge.game.spellability.SpellAbility; import forge.game.spellability.TargetRestrictions; import forge.game.zone.ZoneType; import forge.gui.GuiChoose; -import forge.gui.GuiDialog; import forge.gui.input.InputPayMana; import forge.gui.input.InputPayManaExecuteCommands; import forge.gui.input.InputPayManaSimple; import forge.gui.input.InputSelectCards; import forge.gui.input.InputSelectCardsFromList; +import forge.gui.input.InputYesOrNo; import forge.util.Lang; /** @@ -300,15 +300,18 @@ public class HumanPlay { if (!parts.isEmpty()) { 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)) { - 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 else if (costPart instanceof CostPartMana && parts.size() < 2) { 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) { final int amount = getAmountFromPart(part, source, sourceAbility); - if (!p.canPayLife(amount)) + if (!p.canPayLife(amount)) { 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; + } p.payLife(amount, null); } @@ -345,9 +350,13 @@ public class HumanPlay { sb.append("Do you want to "); sb.append(res.contains(p) ? "" : "let that player "); 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; } @@ -361,7 +370,7 @@ public class HumanPlay { } } 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() + " to your mana pool?" + orString)) { return false; @@ -374,7 +383,8 @@ public class HumanPlay { final int amount = getAmountFromPart(part, source, sourceAbility); final List list = p.getCardsIn(ZoneType.Library); 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; } List listmill = p.getCardsIn(ZoneType.Library, amount); @@ -382,7 +392,8 @@ public class HumanPlay { } else if (part instanceof CostFlipCoin) { 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; } final int n = FlipCoinEffect.getFilpMultiplier(p); @@ -396,7 +407,7 @@ public class HumanPlay { 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; } @@ -412,7 +423,7 @@ public class HumanPlay { 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; } @@ -422,12 +433,12 @@ public class HumanPlay { List list = p.getGame().getCardsIn(ZoneType.Battlefield); list = CardLists.getValidCards(list, part.getType().split(";"), p, source); 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; } while (amount > 0) { 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); Singletons.getControl().getInputQueue().setInputAndWait(inp); if (inp.hasCancelled()) { @@ -447,7 +458,7 @@ public class HumanPlay { 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; } @@ -463,8 +474,8 @@ public class HumanPlay { allCounters += value; } } - if (allCounters < amount) return false; - if (!GuiDialog.confirm(source, "Do you want to remove counters from " + part.getDescriptiveType() + " ?")) { + if (allCounters < amount) { return false; } + if (!InputYesOrNo.ask("Do you want to remove counters from " + part.getDescriptiveType() + " ?")) { return false; } @@ -506,7 +517,7 @@ public class HumanPlay { } else if (part instanceof CostExile) { 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; } @@ -524,7 +535,8 @@ public class HumanPlay { return false; } 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; } list = list.subList(0, nNeeded);