Search in sources :

Example 16 with MageCard

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

the class CardPluginImpl method calculateNeededNumberOfVerticalColumns.

private AttachmentLayoutInfos calculateNeededNumberOfVerticalColumns(int currentCol, Map<UUID, MageCard> cards, MageCard cardWithAttachments) {
    int maxCol = ++currentCol;
    int attachments = 0;
    MagePermanent permWithAttachments = (MagePermanent) cardWithAttachments.getMainPanel();
    for (UUID attachmentId : permWithAttachments.getOriginalPermanent().getAttachments()) {
        MageCard attachedCard = cards.get(attachmentId);
        if (attachedCard != null) {
            attachments++;
            MagePermanent attachedPerm = (MagePermanent) attachedCard.getMainPanel();
            if (attachedPerm.getOriginalPermanent().getAttachments() != null && !attachedPerm.getOriginalPermanent().getAttachments().isEmpty()) {
                AttachmentLayoutInfos attachmentLayoutInfos = calculateNeededNumberOfVerticalColumns(currentCol, cards, attachedCard);
                if (attachmentLayoutInfos.getColumns() > maxCol) {
                    maxCol = attachmentLayoutInfos.getColumns();
                    attachments += attachmentLayoutInfos.getAttachments();
                }
            }
        }
    }
    return new AttachmentLayoutInfos(maxCol, attachments);
}
Also used : MageCard(mage.cards.MageCard) MagePermanent(mage.cards.MagePermanent)

Example 17 with MageCard

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

the class CardLayoutStrategyImpl method doLayout.

@Override
public void doLayout(BattlefieldPanel battlefieldPanel, int battlefieldWidth) {
    Map<UUID, MageCard> cards = battlefieldPanel.getPermanentPanels();
    JLayeredPane mainPanel = battlefieldPanel.getMainPanel();
    // does the basic layout of rows and colums
    int height = Plugins.instance.sortPermanents(battlefieldPanel.getUiComponentsList(), cards, battlefieldPanel.isTopPanelBattlefield());
    mainPanel.setPreferredSize(new Dimension(battlefieldWidth - 30, height));
    for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) {
        if (permanent.getAttachments() != null && !permanent.isAttachedTo()) {
            // Layout only permanents that are not attached to other permanents itself
            groupAttachments(battlefieldPanel, mainPanel, cards, permanent);
        }
    }
}
Also used : JLayeredPane(javax.swing.JLayeredPane) PermanentView(mage.view.PermanentView) MageCard(mage.cards.MageCard) Dimension(java.awt.Dimension) UUID(java.util.UUID) Point(java.awt.Point)

Example 18 with MageCard

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

the class Animation method tapCardToggle.

public static void tapCardToggle(final CardPanel source, final boolean tapped, final boolean flipped) {
    CardPanel mainPanel = source;
    MageCard parentPanel = mainPanel.getTopPanelRef();
    new Animation(300) {

        @Override
        protected void start() {
            parentPanel.onBeginAnimation();
        }

        @Override
        protected void update(float percentage) {
            if (tapped) {
                mainPanel.setTappedAngle(CardPanel.TAPPED_ANGLE * percentage);
                // reverse movement if untapping
                if (!mainPanel.isTapped()) {
                    mainPanel.setTappedAngle(CardPanel.TAPPED_ANGLE - mainPanel.getTappedAngle());
                }
            }
            if (flipped) {
                mainPanel.setFlippedAngle(CardPanel.FLIPPED_ANGLE * percentage);
                if (!mainPanel.isFlipped()) {
                    mainPanel.setFlippedAngle(CardPanel.FLIPPED_ANGLE - mainPanel.getFlippedAngle());
                }
            }
            parentPanel.repaint();
        }

        @Override
        protected void end() {
            if (tapped) {
                mainPanel.setTappedAngle(mainPanel.isTapped() ? CardPanel.TAPPED_ANGLE : 0);
            }
            if (flipped) {
                mainPanel.setFlippedAngle(mainPanel.isFlipped() ? CardPanel.FLIPPED_ANGLE : 0);
            }
            parentPanel.onEndAnimation();
            parentPanel.repaint();
        }
    };
}
Also used : MageCard(mage.cards.MageCard)

Example 19 with MageCard

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

the class Animation method transformCard.

public static void transformCard(final CardPanel source) {
    CardPanel mainPanel = source;
    MageCard parentPanel = mainPanel.getTopPanelRef();
    new Animation(600) {

        private boolean state = false;

        @Override
        protected void start() {
            parentPanel.onBeginAnimation();
        }

        @Override
        protected void update(float percentage) {
            double p = percentage * 2;
            if (percentage > 0.5) {
                if (!state) {
                    parentPanel.toggleTransformed();
                }
                state = true;
                p = (p - 0.5) * 2;
            }
            if (!state) {
                mainPanel.transformAngle = Math.max(0.01, 1 - p);
            } else {
                mainPanel.transformAngle = Math.max(0.01, p - 1);
            }
            parentPanel.repaint();
        }

        @Override
        protected void end() {
            if (!state) {
                parentPanel.toggleTransformed();
            }
            state = true;
            mainPanel.transformAngle = 1;
            parentPanel.onEndAnimation();
            parentPanel.repaint();
        }
    };
}
Also used : MageCard(mage.cards.MageCard)

Example 20 with MageCard

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

the class ArrowUtil method drawArrowsForSource.

public static void drawArrowsForSource(TransferData data, Point parentPoint) {
    if (data.getCard().isAbility()) {
        Point me = new Point(data.getLocationOnScreen());
        me.translate(-parentPoint.x, -parentPoint.y);
        UUID uuid = data.getCard().getParentId();
        for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) {
            MageCard permanent = pa.getBattlefieldPanel().getPermanentPanels().get(uuid);
            if (permanent != null) {
                Point source = permanent.getCardLocationOnScreen().getCardPoint();
                source.translate(-parentPoint.x, -parentPoint.y);
                ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue, ArrowBuilder.Type.SOURCE);
            }
        }
    }
}
Also used : PlayAreaPanel(mage.client.game.PlayAreaPanel) MageCard(mage.cards.MageCard) UUID(java.util.UUID)

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