Skip to content

Commit

Permalink
SchematicBrowserDialog optimization for people with many schems
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Nov 10, 2024
1 parent dace346 commit 41e2042
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion core/src/mindustry/client/ui/SchematicBrowserDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import arc.graphics.gl.*;
import arc.math.*;
import arc.math.geom.*;
import arc.scene.*;
import arc.scene.actions.*;
import arc.scene.event.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
Expand Down Expand Up @@ -169,6 +171,7 @@ void buildTags() {
void buildResults() {
Table[] t = {null}; // Peak java
t[0] = new Table() {
/** Custom cullingArea fix, propagates the culling size of the ScrollPane to all children. */
@Override
public void setCullingArea(Rect cullingArea) {
super.setCullingArea(cullingArea);
Expand Down Expand Up @@ -201,7 +204,7 @@ void buildRepo(Table table, String repo, String nameSearchString, String descSea
table.row();
table.image().growX().padTop(10).height(3).color(Pal.accent).center();
table.row();
table.table(t -> {
table.add(new Table(t -> {
t.setCullingArea(new Rect()); // Make sure this isn't null for later

int[] i = {0};
Expand Down Expand Up @@ -288,6 +291,33 @@ public void draw() { // Update the name in the draw method as update() is called
t.add("@none").color(Color.lightGray);
}
}
}) {
/** Custom hit implementation that respects the cullingArea. Allows for significantly larger schem repos without lag */
@Override
public Element hit(float x, float y, boolean touchable) {
// if (cullingArea == null) return super.hit(x, y, touchable); // Fallback to vanilla behavior if cullingArea is null

float cullLeft = cullingArea.x;
float cullRight = cullLeft + cullingArea.width;
float cullBottom = cullingArea.y;
float cullTop = cullBottom + cullingArea.height;
if(x > cullRight || y > cullTop || x + getWidth() < cullLeft || y + getHeight() < cullBottom) return null; // Whole table is outside of culling bounds.

Vec2 point = Tmp.v5;
Element[] childrenArray = children.items;
for(int i = children.size - 1; i >= 0; i--){
Element child = childrenArray[i];
if(!child.visible || (child.x > cullRight || child.y > cullTop || child.x + child.getWidth() < cullLeft || child.y + child.getHeight() < cullBottom) && child.cullable) continue;
child.parentToLocalCoordinates(point.set(x, y));
Element hit = child.hit(point.x, point.y, touchable);
if(hit != null) return hit;
}

// Element.hit pasted (to check if the table was the thing hit)
if(touchable && this.touchable != Touchable.enabled) return null;
Element e = this;
return x >= e.translation.x && x < width + e.translation.x && y >= e.translation.y && y < height + e.translation.y ? this : null;
}
});
table.row();
}
Expand Down

0 comments on commit 41e2042

Please sign in to comment.