add Artist & adjust crop for modern/old frames

This commit is contained in:
Anthony Calosa
2021-09-04 18:54:49 +08:00
parent e1d8b5f01a
commit cd47c591b3
7 changed files with 53 additions and 26 deletions

View File

@@ -174,7 +174,7 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
artIndex = Math.max(artIndex0, IPaperCard.DEFAULT_ART_INDEX);
foil = foil0;
rarity = rarity0;
artist = (artist0 != null ? artist0 : IPaperCard.NO_ARTIST_NAME);
artist = (artist0 != null ? TextUtil.normalizeText(artist0) : IPaperCard.NO_ARTIST_NAME);
collectorNumber = (collectorNumber0 != null) && (collectorNumber0.length() > 0) ? collectorNumber0 : IPaperCard.NO_COLLECTOR_NUMBER;
}

View File

@@ -1,11 +1,13 @@
package forge.util;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import forge.item.IPaperCard;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
@@ -27,14 +29,19 @@ public class TextUtil {
.put(10, "X").put(9, "IX")
.put(5, "V").put(4, "IV").put(1, "I").build();
public final static String toRoman(int number) {
public static String toRoman(int number) {
if (number <= 0) {
return "";
}
int l = romanMap.floorKey(number);
return romanMap.get(l) + toRoman(number-l);
}
public static String normalizeText(String text) {
if (text == null)
return IPaperCard.NO_ARTIST_NAME;
return Normalizer.normalize(text, Normalizer.Form.NFD);
}
/**
* Safely converts an object to a String.
*

View File

@@ -32,7 +32,7 @@ public class CardAvatarImage implements FImage {
@Override
public void draw(Graphics g, float x, float y, float w, float h) {
//force to get the avatar since the the cardartcache & loadingcache is always cleared on screen change or the battle bar will display black
image = CardRenderer.getCardArt(imageKey, false, false, false, false, false, false, false, false);
image = CardRenderer.getCardArt(imageKey, false, false, false, false, false, false, false, false, true);
if (image == null) {
return; //can't draw anything if can't be loaded yet
}

View File

@@ -38,14 +38,14 @@ public class CardImage implements FImage {
image = ImageCache.getImage(card);
if (image == null) {
if (!Forge.enableUIMask.equals("Off")) //render this if mask is still loading
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top, Forge.enableUIMask.equals("Art"));
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top, Forge.enableUIMask.equals("Art"), true);
return; //can't draw anything if can't be loaded yet
}
}
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top, true);
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(card), false, x, y, w, h, CardStackPosition.Top, true, true);
}
else {
if (Forge.enableUIMask.equals("Full")) {

View File

@@ -8,6 +8,7 @@ import java.util.List;
import forge.ImageKeys;
import forge.assets.*;
import forge.item.PaperCard;
import forge.util.ImageUtil;
import org.apache.commons.lang3.StringUtils;
@@ -83,10 +84,10 @@ public class CardImageRenderer {
drawArt(null, g, x, y, w, h, false, true);
}
public static void drawCardImage(Graphics g, CardView card, boolean altState, float x, float y, float w, float h, CardStackPosition pos, boolean useCardBGTexture) {
drawCardImage(g, card, altState, x, y, w, h, pos, useCardBGTexture, false, false);
public static void drawCardImage(Graphics g, CardView card, boolean altState, float x, float y, float w, float h, CardStackPosition pos, boolean useCardBGTexture, boolean showArtist) {
drawCardImage(g, card, altState, x, y, w, h, pos, useCardBGTexture, false, false, showArtist);
}
public static void drawCardImage(Graphics g, CardView card, boolean altState, float x, float y, float w, float h, CardStackPosition pos, boolean useCardBGTexture, boolean noText, boolean isChoiceList) {
public static void drawCardImage(Graphics g, CardView card, boolean altState, float x, float y, float w, float h, CardStackPosition pos, boolean useCardBGTexture, boolean noText, boolean isChoiceList, boolean showArtist) {
updateStaticFields(w, h);
float blackBorderThickness = w * BLACK_BORDER_THICKNESS_RATIO;
@@ -142,14 +143,16 @@ public class CardImageRenderer {
float typeBoxHeight = 2 * TYPE_FONT.getCapHeight();
float ptBoxHeight = 0;
float textBoxHeight = h - headerHeight - artHeight - typeBoxHeight - outerBorderThickness - artInset;
if (state.isCreature() || state.isPlaneswalker() || state.getType().hasSubtype("Vehicle")) {
//if P/T box needed, make room for it
ptBoxHeight = 2 * PT_FONT.getCapHeight();
textBoxHeight -= ptBoxHeight;
}
else {
textBoxHeight -= 2 * artInset;
}
//space for artist
textBoxHeight -= 2 * PT_FONT.getCapHeight();
PaperCard paperCard = ImageUtil.getPaperCardFromImageKey(state.getImageKey());
String artist = "WOTC";
if (paperCard != null && !paperCard.getArtist().isEmpty())
artist = paperCard.getArtist();
float minTextBoxHeight = 2 * headerHeight;
if (textBoxHeight < minTextBoxHeight) {
if (textBoxHeight < minTextBoxHeight) {
@@ -223,6 +226,9 @@ public class CardImageRenderer {
Color[] ptColors = FSkinColor.tintColors(Color.WHITE, colors, CardRenderer.PT_BOX_TINT);
drawPtBox(g, card, state, ptColors, x, y - 2 * artInset, w, ptBoxHeight, noText);
}
//draw artist
if (showArtist)
g.drawOutlinedText(artist, TEXT_FONT, Color.WHITE, Color.DARK_GRAY, x+(TYPE_FONT.getCapHeight()/2), y+(TYPE_FONT.getCapHeight()/2), w, h, false, Align.left, false);
}
private static void drawHeader(Graphics g, CardView card, CardStateView state, Color[] colors, float x, float y, float w, float h, boolean noText) {
@@ -306,7 +312,7 @@ public class CardImageRenderer {
altArt = CardRenderer.getAlternateCardArt(cv.getAlternateState().getImageKey(), cv.getAlternateState().isPlaneswalker());
else {
altArt = CardRenderer.getCardArt(cv.getAlternateState().getImageKey(), cv.isSplitCard(), cv.getAlternateState().isPlane() || cv.getAlternateState().isPhenomenon(), cv.getText().contains("Aftermath"),
cv.getAlternateState().getType().hasSubtype("Saga"), cv.getAlternateState().getType().hasSubtype("Class"), cv.getAlternateState().getType().isDungeon(), cv.isFlipCard(), cv.getAlternateState().isPlaneswalker());
cv.getAlternateState().getType().hasSubtype("Saga"), cv.getAlternateState().getType().hasSubtype("Class"), cv.getAlternateState().getType().isDungeon(), cv.isFlipCard(), cv.getAlternateState().isPlaneswalker(), CardRenderer.isModernFrame(cv));
}
}
}
@@ -628,7 +634,7 @@ public class CardImageRenderer {
}
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) { //support drawing card image manually if card image not found
drawCardImage(g, card, altState, x, y, w, h, CardStackPosition.Top, true);
drawCardImage(g, card, altState, x, y, w, h, CardStackPosition.Top, true, true);
} else {
float radius = (h - w)/8;
float wh_Adj = ForgeConstants.isGdxPortLandscape && isCurrentCard ? 1.38f:1.0f;

View File

@@ -211,15 +211,20 @@ public class CardRenderer {
public static FImageComplex getCardArt(IPaperCard pc, boolean backFace) {
CardType type = pc.getRules().getType();
return getCardArt(pc.getImageKey(backFace), pc.getRules().getSplitType() == CardSplitType.Split, type.isPlane() || type.isPhenomenon(),pc.getRules().getOracleText().contains("Aftermath"), type.hasSubtype("Saga"), type.hasSubtype("Class"), type.isDungeon(), CardSplitType.Flip.equals(pc.getRules().getSplitType()), type.isPlaneswalker());
return getCardArt(pc.getImageKey(backFace), pc.getRules().getSplitType() == CardSplitType.Split,
type.isPlane() || type.isPhenomenon(),pc.getRules().getOracleText().contains("Aftermath"),
type.hasSubtype("Saga"), type.hasSubtype("Class"), type.isDungeon(), CardSplitType.Flip.equals(pc.getRules().getSplitType()),
type.isPlaneswalker(), isModernFrame(pc));
}
public static FImageComplex getCardArt(CardView card) {
CardTypeView type = card.getCurrentState().getType();
return getCardArt(card.getCurrentState().getImageKey(), card.isSplitCard(), type.isPlane() || type.isPhenomenon(),card.getText().contains("Aftermath"), type.hasSubtype("Saga"), type.hasSubtype("Class"), type.isDungeon(), card.isFlipCard(), type.isPlaneswalker());
return getCardArt(card.getCurrentState().getImageKey(), card.isSplitCard(), type.isPlane() || type.isPhenomenon(),
card.getText().contains("Aftermath"), type.hasSubtype("Saga"), type.hasSubtype("Class"), type.isDungeon(),
card.isFlipCard(), type.isPlaneswalker(), isModernFrame(card));
}
public static FImageComplex getCardArt(String imageKey, boolean isSplitCard, boolean isHorizontalCard, boolean isAftermathCard, boolean isSaga, boolean isClass, boolean isDungeon, boolean isFlipCard, boolean isPlanesWalker) {
public static FImageComplex getCardArt(String imageKey, boolean isSplitCard, boolean isHorizontalCard, boolean isAftermathCard, boolean isSaga, boolean isClass, boolean isDungeon, boolean isFlipCard, boolean isPlanesWalker, boolean isModernFrame) {
FImageComplex cardArt = cardArtCache.get(imageKey);
boolean isClassicModule = classicModuleCardtoCrop.contains(imageKey.substring(ImageKeys.CARD_PREFIX.length()).replace(".jpg","").replace(".png", ""));
if (cardArt == null) {
@@ -285,9 +290,10 @@ public class CardRenderer {
return cardArt;
}
} else {
x = w * 0.1f;
y = h * 0.11f;
w -= 2 * x;
//adjust smaller crop
x = isModernFrame ? w * 0.1f :w * 0.12f;
y = isModernFrame ? h * 0.12f : h * 0.11f;
w -= isModernFrame ? 2 * x : 2.1f * x;
h *= CARD_ART_HEIGHT_PERCENTAGE;
float ratioRatio = w / h / CARD_ART_RATIO;
if (ratioRatio > 1) { //if too wide, shrink width
@@ -534,7 +540,7 @@ public class CardRenderer {
}
if (image != null) {
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos, true);
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos, true, true);
} else {
if (Forge.enableUIMask.equals("Full")) {
if (ImageCache.isBorderlessCardArt(image))
@@ -558,7 +564,7 @@ public class CardRenderer {
}
} else {
//if card has invalid or no texture due to sudden changes in ImageCache, draw CardImageRenderer instead and wait for it to refresh automatically
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos, Forge.enableUIMask.equals("Art"));
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos, Forge.enableUIMask.equals("Art"), true);
}
}
public static void drawCard(Graphics g, CardView card, float x, float y, float w, float h, CardStackPosition pos, boolean rotate) {
@@ -578,7 +584,11 @@ public class CardRenderer {
}
if (image != null) {
if (image == ImageCache.defaultImage || Forge.enableUIMask.equals("Art")) {
CardImageRenderer.drawCardImage(g, card, showAltState, x, y, w, h, pos, true, false, isChoiceList);
float oldAlpha = g.getfloatAlphaComposite();
if (card.isPhasedOut())
g.setAlphaComposite(0.2f);
CardImageRenderer.drawCardImage(g, card, showAltState, x, y, w, h, pos, true, false, isChoiceList, !showCardIdOverlay(card));
g.setAlphaComposite(oldAlpha);
} else if (showsleeves) {
if (!card.isForeTold())
g.drawImage(sleeves, x, y, w, h);
@@ -620,7 +630,11 @@ public class CardRenderer {
drawFoilEffect(g, card, x, y, w, h, false);
} else {
//if card has invalid or no texture due to sudden changes in ImageCache, draw CardImageRenderer instead and wait for it to refresh automatically
CardImageRenderer.drawCardImage(g, card, showAltState, x, y, w, h, pos, Forge.enableUIMask.equals("Art"), false, isChoiceList);
float oldAlpha = g.getfloatAlphaComposite();
if (card.isPhasedOut())
g.setAlphaComposite(0.2f);
CardImageRenderer.drawCardImage(g, card, showAltState, x, y, w, h, pos, Forge.enableUIMask.equals("Art"), false, isChoiceList, !showCardIdOverlay(card));
g.setAlphaComposite(oldAlpha);
}
}

View File

@@ -1025,7 +1025,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
}
if (paperCard != null && Forge.enableUIMask.equals("Art")) {
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(paperCard), false,
x + (w - w * scale) / 2, y + (h - h * scale) / 1.5f, w * scale, h * scale, CardStackPosition.Top, true, false, false);
x + (w - w * scale) / 2, y + (h - h * scale) / 1.5f, w * scale, h * scale, CardStackPosition.Top, true, false, false, true);
} else {
TextureRegion tr = ImageCache.croppedBorderImage(dpImg);
g.drawImage(tr, x + (w - w * scale) / 2, y + (h - h * scale) / 1.5f, w * scale, h * scale);