mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
displays assigned damage on cards
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -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/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/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/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/arcane/util/package-info.java svneol=native#text/plain
|
||||||
src/main/java/forge/view/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
|
src/main/resources/no_card.jpg -text
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ import forge.card.mana.ManaCost;
|
|||||||
import forge.gui.CardContainer;
|
import forge.gui.CardContainer;
|
||||||
import forge.gui.toolbox.CardFaceSymbols;
|
import forge.gui.toolbox.CardFaceSymbols;
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
import forge.view.arcane.util.GlowText;
|
import forge.view.arcane.util.OutlinedLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -78,10 +78,7 @@ public class CardPanel extends JPanel implements CardContainer {
|
|||||||
private static final float SELECTED_BORDER_SIZE = 0.01f;
|
private static final float SELECTED_BORDER_SIZE = 0.01f;
|
||||||
/** Constant <code>BLACK_BORDER_SIZE=0.03f</code>. */
|
/** Constant <code>BLACK_BORDER_SIZE=0.03f</code>. */
|
||||||
private static final float BLACK_BORDER_SIZE = 0.03f;
|
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
|
* Constant
|
||||||
* <code>rotCenterToTopCorner=1.0295630140987000315797369464196f</code>.
|
* <code>rotCenterToTopCorner=1.0295630140987000315797369464196f</code>.
|
||||||
@@ -118,8 +115,9 @@ public class CardPanel extends JPanel implements CardContainer {
|
|||||||
*/
|
*/
|
||||||
private final ScaledImagePanel imagePanel;
|
private final ScaledImagePanel imagePanel;
|
||||||
|
|
||||||
private final GlowText titleText;
|
private final OutlinedLabel titleText;
|
||||||
private final GlowText ptText;
|
private final OutlinedLabel ptText;
|
||||||
|
private final OutlinedLabel damageText;
|
||||||
private final List<CardPanel> imageLoadListeners = new ArrayList<CardPanel>(2);
|
private final List<CardPanel> imageLoadListeners = new ArrayList<CardPanel>(2);
|
||||||
private boolean displayEnabled = true;
|
private boolean displayEnabled = true;
|
||||||
private boolean isAnimationPanel;
|
private boolean isAnimationPanel;
|
||||||
@@ -141,19 +139,26 @@ public class CardPanel extends JPanel implements CardContainer {
|
|||||||
this.setBackground(Color.black);
|
this.setBackground(Color.black);
|
||||||
this.setOpaque(false);
|
this.setOpaque(false);
|
||||||
|
|
||||||
this.titleText = new GlowText();
|
this.titleText = new OutlinedLabel();
|
||||||
this.titleText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
this.titleText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
||||||
this.titleText.setForeground(Color.white);
|
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.titleText.setWrap(true);
|
||||||
this.add(this.titleText);
|
this.add(this.titleText);
|
||||||
|
|
||||||
this.ptText = new GlowText();
|
this.ptText = new OutlinedLabel();
|
||||||
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
this.ptText.setFont(this.getFont().deriveFont(Font.BOLD, 13f));
|
||||||
this.ptText.setForeground(Color.white);
|
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.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.imagePanel = new ScaledImagePanel();
|
||||||
this.add(this.imagePanel);
|
this.add(this.imagePanel);
|
||||||
this.addComponentListener(new ComponentAdapter() {
|
this.addComponentListener(new ComponentAdapter() {
|
||||||
@@ -451,26 +456,41 @@ public class CardPanel extends JPanel implements CardContainer {
|
|||||||
@Override
|
@Override
|
||||||
public final void doLayout() {
|
public final void doLayout() {
|
||||||
final int borderSize = Math.round(this.cardWidth * CardPanel.BLACK_BORDER_SIZE);
|
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 int fontHeight = Math.round(this.cardHeight * (27f / 680));
|
||||||
final boolean showText = !this.imagePanel.hasImage() || (!this.isAnimationPanel && (fontHeight < 12));
|
final boolean showText = !this.imagePanel.hasImage() || (!this.isAnimationPanel && (fontHeight < 12));
|
||||||
this.titleText.setVisible(showText);
|
this.titleText.setVisible(showText);
|
||||||
this.ptText.setVisible(showText);
|
this.ptText.setVisible(showText);
|
||||||
|
this.damageText.setVisible(showText);
|
||||||
|
|
||||||
final int titleX = Math.round(this.cardWidth * (20f / 480));
|
final int TEXT_GLOW_SIZE = 1;
|
||||||
final int titleY = Math.round(this.cardHeight * (9f / 680));
|
|
||||||
this.titleText.setBounds(this.cardXOffset + titleX, this.cardYOffset + titleY, this.cardWidth - titleX,
|
final int titleX = Math.round(imgSize.width * (24f / 480));
|
||||||
this.cardHeight);
|
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();
|
final Dimension ptSize = this.ptText.getPreferredSize();
|
||||||
this.ptText.setSize(ptSize.width, ptSize.height);
|
this.ptText.setSize(ptSize.width, ptSize.height);
|
||||||
final int ptX = Math.round(this.cardWidth * (420f / 480)) - (ptSize.width / 2);
|
final int ptX = rightLine - ptSize.width/2;
|
||||||
final int ptY = Math.round(this.cardHeight * (675f / 680)) - ptSize.height;
|
final int ptY = Math.round(imgSize.height * (650f / 680)) - 13;
|
||||||
this.ptText.setLocation((this.cardXOffset + ptX) - (CardPanel.TEXT_GLOW_SIZE / 2), (this.cardYOffset + ptY)
|
this.ptText.setLocation(imgPos.x + ptX, imgPos.y + ptY);
|
||||||
- (CardPanel.TEXT_GLOW_SIZE / 2));
|
|
||||||
|
|
||||||
|
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;
|
this.showCastingCost = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String sPt = "";
|
||||||
if (card.isCreature() && card.isPlaneswalker()) {
|
if (card.isCreature() && card.isPlaneswalker()) {
|
||||||
this.ptText.setText(card.getNetAttack() + "/" + card.getNetDefense() + " ("
|
sPt = String.format("%d/%d (%d)", card.getNetAttack(), card.getNetDefense(), card.getCounters(CounterType.LOYALTY));
|
||||||
+ String.valueOf(card.getCounters(CounterType.LOYALTY)) + ")");
|
|
||||||
} else if (card.isCreature()) {
|
} else if (card.isCreature()) {
|
||||||
this.ptText.setText(card.getNetAttack() + "/" + card.getNetDefense());
|
sPt = String.format("%d/%d", card.getNetAttack(), card.getNetDefense());
|
||||||
} else if (card.isPlaneswalker()) {
|
} else if (card.isPlaneswalker()) {
|
||||||
int loyalty = card.getCounters(CounterType.LOYALTY);
|
int loyalty = card.getCounters(CounterType.LOYALTY);
|
||||||
if (loyalty == 0) {
|
sPt = String.valueOf(loyalty == 0 ? card.getBaseLoyalty() : loyalty);
|
||||||
loyalty = card.getBaseLoyalty();
|
|
||||||
}
|
|
||||||
this.ptText.setText(String.valueOf(loyalty));
|
|
||||||
} else {
|
|
||||||
this.ptText.setText("");
|
|
||||||
}
|
}
|
||||||
|
this.ptText.setText(sPt);
|
||||||
|
|
||||||
|
int damage = card.getDamage();
|
||||||
|
this.damageText.setText(damage > 0 ? "\u00BB " + String.valueOf(damage) + " \u00AB" : "");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,18 +42,18 @@ import javax.swing.JLabel;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GlowText extends JLabel {
|
public class OutlinedLabel extends JLabel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new glow text.
|
* Instantiates a new glow text.
|
||||||
*/
|
*/
|
||||||
public GlowText() {
|
public OutlinedLabel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constant <code>serialVersionUID=-2868833097364223352L</code>. */
|
/** Constant <code>serialVersionUID=-2868833097364223352L</code>. */
|
||||||
private static final long serialVersionUID = -2868833097364223352L;
|
private static final long serialVersionUID = -2868833097364223352L;
|
||||||
private int glowSize;
|
private Color outlineColor;
|
||||||
private Color glowColor;
|
private final static int outlineSize = 1;
|
||||||
private boolean wrap;
|
private boolean wrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,9 +68,8 @@ public class GlowText extends JLabel {
|
|||||||
* @param intensity
|
* @param intensity
|
||||||
* a float.
|
* a float.
|
||||||
*/
|
*/
|
||||||
public final void setGlow(final Color glowColor, int size, float intensity) {
|
public final void setGlow(final Color glowColor) {
|
||||||
this.glowColor = glowColor;
|
this.outlineColor = glowColor;
|
||||||
this.glowSize = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,8 +94,8 @@ public class GlowText extends JLabel {
|
|||||||
@Override
|
@Override
|
||||||
public final Dimension getPreferredSize() {
|
public final Dimension getPreferredSize() {
|
||||||
Dimension size = super.getPreferredSize();
|
Dimension size = super.getPreferredSize();
|
||||||
size.width += glowSize;
|
size.width += outlineSize * 2;
|
||||||
size.height += glowSize / 2;
|
size.height += outlineSize * 2;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,21 +112,27 @@ public class GlowText extends JLabel {
|
|||||||
return;
|
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;
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
|
||||||
Dimension size = getSize();
|
int textX = outlineSize, textY = 0;
|
||||||
int textX = 0, textY = 0;
|
int wrapWidth = Math.max(0, wrap ? size.width - outlineSize * 2 : Integer.MAX_VALUE);
|
||||||
int wrapWidth = Math.max(0, wrap ? size.width - glowSize : Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
AttributedString attributedString = new AttributedString(getText());
|
AttributedString attributedString = new AttributedString(getText());
|
||||||
attributedString.addAttribute(TextAttribute.FONT, getFont());
|
attributedString.addAttribute(TextAttribute.FONT, getFont());
|
||||||
AttributedCharacterIterator charIterator = attributedString.getIterator();
|
AttributedCharacterIterator charIterator = attributedString.getIterator();
|
||||||
FontRenderContext fontContext = g2d.getFontRenderContext();
|
FontRenderContext fontContext = g2d.getFontRenderContext();
|
||||||
|
|
||||||
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH),
|
LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, BreakIterator.getWordInstance(Locale.ENGLISH), fontContext);
|
||||||
fontContext);
|
|
||||||
int lineCount = 0;
|
int lineCount = 0;
|
||||||
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
while (measurer.getPosition() < charIterator.getEndIndex()) {
|
||||||
measurer.nextLayout(wrapWidth);
|
measurer.nextLayout(wrapWidth);
|
||||||
@@ -139,8 +144,7 @@ public class GlowText extends JLabel {
|
|||||||
charIterator.first();
|
charIterator.first();
|
||||||
// Use char wrap if word wrap would cause more than two lines of text.
|
// Use char wrap if word wrap would cause more than two lines of text.
|
||||||
if (lineCount > 2) {
|
if (lineCount > 2) {
|
||||||
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH),
|
measurer = new LineBreakMeasurer(charIterator, BreakIterator.getCharacterInstance(Locale.ENGLISH), fontContext);
|
||||||
fontContext);
|
|
||||||
} else {
|
} else {
|
||||||
measurer.setPosition(0);
|
measurer.setPosition(0);
|
||||||
}
|
}
|
||||||
@@ -149,24 +153,21 @@ public class GlowText extends JLabel {
|
|||||||
float ascent = textLayout.getAscent();
|
float ascent = textLayout.getAscent();
|
||||||
textY += ascent; // Move down to baseline.
|
textY += ascent; // Move down to baseline.
|
||||||
|
|
||||||
g2d.setColor(glowColor);
|
g2d.setColor(outlineColor);
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f));
|
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 + outlineSize, textY - outlineSize);
|
||||||
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);
|
||||||
|
|
||||||
g2d.setColor(getForeground());
|
g2d.setColor(getForeground());
|
||||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
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
|
// Move down to top of next line.
|
||||||
// down
|
textY += textLayout.getDescent() + textLayout.getLeading();
|
||||||
// to
|
|
||||||
// top
|
|
||||||
// of
|
|
||||||
// next
|
|
||||||
// line.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user