logic 2
This commit is contained in:
@@ -24,7 +24,7 @@ import mindustry.editor.*;
|
|||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
import mindustry.graphics.*;
|
import mindustry.graphics.*;
|
||||||
import mindustry.logic.*;
|
import mindustry.logic2.LDialog;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
import mindustry.ui.fragments.*;
|
import mindustry.ui.fragments.*;
|
||||||
@@ -68,7 +68,7 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
public SchematicsDialog schematics;
|
public SchematicsDialog schematics;
|
||||||
public ModsDialog mods;
|
public ModsDialog mods;
|
||||||
public ColorPicker picker;
|
public ColorPicker picker;
|
||||||
public LogicDialog logic;
|
public LDialog logic;
|
||||||
|
|
||||||
public Cursor drillCursor, unloadCursor;
|
public Cursor drillCursor, unloadCursor;
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ public class UI implements ApplicationListener, Loadable{
|
|||||||
research = new ResearchDialog();
|
research = new ResearchDialog();
|
||||||
mods = new ModsDialog();
|
mods = new ModsDialog();
|
||||||
schematics = new SchematicsDialog();
|
schematics = new SchematicsDialog();
|
||||||
logic = new LogicDialog();
|
logic = new LDialog();
|
||||||
|
|
||||||
Group group = Core.scene.root;
|
Group group = Core.scene.root;
|
||||||
|
|
||||||
|
|||||||
104
core/src/mindustry/logic2/LCanvas.java
Normal file
104
core/src/mindustry/logic2/LCanvas.java
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
package mindustry.logic2;
|
||||||
|
|
||||||
|
import arc.input.*;
|
||||||
|
import arc.math.geom.*;
|
||||||
|
import arc.scene.event.*;
|
||||||
|
import arc.scene.ui.layout.*;
|
||||||
|
import arc.struct.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import mindustry.gen.*;
|
||||||
|
import mindustry.logic2.LStatements.*;
|
||||||
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
public class LCanvas extends Table{
|
||||||
|
|
||||||
|
private Table statements;
|
||||||
|
private Seq<StatementElem> elems = new Seq<>();
|
||||||
|
|
||||||
|
public LCanvas(){
|
||||||
|
//left();
|
||||||
|
|
||||||
|
pane(t -> {
|
||||||
|
t.setClip(false);
|
||||||
|
statements = t;
|
||||||
|
statements.defaults().width(300f).pad(4f);
|
||||||
|
t.marginRight(1);
|
||||||
|
}).growY().get().setClip(false);
|
||||||
|
|
||||||
|
add(new AssignStatement());
|
||||||
|
add(new AssignStatement());
|
||||||
|
add(new OpStatement());
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(LStatement statement){
|
||||||
|
StatementElem e = new StatementElem(statement);
|
||||||
|
elems.add(e);
|
||||||
|
|
||||||
|
statements.add(e);
|
||||||
|
statements.row();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StatementElem extends Table{
|
||||||
|
LStatement st;
|
||||||
|
|
||||||
|
public StatementElem(LStatement st){
|
||||||
|
this.st = st;
|
||||||
|
|
||||||
|
background(Tex.whitePane);
|
||||||
|
setColor(st.category().color);
|
||||||
|
margin(0f);
|
||||||
|
|
||||||
|
table(Tex.whiteui, t -> {
|
||||||
|
t.color.set(color);
|
||||||
|
|
||||||
|
t.margin(8f);
|
||||||
|
t.touchable = Touchable.enabled;
|
||||||
|
|
||||||
|
t.add(st.name()).style(Styles.outlineLabel).color(color).padRight(8);
|
||||||
|
t.add().growX();
|
||||||
|
t.button(Icon.cancel, Styles.onlyi, () -> {
|
||||||
|
//TODO disconnect things
|
||||||
|
remove();
|
||||||
|
elems.remove(this);
|
||||||
|
//TODO rebuild
|
||||||
|
});
|
||||||
|
|
||||||
|
t.addListener(new InputListener(){
|
||||||
|
float lastx, lasty;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||||
|
Vec2 v = localToStageCoordinates(Tmp.v1.set(x, y));
|
||||||
|
lastx = v.x;
|
||||||
|
lasty = v.y;
|
||||||
|
toFront();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
||||||
|
Vec2 v = localToStageCoordinates(Tmp.v1.set(x, y));
|
||||||
|
|
||||||
|
translation.add(v.x - lastx, v.y - lasty);
|
||||||
|
lastx = v.x;
|
||||||
|
lasty = v.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||||
|
translation.setZero();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).growX().padBottom(6);
|
||||||
|
|
||||||
|
row();
|
||||||
|
|
||||||
|
table(t -> {
|
||||||
|
t.setColor(color);
|
||||||
|
st.build(t);
|
||||||
|
}).pad(8).padTop(2);
|
||||||
|
|
||||||
|
marginBottom(7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
core/src/mindustry/logic2/LCategory.java
Normal file
15
core/src/mindustry/logic2/LCategory.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package mindustry.logic2;
|
||||||
|
|
||||||
|
import arc.graphics.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
|
|
||||||
|
public enum LCategory{
|
||||||
|
control(Pal.accentBack),
|
||||||
|
operations(Pal.place.cpy().shiftSaturation(-0.4f).mul(0.7f));
|
||||||
|
|
||||||
|
public final Color color;
|
||||||
|
|
||||||
|
LCategory(Color color){
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
package mindustry.logic;
|
package mindustry.logic2;
|
||||||
|
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
|
|
||||||
public class LogicDialog extends BaseDialog{
|
public class LDialog extends BaseDialog{
|
||||||
LogicCanvas canvas;
|
LCanvas canvas;
|
||||||
|
|
||||||
public LogicDialog(){
|
public LDialog(){
|
||||||
super("logic");
|
super("logic");
|
||||||
|
|
||||||
canvas = new LogicCanvas();
|
canvas = new LCanvas();
|
||||||
addCloseButton();
|
addCloseButton();
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
6
core/src/mindustry/logic2/LExecutor.java
Normal file
6
core/src/mindustry/logic2/LExecutor.java
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package mindustry.logic2;
|
||||||
|
|
||||||
|
public class LExecutor{
|
||||||
|
LStatement[] statements;
|
||||||
|
int counter;
|
||||||
|
}
|
||||||
14
core/src/mindustry/logic2/LStatement.java
Normal file
14
core/src/mindustry/logic2/LStatement.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package mindustry.logic2;
|
||||||
|
|
||||||
|
import arc.scene.ui.layout.*;
|
||||||
|
|
||||||
|
public abstract class LStatement{
|
||||||
|
|
||||||
|
public abstract void run(LExecutor exec);
|
||||||
|
public abstract void build(Table table);
|
||||||
|
public abstract LCategory category();
|
||||||
|
|
||||||
|
public String name(){
|
||||||
|
return getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
}
|
||||||
60
core/src/mindustry/logic2/LStatements.java
Normal file
60
core/src/mindustry/logic2/LStatements.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package mindustry.logic2;
|
||||||
|
|
||||||
|
import arc.scene.ui.layout.*;
|
||||||
|
import arc.util.*;
|
||||||
|
import mindustry.logic.*;
|
||||||
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
public class LStatements{
|
||||||
|
|
||||||
|
public static class AssignStatement extends LStatement{
|
||||||
|
public int output;
|
||||||
|
public double value;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Table table){
|
||||||
|
table.field(value + "", Styles.nodeField, str -> value = parseDouble(str))
|
||||||
|
.size(100f, 40f).pad(2f).color(table.color).padRight(20);
|
||||||
|
|
||||||
|
table.field(value + "", Styles.nodeField, str -> value = parseDouble(str))
|
||||||
|
.size(100f, 40f).pad(2f).color(table.color);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LCategory category(){
|
||||||
|
return LCategory.operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double parseDouble(String s){
|
||||||
|
return s.equals("yes") || s.equals("true") ? 1 :
|
||||||
|
s.equals("no") || s.equals("false") ? 0 :
|
||||||
|
Strings.parseDouble(s, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class OpStatement extends LStatement{
|
||||||
|
public BinaryOp op = BinaryOp.add;
|
||||||
|
public int output;
|
||||||
|
public double result;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(LExecutor exec){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void build(Table table){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LCategory category(){
|
||||||
|
return LCategory.operations;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
org.gradle.daemon=true
|
org.gradle.daemon=true
|
||||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||||
archash=d71d43f90bca3d764b79e22c868f840fc4261361
|
archash=327b394e0e91a7a6d4d3320ede319b1f63d29ddb
|
||||||
|
|||||||
Reference in New Issue
Block a user