Search in sources :

Example 41 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class MageActionCallback method clearDragging.

private void clearDragging(MageCard clearCard) {
    if (this.startedDragging && prevCardPanel != null && clearCard != null) {
        // distribute cards between cards container and a drag container
        for (Component comp : clearCard.getCardContainer().getComponents()) {
            if (comp instanceof MageCard) {
                MageCard realCard = (MageCard) comp;
                if (draggingCards.contains(realCard)) {
                    realCard.setCardLocation(realCard.getCardLocation().getCardX(), realCard.getCardLocation().getCardY() - GO_DOWN_ON_DRAG_Y_OFFSET);
                }
            }
        }
        clearCard.setCardLocation(clearCard.getCardLocation().getCardX(), clearCard.getCardLocation().getCardY() + GO_UP_ON_DRAG_Y_OFFSET);
        sortHandCards(clearCard, clearCard.getCardContainer(), true);
        draggingCards.clear();
    }
    prevCardPanel = null;
}
Also used : MageCard(mage.cards.MageCard)

Example 42 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class MageActionCallback method mouseDragged.

@Override
public void mouseDragged(MouseEvent e, TransferData data) {
    // start the dragging
    MageCard cardPanel = data.getComponent().getTopPanelRef();
    if (cardPanel.getZone() != Zone.HAND) {
        // drag'n'drop is allowed for HAND zone only
        return;
    }
    if (!SwingUtilities.isLeftMouseButton(e)) {
        // only allow draging with the left mouse button
        return;
    }
    isDragging = true;
    prevCardPanel = cardPanel;
    Point cardPanelLocationOld = cardPanel.getCardLocation().getCardPoint();
    Point mouse = new Point(e.getX(), e.getY());
    SwingUtilities.convertPointToScreen(mouse, data.getComponent());
    // starting position
    int xOffset = 0;
    // TODO: fix
    int newX = Math.max(initialCardPos.x + (int) (mouse.getX() - initialMousePos.x) - xOffset, 0);
    cardPanel.setCardBounds(newX, cardPanelLocationOld.y, cardPanel.getCardLocation().getCardWidth(), cardPanel.getCardLocation().getCardHeight());
    cardPanel.getCardContainer().setComponentZOrder(cardPanel, 0);
    sortHandCards(cardPanel, cardPanel.getCardContainer(), false);
    if (!this.startedDragging) {
        this.startedDragging = true;
    }
}
Also used : MageCard(mage.cards.MageCard)

Example 43 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class MageActionCallback method startCardHintPopup.

private void startCardHintPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
    MageCard cardPanel = data.getComponent().getTopPanelRef();
    if (data.getTooltipDelay() > 0) {
        // custom tooltip
        tooltipDelay = data.getTooltipDelay();
    } else {
        // from preferences
        tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300);
    }
    if (tooltipDelay == 0) {
        // disabled
        return;
    }
    if (cardInfoPane == null) {
        // create new popup
        if (data.getLocationOnScreen() == null) {
            data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
        }
        PopupFactory factory = PopupFactory.getSharedInstance();
        data.getPopupText().updateText();
        tooltipPopup = factory.getPopup(cardPanel, data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
        tooltipPopup.show();
        // hack to get popup to resize to fit text
        tooltipPopup.hide();
        tooltipPopup = factory.getPopup(cardPanel, data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
        tooltipPopup.show();
    } else {
        showCardHintPopup(data, parentComponent, parentPoint);
    }
}
Also used : MageCard(mage.cards.MageCard)

Example 44 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class MageActionCallback method handleMouseMoveOverNewCard.

private void handleMouseMoveOverNewCard(TransferData data) {
    MageCard cardPanel = data.getComponent().getTopPanelRef();
    // Prevent to show tooltips from panes not in front
    MagePane topPane = MageFrame.getTopMost(null);
    if (topPane instanceof GamePane) {
        if (data.getGameId() != null && !((GamePane) topPane).getGameId().equals(data.getGameId())) {
            return;
        }
    }
    hideTooltipPopup();
    cancelTimeout();
    Component parentComponent = SwingUtilities.getRoot(cardPanel);
    if (parentComponent == null) {
        // virtual card (example: show card popup in non cards panel like PickChoiceDialog)
        parentComponent = MageFrame.getDesktop();
    }
    Point parentPoint = parentComponent.getLocationOnScreen();
    if (data.getLocationOnScreen() == null) {
        data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
    }
    ArrowUtil.drawArrowsForTargets(data, parentPoint);
    ArrowUtil.drawArrowsForSource(data, parentPoint);
    ArrowUtil.drawArrowsForPairedCards(data, parentPoint);
    ArrowUtil.drawArrowsForBandedCards(data, parentPoint);
    ArrowUtil.drawArrowsForEnchantPlayers(data, parentPoint);
    tooltipCard = data.getCard();
    startCardHintPopup(data, parentComponent, parentPoint);
}
Also used : MagePane(mage.client.MagePane) MageCard(mage.cards.MageCard) GamePane(mage.client.game.GamePane)

Example 45 with MageCard

use of mage.cards.MageCard in project mage by magefree.

the class MageActionCallback method showCardHintPopup.

private void showCardHintPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
    MageCard cardPanel = data.getComponent().getTopPanelRef();
    ThreadUtils.threadPool2.submit(new Runnable() {

        @Override
        public void run() {
            ThreadUtils.sleep(tooltipDelay);
            if (tooltipCard == null || !tooltipCard.equals(data.getCard()) || SessionHandler.getSession() == null || !popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) {
                return;
            }
            try {
                final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
                Component popupInfo = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
                ((CardInfoPane) popupInfo).setCard(data.getCard(), popupContainer);
                showPopup(popupContainer, popupInfo);
            } catch (InterruptedException e) {
                logger.error("Can't show card tooltip", e);
                Thread.currentThread().interrupt();
            }
        }

        public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException {
            final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
            SwingUtilities.invokeLater(() -> {
                if (!popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) {
                    return;
                }
                if (data.getLocationOnScreen() == null) {
                    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, infoPane, parentComponent);
                location.translate(-parentPoint.x, -parentPoint.y);
                popupContainer.setLocation(location);
                popupContainer.setVisible(true);
                c.repaint();
            });
        }
    });
}
Also used : 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