mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 03:08:38 +07:00
Better logic UI
This commit is contained in:
parent
1d5a25ce75
commit
6dca449b08
@ -33,7 +33,9 @@ public class LCanvas extends Table{
|
|||||||
|
|
||||||
statements = new DragLayout();
|
statements = new DragLayout();
|
||||||
|
|
||||||
pane(statements).grow().get().setClip(false);
|
ScrollPane pane = pane(statements).grow().get();
|
||||||
|
pane.setClip(false);
|
||||||
|
pane.setFlickScroll(false);
|
||||||
|
|
||||||
row();
|
row();
|
||||||
|
|
||||||
@ -41,13 +43,14 @@ public class LCanvas extends Table{
|
|||||||
BaseDialog dialog = new BaseDialog("@add");
|
BaseDialog dialog = new BaseDialog("@add");
|
||||||
dialog.cont.pane(t -> {
|
dialog.cont.pane(t -> {
|
||||||
t.background(Tex.button);
|
t.background(Tex.button);
|
||||||
|
int i = 0;
|
||||||
for(Prov<LStatement> prov : LogicIO.allStatements){
|
for(Prov<LStatement> prov : LogicIO.allStatements){
|
||||||
LStatement example = prov.get();
|
LStatement example = prov.get();
|
||||||
t.button(example.name(), Styles.cleart, () -> {
|
t.button(example.name(), Styles.cleart, () -> {
|
||||||
add(prov.get());
|
add(prov.get());
|
||||||
dialog.hide();
|
dialog.hide();
|
||||||
}).size(200f, 50f);
|
}).size(140f, 50f);
|
||||||
t.row();
|
if(++i % 2 == 0) t.row();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.addCloseButton();
|
dialog.addCloseButton();
|
||||||
@ -126,7 +129,7 @@ public class LCanvas extends Table{
|
|||||||
|
|
||||||
public class DragLayout extends WidgetGroup{
|
public class DragLayout extends WidgetGroup{
|
||||||
float margin = 4f;
|
float margin = 4f;
|
||||||
float space = 10f, width = 400f, prefWidth, prefHeight;
|
float space = 10f, prefWidth, prefHeight;
|
||||||
Seq<Element> seq = new Seq<>();
|
Seq<Element> seq = new Seq<>();
|
||||||
int insertPosition = 0;
|
int insertPosition = 0;
|
||||||
|
|
||||||
@ -135,7 +138,10 @@ public class LCanvas extends Table{
|
|||||||
float cy = 0;
|
float cy = 0;
|
||||||
seq.clear();
|
seq.clear();
|
||||||
|
|
||||||
prefWidth = width;
|
float totalHeight = getChildren().sumf(e -> e.getHeight() + space) + margin*2f;
|
||||||
|
|
||||||
|
height = prefHeight = totalHeight;
|
||||||
|
width = prefWidth = 400f;
|
||||||
|
|
||||||
//layout everything normally
|
//layout everything normally
|
||||||
for(int i = 0; i < getChildren().size; i++){
|
for(int i = 0; i < getChildren().size; i++){
|
||||||
@ -175,7 +181,7 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prefHeight = cy;
|
invalidateHierarchy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -12,10 +12,11 @@ public class LDialog extends BaseDialog{
|
|||||||
public LDialog(){
|
public LDialog(){
|
||||||
super("logic");
|
super("logic");
|
||||||
|
|
||||||
|
clearChildren();
|
||||||
|
|
||||||
canvas = new LCanvas();
|
canvas = new LCanvas();
|
||||||
addCloseButton();
|
addCloseButton();
|
||||||
|
|
||||||
clear();
|
|
||||||
stack(canvas, new Table(t -> {
|
stack(canvas, new Table(t -> {
|
||||||
t.bottom();
|
t.bottom();
|
||||||
t.add(buttons);
|
t.add(buttons);
|
||||||
|
@ -311,20 +311,21 @@ public class LExecutor{
|
|||||||
//graphics on headless servers are useless.
|
//graphics on headless servers are useless.
|
||||||
if(Vars.headless) return;
|
if(Vars.headless) return;
|
||||||
|
|
||||||
Building build = exec.building(target);
|
if(type == commandFlush){
|
||||||
if(build instanceof LogicDisplayEntity){
|
Building build = exec.building(target);
|
||||||
//flush is a special command
|
if(build instanceof LogicDisplayEntity){
|
||||||
if(type == commandFlush){
|
//flush is a special command
|
||||||
LogicDisplayEntity d = (LogicDisplayEntity)build;
|
LogicDisplayEntity d = (LogicDisplayEntity)build;
|
||||||
for(int i = 0; i < exec.graphicsBuffer.size; i++){
|
for(int i = 0; i < exec.graphicsBuffer.size; i++){
|
||||||
d.commands.addLast(exec.graphicsBuffer.items[i]);
|
d.commands.addLast(exec.graphicsBuffer.items[i]);
|
||||||
}
|
}
|
||||||
exec.graphicsBuffer.clear();
|
exec.graphicsBuffer.clear();
|
||||||
}else{
|
}
|
||||||
//cap graphics buffer size
|
|
||||||
if(exec.graphicsBuffer.size < 1024){
|
}else{
|
||||||
exec.graphicsBuffer.add(DisplayCmd.get(type, exec.numi(x), exec.numi(y), exec.numi(p1), exec.numi(p2), exec.numi(p3)));
|
//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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,13 @@ public abstract class LStatement{
|
|||||||
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
|
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
protected void fields(Table table, String desc, String value, Cons<String> setter){
|
||||||
return field(table, value, setter).width(70f);
|
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){
|
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){
|
||||||
|
@ -88,10 +88,9 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RegisterStatement("display")
|
@RegisterStatement("draw")
|
||||||
public static class DisplayStatement extends LStatement{
|
public static class DrawStatement extends LStatement{
|
||||||
public CommandType type = CommandType.line;
|
public CommandType type = CommandType.line;
|
||||||
public String target = "monitor";
|
|
||||||
public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0";
|
public String x = "0", y = "0", p1 = "0", p2 = "0", p3 = "0";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -102,65 +101,64 @@ public class LStatements{
|
|||||||
void rebuild(Table table){
|
void rebuild(Table table){
|
||||||
table.clearChildren();
|
table.clearChildren();
|
||||||
|
|
||||||
table.add("draw").padLeft(4);
|
table.left();
|
||||||
|
|
||||||
table.button(b -> {
|
table.button(b -> {
|
||||||
b.label(() -> type.name());
|
b.label(() -> type.name());
|
||||||
b.clicked(() -> showSelect(b, CommandType.all, type, t -> {
|
b.clicked(() -> showSelect(b, CommandType.allNormal, type, t -> {
|
||||||
type = t;
|
type = t;
|
||||||
rebuild(table);
|
rebuild(table);
|
||||||
}, 2, cell -> cell.size(100, 50)));
|
}, 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){
|
switch(type){
|
||||||
case clear:
|
case clear:
|
||||||
case color:
|
case color:
|
||||||
c.add("rgb ");
|
fields(s, "r", x, v -> x = v);
|
||||||
fields(c, x, v -> x = v);
|
fields(s, "g", y, v -> y = v);
|
||||||
fields(c, y, v -> y = v);
|
fields(s, "b", p1, v -> p1 = v);
|
||||||
fields(c, p1, v -> p1 = v);
|
|
||||||
break;
|
break;
|
||||||
case stroke:
|
case stroke:
|
||||||
c.add("width ");
|
s.add().width(4);
|
||||||
fields(c, x, v -> x = v);
|
fields(s, x, v -> x = v);
|
||||||
break;
|
break;
|
||||||
case line:
|
case line:
|
||||||
c.add("xyx2y2 ");
|
fields(s, "x", x, v -> x = v);
|
||||||
fields(c, x, v -> x = v);
|
fields(s, "y", y, v -> y = v);
|
||||||
fields(c, y, v -> y = v);
|
s.row();
|
||||||
fields(c, p1, v -> p1 = v);
|
fields(s, "x2", p1, v -> p1 = v);
|
||||||
fields(c, p2, v -> p2 = v);
|
fields(s, "y2", p2, v -> p2 = v);
|
||||||
break;
|
break;
|
||||||
case rect:
|
case rect:
|
||||||
case lineRect:
|
case lineRect:
|
||||||
c.add("xywh ");
|
fields(s, "x", x, v -> x = v);
|
||||||
fields(c, x, v -> x = v);
|
fields(s, "y", y, v -> y = v);
|
||||||
fields(c, y, v -> y = v);
|
s.row();
|
||||||
fields(c, p1, v -> p1 = v);
|
fields(s, "width", p1, v -> p1 = v);
|
||||||
fields(c, p2, v -> p2 = v);
|
fields(s, "height", p2, v -> p2 = v);
|
||||||
break;
|
break;
|
||||||
case poly:
|
case poly:
|
||||||
case linePoly:
|
case linePoly:
|
||||||
c.add("xysra ");
|
fields(s, "x", x, v -> x = v);
|
||||||
fields(c, x, v -> x = v);
|
fields(s, "y", y, v -> y = v);
|
||||||
fields(c, y, v -> y = v);
|
s.row();
|
||||||
c.row();
|
fields(s, "sides", p1, v -> p1 = v);
|
||||||
fields(c, p1, v -> p1 = v);
|
fields(s, "radius", p2, v -> p2 = v);
|
||||||
fields(c, p2, v -> p2 = v);
|
s.row();
|
||||||
fields(c, p3, v -> p3 = v);
|
fields(s, "rotation", p3, v -> p3 = v);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}).colspan(4).left();
|
}).expand().left();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -170,7 +168,28 @@ public class LStatements{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LInstruction build(LAssembler builder){
|
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.row();
|
||||||
t.add(stack).colspan(3).expand().left();
|
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 ");
|
table.add(" in ");
|
||||||
|
|
||||||
@ -345,7 +364,7 @@ public class LStatements{
|
|||||||
table.button(b -> {
|
table.button(b -> {
|
||||||
b.label(() -> op.symbol);
|
b.label(() -> op.symbol);
|
||||||
b.clicked(() -> showSelect(b, BinaryOp.all, op, o -> op = o));
|
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);
|
field(table, b, str -> b = str);
|
||||||
}
|
}
|
||||||
@ -375,7 +394,7 @@ public class LStatements{
|
|||||||
table.button(b -> {
|
table.button(b -> {
|
||||||
b.label(() -> op.symbol);
|
b.label(() -> op.symbol);
|
||||||
b.clicked(() -> showSelect(b, UnaryOp.all, op, o -> op = o));
|
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);
|
field(table, value, str -> value = str);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import static mindustry.gen.Tex.*;
|
|||||||
public class Styles{
|
public class Styles{
|
||||||
public static Drawable black, black9, black8, black6, black3, black5, none, flatDown, flatOver;
|
public static Drawable black, black9, black8, black6, black3, black5, none, flatDown, flatOver;
|
||||||
public static ButtonStyle defaultb, waveb;
|
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 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 ScrollPaneStyle defaultPane, horizontalPane, smallPane;
|
||||||
public static KeybindDialogStyle defaultKeybindDialog;
|
public static KeybindDialogStyle defaultKeybindDialog;
|
||||||
@ -93,6 +93,14 @@ public class Styles{
|
|||||||
down = flatOver;
|
down = flatOver;
|
||||||
up = black;
|
up = black;
|
||||||
}};
|
}};
|
||||||
|
logict = new TextButtonStyle(){{
|
||||||
|
over = flatOver;
|
||||||
|
font = Fonts.def;
|
||||||
|
fontColor = Color.white;
|
||||||
|
disabledFontColor = Color.gray;
|
||||||
|
down = flatOver;
|
||||||
|
up = underlineWhite;
|
||||||
|
}};
|
||||||
discordt = new TextButtonStyle(){{
|
discordt = new TextButtonStyle(){{
|
||||||
font = Fonts.def;
|
font = Fonts.def;
|
||||||
fontColor = Color.white;
|
fontColor = Color.white;
|
||||||
|
@ -98,6 +98,7 @@ public class LogicDisplay extends Block{
|
|||||||
flush;
|
flush;
|
||||||
|
|
||||||
public static final CommandType[] all = values();
|
public static final CommandType[] all = values();
|
||||||
|
public static final CommandType[] allNormal = Seq.select(all, t -> t != flush).toArray(CommandType.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Struct
|
@Struct
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=db8aa62298fc1500ede3a09776f1414be9b6ba30
|
archash=14934155d6c4bafa07f9a31c27b1e1cf565e8008
|
||||||
|
Loading…
Reference in New Issue
Block a user