diff --git a/core/src/mindustry/logic/BinaryOp.java b/core/src/mindustry/logic/BinaryOp.java index c993697a5e..6ceeae492c 100644 --- a/core/src/mindustry/logic/BinaryOp.java +++ b/core/src/mindustry/logic/BinaryOp.java @@ -18,7 +18,8 @@ public enum BinaryOp{ and("and", (a, b) -> (int)a & (int)b), xor("xor", (a, b) -> (int)a ^ (int)b), max("max", Math::max), - min("min", Math::min); + min("min", Math::min), + atan2("atan2", Math::atan2); public static final BinaryOp[] all = values(); @@ -30,6 +31,11 @@ public enum BinaryOp{ this.function = function; } + @Override + public String toString(){ + return symbol; + } + interface OpLambda{ double get(double a, double b); } diff --git a/core/src/mindustry/logic/LCanvas.java b/core/src/mindustry/logic/LCanvas.java index cd903e8e78..5f8bd4af30 100644 --- a/core/src/mindustry/logic/LCanvas.java +++ b/core/src/mindustry/logic/LCanvas.java @@ -58,7 +58,7 @@ public class LCanvas extends Table{ add(new SetStatement()); add(new JumpStatement()); add(new EnableStatement()); - add(new OpStatement()); + add(new BinaryOpStatement()); } private void drawGrid(){ diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 1bc4091581..be9d4495c2 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -257,6 +257,24 @@ public class LExecutor{ } } + public static class UnaryOpI implements LInstruction{ + public UnaryOp op; + public int value, dest; + + public UnaryOpI(UnaryOp op, int value, int dest){ + this.op = op; + this.value = value; + this.dest = dest; + } + + UnaryOpI(){} + + @Override + public void run(LExecutor exec){ + exec.setnum(dest, op.function.get(exec.num(value))); + } + } + public static class EndI implements LInstruction{ @Override @@ -296,8 +314,8 @@ public class LExecutor{ }else{ out.setLength(0); //display integer version when possible - if(Math.abs(v.numval - (int)v.numval) < 0.000001){ - out.append((int)v.numval); + if(Math.abs(v.numval - (long)v.numval) < 0.000001){ + out.append((long)v.numval); }else{ out.append(v.numval); } diff --git a/core/src/mindustry/logic/LStatement.java b/core/src/mindustry/logic/LStatement.java index b2d38f35f2..b3157593be 100644 --- a/core/src/mindustry/logic/LStatement.java +++ b/core/src/mindustry/logic/LStatement.java @@ -1,7 +1,13 @@ package mindustry.logic; +import arc.*; import arc.func.*; +import arc.math.*; +import arc.scene.*; +import arc.scene.actions.*; +import arc.scene.ui.*; import arc.scene.ui.layout.*; +import arc.util.*; import arc.util.ArcAnnotate.*; import mindustry.gen.*; import mindustry.logic.LCanvas.*; @@ -23,6 +29,46 @@ public abstract class LStatement{ .size(130f, 40f).pad(2f).color(table.color); } + protected void showSelect(Button b, T[] values, T current, Cons getter){ + Table t = new Table(Tex.button); + + //triggers events behind the element to simulate deselection + Element hitter = new Element(); + + Runnable hide = () -> { + Core.app.post(hitter::remove); + t.actions(Actions.fadeOut(0.3f, Interp.fade), Actions.remove()); + }; + + hitter.fillParent = true; + hitter.tapped(hide); + Core.scene.add(hitter); + + Core.scene.add(t); + + t.update(() -> { + b.localToStageCoordinates(Tmp.v1.set(b.getWidth()/2f, b.getHeight()/2f)); + Tmp.v1.clamp(0, 0, Core.graphics.getWidth() - b.getWidth(), Core.graphics.getHeight() - b.getHeight()); + t.setPosition(Tmp.v1.x, Tmp.v1.y, Align.center); + }); + t.actions(Actions.alpha(0), Actions.fadeIn(0.3f, Interp.fade)); + + ButtonGroup