LStatement categories + improved UI (#7046)

* LStatement categories + improved UI

Co-authored-by: code-explorer786 <68312688+code-explorer786@users.noreply.github.com>

* annihilate LStatement#color

Co-authored-by: code-explorer786 <68312688+code-explorer786@users.noreply.github.com>
This commit is contained in:
Goobrr
2022-06-19 21:57:49 +07:00
committed by GitHub
parent a30f6325d4
commit 625f7e9936
7 changed files with 247 additions and 158 deletions

View File

@@ -327,7 +327,7 @@ public class LCanvas extends Table{
st.elem = this;
background(Tex.whitePane);
setColor(st.color());
setColor(st.category().color);
margin(0f);
touchable = Touchable.enabled;

View File

@@ -0,0 +1,55 @@
package mindustry.logic;
import arc.*;
import arc.graphics.*;
import arc.scene.style.*;
import arc.struct.*;
import arc.util.*;
import mindustry.gen.*;
import mindustry.graphics.*;
public class LCategory implements Comparable<LCategory>{
public static final Seq<LCategory> all = new Seq<>();
public static final LCategory
unknown = new LCategory("unknown", Pal.darkishGray),
io = new LCategory("io", Pal.logicIo, Icon.logicSmall),
block = new LCategory("block", Pal.logicBlocks, Icon.effectSmall),
operation = new LCategory("operation", Pal.logicOperations, Icon.settingsSmall),
control = new LCategory("control", Pal.logicControl, Icon.rotateSmall),
unit = new LCategory("unit", Pal.logicUnits, Icon.unitsSmall),
world = new LCategory("world", Pal.logicWorld, Icon.terminalSmall);
public final String name;
public final int id;
public final Color color;
@Nullable
public final Drawable icon;
public LCategory(String name, Color color){
this(name, color,null);
}
public LCategory(String name, Color color, Drawable icon){
this.icon = icon;
this.color = color;
this.name = name;
id = all.size;
all.add(this);
}
public String localized(){
return Core.bundle.get("lcategory." + name);
}
public String description(){
return Core.bundle.get("lcategory." + name + ".description");
}
@Override
public int compareTo(LCategory o){
return id - o.id;
}
}

View File

@@ -24,9 +24,13 @@ public abstract class LStatement{
public transient @Nullable StatementElem elem;
public abstract void build(Table table);
public abstract Color color();
public abstract LInstruction build(LAssembler builder);
public LCategory category(){
return LCategory.unknown;
}
public LStatement copy(){
StringBuilder build = new StringBuilder();
write(build);

View File

@@ -34,11 +34,6 @@ public class LStatements{
table.area(comment, Styles.nodeArea, v -> comment = v).growX().height(90f).padLeft(2).padRight(6).color(table.color);
}
@Override
public Color color(){
return Pal.logicControl;
}
@Override
public LInstruction build(LAssembler builder){
return null;
@@ -52,11 +47,6 @@ public class LStatements{
public void build(Table table){
}
@Override
public Color color(){
return Pal.logicOperations;
}
@Override
public LInstruction build(LAssembler builder){
return new NoopI();
@@ -85,13 +75,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicIo;
public LInstruction build(LAssembler builder){
return new ReadI(builder.var(target), builder.var(address), builder.var(output));
}
@Override
public LInstruction build(LAssembler builder){
return new ReadI(builder.var(target), builder.var(address), builder.var(output));
public LCategory category(){
return LCategory.io;
}
}
@@ -117,13 +107,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicIo;
public LInstruction build(LAssembler builder){
return new WriteI(builder.var(target), builder.var(address), builder.var(input));
}
@Override
public LInstruction build(LAssembler builder){
return new WriteI(builder.var(target), builder.var(address), builder.var(input));
public LCategory category(){
return LCategory.io;
}
}
@@ -242,13 +232,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicIo;
public LInstruction build(LAssembler builder){
return new DrawI((byte)type.ordinal(), 0, builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
}
@Override
public LInstruction build(LAssembler builder){
return new DrawI((byte)type.ordinal(), 0, builder.var(x), builder.var(y), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
public LCategory category(){
return LCategory.io;
}
}
@@ -266,9 +256,10 @@ public class LStatements{
return new PrintI(builder.var(value));
}
@Override
public Color color(){
return Pal.logicIo;
public LCategory category(){
return LCategory.io;
}
}
@@ -283,13 +274,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new DrawFlushI(builder.var(target));
}
@Override
public LInstruction build(LAssembler builder){
return new DrawFlushI(builder.var(target));
public LCategory category(){
return LCategory.block;
}
}
@@ -304,13 +295,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new PrintFlushI(builder.var(target));
}
@Override
public LInstruction build(LAssembler builder){
return new PrintFlushI(builder.var(target));
public LCategory category(){
return LCategory.block;
}
}
@@ -328,13 +319,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new GetLinkI(builder.var(output), builder.var(address));
}
@Override
public LInstruction build(LAssembler builder){
return new GetLinkI(builder.var(output), builder.var(address));
public LCategory category(){
return LCategory.block;
}
}
@@ -381,13 +372,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new ControlI(type, builder.var(target), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
}
@Override
public LInstruction build(LAssembler builder){
return new ControlI(type, builder.var(target), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
public LCategory category(){
return LCategory.block;
}
}
@@ -452,13 +443,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new RadarI(target1, target2, target3, sort, builder.var(radar), builder.var(sortOrder), builder.var(output));
}
@Override
public LInstruction build(LAssembler builder){
return new RadarI(target1, target2, target3, sort, builder.var(radar), builder.var(sortOrder), builder.var(output));
public LCategory category(){
return LCategory.block;
}
}
@@ -557,13 +548,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicBlocks;
public LInstruction build(LAssembler builder){
return new SenseI(builder.var(from), builder.var(to), builder.var(type));
}
@Override
public LInstruction build(LAssembler builder){
return new SenseI(builder.var(from), builder.var(to), builder.var(type));
public LCategory category(){
return LCategory.block;
}
}
@@ -582,13 +573,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicOperations;
public LInstruction build(LAssembler builder){
return new SetI(builder.var(from), builder.var(to));
}
@Override
public LInstruction build(LAssembler builder){
return new SetI(builder.var(from), builder.var(to));
public LCategory category(){
return LCategory.operation;
}
}
@@ -622,7 +613,7 @@ public class LStatements{
table.left();
table.row();
table.table(c -> {
c.color.set(color());
c.color.set(category().color);
c.left();
funcs(c, table);
}).colspan(2).left();
@@ -663,8 +654,8 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicOperations;
public LCategory category(){
return LCategory.operation;
}
}
@@ -679,13 +670,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicOperations;
public LInstruction build(LAssembler builder){
return new WaitI(builder.var(value));
}
@Override
public LInstruction build(LAssembler builder){
return new WaitI(builder.var(value));
public LCategory category(){
return LCategory.operation;
}
}
@@ -715,13 +706,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicOperations;
public LInstruction build(LAssembler builder){
return new LookupI(builder.var(result), builder.var(id), type);
}
@Override
public LInstruction build(LAssembler builder){
return new LookupI(builder.var(result), builder.var(id), type);
public LCategory category(){
return LCategory.operation;
}
}
@@ -744,13 +735,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicOperations;
public LInstruction build(LAssembler builder){
return new PackColorI(builder.var(result), builder.var(r), builder.var(g), builder.var(b), builder.var(a));
}
@Override
public LInstruction build(LAssembler builder){
return new PackColorI(builder.var(result), builder.var(r), builder.var(g), builder.var(b), builder.var(a));
public LCategory category(){
return LCategory.operation;
}
}
@@ -767,8 +758,8 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicControl;
public LCategory category(){
return LCategory.control;
}
}
@@ -846,8 +837,8 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicControl;
public LCategory category(){
return LCategory.control;
}
}
@@ -884,13 +875,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicUnits;
public LInstruction build(LAssembler builder){
return new UnitBindI(builder.var(type));
}
@Override
public LInstruction build(LAssembler builder){
return new UnitBindI(builder.var(type));
public LCategory category(){
return LCategory.unit;
}
}
@@ -941,13 +932,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicUnits;
public LInstruction build(LAssembler builder){
return new UnitControlI(type, builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4), builder.var(p5));
}
@Override
public LInstruction build(LAssembler builder){
return new UnitControlI(type, builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4), builder.var(p5));
public LCategory category(){
return LCategory.unit;
}
}
@@ -965,13 +956,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicUnits;
public LInstruction build(LAssembler builder){
return new RadarI(target1, target2, target3, sort, LExecutor.varUnit, builder.var(sortOrder), builder.var(output));
}
@Override
public LInstruction build(LAssembler builder){
return new RadarI(target1, target2, target3, sort, LExecutor.varUnit, builder.var(sortOrder), builder.var(output));
public LCategory category(){
return LCategory.unit;
}
}
@@ -1074,13 +1065,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicUnits;
public LInstruction build(LAssembler builder){
return new UnitLocateI(locate, flag, builder.var(enemy), builder.var(ore), builder.var(outX), builder.var(outY), builder.var(outFound), builder.var(outBuild));
}
@Override
public LInstruction build(LAssembler builder){
return new UnitLocateI(locate, flag, builder.var(enemy), builder.var(ore), builder.var(outX), builder.var(outY), builder.var(outFound), builder.var(outBuild));
public LCategory category(){
return LCategory.unit;
}
}
@@ -1115,13 +1106,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new GetBlockI(builder.var(x), builder.var(y), builder.var(result), layer);
}
@Override
public LInstruction build(LAssembler builder){
return new GetBlockI(builder.var(x), builder.var(y), builder.var(result), layer);
public LCategory category(){
return LCategory.world;
}
}
@@ -1178,13 +1169,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new SetBlockI(builder.var(x), builder.var(y), builder.var(block), builder.var(team), builder.var(rotation), layer);
}
@Override
public LInstruction build(LAssembler builder){
return new SetBlockI(builder.var(x), builder.var(y), builder.var(block), builder.var(team), builder.var(rotation), layer);
public LCategory category(){
return LCategory.world;
}
}
@@ -1224,13 +1215,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), builder.var(result));
}
@Override
public LInstruction build(LAssembler builder){
return new SpawnUnitI(builder.var(type), builder.var(x), builder.var(y), builder.var(rotation), builder.var(team), builder.var(result));
public LCategory category(){
return LCategory.world;
}
}
@@ -1289,13 +1280,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new ApplyEffectI(clear, effect, builder.var(unit), builder.var(duration));
}
@Override
public LInstruction build(LAssembler builder){
return new ApplyEffectI(clear, effect, builder.var(unit), builder.var(duration));
public LCategory category(){
return LCategory.world;
}
}
@@ -1319,13 +1310,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new SpawnWaveI(builder.var(x), builder.var(y));
}
@Override
public LInstruction build(LAssembler builder){
return new SpawnWaveI(builder.var(x), builder.var(y));
public LCategory category(){
return LCategory.world;
}
}
@@ -1384,13 +1375,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new SetRuleI(rule, builder.var(value), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
}
@Override
public LInstruction build(LAssembler builder){
return new SetRuleI(rule, builder.var(value), builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
public LCategory category(){
return LCategory.world;
}
}
@@ -1430,13 +1421,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new FlushMessageI(type, builder.var(duration));
}
@Override
public LInstruction build(LAssembler builder){
return new FlushMessageI(type, builder.var(duration));
public LCategory category(){
return LCategory.world;
}
}
@@ -1486,13 +1477,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new CutsceneI(action, builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
}
@Override
public LInstruction build(LAssembler builder){
return new CutsceneI(action, builder.var(p1), builder.var(p2), builder.var(p3), builder.var(p4));
public LCategory category(){
return LCategory.world;
}
}
@@ -1521,13 +1512,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler b){
return new ExplosionI(b.var(team), b.var(x), b.var(y), b.var(radius), b.var(damage), b.var(air), b.var(ground), b.var(pierce));
}
@Override
public LInstruction build(LAssembler b){
return new ExplosionI(b.var(team), b.var(x), b.var(y), b.var(radius), b.var(damage), b.var(air), b.var(ground), b.var(pierce));
public LCategory category(){
return LCategory.world;
}
}
@@ -1546,13 +1537,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new SetRateI(builder.var(amount));
}
@Override
public LInstruction build(LAssembler builder){
return new SetRateI(builder.var(amount));
public LCategory category(){
return LCategory.world;
}
}
@@ -1606,13 +1597,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new FetchI(type, builder.var(result), builder.var(team), builder.var(extra), builder.var(index));
}
@Override
public LInstruction build(LAssembler builder){
return new FetchI(type, builder.var(result), builder.var(team), builder.var(extra), builder.var(index));
public LCategory category(){
return LCategory.world;
}
}
@@ -1635,13 +1626,13 @@ public class LStatements{
}
@Override
public Color color(){
return Pal.logicWorld;
public LInstruction build(LAssembler builder){
return new GetFlagI(builder.var(result), builder.var(flag));
}
@Override
public LInstruction build(LAssembler builder){
return new GetFlagI(builder.var(result), builder.var(flag));
public LCategory category(){
return LCategory.world;
}
}
@@ -1663,14 +1654,14 @@ public class LStatements{
return true;
}
@Override
public Color color(){
return Pal.logicWorld;
}
@Override
public LInstruction build(LAssembler builder){
return new SetFlagI(builder.var(flag), builder.var(value));
}
@Override
public LCategory category(){
return LCategory.world;
}
}
}

