* Fixed that the render frame of copies of normal cards got the normal card rule box size.

This commit is contained in:
LevelX2 2017-01-19 23:50:20 +01:00
parent a175ac3a1d
commit 05940aa481
3 changed files with 35 additions and 30 deletions

View file

@ -14,7 +14,6 @@ import java.awt.Paint;
import java.awt.Polygon; import java.awt.Polygon;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.constants.AbilityType; import mage.constants.AbilityType;
import mage.constants.CardType; import mage.constants.CardType;
@ -171,11 +170,12 @@ public abstract class CardRenderer {
} }
/** /**
* How far does a card have to be spaced down from * How far does a card have to be spaced down from a rendered card to show
* a rendered card to show it's entire name line? * it's entire name line? This function is a bit of a hack, as different
* This function is a bit of a hack, as different card faces need * card faces need slightly different spacing, but we need it in a static
* slightly different spacing, but we need it in a static context * context so that spacing is consistent in GY / deck views etc.
* so that spacing is consistent in GY / deck views etc. *
* @param cardWidth
* @return * @return
*/ */
public static int getCardTopHeight(int cardWidth) { public static int getCardTopHeight(int cardWidth) {
@ -186,7 +186,7 @@ public abstract class CardRenderer {
BOX_HEIGHT_MIN, BOX_HEIGHT_MIN,
BOX_HEIGHT_FRAC * cardWidth * 1.4f); BOX_HEIGHT_FRAC * cardWidth * 1.4f);
int borderWidth = getBorderWidth(cardWidth); int borderWidth = getBorderWidth(cardWidth);
return 2*borderWidth + boxHeight; return 2 * borderWidth + boxHeight;
} }
// The Draw Method // The Draw Method

View file

