mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
Merge pull request #4283 from JayDi85/ui-choose-new
Added new choose dialog
This commit is contained in:
commit
7954031f41
46 changed files with 1111 additions and 371 deletions
|
|
@ -221,6 +221,19 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
|
|||
return new Mana(0, 0, 0, 0, 0, 0, 0, notNegative(num, "Colorless"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Mana} object with the passed in {@code num} of Any
|
||||
* mana. {@code num} can not be a negative value. Negative values will be
|
||||
* logged and set to 0.
|
||||
*
|
||||
* @param num value of Any mana to create.
|
||||
* @return a {@link Mana} object with the passed in {@code num} of Any
|
||||
* mana.
|
||||
*/
|
||||
public static Mana AnyMana(int num) {
|
||||
return new Mana(0, 0, 0, 0, 0, 0, notNegative(num, "Any"), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds mana from the passed in {@link Mana} object to this object.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -69,11 +69,13 @@ public class AddManaOfAnyColorEffect extends BasicManaEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
ChoiceColor choice = new ChoiceColor(true);
|
||||
String mes = String.format("Select color of %d mana to add it to your mana pool", this.amount);
|
||||
ChoiceColor choice = new ChoiceColor(true, mes, game.getObject(source.getSourceId()));
|
||||
|
||||
if (controller.choose(outcome, choice, game)) {
|
||||
if (choice.getColor() == null) {
|
||||
return false; // it happens, don't know how
|
||||
// on user's reconnect choice dialog close and return null even with required settings
|
||||
return false;
|
||||
}
|
||||
Mana createdMana = choice.getMana(amount);
|
||||
if (createdMana != null) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import mage.MageObject;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.choices.Choice;
|
||||
import mage.choices.ChoiceCreatureType;
|
||||
import mage.choices.ChoiceImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
|
|
@ -63,9 +64,7 @@ public class ChooseCreatureTypeEffect extends OneShotEffect {
|
|||
mageObject = game.getObject(source.getSourceId());
|
||||
}
|
||||
if (controller != null && mageObject != null) {
|
||||
Choice typeChoice = new ChoiceImpl(true);
|
||||
typeChoice.setMessage("Choose creature type");
|
||||
typeChoice.setChoices(SubType.getCreatureTypes(false).stream().map(SubType::toString).collect(Collectors.toCollection(LinkedHashSet::new)));
|
||||
Choice typeChoice = new ChoiceCreatureType(mageObject);
|
||||
while (!controller.choose(outcome, typeChoice, game)) {
|
||||
if (!controller.canRespond()) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -225,6 +225,9 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
|
|||
if (types.getColorless() > 0) {
|
||||
netManas.add(Mana.ColorlessMana(1));
|
||||
}
|
||||
if (types.getAny() > 0) {
|
||||
netManas.add(Mana.AnyMana(1));
|
||||
}
|
||||
return netManas;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@
|
|||
package mage.abilities.mana;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mage.Mana;
|
||||
import mage.game.Game;
|
||||
|
||||
|
|
@ -326,4 +329,19 @@ public class ManaOptions extends ArrayList<Mana> {
|
|||
payCombinations.add(newMana);
|
||||
payCombinationsStrings.add(newMana.toString());
|
||||
}
|
||||
|
||||
|
||||
public void removeDuplicated(){
|
||||
Set<String> list = new HashSet<>();
|
||||
|
||||
for(int i = this.size() - 1; i >= 0; i--){
|
||||
String s = this.get(i).toString();
|
||||
if (list.contains(s)){
|
||||
// remove duplicated
|
||||
this.remove(i);
|
||||
}else{
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,19 +37,34 @@ import java.util.Set;
|
|||
*/
|
||||
public interface Choice {
|
||||
|
||||
boolean isChosen();
|
||||
boolean isRequired();
|
||||
void clearChoice();
|
||||
String getMessage();
|
||||
void setMessage(String message);
|
||||
void setChoice(String choice);
|
||||
void setChoiceByKey(String choiceKey);
|
||||
Set<String> getChoices();
|
||||
Map<String,String> getKeyChoices();
|
||||
void setChoices(Set<String> choices);
|
||||
void setKeyChoices(Map<String, String> choices);
|
||||
String getChoice();
|
||||
String getChoiceKey();
|
||||
boolean isKeyChoice();
|
||||
|
||||
String getSubMessage();
|
||||
void setSubMessage(String subMessage);
|
||||
|
||||
void clearChoice();
|
||||
boolean isChosen();
|
||||
boolean isRequired();
|
||||
|
||||
Choice copy();
|
||||
|
||||
// string choice
|
||||
void setChoices(Set<String> choices);
|
||||
Set<String> getChoices();
|
||||
void setChoice(String choice);
|
||||
String getChoice();
|
||||
|
||||
// key-value choice
|
||||
boolean isKeyChoice();
|
||||
void setKeyChoices(Map<String, String> choices);
|
||||
Map<String,String> getKeyChoices();
|
||||
void setChoiceByKey(String choiceKey);
|
||||
String getChoiceKey();
|
||||
|
||||
// search
|
||||
boolean isSearchEnabled();
|
||||
void setSearchEnabled(boolean isEnabled);
|
||||
void setSearchText(String searchText);
|
||||
String getSearchText();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,17 +27,22 @@
|
|||
*/
|
||||
package mage.choices;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.ObjectColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class ChoiceColor extends ChoiceImpl {
|
||||
|
||||
public static final ArrayList<String> colorChoices = new ArrayList<>();
|
||||
//public static final Set<String> colorChoices = new HashSet<>(); // JayDi85: uncomment 1 of 2 to broke unit tests find wrong tests (?)
|
||||
public static final ArrayList<String> colorChoices = new ArrayList<>();
|
||||
|
||||
static {
|
||||
colorChoices.add("Green");
|
||||
|
|
@ -52,9 +57,25 @@ public class ChoiceColor extends ChoiceImpl {
|
|||
}
|
||||
|
||||
public ChoiceColor(boolean required) {
|
||||
this(required, "Choose color");
|
||||
}
|
||||
|
||||
public ChoiceColor(boolean required, String chooseMessage){
|
||||
this(required, chooseMessage, "");
|
||||
}
|
||||
|
||||
public ChoiceColor(boolean required, String chooseMessage, MageObject source){
|
||||
this(required, chooseMessage, source.getIdName());
|
||||
}
|
||||
|
||||
public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessage){
|
||||
super(required);
|
||||
|
||||
this.choices.addAll(colorChoices);
|
||||
this.message = "Choose color";
|
||||
//this.setChoices(colorChoices); // JayDi85: uncomment 2 of 2 to broke unit tests find wrong tests (?)
|
||||
|
||||
this.setMessage(chooseMessage);
|
||||
this.setSubMessage(chooseSubMessage);
|
||||
}
|
||||
|
||||
public ChoiceColor(final ChoiceColor choice) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mage.choices;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.constants.SubType;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
|
|
@ -7,10 +8,28 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class ChoiceCreatureType extends ChoiceImpl {
|
||||
|
||||
private static String DEFAULT_MESSAGE = "Choose a creature type";
|
||||
|
||||
public ChoiceCreatureType() {
|
||||
super(true);
|
||||
this(true, DEFAULT_MESSAGE, null);
|
||||
}
|
||||
|
||||
public ChoiceCreatureType(MageObject source) {
|
||||
this(true, DEFAULT_MESSAGE, source);
|
||||
}
|
||||
|
||||
public ChoiceCreatureType(String chooseMessage, MageObject source) {
|
||||
this(true, chooseMessage, source);
|
||||
}
|
||||
|
||||
public ChoiceCreatureType(boolean required, String chooseMessage, MageObject source){
|
||||
super(required);
|
||||
this.setChoices(SubType.getCreatureTypes(false).stream().map(SubType::toString).collect(Collectors.toCollection(LinkedHashSet::new)));
|
||||
this.message = "Choose a creature type:";
|
||||
this.setMessage(chooseMessage);
|
||||
if(source != null) {
|
||||
this.setSubMessage(source.getIdName());
|
||||
}
|
||||
this.setSearchEnabled(true);
|
||||
}
|
||||
|
||||
public ChoiceCreatureType(final ChoiceCreatureType choice) {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import java.util.Set;
|
|||
*/
|
||||
public class ChoiceImpl implements Choice, Serializable {
|
||||
|
||||
// TODO: add sorting to items
|
||||
protected boolean chosen;
|
||||
protected final boolean required;
|
||||
protected String choice;
|
||||
|
|
@ -47,6 +48,9 @@ public class ChoiceImpl implements Choice, Serializable {
|
|||
protected Set<String> choices = new LinkedHashSet<>();
|
||||
protected Map<String, String> keyChoices = new LinkedHashMap<>();
|
||||
protected String message;
|
||||
protected String subMessage;
|
||||
protected boolean searchEnabled = true; // enable for all windows by default
|
||||
protected String searchText;
|
||||
|
||||
public ChoiceImpl() {
|
||||
this(false);
|
||||
|
|
@ -61,6 +65,7 @@ public class ChoiceImpl implements Choice, Serializable {
|
|||
this.chosen = choice.chosen;
|
||||
this.required = choice.required;
|
||||
this.message = choice.message;
|
||||
this.message = choice.subMessage;
|
||||
this.choices.addAll(choice.choices);
|
||||
this.choiceKey = choice.choiceKey;
|
||||
this.keyChoices = choice.keyChoices; // list should never change for the same object so copy by reference
|
||||
|
|
@ -88,6 +93,12 @@ public class ChoiceImpl implements Choice, Serializable {
|
|||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubMessage(){ return subMessage; }
|
||||
|
||||
@Override
|
||||
public void setSubMessage(String subMessage){ this.subMessage = subMessage; }
|
||||
|
||||
@Override
|
||||
public Set<String> getChoices() {
|
||||
return choices;
|
||||
|
|
@ -150,4 +161,24 @@ public class ChoiceImpl implements Choice, Serializable {
|
|||
return !keyChoices.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public boolean isSearchEnabled(){
|
||||
return this.searchEnabled;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void setSearchEnabled(boolean isEnabled){
|
||||
this.searchEnabled = isEnabled;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void setSearchText(String searchText){
|
||||
this.searchText = searchText;
|
||||
};
|
||||
|
||||
@Override
|
||||
public String getSearchText(){
|
||||
return this.searchText;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -2439,6 +2439,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
for (Abilities<ActivatedManaAbilityImpl> manaAbilities : sourceWithCosts) {
|
||||
available.addManaWithCost(manaAbilities, game);
|
||||
}
|
||||
|
||||
// remove duplicated variants (see ManaOptionsTest for info - when thats rises)
|
||||
available.removeDuplicated();
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue