Search in sources :

Example 26 with CardView

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

the class SelectionBox method blingDeck.

public void blingDeck() {
    if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
        return;
    }
    if (JOptionPane.showConfirmDialog(null, "Are you sure you want to bling your deck?  This process will add cards!", "WARNING", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION) {
        return;
    }
    // TODO: Why are these a HashMap? It can be a HashSet<String> instead, as the value is never used in the code.
    Map<String, Integer> pimpedSets = new HashMap<>();
    Map<CardView, Integer> pimpedCards = new HashMap<>();
    pimpedSets.put("PCMP", 1);
    pimpedSets.put("MPS", 1);
    pimpedSets.put("MP2", 1);
    pimpedSets.put("EXP", 1);
    pimpedSets.put("CP1", 1);
    pimpedSets.put("CP2", 1);
    pimpedSets.put("CP3", 1);
    // Judge Reward Gifts
    pimpedSets.put("JGP", 1);
    pimpedSets.put("G99", 1);
    pimpedSets.put("G00", 1);
    pimpedSets.put("G01", 1);
    pimpedSets.put("G02", 1);
    pimpedSets.put("G03", 1);
    pimpedSets.put("G04", 1);
    pimpedSets.put("G05", 1);
    pimpedSets.put("G06", 1);
    pimpedSets.put("G07", 1);
    pimpedSets.put("G08", 1);
    pimpedSets.put("G09", 1);
    pimpedSets.put("G10", 1);
    pimpedSets.put("G11", 1);
    pimpedSets.put("J12", 1);
    pimpedSets.put("J13", 1);
    pimpedSets.put("J14", 1);
    pimpedSets.put("J15", 1);
    pimpedSets.put("J16", 1);
    pimpedSets.put("J17", 1);
    pimpedSets.put("J18", 1);
    pimpedSets.put("J19", 1);
    pimpedSets.put("J20", 1);
    // Arena League
    pimpedSets.put("PARL", 1);
    pimpedSets.put("PAL99", 1);
    pimpedSets.put("PAL00", 1);
    pimpedSets.put("PAL01", 1);
    pimpedSets.put("PAL02", 1);
    pimpedSets.put("PAL03", 1);
    pimpedSets.put("PAL04", 1);
    pimpedSets.put("PAL05", 1);
    pimpedSets.put("PAL06", 1);
    pimpedSets.put("UGIN", 1);
    pimpedSets.put("PALP", 1);
    pimpedSets.put("PELP", 1);
    // Friday Night Magic
    pimpedSets.put("FNM", 1);
    pimpedSets.put("F01", 1);
    pimpedSets.put("F02", 1);
    pimpedSets.put("F03", 1);
    pimpedSets.put("F04", 1);
    pimpedSets.put("F05", 1);
    pimpedSets.put("F06", 1);
    pimpedSets.put("F07", 1);
    pimpedSets.put("F08", 1);
    pimpedSets.put("F09", 1);
    pimpedSets.put("F10", 1);
    pimpedSets.put("F11", 1);
    pimpedSets.put("F12", 1);
    pimpedSets.put("F13", 1);
    pimpedSets.put("F14", 1);
    pimpedSets.put("F15", 1);
    pimpedSets.put("F16", 1);
    pimpedSets.put("F17", 1);
    pimpedSets.put("F18", 1);
    // Magic Player Rewards 2001-2011, except for 2002 (P02), which only contains tokens
    pimpedSets.put("MPR", 1);
    pimpedSets.put("P03", 1);
    pimpedSets.put("P04", 1);
    pimpedSets.put("P05", 1);
    pimpedSets.put("P06", 1);
    pimpedSets.put("P07", 1);
    pimpedSets.put("P08", 1);
    pimpedSets.put("P09", 1);
    pimpedSets.put("P10", 1);
    pimpedSets.put("P11", 1);
    // Vintage Championship
    pimpedSets.put("OVNT", 1);
    // Junior Series Europe
    pimpedSets.put("PJSE", 1);
    // Two-Headed Giant Tournament
    pimpedSets.put("P2HG", 1);
    // Gateway 2006
    pimpedSets.put("PGTW", 1);
    // Junior APAC Series
    pimpedSets.put("PJAS", 1);
    pimpedSets.put("EXP", 1);
    pimpedSets.put("PGPX", 1);
    pimpedSets.put("PMEI", 1);
    pimpedSets.put("PLS", 1);
    String[] sets = pimpedSets.keySet().toArray(new String[pimpedSets.keySet().size()]);
    Boolean didModify = false;
    for (List<List<CardView>> gridRow : cardGrid) {
        for (List<CardView> stack : gridRow) {
            for (CardView card : stack) {
                if (card.getSuperTypes().contains(SuperType.BASIC)) {
                    continue;
                }
                if (!pimpedSets.containsKey(card.getExpansionSetCode())) {
                    final CardCriteria cardCriteria = new CardCriteria();
                    cardCriteria.setCodes(sets);
                    cardCriteria.name(card.getName());
                    java.util.List<CardInfo> cardPool = CardRepository.instance.findCards(cardCriteria);
                    if (!cardPool.isEmpty()) {
                        Card acard = cardPool.get(RandomUtil.nextInt(cardPool.size())).getMockCard();
                        if (acard.getName().equals(card.getName())) {
                            CardView pimpedCard = new CardView(acard);
                            addCardView(pimpedCard, false);
                            eventSource.fireEvent(pimpedCard, ClientEventType.DECK_ADD_SPECIFIC_CARD);
                            pimpedCards.put(pimpedCard, 1);
                            didModify = true;
                        }
                    }
                }
            }
        }
        if (didModify) {
            for (CardView c : pimpedCards.keySet()) {
                sortIntoGrid(c);
            }
            trimGrid();
            layoutGrid();
            repaintGrid();
            JOptionPane.showMessageDialog(null, "Added " + pimpedCards.size() + " cards.  You can select them and the originals by choosing 'Multiples'");
        }
    }
}
Also used : CardCriteria(mage.cards.repository.CardCriteria) CardView(mage.view.CardView) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardInfo(mage.cards.repository.CardInfo) MageCard(mage.cards.MageCard) Card(mage.cards.Card) java.util(java.util) List(java.util.List)

