From 5b368af9efcc1c587c608d014e9dc79bcc3c691c Mon Sep 17 00:00:00 2001 From: isXander Date: Fri, 5 May 2023 20:14:16 +0100 Subject: improve compat with controlify --- .../java/dev/isxander/yacl/gui/OptionListWidget.java | 4 ++-- .../dev/isxander/yacl/gui/TextScaledButtonWidget.java | 14 ++++++-------- .../dev/isxander/yacl/gui/TooltipButtonWidget.java | 18 ++++++++---------- 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'common/src/main') 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 { + 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 { + 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); } } -- cgit