From 3a86e9d2ba89466f7f9ef51c29eb5879bcb8a98e Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 17 Nov 2022 17:18:19 +0000 Subject: 22w46a --- src/main/java/dev/isxander/yacl/gui/AbstractWidget.java | 2 +- src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java | 4 ++-- .../java/dev/isxander/yacl/gui/LowProfileButtonWidget.java | 10 ++++++---- src/main/java/dev/isxander/yacl/gui/OptionListWidget.java | 6 +++--- src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java | 2 +- .../java/dev/isxander/yacl/gui/TextScaledButtonWidget.java | 11 ++++++----- src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java | 4 ++-- src/main/java/dev/isxander/yacl/gui/YACLScreen.java | 9 ++++----- 8 files changed, 25 insertions(+), 23 deletions(-) (limited to 'src/main/java/dev') diff --git a/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java index 03dc9b9..bede0ae 100644 --- a/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java @@ -82,7 +82,7 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { int width = x2 - x1; int height = y2 - y1; - RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.setShader(GameRenderer::getPositionTexProgram); RenderSystem.setShaderTexture(0, ClickableWidget.WIDGETS_TEXTURE); RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); int i = !enabled ? 0 : hovered ? 2 : 1; diff --git a/src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java b/src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java index 2cb6bb6..46a9fdf 100644 --- a/src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java @@ -15,7 +15,7 @@ public class CategoryListWidget extends ElementListWidget widget.render(matrices, mouseX, mouseY, tickDelta); if (resetButton != null) { - resetButton.y = y; + resetButton.setY(y); resetButton.render(matrices, mouseX, mouseY, tickDelta); } } @@ -402,8 +402,8 @@ public class OptionListWidget extends ElementListWidget public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { this.y = y; - expandMinimizeButton.x = x; - expandMinimizeButton.y = y + entryHeight / 2 - expandMinimizeButton.getHeight() / 2; + expandMinimizeButton.setX(x); + expandMinimizeButton.setY(y + entryHeight / 2 - expandMinimizeButton.getHeight() / 2); expandMinimizeButton.render(matrices, mouseX, mouseY, tickDelta); wrappedName.drawCenterWithShadow(matrices, x + entryWidth / 2, y + getYPadding()); diff --git a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java index 6184405..5b7c9dc 100644 --- a/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java @@ -25,7 +25,7 @@ public class SearchFieldWidget extends TextFieldWidget { public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { super.renderButton(matrices, mouseX, mouseY, delta); if (isVisible() && isEmpty()) { - textRenderer.drawWithShadow(matrices, emptyText, x + 4, this.y + (this.height - 8) / 2f, 0x707070); + textRenderer.drawWithShadow(matrices, emptyText, getX() + 4, this.getY() + (this.height - 8) / 2f, 0x707070); } } diff --git a/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java index d588d52..197a162 100644 --- a/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java @@ -2,6 +2,7 @@ package dev.isxander.yacl.gui; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.screen.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; @@ -12,13 +13,13 @@ public class TextScaledButtonWidget extends ButtonWidget { public float textScale; public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress); + super(x, y, width, height, message, onPress, ButtonWidget.DEFAULT_NARRATION_SUPPLIER); this.textScale = textScale; } - public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Text message, PressAction onPress, TooltipSupplier tooltipSupplier) { - super(x, y, width, height, message, onPress, tooltipSupplier); - this.textScale = textScale; + public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Text message, PressAction onPress, Tooltip tooltip) { + this(x, y, width, height, textScale, message, onPress); + setTooltip(tooltip); } @Override @@ -35,7 +36,7 @@ public class TextScaledButtonWidget extends ButtonWidget { TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; matrices.push(); - matrices.translate(((this.x + this.width / 2f) - textRenderer.getWidth(orderedText) * textScale / 2), (float)this.y + (this.height - 8 * textScale) / 2f / textScale, 0); + matrices.translate(((this.getX() + this.width / 2f) - textRenderer.getWidth(orderedText) * textScale / 2), (float)this.getY() + (this.height - 8 * textScale) / 2f / textScale, 0); matrices.scale(textScale, textScale, 1); textRenderer.drawWithShadow(matrices, orderedText, 0, 0, j | MathHelper.ceil(this.alpha * 255.0F) << 24); matrices.pop(); diff --git a/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java index d105f7b..706765a 100644 --- a/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java @@ -13,14 +13,14 @@ public class TooltipButtonWidget extends ButtonWidget { protected MultilineText wrappedDescription; public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Text message, Text tooltip, PressAction onPress) { - super(x, y, width, height, message, onPress); + super(x, y, width, height, message, onPress, ButtonWidget.DEFAULT_NARRATION_SUPPLIER); this.screen = screen; setTooltip(tooltip); } public void renderHoveredTooltip(MatrixStack matrices) { if (isHovered()) { - YACLScreen.renderMultilineTooltip(matrices, MinecraftClient.getInstance().textRenderer, wrappedDescription, x + width / 2, y - 4, y + height + 4, screen.width, screen.height); + YACLScreen.renderMultilineTooltip(matrices, MinecraftClient.getInstance().textRenderer, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height); } } diff --git a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index 629fd4c..e36c8e8 100644 --- a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -13,8 +13,7 @@ import net.minecraft.client.render.*; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Matrix4f; +import org.joml.Matrix4f; import java.util.HashSet; import java.util.Set; @@ -85,7 +84,7 @@ public class YACLScreen extends Screen { OptionUtils.forEachOptions(config, Option::forgetPendingValue); }); - searchFieldWidget = new SearchFieldWidget(this, textRenderer, width / 3 / 2 - paddedWidth / 2 + 1, undoButton.y - 22, paddedWidth - 2, 18, Text.translatable("gui.recipebook.search_hint"), Text.translatable("gui.recipebook.search_hint")); + searchFieldWidget = new SearchFieldWidget(this, textRenderer, width / 3 / 2 - paddedWidth / 2 + 1, undoButton.getY() - 22, paddedWidth - 2, 18, Text.translatable("gui.recipebook.search_hint"), Text.translatable("gui.recipebook.search_hint")); categoryList = new CategoryListWidget(client, this, width, height); addSelectableChild(categoryList); @@ -241,7 +240,7 @@ public class YACLScreen extends Screen { matrices.push(); Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferBuilder = tessellator.getBuffer(); - RenderSystem.setShader(GameRenderer::getPositionColorShader); + RenderSystem.setShader(GameRenderer::getPositionColorProgram); bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); Matrix4f matrix4f = matrices.peek().getPositionMatrix(); fillGradient(matrix4f, bufferBuilder, drawX - 3, drawY - 4, drawX + maxWidth + 3, drawY - 3, 400, -267386864, -267386864); @@ -257,7 +256,7 @@ public class YACLScreen extends Screen { RenderSystem.disableTexture(); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - BufferRenderer.drawWithShader(bufferBuilder.end()); + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); RenderSystem.disableBlend(); RenderSystem.enableTexture(); matrices.translate(0.0, 0.0, 400.0); -- cgit From a79f21c5b7ba20469797f3f9e424f88d77f0927d Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 17 Nov 2022 17:30:03 +0000 Subject: make tickbox & boolean controller element constructors public --- src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java | 2 +- src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java/dev') diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java b/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java index b7a77dd..7037ff5 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java @@ -102,7 +102,7 @@ public class BooleanController implements Controller { } public static class BooleanControllerElement extends ControllerWidget { - private BooleanControllerElement(BooleanController control, YACLScreen screen, Dimension dim) { + public BooleanControllerElement(BooleanController control, YACLScreen screen, Dimension dim) { super(control, screen, dim); } diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java index ff693a9..193f5a6 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -50,7 +50,7 @@ public class TickBoxController implements Controller { } public static class TickBoxControllerElement extends ControllerWidget { - private TickBoxControllerElement(TickBoxController control, YACLScreen screen, Dimension dim) { + public TickBoxControllerElement(TickBoxController control, YACLScreen screen, Dimension dim) { super(control, screen, dim); } -- cgit From c26d3a89caae20f1a91898202d91de8dc90da5ad Mon Sep 17 00:00:00 2001 From: isXander Date: Fri, 25 Nov 2022 16:08:07 +0000 Subject: pre2 mapping changes + bug fix Fix tick box name text length limiting --- src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java | 2 +- src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java | 2 +- .../java/dev/isxander/yacl/gui/controllers/TickBoxController.java | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src/main/java/dev') diff --git a/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java index a4d6304..4823428 100644 --- a/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Tooltip; +import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; diff --git a/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java index 197a162..9f153f6 100644 --- a/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.Tooltip; +import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java index 193f5a6..340983d 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -93,6 +93,11 @@ public class TickBoxController implements Controller { return 10; } + @Override + protected int getUnhoveredControlWidth() { + return 10; + } + public void toggleSetting() { control.option().requestSet(!control.option().pendingValue()); playDownSound(); -- cgit From d163b9128d760e53e34fd6c08dbf782fa3d50c51 Mon Sep 17 00:00:00 2001 From: isXander Date: Sun, 27 Nov 2022 18:17:36 +0000 Subject: split sourcesets --- src/main/java/dev/isxander/yacl/api/Binding.java | 64 --- .../java/dev/isxander/yacl/api/ButtonOption.java | 123 ------ .../java/dev/isxander/yacl/api/ConfigCategory.java | 158 ------- .../java/dev/isxander/yacl/api/Controller.java | 28 -- .../java/dev/isxander/yacl/api/NameableEnum.java | 10 - src/main/java/dev/isxander/yacl/api/Option.java | 336 --------------- .../java/dev/isxander/yacl/api/OptionFlag.java | 27 -- .../java/dev/isxander/yacl/api/OptionGroup.java | 141 ------- .../dev/isxander/yacl/api/PlaceholderCategory.java | 94 ----- .../dev/isxander/yacl/api/YetAnotherConfigLib.java | 136 ------ .../dev/isxander/yacl/api/utils/Dimension.java | 33 -- .../isxander/yacl/api/utils/MutableDimension.java | 11 - .../dev/isxander/yacl/api/utils/OptionUtils.java | 37 -- .../dev/isxander/yacl/config/ConfigInstance.java | 7 - .../java/dev/isxander/yacl/gui/AbstractWidget.java | 108 ----- .../dev/isxander/yacl/gui/CategoryListWidget.java | 96 ----- .../java/dev/isxander/yacl/gui/CategoryWidget.java | 31 -- .../isxander/yacl/gui/LowProfileButtonWidget.java | 29 -- .../dev/isxander/yacl/gui/OptionListWidget.java | 470 --------------------- .../isxander/yacl/gui/RequireRestartScreen.java | 16 - .../dev/isxander/yacl/gui/SearchFieldWidget.java | 62 --- .../isxander/yacl/gui/TextScaledButtonWidget.java | 44 -- .../dev/isxander/yacl/gui/TooltipButtonWidget.java | 30 -- .../java/dev/isxander/yacl/gui/YACLScreen.java | 269 ------------ .../yacl/gui/controllers/ActionController.java | 120 ------ .../yacl/gui/controllers/BooleanController.java | 156 ------- .../yacl/gui/controllers/ColorController.java | 203 --------- .../yacl/gui/controllers/ControllerWidget.java | 165 -------- .../yacl/gui/controllers/EnumController.java | 35 -- .../yacl/gui/controllers/LabelController.java | 144 ------- .../yacl/gui/controllers/TickBoxController.java | 120 ------ .../cycling/CyclingControllerElement.java | 60 --- .../controllers/cycling/CyclingListController.java | 79 ---- .../gui/controllers/cycling/EnumController.java | 60 --- .../controllers/cycling/ICyclingController.java | 38 -- .../yacl/gui/controllers/package-info.java | 12 - .../controllers/slider/DoubleSliderController.java | 114 ----- .../controllers/slider/FloatSliderController.java | 114 ----- .../gui/controllers/slider/ISliderController.java | 54 --- .../slider/IntegerSliderController.java | 111 ----- .../controllers/slider/LongSliderController.java | 111 ----- .../slider/SliderControllerElement.java | 160 ------- .../yacl/gui/controllers/slider/package-info.java | 10 - .../gui/controllers/string/IStringController.java | 32 -- .../gui/controllers/string/StringController.java | 45 -- .../string/StringControllerElement.java | 283 ------------- .../dev/isxander/yacl/impl/ButtonOptionImpl.java | 142 ------- .../dev/isxander/yacl/impl/ConfigCategoryImpl.java | 10 - .../dev/isxander/yacl/impl/GenericBindingImpl.java | 35 -- .../dev/isxander/yacl/impl/OptionGroupImpl.java | 10 - .../java/dev/isxander/yacl/impl/OptionImpl.java | 145 ------- .../yacl/impl/PlaceholderCategoryImpl.java | 19 - .../yacl/impl/YetAnotherConfigLibImpl.java | 19 - .../yacl/impl/utils/DimensionIntegerImpl.java | 115 ----- .../isxander/yacl/impl/utils/YACLConstants.java | 8 - .../isxander/yacl/mixin/SimpleOptionAccessor.java | 11 - 56 files changed, 5100 deletions(-) delete mode 100644 src/main/java/dev/isxander/yacl/api/Binding.java delete mode 100644 src/main/java/dev/isxander/yacl/api/ButtonOption.java delete mode 100644 src/main/java/dev/isxander/yacl/api/ConfigCategory.java delete mode 100644 src/main/java/dev/isxander/yacl/api/Controller.java delete mode 100644 src/main/java/dev/isxander/yacl/api/NameableEnum.java delete mode 100644 src/main/java/dev/isxander/yacl/api/Option.java delete mode 100644 src/main/java/dev/isxander/yacl/api/OptionFlag.java delete mode 100644 src/main/java/dev/isxander/yacl/api/OptionGroup.java delete mode 100644 src/main/java/dev/isxander/yacl/api/PlaceholderCategory.java delete mode 100644 src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java delete mode 100644 src/main/java/dev/isxander/yacl/api/utils/Dimension.java delete mode 100644 src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java delete mode 100644 src/main/java/dev/isxander/yacl/api/utils/OptionUtils.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/AbstractWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/CategoryListWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/CategoryWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/OptionListWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/RequireRestartScreen.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/SearchFieldWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/YACLScreen.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/EnumController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/package-info.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/slider/package-info.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/string/IStringController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/string/StringController.java delete mode 100644 src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/GenericBindingImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/OptionImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java delete mode 100644 src/main/java/dev/isxander/yacl/impl/utils/YACLConstants.java delete mode 100644 src/main/java/dev/isxander/yacl/mixin/SimpleOptionAccessor.java (limited to 'src/main/java/dev') diff --git a/src/main/java/dev/isxander/yacl/api/Binding.java b/src/main/java/dev/isxander/yacl/api/Binding.java deleted file mode 100644 index 395beb2..0000000 --- a/src/main/java/dev/isxander/yacl/api/Binding.java +++ /dev/null @@ -1,64 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.impl.GenericBindingImpl; -import dev.isxander.yacl.mixin.SimpleOptionAccessor; -import net.minecraft.client.option.SimpleOption; -import org.apache.commons.lang3.Validate; - -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * Controls modifying the bound option. - * Provides the default value, a setter and a getter. - */ -public interface Binding { - void setValue(T value); - - T getValue(); - - T defaultValue(); - - /** - * Creates a generic binding. - * - * @param def default value of the option, used to reset - * @param getter should return the current value of the option - * @param setter should set the option to the supplied value - */ - static Binding generic(T def, Supplier getter, Consumer setter) { - Validate.notNull(def, "`def` must not be null"); - Validate.notNull(getter, "`getter` must not be null"); - Validate.notNull(setter, "`setter` must not be null"); - - return new GenericBindingImpl<>(def, getter, setter); - } - - /** - * Creates a {@link Binding} for Minecraft's {@link SimpleOption} - */ - static Binding minecraft(SimpleOption minecraftOption) { - Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); - - return new GenericBindingImpl<>( - ((SimpleOptionAccessor) (Object) minecraftOption).getDefaultValue(), - minecraftOption::getValue, - minecraftOption::setValue - ); - } - - /** - * Creates an immutable binding that has no default and cannot be modified. - * - * @param value the value for the binding - */ - static Binding immutable(T value) { - Validate.notNull(value, "`value` must not be null"); - - return new GenericBindingImpl<>( - value, - () -> value, - changed -> {} - ); - } -} diff --git a/src/main/java/dev/isxander/yacl/api/ButtonOption.java b/src/main/java/dev/isxander/yacl/api/ButtonOption.java deleted file mode 100644 index 1124a9a..0000000 --- a/src/main/java/dev/isxander/yacl/api/ButtonOption.java +++ /dev/null @@ -1,123 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.ButtonOptionImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; - -public interface ButtonOption extends Option> { - /** - * Action to be executed upon button press - */ - BiConsumer action(); - - static Builder createBuilder() { - return new Builder(); - } - - class Builder { - private Text name; - private final List tooltipLines = new ArrayList<>(); - private boolean available = true; - private Function>> controlGetter; - private BiConsumer action; - - private Builder() { - - } - - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - public Builder name(@NotNull Text name) { - Validate.notNull(name, "`name` cannot be null"); - - this.name = name; - return this; - } - - /** - * Sets the tooltip to be used by the option. - * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltips text lines - merged with a new-line on {@link Option.Builder#build()}. - */ - public Builder tooltip(@NotNull Text... tooltips) { - Validate.notNull(tooltips, "`tooltips` cannot be empty"); - - tooltipLines.addAll(List.of(tooltips)); - return this; - } - - public Builder action(@NotNull BiConsumer action) { - Validate.notNull(action, "`action` cannot be null"); - - this.action = action; - return this; - } - - /** - * Action to be executed upon button press - * - * @see ButtonOption#action() - */ - @Deprecated - public Builder action(@NotNull Consumer action) { - Validate.notNull(action, "`action` cannot be null"); - - this.action = (screen, button) -> action.accept(screen); - return this; - } - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - public Builder available(boolean available) { - this.available = available; - return this; - } - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - public Builder controller(@NotNull Function>> control) { - Validate.notNull(control, "`control` cannot be null"); - - this.controlGetter = control; - return this; - } - - public ButtonOption build() { - Validate.notNull(name, "`name` must not be null when building `Option`"); - Validate.notNull(controlGetter, "`control` must not be null when building `Option`"); - Validate.notNull(action, "`action` must not be null when building `Option`"); - - MutableText concatenatedTooltip = Text.empty(); - boolean first = true; - for (Text line : tooltipLines) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } - - return new ButtonOptionImpl(name, concatenatedTooltip, action, available, controlGetter); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/ConfigCategory.java b/src/main/java/dev/isxander/yacl/api/ConfigCategory.java deleted file mode 100644 index 27c3e95..0000000 --- a/src/main/java/dev/isxander/yacl/api/ConfigCategory.java +++ /dev/null @@ -1,158 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.impl.ConfigCategoryImpl; -import dev.isxander.yacl.impl.OptionGroupImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Function; - -/** - * Separates {@link Option}s or {@link OptionGroup}s into multiple distinct sections. - * Served to a user as a button in the left column, - * upon pressing, the options list is filled with options contained within this category. - */ -public interface ConfigCategory { - /** - * Name of category, displayed as a button on the left column. - */ - @NotNull Text name(); - - /** - * Gets every {@link OptionGroup} in this category. - */ - @NotNull ImmutableList groups(); - - /** - * Tooltip (or description) of the category. - * Rendered on hover. - */ - @NotNull Text tooltip(); - - /** - * Creates a builder to construct a {@link ConfigCategory} - */ - static Builder createBuilder() { - return new Builder(); - } - - class Builder { - private Text name; - - private final List> rootOptions = new ArrayList<>(); - private final List groups = new ArrayList<>(); - - private final List tooltipLines = new ArrayList<>(); - - private Builder() { - - } - - /** - * Sets name of the category - * - * @see ConfigCategory#name() - */ - public Builder name(@NotNull Text name) { - Validate.notNull(name, "`name` cannot be null"); - - this.name = name; - return this; - } - - /** - * Adds an option to the root group of the category. - * To add to another group, use {@link Builder#group(OptionGroup)}. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see ConfigCategory#groups() - * @see OptionGroup#isRoot() - */ - public Builder option(@NotNull Option option) { - Validate.notNull(option, "`option` must not be null"); - - this.rootOptions.add(option); - return this; - } - - /** - * Adds multiple options to the root group of the category. - * To add to another group, use {@link Builder#groups(Collection)}. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see ConfigCategory#groups() - * @see OptionGroup#isRoot() - */ - public Builder options(@NotNull Collection> options) { - Validate.notNull(options, "`options` must not be null"); - - this.rootOptions.addAll(options); - return this; - } - - /** - * Adds an option group. - * To add an option to the root group, use {@link Builder#option(Option)} - * To construct a group, use {@link OptionGroup#createBuilder()} - */ - public Builder group(@NotNull OptionGroup group) { - Validate.notNull(group, "`group` must not be null"); - - this.groups.add(group); - return this; - } - - /** - * Adds multiple option groups. - * To add multiple options to the root group, use {@link Builder#options(Collection)} - * To construct a group, use {@link OptionGroup#createBuilder()} - */ - public Builder groups(@NotNull Collection groups) { - Validate.notEmpty(groups, "`groups` must not be empty"); - - this.groups.addAll(groups); - return this; - } - - /** - * Sets the tooltip to be used by the category. - * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. - */ - public Builder tooltip(@NotNull Text... tooltips) { - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - tooltipLines.addAll(List.of(tooltips)); - return this; - } - - public ConfigCategory build() { - Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); - - List combinedGroups = new ArrayList<>(); - combinedGroups.add(new OptionGroupImpl(Text.empty(), Text.empty(), ImmutableList.copyOf(rootOptions), false, true)); - combinedGroups.addAll(groups); - - Validate.notEmpty(combinedGroups, "at least one option must be added to build `ConfigCategory`"); - - MutableText concatenatedTooltip = Text.empty(); - boolean first = true; - for (Text line : tooltipLines) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } - - return new ConfigCategoryImpl(name, ImmutableList.copyOf(combinedGroups), concatenatedTooltip); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/Controller.java b/src/main/java/dev/isxander/yacl/api/Controller.java deleted file mode 100644 index 7bf7e7f..0000000 --- a/src/main/java/dev/isxander/yacl/api/Controller.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.api.utils.Dimension; -import dev.isxander.yacl.gui.AbstractWidget; -import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.text.Text; - -/** - * Provides a widget to control the option. - */ -public interface Controller { - /** - * Gets the dedicated {@link Option} for this controller - */ - Option option(); - - /** - * Gets the formatted value based on {@link Option#pendingValue()} - */ - Text formatValue(); - - /** - * Provides a widget to display - * - * @param screen parent screen - */ - AbstractWidget provideWidget(YACLScreen screen, Dimension widgetDimension); -} diff --git a/src/main/java/dev/isxander/yacl/api/NameableEnum.java b/src/main/java/dev/isxander/yacl/api/NameableEnum.java deleted file mode 100644 index 793b230..0000000 --- a/src/main/java/dev/isxander/yacl/api/NameableEnum.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.isxander.yacl.api; - -import net.minecraft.text.Text; - -/** - * Used for the default value formatter of {@link dev.isxander.yacl.gui.controllers.cycling.EnumController} - */ -public interface NameableEnum { - Text getDisplayName(); -} diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java deleted file mode 100644 index 772c816..0000000 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ /dev/null @@ -1,336 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableSet; -import dev.isxander.yacl.impl.OptionImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Stream; - -public interface Option { - /** - * Name of the option - */ - @NotNull Text name(); - - /** - * Tooltip (or description) of the option. - * Rendered on hover. - */ - @NotNull Text tooltip(); - - /** - * Widget provider for a type of option. - * - * @see dev.isxander.yacl.gui.controllers - */ - @NotNull Controller controller(); - - /** - * Binding for the option. - * Controls setting, getting and default value. - * - * @see Binding - */ - @NotNull Binding binding(); - - /** - * If the option can be configured - */ - boolean available(); - - /** - * Sets if the option can be configured after being built - * - * @see Option#available() - */ - void setAvailable(boolean available); - - /** - * Class of the option type. - * Used by some controllers. - */ - @NotNull Class typeClass(); - - /** - * Tasks that needs to be executed upon applying changes. - */ - @NotNull ImmutableSet flags(); - - /** - * Checks if the pending value is not equal to the current set value - */ - boolean changed(); - - /** - * If true, modifying this option recommends a restart. - */ - @Deprecated - boolean requiresRestart(); - - /** - * Value in the GUI, ready to set the actual bound value or be undone. - */ - @NotNull T pendingValue(); - - /** - * Sets the pending value - */ - void requestSet(T value); - - /** - * Applies the pending value to the bound value. - * Cannot be undone. - * - * @return if there were changes to apply {@link Option#changed()} - */ - boolean applyValue(); - - /** - * Sets the pending value to the bound value. - */ - void forgetPendingValue(); - - /** - * Sets the pending value to the default bound value. - */ - void requestSetDefault(); - - /** - * Checks if the current pending value is equal to its default value - */ - boolean isPendingValueDefault(); - - /** - * Adds a listener for when the pending value changes - */ - void addListener(BiConsumer, T> changedListener); - - /** - * Creates a builder to construct an {@link Option} - * - * @param type of the option's value - * @param typeClass used to capture the type - */ - static Builder createBuilder(Class typeClass) { - return new Builder<>(typeClass); - } - - class Builder { - private Text name = Text.literal("Name not specified!").formatted(Formatting.RED); - - private final List> tooltipGetters = new ArrayList<>(); - - private Function, Controller> controlGetter; - - private Binding binding; - - private boolean available = true; - - private boolean instant = false; - - private final Set flags = new HashSet<>(); - - private final Class typeClass; - - private final List, T>> listeners = new ArrayList<>(); - - private Builder(Class typeClass) { - this.typeClass = typeClass; - } - - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - public Builder name(@NotNull Text name) { - Validate.notNull(name, "`name` cannot be null"); - - this.name = name; - return this; - } - - /** - * Sets the tooltip to be used by the option. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. - */ - @SafeVarargs - public final Builder tooltip(@NotNull Function... tooltipGetter) { - Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); - - this.tooltipGetters.addAll(List.of(tooltipGetter)); - return this; - } - - /** - * Sets the tooltip to be used by the option. - * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. - */ - public Builder tooltip(@NotNull Text... tooltips) { - Validate.notNull(tooltips, "`tooltips` cannot be empty"); - - this.tooltipGetters.addAll(Stream.of(tooltips).map(text -> (Function) t -> text).toList()); - return this; - } - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - public Builder controller(@NotNull Function, Controller> control) { - Validate.notNull(control, "`control` cannot be null"); - - this.controlGetter = control; - return this; - } - - /** - * Sets the binding for the option. - * Used for default, getter and setter. - * - * @see Binding - */ - public Builder binding(@NotNull Binding binding) { - Validate.notNull(binding, "`binding` cannot be null"); - - this.binding = binding; - return this; - } - - /** - * Sets the binding for the option. - * Shorthand of {@link Binding#generic(Object, Supplier, Consumer)} - * - * @param def default value of the option, used to reset - * @param getter should return the current value of the option - * @param setter should set the option to the supplied value - * @see Binding - */ - public Builder binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter) { - Validate.notNull(def, "`def` must not be null"); - Validate.notNull(getter, "`getter` must not be null"); - Validate.notNull(setter, "`setter` must not be null"); - - this.binding = Binding.generic(def, getter, setter); - return this; - } - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - public Builder available(boolean available) { - this.available = available; - return this; - } - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - public Builder flag(@NotNull OptionFlag... flag) { - Validate.notNull(flag, "`flag` must not be null"); - - this.flags.addAll(Arrays.asList(flag)); - return this; - } - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - public Builder flags(@NotNull Collection flags) { - Validate.notNull(flags, "`flags` must not be null"); - - this.flags.addAll(flags); - return this; - } - - /** - * Instantly invokes the binder's setter when modified in the GUI. - * Prevents the user from undoing the change - *

- * Does not support {@link Option#flags()}! - */ - public Builder instant(boolean instant) { - this.instant = instant; - return this; - } - - /** - * Adds a listener to the option. Invoked upon changing the pending value. - * - * @see Option#addListener(BiConsumer) - */ - public Builder listener(@NotNull BiConsumer, T> listener) { - this.listeners.add(listener); - return this; - } - - /** - * Adds multiple listeners to the option. Invoked upon changing the pending value. - * - * @see Option#addListener(BiConsumer) - */ - public Builder listeners(@NotNull Collection, T>> listeners) { - this.listeners.addAll(listeners); - return this; - } - - /** - * Dictates whether the option should require a restart. - * {@link Option#requiresRestart()} - */ - @Deprecated - public Builder requiresRestart(boolean requiresRestart) { - if (requiresRestart) flag(OptionFlag.GAME_RESTART); - else flags.remove(OptionFlag.GAME_RESTART); - - return this; - } - - public Option build() { - Validate.notNull(controlGetter, "`control` must not be null when building `Option`"); - Validate.notNull(binding, "`binding` must not be null when building `Option`"); - Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags"); - - Function concatenatedTooltipGetter = value -> { - MutableText concatenatedTooltip = Text.empty(); - boolean first = true; - for (Function line : tooltipGetters) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line.apply(value)); - } - - return concatenatedTooltip; - }; - - if (instant) { - listeners.add((opt, pendingValue) -> opt.applyValue()); - } - - return new OptionImpl<>(name, concatenatedTooltipGetter, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass, listeners); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/OptionFlag.java b/src/main/java/dev/isxander/yacl/api/OptionFlag.java deleted file mode 100644 index 203a674..0000000 --- a/src/main/java/dev/isxander/yacl/api/OptionFlag.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.RequireRestartScreen; -import net.minecraft.client.MinecraftClient; - -import java.util.function.Consumer; - -/** - * Code that is executed upon certain options being applied. - * Each flag is executed only once per save, no matter the amount of options with the flag. - */ -@FunctionalInterface -public interface OptionFlag extends Consumer { - /** - * Warns the user that a game restart is required for the changes to take effect - */ - OptionFlag GAME_RESTART = client -> client.setScreen(new RequireRestartScreen(client.currentScreen)); - - /** - * Reloads chunks upon applying (F3+A) - */ - OptionFlag RELOAD_CHUNKS = client -> client.worldRenderer.reload(); - - OptionFlag WORLD_RENDER_UPDATE = client -> client.worldRenderer.scheduleTerrainUpdate(); - - OptionFlag ASSET_RELOAD = MinecraftClient::reloadResourcesConcurrently; -} diff --git a/src/main/java/dev/isxander/yacl/api/OptionGroup.java b/src/main/java/dev/isxander/yacl/api/OptionGroup.java deleted file mode 100644 index 3364bdf..0000000 --- a/src/main/java/dev/isxander/yacl/api/OptionGroup.java +++ /dev/null @@ -1,141 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.impl.OptionGroupImpl; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Serves as a separator between multiple chunks of options - * that may be too similar or too few to be placed in a separate {@link ConfigCategory}. - * Or maybe you just want your config to feel less dense. - */ -public interface OptionGroup { - /** - * Name of the option group, displayed as a separator in the option lists. - * Can be empty. - */ - Text name(); - - /** - * Tooltip displayed on hover. - */ - Text tooltip(); - - /** - * List of all options in the group - */ - @NotNull ImmutableList> options(); - - /** - * Dictates if the group should be collapsed by default. - */ - boolean collapsed(); - - /** - * Always false when using the {@link Builder} - * used to not render the separator if true - */ - boolean isRoot(); - - /** - * Creates a builder to construct a {@link OptionGroup} - */ - static Builder createBuilder() { - return new Builder(); - } - - class Builder { - private Text name = Text.empty(); - private final List tooltipLines = new ArrayList<>(); - private final List> options = new ArrayList<>(); - private boolean collapsed = false; - - private Builder() { - - } - - /** - * Sets name of the group, can be {@link Text#empty()} to just separate options, like sodium. - * - * @see OptionGroup#name() - */ - public Builder name(@NotNull Text name) { - Validate.notNull(name, "`name` must not be null"); - - this.name = name; - return this; - } - - /** - * Sets the tooltip to be used by the option group. - * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. - */ - public Builder tooltip(@NotNull Text... tooltips) { - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - tooltipLines.addAll(List.of(tooltips)); - return this; - } - - /** - * Adds an option to group. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see OptionGroup#options() - */ - public Builder option(@NotNull Option option) { - Validate.notNull(option, "`option` must not be null"); - - this.options.add(option); - return this; - } - - /** - * Adds multiple options to group. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see OptionGroup#options() - */ - public Builder options(@NotNull Collection> options) { - Validate.notEmpty(options, "`options` must not be empty"); - - this.options.addAll(options); - return this; - } - - /** - * Dictates if the group should be collapsed by default - * - * @see OptionGroup#collapsed() - */ - public Builder collapsed(boolean collapsible) { - this.collapsed = collapsible; - return this; - } - - public OptionGroup build() { - Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`"); - - MutableText concatenatedTooltip = Text.empty(); - boolean first = true; - for (Text line : tooltipLines) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } - - return new OptionGroupImpl(name, concatenatedTooltip, ImmutableList.copyOf(options), collapsed, false); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/PlaceholderCategory.java b/src/main/java/dev/isxander/yacl/api/PlaceholderCategory.java deleted file mode 100644 index de7441c..0000000 --- a/src/main/java/dev/isxander/yacl/api/PlaceholderCategory.java +++ /dev/null @@ -1,94 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.PlaceholderCategoryImpl; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiFunction; - -/** - * A placeholder category that actually just opens another screen, - * instead of displaying options - */ -public interface PlaceholderCategory extends ConfigCategory { - /** - * Function to create a screen to open upon changing to this category - */ - BiFunction screen(); - - static Builder createBuilder() { - return new Builder(); - } - - class Builder { - private Text name; - - private final List tooltipLines = new ArrayList<>(); - - private BiFunction screenFunction; - - private Builder() { - - } - - /** - * Sets name of the category - * - * @see ConfigCategory#name() - */ - public Builder name(@NotNull Text name) { - Validate.notNull(name, "`name` cannot be null"); - - this.name = name; - return this; - } - - /** - * Sets the tooltip to be used by the category. - * Can be invoked twice to append more lines. - * No need to wrap the text yourself, the gui does this itself. - * - * @param tooltips text lines - merged with a new-line on {@link Builder#build()}. - */ - public Builder tooltip(@NotNull Text... tooltips) { - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - tooltipLines.addAll(List.of(tooltips)); - return this; - } - - /** - * Screen to open upon selecting this category - * - * @see PlaceholderCategory#screen() - */ - public Builder screen(@NotNull BiFunction screenFunction) { - Validate.notNull(screenFunction, "`screenFunction` cannot be null"); - - this.screenFunction = screenFunction; - return this; - } - - public PlaceholderCategory build() { - Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); - - MutableText concatenatedTooltip = Text.empty(); - boolean first = true; - for (Text line : tooltipLines) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } - - return new PlaceholderCategoryImpl(name, screenFunction, concatenatedTooltip); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java deleted file mode 100644 index a69ae4e..0000000 --- a/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java +++ /dev/null @@ -1,136 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.YetAnotherConfigLibImpl; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.text.Text; -import org.apache.commons.lang3.Validate; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.function.Consumer; - -/** - * Main class of the mod. - * Contains all data and used to provide a {@link Screen} - */ -public interface YetAnotherConfigLib { - /** - * Title of the GUI. Only used for Minecraft narration. - */ - Text title(); - - /** - * Gets all config categories. - */ - ImmutableList categories(); - - /** - * Ran when changes are saved. Can be used to save config to a file etc. - */ - Runnable saveFunction(); - - /** - * Ran every time the YACL screen initialises. Can be paired with FAPI to add custom widgets. - */ - Consumer initConsumer(); - - /** - * Generates a Screen to display based on this instance. - * - * @param parent parent screen to open once closed - */ - Screen generateScreen(@Nullable Screen parent); - - /** - * Creates a builder to construct YACL - */ - static Builder createBuilder() { - return new Builder(); - } - - class Builder { - private Text title; - private final List categories = new ArrayList<>(); - private Runnable saveFunction = () -> {}; - private Consumer initConsumer = screen -> {}; - - private Builder() { - - } - - /** - * Sets title of GUI for Minecraft narration - * - * @see YetAnotherConfigLib#title() - */ - public Builder title(@NotNull Text title) { - Validate.notNull(title, "`title` cannot be null"); - - this.title = title; - return this; - } - - /** - * Adds a new category. - * To create a category you need to use {@link ConfigCategory#createBuilder()} - * - * @see YetAnotherConfigLib#categories() - */ - public Builder category(@NotNull ConfigCategory category) { - Validate.notNull(category, "`category` cannot be null"); - - this.categories.add(category); - return this; - } - - /** - * Adds multiple categories at once. - * To create a category you need to use {@link ConfigCategory#createBuilder()} - * - * @see YetAnotherConfigLib#categories() - */ - public Builder categories(@NotNull Collection categories) { - Validate.notNull(categories, "`categories` cannot be null"); - - this.categories.addAll(categories); - return this; - } - - /** - * Used to define a save function for when user clicks the Save Changes button - * - * @see YetAnotherConfigLib#saveFunction() - */ - public Builder save(@NotNull Runnable saveFunction) { - Validate.notNull(saveFunction, "`saveFunction` cannot be null"); - - this.saveFunction = saveFunction; - return this; - } - - /** - * Defines a consumer that is accepted every time the YACL screen initialises - * - * @see YetAnotherConfigLib#initConsumer() - */ - public Builder screenInit(@NotNull Consumer initConsumer) { - Validate.notNull(initConsumer, "`initConsumer` cannot be null"); - - this.initConsumer = initConsumer; - return this; - } - - public YetAnotherConfigLib build() { - Validate.notNull(title, "`title must not be null to build `YetAnotherConfigLib`"); - Validate.notEmpty(categories, "`categories` must not be empty to build `YetAnotherConfigLib`"); - Validate.isTrue(!categories.stream().allMatch(category -> category instanceof PlaceholderCategory), "At least one regular category is required to build `YetAnotherConfigLib`"); - - return new YetAnotherConfigLibImpl(title, ImmutableList.copyOf(categories), saveFunction, initConsumer); - } - } -} diff --git a/src/main/java/dev/isxander/yacl/api/utils/Dimension.java b/src/main/java/dev/isxander/yacl/api/utils/Dimension.java deleted file mode 100644 index 0de0a58..0000000 --- a/src/main/java/dev/isxander/yacl/api/utils/Dimension.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.isxander.yacl.api.utils; - -import dev.isxander.yacl.impl.utils.DimensionIntegerImpl; - -public interface Dimension { - T