|
107 | 107 | import java.util.OptionalInt; |
108 | 108 | import java.util.function.IntSupplier; |
109 | 109 | import java.util.function.ToIntBiFunction; |
| 110 | +import java.util.stream.Gatherers; |
110 | 111 | import java.util.stream.IntStream; |
111 | 112 | import java.util.stream.Stream; |
112 | 113 |
|
@@ -661,26 +662,21 @@ protected void drawDirectionArrow(GuiGraphicsExtractor guiGraphicsExtractor, int |
661 | 662 | } |
662 | 663 |
|
663 | 664 | private void createFeatureToggles() { |
664 | | - // TODO: replace with Gatherers API? |
665 | 665 | // TODO: only calculate on resize? |
666 | 666 | int rows = Math.ceilDiv(this.featureIconsCombinedWidth, this.seedMapWidth); |
667 | 667 | int togglesPerRow = Math.ceilDiv(this.toggleableFeatures.size(), rows); |
| 668 | + List<List<MapFeature>> toggleRows = this.toggleableFeatures.stream().gather(Gatherers.windowFixed(togglesPerRow)).toList(); |
| 669 | + |
668 | 670 | 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 | + } |
671 | 678 | toggleMinY += FEATURE_TOGGLE_HEIGHT + VERTICAL_FEATURE_TOGGLE_SPACING; |
672 | 679 | } |
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 | | - } |
684 | 680 | } |
685 | 681 |
|
686 | 682 | private int[] calculateBiomeData(TilePos tilePos) { |
|
0 commit comments