mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
[Desktop] update ImageView for Decks
This commit is contained in:
@@ -197,7 +197,7 @@ public class ImageCache {
|
||||
return original;
|
||||
}
|
||||
|
||||
private static BufferedImage scaleImage(String key, final int width, final int height, boolean useDefaultImage) {
|
||||
public static BufferedImage scaleImage(String key, final int width, final int height, boolean useDefaultImage) {
|
||||
if (StringUtils.isEmpty(key) || (3 > width && -1 != width) || (3 > height && -1 != height)) {
|
||||
// picture too small or key not defined; return a blank
|
||||
return null;
|
||||
@@ -251,7 +251,29 @@ public class ImageCache {
|
||||
_CACHE.put(resizedKey, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Crops the Card Image to get the Card Art of "regular Card frame".
|
||||
* @param bufferedImage the image that will be crop
|
||||
*/
|
||||
public static BufferedImage getCroppedArt(BufferedImage bufferedImage, float x, float y, float w, float h) {
|
||||
//todo add support for other card frames ie split card, etc.
|
||||
x = w * 0.1f;
|
||||
y = h * 0.11f;
|
||||
w -= 2 * x;
|
||||
h *= 0.43f;
|
||||
float ratioRatio = w / h / 1.302f;
|
||||
if (ratioRatio > 1) { //if too wide, shrink width
|
||||
float dw = w * (ratioRatio - 1);
|
||||
w -= dw;
|
||||
x += dw / 2;
|
||||
}
|
||||
else { //if too tall, shrink height
|
||||
float dh = h * (1 - ratioRatio);
|
||||
h -= dh;
|
||||
y += dh / 2;
|
||||
}
|
||||
return bufferedImage.getSubimage(Math.round(x), Math.round(y), Math.round(w), Math.round(h));
|
||||
}
|
||||
/**
|
||||
* Returns the Image corresponding to the key.
|
||||
*/
|
||||
|
||||
@@ -1,16 +1,6 @@
|
||||
package forge.itemmanager.views;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Shape;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
@@ -31,6 +21,7 @@ import javax.swing.SwingUtilities;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.ColorSet;
|
||||
import forge.deck.DeckProxy;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
@@ -57,6 +48,8 @@ import forge.util.ImageUtil;
|
||||
import forge.util.Localizer;
|
||||
import forge.view.arcane.CardPanel;
|
||||
|
||||
import static forge.ImageCache.getCroppedArt;
|
||||
|
||||
public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
private static final int PADDING = 5;
|
||||
private static final float PILE_SPACING_Y = 0.1f;
|
||||
@@ -1120,6 +1113,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
Rectangle bounds = itemInfo.getBounds();
|
||||
final int itemWidth = bounds.width;
|
||||
final int selBorderSize = 1;
|
||||
boolean deckSelectMode = itemInfo.item instanceof DeckProxy;
|
||||
|
||||
// Determine whether to render border from properties
|
||||
boolean noBorder = !isPreferenceEnabled(ForgePreferences.FPref.UI_RENDER_BLACK_BORDERS);
|
||||
@@ -1170,6 +1164,37 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
|
||||
g.drawImage(img, null, bounds.x + borderSize, bounds.y + borderSize);
|
||||
}
|
||||
else {
|
||||
if (deckSelectMode) {
|
||||
DeckProxy dp = ((DeckProxy) item);
|
||||
if (dp.isGeneratedDeck()) {
|
||||
//draw generic box
|
||||
FSkin.drawImage(g, FSkin.getImage(FSkinProp.IMG_DECK_GENERIC), bounds.x, bounds.y, bounds.width - 2 * cornerSize, bounds.height - 2 * cornerSize);
|
||||
} else {
|
||||
String deckImageKey = dp.getDeck().getCommanders().isEmpty() ? dp.getHighestCMCCard().getImageKey(false) : dp.getDeck().getCommanders().get(0).getImageKey(false);
|
||||
|
||||
ColorSet deckColor = dp.getColor();
|
||||
int scale = CardFaceSymbols.getHeight() * cornerSize/8;
|
||||
int scaleArt = CardFaceSymbols.getHeight() * cornerSize/7;
|
||||
|
||||
BufferedImage cardImage = ImageCache.scaleImage(deckImageKey, bounds.width, bounds.height, false);
|
||||
|
||||
if (cardImage == null) {
|
||||
//draw generic box
|
||||
FSkin.drawImage(g, FSkin.getImage(FSkinProp.IMG_DECK_GENERIC), bounds.x, bounds.y, bounds.width - 2 * cornerSize, bounds.height - 2 * cornerSize);
|
||||
} else {
|
||||
//draw card art
|
||||
g.drawImage(ImageCache.getCroppedArt(cardImage,bounds.x, bounds.y,bounds.width, bounds.height).getScaledInstance(scaleArt*3, Math.round(scaleArt*2.5f), Image.SCALE_SMOOTH),
|
||||
bounds.x+bounds.width/9, 2*cornerSize+bounds.y+bounds.height/7, null);
|
||||
//draw deck box
|
||||
FSkin.drawImage(g, FSkin.getImage(FSkinProp.IMG_DECK_CARD_ART), bounds.x, bounds.y, bounds.width - 2 * cornerSize, bounds.height - 2 * cornerSize);
|
||||
}
|
||||
|
||||
//deck colors
|
||||
if (deckColor != null) {
|
||||
CardFaceSymbols.drawColorSet(g, deckColor, bounds.x + bounds.width - (scale*2) + cornerSize, bounds.y + bounds.height/2 - (scale*2), scale, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
g.setColor(Color.white);
|
||||
Shape clip = g.getClip();
|
||||
g.setClip(bounds);
|
||||
|
||||
@@ -19,6 +19,7 @@ package forge.toolbox;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.toolbox.FSkin.SkinImage;
|
||||
@@ -39,6 +40,7 @@ import java.util.StringTokenizer;
|
||||
public class CardFaceSymbols {
|
||||
/** Constant <code>manaImages</code>. */
|
||||
private static final Map<String, SkinImage> MANA_IMAGES = new HashMap<>();
|
||||
private static final Map<String, SkinImage> DECK_COLORSET = new HashMap<>();
|
||||
|
||||
private static final int manaImageSize = 13;
|
||||
|
||||
@@ -48,6 +50,13 @@ public class CardFaceSymbols {
|
||||
* </p>
|
||||
*/
|
||||
public static void loadImages() {
|
||||
DECK_COLORSET.put("C", FSkin.getImage(FSkinProp.IMG_MANA_COLORLESS));
|
||||
DECK_COLORSET.put("R", FSkin.getImage(FSkinProp.IMG_MANA_R));
|
||||
DECK_COLORSET.put("G", FSkin.getImage(FSkinProp.IMG_MANA_G));
|
||||
DECK_COLORSET.put("B", FSkin.getImage(FSkinProp.IMG_MANA_B));
|
||||
DECK_COLORSET.put("U", FSkin.getImage(FSkinProp.IMG_MANA_U));
|
||||
DECK_COLORSET.put("W", FSkin.getImage(FSkinProp.IMG_MANA_W));
|
||||
|
||||
for (int i = 0; i <= 20; i++) {
|
||||
MANA_IMAGES.put(String.valueOf(i), FSkin.getImage(FSkinProp.valueOf("IMG_MANA_" + i), manaImageSize, manaImageSize));
|
||||
}
|
||||
@@ -222,6 +231,16 @@ public class CardFaceSymbols {
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawColorSet(Graphics g, ColorSet colorSet, int x, int y, int imageSize, boolean vertical) {
|
||||
for (final ManaCostShard s : colorSet.getOrderedShards()) {
|
||||
if (DECK_COLORSET.get(s.getImageKey())!=null)
|
||||
FSkin.drawImage(g, DECK_COLORSET.get(s.getImageKey()), x, y, imageSize, imageSize);
|
||||
if (!vertical)
|
||||
x += imageSize;
|
||||
else
|
||||
y += imageSize;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* draw.
|
||||
|
||||
@@ -1045,8 +1045,8 @@ public class FSkin {
|
||||
private static int currentSkinIndex;
|
||||
private static String preferredDir;
|
||||
private static String preferredName;
|
||||
private static BufferedImage bimDefaultSprite, bimFavIcon, bimPreferredSprite, bimFoils, bimQuestDraftDeck,
|
||||
bimOldFoils, bimDefaultAvatars, bimPreferredAvatars, bimTrophies, bimAbilities, bimManaIcons, bimDefaultSleeve, bimDefaultSleeve2;
|
||||
private static BufferedImage bimDefaultSprite, bimFavIcon, bimPreferredSprite, bimFoils, bimQuestDraftDeck, bimOldFoils,
|
||||
bimDefaultAvatars, bimPreferredAvatars, bimTrophies, bimAbilities, bimManaIcons, bimDefaultSleeve, bimDefaultSleeve2, bimDefaultDeckbox;
|
||||
private static int x0, y0, w0, h0, newW, newH, preferredW, preferredH;
|
||||
private static int[] tempCoords;
|
||||
private static int defaultFontSize = 12;
|
||||
@@ -1183,6 +1183,7 @@ public class FSkin {
|
||||
final File f11 = new File(defaultDir + ForgeConstants.SPRITE_MANAICONS_FILE);
|
||||
final File f12 = new File(defaultDir + ForgeConstants.SPRITE_SLEEVES_FILE);
|
||||
final File f13 = new File(defaultDir + ForgeConstants.SPRITE_SLEEVES2_FILE);
|
||||
final File f14 = new File(defaultDir + ForgeConstants.SPRITE_DECKBOX_FILE);
|
||||
|
||||
try {
|
||||
int p = 0;
|
||||
@@ -1204,6 +1205,8 @@ public class FSkin {
|
||||
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
|
||||
bimDefaultSleeve2 = ImageIO.read(f13);
|
||||
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
|
||||
bimDefaultDeckbox = ImageIO.read(f14);
|
||||
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
|
||||
bimTrophies = ImageIO.read(f7);
|
||||
FView.SINGLETON_INSTANCE.incrementSplashProgessBar(++p);
|
||||
bimQuestDraftDeck = ImageIO.read(f8);
|
||||
@@ -1262,6 +1265,9 @@ public class FSkin {
|
||||
case MANAICONS:
|
||||
setImage(prop, bimManaIcons);
|
||||
break;
|
||||
case DECKBOX:
|
||||
setImage(prop, bimDefaultDeckbox);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -1284,6 +1290,7 @@ public class FSkin {
|
||||
bimDefaultAvatars.flush();
|
||||
bimDefaultSleeve.flush();
|
||||
bimDefaultSleeve2.flush();
|
||||
bimDefaultDeckbox.flush();
|
||||
bimQuestDraftDeck.flush();
|
||||
bimTrophies.flush();
|
||||
bimAbilities.flush();
|
||||
@@ -1298,6 +1305,7 @@ public class FSkin {
|
||||
bimDefaultAvatars = null;
|
||||
bimDefaultSleeve = null;
|
||||
bimDefaultSleeve2 = null;
|
||||
bimDefaultDeckbox = null;
|
||||
bimPreferredAvatars = null;
|
||||
bimQuestDraftDeck = null;
|
||||
bimTrophies = null;
|
||||
|
||||
Reference in New Issue
Block a user