Skip to content

Commit 80a721c

Browse files
committed
rework slot overlay methods
set max inputs before ui build split overlay maps into Int2Obj maps pull pos out of make slot methods
1 parent 9fe269c commit 80a721c

4 files changed

Lines changed: 148 additions & 72 deletions

File tree

src/main/java/gregtech/api/recipes/RecipeMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public RecipeMap(@NotNull String unlocalizedName, @NotNull R defaultRecipeBuilde
145145
@NotNull RecipeMapUIFunction recipeMapUI, int maxInputs, int maxOutputs, int maxFluidInputs,
146146
int maxFluidOutputs) {
147147
this.unlocalizedName = unlocalizedName;
148-
this.recipeMapUI = recipeMapUI.apply(this);
149148

150149
this.maxInputs = maxInputs;
151150
this.maxFluidInputs = maxFluidInputs;
@@ -154,6 +153,8 @@ public RecipeMap(@NotNull String unlocalizedName, @NotNull R defaultRecipeBuilde
154153
this.primaryRecipeCategory = GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(),
155154
this);
156155

156+
this.recipeMapUI = recipeMapUI.apply(this);
157+
157158
defaultRecipeBuilder.setRecipeMap(this);
158159
defaultRecipeBuilder.category(primaryRecipeCategory);
159160
this.recipeBuilderSample = defaultRecipeBuilder;

src/main/java/gregtech/api/recipes/RecipeMaps.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import gregtech.api.GTValues;
44
import gregtech.api.gui.GuiTextures;
5-
import gregtech.api.gui.widgets.ProgressWidget;
65
import gregtech.api.mui.GTGuiTextures;
76
import gregtech.api.recipes.builders.AssemblerRecipeBuilder;
87
import gregtech.api.recipes.builders.AssemblyLineRecipeBuilder;
@@ -36,6 +35,7 @@
3635

3736
import net.minecraft.init.SoundEvents;
3837

38+
import com.cleanroommc.modularui.api.drawable.IDrawable;
3939
import com.cleanroommc.modularui.widgets.ProgressWidget.Direction;
4040
import crafttweaker.annotations.ZenRegister;
4141
import stanhebben.zenscript.annotations.ZenClass;
@@ -323,16 +323,14 @@ public final class RecipeMaps {
323323
@ZenProperty
324324
public static final RecipeMap<SimpleRecipeBuilder> CANNER_RECIPES = new RecipeMapFluidCanner("canner",
325325
new SimpleRecipeBuilder(), recipeMap -> {
326-
327326
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
328-
// todo update canner to mui2
329-
ui.setItemSlotOverlay(GuiTextures.CANNER_OVERLAY, false, false);
330-
ui.setItemSlotOverlay(GuiTextures.CANISTER_OVERLAY, false, true);
331-
ui.setItemSlotOverlay(GuiTextures.CANISTER_OVERLAY, true);
332-
ui.setFluidSlotOverlay(GuiTextures.DARK_CANISTER_OVERLAY, false);
333-
ui.setFluidSlotOverlay(GuiTextures.DARK_CANISTER_OVERLAY, true);
334-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_CANNER, ProgressWidget.MoveType.HORIZONTAL);
335-
return ui;
327+
return ui.buildMui2(b -> b
328+
.itemSlotOverlay(GTGuiTextures.CANNER_OVERLAY, false, false)
329+
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, false, true)
330+
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, true)
331+
.fluidSlotOverlay(GTGuiTextures.DARK_CANISTER_OVERLAY, false)
332+
.fluidSlotOverlay(GTGuiTextures.DARK_CANISTER_OVERLAY, true)
333+
.progressBar(GTGuiTextures.PROGRESS_BAR_CANNER, Direction.RIGHT));
336334
});
337335