Example 27 with CardView

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

the class SelectionBox method chooseMatching.

private void chooseMatching() {
    Collection<CardView> toMatch = dragCardList();
    for (DragCardGridListener l : listeners) {
        for (CardView card : allCards) {
            for (CardView aMatch : toMatch) {
                if (card.getName().equals(aMatch.getName())) {
                    card.setSelected(true);
                    cardViews.get(card.getId()).update(card);
                }
            }
        }
    }
    repaint();
}
Also used : CardView(mage.view.CardView)

Example 28 with CardView

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

the class CardsList method drawCards.

@Override
public void drawCards(SortSetting sortSetting) {
    for (JLabel label : this.countLabels) {
        cardArea.remove(label);
    }
    this.countLabels.clear();
    int maxWidth = this.getParent().getWidth();
    int numColumns = maxWidth / cardDimension.width;
    int curColumn = 0;
    int curRow = 0;
    int maxRow = 0;
    int maxColumn = 0;
    CardViewComparator comparator = null;
    Map<UUID, MageCard> oldMageCards = mageCards;
    mageCards = new LinkedHashMap<>();
    // Find card view
    for (Map.Entry<UUID, CardView> view : cards.entrySet()) {
        UUID uuid = view.getKey();
        CardView cardView = view.getValue();
        if (oldMageCards.containsKey(uuid)) {
            mageCards.put(uuid, oldMageCards.get(uuid));
            oldMageCards.remove(uuid);
        } else {
            mageCards.put(uuid, addCard(cardView, bigCard, gameId));
        }
    }
    // Remove unused cards
    for (MageCard card : oldMageCards.values()) {
        cardArea.remove(card);
    }
    if (cards != null && !cards.isEmpty()) {
        Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
        List<CardView> sortedCards = new ArrayList<>(cards.values());
        switch(sortSetting.getSortBy()) {
            case NAME:
                comparator = new CardViewNameComparator();
                break;
            case RARITY:
                comparator = new CardViewRarityComparator();
                break;
            case CARD_TYPE:
                comparator = new CardViewCardTypeComparator();
                break;
            case COLOR:
                comparator = new CardViewColorComparator();
                break;
            case COLOR_IDENTITY:
                comparator = new CardViewColorIdentityComparator();
                break;
            case CASTING_COST:
                comparator = new CardViewCostComparator();
                break;
            case UNSORTED:
                comparator = new CardViewNoneComparator();
                break;
            case EDH_POWER_LEVEL:
                comparator = new CardViewEDHPowerLevelComparator();
                break;
            default:
                throw new IllegalArgumentException("Error, unknown sort settings in deck editor: " + sortSetting.getSortBy());
        }
        sortedCards.sort(new CardViewNameComparator());
        sortedCards.sort(comparator);
        CardView lastCard = null;
        JLabel lastCountLabel = null;
        for (CardView card : sortedCards) {
            if (sortSetting.isPilesToggle()) {
                if (lastCard == null) {
                    lastCard = card;
                    // new new count label
                    lastCountLabel = addNewCountLabel(curColumn);
                }
                // create new column on different card sorting
                if (comparator.compare(card, lastCard) != 0) {
                    curColumn++;
                    maxRow = Math.max(maxRow, curRow);
                    curRow = 0;
                    // add new count label
                    lastCountLabel = addNewCountLabel(curColumn);
                }
                // update last count label stats
                String description = comparator.getCategoryName(card);
                DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description);
                rectangle.setLocation(curColumn * cardDimension.width, curRow * rowHeight + DragCardGrid.COUNT_LABEL_HEIGHT);
                setCardBounds(mageCards.get(card.getId()), rectangle);
                curRow++;
                lastCard = card;
            } else {
                rectangle.setLocation(curColumn * cardDimension.width, curRow * rowHeight);
                setCardBounds(mageCards.get(card.getId()), rectangle);
                curColumn++;
                if (curColumn == numColumns) {
                    maxColumn = Math.max(maxColumn, curColumn);
                    curColumn = 0;
                    curRow++;
                }
            }
        }
    }
    maxRow = Math.max(maxRow, curRow);
    maxColumn = Math.max(maxColumn, curColumn);
    updateCounts();
    cardArea.setPreferredSize(new Dimension((maxColumn + 1) * cardDimension.width, cardDimension.height + maxRow * rowHeight));
    cardArea.revalidate();
    this.revalidate();
    this.repaint();
    this.setVisible(true);
}
Also used : CardView(mage.view.CardView) MageCard(mage.cards.MageCard)

