From 27aa3e94f19142009bc277a709959ad9439d2e89 Mon Sep 17 00:00:00 2001 From: ThatGravyBoat Date: Tue, 24 Sep 2024 18:27:39 -0230 Subject: [PATCH] Bump version --- changelog.md | 7 +- .../api/client/ResourcefulConfigScreen.java | 10 +- .../api/client/ResourcefulConfigUI.java | 91 +++++++++++++++++++ 3 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigUI.java diff --git a/changelog.md b/changelog.md index 9c6b4a6..50e97a0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,2 +1,5 @@ -- Fix crash on newer neoforge versions -- Fix error in web server \ No newline at end of file +- Fix screen not opening when only 1 config available +- Add info buttons +- Add support for dedicated server properties (Web Config Only) +- Add proper color picker +- Add UI element creation to API \ No newline at end of file diff --git a/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigScreen.java b/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigScreen.java index aa78227..d9a59e2 100644 --- a/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigScreen.java +++ b/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigScreen.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Set; import java.util.function.Function; -import java.util.function.UnaryOperator; public class ResourcefulConfigScreen { @@ -55,13 +54,10 @@ public static Screen get(@Nullable Screen parent, String mod) { } /** - * Opens a modal screen with the given title and constructor. - * @param title The title of the modal screen. - * @param constructor The constructor for the modal screen. This should be a lambda that returns a widget that contains the modal screen's content. - * - * @apiNote The widget for this modal should contain all other widgets and should be used for rendering of inside the modal. + * @deprecated Use {@link ResourcefulConfigUI} */ + @Deprecated public static void openModal(Component title, ModalWidgetConstructor constructor) { - new GenericModalOverlay(title, constructor).open(); + ResourcefulConfigUI.openModal(title, constructor); } } diff --git a/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigUI.java b/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigUI.java new file mode 100644 index 0000000..a3f7232 --- /dev/null +++ b/common/src/main/java/com/teamresourceful/resourcefulconfig/api/client/ResourcefulConfigUI.java @@ -0,0 +1,91 @@ +package com.teamresourceful.resourcefulconfig.api.client; + +import com.teamresourceful.resourcefulconfig.client.components.base.ContainerWidget; +import com.teamresourceful.resourcefulconfig.client.components.base.CustomButton; +import com.teamresourceful.resourcefulconfig.client.components.base.SpriteButton; +import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.layouts.Layout; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +public class ResourcefulConfigUI { + + /** + * Opens a modal screen with the given title and constructor. + * + * @param title The title of the modal screen. + * @param constructor The constructor for the modal screen. This should be a lambda that returns a widget that contains the modal screen's content. + * @apiNote The widget for this modal should contain all other widgets and should be used for rendering of inside the modal. + * See {@link #container} for an example. + */ + public static void openModal(Component title, ModalWidgetConstructor constructor) { + new GenericModalOverlay(title, constructor).open(); + } + + /** + * Create a widget that contains all other widgets. + * + * @param x The x position of the widget. + * @param y The y position of the widget. + * @param width The width of the widget. + * @param height The height of the widget. + */ + public static AbstractWidget container(int x, int y, int width, int height, Layout layout) { + return new ContainerWidget(x, y, width, height) { + + { + positionUpdated(); + } + + @Override + protected void positionUpdated() { + this.clear(); + layout.setPosition(getX(), getY()); + layout.arrangeElements(); + layout.visitWidgets(this::addRenderableWidget); + } + }; + } + + /** + * Create a button with the given text and onClick action. + * + * @param x The x position of the button. + * @param y The y position of the button. + * @param width The width of the button. + * @param height The height of the button. + * @param text The text of the button. + * @param onClick The action to run when the button is clicked. + * @return The created button. + */ + public static AbstractWidget button(int x, int y, int width, int height, Component text, Runnable onClick) { + var button = new CustomButton(width, height, text, onClick); + button.setPosition(x, y); + return button; + } + + /** + * Create a button with the given sprite and onClick action. + * + * @param x The x position of the button. + * @param y The y position of the button. + * @param width The width of the button. + * @param height The height of the button. + * @param sprite The sprite of the button. + * @param tooltip The tooltip of the button. + * @param onClick The action to run when the button is clicked. + * @return The created button. + */ + public static AbstractWidget button(int x, int y, int width, int height, ResourceLocation sprite, @Nullable Component tooltip, Runnable onClick) { + var button = SpriteButton.builder(width, height) + .padding(2) + .sprite(sprite) + .tooltip(tooltip) + .onPress(onClick) + .build(); + button.setPosition(x, y); + return button; + } + +}