338336
/**
@@ -364,7 +362,7 @@ public final class RecipeMaps {
364362
.uiBuilder(b -> b
365363
.itemSlotOverlay(GTGuiTextures.EXTRACTOR_OVERLAY, false, false)
366364
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, false, true)
367-
.fluidSlotOverlay(GTGuiTextures.CENTRIFUGE_OVERLAY, false, true)
365+
.fluidSlotOverlay(GTGuiTextures.CENTRIFUGE_OVERLAY, false)
368366
.progressBar(GTGuiTextures.PROGRESS_BAR_EXTRACT))
369367
.sound(GTSoundEvents.CENTRIFUGE)
370368
.build();
@@ -429,8 +427,8 @@ public final class RecipeMaps {
429427
.itemSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_1, false, false)
430428
.itemSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_2, false, true)
431429
.itemSlotOverlay(GTGuiTextures.VIAL_OVERLAY_1, true)
432-
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_3, false, false)
433-
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_4, false, true)
430+
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_3, false)
431+
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_4, false)
434432
.fluidSlotOverlay(GTGuiTextures.VIAL_OVERLAY_2, true)
435433
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW_MULTIPLE))
436434
.sound(GTValues.FOOLS.get() ? GTSoundEvents.SCIENCE : GTSoundEvents.CHEMICAL_REACTOR)
@@ -923,8 +921,17 @@ public final class RecipeMaps {
923921
*/
924922
@ZenProperty
925923
public static final RecipeMap<SimpleRecipeBuilder> FORMING_PRESS_RECIPES = new RecipeMapFormingPress(
926-
"forming_press", new SimpleRecipeBuilder(), FormingPressUI::new);
927-
// todo update forming press to mui2
924+
"forming_press", new SimpleRecipeBuilder(), recipeMap -> new FormingPressUI<>(recipeMap)
925+
.buildMui2(b -> {
926+
IDrawable[] overlays = { GTGuiTextures.PRESS_OVERLAY_2, GTGuiTextures.PRESS_OVERLAY_4,
927+
GTGuiTextures.PRESS_OVERLAY_1 };
928+
for (int i = 0; i < 3; i++) {
929+
b.itemSlotOverlay(overlays[i], i, false);
930+
b.itemSlotOverlay(overlays[i], i + 3, false);
931+
}
932+
b.itemSlotOverlay(GTGuiTextures.PRESS_OVERLAY_3, true);
933+
b.progressBar(GTGuiTextures.PROGRESS_BAR_COMPRESS, Direction.RIGHT);
934+
}));
928935

929936
/**
930937
*
@@ -950,11 +957,10 @@ public final class RecipeMaps {
950957
public static final RecipeMap<SimpleRecipeBuilder> FURNACE_RECIPES = new RecipeMapFurnace("electric_furnace",
951958
new SimpleRecipeBuilder(), recipeMap -> {
952959
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
953-
ui.setItemSlotOverlay(GuiTextures.FURNACE_OVERLAY_1, false);
954-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);
955-
return ui;
960+
return ui.buildMui2(b -> b
961+
.itemSlotOverlay(GTGuiTextures.FURNACE_OVERLAY_1, false)
962+
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW, Direction.RIGHT));
956963
});
957-
// todo update electric furnace to mui2
958964

959965
/**
960966
* Example:
@@ -1175,7 +1181,7 @@ public final class RecipeMaps {
11751181
.itemSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_1, false)
11761182
.fluidSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_2, false)
11771183
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, true)
1178-
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, true, true)
1184+
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, true)
11791185
.progressBar(GTGuiTextures.PROGRESS_BAR_MASS_FAB))
11801186
.sound(GTSoundEvents.REPLICATOR)
11811187
.build();
@@ -1352,7 +1358,7 @@ public final class RecipeMaps {
13521358
.itemSlotOverlay(GTGuiTextures.DATA_ORB_OVERLAY, false)
13531359
.itemSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_1, true)
13541360
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, false)
1355-
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, false, true)
1361+
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, false)
13561362
.fluidSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_2, true)
13571363
.progressBar(GTGuiTextures.PROGRESS_BAR_REPLICATOR))
13581364
.sound(GTSoundEvents.REPLICATOR)
@@ -1391,12 +1397,11 @@ public final class RecipeMaps {
13911397
public static final RecipeMap<SimpleRecipeBuilder> SCANNER_RECIPES = new RecipeMapScanner("scanner",
13921398
new SimpleRecipeBuilder(), recipeMap -> {
13931399
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
1394-
ui.setItemSlotOverlay(GuiTextures.DATA_ORB_OVERLAY, false, false);
1395-
ui.setItemSlotOverlay(GuiTextures.SCANNER_OVERLAY, false, true);
1396-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);
1397-
return ui;
1400+
return ui.buildMui2(b -> b
1401+
.itemSlotOverlay(GTGuiTextures.DATA_ORB_OVERLAY, false, false)
1402+
.itemSlotOverlay(GTGuiTextures.SCANNER_OVERLAY, false, true)
1403+
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW, Direction.RIGHT));
13981404
});
1399-
// todo update scanner to mui2
14001405

14011406
/**
14021407
* Example:

src/main/java/gregtech/api/recipes/ui/RecipeMapUI.java

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
2727
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
2828
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
29+
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
30+
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
2931
import org.jetbrains.annotations.ApiStatus;
3032
import org.jetbrains.annotations.Contract;
3133
import org.jetbrains.annotations.NotNull;
3234
import org.jetbrains.annotations.Nullable;
3335

36+
import java.util.function.Consumer;
3437
import java.util.function.DoubleSupplier;
3538

3639
@ApiStatus.Experimental
@@ -62,14 +65,17 @@ public class RecipeMapUI<R extends RecipeMap<?>> {
6265
/* *********************** MUI 2 *********************** */
6366

