GUI: added missing image info in card popup hint (works in any render mode, support cards, tokens, emblems, etc - can be disabled in Preferences, related to #7759, #2158);

This commit is contained in:
Oleg Agafonov 2024-02-19 12:40:35 +04:00
parent e26445774b
commit 34816be219
7 changed files with 83 additions and 52 deletions

View file

@ -9,9 +9,11 @@ import mage.constants.*;
import mage.view.CardView;
import mage.view.CounterView;
import mage.view.PermanentView;
import net.java.truevfs.access.TFile;
import org.jdesktop.swingx.JXPanel;
import org.mage.card.arcane.ManaSymbols;
import org.mage.card.arcane.UI;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.swing.*;
import java.awt.*;
@ -402,6 +404,15 @@ public final class GuiDisplayUtil {
buffer.append("<p style='margin: 2px'><b>Card Zone:</b> ").append(zone).append("</p>");
}
// missing image info in card popup
boolean displayFullImagePath = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_FULL_IMAGE_PATH, "false").equals("true");
if (displayFullImagePath) {
String imageFile = CardImageUtils.buildImagePathToCardView(card);
if (imageFile.startsWith("ERROR") || !(new TFile(imageFile).exists())) {
buffer.append("<p style='margin: 2px'><b>Missing image:</b> ").append(imageFile).append("</p>");
}
}
buffer.append("<br></body></html>");
return buffer;
}

View file

@ -11,7 +11,6 @@ public class CardDownloadData {
private String name;
private String downloadName;
private String fileName = "";
private String set;
private final String collectorId;
private final Integer imageNumber;
@ -25,18 +24,13 @@ public class CardDownloadData {
private String tokenClassName;
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber) {
this(name, setCode, collectorId, usesVariousArt, imageNumber, false, "");
this(name, setCode, collectorId, usesVariousArt, imageNumber, false);
}
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token) {
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, false, false, "");
}
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token, String fileName) {
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, false, false, "");
this.fileName = fileName;
}
public CardDownloadData(String name, String setCode, String collectorId, boolean usesVariousArt, Integer imageNumber, boolean token, boolean twoFacedCard, boolean secondSide) {
this(name, setCode, collectorId, usesVariousArt, imageNumber, token, twoFacedCard, secondSide, "");
}
@ -56,7 +50,6 @@ public class CardDownloadData {
public CardDownloadData(final CardDownloadData card) {
this.name = card.name;
this.downloadName = card.downloadName;
this.fileName = card.fileName;
this.set = card.set;
this.collectorId = card.collectorId;
this.imageNumber = card.imageNumber;
@ -144,14 +137,6 @@ public class CardDownloadData {
return name;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public void setName(String name) {
this.name = name;
}

View file

@ -532,8 +532,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
"0",
false,
token.getImageNumber(),
true,
token.getImageFileName()
true
);
allCardsUrls.add(card);
});

View file

