Search in sources :

Example 1 with MageCard

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

the class DraftGrid method loadBooster.

public void loadBooster(CardsView booster, BigCard bigCard) {
    if (booster != null && booster.isEmpty()) {
        emptyGrid = true;
    } else {
        if (!emptyGrid) {
            AudioManager.playOnDraftSelect();
        }
        emptyGrid = false;
    }
    this.bigCard = bigCard;
    this.removeAll();
    int maxRows = 4;
    int numColumns = 5;
    int curColumn = 0;
    int curRow = 0;
    int offsetX = 5;
    int offsetY = 3;
    CardDimensions cardDimension = null;
    int maxCards;
    double scale;
    for (int i = 1; i < maxRows; i++) {
        scale = (double) (this.getHeight() / i) / Constants.FRAME_MAX_HEIGHT;
        cardDimension = new CardDimensions(scale);
        maxCards = this.getWidth() / (cardDimension.getFrameWidth() + offsetX);
        if ((maxCards * i) >= booster.size()) {
            numColumns = booster.size() / i;
            if (booster.size() % i > 0) {
                numColumns++;
            }
            break;
        }
    }
    if (cardDimension != null) {
        Rectangle rectangle = new Rectangle(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
        Dimension dimension = new Dimension(cardDimension.getFrameWidth(), cardDimension.getFrameHeight());
        List<CardView> sortedCards = new ArrayList<>(booster.values());
        sortedCards.sort(new CardViewRarityComparator());
        for (CardView card : sortedCards) {
            MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), dimension, null, true, true, PreferencesDialog.getRenderMode(), true);
            cardImg.setCardContainerRef(this);
            cardImg.update(card);
            this.add(cardImg);
            rectangle.setLocation(curColumn * (cardDimension.getFrameWidth() + offsetX) + offsetX, curRow * (rectangle.height + offsetY) + offsetY);
            cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
            curColumn++;
            if (curColumn == numColumns) {
                curColumn = 0;
                curRow++;
            }
        }
        repaint();
    } else {
        logger.warn("Draft Grid - no possible fit of cards");
    }
}
Also used : CardViewRarityComparator(mage.client.util.comparators.CardViewRarityComparator) CardView(mage.view.CardView) ArrayList(java.util.ArrayList) CardDimensions(mage.cards.CardDimensions) MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 2 with MageCard

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

the class SelectionBox method layoutGrid.

/**
 * Position all of the card views correctly
 */
private void layoutGrid() {
    // Basic dimensions
    int cardWidth = getCardWidth();
    int cardHeight = getCardHeight();
    int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
    // Layout one at a time
    int layerIndex = 0;
    int currentY = COUNT_LABEL_HEIGHT;
    int maxWidth = 0;
    for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
        int rowMaxStackSize = 0;
        List<List<CardView>> gridRow = cardGrid.get(rowIndex);
        for (int colIndex = 0; colIndex < gridRow.size(); ++colIndex) {
            List<CardView> stack = gridRow.get(colIndex);
            // Stack count label
            if (stackCountLabels.size() <= rowIndex) {
                stackCountLabels.add(new ArrayList<>());
            }
            if (stackCountLabels.get(rowIndex).size() <= colIndex) {
                // ENABLE cards auto-selection in the stack
                if (this.countLabelListener == null) {
                    this.countLabelListener = new MouseAdapter() {

                        @Override
                        public void mouseClicked(MouseEvent e) {
                            JLabel countLabel = (JLabel) e.getComponent();
                            List<CardView> cards = findCardStackByCountLabel(countLabel);
                            boolean selected = !cards.isEmpty() && cards.get(0).isSelected();
                            cards.forEach(card -> {
                                card.setSelected(!selected);
                                cardViews.get(card.getId()).update(card);
                            });
                        }
                    };
                }
                JLabel countLabel = DragCardGrid.createCountLabel(this.countLabelListener);
                cardContent.add(countLabel, (Integer) 0);
                stackCountLabels.get(rowIndex).add(countLabel);
            }
            JLabel countLabel = stackCountLabels.get(rowIndex).get(colIndex);
            if (stack.isEmpty()) {
                countLabel.setVisible(false);
            } else {
                String description = cardSort.getComparator().getCategoryName(stack.get(0));
                DragCardGrid.updateCountLabel(countLabel, stack.size(), description);
                countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT);
                countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT);
                countLabel.setVisible(true);
            }
            // Max stack size
            rowMaxStackSize = Math.max(rowMaxStackSize, stack.size());
            // Layout cards in stack
            for (int i = 0; i < stack.size(); ++i) {
                CardView card = stack.get(i);
                MageCard view = cardViews.get(card.getId());
                int x = GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex;
                int y = currentY + i * cardTopHeight;
                view.setCardBounds(x, y, cardWidth, cardHeight);
                cardContent.setLayer(view, layerIndex++);
            }
        }
        // Update the max stack size for this row and the max width
        maxWidth = Math.max(maxWidth, GRID_PADDING + (GRID_PADDING + cardWidth) * gridRow.size());
        maxStackSize.set(rowIndex, rowMaxStackSize);
        currentY += (cardTopHeight * (rowMaxStackSize - 1) + cardHeight) + COUNT_LABEL_HEIGHT;
    }
    // Resize card container
    cardContent.setPreferredSize(new Dimension(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING));
// cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING);
}
Also used : ManaSymbols(org.mage.card.arcane.ManaSymbols) java.util(java.util) CardCriteria(mage.cards.repository.CardCriteria) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings) SubType(mage.constants.SubType) DeckCardLayout(mage.cards.decks.DeckCardLayout) Logger(org.apache.log4j.Logger) ClientEventType(mage.client.util.ClientEventType) Matcher(java.util.regex.Matcher) CardType(mage.constants.CardType) MageCard(mage.cards.MageCard) Card(mage.cards.Card) RandomUtil(mage.util.RandomUtil) DeckCardInfo(mage.cards.decks.DeckCardInfo) DebugUtil(mage.util.DebugUtil) CardRepository(mage.cards.repository.CardRepository) CardsView(mage.view.CardsView) Collectors(java.util.stream.Collectors) CardRenderer(org.mage.card.arcane.CardRenderer) java.awt(java.awt) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) List(java.util.List) Event(mage.client.util.Event) Listener(mage.client.util.Listener) CardInfo(mage.cards.repository.CardInfo) java.awt.event(java.awt.event) GUISizeHelper(mage.client.util.GUISizeHelper) Rarity(mage.constants.Rarity) Constants(mage.client.constants.Constants) Pattern(java.util.regex.Pattern) CardView(mage.view.CardView) mage.client.util.comparators(mage.client.util.comparators) SuperType(mage.constants.SuperType) javax.swing(javax.swing) CardView(mage.view.CardView) MageCard(mage.cards.MageCard) List(java.util.List)

Example 3 with MageCard

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

the class SelectionBox method cleanUp.

public void cleanUp() {
    // Remove all of the cards from us
    for (MageCard cardView : cardViews.values()) {
        cardContent.remove(cardView);
    }
    // Clear out our tracking of stuff
    cardGrid.clear();
    maxStackSize.clear();
    allCards.clear();
    lastBigCard = null;
    clearCardEventListeners();
}
Also used : MageCard(mage.cards.MageCard)

Example 4 with MageCard

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

the class SelectionBox method invertSelection.

private void invertSelection() {
    Collection<CardView> toInvert = allCards;
    for (DragCardGridListener l : listeners) {
        l.invertCardSelection(toInvert);
        for (CardView card : allCards) {
            MageCard view = cardViews.get(card.getId());
            view.update(card);
        }
    }
    repaint();
}
Also used : CardView(mage.view.CardView) MageCard(mage.cards.MageCard)

Example 5 with MageCard

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

the class MageActionCallback method updateCardHints.

private void updateCardHints(TransferData data) {
    MageCard cardPanel = data.getComponent().getTopPanelRef();
    if (!popupTextWindowOpen || !Objects.equals(cardPanel.getOriginal().getId(), bigCard.getCardId())) {
        if (bigCard.getWidth() > 0) {
            synchronized (MageActionCallback.class) {
                if (!popupTextWindowOpen || !Objects.equals(cardPanel.getOriginal().getId(), bigCard.getCardId())) {
                    if (!popupTextWindowOpen) {
                        bigCard.resetCardId();
                    }
                    popupTextWindowOpen = true;
                    Image image = cardPanel.getImage();
                    displayCardInfo(cardPanel.getOriginal(), image, bigCard);
                }
            }
        } else {
            popupTextWindowOpen = true;
        }
        if (enlargedWindowState != EnlargedWindowState.CLOSED) {
            cancelTimeout();
            displayEnlargedCard(cardPanel.getOriginal(), data);
        }
    }
}
Also used : MageCard(mage.cards.MageCard) BufferedImage(java.awt.image.BufferedImage)

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