6467
// todo try to store this better
65-
private final Byte2ObjectMap<UITexture> slotTextureOverlays = new Byte2ObjectOpenHashMap<>();
68+
private final Int2ObjectMap<IDrawable> itemInputOverlays = new Int2ObjectOpenHashMap<>();
69+
private final Int2ObjectMap<IDrawable> itemOutputOverlays = new Int2ObjectOpenHashMap<>();
70+
private final Int2ObjectMap<IDrawable> fluidInputOverlays = new Int2ObjectOpenHashMap<>();
71+
private final Int2ObjectMap<IDrawable> fluidOutputOverlays = new Int2ObjectOpenHashMap<>();
6672

6773
@ApiStatus.Experimental
6874
private boolean usesMui2 = false;
6975
private UITexture progressTexture = GTGuiTextures.PROGRESS_BAR_ARROW;
7076
private ProgressWidget.Direction progressDirection = ProgressWidget.Direction.RIGHT;
7177
// todo sus name
72-
private @Nullable UITexture specialTextureNew;
78+
private @Nullable IDrawable specialTextureNew;
7379

7480
/**
7581
* @param recipeMap the recipemap corresponding to this ui
@@ -571,9 +577,11 @@ protected void addInventorySlotGroup(@NotNull ParentWidget<?> group,
571577
int x = startInputsX + 18 * j;
572578
int y = startInputsY + 18 * i;
573579
if (invertFluids) {
574-
group.child(makeFluidSlot(x, y, slotIndex, fluidHandler, isOutputs));
580+
group.child(makeFluidSlot(slotIndex, fluidHandler, isOutputs)
581+
.pos(x, y));
575582
} else {
576-
group.child(makeItemSlot(slotGroup, x, y, slotIndex, itemHandler, isOutputs));
583+
group.child(makeItemSlot(slotGroup, slotIndex, itemHandler, isOutputs)
584+
.pos(x, y));
577585
}
578586
}
579587
}
@@ -584,9 +592,11 @@ protected void addInventorySlotGroup(@NotNull ParentWidget<?> group,
584592
for (int i = 0; i < fluidInputsCount; i++) {
585593
int y = startInputsY + 18 * i;
586594
if (!invertFluids) {
587-
group.child(makeFluidSlot(startSpecX, y, i, fluidHandler, isOutputs));
595+
group.child(makeFluidSlot(i, fluidHandler, isOutputs)
596+
.pos(startSpecX, y));
588597
} else {
589-
group.child(makeItemSlot(slotGroup, startSpecX, y, i, itemHandler, isOutputs));
598+
group.child(makeItemSlot(slotGroup, i, itemHandler, isOutputs)
599+
.pos(startSpecX, y));
590600
}
591601
}
592602
} else {
@@ -596,44 +606,49 @@ protected void addInventorySlotGroup(@NotNull ParentWidget<?> group,
596606
startInputsX + itemSlotsToLeft * 18 - 18 - 18 * (i % 3);
597607
int y = startSpecY + (i / 3) * 18;
598608
if (!invertFluids) {
599-
group.child(makeFluidSlot(x, y, i, fluidHandler, isOutputs));
609+
group.child(makeFluidSlot(i, fluidHandler, isOutputs)
610+
.pos(x, y));
600611
} else {
601-
group.child(makeItemSlot(slotGroup, x, y, i, itemHandler, isOutputs));
612+
group.child(makeItemSlot(slotGroup, i, itemHandler, isOutputs)
613+
.pos(x, y));
602614
}
603615
}
604616
}
605617
}
606618
}
607619

608-
protected ItemSlot makeItemSlot(SlotGroup group, int x, int y, int slotIndex, IItemHandlerModifiable itemHandler,
620+
protected ItemSlot makeItemSlot(SlotGroup group, int slotIndex, IItemHandlerModifiable itemHandler,
609621
boolean isOutputs) {
610622
return new ItemSlot()
611623
.slot(SyncHandlers.itemSlot(itemHandler, slotIndex)
612624
.slotGroup(group)
613625
.accessibility(!isOutputs, true))
614-
.pos(x, y)
615-
.background(getOverlaysForSlotNew(isOutputs, false, slotIndex == itemHandler.getSlots() - 1));
626+
.background(getOverlaysForSlotNew(isOutputs, false, slotIndex));
616627
}
617628

618-
protected GTFluidSlot makeFluidSlot(int x, int y, int slotIndex, FluidTankList fluidHandler, boolean isOutputs) {
629+
protected GTFluidSlot makeFluidSlot(int slotIndex, FluidTankList fluidHandler, boolean isOutputs) {
619630
return new GTFluidSlot()
620631
.syncHandler(GTFluidSlot.sync(fluidHandler.getTankAt(slotIndex))
621632
.accessibility(true, !isOutputs))
622633
// todo show always full, should be implemented with mui2 multis
623-
.pos(x, y)
624-
.background(getOverlaysForSlotNew(isOutputs, true, slotIndex == fluidHandler.getTanks() - 1));
634+
.background(getOverlaysForSlotNew(isOutputs, true, slotIndex));
625635
}
626636

627637
@ApiStatus.Experimental
628-
protected IDrawable getOverlaysForSlotNew(boolean isOutput, boolean isFluid, boolean isLast) {
638+
protected IDrawable getOverlaysForSlotNew(boolean isOutput, boolean isFluid, int index) {
629639
UITexture base = isFluid ? GTGuiTextures.FLUID_SLOT : GTGuiTextures.SLOT;
630-
byte overlayKey = computeOverlayKey(isOutput, isFluid, isLast);
631-
if (slotTextureOverlays.containsKey(overlayKey)) {
632-
return IDrawable.of(base, slotTextureOverlays.get(overlayKey));
640+
var overlays = getOverlayMap(isOutput, isFluid);
641+
if (overlays.containsKey(index)) {
642+
return IDrawable.of(base, overlays.get(index));
633643
}
634644
return IDrawable.of(base);
635645
}
636646

647+
protected Int2ObjectMap<IDrawable> getOverlayMap(boolean isOutput, boolean isFluid) {
648+
if (isOutput) return isFluid ? fluidOutputOverlays : itemOutputOverlays;
649+
else return isFluid ? fluidInputOverlays : itemInputOverlays;
650+
}
651+
637652
/** Marked experimental as this method will be removed when all GTCEu UIs are ported to MUI2. */
638653
@ApiStatus.Experimental
639654
@ApiStatus.Internal
@@ -647,6 +662,14 @@ public boolean usesMui2() {
647662
return usesMui2;
648663
}
649664

