mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Also render tokens and emblems when not using images
This commit is contained in:
@@ -6,6 +6,7 @@ import forge.card.CardDb;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardSplitType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PaperToken;
|
||||
|
||||
public class ImageUtil {
|
||||
public static float getNearestHQSize(float baseSize, float actualSize) {
|
||||
@@ -29,6 +30,24 @@ public class ImageUtil {
|
||||
return cp;
|
||||
}
|
||||
|
||||
public static PaperToken getPaperTokenFromImageKey(String key) {
|
||||
if ( key == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
key = key.substring(2);
|
||||
int index = key.lastIndexOf('_');
|
||||
if (index != -1) {
|
||||
String script = key.substring(0, index);
|
||||
String edition = key.substring(index + 1);
|
||||
if (script.startsWith("emblem"))
|
||||
return null;
|
||||
script = script.replaceAll("[0-9]*$", "");
|
||||
return StaticData.instance().getAllTokens().getToken(script, edition);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getImageRelativePath(PaperCard cp, boolean backFace, boolean includeSet, boolean isDownloadUrl) {
|
||||
final String nameToUse = cp == null ? null : getNameToUse(cp, backFace);
|
||||
if (nameToUse == null) {
|
||||
|
||||
@@ -38,9 +38,11 @@ import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.player.PlayerView;
|
||||
import forge.gui.FThreads;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
@@ -144,21 +146,24 @@ public class ImageCache {
|
||||
* the image from file (slower) and then add it to the cache for fast future access.
|
||||
* </p>
|
||||
*/
|
||||
public static BufferedImage getOriginalImage(String imageKey, boolean useDefaultIfNotFound) {
|
||||
public static BufferedImage getOriginalImage(String imageKey, boolean useDefaultIfNotFound, CardView cardView) {
|
||||
if (null == imageKey) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PaperCard pc = null;
|
||||
IPaperCard ipc = null;
|
||||
boolean altState = imageKey.endsWith(ImageKeys.BACKFACE_POSTFIX);
|
||||
if(altState)
|
||||
imageKey = imageKey.substring(0, imageKey.length() - ImageKeys.BACKFACE_POSTFIX.length());
|
||||
if (imageKey.startsWith(ImageKeys.CARD_PREFIX)) {
|
||||
pc = ImageUtil.getPaperCardFromImageKey(imageKey);
|
||||
PaperCard pc = ImageUtil.getPaperCardFromImageKey(imageKey);
|
||||
ipc = pc;
|
||||
imageKey = ImageUtil.getImageKey(pc, altState, true);
|
||||
if (StringUtils.isBlank(imageKey)) {
|
||||
return _defaultImage;
|
||||
}
|
||||
} else if (imageKey.startsWith(ImageKeys.TOKEN_PREFIX)) {
|
||||
ipc = ImageUtil.getPaperTokenFromImageKey(imageKey);
|
||||
}
|
||||
|
||||
// Load from file and add to cache if not found in cache initially.
|
||||
@@ -202,9 +207,10 @@ public class ImageCache {
|
||||
// a default "not available" image, however do not add it to the cache,
|
||||
// as otherwise it's problematic to update if the real image gets fetched.
|
||||
if (original == null && useDefaultIfNotFound) {
|
||||
if (pc != null) {
|
||||
if (ipc != null || cardView != null) {
|
||||
CardView card = ipc != null ? Card.getCardForUi(ipc).getView() : cardView;
|
||||
original = new BufferedImage(480, 680, BufferedImage.TYPE_INT_ARGB);
|
||||
FCardImageRenderer.drawCardImage(original.createGraphics(), pc, altState, 480, 680);
|
||||
FCardImageRenderer.drawCardImage(original.createGraphics(), card, altState, 480, 680);
|
||||
if (!isPreferenceEnabled(ForgePreferences.FPref.UI_ENABLE_ONLINE_IMAGE_FETCHER))
|
||||
_CACHE.put(imageKey, original);
|
||||
} else {
|
||||
@@ -229,7 +235,7 @@ public class ImageCache {
|
||||
return cached;
|
||||
}
|
||||
|
||||
BufferedImage original = getOriginalImage(key, useDefaultImage);
|
||||
BufferedImage original = getOriginalImage(key, useDefaultImage, null);
|
||||
if (original == null) { return null; }
|
||||
|
||||
if (original == _defaultImage) {
|
||||
|
||||
@@ -105,19 +105,19 @@ public final class CardPicturePanel extends JPanel implements ImageFetcher.Callb
|
||||
|
||||
private BufferedImage getImage() {
|
||||
if (!mayView) {
|
||||
return ImageCache.getOriginalImage(ImageKeys.getTokenKey(ImageKeys.HIDDEN_CARD), true);
|
||||
return ImageCache.getOriginalImage(ImageKeys.getTokenKey(ImageKeys.HIDDEN_CARD), true, null);
|
||||
}
|
||||
|
||||
if (displayed instanceof InventoryItem) {
|
||||
final InventoryItem item = (InventoryItem) displayed;
|
||||
BufferedImage image = ImageCache.getOriginalImage(item.getImageKey(false), true);
|
||||
BufferedImage image = ImageCache.getOriginalImage(item.getImageKey(false), true, null);
|
||||
if (ImageCache.isDefaultImage(image) && item instanceof PaperCard) {
|
||||
GuiBase.getInterface().getImageFetcher().fetchImage(item.getImageKey(false), this);
|
||||
}
|
||||
return image;
|
||||
} else if (displayed instanceof CardStateView) {
|
||||
CardStateView card = (CardStateView) displayed;
|
||||
BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(), false);
|
||||
BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(), false, card.getCard());
|
||||
if (image == null) {
|
||||
GuiBase.getInterface().getImageFetcher().fetchImage(card.getImageKey(), this);
|
||||
}
|
||||
|
||||
@@ -22,12 +22,10 @@ import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.card.CardView.CardStateView;
|
||||
import forge.gui.card.CardDetailUtil;
|
||||
import forge.gui.card.CardDetailUtil.DetailColors;
|
||||
import forge.item.PaperCard;
|
||||
import forge.localinstance.properties.ForgePreferences.FPref;
|
||||
import forge.localinstance.skin.FSkinProp;
|
||||
import forge.model.FModel;
|
||||
@@ -148,8 +146,7 @@ public class FCardImageRenderer {
|
||||
prevImageHeight = h;
|
||||
}
|
||||
|
||||
public static void drawCardImage(Graphics2D g, PaperCard pc, boolean altState, int width, int height) {
|
||||
final CardView card = Card.getCardForUi(pc).getView();
|
||||
public static void drawCardImage(Graphics2D g, CardView card, boolean altState, int width, int height) {
|
||||
float x = 0, y = 0, w = width, h = height;
|
||||
updateStaticFields(g, w, h);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
|
||||
@@ -55,7 +55,7 @@ public final class FImageUtil {
|
||||
* For flip cards, returns the un-flipped image.
|
||||
*/
|
||||
public static BufferedImage getImage(final CardStateView card) {
|
||||
BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(), true);
|
||||
BufferedImage image = ImageCache.getOriginalImage(card.getImageKey(), true, card.getCard());
|
||||
final int foilIndex = card.getFoilIndex();
|
||||
if (image != null && foilIndex > 0) {
|
||||
image = getImageWithFoilEffect(image, foilIndex);
|
||||
|
||||
Reference in New Issue
Block a user