Logic edge autoscroll & jump highlighting on hover
This commit is contained in:
@@ -20,9 +20,8 @@ import mindustry.ui.*;
|
|||||||
import mindustry.world.blocks.logic.*;
|
import mindustry.world.blocks.logic.*;
|
||||||
|
|
||||||
public class LCanvas extends Table{
|
public class LCanvas extends Table{
|
||||||
private static final Color backgroundCol = Pal.darkMetal.cpy().mul(0.1f), gridCol = Pal.darkMetal.cpy().mul(0.5f);
|
|
||||||
static Seq<Runnable> postDraw = new Seq<>();
|
static Seq<Runnable> postDraw = new Seq<>();
|
||||||
private Vec2 offset = new Vec2();
|
static Seq<Runnable> postDrawPriority = new Seq<>();
|
||||||
|
|
||||||
DragLayout statements;
|
DragLayout statements;
|
||||||
StatementElem dragging;
|
StatementElem dragging;
|
||||||
@@ -91,11 +90,27 @@ public class LCanvas extends Table{
|
|||||||
this.statements.layout();
|
this.statements.layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void act(float delta){
|
||||||
|
super.act(delta);
|
||||||
|
|
||||||
|
if(Core.input.isTouched()){
|
||||||
|
float y = Core.input.mouseY();
|
||||||
|
float dst = Math.min(y - this.y, Core.graphics.getHeight() - y);
|
||||||
|
if(dst < Scl.scl(100f)){ //scroll margin
|
||||||
|
int sign = Mathf.sign(Core.graphics.getHeight()/2f - y);
|
||||||
|
pane.setScrollY(pane.getScrollY() + sign * Scl.scl(15f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(){
|
public void draw(){
|
||||||
postDraw.clear();
|
postDraw.clear();
|
||||||
|
postDrawPriority.clear();
|
||||||
super.draw();
|
super.draw();
|
||||||
postDraw.each(Runnable::run);
|
postDraw.each(Runnable::run);
|
||||||
|
postDrawPriority.each(Runnable::run);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DragLayout extends WidgetGroup{
|
public class DragLayout extends WidgetGroup{
|
||||||
@@ -252,7 +267,7 @@ public class LCanvas extends Table{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec2 v = localToStageCoordinates(Tmp.v1.set(x, y));
|
Vec2 v = localToParentCoordinates(Tmp.v1.set(x, y));
|
||||||
lastx = v.x;
|
lastx = v.x;
|
||||||
lasty = v.y;
|
lasty = v.y;
|
||||||
dragging = StatementElem.this;
|
dragging = StatementElem.this;
|
||||||
@@ -263,7 +278,7 @@ public class LCanvas extends Table{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
public void touchDragged(InputEvent event, float x, float y, int pointer){
|
||||||
Vec2 v = localToStageCoordinates(Tmp.v1.set(x, y));
|
Vec2 v = localToParentCoordinates(Tmp.v1.set(x, y));
|
||||||
|
|
||||||
translation.add(v.x - lastx, v.y - lasty);
|
translation.add(v.x - lastx, v.y - lasty);
|
||||||
lastx = v.x;
|
lastx = v.x;
|
||||||
@@ -317,16 +332,18 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class JumpButton extends ImageButton{
|
public static class JumpButton extends ImageButton{
|
||||||
|
Color hoverColor = Pal.place;
|
||||||
|
Color defaultColor = Color.white;
|
||||||
@NonNull Prov<StatementElem> to;
|
@NonNull Prov<StatementElem> to;
|
||||||
boolean selecting;
|
boolean selecting;
|
||||||
float mx, my;
|
float mx, my;
|
||||||
|
ClickListener listener;
|
||||||
|
|
||||||
public JumpButton(Color color, @NonNull Prov<StatementElem> getter, Cons<StatementElem> setter){
|
public JumpButton(@NonNull Prov<StatementElem> getter, Cons<StatementElem> setter){
|
||||||
super(Tex.logicNode, Styles.colori);
|
super(Tex.logicNode, Styles.colori);
|
||||||
|
|
||||||
to = getter;
|
to = getter;
|
||||||
|
addListener(listener = new ClickListener());
|
||||||
getStyle().imageUpColor = color;
|
|
||||||
|
|
||||||
addListener(new InputListener(){
|
addListener(new InputListener(){
|
||||||
@Override
|
@Override
|
||||||
@@ -362,6 +379,9 @@ public class LCanvas extends Table{
|
|||||||
if(to.get() != null && to.get().parent == null){
|
if(to.get() != null && to.get().parent == null){
|
||||||
setter.get(null);
|
setter.get(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setColor(listener.isOver() ? hoverColor : defaultColor);
|
||||||
|
getStyle().imageUpColor = this.color;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +389,7 @@ public class LCanvas extends Table{
|
|||||||
public void draw(){
|
public void draw(){
|
||||||
super.draw();
|
super.draw();
|
||||||
|
|
||||||
postDraw.add(() -> {
|
(listener.isOver() ? postDrawPriority : postDraw).add(() -> {
|
||||||
Element hover = to.get() == null && selecting ? hovered() : to.get();
|
Element hover = to.get() == null && selecting ? hovered() : to.get();
|
||||||
float tx = 0, ty = 0;
|
float tx = 0, ty = 0;
|
||||||
boolean draw = false;
|
boolean draw = false;
|
||||||
@@ -402,10 +422,12 @@ public class LCanvas extends Table{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(draw){
|
if(draw){
|
||||||
drawCurve(rx + width/2f, ry + height/2f, tx, ty, color);
|
drawCurve(rx + width/2f, ry + height/2f, tx, ty);
|
||||||
|
|
||||||
float s = width;
|
float s = width;
|
||||||
|
Draw.color(color);
|
||||||
Tex.logicNode.draw(tx + s*0.75f, ty - s/2f, -s, s);
|
Tex.logicNode.draw(tx + s*0.75f, ty - s/2f, -s, s);
|
||||||
|
Draw.reset();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -421,7 +443,7 @@ public class LCanvas extends Table{
|
|||||||
return (StatementElem)e;
|
return (StatementElem)e;
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawCurve(float x, float y, float x2, float y2, Color color){
|
void drawCurve(float x, float y, float x2, float y2){
|
||||||
Lines.stroke(4f, color);
|
Lines.stroke(4f, color);
|
||||||
Draw.alpha(parentAlpha);
|
Draw.alpha(parentAlpha);
|
||||||
|
|
||||||
@@ -434,8 +456,6 @@ public class LCanvas extends Table{
|
|||||||
x2, y2,
|
x2, y2,
|
||||||
Math.max(20, (int)(Mathf.dst(x, y, x2, y2) / 5))
|
Math.max(20, (int)(Mathf.dst(x, y, x2, y2) / 5))
|
||||||
);
|
);
|
||||||
|
|
||||||
Draw.reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package mindustry.logic;
|
package mindustry.logic;
|
||||||
|
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.graphics.*;
|
|
||||||
import arc.scene.style.*;
|
import arc.scene.style.*;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
@@ -655,7 +654,7 @@ public class LStatements{
|
|||||||
field(table, compare, str -> compare = str);
|
field(table, compare, str -> compare = str);
|
||||||
|
|
||||||
table.add().growX();
|
table.add().growX();
|
||||||
table.add(new JumpButton(Color.white, () -> dest, s -> dest = s)).size(30).right().padLeft(-8);
|
table.add(new JumpButton(() -> dest, s -> dest = s)).size(30).right().padLeft(-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
//elements need separate conversion logic
|
//elements need separate conversion logic
|
||||||
|
|||||||
Reference in New Issue
Block a user