mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Merge branch 'newBranch' into 'master'
[Mobile] Refactor Border Generation See merge request core-developers/forge!3190
This commit is contained in:
@@ -19,6 +19,7 @@ package forge.assets;
|
|||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
@@ -39,7 +40,9 @@ import forge.properties.ForgeConstants;
|
|||||||
import forge.util.ImageUtil;
|
import forge.util.ImageUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -77,6 +80,7 @@ public class ImageCache {
|
|||||||
public static final Texture defaultImage;
|
public static final Texture defaultImage;
|
||||||
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
public static FImage BlackBorder = FSkinImage.IMG_BORDER_BLACK;
|
||||||
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
public static FImage WhiteBorder = FSkinImage.IMG_BORDER_WHITE;
|
||||||
|
private static final Map<Texture, Boolean> Borders = new HashMap<>();
|
||||||
|
|
||||||
private static boolean imageLoaded, delayLoadRequested;
|
private static boolean imageLoaded, delayLoadRequested;
|
||||||
public static void allowSingleLoad() {
|
public static void allowSingleLoad() {
|
||||||
@@ -99,6 +103,7 @@ public class ImageCache {
|
|||||||
cache.invalidateAll();
|
cache.invalidateAll();
|
||||||
cache.cleanUp();
|
cache.cleanUp();
|
||||||
missingIconKeys.clear();
|
missingIconKeys.clear();
|
||||||
|
Borders.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disposeTexture(){
|
public static void disposeTexture(){
|
||||||
@@ -181,6 +186,8 @@ public class ImageCache {
|
|||||||
if (useDefaultIfNotFound) {
|
if (useDefaultIfNotFound) {
|
||||||
image = defaultImage;
|
image = defaultImage;
|
||||||
cache.put(imageKey, defaultImage);
|
cache.put(imageKey, defaultImage);
|
||||||
|
if (Borders.get(image) == null)
|
||||||
|
Borders.put(image, false); //black border
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
@@ -192,8 +199,8 @@ public class ImageCache {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static TextureRegion croppedBorderImage(Texture image, boolean fullborder) {
|
public static TextureRegion croppedBorderImage(Texture image) {
|
||||||
if (!fullborder)
|
if (!image.toString().contains(".fullborder."))
|
||||||
return new TextureRegion(image);
|
return new TextureRegion(image);
|
||||||
float rscale = 0.96f;
|
float rscale = 0.96f;
|
||||||
int rw = Math.round(image.getWidth()*rscale);
|
int rw = Math.round(image.getWidth()*rscale);
|
||||||
@@ -202,25 +209,6 @@ public class ImageCache {
|
|||||||
int ry = Math.round((image.getHeight() - rh)/2f)-2;
|
int ry = Math.round((image.getHeight() - rh)/2f)-2;
|
||||||
return new TextureRegion(image, rx, ry, rw, rh);
|
return new TextureRegion(image, rx, ry, rw, rh);
|
||||||
}
|
}
|
||||||
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) {
|
public static Color borderColor(IPaperCard c) {
|
||||||
if (c == null)
|
if (c == null)
|
||||||
return Color.valueOf("#171717");
|
return Color.valueOf("#171717");
|
||||||
@@ -271,17 +259,38 @@ public class ImageCache {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static FImage getBorderImage(CardView c, boolean canshow) {
|
public static FImage getBorder(Texture t) {
|
||||||
|
if (Borders.get(t) == null)
|
||||||
|
Borders.put(t, isCloserToWhite(getpixelColor(t)));
|
||||||
|
return Borders.get(t) ? WhiteBorder : BlackBorder;
|
||||||
|
}
|
||||||
|
public static FImage getBorderImage(Texture t, boolean canshow) {
|
||||||
if (!canshow)
|
if (!canshow)
|
||||||
return BlackBorder;
|
return BlackBorder;
|
||||||
if (isWhiteBordered(c))
|
return getBorder(t);
|
||||||
return WhiteBorder;
|
|
||||||
return BlackBorder;
|
|
||||||
}
|
}
|
||||||
public static FImage getBorderImage(IPaperCard c) {
|
public static FImage getBorderImage(Texture t) {
|
||||||
if (isWhiteBordered(c))
|
return getBorder(t);
|
||||||
return WhiteBorder;
|
}
|
||||||
return BlackBorder;
|
public static String getpixelColor(Texture i) {
|
||||||
|
if (!i.getTextureData().isPrepared()) {
|
||||||
|
i.getTextureData().prepare(); //prepare texture
|
||||||
|
}
|
||||||
|
//get pixmap from texture data
|
||||||
|
Pixmap pixmap = i.getTextureData().consumePixmap();
|
||||||
|
//get pixel color from x,y texture coordinate based on the image fullborder or not
|
||||||
|
Color color = new Color(pixmap.getPixel(croppedBorderImage(i).getRegionX()+1, croppedBorderImage(i).getRegionY()+1));
|
||||||
|
pixmap.dispose();
|
||||||
|
return color.toString();
|
||||||
|
}
|
||||||
|
public static boolean isCloserToWhite(String c){
|
||||||
|
if (c == null || c == "")
|
||||||
|
return 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;
|
||||||
}
|
}
|
||||||
public static Color getTint(CardView c) {
|
public static Color getTint(CardView c) {
|
||||||
if (c == null)
|
if (c == null)
|
||||||
|
|||||||
@@ -49,13 +49,12 @@ public class CardImage implements FImage {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (Forge.enableUIMask) {
|
if (Forge.enableUIMask) {
|
||||||
boolean fullborder = image.toString().contains(".fullborder.");
|
|
||||||
if (ImageCache.isExtendedArt(card))
|
if (ImageCache.isExtendedArt(card))
|
||||||
g.drawImage(image, x, y, w, h);
|
g.drawImage(image, x, y, w, h);
|
||||||
else {
|
else {
|
||||||
float radius = (h - w)/8;
|
float radius = (h - w)/8;
|
||||||
g.drawfillBorder(3, ImageCache.borderColor(card), x, y, w, h, radius);
|
g.drawfillBorder(3, ImageCache.borderColor(card), x, y, w, h, radius);
|
||||||
g.drawImage(ImageCache.croppedBorderImage(image, fullborder), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
|
g.drawImage(ImageCache.croppedBorderImage(image), x+radius/2.2f, y+radius/2, w*0.96f, h*0.96f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -348,7 +348,6 @@ public class CardImageRenderer {
|
|||||||
if (image == ImageCache.defaultImage) { //support drawing card image manually if card image not found
|
if (image == ImageCache.defaultImage) { //support drawing card image manually if card image not found
|
||||||
drawCardImage(g, card, altState, x, y, w, h, CardStackPosition.Top);
|
drawCardImage(g, card, altState, x, y, w, h, CardStackPosition.Top);
|
||||||
} else {
|
} else {
|
||||||
boolean fullborder = image.toString().contains(".fullborder.");
|
|
||||||
float radius = (h - w)/8;
|
float radius = (h - w)/8;
|
||||||
float wh_Adj = ForgeConstants.isGdxPortLandscape && isCurrentCard ? 1.38f:1.0f;
|
float wh_Adj = ForgeConstants.isGdxPortLandscape && isCurrentCard ? 1.38f:1.0f;
|
||||||
float new_w = w*wh_Adj;
|
float new_w = w*wh_Adj;
|
||||||
@@ -371,7 +370,7 @@ public class CardImageRenderer {
|
|||||||
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
||||||
else {
|
else {
|
||||||
g.drawRotatedImage(FSkin.getBorders().get(0), new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
g.drawRotatedImage(FSkin.getBorders().get(0), new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
||||||
g.drawRotatedImage(ImageCache.croppedBorderImage(image, fullborder), new_x+radius/2-minusxy, new_y+radius/2-minusxy, new_w*croppedArea, new_h*croppedArea, (new_x+radius/2-minusxy) + (new_w*croppedArea) / 2, (new_y+radius/2-minusxy) + (new_h*croppedArea) / 2, -90);
|
g.drawRotatedImage(ImageCache.croppedBorderImage(image), new_x+radius/2-minusxy, new_y+radius/2-minusxy, new_w*croppedArea, new_h*croppedArea, (new_x+radius/2-minusxy) + (new_w*croppedArea) / 2, (new_y+radius/2-minusxy) + (new_h*croppedArea) / 2, -90);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, -90);
|
||||||
@@ -382,7 +381,7 @@ public class CardImageRenderer {
|
|||||||
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
||||||
else {
|
else {
|
||||||
g.drawRotatedImage(FSkin.getBorders().get(ImageCache.getFSkinBorders(card)), new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
g.drawRotatedImage(FSkin.getBorders().get(ImageCache.getFSkinBorders(card)), new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
||||||
g.drawRotatedImage(ImageCache.croppedBorderImage(image, fullborder), new_x + radius / 2-minusxy, new_y + radius / 2-minusxy, new_w * croppedArea, new_h * croppedArea, (new_x + radius / 2-minusxy) + (new_w * croppedArea) / 2, (new_y + radius / 2-minusxy) + (new_h * croppedArea) / 2, isAftermath ? 90 : -90);
|
g.drawRotatedImage(ImageCache.croppedBorderImage(image), new_x + radius / 2-minusxy, new_y + radius / 2-minusxy, new_w * croppedArea, new_h * croppedArea, (new_x + radius / 2-minusxy) + (new_w * croppedArea) / 2, (new_y + radius / 2-minusxy) + (new_h * croppedArea) / 2, isAftermath ? 90 : -90);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
g.drawRotatedImage(image, new_x, new_y, new_w, new_h, new_x + new_w / 2, new_y + new_h / 2, isAftermath ? 90 : -90);
|
||||||
@@ -391,8 +390,8 @@ public class CardImageRenderer {
|
|||||||
if (ImageCache.isExtendedArt(card))
|
if (ImageCache.isExtendedArt(card))
|
||||||
g.drawImage(image, x, y, w, h);
|
g.drawImage(image, x, y, w, h);
|
||||||
else {
|
else {
|
||||||
g.drawImage(ImageCache.getBorderImage(card, canshow), x, y, w, h);
|
g.drawImage(ImageCache.getBorderImage(image, canshow), x, y, w, h);
|
||||||
g.drawImage(ImageCache.croppedBorderImage(image, fullborder), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (canshow)
|
if (canshow)
|
||||||
|
|||||||
@@ -459,13 +459,12 @@ public class CardRenderer {
|
|||||||
if (image == ImageCache.defaultImage) {
|
if (image == ImageCache.defaultImage) {
|
||||||
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos);
|
CardImageRenderer.drawCardImage(g, CardView.getCardForUi(pc), false, x, y, w, h, pos);
|
||||||
} else {
|
} else {
|
||||||
boolean fullborder = image.toString().contains(".fullborder.");
|
|
||||||
if (Forge.enableUIMask) {
|
if (Forge.enableUIMask) {
|
||||||
if (ImageCache.isExtendedArt(pc))
|
if (ImageCache.isExtendedArt(pc))
|
||||||
g.drawImage(image, x, y, w, h);
|
g.drawImage(image, x, y, w, h);
|
||||||
else {
|
else {
|
||||||
g.drawImage(ImageCache.getBorderImage(pc), x, y, w, h);
|
g.drawImage(ImageCache.getBorderImage(image), x, y, w, h);
|
||||||
g.drawImage(ImageCache.croppedBorderImage(image, fullborder), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
g.drawImage(image, x, y, w, h);
|
g.drawImage(image, x, y, w, h);
|
||||||
@@ -499,7 +498,6 @@ public class CardRenderer {
|
|||||||
if (image == ImageCache.defaultImage) {
|
if (image == ImageCache.defaultImage) {
|
||||||
CardImageRenderer.drawCardImage(g, card, false, x, y, w, h, pos);
|
CardImageRenderer.drawCardImage(g, card, false, x, y, w, h, pos);
|
||||||
} else {
|
} else {
|
||||||
boolean fullborder = image.toString().contains(".fullborder.");
|
|
||||||
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_ROTATE_PLANE_OR_PHENOMENON)
|
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_ROTATE_PLANE_OR_PHENOMENON)
|
||||||
&& (card.getCurrentState().isPhenomenon() || card.getCurrentState().isPlane()) && rotate){
|
&& (card.getCurrentState().isPhenomenon() || card.getCurrentState().isPlane()) && rotate){
|
||||||
if (Forge.enableUIMask) {
|
if (Forge.enableUIMask) {
|
||||||
@@ -507,7 +505,7 @@ public class CardRenderer {
|
|||||||
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
||||||
else {
|
else {
|
||||||
g.drawRotatedImage(FSkin.getBorders().get(0), x, y, w, h, x + w / 2, y + h / 2, -90);
|
g.drawRotatedImage(FSkin.getBorders().get(0), x, y, w, h, x + w / 2, y + h / 2, -90);
|
||||||
g.drawRotatedImage(ImageCache.croppedBorderImage(image, fullborder), x+radius/2.3f-minusxy, y+radius/2-minusxy, w*croppedArea, h*croppedArea, (x+radius/2.3f-minusxy) + (w*croppedArea) / 2, (y+radius/2-minusxy) + (h*croppedArea) / 2, -90);
|
g.drawRotatedImage(ImageCache.croppedBorderImage(image), x+radius/2.3f-minusxy, y+radius/2-minusxy, w*croppedArea, h*croppedArea, (x+radius/2.3f-minusxy) + (w*croppedArea) / 2, (y+radius/2-minusxy) + (h*croppedArea) / 2, -90);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
g.drawRotatedImage(image, x, y, w, h, x + w / 2, y + h / 2, -90);
|
||||||
@@ -517,8 +515,8 @@ public class CardRenderer {
|
|||||||
g.drawImage(image, x, y, w, h);
|
g.drawImage(image, x, y, w, h);
|
||||||
else {
|
else {
|
||||||
boolean t = (card.getCurrentState().getOriginalColors() != card.getCurrentState().getColors()) || card.getCurrentState().hasChangeColors();
|
boolean t = (card.getCurrentState().getOriginalColors() != card.getCurrentState().getColors()) || card.getCurrentState().hasChangeColors();
|
||||||
g.drawBorderImage(ImageCache.getBorderImage(card, canshow), ImageCache.getTint(card), x, y, w, h, t); //tint check for changed colors
|
g.drawBorderImage(ImageCache.getBorderImage(image, canshow), ImageCache.getTint(card), x, y, w, h, t); //tint check for changed colors
|
||||||
g.drawImage(ImageCache.croppedBorderImage(image, fullborder), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
g.drawImage(ImageCache.croppedBorderImage(image), x + radius / 2.4f-minusxy, y + radius / 2-minusxy, w * croppedArea, h * croppedArea);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (canshow)
|
if (canshow)
|
||||||
|
|||||||
Reference in New Issue
Block a user