Add option to preferences to display full path to image of cards missing images.

This commit is contained in:
spjspj 2017-09-27 09:44:31 +10:00
parent d866234e89
commit 026e7d3e5d
4 changed files with 150 additions and 21 deletions

View file

@ -31,7 +31,8 @@ import java.util.UUID;
import static org.mage.plugins.card.constants.Constants.THUMBNAIL_SIZE_FULL;
/**
* Class for drawing the mage card object by using a form based JComponent approach
* Class for drawing the mage card object by using a form based JComponent
* approach
*
* @author arcane, nantuko, noxx, stravant
*/
@ -68,10 +69,13 @@ public class CardPanelComponentImpl extends CardPanel {
private final GlowText titleText;
private final GlowText ptText;
private final JLabel fullImageText;
private String fullImagePath = null;
private boolean hasImage = false;
private boolean displayTitleAnyway;
private boolean displayFullImagePath;
private final static Map<Key, BufferedImage> IMAGE_CACHE;
@ -202,7 +206,7 @@ public class CardPanelComponentImpl extends CardPanel {
counterPanel.setVisible(false);
}
// Ability icon
if (newGameCard.isAbility()) {
if (newGameCard.getAbilityType() == AbilityType.TRIGGERED) {
@ -211,13 +215,14 @@ public class CardPanelComponentImpl extends CardPanel {
setTypeIcon(ImageManagerImpl.instance.getActivatedAbilityImage(), "Activated Ability");
}
}
// Token icon
if (this.gameCard.isToken()) {
setTypeIcon(ImageManagerImpl.instance.getTokenIconImage(), "Token Permanent");
}
displayTitleAnyway = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_CARD_NAMES, "true").equals("true");
displayFullImagePath = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_FULL_IMAGE_PATH, "true").equals("true");
// Title Text
titleText = new GlowText();
@ -229,6 +234,12 @@ public class CardPanelComponentImpl extends CardPanel {
titleText.setWrap(true);
add(titleText);
// Full path to image text
fullImageText = new JLabel();
fullImageText.setText(fullImagePath);
fullImageText.setForeground(Color.BLACK);
add(fullImageText);
// PT Text
ptText = new GlowText();
if (gameCard.isCreature()) {
@ -300,10 +311,19 @@ public class CardPanelComponentImpl extends CardPanel {
doLayout();
}
private void setFullPath(String fullImagePath) {
this.fullImagePath = fullImagePath;
this.fullImagePath = this.fullImagePath.replaceAll("\\\\", "\\\\<br>");
this.fullImagePath = this.fullImagePath.replaceAll("/", "/<br>");
this.fullImagePath = "<html>" + this.fullImagePath + "</html>";
fullImageText.setText(!displayFullImagePath ? "" : this.fullImagePath);
doLayout();
}
@Override
public void transferResources(final CardPanel panelAbstract) {
if (panelAbstract instanceof CardPanelComponentImpl) {
CardPanelComponentImpl panel = (CardPanelComponentImpl)panelAbstract;
CardPanelComponentImpl panel = (CardPanelComponentImpl) panelAbstract;
synchronized (panel.imagePanel) {
if (panel.imagePanel.hasImage()) {
setImage(panel.imagePanel.getSrcImage());
@ -321,7 +341,7 @@ public class CardPanelComponentImpl extends CardPanel {
this.titleText.setGlowColor(Color.black);
}
}
@Override
protected void paintCard(Graphics2D g2d) {
float alpha = getAlpha();
@ -333,9 +353,9 @@ public class CardPanelComponentImpl extends CardPanel {
g2d.drawImage(
IMAGE_CACHE.get(
new Key(getWidth(), getHeight(), getCardWidth(), getCardHeight(), getCardXOffset(), getCardYOffset(),
hasImage, isSelected(), isChoosable(), gameCard.isPlayable(), gameCard.isCanAttack())),
hasImage, isSelected(), isChoosable(), gameCard.isPlayable(), gameCard.isCanAttack())),
0, 0, null);
g2d.dispose();
g2d.dispose();
}
private static BufferedImage createImage(Key key) {
@ -414,7 +434,7 @@ public class CardPanelComponentImpl extends CardPanel {
@Override
public void doLayout() {
super.doLayout();
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardXOffset = getCardXOffset();
@ -456,6 +476,7 @@ public class CardPanelComponentImpl extends CardPanel {
boolean showText = (!isAnimationPanel() && fontHeight < 12);
titleText.setVisible(showText);
ptText.setVisible(showText);
fullImageText.setVisible(fullImagePath != null);
if (showText) {
int fontSize = cardHeight / 11;
@ -465,6 +486,9 @@ public class CardPanelComponentImpl extends CardPanel {
int titleY = Math.round(cardHeight * (9f / 680)) + getTextOffset();
titleText.setBounds(cardXOffset + titleX, cardYOffset + titleY, cardWidth - titleX, cardHeight - titleY);
fullImageText.setFont(getFont().deriveFont(Font.PLAIN, 10));
fullImageText.setBounds(cardXOffset, cardYOffset + titleY, cardWidth, cardHeight - titleY);
ptText.setFont(getFont().deriveFont(Font.BOLD, fontSize));
Dimension ptSize = ptText.getPreferredSize();
ptText.setSize(ptSize.width, ptSize.height);
@ -486,7 +510,7 @@ public class CardPanelComponentImpl extends CardPanel {
public void setCardBounds(int x, int y, int cardWidth, int cardHeight) {
// Call to super
super.setCardBounds(x, y, cardWidth, cardHeight);
// Update image
if (imagePanel != null && imagePanel.getSrcImage() != null) {
updateArtImage();
@ -496,7 +520,7 @@ public class CardPanelComponentImpl extends CardPanel {
@Override
public void setAlpha(float alpha) {
super.setAlpha(alpha);
// Update components
if (alpha == 0) {
this.ptText.setVisible(false);
@ -529,6 +553,9 @@ public class CardPanelComponentImpl extends CardPanel {
} else {
srcImage = ImageCache.getThumbnail(gameCard);
}
if (srcImage == null) {
setFullPath(ImageCache.getFilePath(gameCard, getCardWidth()));
}
UI.invokeLater(() -> {
if (stamp == updateArtImageStamp) {
hasImage = srcImage != null;

View file

@ -157,6 +157,53 @@ public final class ImageCache {
});
}
public static String getFilePath(CardView card, int width) {
String key = getKey(card, card.getName(), Integer.toString(width));
boolean usesVariousArt = false;
if (key.matches(".*#usesVariousArt.*")) {
usesVariousArt = true;
key = key.replace("#usesVariousArt", "");
}
boolean thumbnail = false;
if (key.matches(".*#thumb.*")) {
thumbnail = true;
key = key.replace("#thumb", "");
}
Matcher m = KEY_PATTERN.matcher(key);
if (m.matches()) {
String name = m.group(1);
String set = m.group(2);
Integer type = Integer.parseInt(m.group(3));
String collectorId = m.group(4);
if (collectorId.equals("null")) {
collectorId = "0";
}
String tokenSetCode = m.group(5);
String tokenDescriptor = m.group(6);
CardDownloadData info = new CardDownloadData(name, set, collectorId, usesVariousArt, type, tokenSetCode, tokenDescriptor);
String path;
if (collectorId.isEmpty() || "0".equals(collectorId)) {
info.setToken(true);
path = CardImageUtils.generateTokenImagePath(info);
if (path == null) {
path = DirectLinksForDownload.outDir + File.separator + DirectLinksForDownload.cardbackFilename;
}
} else {
path = CardImageUtils.generateImagePath(info);
}
if (thumbnail && path.endsWith(".jpg")) {
return buildThumbnailPath(path);
}
return path;
}
return "";
}
private ImageCache() {
}