Move card border color determination to utility class

This commit is contained in:
drdev
2014-04-18 02:51:00 +00:00
parent 42c04bdcdb
commit adb57bed8a
3 changed files with 161 additions and 1 deletions

View File

@@ -216,6 +216,10 @@ public class FSkinColor {
return isColorBright(c) ? Color.BLACK : Color.WHITE;
}
public static Color fromRGB(int r, int g, int b) {
return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f, 1f);
}
public static void updateAll() {
if (FSkinColor.baseColors.size() == 0) { //initialize base skin colors if needed
for (final Colors c : Colors.values()) {

View File

@@ -15,6 +15,8 @@ import forge.assets.FSkinColor;
import forge.assets.FSkinFont;
import forge.assets.ImageCache;
import forge.assets.FSkinColor.Colors;
import forge.card.CardDetailUtil;
import forge.card.CardDetailUtil.CardBorderColor;
import forge.game.card.Card;
import forge.game.spellability.SpellAbility;
import forge.match.input.Input;
@@ -429,7 +431,47 @@ public class InputSelectCard {
}
private static void drawDetails(Graphics g, Card card, float w, float h) {
float x = FDialog.INSETS;
float y = x;
w -= 2 * x;
h -= 2 * y;
float ratio = h / w;
if (ratio > FCardPanel.ASPECT_RATIO) {
float oldHeight = h;
h = w * FCardPanel.ASPECT_RATIO;
y += (oldHeight - h) / 2;
}
else {
float oldWidth = w;
w = h / FCardPanel.ASPECT_RATIO;
x += (oldWidth - w) / 2;
}
boolean canShow = !card.isFaceDown() && FControl.mayShowCard(card);
float blackBorderThickness = w * 0.021f;
g.fillRect(Color.BLACK, x, y, w, h);
x += blackBorderThickness;
y += blackBorderThickness;
w -= 2 * blackBorderThickness;
h -= 2 * blackBorderThickness;
//determine colors for borders
List<CardBorderColor> borderColors = CardDetailUtil.getBorderColors(card, canShow, true);
CardBorderColor borderColor = borderColors.get(0);
Color color1 = FSkinColor.fromRGB(borderColor.r, borderColor.g, borderColor.b);
Color color2 = null;
if (borderColors.size() > 1) {
borderColor = borderColors.get(1);
color2 = FSkinColor.fromRGB(borderColor.r, borderColor.g, borderColor.b);
}
if (color2 == null) {
g.fillRect(color1, x, y, w, h);
}
else {
g.fillGradientRect(color1, color2, false, x, y, w, h);
}
}
}
}

View File

@@ -2,6 +2,7 @@ package forge.card;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import forge.GuiBase;
import forge.game.GameEntity;
@@ -18,6 +19,119 @@ public class CardDetailUtil {
private CardDetailUtil() {
}
public enum CardBorderColor {
WHITE(254, 253, 244),
BLUE(90, 146, 202),
BLACK(32, 34, 31),
RED(253, 66, 40),
GREEN(22, 115, 69),
MULTICOLOR(248, 219, 85),
COLORLESS(160, 166, 164),
LAND(190, 153, 112),
FACE_DOWN(83, 61, 40),
UNKNOWN(200, 0, 230);
public final int r, g, b;
private CardBorderColor(int r0, int g0, int b0) {
r = r0;
g = g0;
b = b0;
}
}
public static CardBorderColor getBorderColor(final Card card, boolean canShow) {
return getBorderColors(card, canShow, false).get(0);
}
public static List<CardBorderColor> getBorderColors(final Card card, boolean canShow, boolean supportMultiple) {
List<CardBorderColor> borderColors = new ArrayList<CardBorderColor>();
ColorSet cardColors = card.determineColor();
if (!canShow) {
borderColors.add(CardBorderColor.FACE_DOWN);
}
else if (cardColors.isColorless()) {
if (card.isLand()) { //use different color for lands vs. other colorless cards
borderColors.add(CardBorderColor.LAND);
}
else {
borderColors.add(CardBorderColor.COLORLESS);
}
}
else {
int colorCount = cardColors.countColors();
if (colorCount > 2 || (colorCount > 1 && !supportMultiple)) {
borderColors.add(CardBorderColor.MULTICOLOR);
}
else if (cardColors.hasWhite()) {
if (colorCount == 1) {
borderColors.add(CardBorderColor.WHITE);
}
else if (cardColors.hasBlue()) {
borderColors.add(CardBorderColor.WHITE);
borderColors.add(CardBorderColor.BLUE);
}
else if (cardColors.hasBlack()) {
borderColors.add(CardBorderColor.WHITE);
borderColors.add(CardBorderColor.BLACK);
}
else if (cardColors.hasRed()) {
borderColors.add(CardBorderColor.RED);
borderColors.add(CardBorderColor.WHITE);
}
else if (cardColors.hasGreen()) {
borderColors.add(CardBorderColor.GREEN);
borderColors.add(CardBorderColor.WHITE);
}
}
else if (cardColors.hasBlue()) {
if (colorCount == 1) {
borderColors.add(CardBorderColor.BLUE);
}
else if (cardColors.hasBlack()) {
borderColors.add(CardBorderColor.BLUE);
borderColors.add(CardBorderColor.BLACK);
}
else if (cardColors.hasRed()) {
borderColors.add(CardBorderColor.BLUE);
borderColors.add(CardBorderColor.RED);
}
else if (cardColors.hasGreen()) {
borderColors.add(CardBorderColor.GREEN);
borderColors.add(CardBorderColor.BLUE);
}
}
else if (cardColors.hasBlack()) {
if (colorCount == 1) {
borderColors.add(CardBorderColor.BLACK);
}
else if (cardColors.hasRed()) {
borderColors.add(CardBorderColor.BLACK);
borderColors.add(CardBorderColor.RED);
}
else if (cardColors.hasGreen()) {
borderColors.add(CardBorderColor.BLACK);
borderColors.add(CardBorderColor.GREEN);
}
}
else if (cardColors.hasRed()) { //if we got this far, must be mono-red or red-green
borderColors.add(CardBorderColor.RED);
if (cardColors.hasGreen()) {
borderColors.add(CardBorderColor.GREEN);
}
}
else if (cardColors.hasGreen()) { //if we got this far, must be mono-green
borderColors.add(CardBorderColor.GREEN);
}
}
if (borderColors.isEmpty()) { // If your card has a violet border, something is wrong
borderColors.add(CardBorderColor.UNKNOWN);
}
return borderColors;
}
public static String getItemDescription(final InventoryItemFromSet item) {
if (item instanceof SealedProduct) {
return ((SealedProduct)item).getDescription();