Search in sources :

Example 36 with MageCard

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

the class ArrowUtil method drawArrowsForBandedCards.

public static void drawArrowsForBandedCards(TransferData data, Point parentPoint) {
    if (data.getCard().getBandedCards() != null && !data.getCard().getBandedCards().isEmpty()) {
        Point me = new Point(data.getLocationOnScreen());
        me.translate(-parentPoint.x, -parentPoint.y);
        for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) {
            for (UUID uuid : data.getCard().getBandedCards()) {
                MageCard permanent = pa.getBattlefieldPanel().getPermanentPanels().get(uuid);
                if (permanent != null) {
                    Point target = permanent.getCardLocationOnScreen().getCardPoint();
                    target.translate(-parentPoint.x, -parentPoint.y);
                    ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 55, (int) me.getY() + 25, (int) target.getX() + 60, (int) target.getY() + 35, Color.yellow, ArrowBuilder.Type.BANDED);
                }
            }
        }
    }
}
Also used : PlayAreaPanel(mage.client.game.PlayAreaPanel) MageCard(mage.cards.MageCard) UUID(java.util.UUID)

Example 37 with MageCard

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

the class ArrowUtil method drawArrowsForPairedCards.

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

Example 38 with MageCard

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

the class Animation method moveCardToPlay.

public static void moveCardToPlay(final int startX, final int startY, final int startWidth, final int endX, final int endY, final int endWidth, final CardPanel cardToAnimate, final CardPanel placeholder, final JLayeredPane layeredPane, final int speed) {
    CardPanel cardPanel = (CardPanel) cardToAnimate.getMainPanel();
    MageCard mainPanel = cardToAnimate.getTopPanelRef();
    UI.invokeLater(() -> {
        final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
        final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO);
        final float a = 2f;
        final float sqrta = (float) Math.sqrt(1 / a);
        mainPanel.setCardBounds(startX, startY, startWidth, startHeight);
        cardPanel.setAnimationPanel(true);
        Container parent = mainPanel.getParent();
        if (parent != null && !parent.equals(layeredPane)) {
            layeredPane.add(mainPanel);
            layeredPane.setLayer(mainPanel, JLayeredPane.MODAL_LAYER);
        }
        new Animation(700) {

            @Override
            protected void update(float percentage) {
                float percent = percentage;
                if (placeholder != null && !placeholder.isShowing()) {
                    cancel();
                    return;
                }
                int currentX = startX + Math.round((endX - startX + endWidth / 2f) * percent);
                int currentY = startY + Math.round((endY - startY + endHeight / 2f) * percent);
                int currentWidth, currentHeight;
                int midWidth = Math.max(200, endWidth * 2);
                int midHeight = Math.round(midWidth * CardPanel.ASPECT_RATIO);
                if (percent <= 0.5f) {
                    percent = percent * 2;
                    float pp = sqrta * (1 - percent);
                    percent = 1 - a * pp * pp;
                    currentWidth = startWidth + Math.round((midWidth - startWidth) * percent);
                    currentHeight = startHeight + Math.round((midHeight - startHeight) * percent);
                } else {
                    percent = (percent - 0.5f) * 2;
                    float pp = sqrta * percent;
                    percent = a * pp * pp;
                    currentWidth = midWidth + Math.round((endWidth - midWidth) * percent);
                    currentHeight = midHeight + Math.round((endHeight - midHeight) * percent);
                }
                currentX -= currentWidth / 2;
                currentY -= currentHeight / 2;
                mainPanel.setCardBounds(currentX, currentY, currentWidth, currentHeight);
            }

            @Override
            protected void end() {
                EventQueue.invokeLater(() -> {
                    if (placeholder != null) {
                        placeholder.setDisplayEnabled(true);
                        placeholder.transferResources(cardPanel);
                    }
                    mainPanel.setVisible(false);
                    mainPanel.repaint();
                    layeredPane.remove(mainPanel);
                });
            }
        };
    });
}
Also used : MageCard(mage.cards.MageCard)

Example 39 with MageCard

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

the class Animation method moveCard.

