From 6cc2472ed6321e9457d04aee04c73d269b8c91d2 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 24 Sep 2019 08:40:58 +0400 Subject: [PATCH] * UI: improved choose target amount dialog (selected targets can be removed/de-selected); --- .../src/mage/player/human/HumanPlayer.java | 15 +++++++++-- .../main/java/mage/target/TargetAmount.java | 25 ++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 48581982990..d2c615b80b9 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -721,8 +721,19 @@ public class HumanPlayer extends PlayerImpl { if (response.getUUID() != null) { if (target.canTarget(response.getUUID(), source, game)) { UUID targetId = response.getUUID(); - int amountSelected = getAmount(1, target.getAmountRemaining(), "Select amount", game); - target.addTarget(targetId, amountSelected, source, game); + MageObject targetObject = game.getObject(targetId); + + boolean removeMode = target.getTargets().contains(targetId) + && chooseUse(outcome, "What do you want to do with " + (targetObject != null ? targetObject.getLogName() : "target") + "?", "", + "Remove from selected", "Add extra amount", source, game); + + if (removeMode) { + target.remove(targetId); + } else { + int amountSelected = getAmount(1, target.getAmountRemaining(), "Select amount", game); + target.addTarget(targetId, amountSelected, source, game); + } + return true; } } else if (!target.isRequired(source)) { diff --git a/Mage/src/main/java/mage/target/TargetAmount.java b/Mage/src/main/java/mage/target/TargetAmount.java index df3f372fd1e..84ced7d035a 100644 --- a/Mage/src/main/java/mage/target/TargetAmount.java +++ b/Mage/src/main/java/mage/target/TargetAmount.java @@ -1,5 +1,3 @@ - - package mage.target; import mage.abilities.Ability; @@ -7,11 +5,14 @@ import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.common.StaticValue; import mage.constants.Outcome; import mage.game.Game; -import java.util.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; /** - * * @author BetaSteward_at_googlemail.com */ public abstract class TargetAmount extends TargetImpl { @@ -63,8 +64,8 @@ public abstract class TargetAmount extends TargetImpl { public void setAmountDefinition(DynamicValue amount) { this.amount = amount; - } - + } + public void setAmount(Ability source, Game game) { remainingAmount = amount.calculate(game, source, null); amountWasSet = true; @@ -82,6 +83,13 @@ public abstract class TargetAmount extends TargetImpl { } } + @Override + public void remove(UUID id) { + int amount = getTargetAmount(id); + super.remove(id); + this.remainingAmount += amount; + } + @Override public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) { if (!amountWasSet) { @@ -111,7 +119,7 @@ public abstract class TargetAmount extends TargetImpl { if (!amountWasSet) { setAmount(source, game); } - for (UUID targetId: targets) { + for (UUID targetId : targets) { for (int n = 1; n <= target.remainingAmount; n++) { TargetAmount t = target.copy(); t.addTarget(targetId, n, source, game, true); @@ -120,8 +128,7 @@ public abstract class TargetAmount extends TargetImpl { Set newTargets = targets.stream().filter(newTarget -> !newTarget.equals(targetId)).collect(Collectors.toSet()); addTargets(t, newTargets, options, source, game); } - } - else { + } else { options.add(t); } }