diff --git a/forge-gui-mobile/src/forge/assets/FSkinTexture.java b/forge-gui-mobile/src/forge/assets/FSkinTexture.java index d2555ab31f0..26fab00c078 100644 --- a/forge-gui-mobile/src/forge/assets/FSkinTexture.java +++ b/forge-gui-mobile/src/forge/assets/FSkinTexture.java @@ -10,7 +10,9 @@ import com.badlogic.gdx.graphics.Texture.TextureWrap; import forge.Forge; import forge.Graphics; +import forge.gui.GuiBase; import forge.localinstance.properties.ForgeConstants; +import forge.util.ImageFetcher; public enum FSkinTexture implements FImage { BG_TEXTURE(ForgeConstants.TEXTURE_BG_FILE, true, false), @@ -198,7 +200,7 @@ public enum FSkinTexture implements FImage { private final boolean repeat; private Texture texture; private final boolean isPlanechaseBG; - private static List PlanesValue; + private static List planechaseString; private boolean isloaded = false; private boolean hasError = false; @@ -207,19 +209,18 @@ public enum FSkinTexture implements FImage { repeat = repeat0; isPlanechaseBG = isPlanechaseBG0; } - - static { - PlanesValue = new ArrayList<>(); - for (FSkinTexture PlanesEnum : FSkinTexture.values()) { - PlanesValue.add(PlanesEnum.filename - .replace(".jpg", "") - .replace("'", "") - .replace("-", "")); - } - } - public static List getValues() { - return Collections.unmodifiableList(PlanesValue); + if (planechaseString == null) { + planechaseString = new ArrayList<>(); + for (FSkinTexture fskinTexture : FSkinTexture.values()) { + if (fskinTexture.isPlanechaseBG) + planechaseString.add(fskinTexture.filename + .replace(".jpg", "") + .replace("'", "") + .replace("-", "")); + } + } + return Collections.unmodifiableList(planechaseString); } public void load() { @@ -243,6 +244,11 @@ public enum FSkinTexture implements FImage { //use default file if can't use preferred file FileHandle defaultFile = FSkin.getDefaultSkinFile(filename); if(isPlanechaseBG) { + ImageFetcher fetcher = GuiBase.getInterface().getImageFetcher(); + fetcher.fetchImage("PLANECHASEBG:" + filename, () -> { + hasError = false; + load(); + }); defaultFile = FSkin.getSkinFile(ForgeConstants.MATCH_BG_FILE); if(!defaultFile.exists()) defaultFile = FSkin.getDefaultSkinFile(ForgeConstants.MATCH_BG_FILE); diff --git a/forge-gui-mobile/src/forge/util/LibGDXImageFetcher.java b/forge-gui-mobile/src/forge/util/LibGDXImageFetcher.java index a00dde71537..95660a58bff 100644 --- a/forge-gui-mobile/src/forge/util/LibGDXImageFetcher.java +++ b/forge-gui-mobile/src/forge/util/LibGDXImageFetcher.java @@ -75,22 +75,32 @@ public class LibGDXImageFetcher extends ImageFetcher { public void run() { for (String urlToDownload : downloadUrls) { + boolean isPlanechaseBG = urlToDownload.startsWith("https://downloads.cardforge.org/images/planes/"); try { - doFetch(tofullBorder(urlToDownload)); - break; + if (isPlanechaseBG) { + doFetch(urlToDownload); + break; + } else { + doFetch(tofullBorder(urlToDownload)); + break; + } } catch (IOException e) { - System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage()); - if (urlToDownload.contains("tokens")) { - int setIndex = urlToDownload.lastIndexOf('_'); - int typeIndex = urlToDownload.lastIndexOf('.'); - String setlessFilename = urlToDownload.substring(0, setIndex); - String extension = urlToDownload.substring(typeIndex); - urlToDownload = setlessFilename+extension; - try { - doFetch(tofullBorder(urlToDownload)); - break; - } catch (IOException t) { - System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage()); + if (isPlanechaseBG) { + System.out.println("Failed to download planechase background [" + destPath + "] image: " + e.getMessage()); + } else { + System.out.println("Failed to download card [" + destPath + "] image: " + e.getMessage()); + if (urlToDownload.contains("tokens")) { + int setIndex = urlToDownload.lastIndexOf('_'); + int typeIndex = urlToDownload.lastIndexOf('.'); + String setlessFilename = urlToDownload.substring(0, setIndex); + String extension = urlToDownload.substring(typeIndex); + urlToDownload = setlessFilename + extension; + try { + doFetch(tofullBorder(urlToDownload)); + break; + } catch (IOException t) { + System.out.println("Failed to download setless token [" + destPath + "]: " + e.getMessage()); + } } } } diff --git a/forge-gui/src/main/java/forge/util/ImageFetcher.java b/forge-gui/src/main/java/forge/util/ImageFetcher.java index a4772e0339f..b7d800bf031 100644 --- a/forge-gui/src/main/java/forge/util/ImageFetcher.java +++ b/forge-gui/src/main/java/forge/util/ImageFetcher.java @@ -87,6 +87,20 @@ public abstract class ImageFetcher { if (imageKey.length() < 2) return; + //planechaseBG file... + if (imageKey.startsWith("PLANECHASEBG:")) { + final ArrayList downloadUrls = new ArrayList<>(); + final String filename = imageKey.substring("PLANECHASEBG:".length()); + downloadUrls.add("https://downloads.cardforge.org/images/planes/" + filename); + FileUtil.ensureDirectoryExists(ForgeConstants.CACHE_PLANECHASE_PICS_DIR); + File destFile = new File(ForgeConstants.CACHE_PLANECHASE_PICS_DIR, filename); + if (destFile.exists()) + return; + + setupObserver(destFile.getAbsolutePath(), callback, downloadUrls); + return; + } + boolean useArtCrop = "Crop".equals(FModel.getPreferences().getPref(ForgePreferences.FPref.UI_CARD_ART_FORMAT)); final String prefix = imageKey.substring(0, 2); final ArrayList downloadUrls = new ArrayList<>(); @@ -234,8 +248,9 @@ public abstract class ImageFetcher { return; } - final String destPath = destFile.getAbsolutePath(); - + setupObserver(destFile.getAbsolutePath(), callback, downloadUrls); + } + private void setupObserver(final String destPath, final Callback callback, final ArrayList downloadUrls) { // Note: No synchronization is needed here because this is executed on // EDT thread (see assert on top) and so is the notification of observers. HashSet observers = currentFetches.get(destPath);