From 6f3dc40a6bc554b6decb685cb6d1eb6370b1eea6 Mon Sep 17 00:00:00 2001 From: isXander Date: Sun, 13 Nov 2022 19:04:45 +0000 Subject: lots of QOL and minor improvements smooth category scrolling individual reset buttons for all controllers separate Dimension into Dimension and MutableDimension to prevent mods from modifying controller dimensions without invoking the hooks made the dimension field private in AbstractWidget so people can't modify it without the method setDimension new Option API method to check if pending value is equal to default value add documentation to ConfigInstance fix bug where Option#requestSetDefault and Option#forgetPendingValue implementations weren't notifying listeners --- .../java/dev/isxander/yacl/api/Controller.java | 1 - src/main/java/dev/isxander/yacl/api/Option.java | 5 ++ .../dev/isxander/yacl/api/utils/Dimension.java | 12 +--- .../isxander/yacl/api/utils/MutableDimension.java | 11 ++++ .../dev/isxander/yacl/config/ConfigInstance.java | 11 +++- .../isxander/yacl/config/YACLConfigManager.java | 38 ++++++++++++- .../java/dev/isxander/yacl/gui/AbstractWidget.java | 6 +- .../dev/isxander/yacl/gui/OptionListWidget.java | 66 +++++++++++++++++++--- .../isxander/yacl/gui/TextScaledButtonWidget.java | 43 ++++++++++++++ .../java/dev/isxander/yacl/gui/YACLScreen.java | 3 +- .../yacl/gui/controllers/ActionController.java | 5 ++ .../yacl/gui/controllers/BooleanController.java | 1 - .../yacl/gui/controllers/ColorController.java | 3 +- .../yacl/gui/controllers/ControllerWidget.java | 17 ++++-- .../yacl/gui/controllers/LabelController.java | 24 ++++---- .../yacl/gui/controllers/TickBoxController.java | 9 ++- .../string/StringControllerElement.java | 2 +- .../dev/isxander/yacl/impl/ButtonOptionImpl.java | 5 ++ .../java/dev/isxander/yacl/impl/OptionImpl.java | 9 ++- .../yacl/impl/utils/DimensionIntegerImpl.java | 21 +++---- 20 files changed, 229 insertions(+), 63 deletions(-) create mode 100644 src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java create mode 100644 src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java (limited to 'src/main/java/dev/isxander/yacl') diff --git a/src/main/java/dev/isxander/yacl/api/Controller.java b/src/main/java/dev/isxander/yacl/api/Controller.java index 7fbc466..7bf7e7f 100644 --- a/src/main/java/dev/isxander/yacl/api/Controller.java +++ b/src/main/java/dev/isxander/yacl/api/Controller.java @@ -4,7 +4,6 @@ import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.text.Text; -import org.jetbrains.annotations.ApiStatus; /** * Provides a widget to control the option. diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java index 8ec7338..772c816 100644 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -104,6 +104,11 @@ public interface Option { */ 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 */ diff --git a/src/main/java/dev/isxander/yacl/api/utils/Dimension.java b/src/main/java/dev/isxander/yacl/api/utils/Dimension.java index 69958b1..0de0a58 100644 --- a/src/main/java/dev/isxander/yacl/api/utils/Dimension.java +++ b/src/main/java/dev/isxander/yacl/api/utils/Dimension.java @@ -17,25 +17,17 @@ public interface Dimension { boolean isPointInside(T x, T y); - Dimension clone(); - - Dimension setX(T x); - Dimension setY(T y); - Dimension setWidth(T width); - Dimension setHeight(T height); + MutableDimension clone(); Dimension withX(T x); Dimension withY(T y); Dimension withWidth(T width); Dimension withHeight(T height); - Dimension move(T x, T y); - Dimension expand(T width, T height); - Dimension moved(T x, T y); Dimension expanded(T width, T height); - static Dimension ofInt(int x, int y, int width, int height) { + static MutableDimension ofInt(int x, int y, int width, int height) { return new DimensionIntegerImpl(x, y, width, height); } } diff --git a/src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java b/src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java new file mode 100644 index 0000000..eff0186 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java @@ -0,0 +1,11 @@ +package dev.isxander.yacl.api.utils; + +public interface MutableDimension extends Dimension { + MutableDimension setX(T x); + MutableDimension setY(T y); + MutableDimension setWidth(T width); + MutableDimension setHeight(T height); + + MutableDimension move(T x, T y); + MutableDimension expand(T width, T height); +} diff --git a/src/main/java/dev/isxander/yacl/config/ConfigInstance.java b/src/main/java/dev/isxander/yacl/config/ConfigInstance.java index e85a645..5271ea2 100644 --- a/src/main/java/dev/isxander/yacl/config/ConfigInstance.java +++ b/src/main/java/dev/isxander/yacl/config/ConfigInstance.java @@ -5,6 +5,16 @@ import dev.isxander.yacl.api.YetAnotherConfigLib; import java.lang.reflect.InvocationTargetException; import java.util.function.BiFunction; +/** + * Responsible for handing the actual config data type. + * Holds the instance along with a final default instance + * to reference default values for options and should not be changed. + * + * Abstract methods to save and load the class, implementations are responsible for + * how it saves and load. + * + * @param config data type + */ public abstract class ConfigInstance { private final Class configClass; private final T defaultInstance; @@ -18,7 +28,6 @@ public abstract class ConfigInstance { } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new IllegalStateException(String.format("Could not create default instance of config for %s. Make sure there is a default constructor!", this.configClass.getSimpleName())); } - } public T getConfig() { diff --git a/src/main/java/dev/isxander/yacl/config/YACLConfigManager.java b/src/main/java/dev/isxander/yacl/config/YACLConfigManager.java index d91f3f6..a312d03 100644 --- a/src/main/java/dev/isxander/yacl/config/YACLConfigManager.java +++ b/src/main/java/dev/isxander/yacl/config/YACLConfigManager.java @@ -3,24 +3,58 @@ package dev.isxander.yacl.config; import java.util.HashMap; import java.util.Map; +/** + * Simple storage of config instances ({@link ConfigInstance}) for ease of access. + */ @SuppressWarnings("unchecked") public class YACLConfigManager { private static final Map, ConfigInstance> configs = new HashMap<>(); + /** + * Registers and loads a config instance + * + * @param configInstance config to register + * @param config data type + */ public static void register(ConfigInstance configInstance) { configs.put(configInstance.getConfigClass(), configInstance); configInstance.load(); } + /** + * Retrieves config data for a certain config. + *

+ * Shorthand of {@code YACLConfigManager.getConfigInstance(configClass).getConfig()} + * + * @param configClass config data to get + * @return config data + * @param config data type + */ public static T getConfigData(Class configClass) { return ((ConfigInstance) configs.get(configClass)).getConfig(); } + /** + * Retrieves the config instance for a certain config. + * + * @param configClass config data type instance is bound to + * @return config instance + * @param config data type + */ public static ConfigInstance getConfigInstance(Class configClass) { return (ConfigInstance) configs.get(configClass); } - public static > I getConfigInstanceType(Class configClass) { - return (I) configs.get(configClass); + /** + * Very similar to {@link YACLConfigManager#getConfigInstance(Class)} but can retrieve + * a certain implementation of {@link ConfigInstance} + * + * @param configClass config data type is bound to + * @return config instance + * @param config data type + * @param config instance type + */ + public static > U getConfigInstanceType(Class configClass) { + return (U) configs.get(configClass); } } diff --git a/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java index d4cae93..03dc9b9 100644 --- a/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java @@ -22,7 +22,7 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { protected final TextRenderer textRenderer = client.textRenderer; protected final int inactiveColor = 0xFFA0A0A0; - protected Dimension dim; + private Dimension dim; public AbstractWidget(Dimension dim) { this.dim = dim; @@ -32,6 +32,10 @@ public abstract class AbstractWidget implements Element, Drawable, Selectable { } + public boolean canReset() { + return false; + } + @Override public boolean isMouseOver(double mouseX, double mouseY) { if (dim == null) return false; diff --git a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java index ddbb06e..cf50a58 100644 --- a/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -28,6 +28,9 @@ public class OptionListWidget extends ElementListWidget private ImmutableList viewableChildren; + private double smoothScrollAmount = getScrollAmount(); + private boolean returnSmoothAmount = false; + public OptionListWidget(YACLScreen screen, MinecraftClient client, int width, int height) { super(client, width / 3 * 2, height, 0, height, 22); this.yaclScreen = screen; @@ -62,7 +65,7 @@ public class OptionListWidget extends ElementListWidget List optionEntries = new ArrayList<>(); for (Option option : group.options()) { - OptionEntry entry = new OptionEntry(category, group, option.controller().provideWidget(yaclScreen, Dimension.ofInt(getRowLeft(), 0, getRowWidth(), 20)), viewableSupplier); + OptionEntry entry = new OptionEntry(option, category, group, option.controller().provideWidget(yaclScreen, Dimension.ofInt(getRowLeft(), 0, getRowWidth(), 20)), viewableSupplier); addEntry(entry); optionEntries.add(entry); } @@ -148,14 +151,34 @@ public class OptionListWidget extends ElementListWidget } } + /* END cloth config code */ + + @Override + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + smoothScrollAmount = MathHelper.lerp(MinecraftClient.getInstance().getLastFrameDuration() * 0.5, smoothScrollAmount, getScrollAmount()); + returnSmoothAmount = true; + super.render(matrices, mouseX, mouseY, delta); + returnSmoothAmount = false; + } + + /** + * awful code to only use smooth scroll state when rendering, + * not other code that needs target scroll amount + */ + @Override + public double getScrollAmount() { + if (returnSmoothAmount) + return smoothScrollAmount; + + return super.getScrollAmount(); + } + public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { for (Entry entry : children()) { entry.postRender(matrices, mouseX, mouseY, delta); } } - /* END cloth config code */ - @Override public int getRowWidth() { return Math.min(396, (int)(width / 1.3f)); @@ -178,7 +201,7 @@ public class OptionListWidget extends ElementListWidget return true; } - this.setScrollAmount(this.getScrollAmount() - amount * (double) (getMaxScroll() / getEntryCount()) / 2.0D); + this.setScrollAmount(this.getScrollAmount() - amount * 20 /* * (double) (getMaxScroll() / getEntryCount()) / 2.0D */); return true; } @@ -221,7 +244,7 @@ public class OptionListWidget extends ElementListWidget int i = 0; for (Entry entry : viewableChildren) { if (entry instanceof OptionEntry optionEntry) - optionEntry.widget.setDimension(optionEntry.widget.getDimension().setY(getRowTop(i))); + optionEntry.widget.setDimension(optionEntry.widget.getDimension().withY(getRowTop(i))); i++; } } @@ -250,29 +273,48 @@ public class OptionListWidget extends ElementListWidget } public class OptionEntry extends Entry { + public final Option option; public final ConfigCategory category; public final OptionGroup group; public final AbstractWidget widget; private final Supplier viewableSupplier; + private final TextScaledButtonWidget resetButton; + private final String categoryName; private final String groupName; - private OptionEntry(ConfigCategory category, OptionGroup group, AbstractWidget widget, Supplier viewableSupplier) { + private OptionEntry(Option option, ConfigCategory category, OptionGroup group, AbstractWidget widget, Supplier viewableSupplier) { + this.option = option; this.category = category; this.group = group; this.widget = widget; this.viewableSupplier = viewableSupplier; this.categoryName = category.name().getString().toLowerCase(); this.groupName = group.name().getString().toLowerCase(); + if (this.widget.canReset()) { + this.widget.setDimension(this.widget.getDimension().expanded(-21, 0)); + this.resetButton = new TextScaledButtonWidget(widget.getDimension().xLimit() + 1, -50, 20, 20, 2f, Text.of("\u21BB"), button -> { + option.requestSetDefault(); + }); + option.addListener((opt, val) -> this.resetButton.active = !opt.isPendingValueDefault() && opt.available()); + this.resetButton.active = !option.isPendingValueDefault() && option.available(); + } else { + this.resetButton = null; + } } @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - widget.setDimension(widget.getDimension().setY(y)); + widget.setDimension(widget.getDimension().withY(y)); widget.render(matrices, mouseX, mouseY, tickDelta); + + if (resetButton != null) { + resetButton.y = y; + resetButton.render(matrices, mouseX, mouseY, tickDelta); + } } @Override @@ -312,12 +354,18 @@ public class OptionListWidget extends ElementListWidget @Override public List selectableChildren() { - return ImmutableList.of(widget); + if (resetButton == null) + return ImmutableList.of(widget); + + return ImmutableList.of(widget, resetButton); } @Override public List children() { - return ImmutableList.of(widget); + if (resetButton == null) + return ImmutableList.of(widget); + + return ImmutableList.of(widget, resetButton); } } diff --git a/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java new file mode 100644 index 0000000..d588d52 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.gui; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.OrderedText; +import net.minecraft.text.Text; +import net.minecraft.util.math.MathHelper; + +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); + 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; + } + + @Override + public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { + // prevents super from rendering text + Text message = getMessage(); + setMessage(Text.empty()); + + super.renderButton(matrices, mouseX, mouseY, delta); + + setMessage(message); + int j = this.active ? 16777215 : 10526880; + OrderedText orderedText = getMessage().asOrderedText(); + 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.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/YACLScreen.java b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index 70c61c1..629fd4c 100644 --- a/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.systems.RenderSystem; import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.api.utils.MutableDimension; import dev.isxander.yacl.api.utils.OptionUtils; import net.minecraft.client.font.MultilineText; import net.minecraft.client.font.TextRenderer; @@ -48,7 +49,7 @@ public class YACLScreen extends Screen { columnWidth = Math.min(columnWidth, 400); int paddedWidth = columnWidth - padding * 2; - Dimension actionDim = Dimension.ofInt(width / 3 / 2, height - padding - 20, paddedWidth, 20); + MutableDimension actionDim = Dimension.ofInt(width / 3 / 2, height - padding - 20, paddedWidth, 20); finishedSaveButton = new TooltipButtonWidget(this, actionDim.x() - actionDim.width() / 2, actionDim.y(), actionDim.width(), actionDim.height(), Text.empty(), Text.empty(), (btn) -> { saveButtonMessage = null; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java index 6207f03..b8e2cd1 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java @@ -107,6 +107,11 @@ public class ActionController implements Controller { public static class ColorControllerElement extends StringControllerElement { private final ColorController colorController; - protected Dimension colorPreviewDim; + protected MutableDimension colorPreviewDim; private final List allowedChars; diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index 520efa7..c7f9e97 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -40,7 +40,7 @@ public abstract class ControllerWidget> extends Abstract String nameString = name.getString(); boolean firstIter = true; - while (textRenderer.getWidth(nameString) > dim.width() - getControlWidth() - getXPadding() - 7) { + while (textRenderer.getWidth(nameString) > getDimension().width() - getControlWidth() - getXPadding() - 7) { nameString = nameString.substring(0, Math.max(nameString.length() - (firstIter ? 2 : 5), 0)).trim(); nameString += "..."; @@ -49,9 +49,9 @@ public abstract class ControllerWidget> extends Abstract Text shortenedName = Text.literal(nameString).fillStyle(name.getStyle()); - drawButtonRect(matrices, dim.x(), dim.y(), dim.xLimit(), dim.yLimit(), isHovered(), isAvailable()); + drawButtonRect(matrices, getDimension().x(), getDimension().y(), getDimension().xLimit(), getDimension().yLimit(), isHovered(), isAvailable()); matrices.push(); - matrices.translate(dim.x() + getXPadding(), getTextY(), 0); + matrices.translate(getDimension().x() + getXPadding(), getTextY(), 0); textRenderer.drawWithShadow(matrices, shortenedName, 0, 0, getValueColor()); matrices.pop(); @@ -64,7 +64,7 @@ public abstract class ControllerWidget> extends Abstract @Override public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { if (hovered) { - YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, dim.centerX(), dim.y() - 5, dim.yLimit() + 5, screen.width, screen.height); + YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); } } @@ -75,7 +75,7 @@ public abstract class ControllerWidget> extends Abstract protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { Text valueText = getValueText(); matrices.push(); - matrices.translate(dim.xLimit() - textRenderer.getWidth(valueText) - getXPadding(), getTextY(), 0); + matrices.translate(getDimension().xLimit() - textRenderer.getWidth(valueText) - getXPadding(), getTextY(), 0); textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); matrices.pop(); } @@ -118,6 +118,11 @@ public abstract class ControllerWidget> extends Abstract return isAvailable() ? -1 : inactiveColor; } + @Override + public boolean canReset() { + return true; + } + protected void drawOutline(MatrixStack matrices, int x1, int y1, int x2, int y2, int width, int color) { DrawableHelper.fill(matrices, x1, y1, x2, y1 + width, color); DrawableHelper.fill(matrices, x2, y1, x2 - width, y2, color); @@ -126,7 +131,7 @@ public abstract class ControllerWidget> extends Abstract } protected float getTextY() { - return dim.y() + dim.height() / 2f - textRenderer.fontHeight / 2f; + return getDimension().y() + getDimension().height() / 2f - textRenderer.fontHeight / 2f; } @Override diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java b/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java index 98f69e1..8369680 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java @@ -62,9 +62,9 @@ public class LabelController implements Controller { public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { updateText(); - float y = dim.y(); + float y = getDimension().y(); for (OrderedText text : wrappedText) { - textRenderer.drawWithShadow(matrices, text, dim.x(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); + textRenderer.drawWithShadow(matrices, text, getDimension().x(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); y += textRenderer.fontHeight; } } @@ -72,7 +72,7 @@ public class LabelController implements Controller { @Override public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { if (isMouseOver(mouseX, mouseY)) { - YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, dim.centerX(), dim.y() - 5, dim.yLimit() + 5, screen.width, screen.height); + YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); Style style = getStyle(mouseX, mouseY); if (style != null && style.getHoverEvent() != null) { @@ -90,8 +90,8 @@ public class LabelController implements Controller { } else { Text text = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); if (text != null) { - MultilineText multilineText = MultilineText.create(textRenderer, text, dim.width()); - YACLScreen.renderMultilineTooltip(matrices, textRenderer, multilineText, dim.centerX(), dim.y(), dim.yLimit(), screen.width, screen.height); + MultilineText multilineText = MultilineText.create(textRenderer, text, getDimension().width()); + YACLScreen.renderMultilineTooltip(matrices, textRenderer, multilineText, getDimension().centerX(), getDimension().y(), getDimension().yLimit(), screen.width, screen.height); } } } @@ -109,15 +109,15 @@ public class LabelController implements Controller { } protected Style getStyle(int mouseX, int mouseY) { - if (!dim.isPointInside(mouseX, mouseY)) + if (!getDimension().isPointInside(mouseX, mouseY)) return null; - int x = mouseX - dim.x(); - int y = mouseY - dim.y() - getYPadding(); + int x = mouseX - getDimension().x(); + int y = mouseY - getDimension().y() - getYPadding(); int line = y / textRenderer.fontHeight; - if (x < 0 || x > dim.xLimit()) return null; - if (y < 0 || y > dim.yLimit()) return null; + if (x < 0 || x > getDimension().xLimit()) return null; + if (y < 0 || y > getDimension().yLimit()) return null; if (line < 0 || line >= wrappedText.size()) return null; return textRenderer.getTextHandler().getStyleAt(wrappedText.get(line), x); @@ -128,8 +128,8 @@ public class LabelController implements Controller { } private void updateText() { - wrappedText = textRenderer.wrapLines(formatValue(), dim.width()); - dim.setHeight(wrappedText.size() * textRenderer.fontHeight + getYPadding() * 2); + wrappedText = textRenderer.wrapLines(formatValue(), getDimension().width()); + setDimension(getDimension().withHeight(wrappedText.size() * textRenderer.fontHeight + getYPadding() * 2)); } private void updateTooltip() { 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 ece6bce..ff693a9 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -8,7 +8,6 @@ import dev.isxander.yacl.gui.YACLScreen; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; -import org.jetbrains.annotations.ApiStatus; import org.lwjgl.glfw.GLFW; /** @@ -58,10 +57,10 @@ public class TickBoxController implements Controller { @Override protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { int outlineSize = 10; - int outlineX1 = dim.xLimit() - getXPadding() - outlineSize; - int outlineY1 = dim.centerY() - outlineSize / 2; - int outlineX2 = dim.xLimit() - getXPadding(); - int outlineY2 = dim.centerY() + outlineSize / 2; + int outlineX1 = getDimension().xLimit() - getXPadding() - outlineSize; + int outlineY1 = getDimension().centerY() - outlineSize / 2; + int outlineX2 = getDimension().xLimit() - getXPadding(); + int outlineY2 = getDimension().centerY() + outlineSize / 2; int color = getValueColor(); int shadowColor = multiplyColor(color, 0.25f); diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index 8598172..0c3b7c9 100644 --- a/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -205,7 +205,7 @@ public class StringControllerElement extends ControllerWidget>, BiConsumer> changedListener) { diff --git a/src/main/java/dev/isxander/yacl/impl/OptionImpl.java b/src/main/java/dev/isxander/yacl/impl/OptionImpl.java index 98a2f48..c76f115 100644 --- a/src/main/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/main/java/dev/isxander/yacl/impl/OptionImpl.java @@ -125,12 +125,17 @@ public class OptionImpl implements Option { @Override public void forgetPendingValue() { - pendingValue = binding().getValue(); + requestSet(binding().getValue()); } @Override public void requestSetDefault() { - pendingValue = binding().defaultValue(); + requestSet(binding().defaultValue()); + } + + @Override + public boolean isPendingValueDefault() { + return binding().defaultValue().equals(pendingValue()); } @Override diff --git a/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java b/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java index 76a5868..6c7508d 100644 --- a/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java +++ b/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java @@ -1,8 +1,9 @@ package dev.isxander.yacl.impl.utils; import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.api.utils.MutableDimension; -public class DimensionIntegerImpl implements Dimension { +public class DimensionIntegerImpl implements MutableDimension { private int x, y; private int width, height; @@ -59,14 +60,14 @@ public class DimensionIntegerImpl implements Dimension { } @Override - public Dimension clone() { + public MutableDimension clone() { return new DimensionIntegerImpl(x, y, width, height); } - @Override public Dimension setX(Integer x) { this.x = x; return this; } - @Override public Dimension setY(Integer y) { this.y = y; return this; } - @Override public Dimension setWidth(Integer width) { this.width = width; return this; } - @Override public Dimension setHeight(Integer height) { this.height = height; return this; } + @Override public MutableDimension setX(Integer x) { this.x = x; return this; } + @Override public MutableDimension setY(Integer y) { this.y = y; return this; } + @Override public MutableDimension setWidth(Integer width) { this.width = width; return this; } + @Override public MutableDimension setHeight(Integer height) { this.height = height; return this; } @Override public Dimension withX(Integer x) { @@ -80,23 +81,23 @@ public class DimensionIntegerImpl implements Dimension { @Override public Dimension withWidth(Integer width) { - return clone().withWidth(width); + return clone().setWidth(width); } @Override public Dimension withHeight(Integer height) { - return clone().withHeight(height); + return clone().setHeight(height); } @Override - public Dimension move(Integer x, Integer y) { + public MutableDimension move(Integer x, Integer y) { this.x += x; this.y += y; return this; } @Override - public Dimension expand(Integer width, Integer height) { + public MutableDimension expand(Integer width, Integer height) { this.width += width; this.height += height; return this; -- cgit