From ffb2d6eeaa30104befc8636b09fe3783a372d74e Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 14 Aug 2020 10:48:29 -0400 Subject: [PATCH] Better logic UI --- .../mindustry/entities/comp/MinerComp.java | 15 ++- core/src/mindustry/input/DesktopInput.java | 2 +- core/src/mindustry/input/InputHandler.java | 2 +- core/src/mindustry/logic/LCanvas.java | 97 +++++++++++-------- core/src/mindustry/logic/LStatement.java | 6 ++ core/src/mindustry/logic/LStatements.java | 32 +++--- core/src/mindustry/logic/LogicDialog.java | 37 +++++-- .../maps/filters/GenerateFilter.java | 4 +- core/src/mindustry/ui/Styles.java | 2 +- gradle.properties | 2 +- 10 files changed, 125 insertions(+), 74 deletions(-) diff --git a/core/src/mindustry/entities/comp/MinerComp.java b/core/src/mindustry/entities/comp/MinerComp.java index 92937f2125..1ec4794ca2 100644 --- a/core/src/mindustry/entities/comp/MinerComp.java +++ b/core/src/mindustry/entities/comp/MinerComp.java @@ -40,7 +40,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{ public void update(){ 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); if(accepted > 0){ 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 || (((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; mineTimer = 0f; }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)); 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){ mineTimer = 0; @@ -73,12 +77,13 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{ mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 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); - } + } } diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 5af981fb9f..f2321c1863 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -197,7 +197,7 @@ public class DesktopInput extends InputHandler{ Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f); } - shouldShoot = true; + shouldShoot = !scene.hasMouse(); if(!scene.hasMouse()){ if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){ diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 65db381c54..4eba2a7181 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -903,7 +903,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ } 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(){ diff --git a/core/src/mindustry/logic/LCanvas.java b/core/src/mindustry/logic/LCanvas.java index 0b4a0c7a8e..aeddb67b8f 100644 --- a/core/src/mindustry/logic/LCanvas.java +++ b/core/src/mindustry/logic/LCanvas.java @@ -16,9 +16,7 @@ import arc.util.*; import arc.util.ArcAnnotate.*; import mindustry.gen.*; import mindustry.graphics.*; -import mindustry.logic.LStatements.*; import mindustry.ui.*; -import mindustry.ui.dialogs.*; import mindustry.world.blocks.logic.*; public class LCanvas extends Table{ @@ -26,38 +24,46 @@ public class LCanvas extends Table{ private static Seq postDraw = new Seq<>(); private Vec2 offset = new Vec2(); - private DragLayout statements; - private StatementElem dragging; + DragLayout statements; + StatementElem dragging; + ScrollPane pane; + float targetWidth; 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(); - 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.setFlickScroll(false); - row(); + //load old scroll percent + Core.app.post(() -> { + pane.setScrollPercentY(s); + pane.updateVisualScroll(); + pane.requestScroll(); + }); - button("@add", Icon.add, Styles.cleart, () -> { - BaseDialog dialog = new BaseDialog("@add"); - dialog.cont.pane(t -> { - t.background(Tex.button); - int i = 0; - for(Prov 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(); - }).height(50f).left().width(400f).marginLeft(10f).disabled(t -> statements.getChildren().size >= LogicBlock.maxInstructions); + if(toLoad != null){ + load(toLoad); + } } private void drawGrid(){ @@ -120,7 +126,6 @@ public class LCanvas extends Table{ } public class DragLayout extends WidgetGroup{ - float margin = Scl.scl(4f); float space = Scl.scl(10f), prefWidth, prefHeight; Seq seq = new Seq<>(); int insertPosition = 0; @@ -134,10 +139,10 @@ public class LCanvas extends Table{ float cy = 0; seq.clear(); - float totalHeight = getChildren().sumf(e -> e.getHeight() + space) + margin*2f; + float totalHeight = getChildren().sumf(e -> e.getHeight() + space); height = prefHeight = totalHeight; - width = prefWidth = Scl.scl(400f); + width = prefWidth = Scl.scl(targetWidth); //layout everything normally for(int i = 0; i < getChildren().size; i++){ @@ -146,8 +151,8 @@ public class LCanvas extends Table{ //ignore the dragged element if(dragging == e) continue; - e.setSize(width - margin * 2f, e.getPrefHeight()); - e.setPosition(x + margin, height- margin - cy, Align.topLeft); + e.setSize(width, e.getPrefHeight()); + e.setPosition(0, height - cy, Align.topLeft); cy += e.getPrefHeight() + space; seq.add(e); @@ -197,10 +202,10 @@ public class LCanvas extends Table{ //draw selection box indicating placement position if(dragging != null && insertPosition <= seq.size){ float shiftAmount = dragging.getHeight(); - float lastX = x + margin; - float lastY = insertPosition == 0 ? height + y - margin : seq.get(insertPosition - 1).y + y - space; + float lastX = x; + 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(); @@ -253,6 +258,10 @@ public class LCanvas extends Table{ t.add(st.name()).style(Styles.outlineLabel).color(color).padRight(8); t.add().growX(); + + t.button(Icon.copy, Styles.logici, () -> { + }).padRight(6).get().tapped(() -> copy()); + t.button(Icon.cancel, Styles.logici, () -> { remove(); dragging = null; @@ -266,15 +275,7 @@ public class LCanvas extends Table{ public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){ if(button == KeyCode.mouseMiddle){ - LStatement copy = st.copy(); - if(copy != null){ - StatementElem s = new StatementElem(copy); - - statements.addChildAfter(StatementElem.this,s); - statements.layout(); - copy.elem = s; - copy.setupUI(); - } + copy(); return false; } @@ -317,6 +318,18 @@ public class LCanvas extends Table{ 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 public void draw(){ float pad = 5f; diff --git a/core/src/mindustry/logic/LStatement.java b/core/src/mindustry/logic/LStatement.java index d965101296..8b0d8422b1 100644 --- a/core/src/mindustry/logic/LStatement.java +++ b/core/src/mindustry/logic/LStatement.java @@ -48,6 +48,12 @@ public abstract class LStatement{ field(table, value, setter).width(85f); } + protected void row(Table table){ + if(LCanvas.useRows()){ + table.row(); + } + } + protected void showSelect(Button b, T[] values, T current, Cons getter, int cols, Cons sizer){ showSelectTable(b, (t, hide) -> { ButtonGroup