Search in sources :

Example 26 with MageCard

use of mage.cards.MageCard 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 27 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class Cards method changeGUISize.

public void changeGUISize() {
    setGUISize();
    for (MageCard mageCard : cards.values()) {
        mageCard.setCardBounds(0, 0, getCardDimension().width, getCardDimension().height);
        mageCard.updateArtImage();
        mageCard.doLayout();
    }
    layoutCards();
    sizeCards(getCardDimension());
}
Also used : MageCard(mage.cards.MageCard)

Example 28 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class Cards method addCard.

private void addCard(CardView card, BigCard bigCard, UUID gameId) {
    MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
    mageCard.setCardContainerRef(cardArea);
    mageCard.update(card);
    if (zone != null) {
        mageCard.setZone(zone);
    }
    cards.put(card.getId(), mageCard);
    cardArea.add(mageCard);
    definePosition(mageCard);
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 29 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class CardArea method setPopupMenu.

public void setPopupMenu(JPopupMenu popupMenu) {
    for (Component component : cardArea.getComponents()) {
        if (component instanceof MageCard) {
            MageCard mageCard = (MageCard) component;
            mageCard.setPopupMenu(popupMenu);
        }
    }
}
Also used : MageCard(mage.cards.MageCard)

Example 30 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class CardArea method addCard.

private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
    if (card instanceof AbilityView) {
        CardView tmp = ((AbilityView) card).getSourceCard();
        tmp.overrideRules(card.getRules());
        tmp.setIsAbility(true);
        tmp.overrideTargets(card.getTargets());
        // cross-reference, required for ability picker
        tmp.setAbility(card);
        card = tmp;
    }
    CardIconRenderSettings currentIconsRender;
    if (this.customRenderMode >= 0) {
        // debug
        currentIconsRender = new CardIconRenderSettings().withDebugMode(true).withCustomPosition(customCardIconPosition).withCustomOrder(customCardIconOrder).withCustomColor(customCardIconColor).withCustomMaxVisibleCount(customCardIconsMaxVisibleCount).withCustomIconSizePercent(30);
    } else {
        // default
        currentIconsRender = new CardIconRenderSettings();
    }
    MageCard cardPanel = Plugins.instance.getMageCard(card, bigCard, currentIconsRender, cardDimension, gameId, true, true, customRenderMode != -1 ? customRenderMode : PreferencesDialog.getRenderMode(), customNeedFullPermanentRender);
    cardPanel.setCardContainerRef(this);
    cardPanel.update(card);
    cardPanel.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
    cardArea.add(cardPanel);
    cardArea.moveToFront(cardPanel);
    // new card have same settings as current view
    cardPanel.setCardCaptionTopOffset(yCardCaptionOffsetPercent);
    cardPanel.showCardTitle();
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Aggregations

MageCard (mage.cards.MageCard)50 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)12 CardView (mage.view.CardView)10 UUID (java.util.UUID)6 java.util (java.util)5 PermanentView (mage.view.PermanentView)5 List (java.util.List)4 MagePermanent (mage.cards.MagePermanent)4 PlayAreaPanel (mage.client.game.PlayAreaPanel)4 java.awt (java.awt)3 BufferedImage (java.awt.image.BufferedImage)3 javax.swing (javax.swing)3 PreferencesDialog (mage.client.dialog.PreferencesDialog)3 Plugins (mage.client.plugins.impl.Plugins)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 MagePane (mage.client.MagePane)2 MageComponents (mage.client.components.MageComponents)2 GamePane (mage.client.game.GamePane)2