Skip to content

Commit 8b30d6c

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 01be8ca commit 8b30d6c

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
@@ -217,13 +217,14 @@ public RecipeMap(@NotNull String unlocalizedName, @NotNull R defaultRecipeBuilde
217217
@NotNull RecipeMapUIFunction recipeMapUI, int maxInputs, int maxOutputs, int maxFluidInputs,
218218
int maxFluidOutputs) {
219219
this.unlocalizedName = unlocalizedName;
220-
this.recipeMapUI = recipeMapUI.apply(this);
221220

222221
this.maxInputs = maxInputs;
223222
this.maxFluidInputs = maxFluidInputs;
224223
this.maxOutputs = maxOutputs;
225224
this.maxFluidOutputs = maxFluidOutputs;
226225

226+
this.recipeMapUI = recipeMapUI.apply(this);
227+
227228
defaultRecipeBuilder.setRecipeMap(this);
228229
defaultRecipeBuilder
229230
.category(GTRecipeCategory.create(GTValues.MODID, unlocalizedName, getTranslationKey(), this));

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;
@@ -39,6 +38,7 @@
3938
import net.minecraft.init.SoundEvents;
4039
import net.minecraft.item.ItemStack;
4140

41+
import com.cleanroommc.modularui.api.drawable.IDrawable;
4242
import com.cleanroommc.modularui.widgets.ProgressWidget.Direction;
4343
import crafttweaker.annotations.ZenRegister;
4444
import stanhebben.zenscript.annotations.ZenClass;
@@ -337,16 +337,14 @@ public final class RecipeMaps {
337337
@ZenProperty
338338
public static final RecipeMap<SimpleRecipeBuilder> CANNER_RECIPES = new RecipeMapFluidCanner("canner",
339339
new SimpleRecipeBuilder(), recipeMap -> {
340-
341340
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
342-
// todo update canner to mui2
343-
ui.setItemSlotOverlay(GuiTextures.CANNER_OVERLAY, false, false);
344-
ui.setItemSlotOverlay(GuiTextures.CANISTER_OVERLAY, false, true);
345-
ui.setItemSlotOverlay(GuiTextures.CANISTER_OVERLAY, true);
346-
ui.setFluidSlotOverlay(GuiTextures.DARK_CANISTER_OVERLAY, false);
347-
ui.setFluidSlotOverlay(GuiTextures.DARK_CANISTER_OVERLAY, true);
348-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_CANNER, ProgressWidget.MoveType.HORIZONTAL);
349-
return ui;
341+
return ui.buildMui2(b -> b
342+
.itemSlotOverlay(GTGuiTextures.CANNER_OVERLAY, false, false)
343+
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, false, true)
344+
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, true)
345+
.fluidSlotOverlay(GTGuiTextures.DARK_CANISTER_OVERLAY, false)
346+
.fluidSlotOverlay(GTGuiTextures.DARK_CANISTER_OVERLAY, true)
347+
.progressBar(GTGuiTextures.PROGRESS_BAR_CANNER, Direction.RIGHT));
350348
});
351349

352350
/**
@@ -378,7 +376,7 @@ public final class RecipeMaps {
378376
.uiBuilder(b -> b
379377
.itemSlotOverlay(GTGuiTextures.EXTRACTOR_OVERLAY, false, false)
380378
.itemSlotOverlay(GTGuiTextures.CANISTER_OVERLAY, false, true)
381-
.fluidSlotOverlay(GTGuiTextures.CENTRIFUGE_OVERLAY, false, true)
379+
.fluidSlotOverlay(GTGuiTextures.CENTRIFUGE_OVERLAY, false)
382380
.progressBar(GTGuiTextures.PROGRESS_BAR_EXTRACT))
383381
.sound(GTSoundEvents.CENTRIFUGE)
384382
.build();
@@ -443,8 +441,8 @@ public final class RecipeMaps {
443441
.itemSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_1, false, false)
444442
.itemSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_2, false, true)
445443
.itemSlotOverlay(GTGuiTextures.VIAL_OVERLAY_1, true)
446-
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_3, false, false)
447-
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_4, false, true)
444+
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_3, false)
445+
.fluidSlotOverlay(GTGuiTextures.MOLECULAR_OVERLAY_4, false)
448446
.fluidSlotOverlay(GTGuiTextures.VIAL_OVERLAY_2, true)
449447
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW_MULTIPLE))
450448
.sound(GTValues.FOOLS.get() ? GTSoundEvents.SCIENCE : GTSoundEvents.CHEMICAL_REACTOR)
@@ -937,8 +935,17 @@ public final class RecipeMaps {
937935
*/
938936
@ZenProperty
939937
public static final RecipeMap<SimpleRecipeBuilder> FORMING_PRESS_RECIPES = new RecipeMapFormingPress(
940-
"forming_press", new SimpleRecipeBuilder(), FormingPressUI::new);
941-
// todo update forming press to mui2
938+
"forming_press", new SimpleRecipeBuilder(), recipeMap -> new FormingPressUI<>(recipeMap)
939+
.buildMui2(b -> {
940+
IDrawable[] overlays = { GTGuiTextures.PRESS_OVERLAY_2, GTGuiTextures.PRESS_OVERLAY_4,
941+
GTGuiTextures.PRESS_OVERLAY_1 };
942+
for (int i = 0; i < 3; i++) {
943+
b.itemSlotOverlay(overlays[i], i, false);
944+
b.itemSlotOverlay(overlays[i], i + 3, false);
945+
}
946+
b.itemSlotOverlay(GTGuiTextures.PRESS_OVERLAY_3, true);
947+
b.progressBar(GTGuiTextures.PROGRESS_BAR_COMPRESS, Direction.RIGHT);
948+
}));
942949