665+
// todo this is a quick and dirty method, find a better way
666+
/** Marked experimental as this method will be removed when all GTCEu UIs are ported to MUI2. */
667+
@ApiStatus.Experimental
668+
public RecipeMapUI<R> buildMui2(Consumer<RecipeMapUIBuilder> builderConsumer) {
669+
builderConsumer.accept(new RecipeMapUIBuilder(this));
670+
return this;
671+
}
672+
650673
/**
651674
* @param progressTexture the new progress bar texture
652675
*/
@@ -665,18 +688,20 @@ public void setProgressBarDirection(@NotNull ProgressWidget.Direction direction)
665688
* @param specialTexture the special texture to set
666689
* @param position the position of the texture: [x, y, width, height]
667690
*/
668-
public void setSpecialTexture(@NotNull UITexture specialTexture, @NotNull Area position) {
691+
public void setSpecialTexture(@NotNull IDrawable specialTexture, @NotNull Area position) {
669692
this.specialTextureNew = specialTexture;
670693
this.specialTexturePosition = position;
671694
}
672695

673696
/**
674-
* @param key the key to store the slot's texture with
675-
* @param texture the texture to store
697+
* @param texture the texture to store
698+
* @param index the key to store the slot's texture with
699+
* @param isFluid if the slot is fluid
700+
* @param isOutput if the slot is an output
676701
*/
677702
@ApiStatus.Internal
678-
public void setSlotOverlay(byte key, @NotNull UITexture texture) {
679-
this.slotTextureOverlays.put(key, texture);
703+
public void setSlotOverlay(@NotNull IDrawable texture, int index, boolean isFluid, boolean isOutput) {
704+
getOverlayMap(isOutput, isFluid).put(index, texture);
680705
}
681706

682707
/**

0 commit comments

Comments
 (0)