Search in sources :

Example 21 with MageCard

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

the class ArrowUtil method drawArrowsForTargets.

public static void drawArrowsForTargets(TransferData data, Point parentPoint) {
    java.util.List<UUID> targets = data.getCard().getTargets();
    if (targets == null) {
        return;
    }
    Point me = new Point(data.getLocationOnScreen());
    me.translate(-parentPoint.x, -parentPoint.y);
    for (UUID uuid : targets) {
        PlayAreaPanel p = MageFrame.getGamePlayers(data.getGameId()).get(uuid);
        if (p != null) {
            Point target = p.getLocationOnScreen();
            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() - 40, Color.red, ArrowBuilder.Type.TARGET);
            continue;
        }
        for (PlayAreaPanel panel : MageFrame.getGamePlayers(data.getGameId()).values()) {
            MageCard permanent = panel.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.red, ArrowBuilder.Type.TARGET);
                continue;
            }
            PlayerView view = panel.getPlayerPanel().getPlayer();
            if (view != null) {
                CardsView graveyard = view.getGraveyard();
                if (graveyard.containsKey(uuid)) {
                    p = MageFrame.getGamePlayers(data.getGameId()).get(view.getPlayerId());
                    if (p != null) {
                        Point target = p.getLocationOnScreen();
                        target.translate(-parentPoint.x, -parentPoint.y);
                        int yOffset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0;
                        ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
                    }
                }
            }
        }
    }
}
Also used : PlayerView(mage.view.PlayerView) PlayAreaPanel(mage.client.game.PlayAreaPanel) MageCard(mage.cards.MageCard) CardsView(mage.view.CardsView) UUID(java.util.UUID)

Example 22 with MageCard

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

the class Cards method layoutCards.

private void layoutCards() {
    // get all the card panels
    java.util.List<MageCard> cardsToLayout = new ArrayList<>();
    for (Component component : cardArea.getComponents()) {
        if (component instanceof MageCard) {
            cardsToLayout.add((MageCard) component);
        }
    }
    // WARNING, must be same sort code as MageActionCallback->sortLayout (if not then hand cards will be messed after drag)
    // sort the cards
    cardsToLayout.sort(Comparator.comparingInt(cp -> cp.getCardLocation().getCardX()));
    // relocate the cards (support only horizontal style: hand and stack panels)
    // TODO: add shrinking of cards list for too big amount (cards will be overlapped, use MageActionCallback.HAND_CARDS_BETWEEN_GAP_X to control it)
    // starting position
    int dx = MageActionCallback.getHandOrStackBetweenGapX(zone);
    for (MageCard component : cardsToLayout) {
        component.setCardLocation(dx, component.getCardLocation().getCardY());
        dx += component.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(zone);
    }
}
Also used : java.util(java.util) MageActionCallback(mage.client.plugins.adapters.MageActionCallback) Zone(mage.constants.Zone) DebugUtil(mage.util.DebugUtil) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings) ClientDefaultSettings(mage.client.util.ClientDefaultSettings) Border(javax.swing.border.Border) java.awt(java.awt) mage.view(mage.view) Logger(org.apache.log4j.Logger) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) CardsViewUtil(mage.client.util.CardsViewUtil) GUISizeHelper(mage.client.util.GUISizeHelper) EmptyBorder(javax.swing.border.EmptyBorder) MageCard(mage.cards.MageCard) javax.swing(javax.swing) java.util(java.util) MageCard(mage.cards.MageCard)

Example 23 with MageCard

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

the class Cards method definePosition.

private void definePosition(MageCard newCard) {
    // starting position
    int dx = MageActionCallback.getHandOrStackMargins(zone).getLeft();
    // search last card's position
    for (Component currentComp : cardArea.getComponents()) {
        if (!currentComp.equals(newCard) && currentComp instanceof MageCard) {
            MageCard currentCard = (MageCard) currentComp;
            dx = Math.max(dx, currentCard.getCardLocation().getCardX());
        }
    }
    // Y position sets here one time only (all sorting and drag manipulations works with X)
    // add card to the end
    dx += newCard.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(newCard.getZone());
    newCard.setCardLocation(dx, MageActionCallback.getHandOrStackMargins(newCard.getZone()).getTop());
}
Also used : MageCard(mage.cards.MageCard)

Example 24 with MageCard

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

