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.*; public class LStatements{ @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("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 -> { int c = 0; for(Item item : Vars.content.items()){ 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 -> { int c = 0; for(Liquid item : Vars.content.liquids()){ 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