@ -1,10 +1,14 @@
package org.mage.plugins.card.utils;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.TokenRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants;
import mage.client.dialog.PreferencesDialog;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import mage.view.CardView;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
@ -113,7 +117,6 @@ public final class CardImageUtils {
}
public static String buildImagePathToCardOrToken(CardDownloadData card) {
String setPath = buildImagePathToSet(card);
String prefixType = "";
@ -121,10 +124,7 @@ public final class CardImageUtils {
prefixType = " " + card.getImageNumber();
}
String cardName = card.getFileName();
if (cardName.isEmpty()) {
cardName = prepareCardNameForFile(card.getName());
}
String cardName = prepareCardNameForFile(card.getName());
String finalFileName;
if (card.getUsesVariousArt()) {
@ -138,6 +138,49 @@ public final class CardImageUtils {
return setPath + finalFileName;
}
/**
* Special version for CardView and direct images info
* (real card images uses image cache and key logic, see ImageCache.getKey)
*
* @return relative image path or "ERROR + reason"
*/
public static String buildImagePathToCardView(CardView card) {
String imageFile;
if (card.getMageObjectType().isUseTokensRepository()) {
// token images
CardDownloadData cardData = new CardDownloadData(
card.getName().replace(" Token", ""),
card.getExpansionSetCode(),
"0",
false,
card.getImageNumber(),
true);
imageFile = CardImageUtils.buildImagePathToCardOrToken(cardData);
} else {
TokenRepository.instance.getAll();
// card images
// workaround to find various art settings first
CardInfo cardInfo = CardRepository.instance.findCardWithPreferredSetAndNumber(
card.getName(),
card.getExpansionSetCode(),
card.getCardNumber()
);
if (cardInfo != null) {
CardDownloadData cardData = new CardDownloadData(
cardInfo.getName(),
cardInfo.getSetCode(),
cardInfo.getCardNumber(),
cardInfo.usesVariousArt(),
card.getImageNumber()
);
imageFile = CardImageUtils.buildImagePathToCardOrToken(cardData);
} else {
imageFile = "ERROR: can't find card info in repository - " + card.getName();
}
}
return imageFile;
}
public static String generateFaceImagePath(String cardName, String setCode) {
return getImagesDir() + File.separator + "FACE" + File.separator + fixSetNameForWindows(setCode) + File.separator + prepareCardNameForFile(cardName) + ".jpg";
}

View file

@ -14,21 +14,18 @@ public class TokenInfo {
private final String classFileName;
private final String imageFileName;
private String downloadUrl = "";
public TokenInfo(TokenType tokenType, String name, String setCode, Integer imageNumber) {
this(tokenType, name, setCode, imageNumber, "", "");
this(tokenType, name, setCode, imageNumber, "");
}
public TokenInfo(TokenType tokenType, String name, String setCode, Integer imageNumber, String classFileName, String imageFileName) {
public TokenInfo(TokenType tokenType, String name, String setCode, Integer imageNumber, String classFileName) {
this.tokenType = tokenType;
this.name = name;
this.setCode = setCode;
this.imageNumber = imageNumber;
this.classFileName = classFileName;
this.imageFileName = imageFileName;
}
@Override
@ -44,10 +41,6 @@ public class TokenInfo {
return name;
}
public String getImageFileName() {
return imageFileName;
}
public String getSetCode() {
return setCode;
}

View file

@ -117,12 +117,6 @@ public enum TokenRepository {
imageNumber = Integer.parseInt(params.get(4));
}
// image file name
String imageFileName = "";
if (params.size() > 5 && !params.get(5).isEmpty()) {
imageFileName = params.get(5);
}
// token class name (uses for images search for render)
String tokenClassName = "";
if (params.size() > 7 && !params.get(6).isEmpty()) {
@ -190,7 +184,7 @@ public enum TokenRepository {
}
// OK
TokenInfo token = new TokenInfo(tokenType, tokenName, setCode, imageNumber, tokenClassName, imageFileName);
TokenInfo token = new TokenInfo(tokenType, tokenName, setCode, imageNumber, tokenClassName);
list.add(token);
} finally {
line = reader.readLine();

View file

@ -43,27 +43,29 @@ package mage.constants;
* @author LevelX2
*/
public enum MageObjectType {
ABILITY_STACK("Ability on the Stack", false, false),
CARD("Card", false, true),
COPY_CARD("Copy of a Card", false, true),
TOKEN("Token", true, true),
SPELL("Spell", false, true),
PERMANENT("Permanent", true, true),
DUNGEON("Dungeon", false, false),
EMBLEM("Emblem", false, false),
COMMANDER("Commander", false, false),
DESIGNATION("Designation", false, false),
PLANE("Plane", false, false),
NULL("NullObject", false, false);
ABILITY_STACK("Ability on the Stack", false, false, false),
CARD("Card", false, true, false),
COPY_CARD("Copy of a Card", false, true, false),
TOKEN("Token", true, true, true),
SPELL("Spell", false, true, false),
PERMANENT("Permanent", true, true, false),
DUNGEON("Dungeon", false, false, true),
EMBLEM("Emblem", false, false, true),
COMMANDER("Commander", false, false, true),
DESIGNATION("Designation", false, false, true),
PLANE("Plane", false, false, true),
NULL("NullObject", false, false, false);
private final String text;
private final boolean permanent;
private final boolean canHaveCounters;
private final boolean useTokensRepository; // card image from tokens or cards repository
MageObjectType(String text, boolean permanent, boolean canHaveCounters) {
MageObjectType(String text, boolean permanent, boolean canHaveCounters, boolean useTokensRepository) {
this.text = text;
this.permanent = permanent;
this.canHaveCounters = canHaveCounters;
this.useTokensRepository = useTokensRepository;
}
@Override
@ -79,4 +81,8 @@ public enum MageObjectType {
return canHaveCounters;
}
public boolean isUseTokensRepository() {
return useTokensRepository;
}
}