Better wave timer / Sprite tweaks / Core wave spawns

This commit is contained in:
Anuken
2019-06-09 21:09:29 -04:00
parent 4199702b9b
commit ea0788f56c
18 changed files with 103 additions and 43 deletions

View File

@@ -2,6 +2,7 @@ package io.anuke.mindustry.ui;
import io.anuke.arc.Core;
import io.anuke.arc.function.Function;
/**
* A low-garbage way to format bundle strings.
@@ -10,15 +11,21 @@ public class IntFormat{
private final StringBuilder builder = new StringBuilder();
private final String text;
private int lastValue = Integer.MIN_VALUE;
private Function<Integer, String> converter = String::valueOf;
public IntFormat(String text){
this.text = text;
}
public IntFormat(String text, Function<Integer, String> converter){
this.text = text;
this.converter = converter;
}
public CharSequence get(int value){
if(lastValue != value){
builder.setLength(0);
builder.append(Core.bundle.format(text, value));
builder.append(Core.bundle.format(text, converter.get(value)));
}
lastValue = value;
return builder;

View File

@@ -534,11 +534,27 @@ public class HudFragment extends Fragment{
}
private void addWaveTable(TextButton table){
StringBuilder ibuild = new StringBuilder();
IntFormat wavef = new IntFormat("wave");
IntFormat enemyf = new IntFormat("wave.enemy");
IntFormat enemiesf = new IntFormat("wave.enemies");
IntFormat waitingf = new IntFormat("wave.waiting");
IntFormat waitingf = new IntFormat("wave.waiting", i -> {
ibuild.setLength(0);
int m = i/60;
int s = i % 60;
if(m <= 0){
ibuild.append(s);
}else{
ibuild.append(m);
ibuild.append(":");
if(s < 10){
ibuild.append("0");
}
ibuild.append(s);
}
return ibuild.toString();
});
table.clearChildren();
table.touchable(Touchable.enabled);