Search in sources :

Example 31 with CardView

use of mage.view.CardView in project mage by magefree.

the class SelectionBox method reselectBy.

public void reselectBy() {
    // Deselect everything
    deselectAll();
    boolean useText = false;
    String searchStr = "";
    if (searchByTextField.getText().length() >= 3) {
        useText = true;
        searchStr = searchByTextField.getText().toLowerCase(Locale.ENGLISH);
    }
    for (CardType cardType : selectByTypeButtons.keySet()) {
        AbstractButton button = selectByTypeButtons.get(cardType);
        if (button != null) {
            if (button.isSelected()) {
                // Special case - "Multiples"  (CONSPIRACY type)
                if (cardType == CardType.CONSPIRACY) {
                    Map<String, CardView> cardNames = new HashMap<>();
                    for (List<List<CardView>> gridRow : cardGrid) {
                        for (List<CardView> stack : gridRow) {
                            for (CardView card : stack) {
                                if (cardNames.get(card.getName()) == null) {
                                    cardNames.put(card.getName(), card);
                                } else {
                                    card.setSelected(true);
                                    cardViews.get(card.getId()).update(card);
                                    CardView origCard = cardNames.get(card.getName());
                                    origCard.setSelected(true);
                                    cardViews.get(origCard.getId()).update(origCard);
                                }
                            }
                        }
                    }
                    continue;
                }
                for (List<List<CardView>> gridRow : cardGrid) {
                    for (List<CardView> stack : gridRow) {
                        for (CardView card : stack) {
                            boolean s = card.isSelected() || card.getCardTypes().contains(cardType);
                            card.setSelected(s);
                            cardViews.get(card.getId()).update(card);
                        }
                    }
                }
            }
        }
    }
    if (useText) {
        for (List<List<CardView>> gridRow : cardGrid) {
            for (List<CardView> stack : gridRow) {
                for (CardView card : stack) {
                    boolean s = card.isSelected();
                    // Name
                    if (!s) {
                        s = card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Sub & Super Types
                    if (!s) {
                        for (SuperType str : card.getSuperTypes()) {
                            s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                        for (SubType str : card.getSubTypes()) {
                            s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    // Rarity
                    if (!s) {
                        Rarity r = card.getRarity();
                        if (r != null) {
                            s |= r.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    // Type line
                    if (!s) {
                        String t = "";
                        for (CardType type : card.getCardTypes()) {
                            t += ' ' + type.toString();
                        }
                        s |= t.toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Casting cost
                    if (!s) {
                        s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr);
                    }
                    // Rules
                    if (!s) {
                        for (String str : card.getRules()) {
                            s |= str.toLowerCase(Locale.ENGLISH).contains(searchStr);
                        }
                    }
                    card.setSelected(s);
                    cardViews.get(card.getId()).update(card);
                }
            }
        }
    }
    // And finally rerender
    layoutGrid();
    repaintGrid();
}
Also used : SubType(mage.constants.SubType) CardView(mage.view.CardView) SuperType(mage.constants.SuperType) Rarity(mage.constants.Rarity) CardType(mage.constants.CardType) List(java.util.List)

Example 32 with CardView

use of mage.view.CardView in project mage by magefree.

the class VirtualCardInfo method init.

public void init(String cardName, BigCard bigCard, UUID gameId) {
    CardInfo cardInfo = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
    if (cardInfo == null) {
        clear();
        return;
    }
    this.init(new CardView(cardInfo.getCard()), bigCard, gameId);
}
Also used : CardView(mage.view.CardView) CardInfo(mage.cards.repository.CardInfo)

Example 33 with CardView

use of mage.view.CardView in project mage by magefree.

the class CardPanelTypeComparator method loadCards.

@Override
public void loadCards(CardsView showCards, SortSetting sortSetting, BigCard bigCard, UUID gameId, boolean merge) {
    boolean drawImage = showCards.size() <= MAX_IMAGES;
    this.bigCard = bigCard;
    this.gameId = gameId;
    if (merge) {
        for (CardView card : showCards.values()) {
            if (!cards.containsKey(card.getId())) {
                addCard(card, bigCard, gameId, drawImage);
            }
        }
        for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext(); ) {
            Entry<UUID, MageCard> entry = i.next();
            if (!showCards.containsKey(entry.getKey())) {
                removeCardImg(entry.getKey());
                i.remove();
            }
        }
    } else {
        this.clearCards();
        for (CardView card : showCards.values()) {
            addCard(card, bigCard, gameId, drawImage);
        }
    }
    drawCards(sortSetting);
    this.setVisible(true);
}
Also used : Entry(java.util.Map.Entry) CardView(mage.view.CardView) MageCard(mage.cards.MageCard)

Example 34 with CardView

use of mage.view.CardView in project mage by magefree.

the class TableModel method loadCards.

@Override
public void loadCards(CardsView showCards, SortSetting sortSetting, BigCard bigCard, UUID gameId, boolean merge) {
    if (this.sortSetting == null) {
        this.sortSetting = sortSetting;
    }
    this.bigCard = bigCard;
    this.gameId = gameId;
    int landCount = 0;
    int creatureCount = 0;
    int instantCount = 0;
    int sorceryCount = 0;
    int enchantmentCount = 0;
    int artifactCount = 0;
    if (!merge) {
        this.clearCards();
        for (CardView card : showCards.values()) {
            addCard(card, bigCard, gameId);
        }
    } else {
        for (CardView card : showCards.values()) {
            if (!cards.containsKey(card.getId())) {
                addCard(card, bigCard, gameId);
            }
            if (updateCountsCallback != null) {
                if (card.isLand()) {
                    landCount++;
                }
                if (card.isCreature()) {
                    creatureCount++;
                }
                if (card.isInstant()) {
                    instantCount++;
                }
                if (card.isSorcery()) {
                    sorceryCount++;
                }
                if (card.isEnchantment()) {
                    enchantmentCount++;
                }
                if (card.isArtifact()) {
                    artifactCount++;
                }
            }
        }
        // no easy logic for merge :)
        for (Iterator<Entry<UUID, CardView>> i = cards.entrySet().iterator(); i.hasNext(); ) {
            Entry<UUID, CardView> entry = i.next();
            if (!showCards.containsKey(entry.getKey())) {
                i.remove();
                if (displayNoCopies) {
                    String key = entry.getValue().getName() + entry.getValue().getExpansionSetCode() + entry.getValue().getCardNumber();
                    if (cardsNoCopies.containsKey(key)) {
                        Integer count = cardsNoCopies.get(key);
                        count--;
                        if (count > 0) {
                            cardsNoCopies.put(key, count);
                        } else {
                            cardsNoCopies.remove(key);
                        }
                        for (int j = 0; j < view.size(); j++) {
                            CardView cv = view.get(j);
                            if (cv.getId().equals(entry.getValue().getId())) {
                                if (count > 0) {
                                    // replace by another card with the same name+setCode
                                    String key1 = cv.getName() + cv.getExpansionSetCode() + cv.getCardNumber();
                                    for (CardView cardView : cards.values()) {
                                        String key2 = cardView.getName() + cardView.getExpansionSetCode() + cardView.getCardNumber();
                                        if (key1.equals(key2)) {
                                            view.set(j, cardView);
                                            break;
                                        }
                                    }
                                } else {
                                    view.remove(j);
                                }
                                break;
                            }
                        }
                    }
                } else {
                    view.removeIf(cardView -> cardView.getId().equals(entry.getKey()));
                }
            }
        }
        if (updateCountsCallback != null) {
            updateCountsCallback.update(cards.size(), creatureCount, landCount, sorceryCount, instantCount, enchantmentCount, artifactCount);
        }
    }
    sort(this.sortSetting.getSortIndex(), this.sortSetting.isAscending());
    drawCards(sortSetting);
}
Also used : Entry(java.util.Map.Entry) CardView(mage.view.CardView)

Example 35 with CardView

use of mage.view.CardView in project mage by magefree.

the class TableModel method getColumn.

private Object getColumn(Object obj, int column) {
    CardView c = (CardView) obj;
    switch(column) {
        case 0:
            if (displayNoCopies) {
                String key = c.getName() + c.getExpansionSetCode() + c.getCardNumber();
                Integer count = cardsNoCopies.get(key);
                return count != null ? count : "";
            }
            return "";
        case 1:
            // show full name in deck editor table, e.g. adventure with spell name
            return c.getDisplayFullName();
        case 2:
            // new svg images version
            return ManaSymbols.getClearManaCost(c.getManaCostStr());
        /*
                // old html images version
                String manaCost = "";
                for (String m : c.getManaCost()) {
                    manaCost += m;
                }
                String castingCost = UI.getDisplayManaCost(manaCost);
                castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.TABLE);
                return "<html>" + castingCost + "</html>";
                return castingCost;
                */
        case 3:
            return c.getColorText();
        case 4:
            return c.getTypeText();
        case 5:
            return c.isCreature() ? c.getPower() + '/' + c.getToughness() : "-";
        case 6:
            return c.getRarity() == null ? "" : c.getRarity().toString();
        case 7:
            return c.getExpansionSetCode();
        case 8:
            return c.getCardNumber();
        case 9:
            return RateCard.rateCard(c.getOriginalCard(), null);
        case 10:
            return ManaSymbols.getClearManaCost(c.getColorIdentityStr());
        default:
            return "error";
    }
}
Also used : CardView(mage.view.CardView)

Aggregations

CardView (mage.view.CardView)41 List (java.util.List)15 MageCard (mage.cards.MageCard)10 CardInfo (mage.cards.repository.CardInfo)9 Card (mage.cards.Card)6 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 java.util (java.util)4 BigCard (mage.client.cards.BigCard)4 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)3 GameView (mage.view.GameView)3 PlayerView (mage.view.PlayerView)3 SimpleCardView (mage.view.SimpleCardView)3 Test (org.junit.Test)3 java.awt (java.awt)2 java.awt.event (java.awt.event)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 javax.swing (javax.swing)2