* Improved handling of enlarged images. Added mode to show other side of flip and transform cards. Added icon for copied cards and possibility to show enlarged original or copied card.

This commit is contained in:
LevelX2 2014-03-06 21:51:51 +01:00
parent 0babf49392
commit 59d907c981
24 changed files with 490 additions and 233 deletions

View file

@ -24,15 +24,17 @@ import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import mage.cards.MagePermanent;
import mage.cards.TextPopup;
import mage.cards.action.ActionCallback;
import mage.cards.action.TransferData;
import mage.client.plugins.adapters.MageActionCallback;
import mage.client.plugins.impl.Plugins;
import mage.client.util.audio.AudioManager;
import mage.components.ImagePanel;
import mage.constants.CardType;
import mage.constants.EnlargeMode;
import mage.utils.CardUtil;
import mage.view.AbilityView;
import mage.view.CardView;
@ -76,7 +78,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
// for two faced cards
public CardView temporary;
private List<MagePermanent> links = new ArrayList<MagePermanent>();
private List<MagePermanent> links = new ArrayList<>();
public double tappedAngle = 0;
public double flippedAngle = 0;
@ -84,6 +86,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
public ImagePanel overlayPanel;
public JPanel buttonPanel;
public JPanel iconPanel;
public JPanel copyIconPanel;
private GlowText titleText;
private GlowText ptText;
@ -111,8 +114,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
private boolean transformed;
private boolean animationInProgress = false;
private JButton dayNightButton;
private JButton tokenButton;
private JButton showCopySourceButton;
private boolean displayTitleAnyway;
@ -140,7 +145,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
dayNightButton.setLocation(2, 2);
dayNightButton.setSize(25, 25);
buttonPanel.setVisible(this.gameCard.canTransform());
buttonPanel.setVisible(true);
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
dayNightButton.setIcon(new ImageIcon(day));
@ -154,9 +159,6 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
// if card is tapped, no visual transforming is possible (implementation limitation)
// if card is permanent, it will be rotated by Mage, so manual rotate should be possible
if (animationInProgress || isTapped() || isPermanent) {
if (isPermanent) {
JOptionPane.showMessageDialog(null, "You can't transform cards on battlefield.");
}
return;
}
Animation.transformCard(CardPanel.this, CardPanel.this, true);
@ -183,6 +185,32 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
iconPanel.add(tokenButton);
}
// icon to inform about permanent is copying something
if (this.gameCard instanceof PermanentView) {
copyIconPanel = new JPanel();
copyIconPanel.setLayout(null);
copyIconPanel.setOpaque(false);
add(copyIconPanel);
showCopySourceButton = new JButton("");
showCopySourceButton.setLocation(2, 2);
showCopySourceButton.setSize(25, 25);
showCopySourceButton.setToolTipText("This permanent is copying a target. To see original image, push this button or turn mouse wheel down while hoovering with the mouse pointer over the permanent.");
copyIconPanel.setVisible(((PermanentView) this.gameCard).isCopy());
showCopySourceButton.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getCopyInformIconImage()));
copyIconPanel.add(showCopySourceButton);
showCopySourceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ActionCallback callback = Plugins.getInstance().getActionCallback();
((MageActionCallback) callback).enlargeCard(EnlargeMode.COPY);
}
});
}
setBackground(Color.black);
setOpaque(false);
@ -462,6 +490,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
iconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
iconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
}
if (copyIconPanel != null) {
copyIconPanel.setLocation(cardXOffset + borderSize, cardYOffset + borderSize);
copyIconPanel.setSize(cardWidth - borderSize * 2, cardHeight - borderSize * 2);
}
int fontHeight = Math.round(cardHeight * (27f / 680));
boolean showText = (!isAnimationPanel && fontHeight < 12);
titleText.setVisible(showText);
@ -634,7 +666,7 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
@Override
public void update(CardView card) {
if (isPermanent) {
if (isPermanent && (card instanceof PermanentView)) {
boolean needsTapping = isTapped() != ((PermanentView) card).isTapped();
boolean needsFlipping = isFlipped() != ((PermanentView) card).isFlipped();
if (needsTapping || needsFlipping) {
@ -648,6 +680,10 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
Animation.transformCard(this, this, card.isTransformed());
}
}
if (card.canTransform()) {
dayNightButton.setVisible(!isPermanent);
}
if (CardUtil.isCreature(card) && CardUtil.isPlaneswalker(card)) {
ptText.setText(card.getPower() + "/" + card.getToughness() + " (" + card.getLoyalty() + ")");
} else if (CardUtil.isCreature(card)) {
@ -658,6 +694,8 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
ptText.setText("");
}
setText(card);
boolean updateImage = !gameCard.getName().equals(card.getName()); // update after e.g. turning a night/day card
this.gameCard = card;
String cardType = getType(card);
@ -668,7 +706,18 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
} else {
overlayPanel.setVisible(false);
}
if (updateImage) {
updateImage();
if (card.canTransform()) {
BufferedImage transformIcon;
if (card.isTransformed()) {
transformIcon = ImageManagerImpl.getInstance().getNightImage();
} else {
transformIcon = ImageManagerImpl.getInstance().getDayImage();
}
dayNightButton.setIcon(new ImageIcon(transformIcon));
}
}
repaint();
}
@ -859,8 +908,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
@Override
public void update(PermanentView card) {
update((CardView) card);
this.hasSickness = card.hasSummoningSickness();
this.copyIconPanel.setVisible(card.isCopy());
update((CardView) card);
}
@Override
@ -883,7 +933,9 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
this.transformed = !this.transformed;
if (transformed) {
BufferedImage night = ImageManagerImpl.getInstance().getNightImage();
dayNightButton.setIcon(new ImageIcon(night));
if (dayNightButton != null) { // if transformbable card is copied, button can be null
dayNightButton.setIcon(new ImageIcon(night));
}
if (this.gameCard.getSecondCardFace() == null) {
log.error("no second side for card to transform!");
return;
@ -892,17 +944,21 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
this.temporary = this.gameCard;
update(this.gameCard.getSecondCardFace());
}
updateImage();
} else {
BufferedImage day = ImageManagerImpl.getInstance().getDayImage();
dayNightButton.setIcon(new ImageIcon(day));
if (dayNightButton != null) { // if transformbable card is copied, button can be null
dayNightButton.setIcon(new ImageIcon(day));
}
if (!isPermanent) { // use only for custom transformation (when pressing day-night button)
this.gameCard = this.temporary;
this.temporary = null;
update(this.gameCard);
}
updateImage();
}
}
String temp = this.gameCard.getAlternateName();
this.gameCard.setAlternateName(this.gameCard.getOriginalName());
this.gameCard.setOriginalName(temp);
updateImage();
}
@Override

