Better logic UI

This commit is contained in:
Anuken 2020-08-09 15:10:13 -04:00
parent 1d5a25ce75
commit 6dca449b08
8 changed files with 103 additions and 62 deletions

View File

@ -33,7 +33,9 @@ public class LCanvas extends Table{
statements = new DragLayout();
pane(statements).grow().get().setClip(false);
ScrollPane pane = pane(statements).grow().get();
pane.setClip(false);
pane.setFlickScroll(false);
row();
@ -41,13 +43,14 @@ public class LCanvas extends Table{
BaseDialog dialog = new BaseDialog("@add");
dialog.cont.pane(t -> {
t.background(Tex.button);
int i = 0;
for(Prov<LStatement> prov : LogicIO.allStatements){
LStatement example = prov.get();
t.button(example.name(), Styles.cleart, () -> {
add(prov.get());
dialog.hide();
}).size(200f, 50f);
t.row();
}).size(140f, 50f);
if(++i % 2 == 0) t.row();
}
});
dialog.addCloseButton();
@ -126,7 +129,7 @@ public class LCanvas extends Table{
public class DragLayout extends WidgetGroup{
float margin = 4f;
float space = 10f, width = 400f, prefWidth, prefHeight;
float space = 10f, prefWidth, prefHeight;
Seq<Element> seq = new Seq<>();
int insertPosition = 0;
@ -135,7 +138,10 @@ public class LCanvas extends Table{
float cy = 0;
seq.clear();
prefWidth = width;
float totalHeight = getChildren().sumf(e -> e.getHeight() + space) + margin*2f;
height = prefHeight = totalHeight;
width = prefWidth = 400f;
//layout everything normally
for(int i = 0; i < getChildren().size; i++){
@ -175,7 +181,7 @@ public class LCanvas extends Table{
}
}
prefHeight = cy;
invalidateHierarchy();
}
@Override

View File

@ -12,10 +12,11 @@ public class LDialog extends BaseDialog{
public LDialog(){
super("logic");
clearChildren();
canvas = new LCanvas();
addCloseButton();
clear();
stack(canvas, new Table(t -> {
t.bottom();
t.add(buttons);

View File

@ -311,20 +311,21 @@ public class LExecutor{
//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){
if(type == commandFlush){
Building build = exec.building(target);
if(build instanceof LogicDisplayEntity){
//flush is a special command
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)));
}
}
}else{
//add graphics calls, 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)));
}
}
}

View File

@ -31,8 +31,13 @@ public abstract class LStatement{
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
}
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
return field(table, value, setter).width(70f);
protected void fields(Table table, String desc, String value, Cons<String> setter){
table.add(desc).padLeft(10).left();
field(table, value, setter).width(85f).padRight(10).left();
}
protected void fields(Table table, String value, Cons<String> setter){
field(table, value, setter).width(85f);
}
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){

View File

@ -88,10 +88,9 @@ public class LStatements{
}
@RegisterStatement("display")
public static class DisplayStatement extends LStatement{
@RegisterStatement("draw")
public static class DrawStatement extends LStatement{
public CommandType type = CommandType.line;
public String target = "monitor";
public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0";
@Override
@ -102,65 +101,64 @@ public class LStatements{
void rebuild(Table table){
table.clearChildren();
table.add("draw").padLeft(4);
table.left();
table.button(b -> {
b.label(() -> type.name());
b.clicked(() -> showSelect(b, CommandType.all, type, t -> {
b.clicked(() -> showSelect(b, CommandType.allNormal, type, t -> {
type = t;
rebuild(table);
}, 2, cell -> cell.size(100, 50)));
}, Styles.cleari, () -> {}).size(90, 50);
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
table.add(" to ");
if(type != CommandType.stroke){
table.row();
}
field(table, target, str -> target = str);
table.table(s -> {
s.left();
s.setColor(table.color);
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);
fields(s, "r", x, v -> x = v);
fields(s, "g", y, v -> y = v);
fields(s, "b", p1, v -> p1 = v);
break;
case stroke:
c.add("width ");
fields(c, x, v -> x = v);
s.add().width(4);
fields(s, 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);
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:
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);
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:
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);
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;
}
}).colspan(4).left();
}).expand().left();
}
@Override
@ -170,7 +168,28 @@ public class LStatements{
@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));
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);
}
}
@ -254,7 +273,7 @@ public class LStatements{
t.row();
t.add(stack).colspan(3).expand().left();
}));
}, Styles.cleart, () -> {}).size(40f).padLeft(-1);
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
table.add(" in ");
@ -345,7 +364,7 @@ public class LStatements{
table.button(b -> {
b.label(() -> op.symbol);
b.clicked(() -> showSelect(b, BinaryOp.all, op, o -> op = o));
}, Styles.cleart, () -> {}).size(50f, 40f).pad(4f);
}, Styles.logict, () -> {}).size(50f, 40f).pad(4f).color(table.color);
field(table, b, str -> b = str);
}
@ -375,7 +394,7 @@ public class LStatements{
table.button(b -> {
b.label(() -> op.symbol);
b.clicked(() -> showSelect(b, UnaryOp.all, op, o -> op = o));
}, Styles.cleart, () -> {}).size(50f, 40f).pad(3f);
}, Styles.logict, () -> {}).size(50f, 40f).pad(3f).color(table.color);
field(table, value, str -> value = str);
}

View File

@ -25,7 +25,7 @@ import static mindustry.gen.Tex.*;
public class Styles{
public static Drawable black, black9, black8, black6, black3, black5, none, flatDown, flatOver;
public static ButtonStyle defaultb, waveb;
public static TextButtonStyle defaultt, squaret, nodet, cleart, discordt, infot, clearPartialt, clearTogglet, clearToggleMenut, togglet, transt, fullTogglet;
public static TextButtonStyle defaultt, squaret, nodet, cleart, discordt, infot, clearPartialt, clearTogglet, clearToggleMenut, togglet, transt, fullTogglet, logict;
public static ImageButtonStyle defaulti, nodei, righti, emptyi, emptytogglei, selecti, onlyi, colori, cleari, clearFulli, clearPartiali, clearPartial2i, clearTogglei, clearTransi, clearToggleTransi, clearTogglePartiali;
public static ScrollPaneStyle defaultPane, horizontalPane, smallPane;
public static KeybindDialogStyle defaultKeybindDialog;
@ -93,6 +93,14 @@ public class Styles{
down = flatOver;
up = black;
}};
logict = new TextButtonStyle(){{
over = flatOver;
font = Fonts.def;
fontColor = Color.white;
disabledFontColor = Color.gray;
down = flatOver;
up = underlineWhite;
}};
discordt = new TextButtonStyle(){{
font = Fonts.def;
fontColor = Color.white;

View File

@ -98,6 +98,7 @@ public class LogicDisplay extends Block{
flush;
public static final CommandType[] all = values();
public static final CommandType[] allNormal = Seq.select(all, t -> t != flush).toArray(CommandType.class);
}
@Struct

View File

@ -1,3 +1,3 @@
org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=db8aa62298fc1500ede3a09776f1414be9b6ba30
archash=14934155d6c4bafa07f9a31c27b1e1cf565e8008