Search in sources :

Example 11 with MageCard

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

the class CardPanelTypeComparator method addCard.

private void addCard(CardView card, BigCard bigCard, UUID gameId, boolean drawImage) {
    MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), cardDimension, gameId, drawImage, true, PreferencesDialog.getRenderMode(), true);
    cardImg.setCardContainerRef(this);
    cardImg.update(card);
    // card position calculated on parent call by drawCards
    // cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
    cards.put(card.getId(), cardImg);
    // count label must be on layer 0 for background drawing
    this.add(cardImg, (Integer) 10);
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 12 with MageCard

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

the class BattlefieldPanel method update.

public void update(Map<UUID, PermanentView> battlefield) {
    gameUpdateTimer.stop();
    boolean changed = false;
    List<PermanentView> permanentsToAdd = new ArrayList<>();
    for (PermanentView permanent : battlefield.values()) {
        if (!permanent.isPhasedIn()) {
            continue;
        }
        MageCard oldFound = permanents.get(permanent.getId());
        MagePermanent oldMagePermanent = oldFound == null ? null : (MagePermanent) oldFound.getMainPanel();
        if (oldMagePermanent == null) {
            permanentsToAdd.add(permanent);
            changed = true;
        } else {
            if (!changed) {
                changed = oldMagePermanent.getOriginalPermanent().isCreature() != permanent.isCreature();
                // Check if there was a change in the permanets that are the permanent attached to
                if (!changed) {
                    int attachments = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size();
                    int attachmentsBefore = oldMagePermanent.getLinks().size();
                    if (attachments != attachmentsBefore) {
                        changed = true;
                    } else if (attachments > 0) {
                        Set<UUID> attachmentIds = new HashSet<>(permanent.getAttachments());
                        for (MageCard mageCard : oldMagePermanent.getLinks()) {
                            MagePermanent magePermanent = (MagePermanent) mageCard.getMainPanel();
                            if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) {
                                // that means that the amount of attachments is the same
                                // but they are different:
                                // we've just found an attachment on previous view
                                // that doesn't exist anymore on current view
                                changed = true;
                                break;
                            }
                        }
                    }
                }
                // Check if permanents it now attached to another or no permanent
                if (!changed) {
                    UUID attachedToIdBefore = oldMagePermanent.getOriginalPermanent().getAttachedTo();
                    UUID attachedToId = permanent.getAttachedTo();
                    if (attachedToIdBefore == null && attachedToId != null || attachedToId == null && attachedToIdBefore != null || (attachedToIdBefore != null && !attachedToIdBefore.equals(attachedToId))) {
                        changed = true;
                    }
                }
                // Check for changes in the counters of the permanent
                if (!changed) {
                    List<CounterView> counters1 = oldMagePermanent.getOriginalPermanent().getCounters();
                    List<CounterView> counters2 = permanent.getCounters();
                    if (counters1 == null && counters2 != null || counters1 != null && counters2 == null) {
                        changed = true;
                    } else if (counters1 != null && counters2 != null && counters1.size() != counters2.size()) {
                        changed = true;
                    }
                }
            }
            oldMagePermanent.update(permanent);
        }
    }
    addedArtifact = addedCreature = addedPermanent = false;
    int count = permanentsToAdd.size();
    for (PermanentView permanent : permanentsToAdd) {
        addPermanent(permanent, count);
    }
    if (addedArtifact) {
        AudioManager.playAddArtifact();
    } else if (addedCreature) {
        AudioManager.playSummon();
    } else if (addedPermanent) {
        AudioManager.playAddPermanent();
    }
    removedCreature = false;
    for (Iterator<Entry<UUID, MageCard>> iterator = permanents.entrySet().iterator(); iterator.hasNext(); ) {
        Entry<UUID, MageCard> entry = iterator.next();
        if (!battlefield.containsKey(entry.getKey()) || !battlefield.get(entry.getKey()).isPhasedIn()) {
            removePermanent(entry.getKey(), 1);
            iterator.remove();
            changed = true;
        }
    }
    if (removedCreature) {
        AudioManager.playDiedCreature();
    }
    if (changed) {
        this.battlefield = battlefield;
        sortLayout();
    }
}
Also used : MageCard(mage.cards.MageCard) Entry(java.util.Map.Entry) CounterView(mage.view.CounterView) PermanentView(mage.view.PermanentView) MagePermanent(mage.cards.MagePermanent)