View file

@ -62,7 +62,7 @@ public class CardPluginImpl implements CardPlugin {
private int cardWidth, cardHeight;
private int extraCardSpacingX, cardSpacingX, cardSpacingY;
private int stackSpacingX, stackSpacingY;
private List<Row> rows = new ArrayList<Row>();
private List<Row> rows = new ArrayList<>();
@Init
public void init() {
@ -183,7 +183,7 @@ public class CardPluginImpl implements CardPlugin {
int afterCreaturesIndex = rows.size();
wrap(lands, rows, afterCreaturesIndex);
// Store the current rows and others.
List<Row> storedRows = new ArrayList<Row>(rows.size());
List<Row> storedRows = new ArrayList<>(rows.size());
for (Row row : rows) {
storedRows.add((Row) row.clone());
}

View file

@ -7,21 +7,21 @@ import com.mortennobel.imagescaling.ResampleOp;
import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileInputStream;
import de.schlichtherle.truezip.file.TFileOutputStream;
import mage.client.dialog.PreferencesDialog;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.client.dialog.PreferencesDialog;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.utils.CardImageUtils;
/**
* This class stores ALL card images in a cache with soft values. this means
@ -167,10 +167,20 @@ public class ImageCache {
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.debug("#key: " + key);
// log.warn("#key: " + key);
return getImage(key);
}
public static BufferedImage getImageOriginalAlternateName(CardView card) {
String key = getKeyAlternateName(card, card.getAlternateName());
if (card.getUsesVariousArt()) {
key += "#usesVariousArt";
}
// log.warn("#key: " + key);
return getImage(key);
}
/**
* Returns the Image corresponding to the key
*/
@ -205,6 +215,18 @@ public class ImageCache {
return sb.toString();
}
/**
* Returns the map key for the flip image of a card, without any suffixes for the image size.
*/
private static String getKeyAlternateName(CardView card, String alternateName) {
StringBuilder sb = new StringBuilder(alternateName).append("#");
sb.append(card.getExpansionSetCode()).append("#");
sb.append(card.getType()).append("#");
sb.append(card.getCardNumber()).append("#");
sb.append(card.getTokenSetCode() == null ? "":card.getTokenSetCode());
return sb.toString();
}
/**
* Load image from file
*
@ -251,6 +273,7 @@ public class ImageCache {
/**
* Returns an image scaled to the size given
* @param original
* @return
*/
public static BufferedImage getNormalSizeImage(BufferedImage original) {
@ -289,6 +312,9 @@ public class ImageCache {
/**
* Returns an image scaled to the size appropriate for the card picture
* panel
* @param original
* @param sizeNeed
* @return
*/
public static BufferedImage getResizedImage(BufferedImage original, Rectangle sizeNeed) {
ResampleOp resampleOp = new ResampleOp(sizeNeed.width, sizeNeed.height);
@ -298,6 +324,10 @@ public class ImageCache {
/**
* Returns the image appropriate to display the card in the picture panel
* @param card
* @param width
* @param height
* @return
*/
public static BufferedImage getImage(CardView card, int width, int height) {
if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) {

View file

@ -13,6 +13,7 @@ public interface ImageManager {
Image getNightImage();
Image getTokenIconImage();
Image getCopyInformIconImage();
Image getDlgAcceptButtonImage();
Image getDlgActiveAcceptButtonImage();

View file

@ -106,6 +106,15 @@ public class ImageManagerImpl implements ImageManager {
return imageTokenIcon;
}
@Override
public BufferedImage getCopyInformIconImage() {
if (imageCopyIcon == null) {
Image image = getImageFromResourceTransparent("/card/copy.png", Color.WHITE, new Rectangle(20, 20));
imageCopyIcon = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB);
}
return imageCopyIcon;
}
@Override
public Image getDlgCancelButtonImage() {
if (imageDlgCancelButton == null) {
@ -226,6 +235,7 @@ public class ImageManagerImpl implements ImageManager {
private static BufferedImage imageNight;
private static BufferedImage imageTokenIcon;
private static BufferedImage imageCopyIcon;
private static BufferedImage imageDlgAcceptButton;
private static BufferedImage imageDlgActiveAcceptButton;