943950
/**
944951
*
@@ -964,11 +971,10 @@ public final class RecipeMaps {
964971
public static final RecipeMap<SimpleRecipeBuilder> FURNACE_RECIPES = new RecipeMapFurnace("electric_furnace",
965972
new SimpleRecipeBuilder(), recipeMap -> {
966973
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
967-
ui.setItemSlotOverlay(GuiTextures.FURNACE_OVERLAY_1, false);
968-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);
969-
return ui;
974+
return ui.buildMui2(b -> b
975+
.itemSlotOverlay(GTGuiTextures.FURNACE_OVERLAY_1, false)
976+
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW, Direction.RIGHT));
970977
});
971-
// todo update electric furnace to mui2
972978

973979
/**
974980
* Example:
@@ -1189,7 +1195,7 @@ public final class RecipeMaps {
11891195
.itemSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_1, false)
11901196
.fluidSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_2, false)
11911197
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, true)
1192-
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, true, true)
1198+
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, true)
11931199
.progressBar(GTGuiTextures.PROGRESS_BAR_MASS_FAB))
11941200
.sound(GTSoundEvents.REPLICATOR)
11951201
.build();
@@ -1366,7 +1372,7 @@ public final class RecipeMaps {
13661372
.itemSlotOverlay(GTGuiTextures.DATA_ORB_OVERLAY, false)
13671373
.itemSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_1, true)
13681374
.fluidSlotOverlay(GTGuiTextures.NEUTRAL_MATTER_OVERLAY, false)
1369-
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, false, true)
1375+
.fluidSlotOverlay(GTGuiTextures.POSITIVE_MATTER_OVERLAY, false)
13701376
.fluidSlotOverlay(GTGuiTextures.ATOMIC_OVERLAY_2, true)
13711377
.progressBar(GTGuiTextures.PROGRESS_BAR_REPLICATOR))
13721378
.sound(GTSoundEvents.REPLICATOR)
@@ -1405,12 +1411,11 @@ public final class RecipeMaps {
14051411
public static final RecipeMap<SimpleRecipeBuilder> SCANNER_RECIPES = new RecipeMapScanner("scanner",
14061412
new SimpleRecipeBuilder(), recipeMap -> {
14071413
RecipeMapUI<?> ui = new RecipeMapUI<>(recipeMap, true, true, true, true, false);
1408-
ui.setItemSlotOverlay(GuiTextures.DATA_ORB_OVERLAY, false, false);
1409-
ui.setItemSlotOverlay(GuiTextures.SCANNER_OVERLAY, false, true);
1410-
ui.setProgressBar(GuiTextures.PROGRESS_BAR_ARROW, ProgressWidget.MoveType.HORIZONTAL);
1411-
return ui;
1414+
return ui.buildMui2(b -> b
1415+
.itemSlotOverlay(GTGuiTextures.DATA_ORB_OVERLAY, false, false)
1416+
.itemSlotOverlay(GTGuiTextures.SCANNER_OVERLAY, false, true)
1417+
.progressBar(GTGuiTextures.PROGRESS_BAR_ARROW, Direction.RIGHT));
14121418
});
1413-
// todo update scanner to mui2
14141419

14151420
/**
14161421
* 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)