use of mage.cards.MageCard in project mage by magefree.
the class CardPanelTypeComparator method loadCards.
@Override
public void loadCards(CardsView showCards, SortSetting sortSetting, BigCard bigCard, UUID gameId, boolean merge) {
boolean drawImage = showCards.size() <= MAX_IMAGES;
this.bigCard = bigCard;
this.gameId = gameId;
if (merge) {
for (CardView card : showCards.values()) {
if (!cards.containsKey(card.getId())) {
addCard(card, bigCard, gameId, drawImage);
}
}
for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext(); ) {
Entry<UUID, MageCard> entry = i.next();
if (!showCards.containsKey(entry.getKey())) {
removeCardImg(entry.getKey());
i.remove();
}
}
} else {
this.clearCards();
for (CardView card : showCards.values()) {
addCard(card, bigCard, gameId, drawImage);
}
}
drawCards(sortSetting);
this.setVisible(true);
}
use of mage.cards.MageCard in project mage by magefree.
the class CardPanelTypeComparator method clearCards.
private void clearCards() {
// remove possible mouse listeners, preventing gc
for (MageCard mageCard : cards.values()) {
mageCard.cleanUp();
}
this.cards.clear();
removeAllCardImg();
}
use of mage.cards.MageCard in project mage by magefree.
the class ChoiceDialog method displayCards.
private void displayCards(CardsView cards, UUID gameId, BigCard bigCard) {
if (cards.isEmpty()) {
return;
}
java.util.List<Component> toRemove = new ArrayList<>();
for (int i = getComponentCount() - 1; i > 0; i--) {
Component o = getComponent(i);
if (o instanceof MageCard) {
toRemove.add(o);
}
}
for (Component aToRemove : toRemove) {
remove(aToRemove);
}
java.util.List<CardView> cardList = new ArrayList<>(cards.values());
int width = SettingsManager.instance.getCardSize().width;
int height = SettingsManager.instance.getCardSize().height;
int dx = 0;
int dy = 30;
int startIndex = (page - 1) * (in_a_row * rows);
int countPerPage = (in_a_row * rows);
int j = 0;
for (int i = startIndex; i < cards.size() && i < startIndex + countPerPage; i++) {
if (i > startIndex && i % in_a_row == 0) {
// next row
j++;
dx = 0;
}
CardView card = cardList.get(i);
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.setCardContainerRef(this);
cardImg.update(card);
cardImg.setCardBounds(dx, dy + j * (height + 30), width, height);
this.add(cardImg);
dx += (width + 20);
}
repaint();
}
use of mage.cards.MageCard in project mage by magefree.
the class CardLayoutStrategyImpl method groupAttachments.
private void groupAttachments(BattlefieldPanel battlefieldPanel, JLayeredPane mainPanel, Map<UUID, MageCard> cards, PermanentView permanentWithAttachmentsView) {
MageCard cardWithAttachments = cards.get(permanentWithAttachmentsView.getId());
if (cardWithAttachments == null) {
return;
}
// calculate how many vertical columns are needed and number of attachements
AttachmentLayoutInfos attachmentLayoutInfos = calculateNeededNumberOfVerticalColumns(0, battlefieldPanel, cards, permanentWithAttachmentsView);
// group by columns
layoutAttachements(cardWithAttachments.getCardLocation().getCardX(), attachmentLayoutInfos.getColumns(), attachmentLayoutInfos.getAttachments(), permanentWithAttachmentsView, cards, battlefieldPanel, mainPanel, cardWithAttachments.getCardLocation().getCardBounds());
mainPanel.setComponentZOrder(cardWithAttachments, 0);
}
use of mage.cards.MageCard in project mage by magefree.
the class CardLayoutStrategyImpl method layoutAttachements.
private void layoutAttachements(int startingCardX, int maxColumnLevels, int ZOrder, PermanentView permanentWithAttachmentsView, Map<UUID, MageCard> cards, BattlefieldPanel battlefieldPanel, JLayeredPane mainPanel, Rectangle lastAttachmentRect) {
// put attachments to the next level (take lastAttachmentRect and apply offsets)
MageCard cardWithAttachments = cards.get(permanentWithAttachmentsView.getId());
if (cardWithAttachments == null) {
return;
}
// from right to left [2][1][0]
int col = getVerticalCul(permanentWithAttachmentsView, battlefieldPanel);
int currentAttachmentCol = col + 1;
cardWithAttachments.getLinks().clear();
int verticalIndex = permanentWithAttachmentsView.getAttachments().size();
for (UUID attachmentId : permanentWithAttachmentsView.getAttachments()) {
// put child attachments of the attachment
PermanentView attachedPermanentView = battlefieldPanel.getBattlefield().get(attachmentId);
if (attachedPermanentView != null && attachedPermanentView.getAttachments() != null && !attachedPermanentView.getAttachments().isEmpty()) {
layoutAttachements(startingCardX, maxColumnLevels, ZOrder, attachedPermanentView, cards, battlefieldPanel, mainPanel, lastAttachmentRect);
}
// put attachment
MageCard attachedCard = cards.get(attachmentId);
if (attachedCard != null) {
// x position
Point point = new Point();
point.setLocation(startingCardX + (maxColumnLevels - currentAttachmentCol) * Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), lastAttachmentRect.getY());
lastAttachmentRect.setLocation(point);
// set position first to the same as of the permanent it is attached to
attachedCard.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
// y position
cardWithAttachments.getLinks().add(attachedCard);
int dyOffset = Math.max(cardWithAttachments.getCardLocation().getCardHeight() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_SINGLE_Y);
if (verticalIndex == 1) {
lastAttachmentRect.translate(Math.max(cardWithAttachments.getCardLocation().getCardWidth() / ATTACHMENTS_MAX_COLUMNS, ATTACHMENTS_OFFSET_ALL_X), dyOffset);
} else {
lastAttachmentRect.translate(0, dyOffset);
}
cardWithAttachments.setCardLocation(lastAttachmentRect.x, lastAttachmentRect.y);
battlefieldPanel.moveToFront(attachedCard);
battlefieldPanel.moveToFront(cardWithAttachments);
mainPanel.setComponentZOrder(attachedCard, ZOrder--);
verticalIndex--;
}
}
}
Aggregations