Search in sources :

Example 6 with CardView

use of mage.view.CardView in project mage by magefree.

the class SelectionBox method deselectAll.

/**
 * Deselect all cards in this DragCardGrid
 */
public void deselectAll() {
    for (List<List<CardView>> gridRow : cardGrid) {
        for (List<CardView> stack : gridRow) {
            for (CardView card : stack) {
                if (card.isSelected()) {
                    card.setSelected(false);
                    cardViews.get(card.getId()).update(card);
                }
            }
        }
    }
}
Also used : CardView(mage.view.CardView) List(java.util.List)

Example 7 with CardView

use of mage.view.CardView 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 8 with CardView

use of mage.view.CardView 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 9 with CardView

use of mage.view.CardView in project mage by magefree.

the class ColorPane method addHyperlinkHandlers.

private void addHyperlinkHandlers() {
    addHyperlinkListener(e -> ThreadUtils.threadPool2.submit(() -> {
        if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300) == 0) {
            // if disabled
            return;
        }
        // finds extra data in html element like object_id, alternative_name, etc
        Map<String, String> extraData = new HashMap<>();
        if (e.getSourceElement() instanceof HTMLDocument.RunElement) {
            HTMLDocument.RunElement el = (HTMLDocument.RunElement) e.getSourceElement();
            Enumeration attNames = el.getAttributeNames();
            while (attNames.hasMoreElements()) {
                Object attName = attNames.nextElement();
                Object attValue = el.getAttribute(attName);
                // custom attributes in SimpleAttributeSet element
                if (attValue instanceof SimpleAttributeSet) {
                    SimpleAttributeSet attReal = (SimpleAttributeSet) attValue;
                    Enumeration attRealNames = attReal.getAttributeNames();
                    while (attRealNames.hasMoreElements()) {
                        Object attRealName = attRealNames.nextElement();
                        Object attRealValue = attReal.getAttribute(attRealName);
                        String name = attRealName.toString();
                        String value = attRealValue.toString();
                        extraData.put(name, value);
                    }
                }
            }
        }
        String cardName = e.getDescription().substring(1);
        String alternativeName = CardUtil.urlDecode(extraData.getOrDefault("alternative_name", ""));
        if (!alternativeName.isEmpty()) {
            cardName = alternativeName;
        }
        if (e.getEventType() == EventType.ENTERED) {
            CardView cardView = null;
            // card
            CardInfo card = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
            if (card != null) {
                cardView = new CardView(card.getMockCard());
            }
            // plane
            if (cardView == null) {
                Plane plane = Plane.createPlaneByFullName(cardName);
                if (plane != null) {
                    cardView = new CardView(new PlaneView(plane));
                }
            }
            if (cardView != null) {
                cardInfo.init(cardView, this.bigCard, this.gameId);
                cardInfo.setTooltipDelay(CHAT_TOOLTIP_DELAY_MS);
                cardInfo.onMouseEntered(MouseInfo.getPointerInfo().getLocation());
                cardInfo.onMouseMoved(MouseInfo.getPointerInfo().getLocation());
            }
        }
        if (e.getEventType() == EventType.EXITED) {
            cardInfo.onMouseExited();
        }
    }));
    addMouseListener(new MouseAdapter() {

        @Override
        public void mouseExited(MouseEvent e) {
            cardInfo.onMouseExited();
        }
    });
}
Also used : Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) Plane(mage.game.command.Plane) HTMLDocument(javax.swing.text.html.HTMLDocument) CardView(mage.view.CardView) MouseAdapter(java.awt.event.MouseAdapter) VirtualCardInfo(mage.client.cards.VirtualCardInfo) CardInfo(mage.cards.repository.CardInfo) PlaneView(mage.view.PlaneView) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with CardView

use of mage.view.CardView in project mage by magefree.

the class TableModel method setNumber.

public void setNumber(int index, int number) {
    CardView card = view.get(index);
    cardEventSource.fireEvent(card, ClientEventType.SET_NUMBER, number);
}
Also used : CardView(mage.view.CardView)

Aggregations

CardView (mage.view.CardView)41 List (java.util.List)15 MageCard (mage.cards.MageCard)10 CardInfo (mage.cards.repository.CardInfo)9 Card (mage.cards.Card)6 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 java.util (java.util)4 BigCard (mage.client.cards.BigCard)4 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)3 GameView (mage.view.GameView)3 PlayerView (mage.view.PlayerView)3 SimpleCardView (mage.view.SimpleCardView)3 Test (org.junit.Test)3 java.awt (java.awt)2 java.awt.event (java.awt.event)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 javax.swing (javax.swing)2