use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method displayEnlargedCard.
private void displayEnlargedCard(final CardView cardView, final TransferData data) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
ThreadUtils.threadPool3.submit(() -> {
if (cardView == null) {
return;
}
try {
if (enlargedWindowState == EnlargedWindowState.CLOSED) {
return;
}
MageComponents mageComponentCardPreviewContainer;
MageComponents mageComponentCardPreviewPane;
if (cardView.isToRotate()) {
if (enlargedWindowState == EnlargedWindowState.NORMAL) {
hideEnlargedCard();
enlargedWindowState = EnlargedWindowState.ROTATED;
}
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER_ROTATED;
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE_ROTATED;
} else {
if (enlargedWindowState == EnlargedWindowState.ROTATED) {
hideEnlargedCard();
enlargedWindowState = EnlargedWindowState.NORMAL;
}
mageComponentCardPreviewContainer = MageComponents.CARD_PREVIEW_CONTAINER;
mageComponentCardPreviewPane = MageComponents.CARD_PREVIEW_PANE;
}
final Component popupContainer = MageFrame.getUI().getComponent(mageComponentCardPreviewContainer);
Component cardPreviewPane = MageFrame.getUI().getComponent(mageComponentCardPreviewPane);
Component parentComponent = SwingUtilities.getRoot(cardPanel);
if (cardPreviewPane != null && parentComponent != null) {
Point parentPoint = parentComponent.getLocationOnScreen();
data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
Point location = new Point((int) data.getLocationOnScreen().getX() + data.getPopupOffsetX() - 40, (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, cardPreviewPane, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
popupContainer.setVisible(true);
// popup hint mode
Image image = null;
CardView displayCard = cardPanel.getOriginal();
switch(enlargeMode) {
case COPY:
if (cardView instanceof PermanentView) {
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
}
break;
case ALTERNATE:
if (cardView.getAlternateName() != null) {
if (cardView instanceof PermanentView && !cardView.isFlipCard() && !cardView.canTransform() && ((PermanentView) cardView).isCopy()) {
image = ImageCache.getImageOriginal(((PermanentView) cardView).getOriginal());
} else {
image = ImageCache.getImageOriginalAlternateName(cardView);
displayCard = displayCard.getSecondCardFace();
}
}
break;
default:
break;
}
if (image == null) {
image = cardPanel.getImage();
}
// shows the card in the popup Container
displayCardInfo(displayCard, image, (BigCard) cardPreviewPane);
} else {
logger.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());
}
} catch (Exception e) {
logger.warn("Problem dring display of enlarged card", e);
}
});
}
use of mage.cards.MageCard in project mage by magefree.
the class CardsList method cleanUp.
public void cleanUp() {
this.clearCardEventListeners();
if (cards != null) {
cards.clear();
}
if (mainModel != null) {
mainModel.removeTableModelListener(mainTable);
mainModel.clear();
}
if (cardArea != null) {
for (MouseListener ml : cardArea.getMouseListeners()) {
cardArea.removeMouseListener(ml);
}
for (Component comp : cardArea.getComponents()) {
if (comp instanceof MageCard) {
((MageCard) comp).cleanUp();
}
}
cardArea.removeAll();
}
if (mainTable != null) {
for (MouseListener ml : mainTable.getMouseListeners()) {
mainTable.removeMouseListener(ml);
}
}
if (currentView != null) {
currentView.clearCardEventListeners();
}
mageCards.clear();
this.bigCard = null;
}
use of mage.cards.MageCard in project mage by magefree.
the class CardsList method addCard.
private MageCard addCard(CardView card, BigCard bigCard, UUID gameId) {
MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, true, PreferencesDialog.getRenderMode(), true);
cardImg.setCardContainerRef(this);
cardImg.update(card);
// card position calculated on parent call by drawCards
// cardImg.setCardBounds(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
// count label must be on layer 0 for background drawing
cardArea.add(cardImg, (Integer) 10);
return cardImg;
}
use of mage.cards.MageCard in project mage by magefree.
the class Cards method loadCards.
public boolean loadCards(CardsView cardsView, BigCard bigCard, UUID gameId, boolean revertOrder) {
boolean changed = false;
// auto-move scrollbars to the end of the list
boolean moveScrollbar;
if (zone == Zone.HAND) {
// hand moves on new cards only
moveScrollbar = lastLoadedCardsCount != 0 && cardsView.size() > lastLoadedCardsCount;
} else {
// stack moves on any changes (e.g. show current stack object)
moveScrollbar = cardsView.size() != lastLoadedCardsCount;
}
this.lastLoadedCardsCount = cardsView.size();
// remove objects no longer to display
changed = removeOutdatedCards(cardsView);
// Workaround for bug leaving display of objects on the stack (issue #213 https://github.com/magefree/mage/issues/213)
if (cardsView.isEmpty() && countCards() > 0) {
// problem happens with transformable cards
logger.fatal("Card object on the cards panel was not removed");
for (Component comp : cardArea.getComponents()) {
if (comp instanceof MageCard) {
MageCard mageCard = (MageCard) comp;
logger.fatal("MageCard name:" + mageCard.getName() + " toolTiptext:" + mageCard.getToolTipText());
} else {
logger.fatal("Unknown object:" + comp.getName() + " className:" + comp.getClass().getName());
}
cardArea.remove(comp);
}
}
java.util.List<CardView> orderedList = new ArrayList<>();
if (revertOrder) {
// order objects for display
for (CardView card : cardsView.values()) {
orderedList.add(0, card);
}
} else {
orderedList.addAll(cardsView.values());
}
// add objects to the panel
for (CardView card : orderedList) {
if (dontDisplayTapped) {
if (card instanceof PermanentView) {
((PermanentView) card).overrideTapped(false);
}
}
if (card instanceof StackAbilityView) {
// replace ability by original card
CardView tmp = ((StackAbilityView) card).getSourceCard();
// sync settings
tmp.overrideRules(card.getRules());
tmp.setChoosable(card.isChoosable());
tmp.setPlayableStats(card.getPlayableStats().copy());
tmp.setSelected(card.isSelected());
tmp.setIsAbility(true);
tmp.overrideTargets(card.getTargets());
tmp.overrideId(card.getId());
tmp.setAbilityType(card.getAbilityType());
// sync card icons
tmp.getCardIcons().clear();
tmp.getCardIcons().addAll(card.getCardIcons());
card = tmp;
} else {
card.setAbilityType(null);
}
if (!cards.containsKey(card.getId())) {
addCard(card, bigCard, gameId);
changed = true;
}
cards.get(card.getId()).update(card);
}
if (changed) {
layoutCards();
}
if (!isVisibleIfEmpty) {
cardArea.setVisible(!cards.isEmpty());
}
sizeCards(getCardDimension());
this.revalidate();
this.repaint();
// auto-scroll (must use it at the end)
if (changed && moveScrollbar) {
SwingUtilities.invokeLater(() -> {
if (jScrollPane1 != null) {
jScrollPane1.getHorizontalScrollBar().setValue(jScrollPane1.getHorizontalScrollBar().getMaximum());
}
if (parentScrollPane != null) {
parentScrollPane.getHorizontalScrollBar().setValue(parentScrollPane.getHorizontalScrollBar().getMaximum());
}
});
}
return changed;
}
use of mage.cards.MageCard in project mage by magefree.
the class CardPanelTypeComparator method drawCards.
@Override
public void drawCards(SortSetting sortSetting) {
this.countLabels.forEach(this::remove);
this.countLabels.clear();
int maxWidth = this.getParent().getWidth();
int vertOffsetPerCardInStack = GUISizeHelper.editorCardVertOffsetInStack;
int numColumns = maxWidth / cardDimension.width;
int curColumn = 0;
int curRow = 0;
if (!cards.isEmpty()) {
Rectangle rectangle = new Rectangle(cardDimension.width, cardDimension.height);
List<CardView> sortedCards = cards.values().stream().map(MageCard::getOriginal).collect(Collectors.toList());
CardViewComparator comparator;
switch(sortSetting.getSortBy()) {
case NAME:
comparator = new CardViewNameComparator();
break;
case CARD_TYPE:
comparator = new CardViewCardTypeComparator();
break;
case RARITY:
comparator = new CardViewRarityComparator();
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);
MageCard lastCard = null;
JLabel lastCountLabel = null;
for (CardView sortedCard : sortedCards) {
MageCard currentCard = this.cards.get(sortedCard.getId());
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard = currentCard;
// new new count label
lastCountLabel = addNewCountLabel(curColumn);
}
// create new column on different card sorting
if (comparator.compare(currentCard.getOriginal(), lastCard.getOriginal()) != 0) {
curColumn++;
curRow = 0;
// add new count label
lastCountLabel = addNewCountLabel(curColumn);
}
// update last count label stats
String description = comparator.getCategoryName(currentCard.getOriginal());
DragCardGrid.updateCountLabel(lastCountLabel, curRow + 1, description);
rectangle.setLocation(curColumn * cardDimension.width, curRow * vertOffsetPerCardInStack + DragCardGrid.COUNT_LABEL_HEIGHT);
currentCard.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
moveToFront(currentCard);
curRow++;
lastCard = currentCard;
} else {
rectangle.setLocation(curColumn * cardDimension.width, curRow * vertOffsetPerCardInStack);
currentCard.setCardBounds(rectangle.x, rectangle.y, cardDimension.width, cardDimension.height);
moveToFront(currentCard);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
}
resizeArea();
revalidate();
repaint();
}
Aggregations