mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Support rendering items for Card objects more accurately
This commit is contained in:
@@ -16,30 +16,38 @@ public class ImageKeys {
|
|||||||
public static final String MORPH_IMAGE = "morph";
|
public static final String MORPH_IMAGE = "morph";
|
||||||
|
|
||||||
public static final String BACKFACE_POSTFIX = "$alt";
|
public static final String BACKFACE_POSTFIX = "$alt";
|
||||||
|
|
||||||
|
public static String getImageKey(PaperCard pc, boolean altState) {
|
||||||
|
return ImageKeys.CARD_PREFIX + pc.getName() + CardDb.NameSetSeparator + pc.getEdition() + CardDb.NameSetSeparator + pc.getArtIndex() + (altState ? BACKFACE_POSTFIX : "");
|
||||||
|
}
|
||||||
|
|
||||||
// Inventory items don't have to know how a certain client should draw them.
|
// Inventory items don't have to know how a certain client should draw them.
|
||||||
// That's why this method is not encapsulated and overloaded in the InventoryItem descendants
|
// That's why this method is not encapsulated and overloaded in the InventoryItem descendants
|
||||||
public static String getImageKey(InventoryItem ii, boolean altState) {
|
public static String getImageKey(InventoryItem ii, boolean altState) {
|
||||||
if ( ii instanceof PaperCard ) {
|
if (ii instanceof PaperCard) {
|
||||||
PaperCard cp = (PaperCard)ii;
|
return getImageKey((PaperCard)ii, altState);
|
||||||
return ImageKeys.CARD_PREFIX + cp.getName() + CardDb.NameSetSeparator + cp.getEdition() + CardDb.NameSetSeparator + cp.getArtIndex() + (altState ? BACKFACE_POSTFIX : "");
|
|
||||||
}
|
}
|
||||||
if ( ii instanceof TournamentPack )
|
if (ii instanceof TournamentPack) {
|
||||||
return ImageKeys.TOURNAMENTPACK_PREFIX + ((TournamentPack)ii).getEdition();
|
return ImageKeys.TOURNAMENTPACK_PREFIX + ((TournamentPack)ii).getEdition();
|
||||||
if ( ii instanceof BoosterPack ) {
|
}
|
||||||
|
if (ii instanceof BoosterPack) {
|
||||||
BoosterPack bp = (BoosterPack)ii;
|
BoosterPack bp = (BoosterPack)ii;
|
||||||
int cntPics = StaticData.instance().getEditions().get(bp.getEdition()).getCntBoosterPictures();
|
int cntPics = StaticData.instance().getEditions().get(bp.getEdition()).getCntBoosterPictures();
|
||||||
String suffix = (1 >= cntPics) ? "" : ("_" + bp.getArtIndex());
|
String suffix = (1 >= cntPics) ? "" : ("_" + bp.getArtIndex());
|
||||||
return ImageKeys.BOOSTER_PREFIX + bp.getEdition() + suffix;
|
return ImageKeys.BOOSTER_PREFIX + bp.getEdition() + suffix;
|
||||||
}
|
}
|
||||||
if ( ii instanceof FatPack )
|
if (ii instanceof FatPack) {
|
||||||
return ImageKeys.FATPACK_PREFIX + ((FatPack)ii).getEdition();
|
return ImageKeys.FATPACK_PREFIX + ((FatPack)ii).getEdition();
|
||||||
if ( ii instanceof BoosterBox )
|
}
|
||||||
|
if (ii instanceof BoosterBox) {
|
||||||
return ImageKeys.BOOSTERBOX_PREFIX + ((BoosterBox)ii).getEdition();
|
return ImageKeys.BOOSTERBOX_PREFIX + ((BoosterBox)ii).getEdition();
|
||||||
if ( ii instanceof PreconDeck )
|
}
|
||||||
|
if (ii instanceof PreconDeck) {
|
||||||
return ImageKeys.PRECON_PREFIX + ((PreconDeck)ii).getImageFilename();
|
return ImageKeys.PRECON_PREFIX + ((PreconDeck)ii).getImageFilename();
|
||||||
if ( ii instanceof PaperToken )
|
}
|
||||||
|
if (ii instanceof PaperToken) {
|
||||||
return ImageKeys.TOKEN_PREFIX + ((PaperToken)ii).getImageFilename();
|
return ImageKeys.TOKEN_PREFIX + ((PaperToken)ii).getImageFilename();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3721,6 +3721,14 @@ public class Card extends GameEntity implements Comparable<Card> {
|
|||||||
return this.baseLoyalty;
|
return this.baseLoyalty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int getCurrentLoyalty() {
|
||||||
|
int loyalty = getCounters(CounterType.LOYALTY);
|
||||||
|
if (loyalty == 0) {
|
||||||
|
loyalty = this.baseLoyalty;
|
||||||
|
}
|
||||||
|
return loyalty;
|
||||||
|
}
|
||||||
|
|
||||||
// values that are printed on card
|
// values that are printed on card
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import forge.card.CardCharacteristicName;
|
|||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
import forge.card.mana.ManaCost;
|
import forge.card.mana.ManaCost;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CounterType;
|
|
||||||
import forge.game.combat.Combat;
|
import forge.game.combat.Combat;
|
||||||
import forge.gui.CardContainer;
|
import forge.gui.CardContainer;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
@@ -623,12 +622,11 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
|||||||
// P/T overlay
|
// P/T overlay
|
||||||
String sPt = "";
|
String sPt = "";
|
||||||
if (card.isCreature() && card.isPlaneswalker()) {
|
if (card.isCreature() && card.isPlaneswalker()) {
|
||||||
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCounters(CounterType.LOYALTY));
|
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCurrentLoyalty());
|
||||||
} else if (card.isCreature()) {
|
} else if (card.isCreature()) {
|
||||||
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
|
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
|
||||||
} else if (card.isPlaneswalker()) {
|
} else if (card.isPlaneswalker()) {
|
||||||
int loyalty = card.getCounters(CounterType.LOYALTY);
|
sPt = String.valueOf(card.getCurrentLoyalty());
|
||||||
sPt = String.valueOf(loyalty == 0 ? card.getBaseLoyalty() : loyalty);
|
|
||||||
}
|
}
|
||||||
this.ptText.setText(sPt);
|
this.ptText.setText(sPt);
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import forge.ImageKeys;
|
|||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.player.IHasIcon;
|
import forge.game.player.IHasIcon;
|
||||||
import forge.item.InventoryItem;
|
import forge.item.InventoryItem;
|
||||||
|
import forge.item.PaperCard;
|
||||||
import forge.properties.ForgeConstants;
|
import forge.properties.ForgeConstants;
|
||||||
import forge.screens.match.FControl;
|
import forge.screens.match.FControl;
|
||||||
|
|
||||||
@@ -84,6 +85,9 @@ public class ImageCache {
|
|||||||
return getImage(key, true);
|
return getImage(key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Texture getImage(PaperCard pc) {
|
||||||
|
return getImage(ImageKeys.getImageKey(pc, false), true);
|
||||||
|
}
|
||||||
public static Texture getImage(InventoryItem ii) {
|
public static Texture getImage(InventoryItem ii) {
|
||||||
return getImage(ImageKeys.getImageKey(ii, false), true);
|
return getImage(ImageKeys.getImageKey(ii, false), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
|||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
import forge.Forge.Graphics;
|
import forge.Forge.Graphics;
|
||||||
|
import forge.ImageKeys;
|
||||||
import forge.assets.FSkinColor;
|
import forge.assets.FSkinColor;
|
||||||
import forge.assets.FSkinFont;
|
import forge.assets.FSkinFont;
|
||||||
import forge.assets.FSkinImage;
|
import forge.assets.FSkinImage;
|
||||||
@@ -157,14 +158,20 @@ public class CardRenderer {
|
|||||||
return Math.round(MANA_SYMBOL_SIZE + FSkinFont.get(12).getFont().getLineHeight() + 3 * FList.PADDING + 1);
|
return Math.round(MANA_SYMBOL_SIZE + FSkinFont.get(12).getFont().getLineHeight() + 3 * FList.PADDING + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<PaperCard, TextureRegion> cardArtCache = new HashMap<PaperCard, TextureRegion>();
|
private static Map<String, TextureRegion> cardArtCache = new HashMap<String, TextureRegion>();
|
||||||
private static final float CARD_ART_RATIO = 1.302f;
|
private static final float CARD_ART_RATIO = 1.302f;
|
||||||
|
|
||||||
//extract card art from the given card
|
//extract card art from the given card
|
||||||
public static TextureRegion getCardArt(PaperCard paperCard) {
|
public static TextureRegion getCardArt(PaperCard paperCard) {
|
||||||
TextureRegion cardArt = cardArtCache.get(paperCard);
|
return getCardArt(ImageKeys.getImageKey(paperCard, false));
|
||||||
|
}
|
||||||
|
public static TextureRegion getCardArt(Card card) {
|
||||||
|
return getCardArt(card.getImageKey());
|
||||||
|
}
|
||||||
|
public static TextureRegion getCardArt(String imageKey) {
|
||||||
|
TextureRegion cardArt = cardArtCache.get(imageKey);
|
||||||
if (cardArt == null) {
|
if (cardArt == null) {
|
||||||
Texture image = ImageCache.getImage(paperCard);
|
Texture image = ImageCache.getImage(imageKey, true);
|
||||||
float w = image.getWidth();
|
float w = image.getWidth();
|
||||||
float h = image.getHeight();
|
float h = image.getHeight();
|
||||||
float x = w * 0.1f;
|
float x = w * 0.1f;
|
||||||
@@ -183,22 +190,31 @@ public class CardRenderer {
|
|||||||
y += dh / 2;
|
y += dh / 2;
|
||||||
}
|
}
|
||||||
cardArt = new TextureRegion(image, Math.round(x), Math.round(y), Math.round(w), Math.round(h));
|
cardArt = new TextureRegion(image, Math.round(x), Math.round(y), Math.round(w), Math.round(h));
|
||||||
cardArtCache.put(paperCard, cardArt);
|
cardArtCache.put(imageKey, cardArt);
|
||||||
}
|
}
|
||||||
return cardArt;
|
return cardArt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void drawCardListItem(Graphics g, FSkinFont font, FSkinColor foreColor, Card card, int count, float x, float y, float w, float h) {
|
||||||
|
drawCardListItem(g, font, foreColor, getCardArt(card), card.getRules(), card.getCurSetCode(),
|
||||||
|
card.getRarity(), card.getNetAttack(), card.getNetDefense(),
|
||||||
|
card.getCurrentLoyalty(), count, x, y, w, h);
|
||||||
|
}
|
||||||
public static void drawCardListItem(Graphics g, FSkinFont font, FSkinColor foreColor, PaperCard paperCard, int count, float x, float y, float w, float h) {
|
public static void drawCardListItem(Graphics g, FSkinFont font, FSkinColor foreColor, PaperCard paperCard, int count, float x, float y, float w, float h) {
|
||||||
TextureRegion cardArt = getCardArt(paperCard);
|
CardRules cardRules = paperCard.getRules();
|
||||||
|
drawCardListItem(g, font, foreColor, getCardArt(paperCard), cardRules, paperCard.getEdition(),
|
||||||
|
paperCard.getRarity(), cardRules.getIntPower(), cardRules.getIntToughness(),
|
||||||
|
cardRules.getInitialLoyalty(), count, x, y, w, h);
|
||||||
|
}
|
||||||
|
public static void drawCardListItem(Graphics g, FSkinFont font, FSkinColor foreColor, TextureRegion cardArt, CardRules cardRules, String set, CardRarity rarity, int power, int toughness, int loyalty, int count, float x, float y, float w, float h) {
|
||||||
float cardArtHeight = h + 2 * FList.PADDING;
|
float cardArtHeight = h + 2 * FList.PADDING;
|
||||||
float cardArtWidth = cardArtHeight * CARD_ART_RATIO;
|
float cardArtWidth = cardArtHeight * CARD_ART_RATIO;
|
||||||
g.drawImage(cardArt, x - FList.PADDING, y - FList.PADDING, cardArtWidth, cardArtHeight);
|
g.drawImage(cardArt, x - FList.PADDING, y - FList.PADDING, cardArtWidth, cardArtHeight);
|
||||||
x += cardArtWidth;
|
x += cardArtWidth;
|
||||||
|
|
||||||
CardRules cardRules = paperCard.getRules();
|
String name = cardRules.getName();
|
||||||
ManaCost manaCost = cardRules.getManaCost();
|
ManaCost manaCost = cardRules.getManaCost();
|
||||||
float availableNameWidth = w - CardFaceSymbols.getWidth(manaCost, MANA_SYMBOL_SIZE) - cardArtWidth - FList.PADDING;
|
float availableNameWidth = w - CardFaceSymbols.getWidth(manaCost, MANA_SYMBOL_SIZE) - cardArtWidth - FList.PADDING;
|
||||||
String name = paperCard.getName();
|
|
||||||
if (count > 0) { //preface name with count if applicable
|
if (count > 0) { //preface name with count if applicable
|
||||||
name = count + " " + name;
|
name = count + " " + name;
|
||||||
}
|
}
|
||||||
@@ -212,26 +228,33 @@ public class CardRenderer {
|
|||||||
FSkinFont typeFont = FSkinFont.get(12);
|
FSkinFont typeFont = FSkinFont.get(12);
|
||||||
float availableTypeWidth = w - cardArtWidth;
|
float availableTypeWidth = w - cardArtWidth;
|
||||||
float lineHeight = typeFont.getFont().getLineHeight();
|
float lineHeight = typeFont.getFont().getLineHeight();
|
||||||
String set = paperCard.getEdition();
|
|
||||||
if (!StringUtils.isEmpty(set)) {
|
if (!StringUtils.isEmpty(set)) {
|
||||||
float setWidth = getSetWidth(typeFont, set);
|
float setWidth = getSetWidth(typeFont, set);
|
||||||
availableTypeWidth -= setWidth;
|
availableTypeWidth -= setWidth;
|
||||||
drawSetLabel(g, typeFont, set, paperCard.getRarity(), x + availableTypeWidth + SET_BOX_MARGIN, y - SET_BOX_MARGIN, setWidth, lineHeight + 2 * SET_BOX_MARGIN);
|
drawSetLabel(g, typeFont, set, rarity, x + availableTypeWidth + SET_BOX_MARGIN, y - SET_BOX_MARGIN, setWidth, lineHeight + 2 * SET_BOX_MARGIN);
|
||||||
}
|
}
|
||||||
String type = cardRules.getType().toString();
|
String type = cardRules.getType().toString();
|
||||||
if (cardRules.getType().isCreature()) { //include P/T or Loyalty at end of type
|
if (cardRules.getType().isCreature()) { //include P/T or Loyalty at end of type
|
||||||
type += " (" + cardRules.getPower() + " / " + cardRules.getToughness() + ")";
|
type += " (" + power + " / " + toughness + ")";
|
||||||
}
|
}
|
||||||
else if (cardRules.getType().isPlaneswalker()) {
|
else if (cardRules.getType().isPlaneswalker()) {
|
||||||
type += " (" + cardRules.getInitialLoyalty() + ")";
|
type += " (" + loyalty + ")";
|
||||||
}
|
}
|
||||||
g.drawText(type, typeFont, foreColor, x, y, availableTypeWidth, lineHeight, false, HAlignment.LEFT, true);
|
g.drawText(type, typeFont, foreColor, x, y, availableTypeWidth, lineHeight, false, HAlignment.LEFT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean cardListItemTap(PaperCard paperCard, float x, float y, int count) {
|
public static boolean cardListItemTap(Card card, float x, float y, int count) {
|
||||||
TextureRegion cardArt = getCardArt(paperCard);
|
|
||||||
float cardArtHeight = getCardListItemHeight();
|
float cardArtHeight = getCardListItemHeight();
|
||||||
float cardArtWidth = cardArtHeight * (float)cardArt.getRegionWidth() / (float)cardArt.getRegionHeight();
|
float cardArtWidth = cardArtHeight * CARD_ART_RATIO;
|
||||||
|
if (x <= cardArtWidth && y <= cardArtHeight) {
|
||||||
|
CardZoom.show(card);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public static boolean cardListItemTap(PaperCard paperCard, float x, float y, int count) {
|
||||||
|
float cardArtHeight = getCardListItemHeight();
|
||||||
|
float cardArtWidth = cardArtHeight * CARD_ART_RATIO;
|
||||||
if (x <= cardArtWidth && y <= cardArtHeight) {
|
if (x <= cardArtWidth && y <= cardArtHeight) {
|
||||||
CardZoom.show(Card.getCardForUi(paperCard));
|
CardZoom.show(Card.getCardForUi(paperCard));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -271,12 +271,12 @@ public class ListChooser<T> extends FContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean tap(T value, float x, float y, int count) {
|
public boolean tap(T value, float x, float y, int count) {
|
||||||
return CardRenderer.cardListItemTap(((Card)value).getPaperCard(), x, y, count);
|
return CardRenderer.cardListItemTap((Card)value, x, y, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
public void drawValue(Graphics g, T value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||||
CardRenderer.drawCardListItem(g, font, foreColor, ((Card)value).getPaperCard(), 0, x, y, w, h);
|
CardRenderer.drawCardListItem(g, font, foreColor, (Card)value, 0, x, y, w, h);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,15 +200,12 @@ public class CardDetailUtil {
|
|||||||
if (ptText.length() > 0) {
|
if (ptText.length() > 0) {
|
||||||
ptText.insert(0, "P/T: ");
|
ptText.insert(0, "P/T: ");
|
||||||
ptText.append(" - ").append("Loy: ");
|
ptText.append(" - ").append("Loy: ");
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
ptText.append("Loyalty: ");
|
ptText.append("Loyalty: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
int loyalty = card.getCounters(CounterType.LOYALTY);
|
ptText.append(card.getCurrentLoyalty());
|
||||||
if (loyalty == 0) {
|
|
||||||
loyalty = card.getBaseLoyalty();
|
|
||||||
}
|
|
||||||
ptText.append(loyalty);
|
|
||||||
}
|
}
|
||||||
return ptText.toString();
|
return ptText.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user