public static void moveCard(final int startX, final int startY, final int startWidth, final int endX, final int endY, final int endWidth, final MageCard cardToAnimate, final CardPanel placeholder, final JLayeredPane layeredPane, final int speed) {
    CardPanel cardPanel = (CardPanel) cardToAnimate.getMainPanel();
    MageCard mainPanel = cardToAnimate.getTopPanelRef();
    UI.invokeLater(() -> {
        final int startHeight = Math.round(startWidth * CardPanel.ASPECT_RATIO);
        final int endHeight = Math.round(endWidth * CardPanel.ASPECT_RATIO);
        mainPanel.setCardBounds(startX, startY, startWidth, startHeight);
        cardPanel.setAnimationPanel(true);
        Container parent = mainPanel.getParent();
        if (parent != null && !parent.equals(layeredPane)) {
            layeredPane.add(mainPanel);
            layeredPane.setLayer(mainPanel, JLayeredPane.MODAL_LAYER);
        }
        new Animation(speed) {

            @Override
            protected void update(float percentage) {
                int currentX = startX + Math.round((endX - startX) * percentage);
                int currentY = startY + Math.round((endY - startY) * percentage);
                int currentWidth = startWidth + Math.round((endWidth - startWidth) * percentage);
                int currentHeight = startHeight + Math.round((endHeight - startHeight) * percentage);
                mainPanel.setCardBounds(currentX, currentY, currentWidth, currentHeight);
            }

            @Override
            protected void end() {
                EventQueue.invokeLater(() -> {
                    if (placeholder != null) {
                        placeholder.setDisplayEnabled(true);
                        placeholder.transferResources(cardPanel);
                    }
                    mainPanel.setVisible(false);
                    mainPanel.repaint();
                    layeredPane.remove(mainPanel);
                });
            }
        };
    });
}
Also used : MageCard(mage.cards.MageCard)

Example 40 with MageCard

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

the class CardPluginImpl method sortPermanents.