Example 13 with MageCard

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

the class BattlefieldPanel method removePermanent.

private void removePermanent(UUID permanentId, final int count) {
    for (Component comp : this.jPanel.getComponents()) {
        if (comp instanceof MageCard) {
            MageCard mageCard = (MageCard) comp;
            if (mageCard.getMainPanel() instanceof MagePermanent) {
                MagePermanent magePermanent = (MagePermanent) mageCard.getMainPanel();
                if (magePermanent.getOriginal().getId().equals(permanentId)) {
                    Thread t = new Thread(() -> {
                        Plugins.instance.onRemoveCard(mageCard, count);
                        mageCard.setVisible(false);
                        this.jPanel.remove(mageCard);
                    });
                    t.start();
                }
                if (magePermanent.getOriginal().isCreature()) {
                    removedCreature = true;
                }
            }
        }
    }
}
Also used : MageCard(mage.cards.MageCard) MagePermanent(mage.cards.MagePermanent)

Example 14 with MageCard

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

the class MageBook method addCard.

private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle, boolean asCard) {
    if (cardDimension == null) {
        cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
    }
    final MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, true, PreferencesDialog.getRenderMode(), true);
    cardImg.setCardContainerRef(jLayeredPane);
    cardImg.update(card);
    cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.getFrameWidth(), cardDimensions.getFrameHeight());
    jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
    // card caption must be below real card caption to see full name even with mana icons
    cardImg.setCardCaptionTopOffset(CARD_CAPTION_OFFSET_Y);
    if (asCard) {
        // card number label
        JLabel cardNumber = new JLabel();
        // image panel have empty space in bottom (bug?), need to move label up
        int dy = -5;
        cardNumber.setBounds(rectangle.x, rectangle.y + cardImg.getCardLocation().getCardHeight() + dy, cardDimensions.getFrameWidth(), 20);
        cardNumber.setHorizontalAlignment(SwingConstants.CENTER);
        cardNumber.setFont(jLayeredPane.getFont().deriveFont(jLayeredPane.getFont().getStyle() | Font.BOLD));
        cardNumber.setText(card.getCardNumber());
        jLayeredPane.add(cardNumber);
        // draft rating label
        JLabel draftRating = new JLabel();
        // under card number
        dy = -5 * 2 + cardNumber.getHeight();
        draftRating.setBounds(rectangle.x, rectangle.y + cardImg.getCardLocation().getCardHeight() + dy, cardDimensions.getFrameWidth(), 20);
        draftRating.setHorizontalAlignment(SwingConstants.CENTER);
        draftRating.setFont(jLayeredPane.getFont().deriveFont(jLayeredPane.getFont().getStyle() | Font.BOLD));
        if (card.getOriginalCard() != null) {
            draftRating.setText("draft rating: " + RateCard.rateCard(card.getOriginalCard(), null));
        } else {
            draftRating.setText("");
        }
        jLayeredPane.add(draftRating);
    }
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 15 with MageCard

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

the class MageBook method addToken.

private void addToken(Token token, BigCard bigCard, UUID gameId, Rectangle rectangle) {
    if (cardDimension == null) {
        cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
    }
    PermanentToken newToken = new PermanentToken(token, null, token.getOriginalExpansionSetCode(), null);
    newToken.removeSummoningSickness();
    PermanentView theToken = new PermanentView(newToken, null, null, null);
    theToken.setInViewerOnly(true);
    final MageCard cardImg = Plugins.instance.getMagePermanent(theToken, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
    cardImg.setCardContainerRef(jLayeredPane);
    jLayeredPane.add(cardImg, JLayeredPane.DEFAULT_LAYER, 10);
    cardImg.update(theToken);
    cardImg.setCardBounds(rectangle.x, rectangle.y, cardDimensions.getFrameWidth(), cardDimensions.getFrameHeight());
}
Also used : PermanentToken(mage.game.permanent.PermanentToken) 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