@ -19,14 +19,16 @@ import java.util.regex.Pattern;
/** /**
* @author stravant@gmail.com * @author stravant@gmail.com
* *
* Various static utilities for use in the card renderer * Various static utilities for use in the card renderer
*/ */
public class CardRendererUtils { public class CardRendererUtils {
/** /**
* Convert an abstract image, whose underlying implementation may or may * Convert an abstract image, whose underlying implementation may or may not
* not be a BufferedImage into a BufferedImage by creating one and coping * be a BufferedImage into a BufferedImage by creating one and coping the
* the contents if it is not, and simply up-casting if it is. * contents if it is not, and simply up-casting if it is.
*
* @param img The image to convert * @param img The image to convert
* @return The converted image * @return The converted image
*/ */
@ -35,7 +37,7 @@ public class CardRendererUtils {
if (img == null) { if (img == null) {
return null; return null;
} }
// Already a buffered image? // Already a buffered image?
if (img instanceof BufferedImage) { if (img instanceof BufferedImage) {
return (BufferedImage) img; return (BufferedImage) img;
@ -52,25 +54,25 @@ public class CardRendererUtils {
// Return the buffered image // Return the buffered image
return bimage; return bimage;
} }
// Draw a rounded box with a 2-pixel border // Draw a rounded box with a 2-pixel border
// Used on various card parts. // Used on various card parts.
public static void drawRoundedBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Color fill) { public static void drawRoundedBox(Graphics2D g, int x, int y, int w, int h, int bevel, Paint border, Color fill) {
g.setColor(new Color(0, 0, 0, 150)); g.setColor(new Color(0, 0, 0, 150));
g.drawOval(x-1, y-1, bevel*2, h); g.drawOval(x - 1, y - 1, bevel * 2, h);
g.setPaint(border); g.setPaint(border);
g.drawOval(x, y, bevel*2-1, h-1); g.drawOval(x, y, bevel * 2 - 1, h - 1);
g.drawOval(x + w - bevel*2, y, bevel*2-1, h-1); g.drawOval(x + w - bevel * 2, y, bevel * 2 - 1, h - 1);
g.drawOval(x+1, y+1, bevel*2-3, h-3); g.drawOval(x + 1, y + 1, bevel * 2 - 3, h - 3);
g.drawOval(x+1 + w - bevel*2, y+1, bevel*2-3, h-3); g.drawOval(x + 1 + w - bevel * 2, y + 1, bevel * 2 - 3, h - 3);
g.drawRect(x + bevel, y, w - 2*bevel, h-1); g.drawRect(x + bevel, y, w - 2 * bevel, h - 1);
g.drawRect(x+1 + bevel, y+1, w - 2*bevel-2, h-3); g.drawRect(x + 1 + bevel, y + 1, w - 2 * bevel - 2, h - 3);
g.setColor(fill); g.setColor(fill);
g.fillOval(x+2, y+2, bevel*2-4, h-4); g.fillOval(x + 2, y + 2, bevel * 2 - 4, h - 4);
g.fillOval(x+2 + w - bevel*2, y+2, bevel*2-4, h-4); g.fillOval(x + 2 + w - bevel * 2, y + 2, bevel * 2 - 4, h - 4);
g.fillRect(x + bevel, y+2, w - 2*bevel, h-4); g.fillRect(x + bevel, y + 2, w - 2 * bevel, h - 4);
} }
// Get the width of a mana cost rendered with ManaSymbols.draw // Get the width of a mana cost rendered with ManaSymbols.draw
public static int getManaCostWidth(String manaCost, int symbolSize) { public static int getManaCostWidth(String manaCost, int symbolSize) {
int width = 0; int width = 0;
@ -82,18 +84,19 @@ public class CardRendererUtils {
} }
return width; return width;
} }
// Abbreviate a piece of rules text, making substitutions to decrease its // Abbreviate a piece of rules text, making substitutions to decrease its
// length. Also abbreviate reminder text. // length. Also abbreviate reminder text.
private static final Pattern abbreviationPattern; private static final Pattern abbreviationPattern;
private static final Map<String, String> abbreviations = new HashMap<String, String>(); private static final Map<String, String> abbreviations = new HashMap<>();
private static final Pattern killReminderTextPattern; private static final Pattern killReminderTextPattern;
static { static {
// Available abbreviations // Available abbreviations
abbreviations.put("enters the battlefield", "ETB"); abbreviations.put("enters the battlefield", "ETB");
abbreviations.put("less than", "<"); abbreviations.put("less than", "<");
abbreviations.put("greater than", ">"); abbreviations.put("greater than", ">");
// Compile into regex // Compile into regex
String patternString = "("; String patternString = "(";
Iterator<String> it = abbreviations.keySet().iterator(); Iterator<String> it = abbreviations.keySet().iterator();
@ -105,10 +108,11 @@ public class CardRendererUtils {
} }
patternString += ")"; patternString += ")";
abbreviationPattern = Pattern.compile(patternString); abbreviationPattern = Pattern.compile(patternString);
// Reminder text killing // Reminder text killing
killReminderTextPattern = Pattern.compile("\\([^\\)]*\\)"); killReminderTextPattern = Pattern.compile("\\([^\\)]*\\)");
} }
public static String abbreviateRule(String rule) { public static String abbreviateRule(String rule) {
StringBuffer build = new StringBuffer(); StringBuffer build = new StringBuffer();
Matcher match = abbreviationPattern.matcher(rule); Matcher match = abbreviationPattern.matcher(rule);
@ -118,6 +122,7 @@ public class CardRendererUtils {
match.appendTail(build); match.appendTail(build);
return build.toString(); return build.toString();
} }
public static String killReminderText(String rule) { public static String killReminderText(String rule) {
return killReminderTextPattern.matcher(rule).replaceAll(""); return killReminderTextPattern.matcher(rule).replaceAll("");
} }

View file

@ -311,7 +311,7 @@ public class ModernCardRenderer extends CardRenderer {
Rectangle2D rect; Rectangle2D rect;
if (useInventionFrame()) { if (useInventionFrame()) {
rect = new Rectangle2D.Float(0, 0, 1, 1); rect = new Rectangle2D.Float(0, 0, 1, 1);
} else if (cardView.getFrameStyle().isFullArt() || cardView.isToken()) { } else if (cardView.getFrameStyle().isFullArt() || (cardView.isToken())) {
rect = new Rectangle2D.Float(.079f, .11f, .84f, .63f); rect = new Rectangle2D.Float(.079f, .11f, .84f, .63f);
} else { } else {
rect = new Rectangle2D.Float(.079f, .11f, .84f, .42f); rect = new Rectangle2D.Float(.079f, .11f, .84f, .42f);
@ -320,7 +320,7 @@ public class ModernCardRenderer extends CardRenderer {
} }
private float getTypeLineYFrac() { private float getTypeLineYFrac() {
if (cardView.isToken()) { if (cardView.isToken() && cardView.getCardNumber() == null) {
return TYPE_LINE_Y_FRAC_TOKEN; return TYPE_LINE_Y_FRAC_TOKEN;
} else if (cardView.getFrameStyle().isFullArt()) { } else if (cardView.getFrameStyle().isFullArt()) {
return TYPE_LINE_Y_FRAC_FULL_ART; return TYPE_LINE_Y_FRAC_FULL_ART;