use of mage.choices.ChoiceImpl in project mage by magefree.
the class FastSearchUtil method showFastSearchForStringComboBox.
/**
* Show fast choice modal dialog with incremental searching for any string combobox components
*
* @param combo combobox control with default data model
* @param chooseMessage caption message for dialog
*/
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage, int windowWidth, int windowHeight) {
// fast search/choice dialog for string combobox
mage.choices.Choice choice = new ChoiceImpl(false);
// collect data from expansion combobox (String)
DefaultComboBoxModel comboModel = (DefaultComboBoxModel) combo.getModel();
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
String item;
for (int i = 0; i < comboModel.getSize(); i++) {
item = comboModel.getElementAt(i).toString();
choiceItems.put(item, item);
// need so sorting
choiceSorting.put(item, i);
}
choice.setKeyChoices(choiceItems);
choice.setSortData(choiceSorting);
choice.setMessage(chooseMessage);
// current selection value restore
String needSelectValue;
needSelectValue = comboModel.getSelectedItem().toString();
// ask for new value
PickChoiceDialog dlg = new PickChoiceDialog();
dlg.setWindowSize(windowWidth, windowHeight);
dlg.showDialog(choice, needSelectValue);
if (choice.isChosen()) {
item = choice.getChoiceKey();
// compatible select for object's models (use setSelectedIndex instead setSelectedObject)
for (int i = 0; i < comboModel.getSize(); i++) {
if (comboModel.getElementAt(i).toString().equals(item)) {
combo.setSelectedIndex(i);
}
}
}
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class AngelicSkirmisherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null && sourcePermanent != null) {
Choice abilityChoice = new ChoiceImpl(true);
Set<String> abilityChoices = new HashSet<>(3);
abilityChoice.setMessage("Choose ability for your creatures");
abilityChoices.add("First strike");
abilityChoices.add("Vigilance");
abilityChoices.add("Lifelink");
abilityChoice.setChoices(abilityChoices);
if (controller.choose(outcome, abilityChoice, game)) {
Ability ability = null;
switch(abilityChoice.getChoice()) {
case "First strike":
ability = FirstStrikeAbility.getInstance();
break;
case "Vigilance":
ability = VigilanceAbility.getInstance();
break;
case "Lifelink":
ability = LifelinkAbility.getInstance();
break;
default:
break;
}
if (ability != null) {
GainAbilityControlledEffect effect = new GainAbilityControlledEffect(ability, Duration.EndOfTurn, new FilterControlledCreaturePermanent());
game.addEffect(effect, source);
game.informPlayers(sourcePermanent.getName() + ": " + controller.getLogName() + " has chosen " + abilityChoice.getChoice().toLowerCase(Locale.ENGLISH));
return true;
}
}
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class AnimationModuleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (permanent != null) {
if (!permanent.getCounters(game).isEmpty()) {
if (permanent.getCounters(game).size() == 1) {
for (Counter counter : permanent.getCounters(game).values()) {
Counter newCounter = new Counter(counter.getName());
permanent.addCounters(newCounter, source.getControllerId(), source, game);
}
} else {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>(permanent.getCounters(game).size());
for (Counter counter : permanent.getCounters(game).values()) {
choices.add(counter.getName());
}
choice.setChoices(choices);
choice.setMessage("Choose a counter");
if (controller.choose(Outcome.Benefit, choice, game)) {
for (Counter counter : permanent.getCounters(game).values()) {
if (counter.getName().equals(choice.getChoice())) {
Counter newCounter = new Counter(counter.getName());
permanent.addCounters(newCounter, source.getControllerId(), source, game);
break;
}
}
} else {
return false;
}
}
}
} else {
Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (player != null) {
if (!player.getCounters().isEmpty()) {
if (player.getCounters().size() == 1) {
for (Counter counter : player.getCounters().values()) {
Counter newCounter = new Counter(counter.getName());
player.addCounters(newCounter, source.getControllerId(), source, game);
}
} else {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>(player.getCounters().size());
for (Counter counter : player.getCounters().values()) {
choices.add(counter.getName());
}
choice.setChoices(choices);
choice.setMessage("Choose a counter");
if (controller.choose(Outcome.Benefit, choice, game)) {
for (Counter counter : player.getCounters().values()) {
if (counter.getName().equals(choice.getChoice())) {
Counter newCounter = new Counter(counter.getName());
player.addCounters(newCounter, source.getControllerId(), source, game);
break;
}
}
} else {
return false;
}
}
}
}
}
return true;
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class CharmedPendantManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (Cost cost : source.getCosts()) {
if (cost instanceof MillCardsCost) {
Set<Card> cards = ((MillCardsCost) cost).getCardsMovedToGraveyard();
if (!cards.isEmpty()) {
Card card = cards.iterator().next();
if (card != null && card.getManaCost() != null) {
ManaCosts<ManaCost> newManaCosts = new ManaCostsImpl<>();
for (ManaCost manaCost : card.getManaCost()) {
if (manaCost instanceof ColorlessManaCost || manaCost instanceof GenericManaCost || manaCost instanceof VariableManaCost) {
continue;
}
if (manaCost instanceof MonoHybridManaCost) {
newManaCosts.add(new ColoredManaCost(((MonoHybridManaCost) manaCost).getManaColor()));
} else {
newManaCosts.add(manaCost.copy());
}
}
ManaOptions manaOptions = newManaCosts.getOptions();
if (manaOptions.size() == 1) {
mana = newManaCosts.getMana();
} else {
Choice manaChoice = new ChoiceImpl(true);
manaChoice.setMessage("Select which mana you like to produce");
for (Mana manaOption : manaOptions) {
manaChoice.getChoices().add(manaOption.toString());
}
if (manaChoice.getChoices().isEmpty()) {
// no mana choices available
return mana;
}
if (controller.choose(outcome, manaChoice, game)) {
for (Mana manaOption : manaOptions) {
if (manaChoice.getChoice().equals(manaOption.toString())) {
mana = manaOption;
break;
}
}
}
}
}
}
}
}
}
return mana;
}
Aggregations