diff options
21 files changed, 212 insertions, 96 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java index 8c3d68d4f..a17751703 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java @@ -37,6 +37,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -144,6 +145,15 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { void queueTooltip(@Nullable Tooltip tooltip); /** + * Clear all queued tooltips. + * + * @see Tooltip#queue() + * @since 8.3 + */ + @ApiStatus.Experimental + void clearTooltips(); + + /** * Returns the texture location of the default display background. * <p> * This is different depending on whether dark mode is enabled. diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java index 1bf43694b..e4ff00b7b 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidget.java @@ -34,11 +34,9 @@ import java.util.List; public class DelegateWidget extends WidgetWithBounds { private static final Rectangle EMPTY = new Rectangle(); protected final Widget widget; - private final List<Widget> children; public DelegateWidget(Widget widget) { this.widget = widget; - this.children = Collections.singletonList(widget); } protected Widget delegate() { @@ -52,7 +50,7 @@ public class DelegateWidget extends WidgetWithBounds { @Override public List<? extends GuiEventListener> children() { - return children; + return Collections.singletonList(delegate()); } @Override @@ -126,4 +124,9 @@ public class DelegateWidget extends WidgetWithBounds { this.setDragging(false); return delegate().mouseReleased(mouseX, mouseY, button); } + + @Override + public double getZRenderingPriority() { + return delegate().getZRenderingPriority(); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java index df350c9c7..16ef576ee 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widget.java @@ -37,10 +37,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; -import java.io.Closeable; -import java.io.IOException; import java.util.Stack; /** @@ -122,6 +119,11 @@ public abstract class Widget extends AbstractContainerEventHandler implements ne } @ApiStatus.Experimental + public double getZRenderingPriority() { + return 0; + } + + @ApiStatus.Experimental public static CloseableScissors scissor(PoseStack matrices, Rectangle bounds) { return scissor(matrices.last().pose(), bounds); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java index eb1f54d7d..028947c34 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Widgets.java @@ -327,6 +327,29 @@ public final class Widgets { return ClientInternals.getWidgetsProvider().wrapPadded(padLeft, padRight, padTop, padBottom, widget); } + public static Widget delegate(Supplier<Widget> supplier) { + return new DelegateWidget(Widgets.noOp()) { + @Override + protected Widget delegate() { + return supplier.get(); + } + }; + } + + public static WidgetWithBounds delegateWithBounds(Supplier<WidgetWithBounds> supplier) { + return new DelegateWidgetWithBounds(Widgets.noOp(), Rectangle::new) { + @Override + protected WidgetWithBounds delegate() { + return supplier.get(); + } + + @Override + public Rectangle getBounds() { + return delegate().getBounds(); + } + }; + } + public static <T> Iterable<T> walk(Iterable<? extends GuiEventListener> listeners, Predicate<GuiEventListener> predicate) { return () -> new AbstractIterator<T>() { Stack<Iterator<? extends GuiEventListener>> stack; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java index 49ebb91ca..342df8719 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/DefaultTagCategory.java @@ -23,15 +23,20 @@ package me.shedaniel.rei.plugin.client.categories.tag; +import com.mojang.blaze3d.platform.Window; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.math.Matrix4f; +import me.shedaniel.clothconfig2.api.animator.ValueAnimator; +import me.shedaniel.math.FloatingRectangle; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.ClientHelper; +import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.client.gui.widgets.DelegateWidgetWithBounds; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.gui.widgets.*; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.api.common.util.EntryStacks; import me.shedaniel.rei.plugin.common.BuiltinPlugin; import me.shedaniel.rei.plugin.common.displays.tag.DefaultTagDisplay; @@ -45,6 +50,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Items; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, ?>> { @@ -67,24 +73,50 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, public List<Widget> setupDisplay(DefaultTagDisplay<?, ?> display, Rectangle bounds) { List<Widget> widgets = new ArrayList<>(); - widgets.add(Widgets.createRecipeBase(bounds)); + Window window = Minecraft.getInstance().getWindow(); + Rectangle boundsBig = new Rectangle(window.getGuiScaledWidth() * 0.05, window.getGuiScaledHeight() * 0.1, window.getGuiScaledWidth() * 0.9, window.getGuiScaledHeight() * 0.8); + Rectangle recipeBounds = bounds.clone(); + + boolean[] expanded = {false}; + Rectangle innerBounds = new Rectangle(bounds.x + 6 + 14, bounds.y + 6, bounds.width - 12 - 14, bounds.height - 12); + Rectangle overflowBounds = new Rectangle(innerBounds.x + 1, innerBounds.y + 1, innerBounds.width - 2, innerBounds.height - 2); + + Rectangle expandButtonBounds = new Rectangle(bounds.x + 5, bounds.y + 6, 13, 13); + Rectangle expandOverlayBounds = new Rectangle(bounds.x + 5 + 2, bounds.y + 6 + 2, 13 - 4, 13 - 4); + Rectangle copyButtonBounds = new Rectangle(bounds.x + 5, bounds.getMaxY() - 6 - 13, 13, 13); + Rectangle copyOverlayBounds = new Rectangle(bounds.x + 5 + 2, bounds.getMaxY() - 6 - 13 + 2, 13 - 4, 13 - 4); + + ValueAnimator<FloatingRectangle> boundsAnimator = ValueAnimator.ofFloatingRectangle(bounds.getFloatingBounds()) + .withConvention(() -> { + if (expanded[0]) { + return boundsBig.getFloatingBounds(); + } else { + return bounds.getFloatingBounds(); + } + }, 1400); + + widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + innerBounds.setBounds(recipeBounds.x + 6 + 14, recipeBounds.y + 6, recipeBounds.width - 12 - 14, recipeBounds.height - 12); + overflowBounds.setBounds(innerBounds.x + 1, innerBounds.y + 1, innerBounds.width - 2, innerBounds.height - 2); + expandButtonBounds.setBounds(recipeBounds.x + 5, recipeBounds.y + 6, 13, 13); + copyButtonBounds.setBounds(recipeBounds.x + 5, recipeBounds.getMaxY() - 6 - 13, 13, 13); + expandOverlayBounds.setBounds(recipeBounds.x + 5 + 2, recipeBounds.y + 6 + 2, 13 - 4, 13 - 4); + copyOverlayBounds.setBounds(recipeBounds.x + 5 + 2, recipeBounds.getMaxY() - 6 - 13 + 2, 13 - 4, 13 - 4); + recipeBounds.setBounds(boundsAnimator.value()); + boundsAnimator.update(delta); + + if (overflowBounds.contains(mouseX, mouseY)) { + REIRuntime.getInstance().clearTooltips(); + } + })); + + widgets.add(Widgets.createRecipeBase(recipeBounds)); widgets.add(Widgets.createSlotBase(innerBounds)); WidgetWithBounds[] delegate = new WidgetWithBounds[]{Widgets.noOp()}; TagNode<?>[] tagNode = new TagNode[]{null}; - Rectangle overflowBounds = new Rectangle(innerBounds.x + 1, innerBounds.y + 1, innerBounds.width - 2, innerBounds.height - 2); - widgets.add(Widgets.withTranslate(Widgets.overflowed(overflowBounds, new DelegateWidgetWithBounds(Widgets.noOp(), Rectangle::new) { - @Override - protected WidgetWithBounds delegate() { - return delegate[0]; - } - - @Override - public Rectangle getBounds() { - return delegate().getBounds(); - } - }), 0, 0, 20)); + widgets.add(Widgets.withTranslate(Widgets.delegateWithBounds(() -> delegate[0]), 0, 0, 20)); TagNodes.create(display.getKey(), dataResult -> { if (dataResult.error().isPresent()) { @@ -95,18 +127,19 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, } else { tagNode[0] = dataResult.result().get(); //noinspection rawtypes - delegate[0] = Widgets.padded(16, new TagTreeWidget(tagNode[0], display.getMapper())); + delegate[0] = Widgets.overflowed(overflowBounds, Widgets.padded(16, new TagTreeWidget(tagNode[0], display.getMapper()))); } }); - widgets.add(Widgets.createButton(new Rectangle(bounds.x + 5, bounds.y + 6, 13, 13), new TextComponent("")) + widgets.add(Widgets.createButton(expandButtonBounds, new TextComponent("")) .onRender((poseStack, button) -> { button.setEnabled(tagNode[0] != null); }) .onClick(button -> { + expanded[0] = !expanded[0]; }) - .tooltipLine(new TranslatableComponent("text.rei.expand.view"))); - widgets.add(Widgets.createButton(new Rectangle(bounds.x + 5, bounds.getMaxY() - 6 - 13, 13, 13), new TextComponent("")) + .tooltipSupplier(button -> new Component[]{new TranslatableComponent(!expanded[0] ? "text.rei.expand.view" : "text.rei.expand.view.close")})); + widgets.add(Widgets.createButton(copyButtonBounds, new TextComponent("")) .onRender((poseStack, button) -> { button.setEnabled(tagNode[0] != null); }) @@ -118,11 +151,24 @@ public class DefaultTagCategory implements DisplayCategory<DefaultTagDisplay<?, } }) .tooltipLine(new TranslatableComponent("text.rei.tag.copy.clipboard"))); - widgets.add(Widgets.withTranslate(Widgets.createTexturedWidget(new ResourceLocation("roughlyenoughitems", "textures/gui/expand.png"), - new Rectangle(bounds.x + 5 + 2, bounds.y + 6 + 2, 13 - 4, 13 - 4), 0, 0, 9, 9), 0, 0, 10)); - widgets.add(Widgets.withTranslate(Widgets.createTexturedWidget(new ResourceLocation("roughlyenoughitems", "textures/gui/clipboard.png"), - new Rectangle(bounds.x + 5 + 2, bounds.getMaxY() - 6 - 13 + 2, 13 - 4, 13 - 4), 0, 0, 9, 9), 0, 0.5, 10)); + widgets.add(Widgets.withTranslate(new DelegateWidget(Widgets.noOp()) { + @Override + protected Widget delegate() { + ResourceLocation expandTexture = !expanded[0] ? new ResourceLocation("roughlyenoughitems", "textures/gui/expand.png") + : new ResourceLocation("roughlyenoughitems", "textures/gui/shrink.png"); + return Widgets.concat( + Widgets.createTexturedWidget(expandTexture, + new Rectangle(recipeBounds.x + 5 + 2, recipeBounds.y + 6 + 2, 13 - 4, 13 - 4), 0, 0, 9, 9), + Widgets.createTexturedWidget(new ResourceLocation("roughlyenoughitems", "textures/gui/clipboard.png"), + new Rectangle(recipeBounds.x + 5 + 2, recipeBounds.getMaxY() - 6 - 13 + 2, 13 - 4, 13 - 4), 0, 0, 9, 9) + ); + } + }, 0, 0, 10)); - return widgets; + Matrix4f translateMatrix = Matrix4f.createTranslateMatrix(0, 0, 200); + Matrix4f identity = new Matrix4f(); + identity.setIdentity(); + return CollectionUtils.map(widgets, widget -> Widgets.withTranslate(widget, () -> + expanded[0] || !boundsAnimator.value().equals(boundsAnimator.target()) ? translateMatrix : identity)); } } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java index 677c4cd1d..e0d91e258 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/categories/tag/ValueTagNodeWidget.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.plugin.client.categories.tag; +import com.google.common.base.Predicates; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; import me.shedaniel.math.Rectangle; @@ -50,7 +51,8 @@ public class ValueTagNodeWidget<S, T> extends TagNodeWidget<S, T> { int width = Math.min(4, holders.size()); int height = Math.max((int) Math.ceil(holders.size() * 1.0 / width), 1); this.bounds = new Rectangle(0, 0, 16 * width + 12, 16 * height + 12); - Panel background = Widgets.createRecipeBase(bounds.clone()); + Panel background = Widgets.createRecipeBase(bounds.clone()) + .rendering(Predicates.alwaysTrue()); Panel slotBackground = Widgets.createSlotBase(new Rectangle(5, 5, 16 * width + 2, 16 * height + 2)); int i = 0; List<Widget> widgets = new ArrayList<>(); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index 2058d1fee..ac3d399ec 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -411,7 +411,9 @@ public class RoughlyEnoughItemsCoreClient { if (shouldReturn(screen)) return; resetFocused(screen); - getOverlay().render(matrices, mouseX, mouseY, delta); + if (!(screen instanceof DisplayScreen)) { + getOverlay().render(matrices, mouseX, mouseY, delta); + } ((ScreenOverlayImpl) getOverlay()).lateRender(matrices, mouseX, mouseY, delta); resetFocused(screen); }); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java index 8791301b0..89032a613 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIRuntimeImpl.java @@ -99,6 +99,13 @@ public class REIRuntimeImpl implements REIRuntime { } @Override + public void clearTooltips() { + if (overlay != null) { + overlay.clearTooltips(); + } + } + + @Override @Nullable public TextField getSearchTextField() { if (searchField == null) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java index 986c6a93e..10588b9f8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java @@ -740,10 +740,9 @@ public class ScreenOverlayImpl extends ScreenOverlay { } Screen currentScreen = Minecraft.getInstance().screen; if (choosePageWidget == null) { - for (Tooltip tooltip : TOOLTIPS) { - if (tooltip != null) - renderTooltip(matrices, tooltip); - } + TOOLTIPS.stream().filter(Objects::nonNull) + .reduce((tooltip, tooltip2) -> tooltip2) + .ifPresent(tooltip -> renderTooltip(matrices, tooltip)); } TOOLTIPS.clear(); if (REIRuntime.getInstance().isOverlayVisible()) { @@ -768,6 +767,10 @@ public class ScreenOverlayImpl extends ScreenOverlay { TOOLTIPS.add(tooltip); } + public void clearTooltips() { + TOOLTIPS.clear(); + } + public void renderWidgets(PoseStack matrices, int mouseX, int mouseY, float delta) { if (!REIRuntime.getInstance().isOverlayVisible()) return; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index f524a74cf..27a6551d7 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -96,8 +96,11 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis } } - public List<GuiEventListener> _children() { - return (List<GuiEventListener>) children(); + @Override + public List<GuiEventListener> children() { + List<? extends GuiEventListener> children = super.children(); + children.sort(Comparator.comparingDouble(value -> value instanceof Widget widget ? widget.getZRenderingPriority() : 0).reversed()); + return (List<GuiEventListener>) children; } @Override @@ -325,7 +328,7 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis widget.tooltipProcessor(new TooltipProcessor()); } - private static ScreenOverlay getOverlay() { + protected static ScreenOverlay getOverlay() { return REIRuntime.getInstance().getOverlay().orElseThrow(() -> new IllegalStateException("Overlay not initialized!")); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index 823060f26..544801a3c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; @@ -228,9 +229,9 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen ViewSearchBuilder.builder().addAllCategories().open(); }).tooltip(Component.translatable("text.rei.view_all_categories")).noShadow().color(0xFF404040, 0xFFBBBBBB).hoveredColor(0xFF0041FF, 0xFFFFBD4D)); - this._children().addAll(buttonList); + this.children().addAll(buttonList); this.widgets.addAll(tabs); - this._children().addAll(widgets); + this.children().addAll(widgets); } @Override @@ -350,10 +351,12 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen scrolling.updatePosition(delta); renderBackground(matrices); int yOffset = 0; + getOverlay().render(matrices, mouseX, mouseY, delta); + super.render(matrices, mouseX, mouseY, delta); for (Widget widget : widgets) { + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); widget.render(matrices, mouseX, mouseY, delta); } - super.render(matrices, mouseX, mouseY, delta); matrices.pushPose(); ScissorsHandler.INSTANCE.scissor(scrolling.getBounds()); for (Button button : buttonList) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java index 79a12001d..e576f54b1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.java @@ -81,10 +81,8 @@ import java.util.function.Supplier; @ApiStatus.Internal public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); - private final List<Widget> preWidgets = Lists.newArrayList(); - private final List<Widget> widgets = Lists.newArrayList(); private final Map<Rectangle, Pair<DisplaySpec, List<Widget>>> recipeBounds = Maps.newHashMap(); - private final List<TabWidget> tabs = Lists.newArrayList(); + private List<Widget> widgets = Lists.newArrayList(); public int page; public int categoryPages = -1; @Nullable @@ -145,8 +143,6 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { super.init(); this.children().clear(); this.recipeBounds.clear(); - this.tabs.clear(); - this.preWidgets.clear(); this.widgets.clear(); int largestHeight = Math.min(Math.max(height - 34 - 30, 100), ConfigObject.getInstance().getMaxRecipesPageHeight()); int maxWidthDisplay = CollectionUtils.<DisplaySpec, Integer>mapAndMax(getCurrentDisplayed(), display -> getCurrentCategory().getDisplayWidth(display.provideInternalDisplay()), Comparator.naturalOrder()).orElse(150); @@ -232,7 +228,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { int tabIndex = id + categoryPages * tabsPerPage; if (categories.size() > tabIndex) { TabWidget tab; - tabs.add(tab = TabWidget.create(id, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - categoryPages * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, isCompactTabs ? 166 : 192, widget -> { + widgets.add(tab = TabWidget.create(id, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - categoryPages * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, isCompactTabs ? 166 : 192, widget -> { Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); if (widget.getId() + categoryPages * tabsPerPage == selectedCategoryIndex) return false; @@ -243,11 +239,15 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } } initDisplays(); - initWorkstations(preWidgets); + widgets = CollectionUtils.map(widgets, widget -> Widgets.withTranslate(widget, 0, 0, 10)); + widgets.add(Widgets.withTranslate(new PanelWidget(bounds), 0, 0, 5)); + widgets.add(Widgets.withTranslate(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { + fill(matrices, bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, darkStripesColor.value().getColor()); + fill(matrices, bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, darkStripesColor.value().getColor()); + }), 0, 0, 6)); + initWorkstations(widgets); - _children().addAll(tabs); - _children().addAll(widgets); - _children().addAll(preWidgets); + children().addAll(widgets); } private void initDisplays() { @@ -284,7 +284,7 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } } - private void initWorkstations(List<Widget> preWidgets) { + private void initWorkstations(List<Widget> widgets) { workingStationsBaseWidget = null; List<EntryIngredient> workstations = CategoryRegistry.getInstance().get(getCurrentCategoryId()).getWorkstations(); if (!workstations.isEmpty()) { @@ -293,12 +293,12 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { int innerWidth = Mth.ceil(workstations.size() / ((float) hh)); int xx = bounds.x - (8 + innerWidth * 16) + 6; int yy = bounds.y + 16; - preWidgets.add(workingStationsBaseWidget = Widgets.createCategoryBase(new Rectangle(xx - 5, yy - 5, 15 + innerWidth * 16, 10 + actualHeight * 16))); - preWidgets.add(Widgets.createSlotBase(new Rectangle(xx - 1, yy - 1, innerWidth * 16 + 2, actualHeight * 16 + 2))); + widgets.add(workingStationsBaseWidget = Widgets.createCategoryBase(new Rectangle(xx - 5, yy - 5, 15 + innerWidth * 16, 10 + actualHeight * 16))); + widgets.add(Widgets.createSlotBase(new Rectangle(xx - 1, yy - 1, innerWidth * 16 + 2, actualHeight * 16 + 2))); int index = 0; xx += (innerWidth - 1) * 16; for (EntryIngredient workingStation : workstations) { - preWidgets.add(new WorkstationSlotWidget(xx, yy, workingStation)); + widgets.add(new WorkstationSlotWidget(xx, yy, workingStation)); index++; yy += 16; if (index >= hh) { @@ -310,7 +310,8 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } } - public List<Widget> getWidgets() { + public List<Widget> widgets() { + widgets.sort(Comparator.comparingDouble(Widget::getZRenderingPriority)); return widgets; } @@ -352,31 +353,16 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { darkStripesColor.update(delta); renderBackground(matrices); - for (Widget widget : preWidgets) { - widget.render(matrices, mouseX, mouseY, delta); - } - PanelWidget.render(matrices, bounds, -1, delta); - fill(matrices, bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, darkStripesColor.value().getColor()); - fill(matrices, bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, darkStripesColor.value().getColor()); - for (TabWidget tab : tabs) { - if (!tab.isSelected()) { - tab.render(matrices, mouseX, mouseY, delta); - } - } super.render(matrices, mouseX, mouseY, delta); - for (Widget widget : widgets) { + getOverlay().render(matrices, mouseX, mouseY, delta); + for (Widget widget : widgets()) { + RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); widget.render(matrices, mouseX, mouseY, delta); } - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - for (TabWidget tab : tabs) { - if (tab.isSelected()) { - tab.render(matrices, mouseX, mouseY, delta); - } - } { ModifierKeyCode export = ConfigObject.getInstance().getExportImageKeybind(); if (export.matchesCurrentKey() || export.matchesCurrentMouse()) { - for (Rectangle bounds : Iterables.concat(recipeBounds.keySet(), Iterables.transform(tabs, TabWidget::getBounds))) { + for (Rectangle bounds : Iterables.concat(recipeBounds.keySet(), Iterables.transform(getTabs(), TabWidget::getBounds))) { setBlitOffset(470); if (bounds.contains(mouseX, mouseY)) { fillGradient(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), 1744822402, 1744822402); @@ -397,6 +383,10 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } } + private Iterable<TabWidget> getTabs() { + return Widgets.walk(widgets(), widget -> widget instanceof TabWidget); + } + @Override public boolean keyReleased(int keyCode, int scanCode, int modifiers) { ModifierKeyCode export = ConfigObject.getInstance().getExportImageKeybind(); @@ -415,19 +405,19 @@ public class DefaultDisplayViewingScreen extends AbstractDisplayViewingScreen { } @Override - public boolean charTyped(char char_1, int int_1) { + public boolean charTyped(char character, int modifiers) { for (GuiEventListener listener : children()) - if (listener.charTyped(char_1, int_1)) + if (listener.charTyped(character, modifiers)) return true; - return super.charTyped(char_1, int_1); + return super.charTyped(character, modifiers); } @Override - public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) { + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { |
