mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Prevent NPE
This commit is contained in:
@@ -558,39 +558,37 @@ public class CardRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//if (counterBoxBaseWidth + font.getBounds(String.valueOf(maxCounters)).width > w) {
|
//if (counterBoxBaseWidth + font.getBounds(String.valueOf(maxCounters)).width > w) {
|
||||||
layout.setText(font, String.valueOf(maxCounters));
|
if(font != null && !String.valueOf(maxCounters).isEmpty()){
|
||||||
|
layout.setText(font, String.valueOf(maxCounters));
|
||||||
if (counterBoxBaseWidth + layout.width > w) {
|
if (counterBoxBaseWidth + layout.width > w) {
|
||||||
|
drawCounterImage(card, g, x, y, w, h);
|
||||||
drawCounterImage(card, g, x, y, w, h);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<CounterType, Integer> counterEntry : card.getCounters().entrySet()) {
|
for (Map.Entry<CounterType, Integer> counterEntry : card.getCounters().entrySet()) {
|
||||||
|
|
||||||
final CounterType counter = counterEntry.getKey();
|
final CounterType counter = counterEntry.getKey();
|
||||||
final int numberOfCounters = counterEntry.getValue();
|
final int numberOfCounters = counterEntry.getValue();
|
||||||
//final float counterBoxRealWidth = counterBoxBaseWidth + font.getBounds(String.valueOf(numberOfCounters)).width + 4;
|
//final float counterBoxRealWidth = counterBoxBaseWidth + font.getBounds(String.valueOf(numberOfCounters)).width + 4;
|
||||||
layout.setText(font, String.valueOf(numberOfCounters));
|
if(font != null && !String.valueOf(numberOfCounters).isEmpty()){
|
||||||
final float counterBoxRealWidth = counterBoxBaseWidth + layout.width + 4;
|
layout.setText(font, String.valueOf(numberOfCounters));
|
||||||
|
final float counterBoxRealWidth = counterBoxBaseWidth + layout.width + 4;
|
||||||
|
|
||||||
final float counterYOffset = spaceFromTopOfCard - (currentCounter++ * (counterBoxHeight + counterBoxSpacing));
|
final float counterYOffset = spaceFromTopOfCard - (currentCounter++ * (counterBoxHeight + counterBoxSpacing));
|
||||||
|
|
||||||
g.fillRect(counterBackgroundColor, x - 3, counterYOffset, counterBoxRealWidth, counterBoxHeight);
|
g.fillRect(counterBackgroundColor, x - 3, counterYOffset, counterBoxRealWidth, counterBoxHeight);
|
||||||
|
|
||||||
if (!counterColorCache.containsKey(counter)) {
|
if (!counterColorCache.containsKey(counter)) {
|
||||||
counterColorCache.put(counter, new Color(counter.getRed() / 255.0f, counter.getGreen() / 255.0f, counter.getBlue() / 255.0f, 1.0f));
|
counterColorCache.put(counter, new Color(counter.getRed() / 255.0f, counter.getGreen() / 255.0f, counter.getBlue() / 255.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
Color counterColor = counterColorCache.get(counter);
|
||||||
|
|
||||||
|
drawText(g, counter.getCounterOnCardDisplayName(), font, counterColor, x + 2 + additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, Align.left);
|
||||||
|
drawText(g, String.valueOf(numberOfCounters), font, counterColor, x + counterBoxBaseWidth - 4f - additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, Align.left);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color counterColor = counterColorCache.get(counter);
|
|
||||||
|
|
||||||
drawText(g, counter.getCounterOnCardDisplayName(), font, counterColor, x + 2 + additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, Align.left);
|
|
||||||
drawText(g, String.valueOf(numberOfCounters), font, counterColor, x + counterBoxBaseWidth - 4f - additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, Align.left);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final int GL_BLEND = GL20.GL_BLEND;
|
private static final int GL_BLEND = GL20.GL_BLEND;
|
||||||
@@ -600,22 +598,22 @@ public class CardRenderer {
|
|||||||
if (color.a < 1) { //enable blending so alpha colored shapes work properly
|
if (color.a < 1) { //enable blending so alpha colored shapes work properly
|
||||||
Gdx.gl.glEnable(GL_BLEND);
|
Gdx.gl.glEnable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
if(font != null && !text.isEmpty()) {
|
||||||
|
layout.setText(font, text);
|
||||||
|
TextBounds textBounds = new TextBounds(layout.width, layout.height);
|
||||||
|
|
||||||
layout.setText(font, text);
|
float textHeight = textBounds.height;
|
||||||
TextBounds textBounds = new TextBounds(layout.width, layout.height);
|
if (h > textHeight) {
|
||||||
|
y += (h - textHeight) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
float textHeight = textBounds.height;
|
font.setColor(color);
|
||||||
if (h > textHeight) {
|
font.draw(g.getBatch(), text, g.adjustX(x), g.adjustY(y, 0), w, horizontalAlignment, true);
|
||||||
y += (h - textHeight) / 2;
|
|
||||||
|
if (color.a < 1) {
|
||||||
|
Gdx.gl.glDisable(GL_BLEND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
font.setColor(color);
|
|
||||||
font.draw(g.getBatch(), text, g.adjustX(x), g.adjustY(y, 0), w, horizontalAlignment, true);
|
|
||||||
|
|
||||||
if (color.a < 1) {
|
|
||||||
Gdx.gl.glDisable(GL_BLEND);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawCounterImage(final CardView card, final Graphics g, final float x, final float y, final float w, final float h) {
|
private static void drawCounterImage(final CardView card, final Graphics g, final float x, final float y, final float w, final float h) {
|
||||||
|
|||||||
Reference in New Issue
Block a user