diff options
author | isXander <xandersmith2008@gmail.com> | 2023-05-25 22:07:46 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-05-25 22:07:46 +0100 |
commit | b1909c9c820b16f9f3adda64d3332d867d6ef2f7 (patch) | |
tree | cf1f3aa74903460c192f9722b2adf1bd9e92f55a /common/src/main/java/dev/isxander/yacl | |
parent | f40bd6fef7d5a6a718f89014149da80f201787f3 (diff) | |
download | YetAnotherConfigLib-b1909c9c820b16f9f3adda64d3332d867d6ef2f7.tar.gz YetAnotherConfigLib-b1909c9c820b16f9f3adda64d3332d867d6ef2f7.tar.bz2 YetAnotherConfigLib-b1909c9c820b16f9f3adda64d3332d867d6ef2f7.zip |
Remove references of postRender
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl')
10 files changed, 36 insertions, 83 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java b/common/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java index a34b3fa..06a6e23 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java @@ -24,10 +24,6 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na this.dim = dim; } - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - - } - public boolean canReset() { return false; } diff --git a/common/src/main/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/common/src/main/java/dev/isxander/yacl/gui/ElementListWidgetExt.java index ffeffbf..8fdf2ee 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ b/common/src/main/java/dev/isxander/yacl/gui/ElementListWidgetExt.java @@ -85,12 +85,6 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten this.smoothScrollAmount = getScrollAmount(); } - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - for (E entry : children()) { - entry.postRender(graphics, mouseX, mouseY, delta); - } - } - @Nullable @Override protected E getEntryAtPosition(double x, double y) { @@ -219,10 +213,6 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten return false; } - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - - } - public int getItemHeight() { return 22; } diff --git a/common/src/main/java/dev/isxander/yacl/gui/OptionDescriptionWidget.java b/common/src/main/java/dev/isxander/yacl/gui/OptionDescriptionWidget.java index 4d86048..9f0c642 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/OptionDescriptionWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/OptionDescriptionWidget.java @@ -2,12 +2,14 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.Blaze3D; import com.mojang.blaze3d.platform.InputConstants; -import dev.isxander.yacl.api.OptionDescription; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ComponentPath; import net.minecraft.client.gui.Font; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.narration.NarratedElementType; import net.minecraft.client.gui.narration.NarrationElementOutput; +import net.minecraft.client.gui.navigation.FocusNavigationEvent; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; @@ -19,8 +21,8 @@ import java.util.List; import java.util.function.Supplier; public class OptionDescriptionWidget extends AbstractWidget { - private static final int AUTO_SCROLL_TIMER = 3000; - private static final float AUTO_SCROLL_SPEED = 1; + private static final int AUTO_SCROLL_TIMER = 1500; + private static final float AUTO_SCROLL_SPEED = 1; // lines per second private @Nullable DescriptionWithName description; private List<FormattedCharSequence> wrappedText; @@ -184,6 +186,10 @@ public class OptionDescriptionWidget extends AbstractWidget { @Override protected void updateWidgetNarration(NarrationElementOutput builder) { + if (description != null) { + builder.add(NarratedElementType.TITLE, description.name()); + builder.add(NarratedElementType.HINT, description.description().description()); + } } @@ -198,4 +204,12 @@ public class OptionDescriptionWidget extends AbstractWidget { private int currentTimeMS() { return (int)(Blaze3D.getTime() * 1000); } + + @Nullable + @Override + public ComponentPath nextFocusPath(FocusNavigationEvent event) { + // prevents focusing on this widget + return null; + } + } 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 fb49578..ca903ef 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -305,11 +305,6 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - widget.postRender(graphics, mouseX, mouseY, delta); - } - - @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return widget.mouseScrolled(mouseX, mouseY, amount); } @@ -479,6 +474,7 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr group.addListener((opt, val) -> this.resetListButton.active = !opt.isPendingValueDefault() && opt.available()); this.resetListButton.active = !group.isPendingValueDefault() && group.available(); + this.addListButton = new TooltipButtonWidget(yaclScreen, resetListButton.getX() - 20, -50, 20, 20, Component.literal("+"), Component.translatable("yacl.list.add_top"), btn -> { group.insertNewEntryToTop(); setExpanded(true); @@ -503,15 +499,6 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr addListButton.render(graphics, mouseX, mouseY, tickDelta); } - @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - minimizeIfUnavailable(); // cannot run in render because it *should* cause a ConcurrentModificationException (but doesn't) - - super.postRender(graphics, mouseX, mouseY, delta); - - addListButton.renderHoveredTooltip(graphics); - } - private void minimizeIfUnavailable() { if (!listOption.available() && isExpanded()) { setExpanded(false); 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 824ff86..c948331 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/TooltipButtonWidget.java @@ -1,32 +1,25 @@ package dev.isxander.yacl.gui; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.MultiLineLabel; +import net.minecraft.client.gui.components.Tooltip; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipPositioner; import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; public class TooltipButtonWidget extends Button { protected final Screen screen; - protected MultiLineLabel wrappedDescription = null; public TooltipButtonWidget(Screen screen, int x, int y, int width, int height, Component message, Component tooltip, OnPress onPress) { super(x, y, width, height, message, onPress, DEFAULT_NARRATION); this.screen = screen; if (tooltip != null) - setTooltip(tooltip); + setTooltip(Tooltip.create(tooltip)); } - public void renderHoveredTooltip(GuiGraphics graphics) { - if (isHoveredOrFocused() && wrappedDescription != null) { - YACLScreen.renderMultilineTooltip(graphics, Minecraft.getInstance().font, wrappedDescription, getX() + width / 2, getY() - 4, getY() + height + 4, screen.width, screen.height); - } - } - - public void setTooltip(Component tooltip) { - wrappedDescription = MultiLineLabel.create(Minecraft.getInstance().font, tooltip, screen.width / 3 - 5); + @Override + protected @NotNull ClientTooltipPositioner createTooltipPositioner() { + return new YACLTooltipPositioner(this); } } diff --git a/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java b/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java index a72640e..d225d7e 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/common/src/main/java/dev/isxander/yacl/gui/YACLScreen.java @@ -76,14 +76,7 @@ public class YACLScreen extends Screen { @Override public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) { renderDirtBackground(graphics); - super.render(graphics, mouseX, mouseY, delta); - - for (GuiEventListener child : children()) { - if (child instanceof TooltipButtonWidget tooltipButtonWidget) { - tooltipButtonWidget.renderHoveredTooltip(graphics); - } - } } protected void finishOrSave() { @@ -223,7 +216,7 @@ public class YACLScreen extends Screen { private class CategoryTab implements Tab { private final ConfigCategory category; - private final TabListWidget<OptionListWidget> optionList; + private TabListWidget<OptionListWidget> optionList; private final Button saveFinishedButton; private final Button cancelResetButton; private final Button undoButton; @@ -233,13 +226,6 @@ public class YACLScreen extends Screen { public CategoryTab(ConfigCategory category) { this.category = category; - this.optionList = new TabListWidget<>( - () -> new ScreenRectangle(tabArea.position(), tabArea.width() / 3 * 2 + 1, tabArea.height()), - new OptionListWidget(YACLScreen.this, category, minecraft, 0, 0, width / 3 * 2 + 1, height, desc -> { - descriptionWidget.setOptionDescription(desc); - }) - ); - int columnWidth = width / 3; int padding = columnWidth / 20; columnWidth = Math.min(columnWidth, 400); @@ -275,6 +261,13 @@ public class YACLScreen extends Screen { searchQuery -> optionList.getList().updateSearchQuery(searchQuery) ); + this.optionList = new TabListWidget<>( + () -> new ScreenRectangle(tabArea.position(), tabArea.width() / 3 * 2 + 1, tabArea.height()), + new OptionListWidget(YACLScreen.this, category, minecraft, 0, 0, width / 3 * 2 + 1, height, desc -> { + descriptionWidget.setOptionDescription(desc); + }) + ); + descriptionWidget = new OptionDescriptionWidget( () -> new ScreenRectangle( width / 3 * 2 + padding, diff --git a/common/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/common/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index 232dddb..a277ad4 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -53,13 +53,6 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract } } - @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - if (hovered || focused) { - YACLScreen.renderMultilineTooltip(graphics, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); - } - } - protected void drawHoveredControl(GuiGraphics graphics, int mouseX, int mouseY, float delta) { } diff --git a/common/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java b/common/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java index a55a255..a3d385c 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java +++ b/common/src/main/java/dev/isxander/yacl/gui/controllers/LabelController.java @@ -85,10 +85,9 @@ public class LabelController implements Controller<Component> { graphics.fill(getDimension().x() - 1, getDimension().yLimit(), getDimension().xLimit() + 1, getDimension().yLimit() + 1, -1); graphics.fill(getDimension().xLimit(), getDimension().y() - 1, getDimension().xLimit() + 1, getDimension().yLimit() + 1, -1); } - } - @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { + graphics.pose().pushPose(); + graphics.pose().translate(0, 0, 100); if (isMouseOver(mouseX, mouseY)) { YACLScreen.renderMultilineTooltip(graphics, textRenderer, wrappedTooltip, getDimension().centerX(), getDimension().y() - 5, getDimension().yLimit() + 5, screen.width, screen.height); @@ -115,6 +114,7 @@ public class LabelController implements Controller<Component> { } } } + graphics.pose().popPose(); } @Override diff --git a/common/src/main/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java b/common/src/main/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java index 2156dcc..af60c08 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java +++ b/common/src/main/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java @@ -80,13 +80,6 @@ public class ListEntryWidget extends AbstractWidget implements ContainerEventHan entryWidget.render(graphics, mouseX, mouseY, delta); } - @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - removeButton.renderHoveredTooltip(graphics); - moveUpButton.renderHoveredTooltip(graphics); - moveDownButton.renderHoveredTooltip(graphics); - } - protected void updateButtonStates() { removeButton.active = listOption.available(); moveUpButton.active = listOption.indexOf(listOptionEntry) > 0 && listOption.available(); diff --git a/common/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/common/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java index b60de07..f1b507d 100644 --- a/common/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java +++ b/common/src/main/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java @@ -155,10 +155,4 @@ public class SliderControllerElement extends ControllerWidget<ISliderController< protected int getThumbWidth() { return 4; } - - @Override - public void postRender(GuiGraphics graphics, int mouseX, int mouseY, float delta) { - if (super.isMouseOver(mouseX, mouseY) || focused) - super.postRender(graphics, mouseX, mouseY, delta); - } } |