package arcane.ui; import arcane.ui.ScaledImagePanel.MultipassType; import arcane.ui.ScaledImagePanel.ScalingType; import arcane.ui.util.GlowText; import arcane.ui.util.ManaSymbols; import forge.*; //import forge.view.swing.OldGuiNewGame; import javax.swing.*; import java.awt.Color; import java.awt.*; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.util.ArrayList; import java.util.List; /** *
CardPanel class.
* * @author Forge * @version $Id$ */ public class CardPanel extends JPanel implements CardContainer { /** ConstantserialVersionUID=2361907095724263295L */
private static final long serialVersionUID = 2361907095724263295L;
/**
* Constant TAPPED_ANGLE=Math.PI / 2
*/
public static final double TAPPED_ANGLE = Math.PI / 2;
/**
* Constant ASPECT_RATIO=3.5f / 2.5f
*/
public static final float ASPECT_RATIO = 3.5f / 2.5f;
/**
* Constant dragAnimationPanel
*/
public static CardPanel dragAnimationPanel;
/** Constant ROUNDED_CORNER_SIZE=0.1f */
private static final float ROUNDED_CORNER_SIZE = 0.1f;
/** Constant SELECTED_BORDER_SIZE=0.01f */
private static final float SELECTED_BORDER_SIZE = 0.01f;
/** Constant BLACK_BORDER_SIZE=0.03f */
private static final float BLACK_BORDER_SIZE = 0.03f;
/** Constant TEXT_GLOW_SIZE=6 */
private static final int TEXT_GLOW_SIZE = 6;
/** Constant TEXT_GLOW_INTENSITY=3f */
private static final float TEXT_GLOW_INTENSITY = 3f;
/** Constant rotCenterToTopCorner=1.0295630140987000315797369464196f */
private static final float rotCenterToTopCorner = 1.0295630140987000315797369464196f;
/** Constant rotCenterToBottomCorner=0.7071067811865475244008443621048f */
private static final float rotCenterToBottomCorner = 0.7071067811865475244008443621048f;
public Card gameCard;
public CardPanel attachedToPanel;
public ListConstructor for CardPanel.
* * @param newGameCard a {@link forge.Card} object. */ public CardPanel(Card newGameCard) { this.gameCard = newGameCard; setBackground(Color.black); setOpaque(false); titleText = new GlowText(); titleText.setFont(getFont().deriveFont(Font.BOLD, 13f)); titleText.setForeground(Color.white); titleText.setGlow(Color.black, TEXT_GLOW_SIZE, TEXT_GLOW_INTENSITY); titleText.setWrap(true); add(titleText); ptText = new GlowText(); ptText.setFont(getFont().deriveFont(Font.BOLD, 13f)); ptText.setForeground(Color.white); ptText.setGlow(Color.black, TEXT_GLOW_SIZE, TEXT_GLOW_INTENSITY); add(ptText); imagePanel = new ScaledImagePanel(); add(imagePanel); imagePanel.setScaleLarger(true); imagePanel.setScalingType(ScalingType.nearestNeighbor); imagePanel.setScalingBlur(true); imagePanel.setScalingMultiPassType(MultipassType.none); addComponentListener(new ComponentAdapter() { @Override public void componentShown(ComponentEvent e) { setCard(gameCard); } @Override public void componentResized(ComponentEvent e) { setCard(gameCard); } }); setCard(newGameCard); } /** *setImage.
* * @param srcImage a {@link java.awt.Image} object. * @param srcImageBlurred a {@link java.awt.Image} object. * @param srcImageBlurred a {@link java.awt.Image} object. */ private void setImage(Image srcImage, Image srcImageBlurred) { synchronized (imagePanel) { imagePanel.setImage(srcImage, srcImageBlurred); repaint(); for (CardPanel cardPanel : imageLoadListeners) { cardPanel.setImage(srcImage, srcImageBlurred); cardPanel.repaint(); } imageLoadListeners.clear(); } doLayout(); } /** *setImage.
* * @param panel a {@link arcane.ui.CardPanel} object. */ public void setImage(final CardPanel panel) { synchronized (panel.imagePanel) { if (panel.imagePanel.hasImage()) setImage(panel.imagePanel.srcImage, panel.imagePanel.srcImageBlurred); else panel.imageLoadListeners.add(this); } } /** *setScalingType.
* * @param scalingType a {@link arcane.ui.ScaledImagePanel.ScalingType} object. */ public void setScalingType(ScalingType scalingType) { imagePanel.setScalingType(scalingType); } /** *Setter for the field displayEnabled.
isDisplayEnabled.
* * @return a boolean. */ public boolean isDisplayEnabled() { return displayEnabled; } /** *setAnimationPanel.
* * @param isAnimationPanel a boolean. */ public void setAnimationPanel(boolean isAnimationPanel) { this.isAnimationPanel = isAnimationPanel; } /** *setSelected.
* * @param isSelected a boolean. */ public void setSelected(boolean isSelected) { this.isSelected = isSelected; repaint(); } /** *Setter for the field showCastingCost.
doLayout.
* * @since 1.0.15 */ public void doLayout() { int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE); imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); int fontHeight = Math.round(cardHeight * (27f / 680)); boolean showText = !imagePanel.hasImage() || (!isAnimationPanel && fontHeight < 12); titleText.setVisible(showText); ptText.setVisible(showText); int titleX = Math.round(cardWidth * (20f / 480)); int titleY = Math.round(cardHeight * (9f / 680)); titleText.setBounds(cardXOffset + titleX, cardYOffset + titleY, cardWidth - titleX, cardHeight); Dimension ptSize = ptText.getPreferredSize(); ptText.setSize(ptSize.width, ptSize.height); int ptX = Math.round(cardWidth * (420f / 480)) - ptSize.width / 2; int ptY = Math.round(cardHeight * (675f / 680)) - ptSize.height; ptText.setLocation(cardXOffset + ptX - TEXT_GLOW_SIZE / 2, cardYOffset + ptY - TEXT_GLOW_SIZE / 2); if (isAnimationPanel || cardWidth < 200) imagePanel.setScalingType(ScalingType.nearestNeighbor); else imagePanel.setScalingType(ScalingType.bilinear); } /** *toString.
* * @return a {@link java.lang.String} object. */ public String toString() { return gameCard.getName(); } /** *setCardBounds.
* * @param x a int. * @param y a int. * @param width a int. * @param height a int. */ public void setCardBounds(int x, int y, int width, int height) { cardWidth = width; cardHeight = height; int rotCenterX = Math.round(width / 2f); int rotCenterY = height - rotCenterX; int rotCenterToTopCorner = Math.round(width * CardPanel.rotCenterToTopCorner); int rotCenterToBottomCorner = Math.round(width * CardPanel.rotCenterToBottomCorner); int xOffset = rotCenterX - rotCenterToBottomCorner; int yOffset = rotCenterY - rotCenterToTopCorner; cardXOffset = -xOffset; cardYOffset = -yOffset; width = -xOffset + rotCenterX + rotCenterToTopCorner; height = -yOffset + rotCenterY + rotCenterToBottomCorner; setBounds(x + xOffset, y + yOffset, width, height); } /** *repaint.
*/ public void repaint() { Rectangle b = getBounds(); JRootPane rootPane = SwingUtilities.getRootPane(this); if (rootPane == null) return; Point p = SwingUtilities.convertPoint(getParent(), b.x, b.y, rootPane); rootPane.repaint(p.x, p.y, b.width, b.height); } /** *getCardX.
* * @return a int. */ public int getCardX() { return getX() + cardXOffset; } /** *getCardY.
* * @return a int. */ public int getCardY() { return getY() + cardYOffset; } /** *Getter for the field cardWidth.
Getter for the field cardHeight.
getCardLocation.
* * @return a {@link java.awt.Point} object. */ public Point getCardLocation() { Point p = getLocation(); p.x += cardXOffset; p.y += cardYOffset; return p; } /** *setText.
* * @param card a {@link forge.Card} object. */ public void setText(Card card) { if (card == null || !Singletons.getModel().getPreferences().cardOverlay) return; if (card.isFaceDown()) { titleText.setText(""); showCastingCost = false; } else { titleText.setText(card.getName()); showCastingCost = true; } if (card.isCreature() && card.isPlaneswalker()) { ptText.setText(card.getNetAttack() + "/" + card.getNetDefense() + " (" + String.valueOf(card.getCounters(Counters.LOYALTY)) + ")"); } else if (card.isCreature()) { ptText.setText(card.getNetAttack() + "/" + card.getNetDefense()); } else if (card.isPlaneswalker()) { ptText.setText(String.valueOf(card.getCounters(Counters.LOYALTY))); } else { ptText.setText(""); } } /** *getCard.
* * @return a {@link forge.Card} object. */ public Card getCard() { return gameCard; } /** {@inheritDoc} */ public void setCard(Card card) { if (gameCard != null && gameCard.equals(card) && isAnimationPanel && imagePanel.hasImage()) return; this.gameCard = card; if (!isShowing()) return; Insets i = getInsets(); Image image = card == null ? null : ImageCache.getImage(card, getWidth() - i.left - i.right, getHeight() - i.top - i.bottom); if (gameCard != null && Singletons.getModel().getPreferences().cardOverlay) { setText(gameCard); } setImage(image, image); } }