mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
update ImageFetcher & CardImageRenderer
- allow zoomed cards to fetch image if possible
This commit is contained in:
@@ -712,20 +712,22 @@ public class CardImageRenderer {
|
|||||||
x += pieceWidths[i];
|
x += pieceWidths[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static class CachedCardImageRenderer extends CachedCardImage {
|
||||||
|
|
||||||
|
public CachedCardImageRenderer(String key) {
|
||||||
|
super(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onImageFetched() {
|
||||||
|
ImageCache.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
|
public static void drawZoom(Graphics g, CardView card, GameView gameView, boolean altState, float x, float y, float w, float h, float dispW, float dispH, boolean isCurrentCard) {
|
||||||
boolean canshow = MatchController.instance.mayView(card);
|
boolean canshow = MatchController.instance.mayView(card);
|
||||||
Texture image = null;
|
String key = card.getState(altState).getImageKey();
|
||||||
try {
|
Texture image = new CachedCardImageRenderer(key).getImage();
|
||||||
image = ImageCache.getImage(card.getState(altState).getImageKey(), true);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
//System.err.println(card.toString()+" : " +ex.getMessage());
|
|
||||||
//TODO: don't know why this is needed, needs further investigation...
|
|
||||||
if (!card.hasAlternateState()) {
|
|
||||||
altState = false;
|
|
||||||
image = ImageCache.getImage(card.getState(altState).getImageKey(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
|
FImage sleeves = MatchController.getPlayerSleeve(card.getOwner());
|
||||||
if (image == null) { //draw details if can't draw zoom
|
if (image == null) { //draw details if can't draw zoom
|
||||||
drawDetails(g, card, gameView, altState, x, y, w, h);
|
drawDetails(g, card, gameView, altState, x, y, w, h);
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ public abstract class ImageFetcher {
|
|||||||
if (useArtCrop) {
|
if (useArtCrop) {
|
||||||
filename = TextUtil.fastReplace(filename, ".full", ".artcrop");
|
filename = TextUtil.fastReplace(filename, ".full", ".artcrop");
|
||||||
}
|
}
|
||||||
|
boolean updateLink = false;
|
||||||
|
if ("back".equals(face)) {// seems getimage relative path don't process variants for back faces.
|
||||||
|
try {
|
||||||
|
filename = TextUtil.fastReplace(filename, "1.full", imageKey.substring(imageKey.lastIndexOf('|') + 1, imageKey.indexOf('$')) + ".full");
|
||||||
|
updateLink = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
filename = paperCard.getCardAltImageKey();
|
||||||
|
updateLink = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
destFile = new File(ForgeConstants.CACHE_CARD_PICS_DIR, filename + ".jpg");
|
destFile = new File(ForgeConstants.CACHE_CARD_PICS_DIR, filename + ".jpg");
|
||||||
|
|
||||||
//skip ftp if using art crop
|
//skip ftp if using art crop
|
||||||
@@ -155,8 +165,14 @@ public abstract class ImageFetcher {
|
|||||||
//move priority of ftp image here
|
//move priority of ftp image here
|
||||||
StringBuilder setDownload = new StringBuilder(ForgeConstants.URL_PIC_DOWNLOAD);
|
StringBuilder setDownload = new StringBuilder(ForgeConstants.URL_PIC_DOWNLOAD);
|
||||||
if (!hasSetLookup) {
|
if (!hasSetLookup) {
|
||||||
setDownload.append(ImageUtil.getDownloadUrl(paperCard, face));
|
if (!updateLink) {
|
||||||
downloadUrls.add(setDownload.toString());
|
setDownload.append(ImageUtil.getDownloadUrl(paperCard, face));
|
||||||
|
downloadUrls.add(setDownload.toString());
|
||||||
|
} else {
|
||||||
|
String url = ImageUtil.getDownloadUrl(paperCard, face);
|
||||||
|
setDownload.append(TextUtil.fastReplace(url, "1.full", imageKey.substring(imageKey.lastIndexOf('|') + 1, imageKey.indexOf('$')) + ".full"));
|
||||||
|
downloadUrls.add(setDownload.toString());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
List<PaperCard> clones = StaticData.instance().getCommonCards().getAllCards(paperCard.getName());
|
List<PaperCard> clones = StaticData.instance().getCommonCards().getAllCards(paperCard.getName());
|
||||||
for (PaperCard pc : clones) {
|
for (PaperCard pc : clones) {
|
||||||
@@ -234,15 +250,13 @@ public abstract class ImageFetcher {
|
|||||||
observers.add(callback);
|
observers.add(callback);
|
||||||
currentFetches.put(destPath, observers);
|
currentFetches.put(destPath, observers);
|
||||||
|
|
||||||
final Runnable notifyObservers = new Runnable() {
|
final Runnable notifyObservers = () -> {
|
||||||
public void run() {
|
FThreads.assertExecutedByEdt(true);
|
||||||
FThreads.assertExecutedByEdt(true);
|
|
||||||
|
|
||||||
for (Callback o : currentFetches.get(destPath)) {
|
for (Callback o : currentFetches.get(destPath)) {
|
||||||
o.onImageFetched();
|
o.onImageFetched();
|
||||||
}
|
|
||||||
currentFetches.remove(destPath);
|
|
||||||
}
|
}
|
||||||
|
currentFetches.remove(destPath);
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
ThreadUtil.getServicePool().submit(getDownloadTask(downloadUrls.toArray(new String[0]), destPath, notifyObservers));
|
ThreadUtil.getServicePool().submit(getDownloadTask(downloadUrls.toArray(new String[0]), destPath, notifyObservers));
|
||||||
|
|||||||
Reference in New Issue
Block a user