mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Prevent hiding name/mana cost if default card image shown
This commit is contained in:
@@ -55,9 +55,10 @@ import java.util.concurrent.ExecutionException;
|
|||||||
public class ImageCache {
|
public class ImageCache {
|
||||||
// short prefixes to save memory
|
// short prefixes to save memory
|
||||||
|
|
||||||
private static final Set<String> _missingIconKeys = new HashSet<String>();
|
private static final Set<String> missingIconKeys = new HashSet<String>();
|
||||||
private static final LoadingCache<String, Texture> _CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
|
private static final LoadingCache<String, Texture> cache = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
|
||||||
private static final Texture _defaultImage;
|
public static final Texture defaultImage;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Texture defImage = null;
|
Texture defImage = null;
|
||||||
try {
|
try {
|
||||||
@@ -65,13 +66,13 @@ public class ImageCache {
|
|||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("could not load default card image");
|
System.err.println("could not load default card image");
|
||||||
} finally {
|
} 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() {
|
public static void clear() {
|
||||||
_CACHE.invalidateAll();
|
cache.invalidateAll();
|
||||||
_missingIconKeys.clear();
|
missingIconKeys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Texture getImage(Card card) {
|
public static Texture getImage(Card card) {
|
||||||
@@ -99,9 +100,9 @@ public class ImageCache {
|
|||||||
public static FImage getIcon(IHasIcon ihi) {
|
public static FImage getIcon(IHasIcon ihi) {
|
||||||
String imageKey = ihi.getIconImageKey();
|
String imageKey = ihi.getIconImageKey();
|
||||||
final Texture icon;
|
final Texture icon;
|
||||||
if (_missingIconKeys.contains(imageKey) ||
|
if (missingIconKeys.contains(imageKey) ||
|
||||||
null == (icon = getImage(ihi.getIconImageKey(), false))) {
|
null == (icon = getImage(ihi.getIconImageKey(), false))) {
|
||||||
_missingIconKeys.add(imageKey);
|
missingIconKeys.add(imageKey);
|
||||||
return FSkinImage.UNKNOWN;
|
return FSkinImage.UNKNOWN;
|
||||||
}
|
}
|
||||||
return new FTextureImage(icon);
|
return new FTextureImage(icon);
|
||||||
@@ -127,14 +128,14 @@ public class ImageCache {
|
|||||||
if (imageKey.startsWith(ImageKeys.CARD_PREFIX)) {
|
if (imageKey.startsWith(ImageKeys.CARD_PREFIX)) {
|
||||||
imageKey = ImageUtil.getImageKey(ImageUtil.getPaperCardFromImageKey(imageKey.substring(2)), altState, true);
|
imageKey = ImageUtil.getImageKey(ImageUtil.getPaperCardFromImageKey(imageKey.substring(2)), altState, true);
|
||||||
if (StringUtils.isBlank(imageKey)) {
|
if (StringUtils.isBlank(imageKey)) {
|
||||||
return _defaultImage;
|
return defaultImage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from file and add to cache if not found in cache initially.
|
// Load from file and add to cache if not found in cache initially.
|
||||||
Texture image;
|
Texture image;
|
||||||
try {
|
try {
|
||||||
image = ImageCache._CACHE.get(imageKey);
|
image = ImageCache.cache.get(imageKey);
|
||||||
}
|
}
|
||||||
catch (final ExecutionException ex) {
|
catch (final ExecutionException ex) {
|
||||||
if (!(ex.getCause() instanceof NullPointerException)) {
|
if (!(ex.getCause() instanceof NullPointerException)) {
|
||||||
@@ -150,8 +151,8 @@ public class ImageCache {
|
|||||||
// a default "not available" image and add to cache for given key.
|
// a default "not available" image and add to cache for given key.
|
||||||
if (image == null) {
|
if (image == null) {
|
||||||
if (useDefaultIfNotFound) {
|
if (useDefaultIfNotFound) {
|
||||||
image = _defaultImage;
|
image = defaultImage;
|
||||||
_CACHE.put(imageKey, _defaultImage);
|
cache.put(imageKey, defaultImage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
image = null;
|
image = null;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class CardRenderer {
|
|||||||
private static final float MANA_COST_PADDING = Utils.scaleMin(3);
|
private static final float MANA_COST_PADDING = Utils.scaleMin(3);
|
||||||
private static final float SET_BOX_MARGIN = Utils.scaleMin(1);
|
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 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) {
|
private static Color fromDetailColor(DetailColors detailColor) {
|
||||||
return FSkinColor.fromRGB(detailColor.r, detailColor.g, detailColor.b);
|
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 color = FSkinColor.fromRGB(borderColor.r, borderColor.g, borderColor.b);
|
||||||
color = FSkinColor.tintColor(Color.WHITE, color, CardRenderer.PT_BOX_TINT);
|
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)) {
|
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);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user