Skip to content

Commit 1d9a75a

Browse files
committed
Use Gatherers API for feature toggles
1 parent 24406ca commit 1d9a75a

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import java.util.OptionalInt;
108108
import java.util.function.IntSupplier;
109109
import java.util.function.ToIntBiFunction;
110+
import java.util.stream.Gatherers;
110111
import java.util.stream.IntStream;
111112
import java.util.stream.Stream;
112113

@@ -661,26 +662,21 @@ protected void drawDirectionArrow(GuiGraphicsExtractor guiGraphicsExtractor, int
661662
}
662663

663664
private void createFeatureToggles() {
664-
// TODO: replace with Gatherers API?
665665
// TODO: only calculate on resize?
666666
int rows = Math.ceilDiv(this.featureIconsCombinedWidth, this.seedMapWidth);
667667
int togglesPerRow = Math.ceilDiv(this.toggleableFeatures.size(), rows);
668+
List<List<MapFeature>> toggleRows = this.toggleableFeatures.stream().gather(Gatherers.windowFixed(togglesPerRow)).toList();
669+
668670
int toggleMinY = 1;
669-
for (int row = 0; row < rows - 1; row++) {
670-
this.createFeatureTogglesInner(row, togglesPerRow, togglesPerRow, this.horizontalPadding(), toggleMinY);
671+
for (List<MapFeature> rowToggles : toggleRows) {
672+
int toggleMinX = this.horizontalPadding();
673+
for (MapFeature feature : rowToggles) {
674+
MapFeature.Texture featureIcon = feature.getDefaultTexture();
675+
this.addRenderableWidget(new FeatureToggleWidget(feature, toggleMinX, toggleMinY));
676+
toggleMinX += featureIcon.width() + HORIZONTAL_FEATURE_TOGGLE_SPACING;
677+
}
671678
toggleMinY += FEATURE_TOGGLE_HEIGHT + VERTICAL_FEATURE_TOGGLE_SPACING;
672679
}
673-
int togglesInLastRow = this.toggleableFeatures.size() - togglesPerRow * (rows - 1);
674-
this.createFeatureTogglesInner(rows - 1, togglesPerRow, togglesInLastRow, this.horizontalPadding(), toggleMinY);
675-
}
676-
677-
private void createFeatureTogglesInner(int row, int togglesPerRow, int maxToggles, int toggleMinX, int toggleMinY) {
678-
for (int toggle = 0; toggle < maxToggles; toggle++) {
679-
MapFeature feature = this.toggleableFeatures.get(row * togglesPerRow + toggle);
680-
MapFeature.Texture featureIcon = feature.getDefaultTexture();
681-
this.addRenderableWidget(new FeatureToggleWidget(feature, toggleMinX, toggleMinY));
682-
toggleMinX += featureIcon.width() + HORIZONTAL_FEATURE_TOGGLE_SPACING;
683-
}
684680
}
685681

686682
private int[] calculateBiomeData(TilePos tilePos) {

0 commit comments

Comments
 (0)