mirror of
https://github.com/Relintai/mtg-forge-ios.git
synced 2024-11-14 04:17:19 +01:00
- Partner commander UI support for mobile Forge (both Constructed and Planar Conquest).
git-svn-id: http://svn.slightlymagic.net/forge/trunk@35748 269b9781-a132-4a9b-9d4e-f004f1b56b58
This commit is contained in:
parent
be0df21707
commit
06e032fccf
@ -17,14 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package forge.card;
|
package forge.card;
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import forge.util.TextUtil;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import forge.card.mana.IParserManaCost;
|
import forge.card.mana.IParserManaCost;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.card.mana.ManaCostShard;
|
import forge.card.mana.ManaCostShard;
|
||||||
|
import forge.util.TextUtil;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of methods containing full
|
* A collection of methods containing full
|
||||||
@ -199,6 +199,10 @@ public final class CardRules implements ICardCharacteristics {
|
|||||||
return mainPart.getOracleText().contains("can be your commander");
|
return mainPart.getOracleText().contains("can be your commander");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canBePartnerCommander() {
|
||||||
|
return canBeCommander() && Iterables.contains(mainPart.getKeywords(), "Partner");
|
||||||
|
}
|
||||||
|
|
||||||
public String getMeldWith() {
|
public String getMeldWith() {
|
||||||
return meldWith;
|
return meldWith;
|
||||||
}
|
}
|
||||||
|
@ -17,21 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package forge.deck;
|
package forge.deck;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import forge.util.TextUtil;
|
|
||||||
import org.apache.commons.lang3.Range;
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.card.CardRulesPredicates;
|
import forge.card.CardRulesPredicates;
|
||||||
@ -43,6 +31,12 @@ import forge.deck.generation.IDeckGenPool;
|
|||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
|
import forge.util.TextUtil;
|
||||||
|
import org.apache.commons.lang3.Range;
|
||||||
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GameType is an enum to determine the type of current game. :)
|
* GameType is an enum to determine the type of current game. :)
|
||||||
@ -428,4 +422,12 @@ public enum DeckFormat {
|
|||||||
}
|
}
|
||||||
return Predicates.compose(CardRulesPredicates.hasColorIdentity(cmdCI), PaperCard.FN_GET_RULES);
|
return Predicates.compose(CardRulesPredicates.hasColorIdentity(cmdCI), PaperCard.FN_GET_RULES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Predicate<PaperCard> isLegalCardForCommanderOrLegalPartnerPredicate(List<PaperCard> commanders) {
|
||||||
|
byte cmdCI = 0;
|
||||||
|
for (final PaperCard p : commanders) {
|
||||||
|
cmdCI |= p.getRules().getColorIdentity().getColor();
|
||||||
|
}
|
||||||
|
return Predicates.compose(Predicates.or(CardRulesPredicates.hasColorIdentity(cmdCI), CardRulesPredicates.hasKeyword("Partner")), PaperCard.FN_GET_RULES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,9 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import forge.Forge;
|
import forge.Forge;
|
||||||
import forge.Graphics;
|
|
||||||
import forge.Forge.KeyInputAdapter;
|
import forge.Forge.KeyInputAdapter;
|
||||||
|
import forge.Graphics;
|
||||||
import forge.assets.*;
|
import forge.assets.*;
|
||||||
import forge.card.CardDb;
|
import forge.card.CardDb;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
@ -43,16 +42,10 @@ import forge.util.ItemPool;
|
|||||||
import forge.util.Lang;
|
import forge.util.Lang;
|
||||||
import forge.util.Utils;
|
import forge.util.Utils;
|
||||||
import forge.util.storage.IStorage;
|
import forge.util.storage.IStorage;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
||||||
public static FSkinImage MAIN_DECK_ICON = FSkinImage.DECKLIST;
|
public static FSkinImage MAIN_DECK_ICON = FSkinImage.DECKLIST;
|
||||||
@ -214,7 +207,8 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
case PlanarConquest:
|
case PlanarConquest:
|
||||||
return new DeckEditorPage[] {
|
return new DeckEditorPage[] {
|
||||||
new CatalogPage(ItemManagerConfig.CONQUEST_COLLECTION, "Collection", FSkinImage.SPELLBOOK),
|
new CatalogPage(ItemManagerConfig.CONQUEST_COLLECTION, "Collection", FSkinImage.SPELLBOOK),
|
||||||
new DeckSectionPage(DeckSection.Main, ItemManagerConfig.CONQUEST_DECK_EDITOR, "Deck", FSkinImage.DECKLIST)
|
new DeckSectionPage(DeckSection.Main, ItemManagerConfig.CONQUEST_DECK_EDITOR, "Deck", FSkinImage.DECKLIST),
|
||||||
|
new DeckSectionPage(DeckSection.Commander, ItemManagerConfig.COMMANDER_SECTION)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -924,7 +918,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//if a commander has been set, only show cards that match its color identity
|
//if a commander has been set, only show cards that match its color identity
|
||||||
additionalFilter = DeckFormat.Commander.isLegalCardForCommanderPredicate(commanders);
|
additionalFilter = DeckFormat.Commander.isLegalCardForCommanderOrLegalPartnerPredicate(commanders);
|
||||||
cardManager.setCaption("Cards");
|
cardManager.setCaption("Cards");
|
||||||
}
|
}
|
||||||
//fall through to below
|
//fall through to below
|
||||||
@ -941,6 +935,9 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCardActivated(PaperCard card) {
|
protected void onCardActivated(PaperCard card) {
|
||||||
|
if (canOnlyBePartnerCommander(card)) {
|
||||||
|
return; // don't auto-change commander unexpectedly
|
||||||
|
}
|
||||||
if (needsCommander()) {
|
if (needsCommander()) {
|
||||||
setCommander(card); //handle special case of setting commander
|
setCommander(card); //handle special case of setting commander
|
||||||
return;
|
return;
|
||||||
@ -955,6 +952,24 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
return parentScreen.getCommanderPage() != null && parentScreen.getDeck().getCommanders().isEmpty();
|
return parentScreen.getCommanderPage() != null && parentScreen.getDeck().getCommanders().isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canHavePartnerCommander() {
|
||||||
|
return parentScreen.getCommanderPage() != null && parentScreen.getDeck().getCommanders().size() == 1
|
||||||
|
&& parentScreen.getDeck().getCommanders().get(0).getRules().canBePartnerCommander();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canOnlyBePartnerCommander(final PaperCard card) {
|
||||||
|
if (parentScreen.getCommanderPage() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte cmdCI = 0;
|
||||||
|
for (final PaperCard p : parentScreen.getDeck().getCommanders()) {
|
||||||
|
cmdCI |= p.getRules().getColorIdentity().getColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
return !card.getRules().getColorIdentity().hasNoColorsExcept(cmdCI);
|
||||||
|
}
|
||||||
|
|
||||||
private void setCommander(PaperCard card) {
|
private void setCommander(PaperCard card) {
|
||||||
if (!cardManager.isInfinite()) {
|
if (!cardManager.isInfinite()) {
|
||||||
removeCard(card);
|
removeCard(card);
|
||||||
@ -965,9 +980,17 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
refresh(); //refresh so cards shown that match commander's color identity
|
refresh(); //refresh so cards shown that match commander's color identity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setPartnerCommander(PaperCard card) {
|
||||||
|
if (!cardManager.isInfinite()) {
|
||||||
|
removeCard(card);
|
||||||
|
}
|
||||||
|
parentScreen.getCommanderPage().addCard(card, 1);
|
||||||
|
refresh(); //refresh so cards shown that match commander's color identity
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildMenu(final FDropDownMenu menu, final PaperCard card) {
|
protected void buildMenu(final FDropDownMenu menu, final PaperCard card) {
|
||||||
if (!needsCommander()) {
|
if (!needsCommander() && !canOnlyBePartnerCommander(card)) {
|
||||||
addItem(menu, "Add", "to " + parentScreen.getMainDeckPage().cardManager.getCaption(), parentScreen.getMainDeckPage().getIcon(), true, true, new Callback<Integer>() {
|
addItem(menu, "Add", "to " + parentScreen.getMainDeckPage().cardManager.getCaption(), parentScreen.getMainDeckPage().getIcon(), true, true, new Callback<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Integer result) {
|
public void run(Integer result) {
|
||||||
@ -994,7 +1017,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (parentScreen.getCommanderPage() != null) {
|
if (parentScreen.getCommanderPage() != null) {
|
||||||
if (DeckFormat.Commander.isLegalCommander(card.getRules()) && !parentScreen.getCommanderPage().cardManager.getPool().contains(card)) {
|
if (parentScreen.editorType != EditorType.PlanarConquest && DeckFormat.Commander.isLegalCommander(card.getRules()) && !parentScreen.getCommanderPage().cardManager.getPool().contains(card)) {
|
||||||
addItem(menu, "Set", "as Commander", parentScreen.getCommanderPage().getIcon(), true, true, new Callback<Integer>() {
|
addItem(menu, "Set", "as Commander", parentScreen.getCommanderPage().getIcon(), true, true, new Callback<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void run(Integer result) {
|
public void run(Integer result) {
|
||||||
@ -1003,6 +1026,15 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (canHavePartnerCommander() && card.getRules().canBePartnerCommander()) {
|
||||||
|
addItem(menu, "Set", "as Partner Commander", parentScreen.getCommanderPage().getIcon(), true, true, new Callback<Integer>() {
|
||||||
|
@Override
|
||||||
|
public void run(Integer result) {
|
||||||
|
if (result == null || result <= 0) { return; }
|
||||||
|
setPartnerCommander(card);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentScreen.getEditorType() == EditorType.Constructed) {
|
if (parentScreen.getEditorType() == EditorType.Constructed) {
|
||||||
@ -1257,16 +1289,20 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Commander:
|
case Commander:
|
||||||
addItem(menu, "Remove", null, FSkinImage.MINUS, false, false, new Callback<Integer>() {
|
if (parentScreen.editorType != EditorType.PlanarConquest || isPartnerCommander(card)) {
|
||||||
@Override
|
addItem(menu, "Remove", null, FSkinImage.MINUS, false, false, new Callback<Integer>() {
|
||||||
public void run(Integer result) {
|
@Override
|
||||||
if (result == null || result <= 0) { return; }
|
public void run(Integer result) {
|
||||||
|
if (result == null || result <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
removeCard(card, result);
|
removeCard(card, result);
|
||||||
parentScreen.getCatalogPage().refresh(); //refresh so commander options shown again
|
parentScreen.getCatalogPage().refresh(); //refresh so commander options shown again
|
||||||
parentScreen.setSelectedPage(parentScreen.getCatalogPage());
|
parentScreen.setSelectedPage(parentScreen.getCatalogPage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Avatar:
|
case Avatar:
|
||||||
addItem(menu, "Remove", null, FSkinImage.MINUS, false, false, new Callback<Integer>() {
|
addItem(menu, "Remove", null, FSkinImage.MINUS, false, false, new Callback<Integer>() {
|
||||||
@ -1316,7 +1352,7 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentScreen.getCommanderPage() != null && deckSection != DeckSection.Commander) {
|
if (parentScreen.editorType != EditorType.PlanarConquest && parentScreen.getCommanderPage() != null && deckSection != DeckSection.Commander) {
|
||||||
if (card.getRules().getType().isLegendary() && card.getRules().getType().isCreature() && !parentScreen.getCommanderPage().cardManager.getPool().contains(card)) {
|
if (card.getRules().getType().isLegendary() && card.getRules().getType().isCreature() && !parentScreen.getCommanderPage().cardManager.getPool().contains(card)) {
|
||||||
addItem(menu, "Set", "as Commander", parentScreen.getCommanderPage().getIcon(), false, false, new Callback<Integer>() {
|
addItem(menu, "Set", "as Commander", parentScreen.getCommanderPage().getIcon(), false, false, new Callback<Integer>() {
|
||||||
@Override
|
@Override
|
||||||
@ -1334,6 +1370,16 @@ public class FDeckEditor extends TabPageScreen<FDeckEditor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPartnerCommander(final PaperCard card) {
|
||||||
|
if (parentScreen.getCommanderPage() == null || parentScreen.getDeck().getCommanders().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PaperCard firstCmdr = parentScreen.getDeck().getCommanders().get(0);
|
||||||
|
return !card.getName().equals(firstCmdr.getName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class DraftPackPage extends CatalogPage {
|
private static class DraftPackPage extends CatalogPage {
|
||||||
|
@ -1,36 +1,20 @@
|
|||||||
package forge.planarconquest;
|
package forge.planarconquest;
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import forge.assets.FSkinProp;
|
import forge.assets.FSkinProp;
|
||||||
import forge.assets.IHasSkinProp;
|
import forge.assets.IHasSkinProp;
|
||||||
import forge.card.CardRarity;
|
import forge.card.*;
|
||||||
import forge.card.CardRules;
|
|
||||||
import forge.card.CardType;
|
|
||||||
import forge.card.CardType.CoreType;
|
import forge.card.CardType.CoreType;
|
||||||
import forge.card.mana.ManaCostShard;
|
import forge.card.mana.ManaCostShard;
|
||||||
import forge.card.ColorSet;
|
|
||||||
import forge.card.MagicColor;
|
|
||||||
import forge.deck.CardPool;
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckFormat;
|
import forge.deck.DeckFormat;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
import forge.deck.generation.DeckGenerator2Color;
|
import forge.deck.generation.*;
|
||||||
import forge.deck.generation.DeckGenerator3Color;
|
|
||||||
import forge.deck.generation.DeckGenerator5Color;
|
|
||||||
import forge.deck.generation.DeckGeneratorBase;
|
|
||||||
import forge.deck.generation.DeckGeneratorMonoColor;
|
|
||||||
import forge.deck.generation.IDeckGenPool;
|
|
||||||
import forge.item.PaperCard;
|
import forge.item.PaperCard;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
import forge.planarconquest.ConquestPreferences.CQPref;
|
import forge.planarconquest.ConquestPreferences.CQPref;
|
||||||
@ -40,6 +24,12 @@ import forge.util.FileUtil;
|
|||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
import forge.util.gui.SOptionPane;
|
import forge.util.gui.SOptionPane;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class ConquestUtil {
|
public class ConquestUtil {
|
||||||
private ConquestUtil() {}
|
private ConquestUtil() {}
|
||||||
|
|
||||||
@ -153,7 +143,7 @@ public class ConquestUtil {
|
|||||||
|
|
||||||
//remove any cards that aren't allowed in deck due to color identity
|
//remove any cards that aren't allowed in deck due to color identity
|
||||||
if (colorIdentity != MagicColor.ALL_COLORS) {
|
if (colorIdentity != MagicColor.ALL_COLORS) {
|
||||||
Predicate<PaperCard> pred = DeckFormat.Commander.isLegalCardForCommanderPredicate(deck.getCommanders());
|
Predicate<PaperCard> pred = DeckFormat.Commander.isLegalCardForCommanderOrLegalPartnerPredicate(deck.getCommanders());
|
||||||
|
|
||||||
availableCards.retainAll(Lists.newArrayList(Iterables.filter(availableCards, pred)));
|
availableCards.retainAll(Lists.newArrayList(Iterables.filter(availableCards, pred)));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user