Added health bars to block info / Fixed block info refresh bug

This commit is contained in:
Anuken
2019-01-22 13:45:33 -05:00
parent 72d7c1ba54
commit 0e5b95e3aa
11 changed files with 415 additions and 278 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

View File

@ -148,6 +148,7 @@ save.wave = Wave {0}
save.difficulty = Difficulty: {0}
save.date = Last Saved: {0}
save.playtime = Playtime: {0}
warning = Warning.
confirm = Confirm
delete = Delete
ok = OK
@ -239,6 +240,8 @@ editor = Editor
mapeditor = Map Editor
donate = Donate
abandon = Abandon
abandon.text = This zone and all its resources will be lost to the enemy.
locked = Locked
complete = [LIGHT_GRAY]Complete:
resume = Resume Zone:\n[LIGHT_GRAY]{0}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 988 KiB

After

Width:  |  Height:  |  Size: 989 KiB

View File

@ -38,6 +38,7 @@ public class Palette{
stoneGray = Color.valueOf("8f8f8f"),
health = Color.valueOf("ff341c"),
heal = Color.valueOf("98ffa9"),
bar = Color.SLATE,
accent = Color.valueOf("ffd37f"),

View File

@ -69,10 +69,6 @@ public class MapGenerator extends Generator{
for(int x = 0; x < data.width(); x++){
for(int y = 0; y < data.height(); y++){
if(Mathf.chance(0.05) && tiles[x][y].floor() == Blocks.stone && tiles[x][y].block() == Blocks.air){
tiles[x][y].setBlock(Blocks.rock);
}
final double scl = 10;
final int mag = 3;
int newX = Mathf.clamp((int)(simplex.octaveNoise2D(1, 1, 1.0 / scl, x, y) * mag + x), 0, data.width()-1);
@ -84,7 +80,7 @@ public class MapGenerator extends Generator{
}
if(enemySpawns > enemies.size){
throw new IllegalArgumentException("Enemy spawn pool greater than map spawn #.");
throw new IllegalArgumentException("Enemy spawn pool greater than map spawn number.");
}
if(enemySpawns != -1){

View File

@ -0,0 +1,82 @@
package io.anuke.mindustry.ui;
import io.anuke.arc.Core;
import io.anuke.arc.function.FloatProvider;
import io.anuke.arc.function.Supplier;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.BitmapFont;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.GlyphLayout;
import io.anuke.arc.graphics.g2d.ScissorStack;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Rectangle;
import io.anuke.arc.scene.Element;
import io.anuke.arc.scene.style.Drawable;
import io.anuke.arc.util.pooling.Pools;
public class Bar extends Element{
private static Rectangle scissor = new Rectangle();
private FloatProvider fraction;
private String name = "";
private float value, lastValue, blink;
private Color blinkColor = new Color();
public Bar(String name, Color color, FloatProvider fraction){
this.fraction = fraction;
this.name = Core.bundle.get(name);
this.blinkColor.set(color);
lastValue = value = fraction.get();
setColor(color);
}
public Bar(Supplier<String> name, Supplier<Color> color, FloatProvider fraction){
this.fraction = fraction;
update(() -> {
this.name = name.get();
setColor(color.get());
});
}
public Bar blink(Color color){
blinkColor.set(color);
return this;
}
@Override
public void draw(){
if(!Mathf.isEqual(lastValue, fraction.get())){
blink = 1f;
lastValue = fraction.get();
}
blink = Mathf.lerpDelta(blink, 0f, 0.2f);
value = Mathf.lerpDelta(value, fraction.get(), 0.15f);
Draw.colorl(0.1f);
Draw.drawable("bar", x, y, width, height);
Draw.color(color, blinkColor, blink);
Drawable top = Core.scene.skin.getDrawable("bar-top");
float topWidth = width * value;
if(topWidth > Core.atlas.find("bar-top").getWidth()){
top.draw(x, y, topWidth, height);
}else{
if(ScissorStack.pushScissors(scissor.set(x, y, topWidth, height))){
top.draw(x, y, Core.atlas.find("bar-top").getWidth(), height);
ScissorStack.popScissors();
}
}
Draw.color();
BitmapFont font = Core.scene.skin.getFont("default-font");
GlyphLayout lay = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
lay.setText(font, name);
font.draw(name, x + width/2f - lay.width/2f, y + height/2f + lay.height/2f + 1);
Pools.free(lay);
}
}

View File

@ -154,7 +154,11 @@ public class DeployDialog extends FloatingDialog{
}else{
SaveSlot slot = control.saves.getZoneSlot();
TextButton b[] = {null};
TextButton button = addButton(Core.bundle.format("resume", slot.getZone().localizedName()), () -> {
if(b[0].childrenPressed()) return;
hide();
ui.loadAnd(() -> {
try{
@ -168,6 +172,7 @@ public class DeployDialog extends FloatingDialog{
}
});
}).size(200f).get();
b[0] = button;
String color = "[lightgray]";
@ -177,6 +182,15 @@ public class DeployDialog extends FloatingDialog{
button.row();
button.label(() -> Core.bundle.format("save.playtime", color + slot.getPlayTime()));
button.row();
button.add().grow();
button.row();
button.addButton("$abandon", () -> {
ui.showConfirm("$warning", "$abandon.text", () -> {
slot.delete();
setup();
});
}).growX().height(50f).pad(-12).padTop(10);
}
}})).grow();
}

View File

@ -35,6 +35,7 @@ public class PlacementFragment extends Fragment{
Array<Block> returnArray = new Array<>();
Category currentCategory = Category.distribution;
Block hovered, lastDisplay;
Tile lastHover;
Tile hoverTile;
Table blockTable, toggler, topTable;
boolean shown = true;
@ -162,21 +163,25 @@ public class PlacementFragment extends Fragment{
frame.table("button-edge-2", top -> {
topTable = top;
top.add(new Table()).growX().update(topTable -> {
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround) || (tileDisplayBlock() != null && lastDisplay == tileDisplayBlock() && lastGround))
//don't refresh unnecessarily
if((tileDisplayBlock() == null && lastDisplay == getSelected() && !lastGround)
|| (tileDisplayBlock() != null && lastHover == hoverTile && lastGround))
return;
topTable.clear();
topTable.top().left().margin(5);
lastHover = hoverTile;
lastDisplay = getSelected();
lastGround = tileDisplayBlock() != null;
if(lastDisplay != null){ //show selected recipe
lastGround = false;
topTable.table(header -> {
header.left();
header.add(new Image(lastDisplay.icon(Icon.medium))).size(8 * 4);
header.labelWrap(() ->
!data.isUnlocked(lastDisplay) ? Core.bundle.get("blocks.unknown") : lastDisplay.formalName)
header.labelWrap(() -> !data.isUnlocked(lastDisplay) ? Core.bundle.get("blocks.unknown") : lastDisplay.formalName)
.left().width(190f).padLeft(5);
header.add().growX();
if(data.isUnlocked(lastDisplay)){
@ -219,7 +224,7 @@ public class PlacementFragment extends Fragment{
topTable.table(t -> {
t.left().defaults().left();
lastDisplay.display(hoverTile, t);
}).left();
}).left().growX();
}
});
}).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled);

View File

@ -29,6 +29,7 @@ import io.anuke.mindustry.type.Category;
import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.Item;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.ui.Bar;
import io.anuke.mindustry.ui.ContentDisplay;
import io.anuke.mindustry.world.consumers.ConsumePower;
import io.anuke.mindustry.world.meta.BlockFlag;
@ -463,9 +464,28 @@ public class Block extends BlockStorage{
}
public void display(Tile tile, Table table){
if(tile.entity != null){
//TODO remove/replace
table.label(() -> "Health: [LIGHT_GRAY]" + (int)tile.entity.health + " / " + health);
TileEntity entity = tile.entity;
if(entity != null){
table.table(bars -> {
bars.defaults().growX().height(18f).pad(4);
displayBars(tile, bars);
}).growX();
table.marginBottom(-5);
}
}
public void displayBars(Tile tile, Table bars){
TileEntity entity = tile.entity;
bars.add(new Bar("blocks.health", Palette.health, entity::healthf).blink(Color.WHITE));
bars.row();
if(entity.liquids != null){
bars.add(new Bar(() -> entity.liquids.current().localizedName(), () -> entity.liquids.current().color, () -> entity.liquids.total() / liquidCapacity)).growX();
bars.row();
}
}