StatsView: render as single object

experimental
Kirill Vainer 10 years ago
parent ed61979825
commit a43a405ca1
  1. 24
      jme3-core/src/main/java/com/jme3/app/StatsView.java

@ -60,7 +60,7 @@ import com.jme3.scene.control.Control;
*/ */
public class StatsView extends Node implements Control { public class StatsView extends Node implements Control {
private BitmapText[] labels; private BitmapText statText;
private Statistics statistics; private Statistics statistics;
private String[] statLabels; private String[] statLabels;
@ -81,20 +81,17 @@ public class StatsView extends Node implements Control {
statLabels = statistics.getLabels(); statLabels = statistics.getLabels();
statData = new int[statLabels.length]; statData = new int[statLabels.length];
labels = new BitmapText[statLabels.length];
BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt"); BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
for (int i = 0; i < labels.length; i++){ statText = new BitmapText(font);
labels[i] = new BitmapText(font); statText.setLocalTranslation(0, statText.getLineHeight() * statLabels.length, 0);
labels[i].setLocalTranslation(0, labels[i].getLineHeight() * (i+1), 0); attachChild(statText);
attachChild(labels[i]);
}
addControl(this); addControl(this);
} }
public float getHeight() { public float getHeight() {
return labels[0].getLineHeight() * statLabels.length; return statText.getLineHeight() * statText.getLineCount(); // labels[0].getLineHeight() * statLabels.length;
} }
public void update(float tpf) { public void update(float tpf) {
@ -103,11 +100,14 @@ public class StatsView extends Node implements Control {
return; return;
statistics.getData(statData); statistics.getData(statData);
for (int i = 0; i < labels.length; i++) { stringBuilder.setLength(0);
stringBuilder.setLength(0);
stringBuilder.append(statLabels[i]).append(" = ").append(statData[i]); // Need to walk through it backwards, as the first label
labels[i].setText(stringBuilder); // should appear at the bottom, not the top.
for (int i = statLabels.length - 1; i >= 0; i--) {
stringBuilder.append(statLabels[i]).append(" = ").append(statData[i]).append('\n');
} }
statText.setText(stringBuilder);
// Moved to ResetStatsState to make sure it is // Moved to ResetStatsState to make sure it is
// done even if there is no StatsView or the StatsView // done even if there is no StatsView or the StatsView

Loading…
Cancel
Save