From 3ba57c347369246d1ce89863cc6048651cc3dd40 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 27 Apr 2018 13:43:08 -0400 Subject: [PATCH] Minor cleanup with bars --- .../src/io/anuke/mindustry/core/Renderer.java | 60 ++++++------------- .../mindustry/entities/UnitInventory.java | 4 ++ 2 files changed, 22 insertions(+), 42 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index aeb5f8db6e..25b83c07d3 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -396,26 +396,6 @@ public class Renderer extends RendererModule{ void drawOverlay(){ - //draw tutorial placement point - if(world.getMap().name.equals("tutorial") && control.tutorial().showBlock()){ - //TODO draw placement point for tutorial - /* - int x = world.getCore().x + control.tutorial().getPlacePoint().x; - int y = world.getCore().y + control.tutorial().getPlacePoint().y; - int rot = control.tutorial().getPlaceRotation(); - - Lines.stroke(1f); - Draw.color(Color.YELLOW); - Lines.square(x * tilesize, y * tilesize, tilesize / 2f + Mathf.sin(Timers.time(), 4f, 1f)); - - Draw.color(Color.ORANGE); - Lines.stroke(2f); - if(rot != -1){ - Lines.lineAngle(x * tilesize, y * tilesize, rot * 90, 6); - } - Draw.reset();*/ - } - //draw config selected block if(ui.configfrag.isShown()){ Tile tile = ui.configfrag.getSelectedTile(); @@ -475,8 +455,6 @@ public class Renderer extends RendererModule{ Lines.crect(target.drawx(), target.drawy(), target.block().size * tilesize, target.block().size * tilesize); Vector2 v = new Vector2(); - - Draw.tcolor(Color.YELLOW); Draw.tscl(0.25f); Array arr = target.block().getDebugInfo(target); @@ -541,34 +519,30 @@ public class Renderer extends RendererModule{ } } - //TODO draw health bars if((!debug || showUI) && Settings.getBool("healthbars")){ for(EntityGroup group : unitGroups){ - drawHealth(group); + for(Unit e : group.all()){ + drawStats(e); + } } - drawHealth(playerGroup); + for(Unit e : playerGroup.all()){ + drawStats(e); + } } } - void drawHealth(EntityGroup group){ - for(Unit e : group.all()){ - drawHealth(e); - } - } - - void drawHealth(Unit unit){ + void drawStats(Unit unit){ float x = unit.getDrawPosition().x; float y = unit.getDrawPosition().y; - if(unit instanceof Player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")){ - drawHealth((int) x, (int) y - 7f, unit.health, unit.maxhealth); - }else{ - drawHealth(x, y - 7f, unit.health, unit.maxhealth); - } - } - void drawHealth(float x, float y, float health, float maxhealth){ - drawBar(Color.SCARLET, x, y, health / maxhealth); + if(unit == player && snapCamera && Settings.getBool("smoothcam") && Settings.getBool("pixelate")) { + x = (int)x; + y = (int)y; + } + + drawBar(Color.SCARLET, x, y - 7f, unit.health / unit.maxhealth); + drawBar(Color.valueOf("32cf6d"), x, y - 8f, unit.inventory.totalAmmo() / (float) unit.inventory.ammoCapacity()); } //TODO optimize! @@ -583,11 +557,13 @@ public class Renderer extends RendererModule{ x -= 0.5f; y += 0.5f; - + /* Lines.stroke(3f); Draw.color(Color.SLATE); Lines.line(x - len + 1, y, x + len + 1.5f, y); - Lines.stroke(1f); + + Lines.stroke(1f);*/ + Draw.color(Color.BLACK); Lines.line(x - len + 1, y, x + len + 0.5f, y); Draw.color(color); diff --git a/core/src/io/anuke/mindustry/entities/UnitInventory.java b/core/src/io/anuke/mindustry/entities/UnitInventory.java index 17f09893a8..67ffb9bf8b 100644 --- a/core/src/io/anuke/mindustry/entities/UnitInventory.java +++ b/core/src/io/anuke/mindustry/entities/UnitInventory.java @@ -29,6 +29,10 @@ public class UnitInventory { totalAmmo --; } + public int totalAmmo(){ + return totalAmmo; + } + public int ammoCapacity(){ return ammoCapacity; }