Better logic UI

This commit is contained in:
Anuken
2020-08-14 10:48:29 -04:00
parent 73dd7ba21a
commit ffb2d6eeaa
10 changed files with 125 additions and 74 deletions

View File

@@ -40,7 +40,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
public void update(){ public void update(){
Building core = closestCore(); Building core = closestCore();
if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && within(core, mineTransferRange)){ if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && within(core, mineTransferRange) && !offloadImmediately()){
int accepted = core.acceptStack(item(), stack().amount, this); int accepted = core.acceptStack(item(), stack().amount, this);
if(accepted > 0){ if(accepted > 0){
Call.transferItemTo(item(), accepted, Call.transferItemTo(item(), accepted,
@@ -52,7 +52,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
if(mineTile == null || core == null || mineTile.block() != Blocks.air || dst(mineTile.worldx(), mineTile.worldy()) > miningRange if(mineTile == null || core == null || mineTile.block() != Blocks.air || dst(mineTile.worldx(), mineTile.worldy()) > miningRange
|| (((Object)this) instanceof Builderc && ((Builderc)(Object)this).activelyBuilding()) || (((Object)this) instanceof Builderc && ((Builderc)(Object)this).activelyBuilding())
|| mineTile.drop() == null || !acceptsItem(mineTile.drop()) || !canMine(mineTile.drop())){ || mineTile.drop() == null || !canMine(mineTile.drop())){
mineTile = null; mineTile = null;
mineTimer = 0f; mineTimer = 0f;
}else{ }else{
@@ -60,6 +60,10 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
rotation(Mathf.slerpDelta(rotation(), angleTo(mineTile.worldx(), mineTile.worldy()), 0.4f)); rotation(Mathf.slerpDelta(rotation(), angleTo(mineTile.worldx(), mineTile.worldy()), 0.4f));
mineTimer += Time.delta *type.mineSpeed; mineTimer += Time.delta *type.mineSpeed;
if(Mathf.chance(0.06 * Time.delta)){
Fx.pulverizeSmall.at(mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
}
if(mineTimer >= 50f + item.hardness*10f){ if(mineTimer >= 50f + item.hardness*10f){
mineTimer = 0; mineTimer = 0;
@@ -73,12 +77,13 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldx() + Mathf.range(tilesize / 2f),
mineTile.worldy() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f),
this); this);
}else{
mineTile = null;
mineTimer = 0f;
} }
} }
if(Mathf.chance(0.06 * Time.delta)){
Fx.pulverizeSmall.at(mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
}
} }
} }

View File

@@ -197,7 +197,7 @@ public class DesktopInput extends InputHandler{
Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f); Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f);
} }
shouldShoot = true; shouldShoot = !scene.hasMouse();
if(!scene.hasMouse()){ if(!scene.hasMouse()){
if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){ if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){

View File

@@ -903,7 +903,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
} }
public boolean canShoot(){ public boolean canShoot(){
return block == null && !Core.scene.hasMouse() && !onConfigurable() && !isDroppingItem() && !(player.builder().updateBuilding() && player.builder().isBuilding()); return block == null && !onConfigurable() && !isDroppingItem() && !(player.builder().updateBuilding() && player.builder().isBuilding());
} }
public boolean onConfigurable(){ public boolean onConfigurable(){

View File

@@ -16,9 +16,7 @@ import arc.util.*;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.logic.LStatements.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import mindustry.world.blocks.logic.*; import mindustry.world.blocks.logic.*;
public class LCanvas extends Table{ public class LCanvas extends Table{
@@ -26,38 +24,46 @@ public class LCanvas extends Table{
private static Seq<Runnable> postDraw = new Seq<>(); private static Seq<Runnable> postDraw = new Seq<>();
private Vec2 offset = new Vec2(); private Vec2 offset = new Vec2();
private DragLayout statements; DragLayout statements;
private StatementElem dragging; StatementElem dragging;
ScrollPane pane;
float targetWidth;
public LCanvas(){ public LCanvas(){
//left(); rebuild();
}
/** @return if statement elements should have rows. */
public static boolean useRows(){
return Core.graphics.getWidth() < Scl.scl(900f) * 1.2f;
}
public void rebuild(){
targetWidth = useRows() ? 400f : 900f;
float s = pane != null ? pane.getScrollPercentY() : 0f;
String toLoad = statements != null ? save() : null;
clear();
statements = new DragLayout(); statements = new DragLayout();
ScrollPane pane = pane(statements).grow().get(); pane = pane(t -> {
t.center();
t.add(statements).pad(2f).center().width(targetWidth);
}).grow().get();
pane.setClip(false); pane.setClip(false);
pane.setFlickScroll(false); pane.setFlickScroll(false);
row(); //load old scroll percent
Core.app.post(() -> {
button("@add", Icon.add, Styles.cleart, () -> { pane.setScrollPercentY(s);
BaseDialog dialog = new BaseDialog("@add"); pane.updateVisualScroll();
dialog.cont.pane(t -> { pane.requestScroll();
t.background(Tex.button);
int i = 0;
for(Prov<LStatement> prov : LogicIO.allStatements){
LStatement example = prov.get();
if(example instanceof InvalidStatement) continue;
t.button(example.name(), Styles.cleart, () -> {
add(prov.get());
dialog.hide();
}).size(140f, 50f);
if(++i % 2 == 0) t.row();
}
}); });
dialog.addCloseButton();
dialog.show(); if(toLoad != null){
}).height(50f).left().width(400f).marginLeft(10f).disabled(t -> statements.getChildren().size >= LogicBlock.maxInstructions); load(toLoad);
}
} }
private void drawGrid(){ private void drawGrid(){
@@ -120,7 +126,6 @@ public class LCanvas extends Table{
} }
public class DragLayout extends WidgetGroup{ public class DragLayout extends WidgetGroup{
float margin = Scl.scl(4f);
float space = Scl.scl(10f), prefWidth, prefHeight; float space = Scl.scl(10f), prefWidth, prefHeight;
Seq<Element> seq = new Seq<>(); Seq<Element> seq = new Seq<>();
int insertPosition = 0; int insertPosition = 0;
@@ -134,10 +139,10 @@ public class LCanvas extends Table{
float cy = 0; float cy = 0;
seq.clear(); seq.clear();
float totalHeight = getChildren().sumf(e -> e.getHeight() + space) + margin*2f; float totalHeight = getChildren().sumf(e -> e.getHeight() + space);
height = prefHeight = totalHeight; height = prefHeight = totalHeight;
width = prefWidth = Scl.scl(400f); width = prefWidth = Scl.scl(targetWidth);
//layout everything normally //layout everything normally
for(int i = 0; i < getChildren().size; i++){ for(int i = 0; i < getChildren().size; i++){
@@ -146,8 +151,8 @@ public class LCanvas extends Table{
//ignore the dragged element //ignore the dragged element
if(dragging == e) continue; if(dragging == e) continue;
e.setSize(width - margin * 2f, e.getPrefHeight()); e.setSize(width, e.getPrefHeight());
e.setPosition(x + margin, height- margin - cy, Align.topLeft); e.setPosition(0, height - cy, Align.topLeft);
cy += e.getPrefHeight() + space; cy += e.getPrefHeight() + space;
seq.add(e); seq.add(e);
@@ -197,10 +202,10 @@ public class LCanvas extends Table{
//draw selection box indicating placement position //draw selection box indicating placement position
if(dragging != null && insertPosition <= seq.size){ if(dragging != null && insertPosition <= seq.size){
float shiftAmount = dragging.getHeight(); float shiftAmount = dragging.getHeight();
float lastX = x + margin; float lastX = x;
float lastY = insertPosition == 0 ? height + y - margin : seq.get(insertPosition - 1).y + y - space; float lastY = insertPosition == 0 ? height + y : seq.get(insertPosition - 1).y + y - space;
Tex.pane.draw(lastX, lastY - shiftAmount, width - margin*2f, dragging.getHeight()); Tex.pane.draw(lastX, lastY - shiftAmount, width, dragging.getHeight());
} }
super.draw(); super.draw();
@@ -253,6 +258,10 @@ public class LCanvas extends Table{
t.add(st.name()).style(Styles.outlineLabel).color(color).padRight(8); t.add(st.name()).style(Styles.outlineLabel).color(color).padRight(8);
t.add().growX(); t.add().growX();
t.button(Icon.copy, Styles.logici, () -> {
}).padRight(6).get().tapped(() -> copy());
t.button(Icon.cancel, Styles.logici, () -> { t.button(Icon.cancel, Styles.logici, () -> {
remove(); remove();
dragging = null; dragging = null;
@@ -266,15 +275,7 @@ public class LCanvas extends Table{
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){ public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
if(button == KeyCode.mouseMiddle){ if(button == KeyCode.mouseMiddle){
LStatement copy = st.copy(); copy();
if(copy != null){
StatementElem s = new StatementElem(copy);
statements.addChildAfter(StatementElem.this,s);
statements.layout();
copy.elem = s;
copy.setupUI();
}
return false; return false;
} }
@@ -317,6 +318,18 @@ public class LCanvas extends Table{
marginBottom(7); marginBottom(7);
} }
void copy(){
LStatement copy = st.copy();
if(copy != null){
StatementElem s = new StatementElem(copy);
statements.addChildAfter(StatementElem.this,s);
statements.layout();
copy.elem = s;
copy.setupUI();
}
}
@Override @Override
public void draw(){ public void draw(){
float pad = 5f; float pad = 5f;

View File

@@ -48,6 +48,12 @@ public abstract class LStatement{
field(table, value, setter).width(85f); field(table, value, setter).width(85f);
} }
protected void row(Table table){
if(LCanvas.useRows()){
table.row();
}
}
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){
showSelectTable(b, (t, hide) -> { showSelectTable(b, (t, hide) -> {
ButtonGroup<Button> group = new ButtonGroup<>(); ButtonGroup<Button> group = new ButtonGroup<>();

View File

@@ -94,7 +94,7 @@ public class LStatements{
fields(table, target, str -> target = str); fields(table, target, str -> target = str);
table.row(); row(table);
table.add(" at "); table.add(" at ");
@@ -126,7 +126,7 @@ public class LStatements{
fields(table, target, str -> target = str); fields(table, target, str -> target = str);
table.row(); row(table);
table.add(" at "); table.add(" at ");
@@ -168,7 +168,7 @@ public class LStatements{
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2); }, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
if(type != GraphicsType.stroke){ if(type != GraphicsType.stroke){
table.row(); row(table);
} }
table.table(s -> { table.table(s -> {
@@ -189,7 +189,7 @@ public class LStatements{
case line: case line:
fields(s, "x", x, v -> x = v); fields(s, "x", x, v -> x = v);
fields(s, "y", y, v -> y = v); fields(s, "y", y, v -> y = v);
s.row(); row(s);
fields(s, "x2", p1, v -> p1 = v); fields(s, "x2", p1, v -> p1 = v);
fields(s, "y2", p2, v -> p2 = v); fields(s, "y2", p2, v -> p2 = v);
break; break;
@@ -197,7 +197,7 @@ public class LStatements{
case lineRect: case lineRect:
fields(s, "x", x, v -> x = v); fields(s, "x", x, v -> x = v);
fields(s, "y", y, v -> y = v); fields(s, "y", y, v -> y = v);
s.row(); row(s);
fields(s, "width", p1, v -> p1 = v); fields(s, "width", p1, v -> p1 = v);
fields(s, "height", p2, v -> p2 = v); fields(s, "height", p2, v -> p2 = v);
break; break;
@@ -205,19 +205,19 @@ public class LStatements{
case linePoly: case linePoly:
fields(s, "x", x, v -> x = v); fields(s, "x", x, v -> x = v);
fields(s, "y", y, v -> y = v); fields(s, "y", y, v -> y = v);
s.row(); row(s);
fields(s, "sides", p1, v -> p1 = v); fields(s, "sides", p1, v -> p1 = v);
fields(s, "radius", p2, v -> p2 = v); fields(s, "radius", p2, v -> p2 = v);
s.row(); row(s);
fields(s, "rotation", p3, v -> p3 = v); fields(s, "rotation", p3, v -> p3 = v);
break; break;
case triangle: case triangle:
fields(s, "x", x, v -> x = v); fields(s, "x", x, v -> x = v);
fields(s, "y", y, v -> y = v); fields(s, "y", y, v -> y = v);
s.row(); row(s);
fields(s, "x2", p1, v -> p1 = v); fields(s, "x2", p1, v -> p1 = v);
fields(s, "y2", p2, v -> p2 = v); fields(s, "y2", p2, v -> p2 = v);
s.row(); row(s);
fields(s, "x3", p3, v -> p3 = v); fields(s, "x3", p3, v -> p3 = v);
fields(s, "y3", p4, v -> p4 = v); fields(s, "y3", p4, v -> p4 = v);
break; break;
@@ -328,7 +328,7 @@ public class LStatements{
field(table, target, v -> target = v); field(table, target, v -> target = v);
table.row(); row(table);
//Q: why don't you just use arrays for this? //Q: why don't you just use arrays for this?
//A: arrays aren't as easy to serialize so the code generator doesn't handle them //A: arrays aren't as easy to serialize so the code generator doesn't handle them
@@ -337,7 +337,7 @@ public class LStatements{
fields(table, type.parameters[i], i == 0 ? p1 : i == 1 ? p2 : i == 2 ? p3 : p4, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : i == 2 ? v -> p3 = v : v -> p4 = v); fields(table, type.parameters[i], i == 0 ? p1 : i == 1 ? p2 : i == 2 ? p3 : p4, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : i == 2 ? v -> p3 = v : v -> p4 = v);
if(++c % 2 == 0) table.row(); if(++c % 2 == 0) row(table);
} }
} }
@@ -366,7 +366,7 @@ public class LStatements{
fields(table, radar, v -> radar = v); fields(table, radar, v -> radar = v);
table.row(); row(table);
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
int fi = i; int fi = i;
@@ -382,7 +382,7 @@ public class LStatements{
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2); }, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
if(i == 1){ if(i == 1){
table.row(); row(table);
} }
} }
@@ -390,7 +390,7 @@ public class LStatements{
fields(table, sortOrder, v -> sortOrder = v); fields(table, sortOrder, v -> sortOrder = v);
table.row(); row(table);
table.add(" output "); table.add(" output ");
@@ -422,7 +422,7 @@ public class LStatements{
table.add(" = "); table.add(" = ");
table.row(); row(table);
tfield = field(table, type, str -> type = str).padRight(0f).get(); tfield = field(table, type, str -> type = str).padRight(0f).get();
@@ -547,7 +547,7 @@ public class LStatements{
table.add(" = "); table.add(" = ");
table.row(); row(table);
field(table, a, str -> a = str); field(table, a, str -> a = str);

View File

@@ -3,11 +3,12 @@ package mindustry.logic;
import arc.*; import arc.*;
import arc.func.*; import arc.func.*;
import arc.scene.ui.TextButton.*; import arc.scene.ui.TextButton.*;
import arc.scene.ui.layout.*;
import arc.util.*; import arc.util.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.logic.LStatements.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.ui.dialogs.*; import mindustry.ui.dialogs.*;
import mindustry.world.blocks.logic.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@@ -23,6 +24,8 @@ public class LogicDialog extends BaseDialog{
canvas = new LCanvas(); canvas = new LCanvas();
addCloseButton(); addCloseButton();
buttons.getCells().first().width(170f);
buttons.button("@edit", Icon.edit, () -> { buttons.button("@edit", Icon.edit, () -> {
BaseDialog dialog = new BaseDialog("@editor.export"); BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> { dialog.cont.pane(p -> {
@@ -49,14 +52,36 @@ public class LogicDialog extends BaseDialog{
dialog.addCloseButton(); dialog.addCloseButton();
dialog.show(); dialog.show();
}); }).width(170f);
stack(canvas, new Table(t -> { buttons.button("@add", Icon.add, () -> {
t.bottom(); BaseDialog dialog = new BaseDialog("@add");
t.add(buttons); dialog.cont.pane(t -> {
})).grow(); t.background(Tex.button);
int i = 0;
for(Prov<LStatement> prov : LogicIO.allStatements){
LStatement example = prov.get();
if(example instanceof InvalidStatement) continue;
t.button(example.name(), Styles.cleart, () -> {
canvas.add(prov.get());
dialog.hide();
}).size(140f, 50f);
if(++i % 2 == 0) t.row();
}
});
dialog.addCloseButton();
dialog.show();
}).width(170f).disabled(t -> canvas.statements.getChildren().size >= LogicBlock.maxInstructions);
add(canvas).grow();
row();
add(buttons).growX();
hidden(() -> consumer.get(canvas.save())); hidden(() -> consumer.get(canvas.save()));
onResize(() -> canvas.rebuild());
} }
public void show(String code, Cons<String> consumer){ public void show(String code, Cons<String> consumer){

View File

@@ -44,7 +44,9 @@ public abstract class GenerateFilter{
/** localized display name */ /** localized display name */
public String name(){ public String name(){
return Core.bundle.get("filter." + getClass().getSimpleName().toLowerCase().replace("filter", ""), getClass().getSimpleName().replace("Filter", "")); Class c = getClass();
if(c.isAnonymousClass()) c = c.getSuperclass();
return Core.bundle.get("filter." + c.getSimpleName().toLowerCase().replace("filter", ""), c.getSimpleName().replace("Filter", ""));
} }
/** set the seed to a random number */ /** set the seed to a random number */

View File

@@ -203,7 +203,7 @@ public class Styles{
}}; }};
geni = new ImageButtonStyle(){{ geni = new ImageButtonStyle(){{
imageDownColor = Pal.accent; imageDownColor = Pal.accent;
imageUpColor = Color.white; imageUpColor = Color.black;
}}; }};
colori = new ImageButtonStyle(){{ colori = new ImageButtonStyle(){{
//imageDownColor = Pal.accent; //imageDownColor = Pal.accent;

View File

@@ -1,3 +1,3 @@
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.jvmargs=-Xms256m -Xmx1024m org.gradle.jvmargs=-Xms256m -Xmx1024m
archash=a5c0934b3894e9f2fe793800a2adb39606f32cee archash=7fbbbc6eb77b8f868c962504586e8c4b67c709ec