From 2d1bfbf5902dfe5db8bf95d01ae5b4d68e48020f Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 27 Jun 2022 23:27:37 +0800 Subject: Add expanded view to tag trees, fix #948 --- .../client/categories/tag/DefaultTagCategory.java | 98 ++++++++++++++++------ .../client/categories/tag/ValueTagNodeWidget.java | 4 +- 2 files changed, 75 insertions(+), 27 deletions(-) (limited to 'default-plugin/src') 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> { @@ -67,24 +73,50 @@ public class DefaultTagCategory implements DisplayCategory setupDisplay(DefaultTagDisplay display, Rectangle bounds) { List 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 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 { 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 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 extends TagNodeWidget { 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 widgets = new ArrayList<>(); -- cgit