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