Example 29 with CardView

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

the class CardsList method updateCounts.

private void updateCounts() {
    int landCount = 0;
    int creatureCount = 0;
    int sorceryCount = 0;
    int instantCount = 0;
    int enchantmentCount = 0;
    int artifactCount = 0;
    for (CardView card : cards.values()) {
        if (card.isLand()) {
            landCount++;
        }
        if (card.isCreature()) {
            creatureCount++;
        }
        if (card.isSorcery()) {
            sorceryCount++;
        }
        if (card.isInstant()) {
            instantCount++;
        }
        if (card.isEnchantment()) {
            enchantmentCount++;
        }
        if (card.isArtifact()) {
            artifactCount++;
        }
    }
    int count = cards != null ? cards.size() : 0;
    this.lblCount.setText(Integer.toString(count));
    this.lblCreatureCount.setText(Integer.toString(creatureCount));
    this.lblLandCount.setText(Integer.toString(landCount));
}
Also used : CardView(mage.view.CardView)

Example 30 with CardView

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

the class SelectionBox method sortIntoGrid.

/**
 * Add a card to the cardGrid, in the position that the current sort
 * dictates.
 * <p>
 * Warning, you must call trimGrid() after all cards inserted
 *
 * @param newCard Card to add to the cardGrid array.
 */
private void sortIntoGrid(CardView newCard) {
    // row 1 must exists
    if (cardGrid.isEmpty()) {
        cardGrid.add(0, new ArrayList<>());
        maxStackSize.add(0, 0);
    }
    // target row
    List<List<CardView>> targetRow;
    if (separateCreatures) {
        // row 2 must exists
        if (cardGrid.size() < 2) {
            cardGrid.add(1, new ArrayList<>());
            maxStackSize.add(1, 0);
            // Populate with stacks matching the first row
            for (int i = 0; i < cardGrid.get(0).size(); ++i) {
                cardGrid.get(1).add(new ArrayList<>());
            }
        }
        // workaround to fix wrong sorting on one card insert (if no creatures then trim will remove first row)
        boolean isFirstRowWithCreatures = true;
        for (int i = 0; i < cardGrid.get(0).size(); ++i) {
            if (cardGrid.get(0).get(i).stream().anyMatch(card -> !card.isCreature())) {
                isFirstRowWithCreatures = false;
                break;
            }
        }
        if (!isFirstRowWithCreatures) {
            // move all cards to row 2 (at first position)
            for (int i = 0; i < cardGrid.get(0).size(); ++i) {
                if (!cardGrid.get(0).get(i).isEmpty()) {
                    cardGrid.get(1).add(cardGrid.get(0).get(i));
                }
            }
            cardGrid.get(0).clear();
            while (cardGrid.get(0).size() < cardGrid.get(1).size()) {
                cardGrid.get(0).add(new ArrayList<>());
            }
        }
        if (newCard.isCreature()) {
            // creature cards goes to row 1
            targetRow = cardGrid.get(0);
        } else {
            // non-creature cards goes to row 2
            targetRow = cardGrid.get(1);
        }
    } else {
        // one row mode
        targetRow = cardGrid.get(0);
    }
    // Find the right column to insert into
    boolean didInsert = false;
    for (int currentColumn = 0; currentColumn < targetRow.size(); ++currentColumn) {
        // Find an item from this column
        CardView cardInColumn = null;
        for (List<List<CardView>> gridRow : cardGrid) {
            for (CardView card : gridRow.get(currentColumn)) {
                cardInColumn = card;
                break;
            }
        }
        // No card in this column?
        if (cardInColumn == null) {
            // Error, should not have an empty column
            logger.error("Empty column! " + currentColumn);
        } else {
            CardViewComparator cardComparator = cardSort.getComparator();
            int res = cardComparator.compare(newCard, cardInColumn);
            if (res <= 0) {
                // Insert into this col, but if less, then we need to create a new col here first
                if (res < 0) {
                    for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
                        cardGrid.get(rowIndex).add(currentColumn, new ArrayList<>());
                    }
                }
                targetRow.get(currentColumn).add(newCard);
                didInsert = true;
                break;
            } else {
            // Nothing to do, go to next iteration
            }
        }
    }
    // If nothing else, insert in a new column after everything else
    if (!didInsert) {
        for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
            cardGrid.get(rowIndex).add(new ArrayList<>());
        }
        targetRow.get(targetRow.size() - 1).add(newCard);
    }
// empty row trim (trimGrid) must be called from outside after all cards inserted
}
Also used : CardView(mage.view.CardView) List(java.util.List)

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