Search in sources :

Example 21 with CardView

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

the class SelectionBox method selectByName.

public void selectByName(List<String> cardNames) {
    for (List<List<CardView>> gridRow : cardGrid) {
        for (List<CardView> stack : gridRow) {
            for (CardView card : stack) {
                if (cardNames.contains(card.getName())) {
                    card.setSelected(true);
                    cardViews.get(card.getId()).update(card);
                }
            }
        }
    }
}
Also used : CardView(mage.view.CardView) List(java.util.List)

Example 22 with CardView

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

Example 23 with CardView

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

the class SelectionBox method selectCard.

private void selectCard(CardView targetCard) {
    // Set the selected card to the target card
    for (CardView card : allCards) {
        if (card == targetCard) {
            if (!card.isSelected()) {
                card.setSelected(true);
                cardViews.get(card.getId()).update(card);
            }
        } else if (card.isSelected()) {
            card.setSelected(false);
            cardViews.get(card.getId()).update(card);
        }
    }
}
Also used : CardView(mage.view.CardView)

Example 24 with CardView

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

the class SelectionBox method resort.

// Resort the existing cards based on the current sort
public void resort() {
    // clear grid
    for (List<List<CardView>> gridRow : cardGrid) {
        for (List<CardView> stack : gridRow) {
            stack.clear();
        }
    }
    trimGrid();
    // sort
    allCards.sort(new CardViewNameComparator());
    // re-insert
    for (CardView card : allCards) {
        sortIntoGrid(card);
    }
    trimGrid();
    // Deselect everything
    deselectAll();
    // render new grid
    layoutGrid();
    repaintGrid();
}
Also used : CardView(mage.view.CardView) List(java.util.List)

Example 25 with CardView

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

the class SelectionBox method getCardLayout.

public DeckCardLayout getCardLayout() {
    // 2D Array to put entries into
    List<List<List<DeckCardInfo>>> info = new ArrayList<>();
    for (List<List<CardView>> gridRow : cardGrid) {
        List<List<DeckCardInfo>> row = new ArrayList<>();
        info.add(row);
        for (List<CardView> stack : gridRow) {
            row.add(stack.stream().map(card -> new DeckCardInfo(card.getName(), card.getCardNumber(), card.getExpansionSetCode())).collect(Collectors.toList()));
        }
    }
    // Store layout and settings then return them
    return new DeckCardLayout(info, saveSettings().toString());
}
Also used : DeckCardLayout(mage.cards.decks.DeckCardLayout) DeckCardInfo(mage.cards.decks.DeckCardInfo) CardView(mage.view.CardView) List(java.util.List)

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