From c027169dfe9503a9d913589eb322cc11ddad0baa Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Mar 2021 00:02:16 +0800 Subject: Improve UncertainDisplayViewingScreen Signed-off-by: shedaniel --- .../me/shedaniel/rei/api/config/ConfigObject.java | 6 +-- .../rei/api/gui/AbstractContainerEventHandler.java | 36 ++++++++++++++++++ .../rei/api/gui/config/DisplayScreenType.java | 44 ++++++++++++++++++++++ .../rei/api/gui/config/RecipeScreenType.java | 44 ---------------------- .../rei/api/gui/widgets/DelegateWidget.java | 1 - .../me/shedaniel/rei/api/gui/widgets/Widget.java | 2 +- .../rei/api/gui/widgets/WidgetWithBounds.java | 2 - .../me/shedaniel/rei/api/gui/widgets/Widgets.java | 40 ++++++++++++++++++-- .../rei/api/registry/display/DisplayCategory.java | 2 +- .../main/java/me/shedaniel/rei/impl/Internals.java | 6 +++ 10 files changed, 128 insertions(+), 55 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/gui/AbstractContainerEventHandler.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java (limited to 'api/src/main/java/me') diff --git a/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java index d7cfb2023..649ce4ddf 100644 --- a/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java @@ -70,9 +70,9 @@ public interface ConfigObject { boolean shouldAppendModNames(); - RecipeScreenType getRecipeScreenType(); + DisplayScreenType getRecipeScreenType(); - void setRecipeScreenType(RecipeScreenType recipeScreenType); + void setRecipeScreenType(DisplayScreenType displayScreenType); SearchFieldLocation getSearchFieldLocation(); @@ -103,7 +103,7 @@ public interface ConfigObject { RecipeBorderType getRecipeBorderType(); - boolean doesVillagerScreenHavePermanentScrollBar(); + boolean isCompositeScrollBarPermanent(); boolean doesRegisterRecipesInAnotherThread(); diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/AbstractContainerEventHandler.java b/api/src/main/java/me/shedaniel/rei/api/gui/AbstractContainerEventHandler.java new file mode 100644 index 000000000..3a271194c --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/gui/AbstractContainerEventHandler.java @@ -0,0 +1,36 @@ +package me.shedaniel.rei.api.gui; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.events.ContainerEventHandler; +import net.minecraft.client.gui.components.events.GuiEventListener; +import org.jetbrains.annotations.Nullable; + +@Environment(value = EnvType.CLIENT) +public abstract class AbstractContainerEventHandler extends GuiComponent implements ContainerEventHandler { + @Nullable + private GuiEventListener focused; + private boolean isDragging; + + @Override + public boolean isDragging() { + return this.isDragging; + } + + @Override + public void setDragging(boolean isDragging) { + this.isDragging = isDragging; + } + + @Override + @Nullable + public GuiEventListener getFocused() { + return this.focused; + } + + @Override + public void setFocused(@Nullable GuiEventListener focused) { + this.focused = focused; + } +} \ No newline at end of file diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java b/api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java new file mode 100644 index 000000000..507fa2c28 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java @@ -0,0 +1,44 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.api.gui.config; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.resources.language.I18n; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Locale; + +@ApiStatus.Internal +@Environment(EnvType.CLIENT) +public enum DisplayScreenType { + UNSET, + ORIGINAL, + COMPOSITE; + + @Override + public String toString() { + return I18n.get("config.roughlyenoughitems.recipeScreenType." + name().toLowerCase(Locale.ROOT)); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java b/api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java deleted file mode 100644 index 63ebd814c..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.api.gui.config; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.client.resources.language.I18n; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Locale; - -@ApiStatus.Internal -@Environment(EnvType.CLIENT) -public enum RecipeScreenType { - UNSET, - ORIGINAL, - VILLAGER; - - @Override - public String toString() { - return I18n.get("config.roughlyenoughitems.recipeScreenType." + name().toLowerCase(Locale.ROOT)); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java index ece1ab092..83965b426 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.gui.widgets; -import com.google.common.base.MoreObjects; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; import net.minecraft.client.gui.components.events.GuiEventListener; diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java index 5639acf1b..fb15a8850 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java @@ -26,10 +26,10 @@ package me.shedaniel.rei.api.gui.widgets; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.gui.AbstractContainerEventHandler; import me.shedaniel.rei.api.gui.Renderer; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.events.AbstractContainerEventHandler; /** * The base class for a screen widget diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/WidgetWithBounds.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/WidgetWithBounds.java index b427d8a47..bf43ca215 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/WidgetWithBounds.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/WidgetWithBounds.java @@ -24,10 +24,8 @@ package me.shedaniel.rei.api.gui.widgets; import me.shedaniel.math.Rectangle; -import org.jetbrains.annotations.NotNull; public abstract class WidgetWithBounds extends Widget { - @NotNull public abstract Rectangle getBounds(); @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java index ac9423e4d..4df43934f 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java @@ -36,6 +36,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.events.ContainerEventHandler; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.resources.sounds.SimpleSoundInstance; import net.minecraft.network.chat.Component; @@ -48,6 +49,8 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; @Environment(EnvType.CLIENT) public final class Widgets { @@ -68,14 +71,24 @@ public final class Widgets { } public static WidgetWithBounds withTranslate(Widget widget, Matrix4f translate) { + WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); + return new WidgetWithBoundsWithTranslate(widgetWithBounds, () -> translate); + } + + public static WidgetWithBounds withTranslate(T widget, Function translate) { + WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); + return new WidgetWithBoundsWithTranslate(widgetWithBounds, () -> translate.apply(widget)); + } + + public static WidgetWithBounds withTranslate(Widget widget, Supplier translate) { WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); return new WidgetWithBoundsWithTranslate(widgetWithBounds, translate); } private static class WidgetWithBoundsWithTranslate extends DelegateWidget { - private final Matrix4f translate; + private final Supplier translate; - private WidgetWithBoundsWithTranslate(WidgetWithBounds widget, Matrix4f translate) { + private WidgetWithBoundsWithTranslate(WidgetWithBounds widget, Supplier translate) { super(widget); this.translate = translate; } @@ -83,7 +96,7 @@ public final class Widgets { @Override public void render(PoseStack poseStack, int i, int j, float f) { poseStack.pushPose(); - poseStack.last().pose().multiply(translate); + poseStack.last().pose().multiply(translate.get()); super.render(poseStack, i, j, f); poseStack.popPose(); } @@ -94,6 +107,7 @@ public final class Widgets { public VanillaWrappedWidget(GuiEventListener element) { this.element = Objects.requireNonNull(element); + setFocused(element); } @Override @@ -108,6 +122,26 @@ public final class Widgets { public List children() { return Collections.singletonList(element); } + + @Nullable + @Override + public GuiEventListener getFocused() { + return element; + } + + @Override + public void setFocused(@Nullable GuiEventListener guiEventListener) { + if (guiEventListener == element) { + super.setFocused(element); + } else if (element instanceof ContainerEventHandler) { + ((ContainerEventHandler) element).setFocused(guiEventListener); + } + } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return element.isMouseOver(mouseX, mouseY); + } } public static WidgetWithBounds wrapRenderer(Rectangle bounds, Renderer renderer) { diff --git a/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayCategory.java b/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayCategory.java index 5e19b8d0b..db381c1c2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayCategory.java +++ b/api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayCategory.java @@ -55,7 +55,7 @@ public interface DisplayCategory extends Identifiable { Component getTitle(); /** - * Gets the recipe renderer for the category, used in {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} for rendering simple recipes + * Gets the recipe renderer for the category, used in {@link me.shedaniel.rei.gui.CompositeRecipeViewingScreen} for rendering simple recipes * * @param display the display to render * @return the display renderer diff --git a/api/src/main/java/me/shedaniel/rei/impl/Internals.java b/api/src/main/java/me/shedaniel/rei/impl/Internals.java index 2f2b6325d..035a77bc3 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/Internals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/Internals.java @@ -54,6 +54,7 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.util.Collection; +import java.util.List; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; @@ -76,6 +77,7 @@ public final class Internals { private static Function<@NotNull Boolean, ClickArea.Result> clickAreaHandlerResult = (result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static Supplier builtinPlugin = Internals::throwNotSetup; + private static Supplier> jeiCompatMods = Internals::throwNotSetup; private static T throwNotSetup() { throw new AssertionError("REI Internals have not been initialized!"); @@ -162,6 +164,10 @@ public final class Internals { return emptyEntryRenderer.get().cast(); } + public static List getJeiCompatMods() { + return jeiCompatMods.get(); + } + public interface EntryStackProvider { EntryStack empty(); -- cgit