Search in sources :

Example 46 with MageCard

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();
}
Also used : MageCard(mage.cards.MageCard)

Example 47 with MageCard

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);
}
Also used : java.util(java.util) MageCard(mage.cards.MageCard)

Example 48 with MageCard

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());
        }
    }
}
Also used : java.util(java.util) PermanentView(mage.view.PermanentView) ScheduledFuture(java.util.concurrent.ScheduledFuture) Zone(mage.constants.Zone) MageFrame(mage.client.MageFrame) MagePane(mage.client.MagePane) CardEventProducer(mage.client.cards.CardEventProducer) ActionCallback(mage.cards.action.ActionCallback) Logger(org.apache.log4j.Logger) ClientEventType(mage.client.util.ClientEventType) ArrowUtil(mage.client.util.gui.ArrowUtil) ThreadUtils(mage.utils.ThreadUtils) MouseWheelEvent(java.awt.event.MouseWheelEvent) TransferData(mage.cards.action.TransferData) CardInfoPane(mage.components.CardInfoPane) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MageCard(mage.cards.MageCard) MageCardSpace(mage.cards.MageCardSpace) GamePane(mage.client.game.GamePane) ArrowBuilder(mage.client.util.gui.ArrowBuilder) SessionHandler(mage.client.SessionHandler) MageComponents(mage.client.components.MageComponents) DefaultActionCallback(mage.client.util.DefaultActionCallback) ImageCache(org.mage.plugins.card.images.ImageCache) BufferedImage(java.awt.image.BufferedImage) GuiDisplayUtil(mage.client.util.gui.GuiDisplayUtil) MouseEvent(java.awt.event.MouseEvent) Executors(java.util.concurrent.Executors) JXPanel(org.jdesktop.swingx.JXPanel) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) List(java.util.List) BigCard(mage.client.cards.BigCard) EnlargeMode(mage.constants.EnlargeMode) CardView(mage.view.CardView) javax.swing(javax.swing) MageCard(mage.cards.MageCard)

Example 49 with MageCard

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;
    }
}
Also used : MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 50 with MageCard

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);
        }
    }
}
Also used : PlayableObjectStats(mage.players.PlayableObjectStats) MageCard(mage.cards.MageCard)

Aggregations

MageCard (mage.cards.MageCard)50 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)12 CardView (mage.view.CardView)10 UUID (java.util.UUID)6 java.util (java.util)5 PermanentView (mage.view.PermanentView)5 List (java.util.List)4 MagePermanent (mage.cards.MagePermanent)4 PlayAreaPanel (mage.client.game.PlayAreaPanel)4 java.awt (java.awt)3 BufferedImage (java.awt.image.BufferedImage)3 javax.swing (javax.swing)3 PreferencesDialog (mage.client.dialog.PreferencesDialog)3 Plugins (mage.client.plugins.impl.Plugins)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 MagePane (mage.client.MagePane)2 MageComponents (mage.client.components.MageComponents)2 GamePane (mage.client.game.GamePane)2