diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-03-23 00:02:16 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-03-23 00:02:16 +0800 |
| commit | c027169dfe9503a9d913589eb322cc11ddad0baa (patch) | |
| tree | cea2db418d26b0ba9f054445891f272264ae3d30 /api/src/main/java | |
| parent | 7bbef49785f594dfe3d6eac0cfc6ee84841aae80 (diff) | |
| download | RoughlyEnoughItems-c027169dfe9503a9d913589eb322cc11ddad0baa.tar.gz RoughlyEnoughItems-c027169dfe9503a9d913589eb322cc11ddad0baa.tar.bz2 RoughlyEnoughItems-c027169dfe9503a9d913589eb322cc11ddad0baa.zip | |
Improve UncertainDisplayViewingScreen
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'api/src/main/java')
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/config/ConfigObject.java | 6 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/AbstractContainerEventHandler.java | 36 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java (renamed from api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java) | 4 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/widgets/DelegateWidget.java | 1 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widget.java | 2 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/widgets/WidgetWithBounds.java | 2 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/gui/widgets/Widgets.java | 40 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/api/registry/display/DisplayCategory.java | 2 | ||||
| -rw-r--r-- | api/src/main/java/me/shedaniel/rei/impl/Internals.java | 6 |
9 files changed, 86 insertions, 13 deletions
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/RecipeScreenType.java b/api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java index 63ebd814c..507fa2c28 100644 --- a/api/src/main/java/me/shedaniel/rei/api/gui/config/RecipeScreenType.java +++ b/api/src/main/java/me/shedaniel/rei/api/gui/config/DisplayScreenType.java @@ -32,10 +32,10 @@ import java.util.Locale; @ApiStatus.Internal @Environment(EnvType.CLIENT) -public enum RecipeScreenType { +public enum DisplayScreenType { UNSET, ORIGINAL, - VILLAGER; + COMPOSITE; @Override public String toString() { 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 { @@ -69,13 +72,23 @@ public final class Widgets { public static WidgetWithBounds withTranslate(Widget widget, Matrix4f translate) { WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); + return new WidgetWithBoundsWithTranslate(widgetWithBounds, () -> translate); + } + + public static <T extends Widget> WidgetWithBounds withTranslate(T widget, Function<T, Matrix4f> translate) { + WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); + return new WidgetWithBoundsWithTranslate(widgetWithBounds, () -> translate.apply(widget)); + } + + public static WidgetWithBounds withTranslate(Widget widget, Supplier<Matrix4f> translate) { + WidgetWithBounds widgetWithBounds = wrapWidgetWithBounds(widget); return new WidgetWithBoundsWithTranslate(widgetWithBounds, translate); } private static class WidgetWithBoundsWithTranslate extends DelegateWidget { - private final Matrix4f translate; + private final Supplier<Matrix4f> translate; - private WidgetWithBoundsWithTranslate(WidgetWithBounds widget, Matrix4f translate) { + private WidgetWithBoundsWithTranslate(WidgetWithBounds widget, Supplier<Matrix4f> 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<? extends GuiEventListener> 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<T extends Display> 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<Component>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static Supplier<BuiltinPlugin> builtinPlugin = Internals::throwNotSetup; + private static Supplier<List<String>> jeiCompatMods = Internals::throwNotSetup; private static <T> 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<String> getJeiCompatMods() { + return jeiCompatMods.get(); + } + public interface EntryStackProvider { EntryStack<Unit> empty(); |
