Update Border Colors

It should have more consistent colors to the actual texture since the color is taken directly from the texture itself.
This commit is contained in:
Anthony Calosa
2020-10-07 07:00:41 +08:00
parent ea4ed9c1af
commit ad7f4f1fa8
6 changed files with 43 additions and 39 deletions

View File

@@ -566,17 +566,25 @@ public class Graphics {
}
public float getfloatAlphaComposite() { return alphaComposite; }
public void drawBorderImage(FImage image, Color color, float x, float y, float w, float h, boolean tint) {
image.draw(this, x, y, w, h);
public void drawBorderImage(FImage image, Color borderColor, Color tintColor, float x, float y, float w, float h, boolean tint) {
float oldalpha = alphaComposite;
if(tint){
float oldalpha = alphaComposite;
setAlphaComposite(0.8f);
drawRoundRect(2f, Color.WHITE, x, y, w, h, (h-w)/12);
setAlphaComposite(1f);
fillRoundRect(color, x, y, w, h, (h-w)/12);
setAlphaComposite(oldalpha);
drawRoundRect(2f, borderLining(borderColor.toString()), x, y, w, h, (h-w)/12);
fillRoundRect(tintColor, x, y, w, h, (h-w)/12);
} else {
image.draw(this, x, y, w, h);
fillRoundRect(borderColor, x, y, w, h, (h-w)/10);//show corners edges
}
setAlphaComposite(oldalpha);
}
public void drawborderImage(Color borderColor, float x, float y, float w, float h) {
float oldalpha = alphaComposite;
fillRoundRect(borderColor, x, y, w, h, (h-w)/12);
setAlphaComposite(oldalpha);
}
public void drawImage(FImage image, Color borderColor, float x, float y, float w, float h) {
image.draw(this, x, y, w, h);
fillRoundRect(borderColor, x+1, y+1, w-1.5f, h-1.5f, (h-w)/10);//used by zoom let some edges show...
}
public void drawImage(FImage image, float x, float y, float w, float h) {
drawImage(image, x, y, w, h, false);
@@ -733,4 +741,13 @@ public class Graphics {
public float adjustY(float y, float height) {
return regionHeight - y - bounds.y - height; //flip y-axis
}
public Color borderLining(String c){
if (c == null || c == "")
return Color.valueOf("#fffffd");
int c_r = Integer.parseInt(c.substring(0,2),16);
int c_g = Integer.parseInt(c.substring(2,4),16);
int c_b = Integer.parseInt(c.substring(4,6),16);
int brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
return brightness > 155 ? Color.valueOf("#171717") : Color.valueOf("#fffffd");
}
}

View File

@@ -34,7 +34,6 @@ import forge.card.CardRenderer;
import forge.deck.Deck;
import forge.game.card.CardView;
import forge.game.player.IHasIcon;
import forge.item.IPaperCard;
import forge.item.InventoryItem;
import forge.item.PaperCard;
import forge.model.FModel;
@@ -42,6 +41,7 @@ import forge.properties.ForgeConstants;
import forge.util.ImageUtil;
import forge.util.TextUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.io.File;
import java.util.HashMap;
@@ -84,7 +84,7 @@ public class ImageCache {
public static final Texture defaultImage;
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
private static final Map<String, Boolean> imageBorder = new HashMap<>(1024);
private static final Map<String, Pair<String, Boolean>> imageBorder = new HashMap<>(1024);
private static boolean imageLoaded, delayLoadRequested;
public static void allowSingleLoad() {
@@ -224,7 +224,7 @@ public class ImageCache {
image = defaultImage;
cache.put(imageKey, defaultImage);
if (imageBorder.get(image.toString()) == null)
imageBorder.put(image.toString(), false); //black border
imageBorder.put(image.toString(), Pair.of(Color.valueOf("#171717").toString(), false)); //black border
}
}
return image;
@@ -254,24 +254,10 @@ public class ImageCache {
int ry = Math.round((image.getHeight() - rh)/2f)-2;
return new TextureRegion(image, rx, ry, rw, rh);
}
public static Color borderColor(IPaperCard c) {
if (c == null)
public static Color borderColor(Texture t) {
if (t == null)
return Color.valueOf("#171717");
CardEdition ed = FModel.getMagicDb().getEditions().get(c.getEdition());
if (ed != null && ed.isWhiteBorder())
return Color.valueOf("#fffffd");
return Color.valueOf("#171717");
}
public static Color borderColor(CardView c) {
if (c == null)
return Color.valueOf("#171717");
CardView.CardStateView state = c.getCurrentState();
CardEdition ed = FModel.getMagicDb().getEditions().get(state.getSetCode());
if (ed != null && ed.isWhiteBorder() && state.getFoilIndex() == 0)
return Color.valueOf("#fffffd");
return Color.valueOf("#171717");
return Color.valueOf(imageBorder.get(t.toString()).getLeft());
}
public static int getFSkinBorders(CardView c) {
if (c == null)
@@ -286,13 +272,13 @@ public class ImageCache {
public static boolean isBorderlessCardArt(Texture t) {
return ImageLoader.isBorderless(t);
}
public static void updateBorders(String textureString, boolean val){
imageBorder.put(textureString, val);
public static void updateBorders(String textureString, Pair<String, Boolean> colorPair){
imageBorder.put(textureString, colorPair);
}
public static FImage getBorder(String textureString) {
if (imageBorder.get(textureString) == null)
return BlackBorder;
return imageBorder.get(textureString) ? WhiteBorder : BlackBorder;
return imageBorder.get(textureString).getRight() ? WhiteBorder : BlackBorder;
}
public static FImage getBorderImage(String textureString, boolean canshow) {
if (!canshow)

View File

@@ -17,6 +17,7 @@ import forge.ImageKeys;
import forge.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.TextUtil;
import org.apache.commons.lang3.tuple.Pair;
import static forge.assets.ImageCache.croppedBorderImage;
@@ -34,7 +35,7 @@ final class ImageLoader extends CacheLoader<String, Texture> {
try {
Texture t = new Texture(fh, textureFilter);
//update
ImageCache.updateBorders(t.toString(), extendedArt ? false: isCloserToWhite(getpixelColor(t)));
ImageCache.updateBorders(t.toString(), extendedArt ? Pair.of(Color.valueOf("#171717").toString(), false): isCloserToWhite(getpixelColor(t)));
if (textureFilter)
t.setFilter(Texture.TextureFilter.MipMapLinearLinear, Texture.TextureFilter.Linear);
if (extendedArt)
@@ -145,13 +146,13 @@ final class ImageLoader extends CacheLoader<String, Texture> {
pixmap.dispose();
return color.toString();
}
public static boolean isCloserToWhite(String c){
public static Pair<String, Boolean> isCloserToWhite(String c){
if (c == null || c == "")
return false;
return Pair.of(Color.valueOf("#171717").toString(), false);
int c_r = Integer.parseInt(c.substring(0,2),16);
int c_g = Integer.parseInt(c.substring(2,4),16);
int c_b = Integer.parseInt(c.substring(4,6),16);
int brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
return brightness > 155;
return Pair.of(c,brightness > 155);
}
}

View File

@@ -53,7 +53,7 @@ public class CardImage implements FImage {
g.drawImage(image, x, y, w, h);
else {
float radius = (h - w)/8;
g.drawfillBorder(3, ImageCache.borderColor(card), x, y, w, h, radius);
g.drawborderImage(ImageCache.borderColor(image), x, y, w, h);
g.drawImage(ImageCache.croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
}
}

View File

@@ -403,7 +403,7 @@ public class CardImageRenderer {
if (ImageCache.isBorderlessCardArt(image))
g.drawImage(image, x, y, w, h);
else {
g.drawImage(ImageCache.getBorderImage(image.toString(), canshow), x, y, w, h);
g.drawImage(ImageCache.getBorderImage(image.toString()), ImageCache.borderColor(image), x, y, w, h);
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
}
} else {

View File

@@ -522,7 +522,7 @@ public class CardRenderer {
g.drawImage(image, x, y, w, h);
else {
boolean t = (card.getCurrentState().getOriginalColors() != card.getCurrentState().getColors()) || card.getCurrentState().hasChangeColors();
g.drawBorderImage(ImageCache.getBorderImage(image.toString(), canshow), ImageCache.getTint(card), x, y, w, h, t); //tint check for changed colors
g.drawBorderImage(ImageCache.getBorderImage(image.toString(), canshow), ImageCache.borderColor(image), ImageCache.getTint(card), x, y, w, h, t); //tint check for changed colors
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
}
} else {