mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Change several confirms to use new utility function
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
*/
|
||||
package forge.match.input;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
@@ -45,20 +49,37 @@ public class InputConfirm extends InputSyncronizedBase {
|
||||
private CardView card;
|
||||
|
||||
// simple interface to hide ugliness deciding how to confirm
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final CardView card, String message) {
|
||||
protected static ImmutableList<String> defaultOptions = ImmutableList.of("Yes", "No");
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final CardView card, final String message) {
|
||||
return InputConfirm.confirm(controller, card, message, true, defaultOptions);
|
||||
}
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final CardView card, final String message, final boolean defaultIsYes, final List<String> options) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
return controller.getGui().confirm(card,message);
|
||||
return controller.getGui().confirm(card, message, defaultIsYes, options);
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(controller, message, card);
|
||||
InputConfirm inp;
|
||||
if ( options.size() == 2 ) {
|
||||
inp = new InputConfirm(controller, message, options.get(0), options.get(1), defaultIsYes, card);
|
||||
} else {
|
||||
inp = new InputConfirm(controller, message, defaultOptions.get(0), defaultOptions.get(1), defaultIsYes, card);
|
||||
}
|
||||
inp.showAndWait();
|
||||
return inp.getResult();
|
||||
}
|
||||
}
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final SpellAbility sa, String message) {
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final SpellAbility sa, final String message) {
|
||||
return InputConfirm.confirm(controller, sa, message, true, defaultOptions);
|
||||
}
|
||||
public static boolean confirm(final PlayerControllerHuman controller, final SpellAbility sa, final String message, final boolean defaultIsYes, final List<String> options) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
return controller.getGui().confirm((sa==null)?null:CardView.get(sa.getHostCard()),message);
|
||||
return controller.getGui().confirm((sa==null)?null:CardView.get(sa.getHostCard()), message, defaultIsYes, options);
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(controller, message, sa);
|
||||
InputConfirm inp;
|
||||
if ( options.size() == 2 ) {
|
||||
inp = new InputConfirm(controller, message, options.get(0), options.get(1), defaultIsYes, sa);
|
||||
} else {
|
||||
inp = new InputConfirm(controller, message, defaultOptions.get(0), defaultOptions.get(1), defaultIsYes, sa);
|
||||
}
|
||||
inp.showAndWait();
|
||||
return inp.getResult();
|
||||
}
|
||||
|
||||
@@ -948,18 +948,9 @@ public class HumanCostDecision extends CostDecisionMakerBase {
|
||||
if (cost.payCostFromSource()) {
|
||||
final int maxCounters = source.getCounters(cost.counter);
|
||||
if (amount.equals("All")) {
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
final CardView view = CardView.get(ability.getHostCard());
|
||||
if (!controller.getGui().confirm(view, "Remove all counters?")) {
|
||||
if (!InputConfirm.confirm(controller, ability, "Remove all counters?")) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(controller, "Remove all counters?", ability);
|
||||
inp.showAndWait();
|
||||
if (!inp.getResult()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
cntRemoved = maxCounters;
|
||||
}
|
||||
else if (c == null && "XChoice".equals(sVarAmount)) {
|
||||
|
||||
@@ -649,13 +649,7 @@ public class PlayerControllerHuman
|
||||
getGui().setCard(c.getView());
|
||||
|
||||
boolean result = false;
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
result = getGui().confirm(view, String.format("Put %s on the top or bottom of your library?", view), ImmutableList.of("Top", "Bottom"));
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(this, String.format("Put %s on the top or bottom of your library?", view), "Top", "Bottom", true, c.getView());
|
||||
inp.showAndWait();
|
||||
result = inp.getResult();
|
||||
}
|
||||
result = InputConfirm.confirm(this, view, String.format("Put %s on the top or bottom of your library?", view), true, ImmutableList.of("Top", "Bottom"));
|
||||
|
||||
endTempShowCards();
|
||||
return result;
|
||||
@@ -1024,13 +1018,8 @@ public class PlayerControllerHuman
|
||||
case LeftOrRight: labels = ImmutableList.of("Left", "Right"); break;
|
||||
default: labels = ImmutableList.copyOf(kindOfChoice.toString().split("Or"));
|
||||
}
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
return getGui().confirm(CardView.get(sa.getHostCard()), question, defaultVal == null || defaultVal.booleanValue(), labels);
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(this, question, labels.get(0), labels.get(1), defaultVal == null || defaultVal.booleanValue(), sa);
|
||||
inp.showAndWait();
|
||||
return inp.getResult();
|
||||
}
|
||||
|
||||
return InputConfirm.confirm(this, sa, question, defaultVal == null || defaultVal.booleanValue(), labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1163,14 +1152,7 @@ public class PlayerControllerHuman
|
||||
}
|
||||
|
||||
boolean confirmed = false;
|
||||
if (GuiBase.getInterface().isLibgdxPort()) {
|
||||
confirmed = getGui().confirm(CardView.get(c), message, colorNames) ;
|
||||
} else {
|
||||
final InputConfirm inp = new InputConfirm(this, message, colorNames.get(0), colorNames.get(1), CardView.get(c));
|
||||
inp.showAndWait();
|
||||
confirmed = inp.getResult();
|
||||
}
|
||||
|
||||
confirmed = InputConfirm.confirm(this, CardView.get(c), message, true, colorNames) ;
|
||||
final int idxChosen = confirmed ? 0 : 1;
|
||||
return MagicColor.fromName(colorNames.get(idxChosen));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user