View File

@@ -6,6 +6,7 @@ import arc.graphics.*;
import arc.scene.actions.*;
import arc.scene.ui.*;
import arc.scene.ui.TextButton.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.core.GameState.*;
import mindustry.ctype.*;
@@ -154,28 +155,50 @@ public class LogicDialog extends BaseDialog{
buttons.button("@add", Icon.add, () -> {
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();
if(example instanceof InvalidStatement || example.hidden() || (example.privileged() && !privileged) || (example.nonPrivileged() && privileged)) continue;
dialog.cont.table(table -> {
table.background(Tex.button);
table.pane(t -> {
for(Prov<LStatement> prov : LogicIO.allStatements){
LStatement example = prov.get();
if(example instanceof InvalidStatement || example.hidden() || (example.privileged() && !privileged) || (example.nonPrivileged() && privileged)) continue;
TextButtonStyle style = new TextButtonStyle(Styles.flatt);
style.fontColor = example.color();
style.font = Fonts.outline;
LCategory category = example.category();
Table cat = t.find(category.name);
if(cat == null){
t.table(s -> {
if(category.icon != null){
s.image(category.icon, Pal.darkishGray).left().size(15f).padRight(10f);
}
s.add(category.localized()).color(Pal.darkishGray).left().tooltip(category.description());
s.image(Tex.whiteui, Pal.darkishGray).left().height(5f).growX().padLeft(10f);
}).growX().pad(5f).padTop(10f);
t.button(example.name(), style, () -> {
canvas.add(prov.get());
dialog.hide();
}).size(130f, 50f).self(c -> tooltip(c, "lst." + example.name()));
if(++i % 3 == 0) t.row();
}
});
t.row();
cat = t.table(c -> {
c.top().left();
}).name(category.name).top().left().growX().fillY().get();
t.row();
}
TextButtonStyle style = new TextButtonStyle(Styles.flatt);
style.fontColor = category.color;
style.font = Fonts.outline;
cat.button(example.name(), style, () -> {
canvas.add(prov.get());
dialog.hide();
}).size(130f, 50f).self(c -> tooltip(c, "lst." + example.name())).top().left();
if(cat.getChildren().size % 3 == 0) cat.row();
}
}).grow();
}).fill().maxHeight(Core.graphics.getHeight() * 0.8f);
dialog.addCloseButton();
dialog.show();
}).disabled(t -> canvas.statements.getChildren().size >= LExecutor.maxInstructions);
add(canvas).grow().name("canvas");
row();