From 6cb3e3ed8abc6c8fd20dee471985788580dcd88b Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Sun, 8 Aug 2021 17:21:40 +0200 Subject: [PATCH] SlotElement Supplier as Ingredient --- .../invui/gui/builder/GUIBuilder.java | 7 ++++++- .../invui/gui/structure/Ingredient.java | 16 +++++++--------- .../invui/gui/structure/Structure.java | 17 +++++++++++++---- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java b/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java index 6dc0a1a..810c90e 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java @@ -68,11 +68,16 @@ public class GUIBuilder { return this; } - public GUIBuilder addIngredient(char key, @NotNull Supplier itemSupplier) { + public GUIBuilder addIngredient(char key, @NotNull Supplier itemSupplier) { structure.addIngredient(key, itemSupplier); return this; } + public GUIBuilder addIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { + structure.addIngredientElementSupplier(key, elementSupplier); + return this; + } + public GUIBuilder setItems(@NotNull List items) { if (guiType != PAGED_ITEMS && guiType != SCROLL) throw new UnsupportedOperationException("Items cannot be set in this gui type."); diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Ingredient.java b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Ingredient.java index 330e26d..60a682b 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Ingredient.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Ingredient.java @@ -1,8 +1,6 @@ package de.studiocode.invui.gui.structure; import de.studiocode.invui.gui.SlotElement; -import de.studiocode.invui.gui.SlotElement.ItemSlotElement; -import de.studiocode.invui.item.Item; import java.util.function.Supplier; @@ -10,16 +8,16 @@ class Ingredient { private final SlotElement slotElement; private final Marker marker; - private final Supplier itemSupplier; + private final Supplier elementSupplier; public Ingredient(SlotElement slotElement) { this.slotElement = slotElement; - this.itemSupplier = null; + this.elementSupplier = null; this.marker = null; } - public Ingredient(Supplier itemSupplier) { - this.itemSupplier = itemSupplier; + public Ingredient(Supplier elementSupplier) { + this.elementSupplier = elementSupplier; this.slotElement = null; this.marker = null; } @@ -27,11 +25,11 @@ class Ingredient { public Ingredient(Marker marker) { this.marker = marker; this.slotElement = null; - this.itemSupplier = null; + this.elementSupplier = null; } public SlotElement getSlotElement() { - return slotElement == null ? new ItemSlotElement(itemSupplier.get()) : slotElement; + return slotElement == null ? elementSupplier.get() : slotElement; } public Marker getMarker() { @@ -39,7 +37,7 @@ class Ingredient { } public boolean isSlotElement() { - return slotElement != null || itemSupplier != null; + return slotElement != null || elementSupplier != null; } public boolean isMarker() { diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java index 95184e2..74183ed 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java @@ -38,6 +38,10 @@ public class Structure { addGlobalIngredient(key, new ItemSlotElement(item)); } + public static void addGlobalIngredient(char key, @NotNull Supplier itemSupplier) { + addGlobalIngredientElementSupplier(key, () -> new ItemSlotElement(itemSupplier.get())); + } + public static void addGlobalIngredient(char key, @NotNull SlotElement element) { globalIngredientMap.put(key, new Ingredient(element)); } @@ -46,8 +50,8 @@ public class Structure { globalIngredientMap.put(key, new Ingredient(marker)); } - public static void addGlobalIngredient(char key, @NotNull Supplier itemSupplier) { - globalIngredientMap.put(key, new Ingredient(itemSupplier)); + public static void addGlobalIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { + globalIngredientMap.put(key, new Ingredient(elementSupplier)); } public Structure addIngredient(char key, @NotNull ItemProvider itemBuilder) { @@ -68,8 +72,13 @@ public class Structure { return this; } - public Structure addIngredient(char key, @NotNull Supplier itemSupplier) { - ingredientMap.put(key, new Ingredient(itemSupplier)); + public Structure addIngredient(char key, @NotNull Supplier itemSupplier) { + ingredientMap.put(key, new Ingredient(() -> new ItemSlotElement(itemSupplier.get()))); + return this; + } + + public Structure addIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { + ingredientMap.put(key, new Ingredient(elementSupplier)); return this; }