use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method mousePressed.
@Override
public void mousePressed(MouseEvent e, TransferData data) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
cardPanel.requestFocusInWindow();
// for some reason sometime mouseRelease happens before numerous Mouse_Dragged events
// that results in not finished dragging
clearDragging(this.prevCardPanel);
isDragging = false;
startedDragging = false;
prevCardPanel = null;
draggingCards.clear();
Point mouse = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(mouse, data.getComponent());
initialMousePos = new Point((int) mouse.getX(), (int) mouse.getY());
initialCardPos = cardPanel.getCardLocation().getCardPoint();
// Closes popup & enlarged view if a card/Permanent is selected
hideTooltipPopup();
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method sortHandCards.
private void sortHandCards(MageCard card, Container container, boolean sortSource) {
java.util.List<MageCard> cards = new ArrayList<>();
// distribute cards between cards container and a drag container
for (Component comp : container.getComponents()) {
if (comp instanceof MageCard) {
MageCard realCard = (MageCard) comp;
if (!realCard.equals(card)) {
if (!draggingCards.contains(realCard)) {
realCard.setCardLocation(realCard.getCardLocation().getCardX(), realCard.getCardLocation().getCardY() + GO_DOWN_ON_DRAG_Y_OFFSET);
}
draggingCards.add(realCard);
} else if (!startedDragging) {
realCard.setCardLocation(realCard.getCardLocation().getCardX(), realCard.getCardLocation().getCardY() - GO_DOWN_ON_DRAG_Y_OFFSET);
}
cards.add(realCard);
}
}
sortAndAnimateDraggingHandCards(cards, card, sortSource);
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method sortAndAnimateDraggingHandCards.
private void sortAndAnimateDraggingHandCards(List<MageCard> cards, MageCard source, boolean includeSource) {
// special offset, allows to switch with first card
source.setCardLocation(source.getCardLocation().getCardX() - HAND_CARDS_COMPARE_GAP_X, source.getCardLocation().getCardY());
// sorting card components, so the effect above will be applied too
cards.sort(Comparator.comparingInt(cp -> cp.getCardLocation().getCardX()));
// WARNING, must be same sort code as Cards->layoutCards (if not then hand cards will be messed after drag)
// starting position
int dx = MageActionCallback.getHandOrStackMargins(source.getZone()).getLeft();
boolean createdGapForSource = false;
for (MageCard component : cards) {
// use real component locations, not a card's
if (!includeSource) {
// create special hole between cards to put dragging card into it
if (!component.equals(source)) {
component.setCardLocation(dx, component.getCardLocation().getCardY());
dx += component.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(source.getZone());
// but only once
if (!createdGapForSource && (dx + HAND_CARDS_COMPARE_GAP_X) > source.getCardLocation().getCardX()) {
createdGapForSource = true;
int gapOffset = component.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(source.getZone());
dx += gapOffset;
// workaround to apply gap on the first card (if you drag over first card)
if (cards.get(0).equals(source) && cards.size() > 1 && cards.get(1).equals(component)) {
component.setCardLocation(component.getCardLocation().getCardX() + gapOffset, component.getCardLocation().getCardY());
}
}
}
} else {
component.setCardLocation(dx, component.getCardLocation().getCardY());
dx += component.getCardLocation().getCardWidth() + MageActionCallback.getHandOrStackBetweenGapX(source.getZone());
}
}
}
use of mage.cards.MageCard in project mage by magefree.
the class BattlefieldPanel method addPermanent.
private void addPermanent(PermanentView permanent, final int count) {
if (cardDimension == null) {
cardDimension = new Dimension(ClientDefaultSettings.dimensions.getFrameWidth(), ClientDefaultSettings.dimensions.getFrameHeight());
}
final MageCard perm = Plugins.instance.getMagePermanent(permanent, bigCard, new CardIconRenderSettings(), cardDimension, gameId, true, PreferencesDialog.getRenderMode(), true);
perm.setCardContainerRef(jPanel);
perm.update(permanent);
// cards sizes changes in parent call by sortLayout
// perm.setCardBounds
permanents.put(permanent.getId(), perm);
this.jPanel.add(perm, (Integer) 10);
moveToFront(jPanel);
Plugins.instance.onAddCard(perm, 1);
if (permanent.isArtifact()) {
addedArtifact = true;
} else if (permanent.isCreature()) {
addedCreature = true;
} else {
addedPermanent = true;
}
}
use of mage.cards.MageCard in project mage by magefree.
the class ReplayTask method prepareSelectableWindows.
private void prepareSelectableWindows(Collection<CardInfoWindowDialog> windows, Set<UUID> needSelectable, List<UUID> needChoosen, PlayableObjectsList needPlayable) {
// so it must be updated manually (it's ok to keep outdated cards in dialog, but not ok to show wrong selections)
for (CardInfoWindowDialog window : windows) {
for (MageCard mageCard : window.getMageCardsForUpdate().values()) {
CardView cardView = mageCard.getOriginal();
cardView.setChoosable(needSelectable.contains(cardView.getId()));
cardView.setSelected(needChoosen.contains(cardView.getId()));
if (needPlayable.containsObject(cardView.getId())) {
cardView.setPlayableStats(needPlayable.getStats(cardView.getId()));
} else {
cardView.setPlayableStats(new PlayableObjectStats());
}
// TODO: little bug with toggled night card after update/clicks, but that's ok (can't click on second side)
mageCard.update(cardView);
}
}
}
Aggregations