Revert "Cullable LogicCanvas (#6699)"

This reverts commit 815a396fbd.
This commit is contained in:
Anuken
2022-04-23 11:33:06 -04:00
parent 12eb2dec4e
commit 7b496b610e

View File

@@ -20,7 +20,7 @@ import mindustry.logic.LStatements.*;
import mindustry.ui.*; import mindustry.ui.*;
public class LCanvas extends Table{ public class LCanvas extends Table{
public static final int maxJumpsDrawn = 1000; // TODO Does nothing public static final int maxJumpsDrawn = 100;
//ew static variables //ew static variables
static LCanvas canvas; static LCanvas canvas;
@@ -106,23 +106,14 @@ public class LCanvas extends Table{
clear(); clear();
statements = new DragLayout(); statements = new DragLayout();
jumps = new WidgetGroup(){ jumps = new WidgetGroup();
@Override
public void layout(){
cullable = false; //culling while scrolling results in weirdness
getChildren().each(h -> {
if(!(h instanceof JumpCurve c)) return;
c.setSize(width, c.getPrefHeight());
c.setPosition(c.button.x + c.button.getWidth()/2f, c.py);
});
cullable = true;
}
};
pane = pane(t -> { pane = pane(t -> {
t.center(); t.center();
t.add(statements).pad(2f).center().width(targetWidth); t.add(statements).pad(2f).center().width(targetWidth);
t.add(jumps).growY().width(100f).growY(); t.addChild(jumps);
jumps.cullable = false;
}).grow().get(); }).grow().get();
pane.setFlickScroll(false); pane.setFlickScroll(false);
@@ -169,7 +160,6 @@ public class LCanvas extends Table{
} }
this.statements.layout(); this.statements.layout();
jumps.layout();
} }
StatementElem checkHovered(){ StatementElem checkHovered(){
@@ -197,17 +187,21 @@ public class LCanvas extends Table{
pane.setScrollY(pane.getScrollY() + sign * Scl.scl(15f) * Time.delta); pane.setScrollY(pane.getScrollY() + sign * Scl.scl(15f) * Time.delta);
} }
} }
pane.scrolled(f -> jumps.layout()); //don't ask why this is needed, it just is
} }
public class DragLayout extends WidgetGroup{ public class DragLayout extends WidgetGroup{
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;
boolean invalidated;
{
setTransform(true);
}
@Override @Override
public void layout(){ public void layout(){
invalidated = true;
float cy = 0; float cy = 0;
seq.clear(); seq.clear();
@@ -255,9 +249,10 @@ public class LCanvas extends Table{
} }
} }
if(parent instanceof Table){ invalidateHierarchy();
if(parent != null && parent instanceof Table){
setCullingArea(parent.getCullingArea()); setCullingArea(parent.getCullingArea());
jumps.setCullingArea(parent.getCullingArea());
} }
} }
@@ -284,7 +279,16 @@ public class LCanvas extends Table{
Tex.pane.draw(lastX, lastY - shiftAmount, width, dragging.getHeight()); Tex.pane.draw(lastX, lastY - shiftAmount, width, dragging.getHeight());
} }
if(invalidated){
children.each(c -> c.cullable = false);
}
super.draw(); super.draw();
if(invalidated){
children.each(c -> c.cullable = true);
invalidated = false;
}
} }
void finishLayout(){ void finishLayout(){
@@ -509,17 +513,11 @@ public class LCanvas extends Table{
public static class JumpCurve extends Element{ public static class JumpCurve extends Element{
public JumpButton button; public JumpButton button;
float ph, py;
public JumpCurve(JumpButton button){ public JumpCurve(JumpButton button){
this.button = button; this.button = button;
} }
@Override
public float getPrefHeight(){
return ph;
}
@Override @Override
public void act(float delta){ public void act(float delta){
super.act(delta); super.act(delta);
@@ -538,6 +536,7 @@ public class LCanvas extends Table{
} }
Element hover = button.to.get() == null && button.selecting ? canvas.hovered : button.to.get(); Element hover = button.to.get() == null && button.selecting ? canvas.hovered : button.to.get();
boolean draw = false;
Vec2 t = Tmp.v1, r = Tmp.v2; Vec2 t = Tmp.v1, r = Tmp.v2;
Group desc = canvas.pane; Group desc = canvas.pane;
@@ -546,25 +545,26 @@ public class LCanvas extends Table{
if(hover != null){ if(hover != null){
hover.localToAscendantCoordinates(desc, t.set(hover.getWidth(), hover.getHeight()/2f)); hover.localToAscendantCoordinates(desc, t.set(hover.getWidth(), hover.getHeight()/2f));
draw = true;
}else if(button.selecting){ }else if(button.selecting){
t.set(r).add(button.mx, button.my); t.set(r).add(button.mx, button.my);
}else{ draw = true;
return;
} }
ph = Math.abs(t.y - r.y);
py = Math.min(t.y, r.y);
float offset = canvas.pane.getVisualScrollY() - canvas.pane.getMaxY(); float offset = canvas.pane.getVisualScrollY() - canvas.pane.getMaxY();
t.y += offset; t.y += offset;
r.y += offset; r.y += offset;
drawCurve(r.x + button.getWidth()/2f, r.y + button.getHeight()/2f, t.x, t.y); if(draw){
drawCurve(r.x + button.getWidth()/2f, r.y + button.getHeight()/2f, t.x, t.y);
float s = button.getWidth(); float s = button.getWidth();
Draw.color(button.color); Draw.color(button.color);
Tex.logicNode.draw(t.x + s*0.75f, t.y - s/2f, -s, s); Tex.logicNode.draw(t.x + s*0.75f, t.y - s/2f, -s, s);
Draw.reset(); Draw.reset();
}
} }
public void drawCurve(float x, float y, float x2, float y2){ public void drawCurve(float x, float y, float x2, float y2){