mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Add FPS Display, Add Preload Extended Art, Add Border Images
This commit is contained in:
@@ -35,6 +35,8 @@ import forge.util.FileUtil;
|
||||
import forge.util.Localizer;
|
||||
import forge.util.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
@@ -136,8 +138,32 @@ public class Forge implements ApplicationListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void preloadExtendedArt() {
|
||||
List<String> keys = new ArrayList<>();
|
||||
File[] directories = new File(ForgeConstants.CACHE_CARD_PICS_DIR).listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
if (!file.getName().startsWith("MPS_"))
|
||||
return false;
|
||||
return file.isDirectory();
|
||||
}
|
||||
});
|
||||
for (File folder : directories) {
|
||||
File[] files = new File(folder.toString()).listFiles();
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
keys.add(folder.getName() + "/" +file.getName().replace(".jpg","").replace(".png",""));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String artKeys : keys) {
|
||||
ImageCache.preloadCache(artKeys);
|
||||
}
|
||||
}
|
||||
|
||||
private void afterDbLoaded() {
|
||||
stopContinuousRendering(); //save power consumption by disabling continuous rendering once assets loaded
|
||||
preloadExtendedArt(); // Preloads Extended Art to Cache...
|
||||
|
||||
FSkin.loadFull(splashScreen);
|
||||
|
||||
|
||||
@@ -282,6 +282,9 @@ public enum FSkinImage implements FImage {
|
||||
IMG_ABILITY_HEXPROOF_UB (FSkinProp.IMG_ABILITY_HEXPROOF_UB, SourceFile.ABILITIES),
|
||||
//token icon
|
||||
IMG_ABILITY_TOKEN (FSkinProp.IMG_ABILITY_TOKEN, SourceFile.ABILITIES),
|
||||
//border
|
||||
IMG_BORDER_BLACK (FSkinProp.IMG_BORDER_BLACK, SourceFile.BORDERS),
|
||||
IMG_BORDER_WHITE (FSkinProp.IMG_BORDER_WHITE, SourceFile.BORDERS),
|
||||
//PROTECT ICONS
|
||||
IMG_ABILITY_PROTECT_ALL (FSkinProp.IMG_ABILITY_PROTECT_ALL, SourceFile.ABILITIES),
|
||||
IMG_ABILITY_PROTECT_B (FSkinProp.IMG_ABILITY_PROTECT_B, SourceFile.ABILITIES),
|
||||
@@ -308,6 +311,7 @@ public enum FSkinImage implements FImage {
|
||||
OLD_FOILS(ForgeConstants.SPRITE_OLD_FOILS_FILE),
|
||||
TROPHIES(ForgeConstants.SPRITE_TROPHIES_FILE),
|
||||
ABILITIES(ForgeConstants.SPRITE_ABILITY_FILE),
|
||||
BORDERS(ForgeConstants.SPRITE_BORDER_FILE),
|
||||
MANAICONS(ForgeConstants.SPRITE_MANAICONS_FILE),
|
||||
PLANAR_CONQUEST(ForgeConstants.SPRITE_PLANAR_CONQUEST_FILE);
|
||||
|
||||
|
||||
@@ -64,6 +64,8 @@ public class ImageCache {
|
||||
.loader(new ImageLoader())
|
||||
.build();
|
||||
public static final Texture defaultImage;
|
||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
||||
|
||||
private static boolean imageLoaded, delayLoadRequested;
|
||||
public static void allowSingleLoad() {
|
||||
@@ -162,6 +164,20 @@ public class ImageCache {
|
||||
}
|
||||
return image;
|
||||
}
|
||||
public static void preloadCache(String imageKey) {
|
||||
if (StringUtils.isEmpty(imageKey)) {
|
||||
return;
|
||||
}
|
||||
Texture image;
|
||||
try { image = cache.get(imageKey); }
|
||||
catch (final Exception ex) {
|
||||
image = null;
|
||||
}
|
||||
if (image == null) {
|
||||
image = defaultImage;
|
||||
cache.put(imageKey, defaultImage);
|
||||
}
|
||||
}
|
||||
public static TextureRegion croppedBorderImage(Texture image) {
|
||||
float rscale = 0.96f;
|
||||
int rw = Math.round(image.getWidth()*rscale);
|
||||
@@ -171,6 +187,25 @@ public class ImageCache {
|
||||
TextureRegion rimage = new TextureRegion(image, rx, ry, rw, rh);
|
||||
return rimage;
|
||||
}
|
||||
public static boolean isWhiteBordered(IPaperCard c) {
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
CardEdition ed = FModel.getMagicDb().getEditions().get(c.getEdition());
|
||||
if (ed != null && ed.isWhiteBorder())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static boolean isWhiteBordered(CardView c) {
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
CardView.CardStateView state = c.getCurrentState();
|
||||
CardEdition ed = FModel.getMagicDb().getEditions().get(state.getSetCode());
|
||||
if (ed != null && ed.isWhiteBorder() && state.getFoilIndex() == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static Color borderColor(IPaperCard c) {
|
||||
if (c == null)
|
||||
return Color.valueOf("#171717");
|
||||
@@ -207,4 +242,14 @@ public class ImageCache {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static FImage getBorderImage(CardView c) {
|
||||
if (isWhiteBordered(c))
|
||||
return WhiteBorder;
|
||||
return BlackBorder;
|
||||
}
|
||||
public static FImage getBorderImage(IPaperCard c) {
|
||||
if (isWhiteBordered(c))
|
||||
return WhiteBorder;
|
||||
return BlackBorder;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ final class ImageLoader extends CacheLoader<String, Texture> {
|
||||
if (key.length() > 4){
|
||||
if ((key.substring(0,4).contains("MPS_"))) //TODO add sets to get all extended art???
|
||||
extendedArt = true;
|
||||
//use generated extended art... very few cards have this so little performance lost
|
||||
//use generated extended art... it will preload the cache at startup so... yeah! :)
|
||||
}
|
||||
File file = ImageKeys.getImageFile(key);
|
||||
if (file != null) {
|
||||
|
||||
@@ -391,7 +391,7 @@ public class CardImageRenderer {
|
||||
if (ImageCache.isExtendedArt(card))
|
||||
g.drawImage(image, x, y, w, h);
|
||||
else {
|
||||
g.drawfillBorder(3, ImageCache.borderColor(card), x, y, w, h, radius);
|
||||
g.drawImage(ImageCache.getBorderImage(card), x, y, w, h);
|
||||
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f, y + radius / 2, w * 0.96f, h * 0.96f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ public class CardRenderer {
|
||||
if (ImageCache.isExtendedArt(pc))
|
||||
g.drawImage(image, x, y, w, h);
|
||||
else {
|
||||
g.drawfillBorder(3, ImageCache.borderColor(pc), x, y, w, h, radius);
|
||||
g.drawImage(ImageCache.getBorderImage(pc), x, y, w, h);
|
||||
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f, y + radius / 2, w * 0.96f, h * 0.96f);
|
||||
}
|
||||
}
|
||||
@@ -456,7 +456,7 @@ public class CardRenderer {
|
||||
if (ImageCache.isExtendedArt(card))
|
||||
g.drawImage(image, x, y, w, h);
|
||||
else {
|
||||
g.drawfillBorder(3, ImageCache.borderColor(card), x, y, w, h, radius);
|
||||
g.drawImage(ImageCache.getBorderImage(card), x, y, w, h);
|
||||
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f, y + radius / 2, w * 0.96f, h * 0.96f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,6 +322,9 @@ public enum FSkinProp {
|
||||
IMG_ABILITY_HEXPROOF_UB (new int[] {166, 494, 80, 80}, PropType.ABILITY),
|
||||
//token icon
|
||||
IMG_ABILITY_TOKEN (new int[] {330, 494, 80, 80}, PropType.ABILITY),
|
||||
//border
|
||||
IMG_BORDER_BLACK (new int[] {2, 2, 672, 936}, PropType.BORDERS),
|
||||
IMG_BORDER_WHITE (new int[] {676, 2, 672, 936}, PropType.BORDERS),
|
||||
//Protection From
|
||||
IMG_ABILITY_PROTECT_ALL (new int[] {248, 84, 80, 80}, PropType.ABILITY),
|
||||
IMG_ABILITY_PROTECT_B (new int[] {330, 84, 80, 80}, PropType.ABILITY),
|
||||
@@ -374,6 +377,7 @@ public enum FSkinProp {
|
||||
OLD_FOIL,
|
||||
TROPHY,
|
||||
ABILITY,
|
||||
BORDERS,
|
||||
MANAICONS,
|
||||
PLANAR_CONQUEST,
|
||||
FAVICON
|
||||
|
||||
@@ -94,6 +94,7 @@ public final class ForgeConstants {
|
||||
public static final String SPRITE_OLD_FOILS_FILE = "sprite_old_foils.png";
|
||||
public static final String SPRITE_TROPHIES_FILE = "sprite_trophies.png";
|
||||
public static final String SPRITE_ABILITY_FILE = "sprite_ability.png";
|
||||
public static final String SPRITE_BORDER_FILE = "sprite_border.png";
|
||||
public static final String SPRITE_MANAICONS_FILE = "sprite_manaicons.png";
|
||||
public static final String SPRITE_AVATARS_FILE = "sprite_avatars.png";
|
||||
public static final String SPRITE_FAVICONS_FILE = "sprite_favicons.png";
|
||||
|
||||
Reference in New Issue
Block a user