use of mage.cards.MageCard in project mage by magefree.
the class CardsList method drawCards.
@Override
public void drawCards(SortSetting sortSetting) {
for (JLabel label : this.countLabels) {
cardArea.remove(label);
}
this.countLabels.clear();
int maxWidth = this.getParent().getWidth();
int numColumns = maxWidth / cardDimension.width;
int curColumn = 0;
int curRow = 0;
int maxRow = 0;
int maxColumn = 0;
CardViewComparator comparator = null;
Map<UUID, MageCard> oldMageCards = mageCards;
mageCards = new LinkedHashMap<>();
// Find card view
for (Map.Entry<UUID, CardView> view : cards.entrySet()) {
UUID uuid = view.getKey();
CardView cardView = view.getValue();
if (oldMageCards.containsKey(uuid)) {
mageCards.put(uuid, oldMageCards.get(uuid));
oldMageCards.remove(uuid);
} else {
mageCards.put(uuid, addCard(cardView, bigCard, gameId));
}
}
// Remove unused cards
for (MageCard card : oldMageCards.values()) {
cardArea.remove(card);
}
if (cards != null && !cards.isEmpty()) {
Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
List<CardView> sortedCards = new ArrayList<>(cards.values());
switch(sortSetting.getSortBy()) {
case NAME:
comparator = new CardViewNameComparator();
break;
case RARITY:
comparator = new CardViewRarityComparator();
break;
case CARD_TYPE:
comparator = new CardViewCardTypeComparator();
break;
case COLOR:
comparator = new CardViewColorComparator();
break;
case COLOR_IDENTITY:
comparator = new CardViewColorIdentityComparator();
break;
case CASTING_COST:
comparator = new CardViewCostComparator();
break;
case UNSORTED:
comparator = new CardViewNoneComparator();
break;
case EDH_POWER_LEVEL:
comparator = new CardViewEDHPowerLevelComparator();
break;
default:
throw new IllegalArgumentException("Error, unknown sort settings in deck editor: " + sortSetting.getSortBy());
}
sortedCards.sort(new CardViewNameComparator());
sortedCards.sort(comparator);
CardView lastCard = null;
JLabel lastCountLabel = null;
for (CardView card : sortedCards) {
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard = card;
// new new count label
lastCountLabel = addNewCountLabel(curColumn);
}
// create new column on different card sorting
if (comparator.compare(card, lastCard) != 0) {
curColumn++;
maxRow = Math.max(maxRow, curRow);
curRow = 0;
// add new count label
lastCountLabel = addNewCountLabel(curColumn);
}
// update last count label stats
String description = comparator.getCategoryName(card);
DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description);
rectangle.setLocation(curColumn * cardDimension.width, curRow * rowHeight + DragCardGrid.COUNT_LABEL_HEIGHT);
setCardBounds(mageCards.get(card.getId()), rectangle);
curRow++;
lastCard = card;
} else {
rectangle.setLocation(curColumn * cardDimension.width, curRow * rowHeight);
setCardBounds(mageCards.get(card.getId()), rectangle);
curColumn++;
if (curColumn == numColumns) {
maxColumn = Math.max(maxColumn, curColumn);
curColumn = 0;
curRow++;
}
}
}
}
maxRow = Math.max(maxRow, curRow);
maxColumn = Math.max(maxColumn, curColumn);
updateCounts();
cardArea.setPreferredSize(new Dimension((maxColumn + 1) * cardDimension.width, cardDimension.height + maxRow * rowHeight));
cardArea.revalidate();
this.revalidate();
this.repaint();
this.setVisible(true);
}
use of mage.cards.MageCard in project mage by magefree.
the class Cards method changeGUISize.
public void changeGUISize() {
setGUISize();
for (MageCard mageCard : cards.values()) {
mageCard.setCardBounds(0, 0, getCardDimension().width, getCardDimension().height);
mageCard.updateArtImage();
mageCard.doLayout();
}
layoutCards();
sizeCards(getCardDimension());
}
use of mage.cards.MageCard in project mage by magefree.
the class Cards method addCard.
private void addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard mageCard = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
mageCard.setCardContainerRef(cardArea);
mageCard.update(card);
if (zone != null) {
mageCard.setZone(zone);
}
cards.put(card.getId(), mageCard);
cardArea.add(mageCard);
definePosition(mageCard);
}
use of mage.cards.MageCard in project mage by magefree.
the class CardArea method setPopupMenu.
public void setPopupMenu(JPopupMenu popupMenu) {
for (Component component : cardArea.getComponents()) {
if (component instanceof MageCard) {
MageCard mageCard = (MageCard) component;
mageCard.setPopupMenu(popupMenu);
}
}
}
use of mage.cards.MageCard in project mage by magefree.
the class CardArea method addCard.
private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
if (card instanceof AbilityView) {
CardView tmp = ((AbilityView) card).getSourceCard();
tmp.overrideRules(card.getRules());
tmp.setIsAbility(true);
tmp.overrideTargets(card.getTargets());
// cross-reference, required for ability picker
tmp.setAbility(card);
card = tmp;
}
CardIconRenderSettings currentIconsRender;
if (this.customRenderMode >= 0) {
// debug
currentIconsRender = new CardIconRenderSettings().withDebugMode(true).withCustomPosition(customCardIconPosition).withCustomOrder(customCardIconOrder).withCustomColor(customCardIconColor).withCustomMaxVisibleCount(customCardIconsMaxVisibleCount).withCustomIconSizePercent(30);
} else {
// default
currentIconsRender = new CardIconRenderSettings();
}
MageCard cardPanel = Plugins.instance.getMageCard(card, bigCard, currentIconsRender, cardDimension, gameId, true, true, customRenderMode != -1 ? customRenderMode : PreferencesDialog.getRenderMode(), customNeedFullPermanentRender);
cardPanel.setCardContainerRef(this);
cardPanel.update(card);
cardPanel.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
cardArea.add(cardPanel);
cardArea.moveToFront(cardPanel);
// new card have same settings as current view
cardPanel.setCardCaptionTopOffset(yCardCaptionOffsetPercent);
cardPanel.showCardTitle();
}
Aggregations