[card.plugin] Added sickness image. At the moment there is no way to determine whether permanent has sickness on client - so for a while all creatures will ALWAYS have sickness image displayed.

This commit is contained in:
magenoxx 2010-11-27 16:17:01 +00:00
parent 03cb41f2aa
commit e36d4e57e1
7 changed files with 236 additions and 20 deletions

View file

@ -62,7 +62,7 @@ public class ArrowBuilder {
arrow.setColor(color); arrow.setColor(color);
arrow.setArrowLocation(startX, startY, endX, endY); arrow.setArrowLocation(startX, startY, endX, endY);
arrow.setBounds(0, 0, Math.max(startX, endX) + 30, Math.max(startY, endY) + 30); // 30 is offset for arrow heads (being cut otherwise) arrow.setBounds(0, 0, Math.max(startX, endX) + 30, Math.max(startY, endY) + 30); // 30 is offset for arrow heads (being cut otherwise)
System.out.println(" Adding arrow (startX=" + startX + ", startY=" + startY +", endX=" + endX + ", endY=" + endY + ")"); //System.out.println(" Adding arrow (startX=" + startX + ", startY=" + startY +", endX=" + endX + ", endY=" + endY + ")");
p.add(arrow); p.add(arrow);
p.revalidate(); p.revalidate();
p.repaint(); p.repaint();

View file

@ -37,6 +37,9 @@ import org.apache.log4j.Logger;
import org.mage.card.arcane.ScaledImagePanel.MultipassType; import org.mage.card.arcane.ScaledImagePanel.MultipassType;
import org.mage.card.arcane.ScaledImagePanel.ScalingType; import org.mage.card.arcane.ScaledImagePanel.ScalingType;
import org.mage.plugins.card.images.ImageCache; import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.BufferedImageBuilder;
import org.mage.plugins.card.utils.ImagePanel;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
@SuppressWarnings({"unchecked","rawtypes"}) @SuppressWarnings({"unchecked","rawtypes"})
@ -68,7 +71,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public List<CardPanel> attachedPanels = new ArrayList(); public List<CardPanel> attachedPanels = new ArrayList();
public double tappedAngle = 0; public double tappedAngle = 0;
public ScaledImagePanel imagePanel; public ScaledImagePanel imagePanel;
public ScaledImagePanel overlayPanel; public ImagePanel overlayPanel;
private GlowText titleText; private GlowText titleText;
private GlowText ptText; private GlowText ptText;
@ -90,6 +93,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private TransferData data = new TransferData(); private TransferData data = new TransferData();
private boolean isPermanent; private boolean isPermanent;
private boolean hasSickness = true;
public CardPanel(CardView newGameCard, UUID gameId, boolean loadImage, ActionCallback callback) { public CardPanel(CardView newGameCard, UUID gameId, boolean loadImage, ActionCallback callback) {
this.gameCard = newGameCard; this.gameCard = newGameCard;
@ -129,17 +133,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
ptText.setGlow(Color.black, TEXT_GLOW_SIZE, TEXT_GLOW_INTENSITY); ptText.setGlow(Color.black, TEXT_GLOW_SIZE, TEXT_GLOW_INTENSITY);
add(ptText); add(ptText);
overlayPanel = new ScaledImagePanel(); BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage();
overlayPanel.setBorder(BorderFactory.createLineBorder(Color.white)); overlayPanel = new ImagePanel(sickness, ImagePanel.SCALED);
overlayPanel.setOpaque(false);
add(overlayPanel); add(overlayPanel);
overlayPanel.setScaleLarger(true);
overlayPanel.setScalingType(ScalingType.nearestNeighbor);
overlayPanel.setScalingBlur(true);
overlayPanel.setScalingMultiPassType(MultipassType.none);
//TODO: Image sickness = ImageManager.getSicknessImage();
BufferedImage sickness = null;
overlayPanel.setImage(sickness, sickness);
imagePanel = new ScaledImagePanel(); imagePanel = new ScaledImagePanel();
imagePanel.setBorder(BorderFactory.createLineBorder(Color.white)); imagePanel.setBorder(BorderFactory.createLineBorder(Color.white));
@ -324,19 +321,17 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
} }
} }
public void layout () { public void layout() {
int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE); int borderSize = Math.round(cardWidth * BLACK_BORDER_SIZE);
imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); imagePanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); imagePanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
//TODO: uncomment if (hasSickness && CardUtil.isCreature(gameCard) && isPermanent) {
/*if (gameCard.hasSickness() && gameCard.isCreature() && gameCard.getTableID() != 0) {
overlayPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize); overlayPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
overlayPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2); overlayPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
} else { } else {
overlayPanel.setVisible(false); overlayPanel.setVisible(false);
}*/ }
overlayPanel.setVisible(false);
int fontHeight = Math.round(cardHeight * (27f / 680)); int fontHeight = Math.round(cardHeight * (27f / 680));
boolean showText = (!isAnimationPanel && fontHeight < 12); boolean showText = (!isAnimationPanel && fontHeight < 12);
@ -500,12 +495,11 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
String cardType = getType(card); String cardType = getType(card);
popupText.setText(getText(cardType, card)); popupText.setText(getText(cardType, card));
//TODO: uncomment if (hasSickness && CardUtil.isCreature(gameCard) && isPermanent) {
/*if (gameCard.hasSickness() && gameCard.isCreature() && gameCard.getTableID() != 0) {
overlayPanel.setVisible(true); overlayPanel.setVisible(true);
} else { } else {
overlayPanel.setVisible(false); overlayPanel.setVisible(false);
}*/ }
repaint(); repaint();
} }

