mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
Work on card list rendering
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package forge.card;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
@@ -15,12 +18,15 @@ import forge.assets.FSkinImage;
|
||||
import forge.assets.ImageCache;
|
||||
import forge.assets.TextRenderer;
|
||||
import forge.card.CardDetailUtil.DetailColors;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.card.Card;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.screens.match.FControl;
|
||||
import forge.toolbox.FCardPanel;
|
||||
import forge.toolbox.FDialog;
|
||||
import forge.toolbox.FList;
|
||||
|
||||
public class CardRenderer {
|
||||
private static final FSkinFont NAME_FONT = FSkinFont.get(16);
|
||||
@@ -151,6 +157,43 @@ public class CardRenderer {
|
||||
drawCardIdAndPtBox(g, card, idForeColor, ptColor1, ptColor2, x, y, w, h);
|
||||
}
|
||||
|
||||
public static float getCardListItemHeight() {
|
||||
return 2 * MANA_SYMBOL_SIZE + FSkinFont.get(12).getFont().getLineHeight() + 4 * FList.PADDING;
|
||||
}
|
||||
|
||||
private static Map<PaperCard, TextureRegion> cardArtCache = new HashMap<PaperCard, TextureRegion>();
|
||||
|
||||
//extract card art from the given card
|
||||
public static TextureRegion getCardArt(PaperCard card) {
|
||||
TextureRegion cardArt = cardArtCache.get(card);
|
||||
if (cardArt == null) {
|
||||
Texture image = ImageCache.getImage(card);
|
||||
int w = image.getWidth();
|
||||
int h = image.getHeight();
|
||||
int x = Math.round(w * 0.065f);
|
||||
int y = Math.round(h * 0.105f);
|
||||
w -= 2 * x;
|
||||
h *= 0.45f;
|
||||
cardArt = new TextureRegion(image, x, y, w, h);
|
||||
cardArtCache.put(card, cardArt);
|
||||
}
|
||||
return cardArt;
|
||||
}
|
||||
|
||||
public static void drawCardListItem(Graphics g, FSkinFont font, FSkinColor foreColor, PaperCard card, int count, float x, float y, float w, float h) {
|
||||
TextureRegion cardArt = getCardArt(card);
|
||||
float cardArtHeight = h - MANA_SYMBOL_SIZE - FList.PADDING;
|
||||
float cardArtWidth = cardArtHeight * (float)cardArt.getRegionWidth() / (float)cardArt.getRegionHeight();
|
||||
g.drawImage(cardArt, x - FList.PADDING, y - FList.PADDING, cardArtWidth, cardArtHeight);
|
||||
x += cardArtWidth;
|
||||
|
||||
ManaCost manaCost = card.getRules().getManaCost();
|
||||
float availableNameWidth = w - CardFaceSymbols.getWidth(manaCost, MANA_SYMBOL_SIZE) - cardArtWidth - FList.PADDING;
|
||||
g.drawText(card.getName(), font, foreColor, x, y, availableNameWidth, MANA_SYMBOL_SIZE, false, HAlignment.LEFT, true);
|
||||
x += availableNameWidth + FList.PADDING;
|
||||
CardFaceSymbols.drawManaCost(g, manaCost, x, y, MANA_SYMBOL_SIZE);
|
||||
}
|
||||
|
||||
private static void drawCardNameBox(Graphics g, Card card, Color color1, Color color2, float x, float y, float w, float h) {
|
||||
if (color2 == null) {
|
||||
g.fillRect(color1, x, y, w, h);
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Map.Entry;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.card.CardRenderer;
|
||||
import forge.game.GameFormat;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.filters.CardCMCFilter;
|
||||
@@ -156,12 +157,12 @@ public class CardManager extends ItemManager<PaperCard> {
|
||||
return new ItemRenderer<PaperCard>() {
|
||||
@Override
|
||||
public float getItemHeight() {
|
||||
return 0;
|
||||
return CardRenderer.getCardListItemHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Entry<PaperCard, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
|
||||
CardRenderer.drawCardListItem(g, font, foreColor, value.getKey(), value.getValue(), x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -272,7 +272,7 @@ public final class DeckManager extends ItemManager<DeckProxy> {
|
||||
@Override
|
||||
public void drawValue(Graphics g, Entry<DeckProxy, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
DeckProxy deck = value.getKey();
|
||||
|
||||
|
||||
//draw favorite, name, and color on first line
|
||||
g.drawImage(DeckPreferences.getPrefs(deck).getStarCount() > 0 ? FSkinImage.STAR_FILLED : FSkinImage.STAR_OUTINE, x, y, IMAGE_SIZE, IMAGE_SIZE);
|
||||
x += IMAGE_SIZE + FList.PADDING;
|
||||
|
||||
@@ -5,7 +5,9 @@ import java.util.Map.Entry;
|
||||
import forge.Forge.Graphics;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.card.CardRenderer;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.itemmanager.filters.ItemFilter;
|
||||
import forge.itemmanager.views.ItemListView.ItemRenderer;
|
||||
import forge.menu.FPopupMenu;
|
||||
@@ -36,12 +38,15 @@ public final class SpellShopManager extends ItemManager<InventoryItem> {
|
||||
return new ItemRenderer<InventoryItem>() {
|
||||
@Override
|
||||
public float getItemHeight() {
|
||||
return 0;
|
||||
return CardRenderer.getCardListItemHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Entry<InventoryItem, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
|
||||
if (value.getKey() instanceof PaperCard) {
|
||||
CardRenderer.drawCardListItem(g, font, foreColor, (PaperCard)value.getKey(), value.getValue(), x, y, w, h);
|
||||
}
|
||||
//TODO: render list item for non-card item
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -296,7 +296,7 @@ public final class ItemListView<T extends InventoryItem> extends ItemView<T> {
|
||||
|
||||
@Override
|
||||
public void drawValue(Graphics g, Entry<T, Integer> value, FSkinFont font, FSkinColor foreColor, boolean pressed, float x, float y, float w, float h) {
|
||||
renderer.drawValue(g, value, font, foreColor, pressed, x, y, w, h);
|
||||
renderer.drawValue(g, value, font, foreColor, pressed, x + 1, y, w - 2, h); //x + 1 and w - 2 to account for left and right borders
|
||||
}
|
||||
});
|
||||
setFontSize(14);
|
||||
|
||||
Reference in New Issue
Block a user