use of mage.choices.ChoiceImpl in project mage by magefree.
the class ChooseLandTypeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getPermanentEntering(source.getSourceId());
if (mageObject == null) {
mageObject = game.getObject(source.getSourceId());
}
if (controller != null && mageObject != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose land type");
typeChoice.setChoices(SubType.getLandTypes().stream().map(SubType::toString).collect(Collectors.toSet()));
if (controller.choose(outcome, typeChoice, game)) {
if (!game.isSimulation()) {
game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + typeChoice.getChoice());
}
game.getState().setValue(mageObject.getId() + "_type", SubType.byDescription(typeChoice.getChoice()));
if (mageObject instanceof Permanent) {
((Permanent) mageObject).addInfo("chosen type", CardUtil.addToolTipMarkTags("Chosen type: " + typeChoice.getChoice()), game);
}
return true;
}
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class KayaTheInexorableEmblemEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Choice zoneChoice = new ChoiceImpl(true);
zoneChoice.setMessage("Cast a legendary spell from hand, graveyard, or exile");
zoneChoice.setChoices(choices);
zoneChoice.clearChoice();
if (player.choose(Outcome.PlayForFree, zoneChoice, game)) {
TargetCard target = null;
switch(zoneChoice.getChoice()) {
case "Hand":
target = new TargetCardInHand(0, 1, filter);
target.setTargetName("legendary spell from your hand");
break;
case "Graveyard":
target = new TargetCardInYourGraveyard(0, 1, filter, true);
target.setTargetName("legendary spell from your graveyard");
break;
case "Exile":
target = new TargetCardInExile(0, 1, filter, null, true);
target.setNotTarget(true);
target.setTargetName("legendary spell you own in exile");
break;
}
if (target != null && player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
return cardWasCast;
}
}
}
}
return false;
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class ConnectDialog method doFastFlagSearch.
// GEN-LAST:event_btnFindOtherActionPerformed
private void doFastFlagSearch() {
Choice choice = new ChoiceImpl(false);
// collect data from country combobox String[name][code]
Map<String, String> choiceItems = new LinkedHashMap<>();
DefaultComboBoxModel flagModel = (DefaultComboBoxModel) cbFlag.getModel();
String[] flagItem;
for (int i = 0; i < flagModel.getSize(); i++) {
flagItem = (String[]) flagModel.getElementAt(i);
choiceItems.put(flagItem[1], flagItem[0]);
}
choice.setKeyChoices(choiceItems);
choice.setMessage("Select your country");
// current selection value restore
String needSelectValue = null;
flagItem = (String[]) flagModel.getSelectedItem();
if (flagItem != null) {
needSelectValue = flagItem[1];
}
// ask for new value
PickChoiceDialog dlg = new PickChoiceDialog();
dlg.setWindowSize(300, 500);
dlg.showDialog(choice, needSelectValue);
if (choice.isChosen()) {
flagItem = new String[2];
flagItem[0] = choice.getChoiceValue();
flagItem[1] = choice.getChoiceKey();
flagModel.setSelectedItem(flagItem);
}
}
use of mage.choices.ChoiceImpl in project mage by magefree.
the class ClockspinningAddOrRemoveCounterEffect method selectCounterType.
private Counter selectCounterType(Game game, Ability source, Permanent permanent) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && !permanent.getCounters(game).isEmpty()) {
String counterName = null;
if (permanent.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>(2);
for (Counter counter : permanent.getCounters(game).values()) {
if (permanent.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter type to add to " + permanent.getName());
if (controller.choose(Outcome.Neutral, choice, game)) {
counterName = choice.getChoice();
} else {
return null;
}
} else {
for (Counter counter : permanent.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
return new Counter(counterName);
}
return null;
}
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 CheckBoxList components
*
* @param combo CheckBoxList control with default data model
* @param chooseMessage caption message for dialog
*/
public static void showFastSearchForStringComboBox(CheckBoxList combo, String chooseMessage) {
// fast search/choice dialog for string combobox
mage.choices.Choice choice = new ChoiceImpl(false);
// collect data from expansion combobox (String)
DefaultListModel comboModel = (DefaultListModel) 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.size(); 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 = null;
if (comboModel.size() > 0) {
needSelectValue = comboModel.firstElement().toString();
}
// ask for new value
PickCheckBoxDialog dlg = new PickCheckBoxDialog(combo);
dlg.setWindowSize(300, 500);
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);
}
}
}
}
Aggregations