From 27acaa5c9ae96a4e830c32be13241ea437939436 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 9 Oct 2016 15:28:54 +0200 Subject: [PATCH] Fixed a image cache problem that prevented to show cards with different art correctly. --- .../mage/card/arcane/CardPanelRenderImpl.java | 12 +++++-- .../mage/plugins/card/images/ImageCache.java | 35 +++++++++++-------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderImpl.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderImpl.java index f22fc7d112..9f1b76995b 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderImpl.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelRenderImpl.java @@ -63,7 +63,12 @@ public class CardPanelRenderImpl extends CardPanel { if (!a.getRules().equals(b.getRules())) { return false; } - + if (!a.getRarity().equals(b.getRarity())) { + return false; + } + if (!a.getCardNumber().equals(b.getCardNumber())) { + return false; + } // Expansion set code, with null checking: // TODO: The null checks should not be necessary, but thanks to Issue #2260 // some tokens / commandobjects will be missing expansion set codes. @@ -329,6 +334,7 @@ public class CardPanelRenderImpl extends CardPanel { } else { srcImage = ImageCache.getThumbnail(gameCard); } + UI.invokeLater(new Runnable() { @Override public void run() { @@ -393,7 +399,7 @@ public class CardPanelRenderImpl extends CardPanel { return ImageCache.loadImage(new TFile(DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename)); } } - + @Override public void setSelected(boolean selected) { if (selected != isSelected()) { @@ -403,7 +409,7 @@ public class CardPanelRenderImpl extends CardPanel { repaint(); } } - + @Override public void setChoosable(boolean choosable) { if (choosable != isChoosable()) { diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java b/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java index 97a86655c2..d6613f57d7 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/images/ImageCache.java @@ -1,6 +1,5 @@ package org.mage.plugins.card.images; -import mage.client.util.TransformedImageCache; import com.google.common.base.Function; import com.google.common.collect.ComputationException; import com.google.common.collect.MapMaker; @@ -13,6 +12,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.imageio.ImageIO; import mage.client.dialog.PreferencesDialog; +import mage.client.util.TransformedImageCache; import mage.view.CardView; import net.java.truevfs.access.TFile; import net.java.truevfs.access.TFileInputStream; @@ -27,11 +27,12 @@ import org.mage.plugins.card.utils.CardImageUtils; * that the images may be garbage collected when they are not needed any more, * but will be kept as long as possible. * - * Key format: "####" + * Key format: "[cardname]#[setname]#[type]#[collectorID]#[param]" * * where param is: - * *
    + *
  • size of image
  • + * *
  • #Normal: request for unrotated image
  • *
  • #Tapped: request for rotated image
  • *
  • #Cropped: request for cropped image that is used for Shandalar like card @@ -56,6 +57,7 @@ public class ImageCache { try { boolean usesVariousArt = false; + LOGGER.info("Key load to CACHE: " + key); if (key.matches(".*#usesVariousArt.*")) { usesVariousArt = true; key = key.replace("#usesVariousArt", ""); @@ -127,7 +129,11 @@ public class ImageCache { return makeThumbnailByFile(key, file, thumbnailPath); } } else { - return getWizardsCard(loadImage(file)); + BufferedImage image = loadImage(file); + LOGGER.info("Basic image: @" + Integer.toHexString(image.hashCode())); + image = getWizardsCard(image); + LOGGER.info("Wizard image: @" + Integer.toHexString(image.hashCode())); + return image; } } else { throw new RuntimeException( @@ -201,7 +207,7 @@ public class ImageCache { public static BufferedImage getThumbnail(CardView card) { return getImage(getKey(card, card.getName(), "#thumb")); } - + public static BufferedImage tryGetThumbnail(CardView card) { return tryGetImage(getKey(card, card.getName(), "#thumb")); } @@ -235,10 +241,10 @@ public class ImageCache { return null; } } - + /** - * Returns the Image corresponding to the key only if it already exists - * in the cache. + * Returns the Image corresponding to the key only if it already exists in + * the cache. */ private static BufferedImage tryGetImage(String key) { if (IMAGE_CACHE.containsKey(key)) { @@ -360,15 +366,16 @@ public class ImageCache { return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale)); } - + /** - * Returns the image appropriate to display for a card in a picture panel, but - * only it was ALREADY LOADED. That is, the call is immediate and will not block - * on file IO. + * Returns the image appropriate to display for a card in a picture panel, + * but only it was ALREADY LOADED. That is, the call is immediate and will + * not block on file IO. + * * @param card * @param width * @param height - * @return + * @return */ public static BufferedImage tryGetImage(CardView card, int width, int height) { if (Constants.THUMBNAIL_SIZE_FULL.width + 10 > width) { @@ -386,7 +393,7 @@ public class ImageCache { return original; } - return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale)); + return TransformedImageCache.getResizedImage(original, (int) (original.getWidth() * scale), (int) (original.getHeight() * scale)); } public static TFile getTFile(String path) {