* UI: fixed that face down card displays without image (now it shows default card's back);

This commit is contained in:
Oleg Agafonov 2020-01-22 00:50:10 +04:00
parent 007d0d19b4
commit 959374389b
4 changed files with 36 additions and 37 deletions

View file

@ -1,10 +1,9 @@
package mage.client.constants; package mage.client.constants;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -55,7 +54,7 @@ public final class Constants {
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146); public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);
// resources - default images // resources - default images
public static final String RESOURCE_PATH_DEFAUL_IMAGES = File.separator + "default"; public static final String RESOURCE_PATH_DEFAULT_IMAGES = File.separator + "default";
// resources - symbols // resources - symbols
public static final String RESOURCE_PATH_SYMBOLS = File.separator + "symbols"; public static final String RESOURCE_PATH_SYMBOLS = File.separator + "symbols";
@ -64,6 +63,7 @@ public final class Constants {
public static final String RESOURCE_SYMBOL_FOLDER_LARGE = "large"; public static final String RESOURCE_SYMBOL_FOLDER_LARGE = "large";
public static final String RESOURCE_SYMBOL_FOLDER_SVG = "svg"; public static final String RESOURCE_SYMBOL_FOLDER_SVG = "svg";
public static final String RESOURCE_SYMBOL_FOLDER_PNG = "png"; public static final String RESOURCE_SYMBOL_FOLDER_PNG = "png";
public enum ResourceSymbolSize { public enum ResourceSymbolSize {
SMALL, SMALL,
MEDIUM, MEDIUM,
@ -77,6 +77,7 @@ public final class Constants {
public static final String RESOURCE_SET_FOLDER_SMALL = "small"; public static final String RESOURCE_SET_FOLDER_SMALL = "small";
public static final String RESOURCE_SET_FOLDER_MEDIUM = ""; // empty, medium images laydown in "sets" folder, TODO: delete that and auto gen, use png for html, not gif public static final String RESOURCE_SET_FOLDER_MEDIUM = ""; // empty, medium images laydown in "sets" folder, TODO: delete that and auto gen, use png for html, not gif
public static final String RESOURCE_SET_FOLDER_SVG = "svg"; public static final String RESOURCE_SET_FOLDER_SVG = "svg";
public enum ResourceSetSize { public enum ResourceSetSize {
SMALL, SMALL,
MEDIUM, MEDIUM,

View file

@ -1,19 +1,20 @@
/** /**
* GathererSymbols.java * GathererSymbols.java
* * <p>
* Created on 25.08.2010 * Created on 25.08.2010
*/ */
package org.mage.plugins.card.dl.sources; package org.mage.plugins.card.dl.sources;
import mage.client.constants.Constants;
import org.mage.plugins.card.dl.DownloadJob;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import mage.client.constants.Constants;
import org.mage.plugins.card.dl.DownloadJob;
import static org.mage.plugins.card.dl.DownloadJob.fromURL; import static org.mage.plugins.card.dl.DownloadJob.fromURL;
import static org.mage.plugins.card.dl.DownloadJob.toFile; import static org.mage.plugins.card.dl.DownloadJob.toFile;
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir; import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
@ -36,12 +37,11 @@ public class DirectLinksForDownload implements Iterable<DownloadJob> {
directLinks.put(cardbackFilename, backsideUrl); directLinks.put(cardbackFilename, backsideUrl);
} }
public static File outDir; private File outDir;
public DirectLinksForDownload() { public DirectLinksForDownload() {
outDir = new File(getImagesDir() + Constants.RESOURCE_PATH_DEFAUL_IMAGES); this.outDir = new File(getImagesDir() + Constants.RESOURCE_PATH_DEFAULT_IMAGES);
if (!outDir.exists()) {
if (!outDir.exists()){
outDir.mkdirs(); outDir.mkdirs();
} }
} }

View file

@ -1,26 +1,7 @@
package org.mage.plugins.card.images; package org.mage.plugins.card.images;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.utils.CardImageUtils;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ComputationException; import com.google.common.collect.ComputationException;
import mage.client.constants.Constants; import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.util.SoftValuesLoadingCache; import mage.client.util.SoftValuesLoadingCache;
@ -29,6 +10,17 @@ import mage.view.CardView;
import net.java.truevfs.access.TFile; import net.java.truevfs.access.TFile;
import net.java.truevfs.access.TFileInputStream; import net.java.truevfs.access.TFileInputStream;
import net.java.truevfs.access.TFileOutputStream; import net.java.truevfs.access.TFileOutputStream;
import org.apache.log4j.Logger;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* This class stores ALL card images in a cache with soft values. this means * This class stores ALL card images in a cache with soft values. this means
@ -97,7 +89,8 @@ public final class ImageCache {
path = CardImageUtils.generateTokenImagePath(info); path = CardImageUtils.generateTokenImagePath(info);
if (path == null) { if (path == null) {
cardback = true; cardback = true;
path = DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename; // TODO: replace empty token by other default card, not cardback // TODO: replace empty token by other default card, not cardback
path = CardImageUtils.buildImagePathToDefault(DirectLinksForDownload.cardbackFilename);
} }
} else { } else {
path = CardImageUtils.buildImagePathToCard(info); path = CardImageUtils.buildImagePathToCard(info);
@ -256,7 +249,8 @@ public final class ImageCache {
info.setToken(true); info.setToken(true);
path = CardImageUtils.generateFullTokenImagePath(info); path = CardImageUtils.generateFullTokenImagePath(info);
if (path == null) { if (path == null) {
path = DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename; // TODO: replace empty token by other default card, not cardback // TODO: replace empty token by other default card, not cardback
path = CardImageUtils.buildImagePathToDefault(DirectLinksForDownload.cardbackFilename);
} }
} else { } else {
path = CardImageUtils.buildImagePathToCard(info); path = CardImageUtils.buildImagePathToCard(info);
@ -275,12 +269,13 @@ public final class ImageCache {
} }
public static BufferedImage getCardbackImage() { public static BufferedImage getCardbackImage() {
BufferedImage image = ImageCache.loadImage(new TFile(DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename)); BufferedImage image = ImageCache.loadImage(new TFile(CardImageUtils.buildImagePathToDefault(DirectLinksForDownload.cardbackFilename)));
image = getRoundCorner(image); image = getRoundCorner(image);
return image; return image;
} }
public static BufferedImage getMorphImage() { public static BufferedImage getMorphImage() {
// TODO: replace by morth image
CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK", ""); CardDownloadData info = new CardDownloadData("Morph", "KTK", "0", false, 0, "KTK", "");
info.setToken(true); info.setToken(true);
String path = CardImageUtils.generateTokenImagePath(info); String path = CardImageUtils.generateTokenImagePath(info);
@ -295,6 +290,7 @@ public final class ImageCache {
} }
public static BufferedImage getManifestImage() { public static BufferedImage getManifestImage() {
// TODO: replace by manifestest image
CardDownloadData info = new CardDownloadData("Manifest", "FRF", "0", false, 0, "FRF", ""); CardDownloadData info = new CardDownloadData("Manifest", "FRF", "0", false, 0, "FRF", "");
info.setToken(true); info.setToken(true);
String path = CardImageUtils.generateTokenImagePath(info); String path = CardImageUtils.generateTokenImagePath(info);
@ -367,10 +363,7 @@ public final class ImageCache {
if (file == null) { if (file == null) {
return false; return false;
} }
if (file.exists()) { return file.exists();
return true;
}
return false;
} }
public static BufferedImage getThumbnail(CardView card) { public static BufferedImage getThumbnail(CardView card) {

View file

@ -126,6 +126,11 @@ public final class CardImageUtils {
return path; return path;
} }
public static String buildImagePathToDefault(String defaultFileName) {
// default downloadable images like card back
return getImagesDir() + Constants.RESOURCE_PATH_DEFAULT_IMAGES + File.separator + defaultFileName;
}
public static String fixSetNameForWindows(String set) { public static String fixSetNameForWindows(String set) {
// windows can't create con folders // windows can't create con folders
if (set.equals("CON") || set.equals("con")) { if (set.equals("CON") || set.equals("con")) {