Fixed unit stats bars not being interpolated

This commit is contained in:
Anuken
2018-06-22 15:48:38 -04:00
parent fc058476ed
commit 57d5628750
5 changed files with 17 additions and 12 deletions

View File

@@ -273,15 +273,15 @@ public class Renderer extends RendererModule{
}
}
private <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group){
public <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group){
drawAndInterpolate(group, t -> true, DrawTrait::draw);
}
private <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group, Predicate<T> toDraw){
public <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group, Predicate<T> toDraw){
drawAndInterpolate(group, toDraw, DrawTrait::draw);
}
private <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group, Predicate<T> toDraw, Consumer<T> drawer){
public <T extends DrawTrait> void drawAndInterpolate(EntityGroup<T> group, Predicate<T> toDraw, Consumer<T> drawer){
EntityDraw.drawWith(group, toDraw, t -> {
float lastx = t.getX(), lasty = t.getY(), lastrot = 0f;

View File

@@ -281,6 +281,10 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
}
}
public float getAmmoFraction(){
return inventory.totalAmmo() / (float)inventory.ammoCapacity();
}
public void drawUnder(){}
public void drawOver(){}

View File

@@ -168,6 +168,11 @@ public class Drone extends FlyingUnit implements BuilderTrait {
return isBuilding() ? placeDistance*2f : 30f;
}
@Override
public float getAmmoFraction() {
return inventory.getItem().amount / (float)type.itemCapacity;
}
protected void findItem(){
TileEntity entity = getClosestCore();
if(entity == null){

View File

@@ -156,16 +156,11 @@ public class OverlayRenderer {
}
if((!debug || showUI) && Settings.getBool("healthbars")){
for(TeamData ally : (debug ? state.teams.getTeams() : state.teams.getTeams(true))){
for(Unit e : unitGroups[ally.team.ordinal()].all()){
drawStats(e);
}
renderer.drawAndInterpolate(unitGroups[ally.team.ordinal()], u -> !u.isDead(), this::drawStats);
}
for(Unit e : playerGroup.all()){
drawStats(e);
}
renderer.drawAndInterpolate(playerGroup, u -> !u.isDead(), this::drawStats);
}
}
@@ -182,7 +177,7 @@ public class OverlayRenderer {
drawEncloser(x, y - 8f, 2f);
drawBar(Palette.healthstats, x, y - 8f, unit.healthf());
drawBar(Palette.ammo, x, y - 9f, unit.inventory.totalAmmo() / (float) unit.inventory.ammoCapacity());
drawBar(Palette.ammo, x, y - 9f, unit.getAmmoFraction());
}
void drawBar(Color color, float x, float y, float finion){

View File

@@ -44,6 +44,7 @@ public class CoreBlock extends StorageBlock {
protected float supplyRadius = 50f;
protected float supplyInterval = 5f;
protected float droneRespawnDuration = 60*6;
protected UnitType droneType = UnitTypes.drone;
public CoreBlock(String name) {
@@ -155,7 +156,7 @@ public class CoreBlock extends StorageBlock {
if(entity.currentUnit != null){
entity.heat = Mathf.lerpDelta(entity.heat, 1f, 0.1f);
entity.time += Timers.delta();
entity.progress += 1f / Vars.respawnduration;
entity.progress += 1f / (entity.currentUnit instanceof Player ? respawnduration : droneRespawnDuration);
//instant build for fast testing.
if(debug){