aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/dev/isxander/yacl/api/Controller.java1
-rw-r--r--src/main/java/dev/isxander/yacl/api/Option.java5
-rw-r--r--src/main/java/dev/isxander/yacl/api/utils/Dimension.java12
-rw-r--r--src/main/java/dev/isxander/yacl/api/utils/MutableDimension.java11
-rw-r--r--src/main/java/dev/isxander/yacl/config/ConfigInstance.java11
-rw-r--r--src/main/java/dev/isxander/yacl/config/YACLConfigManager.java38
-rw-r--r--src/main/java/dev/isxander/yacl/gui/AbstractWidget.java6
-rw-r--r--src/main/java/dev/isxander/yacl/gui/OptionListWidget.java66
-rw-r--r--src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java43
-rw-r--r--src/main/java/dev/isxander/yacl/gui/YACLScreen.java3
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/ActionController.java5
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java1
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java3
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java17
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java24
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/TickBoxController.java9
-rw-r--r--src/main/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java2
-rw-r--r--src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java5
-rw-r--r--src/main/java/dev/isxander/yacl/impl/OptionImpl.java9
-rw-r--r--src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java21
20 files changed, 229 insertions, 63 deletions
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
@@ -105,6 +105,11 @@ public interface Option<T> {
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<Option<T>, T> changedListener);
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<T extends Number> {
boolean isPointInside(T x, T y);
- Dimension<T> clone();
-
- Dimension<T> setX(T x);
- Dimension<T> setY(T y);
- Dimension<T> setWidth(T width);
- Dimension<T> setHeight(T height);
+ MutableDimension<T> clone();
Dimension<T> withX(T x);
Dimension<T> withY(T y);
Dimension<T> withWidth(T width);
Dimension<T> withHeight(T height);
- Dimension<T> move(T x, T y);
- Dimension<T> expand(T width, T height);
-
Dimension<T> moved(T x, T y);
Dimension<T> expanded(T width, T height);
- static Dimension<Integer> ofInt(int x, int y, int width, int height) {
+ static MutableDimension<Integer> 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<T extends Number> extends Dimension<T> {
+ MutableDimension<T> setX(T x);
+ MutableDimension<T> setY(T y);
+ MutableDimension<T> setWidth(T width);
+ MutableDimension<T> setHeight(T height);
+
+ MutableDimension<T> move(T x, T y);
+ MutableDimension<T> 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 <T> config data type
+ */
public abstract class ConfigInstance<T> {
private final Class<T> configClass;
private final T defaultInstance;
@@ -18,7 +28,6 @@ public abstract class ConfigInstance<T> {
} 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<Class<?>, ConfigInstance<?>> configs = new HashMap<>();
+ /**
+ * Registers and loads a config instance
+ *
+ * @param configInstance config to register
+ * @param <T> config data type
+ */
public static <T> void register(ConfigInstance<T> configInstance) {
configs.put(configInstance.getConfigClass(), configInstance);
configInstance.load();
}
+ /**
+ * Retrieves config data for a certain config.
+ * <p>
+ * Shorthand of {@code YACLConfigManager.getConfigInstance(configClass).getConfig()}
+ *
+ * @param configClass config data to get
+ * @return config data
+ * @param <T> config data type
+ */
public static <T> T getConfigData(Class<T> configClass) {
return ((ConfigInstance<T>) 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 <T> config data type
+ */
public static <T> ConfigInstance<T> getConfigInstance(Class<T> configClass) {
return (ConfigInstance<T>) configs.get(configClass);
}
- public static <T, I extends ConfigInstance<T>> I getConfigInstanceType(Class<T> 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 <T> config data type
+ * @param <U> config instance type
+ */
+ public static <T, U extends ConfigInstance<T>> U getConfigInstanceType(Class<T> 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<Integer> dim;
+ private Dimension<Integer> dim;
public AbstractWidget(Dimension<Integer> 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<OptionListWidget.Entry>
private ImmutableList<Entry> 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<OptionListWidget.Entry>
List<OptionEntry> 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<OptionListWidget.Entry>
}
}
+ /* 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<OptionListWidget.Entry>
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<OptionListWidget.Entry>
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<OptionListWidget.Entry>
}
public class OptionEntry extends Entry {
+ public final Option<?> option;
public final ConfigCategory category;
public final OptionGroup group;
public final AbstractWidget widget;
private final Supplier<Boolean> viewableSupplier;
+ private final TextScaledButtonWidget resetButton;
+
private final String categoryName;
private final String groupName;
- private OptionEntry(ConfigCategory category, OptionGroup group, AbstractWidget widget, Supplier<Boolean> viewableSupplier) {
+ private OptionEntry(Option<?> option, ConfigCategory category, OptionGroup group, AbstractWidget widget, Supplier<Boolean> 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<OptionListWidget.Entry>
@Override
public List<? extends Selectable> selectableChildren() {
- return ImmutableList.of(widget);
+ if (resetButton == null)
+ return ImmutableList.of(widget);
+
+ return ImmutableList.of(widget, resetButton);
}
@Override
public List<? extends Element> 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<Integer> actionDim = Dimension.ofInt(width / 3 / 2, height - padding - 20, paddedWidth, 20);
+ MutableDimension<Integer> 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
@@ -108,6 +108,11 @@ public class ActionController implements Controller<BiConsumer<YACLScreen, Butto
}
@Override
+ public boolean canReset() {
+ return false;
+ }
+
+ @Override
public boolean matchesSearch(String query) {
return super.matchesSearch(query) || buttonString.contains(query);
}
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 cea6028..b7a77dd 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/BooleanController.java
@@ -8,7 +8,6 @@ import dev.isxander.yacl.gui.YACLScreen;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
-import org.jetbrains.annotations.ApiStatus;
import org.lwjgl.glfw.GLFW;
import java.util.function.Function;
diff --git a/src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java b/src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java
index 11e33d0..0a83fbe 100644
--- a/src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java
+++ b/src/main/java/dev/isxander/yacl/gui/controllers/ColorController.java
@@ -3,6 +3,7 @@ package dev.isxander.yacl.gui.controllers;
import com.google.common.collect.ImmutableList;
import dev.isxander.yacl.api.Option;
import dev.isxander.yacl.api.utils.Dimension;
+import dev.isxander.yacl.api.utils.MutableDimension;
import dev.isxander.yacl.gui.AbstractWidget;
import dev.isxander.yacl.gui.YACLScreen;
import dev.isxander.yacl.gui.controllers.string.IStringController;
@@ -102,7 +103,7 @@ public class ColorController implements IStringController<Color> {
public static class ColorControllerElement extends StringControllerElement {
private final ColorController colorController;
- protected Dimension<Integer> colorPreviewDim;
+ protected MutableDimension<Integer> colorPreviewDim;
private final List<Character> 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<T extends Controller<?>> 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<T extends Controller<?>> 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<T extends Controller<?>> 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<T extends Controller<?>> 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<T extends Controller<?>> 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<T extends Controller<?>> 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<Text> {
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<Text> {
@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<Text> {
} 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<Text> {
}
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<Text> {
}
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<Boolean> {
@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<IStringController<
}
public int getMaxLength() {
- return dim.width() / 8 * 7;
+ return getDimension().width() / 8 * 7;
}
public int getSelectionStart() {
diff --git a/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java b/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
index 7d856b0..dcb9c7a 100644
--- a/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
+++ b/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java
@@ -114,6 +114,11 @@ public class ButtonOptionImpl implements ButtonOption {
}
@Override
+ public boolean isPendingValueDefault() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
public void addListener(BiConsumer<Option<BiConsumer<YACLScreen, ButtonOption>>, BiConsumer<YACLScreen, ButtonOption>> 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<T> implements Option<T> {
@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<Integer> {
+public class DimensionIntegerImpl implements MutableDimension<Integer> {
private int x, y;
private int width, height;
@@ -59,14 +60,14 @@ public class DimensionIntegerImpl implements Dimension<Integer> {
}
@Override
- public Dimension<Integer> clone() {
+ public MutableDimension<Integer> clone() {
return new DimensionIntegerImpl(x, y, width, height);
}
- @Override public Dimension<Integer> setX(Integer x) { this.x = x; return this; }
- @Override public Dimension<Integer> setY(Integer y) { this.y = y; return this; }
- @Override public Dimension<Integer> setWidth(Integer width) { this.width = width; return this; }
- @Override public Dimension<Integer> setHeight(Integer height) { this.height = height; return this; }
+ @Override public MutableDimension<Integer> setX(Integer x) { this.x = x; return this; }
+ @Override public MutableDimension<Integer> setY(Integer y) { this.y = y; return this; }
+ @Override public MutableDimension<Integer> setWidth(Integer width) { this.width = width; return this; }
+ @Override public MutableDimension<Integer> setHeight(Integer height) { this.height = height; return this; }
@Override
public Dimension<Integer> withX(Integer x) {
@@ -80,23 +81,23 @@ public class DimensionIntegerImpl implements Dimension<Integer> {
@Override
public Dimension<Integer> withWidth(Integer width) {
- return clone().withWidth(width);
+ return clone().setWidth(width);
}
@Override
public Dimension<Integer> withHeight(Integer height) {
- return clone().withHeight(height);
+ return clone().setHeight(height);
}
@Override
- public Dimension<Integer> move(Integer x, Integer y) {
+ public MutableDimension<Integer> move(Integer x, Integer y) {
this.x += x;
this.y += y;
return this;
}
@Override
- public Dimension<Integer> expand(Integer width, Integer height) {
+ public MutableDimension<Integer> expand(Integer width, Integer height) {
this.width += width;
this.height += height;
return this;