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");
}
}
Aggregations