Prevent NPE

This commit is contained in:
Anthony Calosa
2019-09-12 20:28:48 +08:00
parent 7a28295585
commit 61f400feac

View File

@@ -558,21 +558,20 @@ public class CardRenderer {
} }
//if (counterBoxBaseWidth + font.getBounds(String.valueOf(maxCounters)).width > w) { //if (counterBoxBaseWidth + font.getBounds(String.valueOf(maxCounters)).width > w) {
if(font != null && !String.valueOf(maxCounters).isEmpty()){
layout.setText(font, String.valueOf(maxCounters)); 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;
if(font != null && !String.valueOf(numberOfCounters).isEmpty()){
layout.setText(font, String.valueOf(numberOfCounters)); layout.setText(font, String.valueOf(numberOfCounters));
final float counterBoxRealWidth = counterBoxBaseWidth + layout.width + 4; final float counterBoxRealWidth = counterBoxBaseWidth + layout.width + 4;
@@ -588,9 +587,8 @@ public class CardRenderer {
drawText(g, counter.getCounterOnCardDisplayName(), font, counterColor, x + 2 + additionalXOffset, counterYOffset, counterBoxRealWidth, counterBoxHeight, Align.left); 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); 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,7 +598,7 @@ 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); layout.setText(font, text);
TextBounds textBounds = new TextBounds(layout.width, layout.height); TextBounds textBounds = new TextBounds(layout.width, layout.height);
@@ -615,7 +613,7 @@ public class CardRenderer {
if (color.a < 1) { if (color.a < 1) {
Gdx.gl.glDisable(GL_BLEND); 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) {