@Override
public int sortPermanents(Map<String, JComponent> ui, Map<UUID, MageCard> cards, boolean nonPermanentsOwnRow, boolean topPanel) {
    if (ui == null) {
        throw new RuntimeException("No battlefield ui for layout");
    }
    JLayeredPane battlefieldPanel = (JLayeredPane) ui.get("battlefieldPanel");
    JComponent cardsPanel = ui.get("jPanel");
    JScrollPane scrollPane = (JScrollPane) ui.get("scrollPane");
    if (battlefieldPanel == null || cardsPanel == null || scrollPane == null) {
        throw new RuntimeException("No battlefield components for layout");
    }
    Row rowAllLands = new Row();
    outerLoop: // 
    for (MageCard card : cards.values()) {
        // all cards must be MagePermanent on battlefield
        MagePermanent perm = (MagePermanent) card.getMainPanel();
        if (!perm.isLand() || perm.isCreature()) {
            continue;
        }
        int insertIndex = -1;
        // Find already added lands with the same name.
        for (int i = 0, n = rowAllLands.size(); i < n; i++) {
            // stack contains main card panel, but for any size/order manipulation you must use top layer panel
            Stack stack = rowAllLands.get(i);
            MagePermanent firstPanelPerm = stack.get(0);
            if (firstPanelPerm.getOriginal().getName().equals(perm.getOriginal().getName())) {
                if (!empty(firstPanelPerm.getOriginalPermanent().getAttachments())) {
                    // Put this land to the left of lands with the same name and attachments.
                    insertIndex = i;
                    break;
                }
                List<CounterView> counters = firstPanelPerm.getOriginalPermanent().getCounters();
                if (counters != null && !counters.isEmpty()) {
                    // don't put to first panel if it has counters
                    insertIndex = i;
                    break;
                }
                if (!empty(perm.getOriginalPermanent().getAttachments()) || stack.size() == landStackMax) {
                    // If this land has attachments or the stack is full, put it to the right.
                    insertIndex = i + 1;
                    continue;
                }
                counters = perm.getOriginalPermanent().getCounters();
                if (counters != null && !counters.isEmpty()) {
                    // if a land has counter, put it to the right
                    insertIndex = i + 1;
                    continue;
                }
                // Add to stack.
                stack.add(0, perm);
                continue outerLoop;
            }
            if (insertIndex != -1) {
                break;
            }
        }
        Stack stack = new Stack();
        if (perm.getOriginalPermanent().getAttachments() != null && !perm.getOriginalPermanent().getAttachments().isEmpty() && !perm.getOriginalPermanent().isAttachedTo()) {
            // get the number of all attachements and sub attachments
            AttachmentLayoutInfos ali = calculateNeededNumberOfVerticalColumns(0, cards, card);
            stack.setMaxAttachedCount(ali.getAttachments());
            stack.setAttachmentColumns(ali.getColumns());
        }
        stack.add(perm);
        rowAllLands.add(insertIndex == -1 ? rowAllLands.size() : insertIndex, stack);
    }
    Row rowAllCreatures = new Row(cards, RowType.creature);
    Row rowAllOthers = new Row(cards, RowType.other);
    Row rowAllAttached = new Row(cards, RowType.attached);
    boolean othersOnTheRight = true;
    if (nonPermanentsOwnRow) {
        othersOnTheRight = false;
        rowAllCreatures.addAll(rowAllOthers);
        rowAllOthers.clear();
    }
    // try to auto-fit cards
    cardWidth = cardWidthMax;
    Rectangle rect = battlefieldPanel.getVisibleRect();
    playAreaWidth = rect.width;
    playAreaHeight = rect.height;
    while (true) {
        rows.clear();
        // calculate values based on the card size that is changing with every iteration
        cardHeight = Math.round(cardWidth * CardPanel.ASPECT_RATIO);
        extraCardSpacingX = Math.round(cardWidth * EXTRA_CARD_SPACING_X);
        // need space for tap animation (horizontal position)
        cardSpacingX = cardHeight - cardWidth + extraCardSpacingX;
        cardSpacingY = Math.round(cardHeight * CARD_SPACING_Y);
        stackSpacingX = stackVertical ? 0 : Math.round(cardWidth * STACK_SPACING_X);
        stackSpacingY = Math.round(cardHeight * STACK_SPACING_Y);
        attachmentSpacingY = Math.round(cardHeight * ATTACHMENT_SPACING_Y);
        // clone data
        Row creatures = (Row) rowAllCreatures.clone();
        Row lands = (Row) rowAllLands.clone();
        Row others = (Row) rowAllOthers.clone();
        // Wrap all creatures and lands.
        int addOthersIndex;
        if (topPanel) {
            wrap(lands, rows, -1);
            wrap(others, rows, rows.size());
            addOthersIndex = rows.size();
            wrap(creatures, rows, addOthersIndex);
        } else {
            wrap(creatures, rows, -1);
            addOthersIndex = rows.size();
            wrap(lands, rows, rows.size());
            wrap(others, rows, rows.size());
        }
        // Store the current rows and others.
        List<Row> storedRows = new ArrayList<>(rows.size());
        for (Row row : rows) {
            storedRows.add((Row) row.clone());
        }
        Row storedOthers = (Row) others.clone();
        // Fill in all rows with others.
        for (Row row : rows) {
            fillRow(others, rows, row);
        }
        // Stop if everything fits, otherwise revert back to the stored values.
        if (creatures.isEmpty() && lands.isEmpty() && others.isEmpty()) {
            break;
        }
        rows = storedRows;
        others = storedOthers;
        // Try to put others on their own row(s) and fill in the rest.
        wrap(others, rows, addOthersIndex);
        for (Row row : rows) {
            fillRow(others, rows, row);
        }
        // If that still doesn't fit, scale down.
        if (creatures.isEmpty() && lands.isEmpty() && others.isEmpty()) {
            break;
        }
        cardWidth -= CARD_WIDTH_AUTO_FIT_INCREMENT;
    }
    // Get size of all the rows.
    int x, y = GUTTER_Y;
    int maxRowWidth = 0;
    for (Row row : rows) {
        int rowBottom = 0;
        x = GUTTER_X;
        for (int stackIndex = 0, stackCount = row.size(); stackIndex < stackCount; stackIndex++) {
            Stack stack = row.get(stackIndex);
            rowBottom = Math.max(rowBottom, y + stack.getHeight());
            x += stack.getWidth();
        }
        y = rowBottom;
        maxRowWidth = Math.max(maxRowWidth, x);
    }
    // Position all card panels
    y = GUTTER_Y;
    for (Row row : rows) {
        int rowBottom = 0;
        x = GUTTER_X;
        for (int stackIndex = 0, stackCount = row.size(); stackIndex < stackCount; stackIndex++) {
            Stack stack = row.get(stackIndex);
            // Align others to the right.
            if (othersOnTheRight && RowType.other.isType(stack.get(0))) {
                x = playAreaWidth - GUTTER_X + extraCardSpacingX;
                for (int i = stackIndex, n = row.size(); i < n; i++) {
                    x -= row.get(i).getWidth();
                }
            }
            for (int panelIndex = 0, panelCount = stack.size(); panelIndex < panelCount; panelIndex++) {
                // it's original card panel, but you must change top layer
                MagePermanent panelPerm = stack.get(panelIndex);
                int stackPosition = panelCount - panelIndex - 1;
                if (cardsPanel != null) {
                    cardsPanel.setComponentZOrder(panelPerm.getTopPanelRef(), panelIndex);
                }
                int panelX = x + (stackPosition * stackSpacingX);
                int panelY = y + (stackPosition * stackSpacingY);
                try {
                    // may cause:
                    // java.lang.IllegalArgumentException: illegal component position 26 should be less then 26
                    battlefieldPanel.moveToFront(panelPerm.getTopPanelRef());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                panelPerm.getTopPanelRef().setCardBounds(panelX, panelY, cardWidth, cardHeight);
            }
            rowBottom = Math.max(rowBottom, y + stack.getHeight());
            x += stack.getWidth();
        }
        y = rowBottom;
    }
    // attached permanents will be handled separately
    for (Stack stack : rowAllAttached) {
        for (MagePermanent panelPerm : stack) {
            panelPerm.getTopPanelRef().setCardBounds(0, 0, cardWidth, cardHeight);
        }
    }
    // scrollbars speed
    scrollPane.getVerticalScrollBar().setUnitIncrement(GUISizeHelper.getCardsScrollbarUnitInc(cardHeight));
    return y;
}
Also used : MageCard(mage.cards.MageCard) List(java.util.List) MagePermanent(mage.cards.MagePermanent)

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