package mindustry.logic; import arc.graphics.*; import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; import mindustry.logic.LCanvas.*; import mindustry.logic.LExecutor.*; import mindustry.type.*; import mindustry.ui.*; import static mindustry.world.blocks.logic.LogicDisplay.*; public class LStatements{ //TODO broken //@RegisterStatement("#") public static class CommentStatement extends LStatement{ public String comment = ""; @Override public void build(Table table){ table.area(comment, Styles.nodeArea, v -> comment = v).growX().height(90f).padLeft(2).padRight(6).color(table.color); } @Override public LCategory category(){ return LCategory.control; } @Override public LInstruction build(LAssembler builder){ return null; } } @RegisterStatement("write") public static class WriteStatement extends LStatement{ public String to = "0"; public String from = "result"; @Override public void build(Table table){ field(table, to, str -> to = str); table.add(" = "); field(table, from, str -> from = str); } @Override public LCategory category(){ return LCategory.io; } @Override public LInstruction build(LAssembler builder){ return new WriteI(builder.var(from), builder.var(to)); } } @RegisterStatement("read") public static class ReadStatement extends LStatement{ public String to = "result"; public String from = "0"; @Override public void build(Table table){ field(table, to, str -> to = str); table.add(" = mem:: "); field(table, from, str -> from = str); } @Override public LCategory category(){ return LCategory.io; } @Override public LInstruction build(LAssembler builder){ return new ReadI(builder.var(from), builder.var(to)); } } @RegisterStatement("draw") public static class DrawStatement extends LStatement{ public CommandType type = CommandType.line; public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0"; @Override public void build(Table table){ rebuild(table); } void rebuild(Table table){ table.clearChildren(); table.left(); table.button(b -> { b.label(() -> type.name()); b.clicked(() -> showSelect(b, CommandType.allNormal, type, t -> { type = t; rebuild(table); }, 2, cell -> cell.size(100, 50))); }, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2); if(type != CommandType.stroke){ table.row(); } table.table(s -> { s.left(); s.setColor(table.color); switch(type){ case clear: case color: fields(s, "r", x, v -> x = v); fields(s, "g", y, v -> y = v); fields(s, "b", p1, v -> p1 = v); break; case stroke: s.add().width(4); fields(s, x, v -> x = v); break; case line: fields(s, "x", x, v -> x = v); fields(s, "y", y, v -> y = v); s.row(); fields(s, "x2", p1, v -> p1 = v); fields(s, "y2", p2, v -> p2 = v); break; case rect: case lineRect: fields(s, "x", x, v -> x = v); fields(s, "y", y, v -> y = v); s.row(); fields(s, "width", p1, v -> p1 = v); fields(s, "height", p2, v -> p2 = v); break; case poly: case linePoly: fields(s, "x", x, v -> x = v); fields(s, "y", y, v -> y = v); s.row(); fields(s, "sides", p1, v -> p1 = v); fields(s, "radius", p2, v -> p2 = v); s.row(); fields(s, "rotation", p3, v -> p3 = v); break; } }).expand().left(); } @Override public LCategory category(){ return LCategory.io; } @Override public LInstruction build(LAssembler builder){ return new DisplayI((byte)type.ordinal(), 0, builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3)); } } @RegisterStatement("flush") public static class FlushStatement extends LStatement{ public String target = "display"; @Override public void build(Table table){ table.add(" to "); field(table, target, str -> target = str); } @Override public LCategory category(){ return LCategory.blocks; } @Override public LInstruction build(LAssembler builder){ return new DisplayI(commandFlush, builder.var(target), 0, 0, 0, 0, 0); } } @RegisterStatement("sensor") public static class SensorStatement extends LStatement{ public String to = "result"; public String from = "@0", type = "@copper"; private transient int selected = 0; private transient TextField tfield; @Override public void build(Table table){ field(table, to, str -> to = str); table.add(" = "); table.row(); tfield = field(table, type, str -> type = str).padRight(0f).get(); table.button(b -> { b.image(Icon.pencilSmall); //240 b.clicked(() -> showSelectTable(b, (t, hide) -> { Table[] tables = { //items new Table(i -> { i.left(); int c = 0; for(Item item : Vars.content.items()){ if(!item.unlockedNow()) continue; i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> { stype("@" + item.name); hide.run(); }).size(40f); if(++c % 6 == 0) i.row(); } }), //liquids new Table(i -> { i.left(); int c = 0; for(Liquid item : Vars.content.liquids()){ if(!item.unlockedNow()) continue; i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> { stype("@" + item.name); hide.run(); }).size(40f); if(++c % 6 == 0) i.row(); } }), //sensors new Table(i -> { for(LSensor sensor : LSensor.all){ i.button(sensor.name(), Styles.cleart, () -> { stype("@" + sensor.name()); hide.run(); }).size(240f, 40f).row(); } }) }; Drawable[] icons = {Icon.box, Icon.liquid, Icon.tree}; Stack stack = new Stack(tables[selected]); ButtonGroup