Search in sources :

Example 1 with CardViewRarityComparator

use of mage.client.util.comparators.CardViewRarityComparator 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)

Aggregations

ArrayList (java.util.ArrayList)1 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)1 CardDimensions (mage.cards.CardDimensions)1 MageCard (mage.cards.MageCard)1 CardViewRarityComparator (mage.client.util.comparators.CardViewRarityComparator)1 CardView (mage.view.CardView)1