displays assigned damage on cards

This commit is contained in:
Maxmtg
2013-05-28 08:35:13 +00:00
parent 8a1b422ca7
commit 176c67e105
3 changed files with 81 additions and 60 deletions

2
.gitattributes vendored
View File

@@ -14689,7 +14689,7 @@ src/main/java/forge/view/arcane/ViewPanel.java svneol=native#text/plain
src/main/java/forge/view/arcane/package-info.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/Animation.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/CardPanelMouseListener.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/GlowText.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/OutlinedLabel.java svneol=native#text/plain
src/main/java/forge/view/arcane/util/package-info.java svneol=native#text/plain
src/main/java/forge/view/package-info.java svneol=native#text/plain
src/main/resources/no_card.jpg -text

View File

@@ -45,7 +45,7 @@ import forge.card.mana.ManaCost;
import forge.gui.CardContainer;
import forge.gui.toolbox.CardFaceSymbols;
import forge.properties.ForgePreferences.FPref;
import forge.view.arcane.util.GlowText;
import forge.view.arcane.util.OutlinedLabel;
/**
* <p>
@@ -78,10 +78,7 @@ public class CardPanel extends JPanel implements CardContainer {
private static final float SELECTED_BORDER_SIZE = 0.01f;
/** Constant <code>BLACK_BORDER_SIZE=0.03f</code>. */
private static final float BLACK_BORDER_SIZE = 0.03f;
/** Constant <code>TEXT_GLOW_SIZE=6</code>. */
private static final int TEXT_GLOW_SIZE = 6;
/** Constant <code>TEXT_GLOW_INTENSITY=3f</code>. */
private static final float TEXT_GLOW_INTENSITY = 3f;
/**
* Constant
* <code>rotCenterToTopCorner=1.0295630140987000315797369464196f</code>.
@@ -118,8 +115,9 @@ public class CardPanel extends JPanel implements CardContainer {
*/
private final ScaledImagePanel imagePanel;
private final GlowText titleText;
private final GlowText ptText;
private final OutlinedLabel titleText;
private final OutlinedLabel ptText;
private final OutlinedLabel damageText;
private final List<CardPanel> imageLoadListeners = new ArrayList<CardPanel>(2);
private boolean displayEnabled = true;
private boolean isAnimationPanel;
@@ -141,19 +139,26 @@ public class CardPanel extends JPanel implements CardContainer {
this.setBackground(Color.black);
this.setOpaque(false);
this.titleText = new GlowText();
this.titleText = new OutlinedLabel();
this.titleText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
this.titleText.setForeground(Color.white);
this.titleText.setGlow(Color.black, CardPanel.TEXT_GLOW_SIZE, CardPanel.TEXT_GLOW_INTENSITY);
this.titleText.setGlow(Color.black);
this.titleText.setWrap(true);
this.add(this.titleText);
this.ptText = new GlowText();
this.ptText = new OutlinedLabel();
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
this.ptText.setForeground(Color.white);
this.ptText.setGlow(Color.black, CardPanel.TEXT_GLOW_SIZE, CardPanel.TEXT_GLOW_INTENSITY);
this.ptText.setGlow(Color.black);
this.add(this.ptText);
this.damageText = new OutlinedLabel();
this.damageText.setFont(this.getFont().deriveFont(Font.BOLD, 15f));
this.damageText.setForeground(new Color(160,0,0));
this.damageText.setGlow(Color.white);
this.add(this.damageText);
this.imagePanel = new ScaledImagePanel();
this.add(this.imagePanel);
this.addComponentListener(new ComponentAdapter() {
@@ -451,25 +456,40 @@ public class CardPanel extends JPanel implements CardContainer {
@Override
public final void doLayout() {
final int borderSize = Math.round(this.cardWidth * CardPanel.BLACK_BORDER_SIZE);
this.imagePanel.setLocation(this.cardXOffset + borderSize, this.cardYOffset + borderSize);
this.imagePanel.setSize(this.cardWidth - (borderSize * 2), this.cardHeight - (borderSize * 2));
final Point imgPos = new Point(this.cardXOffset + borderSize, this.cardYOffset + borderSize);
final Dimension imgSize = new Dimension(this.cardWidth - (borderSize * 2), this.cardHeight - (borderSize * 2));
this.imagePanel.setLocation(imgPos);
this.imagePanel.setSize(imgSize);
final int fontHeight = Math.round(this.cardHeight * (27f / 680));
final boolean showText = !this.imagePanel.hasImage() || (!this.isAnimationPanel && (fontHeight < 12));
this.titleText.setVisible(showText);
this.ptText.setVisible(showText);
this.damageText.setVisible(showText);
final int titleX = Math.round(this.cardWidth * (20f / 480));
final int titleY = Math.round(this.cardHeight * (9f / 680));
this.titleText.setBounds(this.cardXOffset + titleX, this.cardYOffset + titleY, this.cardWidth - titleX,
this.cardHeight);
final int TEXT_GLOW_SIZE = 1;
final int titleX = Math.round(imgSize.width * (24f / 480));
final int titleY = Math.round(imgSize.height * (54f / 640)) - 15;
final int titleH = Math.round(imgSize.height * (360f / 640));
this.titleText.setBounds(imgPos.x + titleX, imgPos.y + titleY, imgSize.width - 2 * titleX, titleH - titleY);
final int rightLine = Math.round(imgSize.width * (412f / 480));
final Dimension ptSize = this.ptText.getPreferredSize();
this.ptText.setSize(ptSize.width, ptSize.height);
final int ptX = Math.round(this.cardWidth * (420f / 480)) - (ptSize.width / 2);
final int ptY = Math.round(this.cardHeight * (675f / 680)) - ptSize.height;
this.ptText.setLocation((this.cardXOffset + ptX) - (CardPanel.TEXT_GLOW_SIZE / 2), (this.cardYOffset + ptY)
- (CardPanel.TEXT_GLOW_SIZE / 2));
final int ptX = rightLine - ptSize.width/2;
final int ptY = Math.round(imgSize.height * (650f / 680)) - 13;
this.ptText.setLocation(imgPos.x + ptX, imgPos.y + ptY);
final Dimension dmgSize = this.damageText.getPreferredSize();
this.damageText.setSize(dmgSize.width, dmgSize.height);
final int dmgX = rightLine - dmgSize.width / 2;
final int dmgY = ptY - 16;
this.damageText.setLocation(imgPos.x + dmgX, imgPos.y + dmgY);
}
@@ -610,20 +630,20 @@ public class CardPanel extends JPanel implements CardContainer {
this.showCastingCost = true;
}
String sPt = "";
if (card.isCreature() && card.isPlaneswalker()) {
this.ptText.setText(card.getNetAttack() + "/" + card.getNetDefense() + " ("
+ String.valueOf(card.getCounters(CounterType.LOYALTY)) + ")");
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCounters(CounterType.LOYALTY));
} else if (card.isCreature()) {
this.ptText.setText(card.getNetAttack() + "/" + card.getNetDefense());
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
} else if (card.isPlaneswalker()) {
int loyalty = card.getCounters(CounterType.LOYALTY);
if (loyalty == 0) {
loyalty = card.getBaseLoyalty();
}
this.ptText.setText(String.valueOf(loyalty));
} else {
this.ptText.setText("");
sPt = String.valueOf(loyalty == 0 ? card.getBaseLoyalty() : loyalty);
}
this.ptText.setText(sPt);
int damage = card.getDamage();
this.damageText.setText(damage > 0 ? "\u00BB " + String.valueOf(damage) + " \u00AB" : "");
}
/**

View File

@@ -42,18 +42,18 @@ import javax.swing.JLabel;
* @author Forge
* @version $Id$
*/
public class GlowText extends JLabel {
public class OutlinedLabel extends JLabel {
/**
* Instantiates a new glow text.
*/
public GlowText() {
public OutlinedLabel() {
}
/** Constant <code>serialVersionUID=-2868833097364223352L</code>. */
private static final long serialVersionUID = -2868833097364223352L;
private int glowSize;
private Color glowColor;
private Color outlineColor;
private final static int outlineSize = 1;
private boolean wrap;
/**
@@ -68,9 +68,8 @@ public class GlowText extends JLabel {
* @param intensity
* a float.
*/
public final void setGlow(final Color glowColor, int size, float intensity) {
this.glowColor = glowColor;
this.glowSize = size;
public final void setGlow(final Color glowColor) {
this.outlineColor = glowColor;
}
/**
@@ -95,8 +94,8 @@ public class GlowText extends JLabel {
@Override
public final Dimension getPreferredSize() {
Dimension size = super.getPreferredSize();
size.width += glowSize;
size.height += glowSize / 2;
size.width += outlineSize * 2;
size.height += outlineSize * 2;
return size;
}
@@ -113,21 +112,27 @@ public class GlowText extends JLabel {
return;
}
Dimension size = getSize();
//
// if( size.width < 50 ) {
// g.setColor(Color.cyan);
// g.drawRect(0, 0, size.width-1, size.height-1);
// }
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
Dimension size = getSize();
int textX = 0, textY = 0;
int wrapWidth = Math.max(0, wrap ? size.width - glowSize : Integer.MAX_VALUE);
int textX = outlineSize, textY = 0;
int wrapWidth = Math.max(0, wrap ? size.width - outlineSize * 2 : Integer.MAX_VALUE);
AttributedString attributedString = new AttributedString(getText());
attributedString.addAttribute(TextAttribute.FONT, getFont());
AttributedCharacterIterator charIterator = attributedString.getIterator();
FontRenderContext fontContext = g2d.getFontRenderContext();
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH),
fontContext);
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
int lineCount = 0;
while (measurer.getPosition() < charIterator.getEndIndex()) {
measurer.nextLayout(wrapWidth);
@@ -139,8 +144,7 @@ public class GlowText extends JLabel {
charIterator.first();
// Use char wrap if word wrap would cause more than two lines of text.
if (lineCount > 2) {
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH),
fontContext);
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
} else {
measurer.setPosition(0);
}
@@ -149,24 +153,21 @@ public class GlowText extends JLabel {
float ascent = textLayout.getAscent();
textY += ascent; // Move down to baseline.
g2d.setColor(glowColor);
g2d.setColor(outlineColor);
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 - 1);
textLayout.draw(g2d, textX + glowSize / 2 + 1, textY + glowSize / 2 + 1);
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 - 1);
textLayout.draw(g2d, textX + glowSize / 2 - 1, textY + glowSize / 2 + 1);
textLayout.draw(g2d, textX + outlineSize, textY - outlineSize);
textLayout.draw(g2d, textX + outlineSize, textY + outlineSize);
textLayout.draw(g2d, textX - outlineSize, textY - outlineSize);
textLayout.draw(g2d, textX - outlineSize, textY + outlineSize);
g2d.setColor(getForeground());
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
textLayout.draw(g2d, textX + glowSize / 2, textY + glowSize / 2);
textLayout.draw(g2d, textX, textY);
textY += textLayout.getDescent() + textLayout.getLeading(); // Move
// down
// to
// top
// of
// next
// line.
// Move down to top of next line.
textY += textLayout.getDescent() + textLayout.getLeading();
}
}
}