use of mage.view.CardView in project mage by magefree.
the class TableModel method doubleClick.
public void doubleClick(int index, MouseEvent e, boolean forceFakeAltDown) {
CardView card = view.get(index);
cardEventSource.fireEvent(card, ClientEventType.CARD_DOUBLE_CLICK, e, forceFakeAltDown);
}
use of mage.view.CardView 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.view.CardView 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();
}
use of mage.view.CardView in project mage by magefree.
the class PickChoiceDialog method choiceHintShow.
private void choiceHintShow(int modelIndex) {
switch(choice.getHintType()) {
case CARD:
case CARD_DUNGEON:
{
// as popup card
if (lastModelIndex != modelIndex) {
// new card
KeyValueItem item = (KeyValueItem) listChoices.getModel().getElementAt(modelIndex);
String cardName = item.getValue();
if (choice.getHintType() == ChoiceHintType.CARD) {
cardInfo.init(cardName, this.bigCard, this.gameId);
} else if (choice.getHintType() == ChoiceHintType.CARD_DUNGEON) {
CardView cardView = new CardView(new DungeonView(Dungeon.createDungeon(cardName)));
cardInfo.init(cardView, this.bigCard, this.gameId);
}
cardInfo.onMouseEntered(MouseInfo.getPointerInfo().getLocation());
} else {
// old card
cardInfo.onMouseMoved(MouseInfo.getPointerInfo().getLocation());
}
lastModelIndex = modelIndex;
break;
}
default:
case TEXT:
{
// as popup text
if (lastModelIndex != modelIndex) {
// new hint
listChoices.setToolTipText(null);
KeyValueItem item = (KeyValueItem) listChoices.getModel().getElementAt(modelIndex);
listChoices.setToolTipText(item.getValue());
}
lastModelIndex = modelIndex;
break;
}
}
}
use of mage.view.CardView in project mage by magefree.
the class CardIconsTest method test_CostX_Abilities.
@Test
public void test_CostX_Abilities() {
// X icon must be visible only for activated ability, not spell cast
// {X}{R}, {tap}, Sacrifice Cinder Elemental: Cinder Elemental deals X damage to any target.
// {3}{R}
addCard(Zone.HAND, playerA, "Cinder Elemental", 1);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
// hand (not visible)
runCode("card icons in hand", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
GameView gameView = getGameView(player);
Assert.assertEquals("must have 1 card in hand", 1, gameView.getHand().values().size());
CardView cardView = gameView.getHand().values().stream().findFirst().get();
Assert.assertEquals("must have non x cost card icons in hand", 0, cardView.getCardIcons().size());
});
// spell cast
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cinder Elemental");
// stack (spell cast - not visible)
runCode("card icons on stack (spell cast - not visible)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
GameView gameView = getGameView(player);
Assert.assertEquals("must have 1 card in stack", 1, gameView.getStack().values().size());
CardView cardView = gameView.getStack().values().stream().findFirst().get();
Assert.assertEquals("must have not x cost card icons in stack", 0, cardView.getCardIcons().size());
});
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
checkPermanentCount("after cast", 1, PhaseStep.PRECOMBAT_MAIN, playerA, "Cinder Elemental", 1);
// battlefield (card, not visible)
runCode("card icons in battlefield (card)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
GameView gameView = getGameView(player);
PlayerView playerView = gameView.getPlayers().get(0);
Assert.assertEquals("player", player.getName(), playerView.getName());
CardView cardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Cinder Elemental")).findFirst().orElse(null);
Assert.assertNotNull("must have Cinder Elemental in battlefield", cardView);
Assert.assertEquals("must have not x cost card icons in battlefield (card)", 0, cardView.getCardIcons().size());
});
// ACTIVATE ABILITY (x must be visible in stack, but not visible after resolve)
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{X}{R}");
setChoice(playerA, "X=2");
addTarget(playerA, playerB);
// stack (ability activated - visible)
runCode("card icons on stack (ability activated - visible)", 3, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
GameView gameView = getGameView(player);
Assert.assertEquals("ability activated - must have 1 card in stack", 1, gameView.getStack().values().size());
CardView cardView = gameView.getStack().values().stream().findFirst().get();
Assert.assertEquals("ability activated - must have x cost card icons in stack", 1, cardView.getCardIcons().size());
});
// battlefield (ability activated, not visible)
runCode("card icons in battlefield (ability activated)", 1, PhaseStep.PRECOMBAT_MAIN, playerA, (info, player, game) -> {
GameView gameView = getGameView(player);
PlayerView playerView = gameView.getPlayers().get(0);
Assert.assertEquals("player", player.getName(), playerView.getName());
CardView cardView = playerView.getBattlefield().values().stream().filter(p -> p.getName().equals("Cinder Elemental")).findFirst().orElse(null);
Assert.assertNotNull("ability activated - must have Cinder Elemental in battlefield", cardView);
Assert.assertEquals("ability activated - must have not x cost card icons in battlefield", 0, cardView.getCardIcons().size());
});
setStrictChooseMode(true);
setStopAt(3, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
}
Aggregations