mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
refactor defaultImage
- use assetmanager to handle defaultImage
This commit is contained in:
@@ -6,6 +6,8 @@ import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
|
||||
import com.badlogic.gdx.assets.loaders.TextureLoader;
|
||||
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.TextureData;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
@@ -15,6 +17,7 @@ import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import forge.Forge;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.localinstance.properties.ForgeConstants;
|
||||
import forge.localinstance.skin.FSkinProp;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -40,6 +43,7 @@ public class Assets implements Disposable {
|
||||
private ObjectMap<String, Texture> tmxMap = new ObjectMap<>();
|
||||
public Skin skin;
|
||||
public BitmapFont advDefaultFont, advBigFont;
|
||||
private Texture defaultImage, dummy;
|
||||
public Assets() {
|
||||
//init titlebg fallback
|
||||
fallback_skins.put(0, new Texture(GuiBase.isAndroid()
|
||||
@@ -69,6 +73,10 @@ public class Assets implements Disposable {
|
||||
advBigFont.dispose();
|
||||
if (skin != null)
|
||||
skin.dispose();
|
||||
if (defaultImage != null)
|
||||
defaultImage.dispose();
|
||||
if (dummy != null)
|
||||
dummy.dispose();
|
||||
}
|
||||
public MemoryTrackingAssetManager manager() {
|
||||
if (manager == null)
|
||||
@@ -155,6 +163,28 @@ public class Assets implements Disposable {
|
||||
tmxMap = new ObjectMap<>();
|
||||
return tmxMap;
|
||||
}
|
||||
public Texture getDefaultImage() {
|
||||
if (defaultImage == null) {
|
||||
FileHandle blankImage = Gdx.files.absolute(ForgeConstants.NO_CARD_FILE);
|
||||
if (blankImage.exists()) {
|
||||
defaultImage = manager.get(blankImage.path(), Texture.class, false);
|
||||
if (defaultImage != null)
|
||||
return defaultImage;
|
||||
//if not loaded yet, load to assetmanager
|
||||
manager.load(blankImage.path(), Texture.class, new TextureLoader.TextureParameter(){{genMipMaps = true; minFilter = Texture.TextureFilter.MipMapLinearLinear; magFilter = Texture.TextureFilter.Linear;}});
|
||||
manager.finishLoadingAsset(blankImage.path());
|
||||
defaultImage = manager.get(blankImage.path());
|
||||
} else {
|
||||
defaultImage = getDummy();
|
||||
}
|
||||
}
|
||||
return defaultImage;
|
||||
}
|
||||
private Texture getDummy() {
|
||||
if (dummy == null)
|
||||
dummy = new Texture(10, 10, Pixmap.Format.RGBA4444);
|
||||
return dummy;
|
||||
}
|
||||
public class MemoryTrackingAssetManager extends AssetManager {
|
||||
private int currentMemory;
|
||||
private Map<String, Integer> memoryPerFile;
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.badlogic.gdx.graphics.glutils.PixmapTextureData;
|
||||
import com.google.common.collect.EvictingQueue;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.common.collect.Sets;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.gui.FThreads;
|
||||
import forge.gui.GuiBase;
|
||||
import forge.util.FileUtil;
|
||||
@@ -98,7 +99,9 @@ public class ImageCache {
|
||||
int cl = GuiBase.isAndroid() ? maxCardCapacity+(capacity/3) : 400;
|
||||
cardsLoaded = new HashSet<>(cl);
|
||||
}
|
||||
public static final Texture defaultImage;
|
||||
public static Texture getDefaultImage() {
|
||||
return Forge.getAssets().getDefaultImage();
|
||||
}
|
||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
||||
private static final HashMap<String, Pair<String, Boolean>> imageBorder = new HashMap<>(1024);
|
||||
@@ -109,17 +112,6 @@ public class ImageCache {
|
||||
delayLoadRequested = false;
|
||||
}
|
||||
|
||||
static {
|
||||
Texture defImage = null;
|
||||
try {
|
||||
defImage = new Texture(Gdx.files.absolute(ForgeConstants.NO_CARD_FILE));
|
||||
} catch (Exception ex) {
|
||||
System.err.println("could not load default card image");
|
||||
} finally {
|
||||
defaultImage = (null == defImage) ? new Texture(10, 10, Format.RGBA4444) : defImage;
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
missingIconKeys.clear();
|
||||
ImageKeys.clearMissingCards();
|
||||
@@ -140,10 +132,11 @@ public class ImageCache {
|
||||
}
|
||||
|
||||
public static Texture getImage(InventoryItem ii) {
|
||||
boolean useDefault = ii instanceof DeckProxy;
|
||||
String imageKey = ii.getImageKey(false);
|
||||
if (imageKey != null) {
|
||||
if(imageKey.startsWith(ImageKeys.CARD_PREFIX) || imageKey.startsWith(ImageKeys.TOKEN_PREFIX))
|
||||
return getImage(ii.getImageKey(false), false, false);
|
||||
return getImage(ii.getImageKey(false), useDefault, false);
|
||||
}
|
||||
return getImage(ii.getImageKey(false), true, true);
|
||||
}
|
||||
@@ -230,7 +223,7 @@ public class ImageCache {
|
||||
imageKey = altState ? card.getCardAltImageKey() : card.getCardImageKey();
|
||||
if (StringUtils.isBlank(imageKey)) {
|
||||
if (useDefaultIfNotFound)
|
||||
return defaultImage;
|
||||
return getDefaultImage();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@@ -265,7 +258,7 @@ public class ImageCache {
|
||||
// a default "not available" image.
|
||||
if (image == null) {
|
||||
if (useDefaultIfNotFound) {
|
||||
image = defaultImage;
|
||||
image = getDefaultImage();
|
||||
/*fix not loading image file since we intentionally not to update the cache in order for the
|
||||
image fetcher to update automatically after the card image/s are downloaded*/
|
||||
imageLoaded = false;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CardAvatarImage implements FImage {
|
||||
if (image != null) {
|
||||
return image.getHeight();
|
||||
}
|
||||
return ImageCache.defaultImage.getHeight() * CardRenderer.CARD_ART_HEIGHT_PERCENTAGE;
|
||||
return ImageCache.getDefaultImage().getHeight() * CardRenderer.CARD_ART_HEIGHT_PERCENTAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,7 @@ public class CardImage implements FImage {
|
||||
if (image != null) {
|
||||
return image.getWidth();
|
||||
}
|
||||
return ImageCache.defaultImage.getWidth();
|
||||
return ImageCache.getDefaultImage().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,7 +44,7 @@ public class CardImage implements FImage {
|
||||
}
|
||||
}
|
||||
|
||||
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
|
||||
if (image == ImageCache.getDefaultImage() || Forge.enableUIMask.equals("Art")) {
|
||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top, true, true);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -819,7 +819,7 @@ public class CardImageRenderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
CardRenderer.drawFoilEffect(g, card, x, y, w, h, isCurrentCard && canshow && image != ImageCache.defaultImage);
|
||||
CardRenderer.drawFoilEffect(g, card, x, y, w, h, isCurrentCard && canshow && image != ImageCache.getDefaultImage());
|
||||
}
|
||||
|
||||
public static void drawDetails(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h) {
|
||||
|
||||
@@ -223,7 +223,7 @@ public class CardRenderer {
|
||||
if (cardArt == null) {
|
||||
Texture image = new RendererCachedCardImage(imageKey, true).getImage();
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage) {
|
||||
if (image == ImageCache.getDefaultImage()) {
|
||||
cardArt = CardImageRenderer.forgeArt;
|
||||
}
|
||||
else {
|
||||
@@ -322,7 +322,7 @@ public class CardRenderer {
|
||||
}
|
||||
}.getImage();
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage) {
|
||||
if (image == ImageCache.getDefaultImage()) {
|
||||
cardArt = CardImageRenderer.forgeArt;
|
||||
} else {
|
||||
float x, y;
|
||||
@@ -355,7 +355,7 @@ public class CardRenderer {
|
||||
}
|
||||
}.getImage();
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage) {
|
||||
if (image == ImageCache.getDefaultImage()) {
|
||||
cardArt = CardImageRenderer.forgeArt;
|
||||
} else {
|
||||
float x, y;
|
||||
@@ -409,7 +409,7 @@ public class CardRenderer {
|
||||
}
|
||||
}.getImage();
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage) {
|
||||
if (image == ImageCache.getDefaultImage()) {
|
||||
cardArt = CardImageRenderer.forgeArt;
|
||||
} else {
|
||||
float x = 0;
|
||||
@@ -575,7 +575,7 @@ public class CardRenderer {
|
||||
minusxy = 0.135f*radius;
|
||||
}
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
|
||||
if (image == ImageCache.getDefaultImage() || Forge.enableUIMask.equals("Art")) {
|
||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos, true, true);
|
||||
} else {
|
||||
if (Forge.enableUIMask.equals("Full")) {
|
||||
@@ -623,7 +623,7 @@ public class CardRenderer {
|
||||
if (card.isPhasedOut() && !magnify)
|
||||
g.setAlphaComposite(0.2f);
|
||||
if (image != null) {
|
||||
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
|
||||
if (image == ImageCache.getDefaultImage() || Forge.enableUIMask.equals("Art")) {
|
||||
CardImageRenderer.drawCardImage(g, card, showAltState, x, y, w, h, pos, true, false, isChoiceList, !showCardIdOverlay(card));
|
||||
} else if (showsleeves) {
|
||||
if (!card.isForeTold())
|
||||
|
||||
Reference in New Issue
Block a user