From ee53b51a1e8d88085c75f227f4710b68c03b19c8 Mon Sep 17 00:00:00 2001 From: isXander Date: Thu, 19 Jan 2023 21:15:26 +0000 Subject: mojmap --- .../yacl/gui/controllers/ActionController.java | 14 ++-- .../yacl/gui/controllers/BooleanController.java | 47 +++++++------ .../yacl/gui/controllers/ColorController.java | 24 +++---- .../yacl/gui/controllers/ControllerWidget.java | 76 ++++++++++---------- .../yacl/gui/controllers/LabelController.java | 61 +++++++++-------- .../yacl/gui/controllers/ListEntryWidget.java | 34 ++++----- .../yacl/gui/controllers/TickBoxController.java | 22 +++--- .../cycling/CyclingControllerElement.java | 10 +-- .../controllers/cycling/CyclingListController.java | 10 +-- .../gui/controllers/cycling/EnumController.java | 22 +++--- .../controllers/slider/DoubleSliderController.java | 12 ++-- .../controllers/slider/FloatSliderController.java | 12 ++-- .../slider/IntegerSliderController.java | 12 ++-- .../controllers/slider/LongSliderController.java | 12 ++-- .../slider/SliderControllerElement.java | 40 +++++------ .../gui/controllers/string/IStringController.java | 6 +- .../string/StringControllerElement.java | 80 +++++++++++----------- .../string/number/DoubleFieldController.java | 7 +- .../string/number/FloatFieldController.java | 7 +- .../string/number/IntegerFieldController.java | 6 +- .../string/number/LongFieldController.java | 6 +- .../string/number/NumberFieldController.java | 12 ++-- 22 files changed, 266 insertions(+), 266 deletions(-) (limited to 'src/client/java/dev/isxander/yacl/gui/controllers') diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java b/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java index 7666dff..e57cdd2 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java @@ -1,12 +1,12 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.yacl.api.ButtonOption; 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 net.minecraft.client.util.InputUtil; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.BiConsumer; @@ -15,10 +15,10 @@ import java.util.function.BiConsumer; * and renders a {@link} Text on the right. */ public class ActionController implements Controller> { - public static final Text DEFAULT_TEXT = Text.translatable("yacl.control.action.execute"); + public static final Component DEFAULT_TEXT = Component.translatable("yacl.control.action.execute"); private final ButtonOption option; - private final Text text; + private final Component text; /** * Constructs an action controller @@ -36,7 +36,7 @@ public class ActionController implements Controller { - public static final Function ON_OFF_FORMATTER = (state) -> + public static final Function ON_OFF_FORMATTER = (state) -> state - ? ScreenTexts.ON - : ScreenTexts.OFF; + ? CommonComponents.OPTION_ON + : CommonComponents.OPTION_OFF; - public static final Function TRUE_FALSE_FORMATTER = (state) -> + public static final Function TRUE_FALSE_FORMATTER = (state) -> state - ? Text.translatable("yacl.control.boolean.true") - : Text.translatable("yacl.control.boolean.false"); + ? Component.translatable("yacl.control.boolean.true") + : Component.translatable("yacl.control.boolean.false"); - public static final Function YES_NO_FORMATTER = (state) -> + public static final Function YES_NO_FORMATTER = (state) -> state - ? ScreenTexts.YES - : ScreenTexts.NO; + ? CommonComponents.GUI_YES + : CommonComponents.GUI_NO; private final Option option; - private final Function valueFormatter; + private final Function valueFormatter; private final boolean coloured; /** @@ -63,10 +62,10 @@ public class BooleanController implements Controller { * Constructs a tickbox controller * * @param option bound option - * @param valueFormatter format value into any {@link Text} + * @param valueFormatter format value into any {@link Component} * @param coloured value format is green or red depending on the state */ - public BooleanController(Option option, Function valueFormatter, boolean coloured) { + public BooleanController(Option option, Function valueFormatter, boolean coloured) { this.option = option; this.valueFormatter = valueFormatter; this.coloured = coloured; @@ -84,7 +83,7 @@ public class BooleanController implements Controller { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } @@ -109,7 +108,7 @@ public class BooleanController implements Controller { } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } @@ -133,9 +132,9 @@ public class BooleanController implements Controller { } @Override - protected Text getValueText() { + protected Component getValueText() { if (control.coloured()) { - return super.getValueText().copy().formatted(control.option().pendingValue() ? Formatting.GREEN : Formatting.RED); + return super.getValueText().copy().withStyle(control.option().pendingValue() ? ChatFormatting.GREEN : ChatFormatting.RED); } return super.getValueText(); @@ -147,7 +146,7 @@ public class BooleanController implements Controller { return false; } - if (keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_SPACE || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { + if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) { toggleSetting(); return true; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java index 9626a9e..473407b 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java @@ -1,6 +1,7 @@ package dev.isxander.yacl.gui.controllers; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.MutableDimension; @@ -8,11 +9,10 @@ import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.string.IStringController; import dev.isxander.yacl.gui.controllers.string.StringControllerElement; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import java.awt.Color; import java.util.List; @@ -62,11 +62,11 @@ public class ColorController implements IStringController { } @Override - public Text formatValue() { - MutableText text = Text.literal("#"); - text.append(Text.literal(toHex(option().pendingValue().getRed())).formatted(Formatting.RED)); - text.append(Text.literal(toHex(option().pendingValue().getGreen())).formatted(Formatting.GREEN)); - text.append(Text.literal(toHex(option().pendingValue().getBlue())).formatted(Formatting.BLUE)); + public Component formatValue() { + MutableComponent text = Component.literal("#"); + text.append(Component.literal(toHex(option().pendingValue().getRed())).withStyle(ChatFormatting.RED)); + text.append(Component.literal(toHex(option().pendingValue().getGreen())).withStyle(ChatFormatting.GREEN)); + text.append(Component.literal(toHex(option().pendingValue().getBlue())).withStyle(ChatFormatting.BLUE)); if (allowAlpha()) text.append(toHex(option().pendingValue().getAlpha())); return text; } @@ -114,13 +114,13 @@ public class ColorController implements IStringController { } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { if (isHovered()) { colorPreviewDim.move(-inputFieldBounds.width() - 5, 0); super.drawValueText(matrices, mouseX, mouseY, delta); } - DrawableHelper.fill(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), colorController.option().pendingValue().getRGB()); + GuiComponent.fill(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), colorController.option().pendingValue().getRGB()); drawOutline(matrices, colorPreviewDim.x(), colorPreviewDim.y(), colorPreviewDim.xLimit(), colorPreviewDim.yLimit(), 1, 0xFF000000); } 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> 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 dim) { @@ -30,22 +30,22 @@ public abstract class ControllerWidget> 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> 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> 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> extends Abstract return 2; } - protected Text getValueText() { + protected Component getValueText() { return control.formatValue(); } @@ -115,15 +115,15 @@ public abstract class ControllerWidget> 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> 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()); } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java index 960c950..0017b59 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java @@ -1,28 +1,31 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.font.MultilineText; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; -import net.minecraft.text.*; +import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.util.FormattedCharSequence; +import net.minecraft.world.item.ItemStack; import java.util.List; /** * Simply renders some text as a label. */ -public class LabelController implements Controller { - private final Option option; +public class LabelController implements Controller { + private final Option option; /** * Constructs a label controller * * @param option bound option */ - public LabelController(Option option) { + public LabelController(Option option) { this.option = option; } @@ -30,12 +33,12 @@ public class LabelController implements Controller { * {@inheritDoc} */ @Override - public Option option() { + public Option option() { return option; } @Override - public Text formatValue() { + public Component formatValue() { return option().pendingValue(); } @@ -45,8 +48,8 @@ public class LabelController implements Controller { } public class LabelControllerElement extends AbstractWidget { - private List wrappedText; - protected MultilineText wrappedTooltip; + private List wrappedText; + protected MultiLineLabel wrappedTooltip; protected final YACLScreen screen; @@ -59,38 +62,38 @@ public class LabelController implements Controller { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { updateText(); float y = getDimension().y(); - for (OrderedText text : wrappedText) { - textRenderer.drawWithShadow(matrices, text, getDimension().x() + getXPadding(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); - y += textRenderer.fontHeight; + for (FormattedCharSequence text : wrappedText) { + textRenderer.drawShadow(matrices, text, getDimension().x() + getXPadding(), y + getYPadding(), option().available() ? -1 : 0xFFA0A0A0); + y += textRenderer.lineHeight; } } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { if (isMouseOver(mouseX, mouseY)) { 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) { HoverEvent hoverEvent = style.getHoverEvent(); - HoverEvent.ItemStackContent itemStackContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ITEM); + HoverEvent.ItemStackInfo itemStackContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ITEM); if (itemStackContent != null) { - ItemStack stack = itemStackContent.asStack(); - screen.renderTooltip(matrices, screen.getTooltipFromItem(stack), stack.getTooltipData(), mouseX, mouseY); + ItemStack stack = itemStackContent.getItemStack(); + screen.renderTooltip(matrices, screen.getTooltipFromItem(stack), stack.getTooltipImage(), mouseX, mouseY); } else { - HoverEvent.EntityContent entityContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ENTITY); + HoverEvent.EntityTooltipInfo entityContent = hoverEvent.getValue(HoverEvent.Action.SHOW_ENTITY); if (entityContent != null) { if (this.client.options.advancedItemTooltips) { - screen.renderTooltip(matrices, entityContent.asTooltip(), mouseX, mouseY); + screen.renderComponentTooltip(matrices, entityContent.getTooltipLines(), mouseX, mouseY); } } else { - Text text = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); + Component text = hoverEvent.getValue(HoverEvent.Action.SHOW_TEXT); if (text != null) { - MultilineText multilineText = MultilineText.create(textRenderer, text, getDimension().width()); + MultiLineLabel multilineText = MultiLineLabel.create(textRenderer, text, getDimension().width()); YACLScreen.renderMultilineTooltip(matrices, textRenderer, multilineText, getDimension().centerX(), getDimension().y(), getDimension().yLimit(), screen.width, screen.height); } } @@ -105,7 +108,7 @@ public class LabelController implements Controller { return false; Style style = getStyle((int) mouseX, (int) mouseY); - return screen.handleTextClick(style); + return screen.handleComponentClicked(style); } protected Style getStyle(int mouseX, int mouseY) { @@ -114,13 +117,13 @@ public class LabelController implements Controller { int x = mouseX - getDimension().x(); int y = mouseY - getDimension().y() - getYPadding(); - int line = y / textRenderer.fontHeight; + int line = y / textRenderer.lineHeight; 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); + return textRenderer.getSplitter().componentStyleAtWidth(wrappedText.get(line), x); } private int getXPadding() { @@ -132,12 +135,12 @@ public class LabelController implements Controller { } private void updateText() { - wrappedText = textRenderer.wrapLines(formatValue(), getDimension().width() - getXPadding() * 2); - setDimension(getDimension().withHeight(wrappedText.size() * textRenderer.fontHeight + getYPadding() * 2)); + wrappedText = textRenderer.split(formatValue(), getDimension().width() - getXPadding() * 2); + setDimension(getDimension().withHeight(wrappedText.size() * textRenderer.lineHeight + getYPadding() * 2)); } private void updateTooltip() { - this.wrappedTooltip = MultilineText.create(textRenderer, option().tooltip(), screen.width / 3 * 2 - 10); + this.wrappedTooltip = MultiLineLabel.create(textRenderer, option().tooltip(), screen.width / 3 * 2 - 10); } @Override diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java index 0a5d581..1acccf1 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java @@ -1,20 +1,20 @@ package dev.isxander.yacl.gui.controllers; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.ListOption; import dev.isxander.yacl.api.ListOptionEntry; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.*; -import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.ParentElement; -import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.events.ContainerEventHandler; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.List; -public class ListEntryWidget extends AbstractWidget implements ParentElement { +public class ListEntryWidget extends AbstractWidget implements ContainerEventHandler { private final TooltipButtonWidget removeButton, moveUpButton, moveDownButton; private final AbstractWidget entryWidget; @@ -23,7 +23,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { private final String optionNameString; - private Element focused; + private GuiEventListener focused; private boolean dragging; public ListEntryWidget(YACLScreen screen, ListOptionEntry listOptionEntry, AbstractWidget entryWidget) { @@ -36,12 +36,12 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { Dimension dim = entryWidget.getDimension(); entryWidget.setDimension(dim.clone().move(20 * 2, 0).expand(-20 * 3, 0)); - removeButton = new TooltipButtonWidget(screen, dim.xLimit() - 20, dim.y(), 20, 20, Text.of("\u274c"), Text.translatable("yacl.list.remove"), btn -> { + removeButton = new TooltipButtonWidget(screen, dim.xLimit() - 20, dim.y(), 20, 20, Component.literal("\u274c"), Component.translatable("yacl.list.remove"), btn -> { listOption.removeEntry(listOptionEntry); updateButtonStates(); }); - moveUpButton = new TooltipButtonWidget(screen, dim.x(), dim.y(), 20, 20, Text.of("\u2191"), Text.translatable("yacl.list.move_up"), btn -> { + moveUpButton = new TooltipButtonWidget(screen, dim.x(), dim.y(), 20, 20, Component.literal("\u2191"), Component.translatable("yacl.list.move_up"), btn -> { int index = listOption.indexOf(listOptionEntry) - 1; if (index >= 0) { listOption.removeEntry(listOptionEntry); @@ -50,7 +50,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } }); - moveDownButton = new TooltipButtonWidget(screen, dim.x() + 20, dim.y(), 20, 20, Text.of("\u2193"), Text.translatable("yacl.list.move_down"), btn -> { + moveDownButton = new TooltipButtonWidget(screen, dim.x() + 20, dim.y(), 20, 20, Component.literal("\u2193"), Component.translatable("yacl.list.move_down"), btn -> { int index = listOption.indexOf(listOptionEntry) + 1; if (index < listOption.options().size()) { listOption.removeEntry(listOptionEntry); @@ -63,7 +63,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { updateButtonStates(); // update every render in case option becomes available/unavailable removeButton.setY(getDimension().y()); @@ -78,7 +78,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { removeButton.renderHoveredTooltip(matrices); moveUpButton.renderHoveredTooltip(matrices); moveDownButton.renderHoveredTooltip(matrices); @@ -96,8 +96,8 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public void appendNarrations(NarrationMessageBuilder builder) { - entryWidget.appendNarrations(builder); + public void updateNarration(NarrationElementOutput builder) { + entryWidget.updateNarration(builder); } @Override @@ -106,7 +106,7 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { } @Override - public List children() { + public List children() { return ImmutableList.of(moveUpButton, moveDownButton, entryWidget, removeButton); } @@ -122,12 +122,12 @@ public class ListEntryWidget extends AbstractWidget implements ParentElement { @Nullable @Override - public Element getFocused() { + public GuiEventListener getFocused() { return focused; } @Override - public void setFocused(@Nullable Element focused) { + public void setFocused(@Nullable GuiEventListener focused) { this.focused = focused; } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java b/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java index b0ae449..3f615db 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java @@ -1,14 +1,14 @@ package dev.isxander.yacl.gui.controllers; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.text.Text; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.network.chat.Component; /** * This controller renders a tickbox @@ -37,8 +37,8 @@ public class TickBoxController implements Controller { * {@inheritDoc} */ @Override - public Text formatValue() { - return Text.empty(); + public Component formatValue() { + return Component.empty(); } /** @@ -55,7 +55,7 @@ public class TickBoxController implements Controller { } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { int outlineSize = 10; int outlineX1 = getDimension().xLimit() - getXPadding() - outlineSize; int outlineY1 = getDimension().centerY() - outlineSize / 2; @@ -68,13 +68,13 @@ public class TickBoxController implements Controller { drawOutline(matrices, outlineX1 + 1, outlineY1 + 1, outlineX2 + 1, outlineY2 + 1, 1, shadowColor); drawOutline(matrices, outlineX1, outlineY1, outlineX2, outlineY2, 1, color); if (control.option().pendingValue()) { - DrawableHelper.fill(matrices, outlineX1 + 3, outlineY1 + 3, outlineX2 - 1, outlineY2 - 1, shadowColor); - DrawableHelper.fill(matrices, outlineX1 + 2, outlineY1 + 2, outlineX2 - 2, outlineY2 - 2, color); + GuiComponent.fill(matrices, outlineX1 + 3, outlineY1 + 3, outlineX2 - 1, outlineY2 - 1, shadowColor); + GuiComponent.fill(matrices, outlineX1 + 2, outlineY1 + 2, outlineX2 - 2, outlineY2 - 2, color); } } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { if (!isHovered()) drawHoveredControl(matrices, mouseX, mouseY, delta); } @@ -109,7 +109,7 @@ public class TickBoxController implements Controller { return false; } - if (keyCode == InputUtil.GLFW_KEY_ENTER || keyCode == InputUtil.GLFW_KEY_SPACE || keyCode == InputUtil.GLFW_KEY_KP_ENTER) { + if (keyCode == InputConstants.KEY_RETURN || keyCode == InputConstants.KEY_SPACE || keyCode == InputConstants.KEY_NUMPADENTER) { toggleSetting(); return true; } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java index 246fbec..b2fa776 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java @@ -1,10 +1,10 @@ package dev.isxander.yacl.gui.controllers.cycling; +import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; +import net.minecraft.client.gui.screens.Screen; public class CyclingControllerElement extends ControllerWidget> { @@ -39,11 +39,11 @@ public class CyclingControllerElement extends ControllerWidget + case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> cycleValue(-1); - case InputUtil.GLFW_KEY_RIGHT, InputUtil.GLFW_KEY_UP -> + case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> cycleValue(1); - case InputUtil.GLFW_KEY_ENTER, InputUtil.GLFW_KEY_SPACE, InputUtil.GLFW_KEY_KP_ENTER -> + case InputConstants.KEY_RETURN, InputConstants.KEY_SPACE, InputConstants.KEY_NUMPADENTER -> cycleValue(Screen.hasControlDown() || Screen.hasShiftDown() ? -1 : 1); default -> { return false; diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java index 3b14066..34f2cc9 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.cycling; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -12,7 +12,7 @@ import java.util.function.Function; */ public class CyclingListController implements ICyclingController { private final Option option; - private final Function valueFormatter; + private final Function valueFormatter; private final ImmutableList values; /** @@ -22,7 +22,7 @@ public class CyclingListController implements ICyclingController { * @param values the values to cycle through */ public CyclingListController(Option option, Iterable values) { - this(option, values, value -> Text.of(value.toString())); + this(option, values, value -> Component.literal(value.toString())); } /** @@ -31,7 +31,7 @@ public class CyclingListController implements ICyclingController { * @param values the values to cycle through * @param valueFormatter function of how to convert each value to a string to display */ - public CyclingListController(Option option, Iterable values, Function valueFormatter) { + public CyclingListController(Option option, Iterable values, Function valueFormatter) { this.option = option; this.valueFormatter = valueFormatter; this.values = ImmutableList.copyOf(values); @@ -49,7 +49,7 @@ public class CyclingListController implements ICyclingController { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java index bc9f46d..ebd2cb6 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java @@ -2,8 +2,8 @@ package dev.isxander.yacl.gui.controllers.cycling; import dev.isxander.yacl.api.NameableEnum; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; -import net.minecraft.util.TranslatableOption; +import net.minecraft.network.chat.Component; +import net.minecraft.util.OptionEnum; import java.util.Arrays; import java.util.function.Function; @@ -16,20 +16,20 @@ import java.util.function.Function; * @param enum type */ public class EnumController> extends CyclingListController { - public static > Function getDefaultFormatter() { + public static > Function getDefaultFormatter() { return value -> { if (value instanceof NameableEnum nameableEnum) return nameableEnum.getDisplayName(); - if (value instanceof TranslatableOption translatableOption) - return translatableOption.getText(); - return Text.of(value.toString()); + if (value instanceof OptionEnum translatableOption) + return translatableOption.getCaption(); + return Component.literal(value.toString()); }; } /** * Constructs a cycling enum controller with a default value formatter and all values being available. * The default value formatter first searches if the - * enum is a {@link NameableEnum} or {@link TranslatableOption} else, just uses {@link Enum#toString()} + * enum is a {@link NameableEnum} or {@link OptionEnum} else, just uses {@link Enum#toString()} * * @param option bound option */ @@ -41,9 +41,9 @@ public class EnumController> extends CyclingListController * Constructs a cycling enum controller with all values being available. * * @param option bound option - * @param valueFormatter format the enum into any {@link Text} + * @param valueFormatter format the enum into any {@link Component} */ - public EnumController(Option option, Function valueFormatter) { + public EnumController(Option option, Function valueFormatter) { this(option, valueFormatter, option.typeClass().getEnumConstants()); } @@ -51,10 +51,10 @@ public class EnumController> extends CyclingListController * Constructs a cycling enum controller. * * @param option bound option - * @param valueFormatter format the enum into any {@link Text} + * @param valueFormatter format the enum into any {@link Component} * @param availableValues all enum constants that can be cycled through */ - public EnumController(Option option, Function valueFormatter, T[] availableValues) { + public EnumController(Option option, Function valueFormatter, T[] availableValues) { super(option, Arrays.asList(availableValues), valueFormatter); } } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java index 54c7476..8e044b1 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -13,13 +13,13 @@ public class DoubleSliderController implements ISliderController { /** * Formats doubles to two decimal places */ - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " ")); private final Option option; private final double min, max, interval; - private final Function valueFormatter; + private final Function valueFormatter; /** * Constructs a {@link ISliderController} for doubles @@ -41,9 +41,9 @@ public class DoubleSliderController implements ISliderController { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public DoubleSliderController(Option option, double min, double max, double interval, Function valueFormatter) { + public DoubleSliderController(Option option, double min, double max, double interval, Function valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -67,7 +67,7 @@ public class DoubleSliderController implements ISliderController { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java index 84ca9a2..25f2206 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -13,13 +13,13 @@ public class FloatSliderController implements ISliderController { /** * Formats floats to one decimal place */ - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " ")); private final Option option; private final float min, max, interval; - private final Function valueFormatter; + private final Function valueFormatter; /** * Constructs a {@link ISliderController} for floats @@ -41,9 +41,9 @@ public class FloatSliderController implements ISliderController { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public FloatSliderController(Option option, float min, float max, float interval, Function valueFormatter) { + public FloatSliderController(Option option, float min, float max, float interval, Function valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -67,7 +67,7 @@ public class FloatSliderController implements ISliderController { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java index 50ec9d2..4a68497 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -10,13 +10,13 @@ import java.util.function.Function; * {@link ISliderController} for integers. */ public class IntegerSliderController implements ISliderController { - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); private final Option option; private final int min, max, interval; - private final Function valueFormatter; + private final Function valueFormatter; /** * Constructs a {@link ISliderController} for integers @@ -38,9 +38,9 @@ public class IntegerSliderController implements ISliderController { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public IntegerSliderController(Option option, int min, int max, int interval, Function valueFormatter) { + public IntegerSliderController(Option option, int min, int max, int interval, Function valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -64,7 +64,7 @@ public class IntegerSliderController implements ISliderController { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java index 3038402..681e7cf 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java @@ -1,7 +1,7 @@ package dev.isxander.yacl.gui.controllers.slider; import dev.isxander.yacl.api.Option; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; import java.util.function.Function; @@ -10,13 +10,13 @@ import java.util.function.Function; * {@link ISliderController} for longs. */ public class LongSliderController implements ISliderController { - public static final Function DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); + public static final Function DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " ")); private final Option option; private final long min, max, interval; - private final Function valueFormatter; + private final Function valueFormatter; /** * Constructs a {@link ISliderController} for longs @@ -38,9 +38,9 @@ public class LongSliderController implements ISliderController { * @param min minimum slider value * @param max maximum slider value * @param interval step size (or increments) for the slider - * @param valueFormatter format the value into any {@link Text} + * @param valueFormatter format the value into any {@link Component} */ - public LongSliderController(Option option, long min, long max, long interval, Function valueFormatter) { + public LongSliderController(Option option, long min, long max, long interval, Function valueFormatter) { Validate.isTrue(max > min, "`max` cannot be smaller than `min`"); Validate.isTrue(interval > 0, "`interval` must be more than 0"); Validate.notNull(valueFormatter, "`valueFormatter` must not be null"); @@ -64,7 +64,7 @@ public class LongSliderController implements ISliderController { * {@inheritDoc} */ @Override - public Text formatValue() { + public Component formatValue() { return valueFormatter.apply(option().pendingValue()); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index ea4e262..ddfdd4d 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -1,13 +1,13 @@ package dev.isxander.yacl.gui.controllers.slider; +import com.mojang.blaze3d.platform.InputConstants; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.MathHelper; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.util.Mth; public class SliderControllerElement extends ControllerWidget> { private final double min, max, interval; @@ -27,32 +27,32 @@ public class SliderControllerElement extends ControllerWidget incrementValue(-1); - case InputUtil.GLFW_KEY_RIGHT, InputUtil.GLFW_KEY_UP -> incrementValue(1); + case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> incrementValue(-1); + case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> incrementValue(1); default -> { return false; } @@ -126,7 +126,7 @@ public class SliderControllerElement extends ControllerWidget extends Controller { * {@inheritDoc} */ @Override - default Text formatValue() { - return Text.of(getString()); + default Component formatValue() { + return Component.literal(getString()); } default boolean isInputValid(String input) { diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index b4358f4..2723089 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -1,16 +1,16 @@ package dev.isxander.yacl.gui.controllers.string; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.InputUtil; -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.screens.Screen; +import net.minecraft.network.chat.Component; import java.util.function.Consumer; @@ -28,7 +28,7 @@ public class StringControllerElement extends ControllerWidget control, YACLScreen screen, Dimension dim, boolean instantApply) { super(control, screen, dim); @@ -36,48 +36,48 @@ public class StringControllerElement extends ControllerWidget inputField = control.getString()); setDimension(dim); } @Override - protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) { + protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) { } @Override - protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { - Text valueText = getValueText(); - if (!isHovered()) valueText = Text.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getMaxUnwrapLength(), "...")).setStyle(valueText.getStyle()); + protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) { + Component valueText = getValueText(); + if (!isHovered()) valueText = Component.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getMaxUnwrapLength(), "...")).setStyle(valueText.getStyle()); - matrices.push(); - int textX = getDimension().xLimit() - textRenderer.getWidth(valueText) + renderOffset - getXPadding(); + matrices.pushPose(); + int textX = getDimension().xLimit() - textRenderer.width(valueText) + renderOffset - getXPadding(); matrices.translate(textX, getTextY(), 0); GuiUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y() - 2, inputFieldBounds.width() + 1, inputFieldBounds.height() + 4); - textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); - matrices.pop(); + textRenderer.drawShadow(matrices, valueText, 0, 0, getValueColor()); + matrices.popPose(); if (isHovered()) { ticks += delta; String text = getValueText().getString(); - DrawableHelper.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1); - DrawableHelper.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040); + GuiComponent.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1); + GuiComponent.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040); if (inputFieldFocused || focused) { - int caretX = textX + textRenderer.getWidth(text.substring(0, caretPos)) - 1; + int caretX = textX + textRenderer.width(text.substring(0, caretPos)) - 1; if (text.isEmpty()) caretX = inputFieldBounds.x() + inputFieldBounds.width() / 2; if (ticks % 20 <= 10) { - DrawableHelper.fill(matrices, caretX, inputFieldBounds.y(), caretX + 1, inputFieldBounds.yLimit(), -1); + GuiComponent.fill(matrices, caretX, inputFieldBounds.y(), caretX + 1, inputFieldBounds.yLimit(), -1); } if (selectionLength != 0) { - int selectionX = textX + textRenderer.getWidth(text.substring(0, caretPos + selectionLength)); - DrawableHelper.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF); + int selectionX = textX + textRenderer.width(text.substring(0, caretPos + selectionLength)); + GuiComponent.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF); } } } @@ -93,12 +93,12 @@ public class StringControllerElement extends ControllerWidget textX) { // if more than halfway past the characters select in front of that char caretPos = pos; break; @@ -129,11 +129,11 @@ public class StringControllerElement extends ControllerWidget { + case InputConstants.KEY_ESCAPE, InputConstants.KEY_RETURN -> { unfocus(); return true; } - case InputUtil.GLFW_KEY_LEFT -> { + case InputConstants.KEY_LEFT -> { if (Screen.hasShiftDown()) { if (Screen.hasControlDown()) { int spaceChar = findSpaceIndex(true); @@ -157,7 +157,7 @@ public class StringControllerElement extends ControllerWidget { + case InputConstants.KEY_RIGHT -> { if (Screen.hasShiftDown()) { if (Screen.hasControlDown()) { int spaceChar = findSpaceIndex(false); @@ -181,11 +181,11 @@ public class StringControllerElement extends ControllerWidget { + case InputConstants.KEY_BACKSPACE -> { doBackspace(); return true; } - case InputUtil.GLFW_KEY_DELETE -> { + case InputConstants.KEY_DELETE -> { doDelete(); return true; } @@ -205,13 +205,13 @@ public class StringControllerElement extends ControllerWidget dim) { super.setDimension(dim); - int width = Math.max(6, Math.min(textRenderer.getWidth(getValueText()), getUnshiftedLength())); - inputFieldBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - width, dim.centerY() - textRenderer.fontHeight / 2, width, textRenderer.fontHeight); + int width = Math.max(6, Math.min(textRenderer.width(getValueText()), getUnshiftedLength())); + inputFieldBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - width, dim.centerY() - textRenderer.lineHeight / 2, width, textRenderer.lineHeight); } @Override @@ -391,14 +391,14 @@ public class StringControllerElement extends ControllerWidget { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public DoubleFieldController(Option option, double min, double max, Function formatter) { + public DoubleFieldController(Option option, double min, double max, Function formatter) { super(option, formatter); this.min = min; this.max = max; @@ -47,7 +46,7 @@ public class DoubleFieldController extends NumberFieldController { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public DoubleFieldController(Option option, Function formatter) { + public DoubleFieldController(Option option, Function formatter) { this(option, -Double.MAX_VALUE, Double.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java index b1eb3a2..957100a 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java @@ -2,9 +2,8 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.FloatSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; -import java.math.BigDecimal; import java.util.function.Function; /** @@ -21,7 +20,7 @@ public class FloatFieldController extends NumberFieldController { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public FloatFieldController(Option option, float min, float max, Function formatter) { + public FloatFieldController(Option option, float min, float max, Function formatter) { super(option, formatter); this.min = min; this.max = max; @@ -47,7 +46,7 @@ public class FloatFieldController extends NumberFieldController { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public FloatFieldController(Option option, Function formatter) { + public FloatFieldController(Option option, Function formatter) { this(option, -Float.MAX_VALUE, Float.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java index 50eecec..2d64a3a 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -20,7 +20,7 @@ public class IntegerFieldController extends NumberFieldController { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public IntegerFieldController(Option option, int min, int max, Function formatter) { + public IntegerFieldController(Option option, int min, int max, Function formatter) { super(option, formatter); this.min = min; this.max = max; @@ -46,7 +46,7 @@ public class IntegerFieldController extends NumberFieldController { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public IntegerFieldController(Option option, Function formatter) { + public IntegerFieldController(Option option, Function formatter) { this(option, -Integer.MAX_VALUE, Integer.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java index 516de74..a640621 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java @@ -2,7 +2,7 @@ package dev.isxander.yacl.gui.controllers.string.number; import dev.isxander.yacl.api.Option; import dev.isxander.yacl.gui.controllers.slider.LongSliderController; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.function.Function; @@ -20,7 +20,7 @@ public class LongFieldController extends NumberFieldController { * @param max maximum allowed value (clamped on apply) * @param formatter display text, not used whilst editing */ - public LongFieldController(Option option, long min, long max, Function formatter) { + public LongFieldController(Option option, long min, long max, Function formatter) { super(option, formatter); this.min = min; this.max = max; @@ -46,7 +46,7 @@ public class LongFieldController extends NumberFieldController { * @param option option to bind controller to * @param formatter display text, not used whilst editing */ - public LongFieldController(Option option, Function formatter) { + public LongFieldController(Option option, Function formatter) { this(option, -Long.MAX_VALUE, Long.MAX_VALUE, formatter); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java index bf0354a..4240849 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java @@ -7,8 +7,8 @@ import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.slider.ISliderController; import dev.isxander.yacl.gui.controllers.string.IStringController; import dev.isxander.yacl.gui.controllers.string.StringControllerElement; -import net.minecraft.text.Text; -import net.minecraft.util.math.MathHelper; +import net.minecraft.network.chat.Component; +import net.minecraft.util.Mth; import java.text.DecimalFormatSymbols; import java.util.function.Function; @@ -20,9 +20,9 @@ import java.util.function.Function; */ public abstract class NumberFieldController implements ISliderController, IStringController { private final Option option; - private final Function displayFormatter; + private final Function displayFormatter; - public NumberFieldController(Option option, Function displayFormatter) { + public NumberFieldController(Option option, Function displayFormatter) { this.option = option; this.displayFormatter = displayFormatter; } @@ -35,7 +35,7 @@ public abstract class NumberFieldController implements ISlider @Override public void setFromString(String value) { if (value.isEmpty() || value.equals(".") || value.equals("-")) value = "0"; - setPendingValue(MathHelper.clamp(Double.parseDouble(cleanupNumberString(value)), min(), max())); + setPendingValue(Mth.clamp(Double.parseDouble(cleanupNumberString(value)), min(), max())); } @Override @@ -49,7 +49,7 @@ public abstract class NumberFieldController implements ISlider } @Override - public Text formatValue() { + public Component formatValue() { return displayFormatter.apply(option().pendingValue()); } -- cgit