From 137db75a99d422d8d422859b54508b8b7e7f5319 Mon Sep 17 00:00:00 2001 From: drdev Date: Mon, 26 May 2014 15:33:06 +0000 Subject: [PATCH] Prevent hiding name/mana cost if default card image shown --- .../src/forge/assets/ImageCache.java | 25 ++++++++++--------- .../src/forge/card/CardRenderer.java | 4 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/forge-gui-mobile/src/forge/assets/ImageCache.java b/forge-gui-mobile/src/forge/assets/ImageCache.java index e00c1351ca4..8171c920339 100644 --- a/forge-gui-mobile/src/forge/assets/ImageCache.java +++ b/forge-gui-mobile/src/forge/assets/ImageCache.java @@ -55,9 +55,10 @@ import java.util.concurrent.ExecutionException; public class ImageCache { // short prefixes to save memory - private static final Set _missingIconKeys = new HashSet(); - private static final LoadingCache _CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader()); - private static final Texture _defaultImage; + private static final Set missingIconKeys = new HashSet(); + private static final LoadingCache cache = CacheBuilder.newBuilder().softValues().build(new ImageLoader()); + public static final Texture defaultImage; + static { Texture defImage = null; try { @@ -65,13 +66,13 @@ public class ImageCache { } catch (Exception ex) { System.err.println("could not load default card image"); } finally { - _defaultImage = (null == defImage) ? new Texture(10, 10, Format.RGBA8888) : defImage; + defaultImage = (null == defImage) ? new Texture(10, 10, Format.RGBA8888) : defImage; } } public static void clear() { - _CACHE.invalidateAll(); - _missingIconKeys.clear(); + cache.invalidateAll(); + missingIconKeys.clear(); } public static Texture getImage(Card card) { @@ -99,9 +100,9 @@ public class ImageCache { public static FImage getIcon(IHasIcon ihi) { String imageKey = ihi.getIconImageKey(); final Texture icon; - if (_missingIconKeys.contains(imageKey) || + if (missingIconKeys.contains(imageKey) || null == (icon = getImage(ihi.getIconImageKey(), false))) { - _missingIconKeys.add(imageKey); + missingIconKeys.add(imageKey); return FSkinImage.UNKNOWN; } return new FTextureImage(icon); @@ -127,14 +128,14 @@ public class ImageCache { if (imageKey.startsWith(ImageKeys.CARD_PREFIX)) { imageKey = ImageUtil.getImageKey(ImageUtil.getPaperCardFromImageKey(imageKey.substring(2)), altState, true); if (StringUtils.isBlank(imageKey)) { - return _defaultImage; + return defaultImage; } } // Load from file and add to cache if not found in cache initially. Texture image; try { - image = ImageCache._CACHE.get(imageKey); + image = ImageCache.cache.get(imageKey); } catch (final ExecutionException ex) { if (!(ex.getCause() instanceof NullPointerException)) { @@ -150,8 +151,8 @@ public class ImageCache { // a default "not available" image and add to cache for given key. if (image == null) { if (useDefaultIfNotFound) { - image = _defaultImage; - _CACHE.put(imageKey, _defaultImage); + image = defaultImage; + cache.put(imageKey, defaultImage); } else { image = null; diff --git a/forge-gui-mobile/src/forge/card/CardRenderer.java b/forge-gui-mobile/src/forge/card/CardRenderer.java index 3ecafc421f3..7851fa8b519 100644 --- a/forge-gui-mobile/src/forge/card/CardRenderer.java +++ b/forge-gui-mobile/src/forge/card/CardRenderer.java @@ -45,6 +45,7 @@ public class CardRenderer { private static final float MANA_COST_PADDING = Utils.scaleMin(3); private static final float SET_BOX_MARGIN = Utils.scaleMin(1); private static final float MANA_SYMBOL_SIZE = FSkinImage.MANA_1.getNearestHQWidth(2 * (NAME_FONT.getFont().getCapHeight() - MANA_COST_PADDING)); + private static final float NAME_COST_THRESHOLD = Utils.scaleY(200); private static Color fromDetailColor(DetailColors detailColor) { return FSkinColor.fromRGB(detailColor.r, detailColor.g, detailColor.b); @@ -392,7 +393,8 @@ public class CardRenderer { Color color = FSkinColor.fromRGB(borderColor.r, borderColor.g, borderColor.b); color = FSkinColor.tintColor(Color.WHITE, color, CardRenderer.PT_BOX_TINT); - if (h < Utils.AVG_FINGER_HEIGHT * 5) { //only draw name and mana cost overlays if card is small + //draw name and mana cost overlays if card is small or default card image being used + if (h <= NAME_COST_THRESHOLD || image == ImageCache.defaultImage) { if (showCardNameOverlay(card)) { g.drawOutlinedText(card.getName(), FSkinFont.forHeight(h * 0.18f), Color.WHITE, Color.BLACK, x + padding, y + padding, w - 2 * padding, h * 0.4f, true, HAlignment.LEFT, false); }