Search in sources :

Example 1 with MageComponents

use of mage.client.components.MageComponents 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);
        }
    });
}
Also used : CardView(mage.view.CardView) PermanentView(mage.view.PermanentView) MageCard(mage.cards.MageCard) BufferedImage(java.awt.image.BufferedImage) MageComponents(mage.client.components.MageComponents)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1 MageCard (mage.cards.MageCard)1 MageComponents (mage.client.components.MageComponents)1 CardView (mage.view.CardView)1 PermanentView (mage.view.PermanentView)1