Skip to content

Commit

Permalink
Add slot index to FluidGrouBuilder#widgetCreator (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
tth05 authored Oct 14, 2023
1 parent d753255 commit 223f8d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

Expand Down Expand Up @@ -233,7 +234,7 @@ public static class FluidGroupBuilder {
private Boolean controlsAmount;
private IDrawable[] background;
private Function<IFluidTank, IFluidTanksHandler> tankHandlerCreator;
private Function<IFluidTanksHandler, FluidSlotWidget> widgetCreator;
private BiFunction<Integer, IFluidTanksHandler, FluidSlotWidget> widgetCreator;

private FluidGroupBuilder(List<IFluidTank> fluidTanks, int slotsPerRow) {
this.fluidTanks = fluidTanks;
Expand All @@ -257,7 +258,7 @@ public SlotGroup build() {
tankHandlerCreator = tank -> new FluidTanksHandler(new FluidTankLongDelegate(tank));
}
if (widgetCreator == null) {
widgetCreator = h -> new FluidSlotWidget(h, 0);
widgetCreator = (i, h) -> new FluidSlotWidget(h);
}

SlotGroup slotGroup = new SlotGroup();
Expand All @@ -266,7 +267,7 @@ public SlotGroup build() {
}
int x = 0, y = 0;
for (int i = startFromSlot; i < endAtSlot + 1; i++) {
FluidSlotWidget toAdd = widgetCreator.apply(tankHandlerCreator.apply(fluidTanks.get(i)));
FluidSlotWidget toAdd = widgetCreator.apply(i, tankHandlerCreator.apply(fluidTanks.get(i)));
toAdd.setPhantom(phantom);
toAdd.setControlsAmount(controlsAmount, false);
toAdd.setBackground(background).setPos(new Pos2d(x * 18, y * 18));
Expand Down Expand Up @@ -309,7 +310,7 @@ public FluidGroupBuilder tankHandlerCreator(Function<IFluidTank, IFluidTanksHand
return this;
}

public FluidGroupBuilder widgetCreator(Function<IFluidTanksHandler, FluidSlotWidget> widgetCreator) {
public FluidGroupBuilder widgetCreator(BiFunction<Integer, IFluidTanksHandler, FluidSlotWidget> widgetCreator) {
this.widgetCreator = widgetCreator;
return this;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/gtnewhorizons/modularui/test/TestTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,10 @@ private Widget createPage3() {
.setSynced(false, false).setPos(99, 85))
.addChild(
SlotGroup.ofFluidTanks(Collections.singletonList(fluidTank2), 1).controlsAmount(true)
.phantom(true).widgetCreator(h -> {
.phantom(true).widgetCreator((slotIndex, h) -> {
FluidSlotWidget widget = new FluidSlotWidget(h);
widget.dynamicTooltip(() -> Collections.singletonList("Dynamic tooltip"));
widget.dynamicTooltip(
() -> Collections.singletonList("Dynamic tooltip " + slotIndex));
return widget;
}).build().setPos(38, 47))
.addChild(new FluidSlotWidget(fluidTank1).setPos(20, 47))
Expand Down

0 comments on commit 223f8d3

Please sign in to comment.