use of mage.cards.MageCard in project mage by magefree.
the class ArrowUtil method drawArrowsForTargets.
public static void drawArrowsForTargets(TransferData data, Point parentPoint) {
java.util.List<UUID> targets = data.getCard().getTargets();
if (targets == null) {
return;
}
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
for (UUID uuid : targets) {
PlayAreaPanel p = MageFrame.getGamePlayers(data.getGameId()).get(uuid);
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() - 40, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
for (PlayAreaPanel panel : MageFrame.getGamePlayers(data.getGameId()).values()) {
MageCard permanent = panel.getBattlefieldPanel().getPermanentPanels().get(uuid);
if (permanent != null) {
Point target = permanent.getCardLocationOnScreen().getCardPoint();
target.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red, ArrowBuilder.Type.TARGET);
continue;
}
PlayerView view = panel.getPlayerPanel().getPlayer();
if (view != null) {
CardsView graveyard = view.getGraveyard();
if (graveyard.containsKey(uuid)) {
p = MageFrame.getGamePlayers(data.getGameId()).get(view.getPlayerId());
if (p != null) {
Point target = p.getLocationOnScreen();
target.translate(-parentPoint.x, -parentPoint.y);
int yOffset = p.isSmallMode() ? (PlayAreaPanel.PANEL_HEIGHT - PlayAreaPanel.PANEL_HEIGHT_SMALL) : 0;
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 15, (int) target.getY() + 145 - yOffset, Color.red, ArrowBuilder.Type.TARGET);
}
}
}
}
}
}
use of mage.cards.MageCard in project mage by magefree.
the class Cards method layoutCards.
private void layoutCards() {
// get all the card panels
java.util.List<MageCard> cardsToLayout = new ArrayList<>();
for (Component component : cardArea.getComponents()) {
if (component instanceof MageCard) {
cardsToLayout.add((MageCard) component);
}
}
// WARNING, must be same sort code as MageActionCallback->sortLayout (if not then hand cards will be messed after drag)
// sort the cards
cardsToLayout.sort(Comparator.comparingInt(cp -> cp.getCardLocation().getCardX()));
// relocate the cards (support only horizontal style: hand and stack panels)
// TODO: add shrinking of cards list for too big amount (cards will be overlapped, use MageActionCallback.HAND_CARDS_BETWEEN_GAP_X to control it)
// starting position
int dx = MageActionCallback.getHandOrStackBetweenGapX(zone);
for (MageCard component : cardsToLayout) {
component.setCardLocation(dx, component.getCardLocation().getCardY());
dx += component.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(zone);
}
}
use of mage.cards.MageCard in project mage by magefree.
the class Cards method definePosition.
private void definePosition(MageCard newCard) {
// starting position
int dx = MageActionCallback.getHandOrStackMargins(zone).getLeft();
// search last card's position
for (Component currentComp : cardArea.getComponents()) {
if (!currentComp.equals(newCard) && currentComp instanceof MageCard) {
MageCard currentCard = (MageCard) currentComp;
dx = Math.max(dx, currentCard.getCardLocation().getCardX());
}
}
// Y position sets here one time only (all sorting and drag manipulations works with X)
// add card to the end
dx += newCard.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(newCard.getZone());
newCard.setCardLocation(dx, MageActionCallback.getHandOrStackMargins(newCard.getZone()).getTop());
}
use of mage.cards.MageCard in project mage by magefree.
the class SelectionBox method addCardView.
public void addCardView(final CardView card, boolean duplicated) {
allCards.add(card);
// Update counts
for (CardTypeCounter counter : allCounters) {
counter.add(card);
}
updateCounts();
// Create the card view
final MageCard cardPanel = Plugins.instance.getMageCard(card, lastBigCard, new CardIconRenderSettings(), new Dimension(getCardWidth(), getCardHeight()), null, true, true, PreferencesDialog.getRenderMode(), true);
cardPanel.setCardContainerRef(this);
cardPanel.update(card);
// cards bounds set in layoutGrid()
cardPanel.setCardCaptionTopOffset(0);
// ENABLE DRAG SUPPORT FOR CARDS
// TODO: rewrite mouseDragged in MageActionCallback, so it can support any drags, not hands only
cardPanel.addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
if (!dragger.isDragging()) {
// If the card isn't already selected, make sure it is
if (!card.isSelected()) {
selectCard(card);
}
dragger.handleDragStart(cardPanel, e);
}
}
});
// And add it
cardContent.add(cardPanel);
cardViews.put(card.getId(), cardPanel);
if (duplicated) {
sortIntoGrid(card);
eventSource.fireEvent(card, ClientEventType.DECK_ADD_SPECIFIC_CARD);
// clear grid from empty rows
trimGrid();
// Update layout
layoutGrid();
repaintGrid();
}
}
use of mage.cards.MageCard in project mage by magefree.
the class SelectionBox method updateSelectionDrag.
private void updateSelectionDrag(int x, int y) {
// Coords
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
int x1 = Math.min(x, selectionDragStartX);
int x2 = Math.max(x, selectionDragStartX);
int y1 = Math.min(y, selectionDragStartY);
int y2 = Math.max(y, selectionDragStartY);
// Update selection panel size
selectionPanel.setLocation(x1, y1);
selectionPanel.setSize(x2 - x1, y2 - y1);
// First and last cols
int col1 = x1 / (cardWidth + GRID_PADDING);
int col2 = x2 / (cardWidth + GRID_PADDING);
int offsetIntoCol2 = x2 % (cardWidth + GRID_PADDING);
if (offsetIntoCol2 < GRID_PADDING) {
--col2;
}
int curY = COUNT_LABEL_HEIGHT;
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
int stackStartIndex;
if (y1 < curY) {
stackStartIndex = 0;
} else {
stackStartIndex = (y1 - curY) / cardTopHeight;
}
int stackEndIndex;
if (y2 < curY) {
stackEndIndex = -1;
} else {
stackEndIndex = (y2 - curY) / cardTopHeight;
}
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
for (int col = 0; col < gridRow.size(); ++col) {
List<CardView> stack = gridRow.get(col);
int stackBottomBegin = curY + cardTopHeight * (stack.size());
int stackBottomEnd = curY + cardTopHeight * (stack.size() - 1) + cardHeight;
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
MageCard view = cardViews.get(card.getId());
boolean inBoundsX = (col >= col1 && col <= col2);
boolean inBoundsY = (i >= stackStartIndex && i <= stackEndIndex);
boolean lastCard = (i == stack.size() - 1);
boolean inSeletionDrag = inBoundsX && (inBoundsY || (lastCard && (y2 >= stackBottomBegin && y1 <= stackBottomEnd)));
if (inSeletionDrag || selectionDragStartCards != null && selectionDragStartCards.contains(card)) {
if (!card.isSelected()) {
card.setSelected(true);
view.update(card);
}
} else if (card.isSelected()) {
card.setSelected(false);
view.update(card);
}
}
}
curY += cardTopHeight * (maxStackSize.get(rowIndex) - 1) + cardHeight + COUNT_LABEL_HEIGHT;
}
}
Aggregations