View file

@ -0,0 +1,7 @@
package org.mage.plugins.card.utils;
import java.awt.image.BufferedImage;
public interface ImageManager {
public BufferedImage getSicknessImage();
}

View file

@ -0,0 +1,105 @@
package org.mage.plugins.card.utils;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JViewport;
@SuppressWarnings("serial")
public class ImagePanel extends JPanel {
public static final int TILED = 0;
public static final int SCALED = 1;
public static final int ACTUAL = 2;
private BufferedImage image;
private int style;
private float alignmentX = 0.5f;
private float alignmentY = 0.5f;
public ImagePanel(BufferedImage image) {
this(image, TILED);
}
public ImagePanel(BufferedImage image, int style) {
this.image = image;
this.style = style;
setLayout(new BorderLayout());
}
public void setImageAlignmentX(float alignmentX) {
this.alignmentX = alignmentX > 1.0f ? 1.0f : alignmentX < 0.0f ? 0.0f : alignmentX;
}
public void setImageAlignmentY(float alignmentY) {
this.alignmentY = alignmentY > 1.0f ? 1.0f : alignmentY < 0.0f ? 0.0f : alignmentY;
}
public void add(JComponent component) {
add(component, null);
}
public void add(JComponent component, Object constraints) {
component.setOpaque(false);
if (component instanceof JScrollPane) {
JScrollPane scrollPane = (JScrollPane) component;
JViewport viewport = scrollPane.getViewport();
viewport.setOpaque(false);
Component c = viewport.getView();
if (c instanceof JComponent) {
((JComponent) c).setOpaque(false);
}
}
super.add(component, constraints);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (image == null)
return;
switch (style) {
case TILED:
drawTiled(g);
break;
case SCALED:
Dimension d = getSize();
g.drawImage(image, 0, 0, d.width, d.height, null);
break;
case ACTUAL:
drawActual(g);
break;
}
}
private void drawTiled(Graphics g) {
Dimension d = getSize();
int width = image.getWidth(null);
int height = image.getHeight(null);
for (int x = 0; x < d.width; x += width) {
for (int y = 0; y < d.height; y += height) {
g.drawImage(image, x, y, null, null);
}
}
}
private void drawActual(Graphics g) {
Dimension d = getSize();
float x = (d.width - image.getWidth()) * alignmentX;
float y = (d.height - image.getHeight()) * alignmentY;
g.drawImage(image, (int) x, (int) y, this);
}
}

View file

@ -0,0 +1,52 @@
package org.mage.plugins.card.utils;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
public class Transparency {
public static Image makeColorTransparent(Image im, final Color color) {
ImageFilter filter = new RGBImageFilter() {
// the color we are looking for... Alpha bits are set to opaque
public int markerRGB = color.getRGB() | 0xFF000000;
@Override
public final int filterRGB(int x, int y, int rgb) {
if ((rgb | 0xFF000000) == markerRGB) {
// Mark the alpha bits as zero - transparent
return 0x00FFFFFF & rgb;
} else {
// nothing to do
return rgb;
}
}
};
ImageProducer ip = new FilteredImageSource(im.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(ip);
}
public static BufferedImage makeImageTranslucent(BufferedImage source,
double alpha) {
BufferedImage target = new BufferedImage(source.getWidth(), source
.getHeight(), java.awt.Transparency.TRANSLUCENT);
// Get the images graphics
Graphics2D g = target.createGraphics();
// Set the Graphics composite to Alpha
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
(float) alpha));
// Draw the image into the prepared reciver image
g.drawImage(source, null, 0, 0);
// let go of all system resources in this Graphics
g.dispose();
// Return the image
return target;
}
}

View file

@ -0,0 +1,58 @@
package org.mage.plugins.card.utils.impl;
import java.awt.Color;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;
import java.net.URL;
import javax.imageio.ImageIO;
import org.mage.plugins.card.utils.BufferedImageBuilder;
import org.mage.plugins.card.utils.ImageManager;
import org.mage.plugins.card.utils.Transparency;
public class ImageManagerImpl implements ImageManager {
private static ImageManagerImpl fInstance = new ImageManagerImpl();
public static ImageManagerImpl getInstance() {
return fInstance;
}
@Override
public BufferedImage getSicknessImage() {
if (imageSickness == null) {
Image image = getImageFromResourceTransparent("/sickness.png", Color.WHITE, new Rectangle(296, 265));
Toolkit tk = Toolkit.getDefaultToolkit();
image = tk.createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(0, 0, 200, 285)));
BufferedImageBuilder builder = new BufferedImageBuilder();
imageSickness = builder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
}
return imageSickness;
}
protected static Image getImageFromResourceTransparent(String path, Color mask, Rectangle rec) {
BufferedImage image = null;
Image imageCardTransparent = null;
Image resized = null;
URL imageURL = ImageManager.class.getResource(path);
try {
image = ImageIO.read(imageURL);
imageCardTransparent = Transparency.makeColorTransparent(image, mask);
resized = imageCardTransparent.getScaledInstance(rec.width, rec.height, java.awt.Image.SCALE_SMOOTH);
} catch (Exception e) {
e.printStackTrace();
}
return resized;
}
private static BufferedImage imageSickness = null;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 138 KiB