Search in sources :

Example 31 with MageCard

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

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

the class CardPanelTypeComparator method clearCards.

private void clearCards() {
    // remove possible mouse listeners, preventing gc
    for (MageCard mageCard : cards.values()) {
        mageCard.cleanUp();
    }
    this.cards.clear();
    removeAllCardImg();
}
Also used : MageCard(mage.cards.MageCard)

Example 33 with MageCard

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

the class ChoiceDialog method displayCards.

private void displayCards(CardsView cards, UUID gameId, BigCard bigCard) {
    if (cards.isEmpty()) {
        return;
    }
    java.util.List<Component> toRemove = new ArrayList<>();
    for (int i = getComponentCount() - 1; i > 0; i--) {
        Component o = getComponent(i);
        if (o instanceof MageCard) {
            toRemove.add(o);
        }
    }
    for (Component aToRemove : toRemove) {
        remove(aToRemove);
    }
    java.util.List<CardView> cardList = new ArrayList<>(cards.values());
    int width = SettingsManager.instance.getCardSize().width;
    int height = SettingsManager.instance.getCardSize().height;
    int dx = 0;
    int dy = 30;
    int startIndex = (page - 1) * (in_a_row * rows);
    int countPerPage = (in_a_row * rows);
    int j = 0;
    for (int i = startIndex; i < cards.size() && i < startIndex + countPerPage; i++) {
        if (i > startIndex && i % in_a_row == 0) {
            // next row
            j++;
            dx = 0;
        }
        CardView card = cardList.get(i);
        MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
        cardImg.setCardContainerRef(this);
        cardImg.update(card);
        cardImg.setCardBounds(dx, dy + j * (height + 30), width, height);
        this.add(cardImg);
        dx += (width + 20);
    }
    repaint();
}
Also used : ArrayList(java.util.ArrayList) CardView(mage.view.CardView) MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 34 with MageCard

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

the class CardLayoutStrategyImpl method groupAttachments.

private void groupAttachments(BattlefieldPanel battlefieldPanel, JLayeredPane mainPanel, Map<UUID, MageCard> cards, PermanentView permanentWithAttachmentsView) {
    MageCard cardWithAttachments = cards.get(permanentWithAttachmentsView.getId());
    if (cardWithAttachments == null) {
        return;
    }
    // calculate how many vertical columns are needed and number of attachements
    AttachmentLayoutInfos attachmentLayoutInfos = calculateNeededNumberOfVerticalColumns(0, battlefieldPanel, cards, permanentWithAttachmentsView);
    // group by columns
    layoutAttachements(cardWithAttachments.getCardLocation().getCardX(), attachmentLayoutInfos.getColumns(), attachmentLayoutInfos.getAttachments(), permanentWithAttachmentsView, cards, battlefieldPanel, mainPanel, cardWithAttachments.getCardLocation().getCardBounds());
    mainPanel.setComponentZOrder(cardWithAttachments, 0);
}
Also used : MageCard(mage.cards.MageCard)

Example 35 with MageCard

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

the class CardLayoutStrategyImpl method layoutAttachements.

private void layoutAttachements(int startingCardX, int maxColumnLevels, int ZOrder, PermanentView permanentWithAttachmentsView, Map<UUID, MageCard> cards, BattlefieldPanel battlefieldPanel, JLayeredPane mainPanel, Rectangle lastAttachmentRect) {
    // put attachments to the next level (take lastAttachmentRect and apply offsets)
    MageCard cardWithAttachments = cards.get(permanentWithAttachmentsView.getId());
    if (cardWithAttachments == null) {
        return;
    }
    // from right to left [2][1][0]
    int col = getVerticalCul(permanentWithAttachmentsView, battlefieldPanel);
    int currentAttachmentCol = col + 1;
    cardWithAttachments.getLinks().clear();
    int verticalIndex = permanentWithAttachmentsView.getAttachments().size();
    for (UUID attachmentId : permanentWithAttachmentsView.getAttachments()) {
        // put child attachments of the attachment
        PermanentView attachedPermanentView = battlefieldPanel.getBattlefield().get(attachmentId);
        if (attachedPermanentView != null && attachedPermanentView.getAttachments() != null && !attachedPermanentView.getAttachments().isEmpty()) {
            layoutAttachements(startingCardX, maxColumnLevels, ZOrder, attachedPermanentView, cards, battlefieldPanel, mainPanel, lastAttachmentRect);
        }
        // put attachment
        MageCard attachedCard = cards.get(attachmentId);
        if (attachedCard != null) {
            // x position
            Point point = new Point();
            point.setLocation(startingCardX + (maxColumnLevels - currentAttachmentCol) * Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), lastAttachmentRect.getY());
            lastAttachmentRect.setLocation(point);
            // set position first to the same as of the permanent it is attached to
            attachedCard.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
            // y position
            cardWithAttachments.getLinks().add(attachedCard);
            int dyOffset = Math.max(cardWithAttachments.getCardLocation().getCardHeight() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_SINGLE_Y);
            if (verticalIndex == 1) {
                lastAttachmentRect.translate(Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), dyOffset);
            } else {
                lastAttachmentRect.translate(0, dyOffset);
            }
            cardWithAttachments.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
            battlefieldPanel.moveToFront(attachedCard);
            battlefieldPanel.moveToFront(cardWithAttachments);
            mainPanel.setComponentZOrder(attachedCard, ZOrder--);
            verticalIndex--;
        }
    }
}
Also used : PermanentView(mage.view.PermanentView) MageCard(mage.cards.MageCard) Point(java.awt.Point) UUID(java.util.UUID) Point(java.awt.Point)

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