diff options
author | isXander <xandersmith2008@gmail.com> | 2023-05-05 20:14:16 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-05-05 20:14:16 +0100 |
commit | 5b368af9efcc1c587c608d014e9dc79bcc3c691c (patch) | |
tree | 7a98f1074f013dc58fd0ec52d808098df88c4b64 /common/src/main | |
parent | 341bb7f507ee36d9727e17362559eaaa20e73b9b (diff) | |
download | YetAnotherConfigLib-5b368af9efcc1c587c608d014e9dc79bcc3c691c.tar.gz YetAnotherConfigLib-5b368af9efcc1c587c608d014e9dc79bcc3c691c.tar.bz2 YetAnotherConfigLib-5b368af9efcc1c587c608d014e9dc79bcc3c691c.zip |
improve compat with controlify
Diffstat (limited to 'common/src/main')
3 files changed, 16 insertions, 20 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java b/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java index a73ce43..d2d1b71 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -273,7 +273,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr this.groupName = group.name().getString().toLowerCase(); if (option.canResetToDefault() && this.widget.canReset()) { this.widget.setDimension(this.widget.getDimension().expanded(-20, 0)); - this.resetButton = new TextScaledButtonWidget(widget.getDimension().xLimit(), -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { + this.resetButton = new TextScaledButtonWidget(yaclScreen, widget.getDimension().xLimit(), -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { option.requestSetDefault(); }); option.addListener((opt, val) -> this.resetButton.active = !opt.isPendingValueDefault() && opt.available()); @@ -469,7 +469,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr super(group, screen); this.listOption = group; - this.resetListButton = new TextScaledButtonWidget(getRowRight() - 20, -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { + this.resetListButton = new TextScaledButtonWidget(screen, getRowRight() - 20, -50, 20, 20, 2f, Component.literal("\u21BB"), button -> { group.requestSetDefault(); }); group.addListener((opt, val) -> this.resetListButton.active = !opt.isPendingValueDefault() && opt.available()); diff --git a/common/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java b/common/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java index b955912..ac58db6 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java @@ -3,22 +3,20 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Tooltip; +import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; -public class TextScaledButtonWidget extends Button { +public class TextScaledButtonWidget extends TooltipButtonWidget { public float textScale; - public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Component message, OnPress onPress) { - super(x, y, width, height, message, onPress, DEFAULT_NARRATION); + public TextScaledButtonWidget(Screen screen, int x, int y, int width, int height, float textScale, Component message, Component tooltip, OnPress onPress) { + super(screen, x, y, width, height, message, tooltip, onPress); this.textScale = textScale; } - public TextScaledButtonWidget(int x, int y, int width, int height, float textScale, Component message, OnPress onPress, Tooltip tooltip) { - this(x, y, width, height, textScale, message, onPress); - setTooltip(tooltip); + public TextScaledButtonWidget(Screen screen, int x, int y, int width, int height, float textScale, Component message, OnPress onPress) { + this(screen, x, y, width, height, textScale, message, null, onPress); } @Override diff --git a/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java b/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java index 3b5b6fc..c8f3cf2 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java @@ -2,27 +2,25 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.MultiLineLabel; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; -public class TooltipButtonWidget extends TextScaledButtonWidget { +public class TooltipButtonWidget extends Button { protected final Screen screen; - protected MultiLineLabel wrappedDescription; - - public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, float textScale, Component tooltip, OnPress onPress) { - super(x, y, width, height, textScale, message, onPress); - this.screen = screen; - setTooltip(tooltip); - } + protected MultiLineLabel wrappedDescription = null; public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, Component tooltip, OnPress onPress) { - this(screen, x, y, width, height, message, 1, tooltip, onPress); + super(x, y, width, height, message, onPress, DEFAULT_NARRATION); + this.screen = screen; + if (tooltip != null) + setTooltip(tooltip); } public void renderHoveredTooltip(PoseStack matrices) { - if (isHoveredOrFocused()) { + if (isHoveredOrFocused() && wrappedDescription != null) { YACLScreen.renderMultilineTooltip(matrices, Minecraft.getInstance().font, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height); } } |