Graphics
This commit is contained in:
@@ -49,7 +49,7 @@ public class LAssembler{
|
||||
|
||||
Seq<LStatement> st = read(data);
|
||||
|
||||
asm.instructions = st.map(l -> l.build(asm)).toArray(LInstruction.class);
|
||||
asm.instructions = st.map(l -> l.build(asm)).filter(l -> l != null).toArray(LInstruction.class);
|
||||
return asm;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class LAssembler{
|
||||
String[] lines = data.split("[;\n]+");
|
||||
for(String line : lines){
|
||||
//comments
|
||||
if(line.startsWith("#")) continue;
|
||||
//if(line.startsWith("#")) continue;
|
||||
|
||||
String[] tokens = line.split(" ");
|
||||
LStatement st = LogicIO.read(tokens);
|
||||
|
||||
@@ -421,6 +421,7 @@ public class LCanvas extends Table{
|
||||
|
||||
void drawCurve(float x, float y, float x2, float y2, Color color){
|
||||
Lines.stroke(4f, color);
|
||||
Draw.alpha(parentAlpha);
|
||||
|
||||
float dist = 100f;
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.struct.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
|
||||
import static mindustry.world.blocks.logic.LogicDisplay.*;
|
||||
|
||||
public class LExecutor{
|
||||
//special variables
|
||||
@@ -15,6 +19,7 @@ public class LExecutor{
|
||||
public double[] memory = {};
|
||||
public LInstruction[] instructions = {};
|
||||
public Var[] vars = {};
|
||||
public LongSeq graphicsBuffer = new LongSeq();
|
||||
|
||||
public boolean initialized(){
|
||||
return instructions != null && vars != null && instructions.length > 0;
|
||||
@@ -283,6 +288,48 @@ public class LExecutor{
|
||||
}
|
||||
}
|
||||
|
||||
public static class DisplayI implements LInstruction{
|
||||
public byte type;
|
||||
public int target;
|
||||
public int x, y, p1, p2, p3;
|
||||
|
||||
public DisplayI(byte type, int target, int x, int y, int p1, int p2, int p3){
|
||||
this.type = type;
|
||||
this.target = target;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.p1 = p1;
|
||||
this.p2 = p2;
|
||||
this.p3 = p3;
|
||||
}
|
||||
|
||||
public DisplayI(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(LExecutor exec){
|
||||
//graphics on headless servers are useless.
|
||||
if(Vars.headless) return;
|
||||
|
||||
Building build = exec.building(target);
|
||||
if(build instanceof LogicDisplayEntity){
|
||||
//flush is a special command
|
||||
if(type == commandFlush){
|
||||
LogicDisplayEntity d = (LogicDisplayEntity)build;
|
||||
for(int i = 0; i < exec.graphicsBuffer.size; i++){
|
||||
d.commands.addLast(exec.graphicsBuffer.items[i]);
|
||||
}
|
||||
exec.graphicsBuffer.clear();
|
||||
}else{
|
||||
//cap graphics buffer size
|
||||
if(exec.graphicsBuffer.size < 1024){
|
||||
exec.graphicsBuffer.add(DisplayCmd.get(type, exec.numi(x), exec.numi(y), exec.numi(p1), exec.numi(p2), exec.numi(p3)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class PrintI implements LInstruction{
|
||||
private static final StringBuilder out = new StringBuilder();
|
||||
|
||||
|
||||
@@ -24,28 +24,38 @@ public abstract class LStatement{
|
||||
public abstract LCategory category();
|
||||
public abstract LInstruction build(LAssembler builder);
|
||||
|
||||
//protected methods are only for internal UI layout utilities
|
||||
|
||||
protected Cell<TextField> field(Table table, String value, Cons<String> setter){
|
||||
return table.field(value, Styles.nodeField, setter)
|
||||
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
|
||||
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||
return field(table, value, setter).width(70f);
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){
|
||||
showSelectTable(b, (t, hide) -> {
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
int i = 0;
|
||||
t.defaults().size(56f, 40f);
|
||||
|
||||
for(T p : values){
|
||||
t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
sizer.get(t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
getter.get(p);
|
||||
hide.run();
|
||||
}).checked(current == p).group(group);
|
||||
}).checked(current == p).group(group));
|
||||
|
||||
if(++i % 4 == 0) t.row();
|
||||
if(++i % cols == 0) t.row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
|
||||
showSelect(b, values, current, getter, 4, c -> {});
|
||||
}
|
||||
|
||||
protected void showSelectTable(Button b, Cons2<Table, Runnable> hideCons){
|
||||
Table t = new Table(Tex.button);
|
||||
|
||||
@@ -64,6 +74,8 @@ public abstract class LStatement{
|
||||
Core.scene.add(t);
|
||||
|
||||
t.update(() -> {
|
||||
if(b.parent == null) return;
|
||||
|
||||
b.localToStageCoordinates(Tmp.v1.set(b.getWidth()/2f, b.getHeight()/2f));
|
||||
t.setPosition(Tmp.v1.x, Tmp.v1.y, Align.center);
|
||||
t.keepInStage();
|
||||
|
||||
@@ -12,8 +12,31 @@ 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";
|
||||
@@ -64,6 +87,93 @@ public class LStatements{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RegisterStatement("display")
|
||||
public static class DisplayStatement extends LStatement{
|
||||
public CommandType type = CommandType.line;
|
||||
public String target = "monitor";
|
||||
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.add("draw").padLeft(4);
|
||||
|
||||
table.button(b -> {
|
||||
b.label(() -> type.name());
|
||||
b.clicked(() -> showSelect(b, CommandType.all, type, t -> {
|
||||
type = t;
|
||||
rebuild(table);
|
||||
}, 2, cell -> cell.size(100, 50)));
|
||||
}, Styles.cleari, () -> {}).size(90, 50);
|
||||
|
||||
table.add(" to ");
|
||||
|
||||
field(table, target, str -> target = str);
|
||||
|
||||
table.row();
|
||||
|
||||
table.table(c -> {
|
||||
c.marginLeft(3);
|
||||
c.left();
|
||||
c.setColor(table.color);
|
||||
switch(type){
|
||||
case clear:
|
||||
case color:
|
||||
c.add("rgb ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
break;
|
||||
case stroke:
|
||||
c.add("width ");
|
||||
fields(c, x, v -> x = v);
|
||||
break;
|
||||
case line:
|
||||
c.add("xyx2y2 ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
break;
|
||||
case rect:
|
||||
case lineRect:
|
||||
c.add("xywh ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
break;
|
||||
case poly:
|
||||
case linePoly:
|
||||
c.add("xysra ");
|
||||
fields(c, x, v -> x = v);
|
||||
fields(c, y, v -> y = v);
|
||||
c.row();
|
||||
fields(c, p1, v -> p1 = v);
|
||||
fields(c, p2, v -> p2 = v);
|
||||
fields(c, p3, v -> p3 = v);
|
||||
break;
|
||||
}
|
||||
}).colspan(4).left();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.io;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LInstruction build(LAssembler builder){
|
||||
return new DisplayI((byte)type.ordinal(), builder.var(target), builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3));
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterStatement("sensor")
|
||||
public static class SensorStatement extends LStatement{
|
||||
public String to = "result";
|
||||
@@ -89,8 +199,10 @@ public class LStatements{
|
||||
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();
|
||||
@@ -101,8 +213,10 @@ public class LStatements{
|
||||
}),
|
||||
//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();
|
||||
@@ -138,7 +252,7 @@ public class LStatements{
|
||||
}).size(80f, 50f).checked(selected == fi).group(group);
|
||||
}
|
||||
t.row();
|
||||
t.add(stack).colspan(3);
|
||||
t.add(stack).colspan(3).expand().left();
|
||||
}));
|
||||
}, Styles.cleart, () -> {}).size(40f).padLeft(-1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user