diff options
author | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-01-19 21:15:26 +0000 |
commit | ee53b51a1e8d88085c75f227f4710b68c03b19c8 (patch) | |
tree | 77a942242a982757da040a6120950bad30e49f77 /src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java | |
parent | ffdd6e5ceacd71c76c55a8716702d4d6da17c7ab (diff) | |
download | YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.gz YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.bz2 YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.zip |
mojmap
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index ae54ca4..90c0e20 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -1,27 +1,27 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.gui.screen.narration.NarrationPart; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.narration.NarratedElementType; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; public abstract class ControllerWidget<T extends Controller<?>> extends AbstractWidget { protected final T control; - protected MultilineText wrappedTooltip; + protected MultiLineLabel wrappedTooltip; protected final YACLScreen screen; protected boolean focused = false; protected boolean hovered = false; - protected final Text modifiedOptionName; + protected final Component modifiedOptionName; protected final String optionNameString; public ControllerWidget(T control, YACLScreen screen, Dimension<Integer> dim) { @@ -30,22 +30,22 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract this.screen = screen; control.option().addListener((opt, pending) -> updateTooltip()); updateTooltip(); - this.modifiedOptionName = control.option().name().copy().formatted(Formatting.ITALIC); + this.modifiedOptionName = control.option().name().copy().withStyle(ChatFormatting.ITALIC); this.optionNameString = control.option().name().getString().toLowerCase(); } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { hovered = isMouseOver(mouseX, mouseY); - Text name = control.option().changed() ? modifiedOptionName : control.option().name(); - Text shortenedName = Text.literal(GuiUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); + Component name = control.option().changed() ? modifiedOptionName : control.option().name(); + Component shortenedName = Component.literal(GuiUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).setStyle(name.getStyle()); drawButtonRect(matrices, getDimension().x(), getDimension().y(), getDimension().xLimit(), getDimension().yLimit(), isHovered(), isAvailable()); - matrices.push(); + matrices.pushPose(); matrices.translate(getDimension().x() + getXPadding(), getTextY(), 0); - textRenderer.drawWithShadow(matrices, shortenedName, 0, 0, getValueColor()); - matrices.pop(); + textRenderer.drawShadow(matrices, shortenedName, 0, 0, getValueColor()); + matrices.popPose(); drawValueText(matrices, mouseX, mouseY, delta); if (isHovered()) { @@ -54,26 +54,26 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if (hovered || focused) { YACLScreen.renderMultilineTooltip(matrices, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); } } - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { - Text valueText = getValueText(); - matrices.push(); - matrices.translate(getDimension().xLimit() - textRenderer.getWidth(valueText) - getXPadding(), getTextY(), 0); - textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); - matrices.pop(); + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { + Component valueText = getValueText(); + matrices.pushPose(); + matrices.translate(getDimension().xLimit() - textRenderer.width(valueText) - getXPadding(), getTextY(), 0); + textRenderer.drawShadow(matrices, valueText, 0, 0, getValueColor()); + matrices.popPose(); } private void updateTooltip() { - this.wrappedTooltip = MultilineText.create(textRenderer, control.option().tooltip(), screen.width / 3 * 2 - 10); + this.wrappedTooltip = MultiLineLabel.create(textRenderer, control.option().tooltip(), screen.width / 3 * 2 - 10); } protected int getControlWidth() { @@ -87,7 +87,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract protected abstract int getHoveredControlWidth(); protected int getUnhoveredControlWidth() { - return textRenderer.getWidth(getValueText()); + return textRenderer.width(getValueText()); } protected int getXPadding() { @@ -98,7 +98,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract return 2; } - protected Text getValueText() { + protected Component getValueText() { return control.formatValue(); } @@ -115,15 +115,15 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract 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); - DrawableHelper.fill(matrices, x1, y2, x2, y2 - width, color); - DrawableHelper.fill(matrices, x1, y1, x1 + width, y2, color); + protected void drawOutline(PoseStack matrices, int x1, int y1, int x2, int y2, int width, int color) { + GuiComponent.fill(matrices, x1, y1, x2, y1 + width, color); + GuiComponent.fill(matrices, x2, y1, x2 - width, y2, color); + GuiComponent.fill(matrices, x1, y2, x2, y2 - width, color); + GuiComponent.fill(matrices, x1, y1, x1 + width, y2, color); } protected float getTextY() { - return getDimension().y() + getDimension().height() / 2f - textRenderer.fontHeight / 2f; + return getDimension().y() + getDimension().height() / 2f - textRenderer.lineHeight / 2f; } @Override @@ -146,13 +146,13 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract } @Override - public SelectionType getType() { - return focused ? SelectionType.FOCUSED : isHovered() ? SelectionType.HOVERED : SelectionType.NONE; + public NarrationPriority narrationPriority() { + return focused ? NarrationPriority.FOCUSED : isHovered() ? NarrationPriority.HOVERED : NarrationPriority.NONE; } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - builder.put(NarrationPart.TITLE, control.option().name()); - builder.put(NarrationPart.HINT, control.option().tooltip()); + public void updateNarration(NarrationElementOutput builder) { + builder.add(NarratedElementType.TITLE, control.option().name()); + builder.add(NarratedElementType.HINT, control.option().tooltip()); } } |