the class SelectionBox method addCardView.

public void addCardView(final CardView card, boolean duplicated) {
    allCards.add(card);
    // Update counts
    for (CardTypeCounter counter : allCounters) {
        counter.add(card);
    }
    updateCounts();
    // Create the card view
    final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new CardIconRenderSettings(), new Dimension(getCardWidth(), getCardHeight()), null, true, true, PreferencesDialog.getRenderMode(), true);
    cardPanel.setCardContainerRef(this);
    cardPanel.update(card);
    // cards bounds set in layoutGrid()
    cardPanel.setCardCaptionTopOffset(0);
    // ENABLE DRAG SUPPORT FOR CARDS
    // TODO: rewrite mouseDragged in MageActionCallback, so it can support any drags, not hands only
    cardPanel.addMouseMotionListener(new MouseAdapter() {

        @Override
        public void mouseDragged(MouseEvent e) {
            if (!dragger.isDragging()) {
                // If the card isn't already selected, make sure it is
                if (!card.isSelected()) {
                    selectCard(card);
                }
                dragger.handleDragStart(cardPanel, e);
            }
        }
    });
    // And add it
    cardContent.add(cardPanel);
    cardViews.put(card.getId(), cardPanel);
    if (duplicated) {
        sortIntoGrid(card);
        eventSource.fireEvent(card, ClientEventType.DECK_ADD_SPECIFIC_CARD);
        // clear grid from empty rows
        trimGrid();
        // Update layout
        layoutGrid();
        repaintGrid();
    }
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 25 with MageCard

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

the class SelectionBox method updateSelectionDrag.

private void updateSelectionDrag(int x, int y) {
    // Coords
    int cardWidth = getCardWidth();
    int cardHeight = getCardHeight();
    int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
    int x1 = Math.min(x, selectionDragStartX);
    int x2 = Math.max(x, selectionDragStartX);
    int y1 = Math.min(y, selectionDragStartY);
    int y2 = Math.max(y, selectionDragStartY);
    // Update selection panel size
    selectionPanel.setLocation(x1, y1);
    selectionPanel.setSize(x2 - x1, y2 - y1);
    // First and last cols
    int col1 = x1 / (cardWidth + GRID_PADDING);
    int col2 = x2 / (cardWidth + GRID_PADDING);
    int offsetIntoCol2 = x2 % (cardWidth + GRID_PADDING);
    if (offsetIntoCol2 < GRID_PADDING) {
        --col2;
    }
    int curY = COUNT_LABEL_HEIGHT;
    for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
        int stackStartIndex;
        if (y1 < curY) {
            stackStartIndex = 0;
        } else {
            stackStartIndex = (y1 - curY) / cardTopHeight;
        }
        int stackEndIndex;
        if (y2 < curY) {
            stackEndIndex = -1;
        } else {
            stackEndIndex = (y2 - curY) / cardTopHeight;
        }
        List<List<CardView>> gridRow = cardGrid.get(rowIndex);
        for (int col = 0; col < gridRow.size(); ++col) {
            List<CardView> stack = gridRow.get(col);
            int stackBottomBegin = curY + cardTopHeight * (stack.size());
            int stackBottomEnd = curY + cardTopHeight * (stack.size() - 1) + cardHeight;
            for (int i = 0; i < stack.size(); ++i) {
                CardView card = stack.get(i);
                MageCard view = cardViews.get(card.getId());
                boolean inBoundsX = (col >= col1 && col <= col2);
                boolean inBoundsY = (i >= stackStartIndex && i <= stackEndIndex);
                boolean lastCard = (i == stack.size() - 1);
                boolean inSeletionDrag = inBoundsX && (inBoundsY || (lastCard && (y2 >= stackBottomBegin && y1 <= stackBottomEnd)));
                if (inSeletionDrag || selectionDragStartCards != null && selectionDragStartCards.contains(card)) {
                    if (!card.isSelected()) {
                        card.setSelected(true);
                        view.update(card);
                    }
                } else if (card.isSelected()) {
                    card.setSelected(false);
                    view.update(card);
                }
            }
        }
        curY += cardTopHeight * (maxStackSize.get(rowIndex) - 1) + cardHeight + COUNT_LABEL_HEIGHT;
    }
}
Also used : CardView(mage.view.CardView) List(java.util.List) MageCard(mage.cards.MageCard)

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