* UI: added cancel button for all target definition abilities;

This commit is contained in:
Oleg Agafonov 2019-03-10 23:31:11 +04:00
parent 904660e624
commit dab481ee17
3 changed files with 24 additions and 8 deletions

View file

@ -325,11 +325,16 @@ public abstract class AbilityImpl implements Ability {
}
if (!getTargets().isEmpty()) {
Outcome outcome = getEffects().isEmpty() ? Outcome.Detriment : getEffects().get(0).getOutcome();
if (getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game) == false) {
if ((variableManaCost != null || announceString != null)) {
// can be cancel by user
if (getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game, true) == false) {
/*
if ((variableManaCost != null) || (announceString != null && !announceString.isEmpty())) {
// ?debug message?
game.informPlayer(controller, (sourceObject != null ? sourceObject.getIdName() : "") + ": no valid targets");
}
return false; // when activation of ability is canceled during target selection
*/
// when activation of ability is canceled during target selection
return false;
}
}
} // end modes

View file

@ -174,7 +174,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override
public Abilities<Ability> getAbilities() {
return new AbilitiesImpl<>(ability);
return new AbilitiesImpl<>(ability);
}
@Override
@ -587,7 +587,7 @@ public class StackAbility extends StackObjImpl implements Ability {
Outcome outcome = newAbility.getEffects().isEmpty() ? Outcome.Detriment : newAbility.getEffects().get(0).getOutcome();
if (controller.chooseUse(outcome, "Choose new targets?", source, game)) {
newAbility.getTargets().clearChosen();
newAbility.getTargets().chooseTargets(outcome, newControllerId, newAbility, false, game);
newAbility.getTargets().chooseTargets(outcome, newControllerId, newAbility, false, game, false);
}
}
game.fireEvent(new GameEvent(GameEvent.EventType.COPIED_STACKOBJECT, newStackAbility.getId(), this.getId(), newControllerId));

View file

@ -64,7 +64,7 @@ public class Targets extends ArrayList<Target> {
return true;
}
public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, boolean noMana, Game game) {
public boolean chooseTargets(Outcome outcome, UUID playerId, Ability source, boolean noMana, Game game, boolean canCancel) {
if (this.size() > 0) {
if (!canChoose(source.getSourceId(), playerId, game)) {
return false;
@ -73,12 +73,23 @@ public class Targets extends ArrayList<Target> {
while (!isChosen()) {
Target target = this.getUnchosen().get(0);
UUID targetController = playerId;
if (target.getTargetController() != null) { // some targets can have controller different than ability controller
// some targets can have controller different than ability controller
if (target.getTargetController() != null) {
targetController = target.getTargetController();
}
if (noMana) { // if cast without mana (e.g. by suspend you may not be able to cancel the casting if you are able to cast it
// if cast without mana (e.g. by suspend you may not be able to cancel the casting if you are able to cast it
if (noMana) {
target.setRequired(true);
}
// can be cancel by user
if (canCancel) {
target.setRequired(false);
}
// make response checks
if (!target.chooseTarget(outcome, targetController, source, game)) {
return false;
}