New block stat system, names for all current block recipes

This commit is contained in:
Anuken
2018-06-27 21:29:57 -04:00
parent 2344fb910b
commit 18b137a1a6
44 changed files with 777 additions and 224 deletions

View File

@@ -2,34 +2,37 @@ package io.anuke.mindustry.ui;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.ucore.function.Supplier;
import io.anuke.ucore.scene.style.TextureRegionDrawable;
import io.anuke.ucore.scene.ui.Image;
import io.anuke.ucore.scene.ui.layout.Stack;
import io.anuke.ucore.scene.ui.layout.Table;
public class ItemImage extends Stack {
private Image image;
public ItemImage(TextureRegion region, Supplier<CharSequence> text, Color color) {
public ItemImage(TextureRegion region, Supplier<CharSequence> text) {
Table t = new Table().left().bottom();
t.label(text).color(Color.DARK_GRAY).padBottom(-60).get().setFontScale(0.5f);
t.row();
t.label(text).get().setFontScale(0.5f);
image = new Image(region);
image.setColor(color);
Image image = new Image(region);
add(image);
add(t);
}
public ItemImage updateColor(Supplier<Color> c){
image.update(() -> image.setColor(c.get()));
return this;
}
public ItemImage(ItemStack stack) {
Table t = new Table().left().bottom();
public ItemImage updateRegion(Supplier<TextureRegion> c){
image.update(() -> image.setDrawable(new TextureRegionDrawable(c.get())));
return this;
t.add(stack.amount + "").color(Color.DARK_GRAY).padBottom(-22).get().setFontScale(0.5f);
t.row();
t.add(stack.amount + "").get().setFontScale(0.5f);
Image image = new Image(stack.item.region);
add(image);
add(t);
}
}

View File

@@ -1,6 +1,5 @@
package io.anuke.mindustry.ui.fragments;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.IntSet;
@@ -106,7 +105,7 @@ public class BlockInventoryFragment implements Fragment {
HandCursorListener l = new HandCursorListener();
l.setEnabled(canPick);
ItemImage image = new ItemImage(item.region, () -> round(items[f]), Color.WHITE);
ItemImage image = new ItemImage(item.region, () -> round(items[f]));
image.addListener(l);
image.tapped(() -> {
if(!canPick.get() || items[f] == 0) return;

View File

@@ -4,15 +4,24 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.OrderedMap;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.type.Category;
import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Recipe;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.BlockStats;
import io.anuke.mindustry.world.meta.StatCategory;
import io.anuke.mindustry.world.meta.StatValue;
import io.anuke.ucore.core.Core;
import io.anuke.ucore.core.Graphics;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.scene.Element;
import io.anuke.ucore.scene.Group;
import io.anuke.ucore.scene.actions.Actions;
@@ -317,6 +326,8 @@ public class BlocksFragment implements Fragment{
nameLabel.setWrap(true);
header.add(nameLabel).padLeft(2).width(120f);
header.addButton("?", () -> showBlockInfo(recipe.result)).expandX().padLeft(3).top().right().size(40f, 44f).padTop(-2);
descTable.add().pad(2);
Table requirements = new Table();
@@ -345,6 +356,56 @@ public class BlocksFragment implements Fragment{
descTable.row();
}
private void showBlockInfo(Block block){
FloatingDialog dialog = new FloatingDialog("$text.blocks.blockinfo");
dialog.addCloseButton();
Table table = new Table();
ScrollPane pane = new ScrollPane(table, "clear");
table.table(title -> {
title.addImage(Draw.region("block-icon-" + block.name)).size(8 * 6);
title.add("[accent]" + block.formalName).padLeft(5);
});
table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row();
if(block.fullDescription != null){
table.add(block.fullDescription);
table.row();
table.addImage("white").height(3).color(Color.LIGHT_GRAY).pad(15).padLeft(0).padRight(0).fillX();
table.row();
}
BlockStats stats = block.stats;
for(StatCategory cat : stats.toMap().keys()){
OrderedMap<BlockStat, StatValue> map = stats.toMap().get(cat);
if(map.size == 0) continue;
table.add("$text.category." + cat.name()).color(Palette.accent).fillX();
table.row();
for (BlockStat stat : map.keys()){
table.table(inset -> {
inset.left();
inset.add("[LIGHT_GRAY]" + stat.localized() + ":[] ");
map.get(stat).display(inset);
}).fillX().padLeft(10);
table.row();
}
}
dialog.content().add(pane).grow();
dialog.show();
}
String format(int number){
if(number >= 1000000) {
return Strings.toFixed(number/1000000f, 1) + "[gray]mil[]";