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