From 94e323f75c17e297c33fba1d3afb5c47ae66a8ad Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 28 Aug 2022 18:50:24 +0900 Subject: Separate EntryListWidget and FavoritesListWidget more --- .../me/shedaniel/rei/api/client/ClientHelper.java | 5 +- .../rei/api/client/gui/widgets/DelegateWidget.java | 4 ++ .../gui/widgets/DelegateWidgetWithBounds.java | 12 +++++ .../rei/api/client/gui/widgets/TooltipQueue.java | 23 +++++++++ .../rei/api/client/gui/widgets/Widgets.java | 4 +- .../rei/api/client/overlay/ScreenOverlay.java | 12 +++++ .../rei/api/client/registry/screen/ClickArea.java | 14 ++++++ .../rei/api/client/view/ViewSearchBuilder.java | 15 ++++++ .../api/common/networking/NetworkingHelper.java | 56 ++++++++++++++++++++++ .../shedaniel/rei/impl/client/ClientInternals.java | 11 ++--- .../rei/impl/client/provider/TooltipRenderer.java | 34 +++++++++++++ 11 files changed, 181 insertions(+), 9 deletions(-) create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java create mode 100644 api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java (limited to 'api/src/main/java') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java index 7169e83ad..c044b583c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java @@ -28,6 +28,7 @@ import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.networking.NetworkingHelper; import me.shedaniel.rei.api.common.util.FormattingUtils; import me.shedaniel.rei.impl.client.ClientInternals; import net.fabricmc.api.EnvType; @@ -206,5 +207,7 @@ public interface ClientHelper { * * @return whether the client can use move items packets */ - boolean canUseMovePackets(); + default boolean canUseMovePackets() { + return NetworkingHelper.getInstance().client().canUseMovePackets(); + } } 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 e4ff00b7b..aa91c9b76 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 @@ -39,6 +39,10 @@ public class DelegateWidget extends WidgetWithBounds { this.widget = widget; } + public DelegateWidget() { + this(Widgets.noOp()); + } + protected Widget delegate() { return widget; } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java index 593a62588..e7f00d773 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/DelegateWidgetWithBounds.java @@ -36,6 +36,18 @@ public class DelegateWidgetWithBounds extends DelegateWidget { this.bounds = bounds; } + public DelegateWidgetWithBounds(Supplier bounds) { + this(Widgets.noOp(), bounds); + } + + public DelegateWidgetWithBounds(Rectangle bounds) { + this(Widgets.noOp(), () -> bounds); + } + + public DelegateWidgetWithBounds() { + this(new Rectangle()); + } + @Override public Rectangle getBounds() { return bounds.get(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java index c938cd8d6..007cd777c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/TooltipQueue.java @@ -1,3 +1,26 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.client.gui.widgets; import me.shedaniel.rei.impl.client.ClientInternals; 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 67dfe7cbb..0183b480e 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 @@ -333,7 +333,7 @@ public final class Widgets { } public static Widget delegate(Supplier supplier) { - return new DelegateWidget(Widgets.noOp()) { + return new DelegateWidget() { @Override protected Widget delegate() { return supplier.get(); @@ -342,7 +342,7 @@ public final class Widgets { } public static WidgetWithBounds delegateWithBounds(Supplier supplier) { - return new DelegateWidgetWithBounds(Widgets.noOp(), Rectangle::new) { + return new DelegateWidgetWithBounds() { @Override protected WidgetWithBounds delegate() { return supplier.get(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java index b9758f235..5d8ed2b80 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/ScreenOverlay.java @@ -28,8 +28,11 @@ import me.shedaniel.rei.api.client.gui.drag.DraggingContext; import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds; +import me.shedaniel.rei.api.client.search.SearchFilter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -96,6 +99,15 @@ public abstract class ScreenOverlay extends WidgetWithBounds { */ public abstract TextField getSearchField(); + /** + * Returns the current search filter. + * + * @return the current search filter + */ + @ApiStatus.Experimental + @Nullable + public abstract SearchFilter getCurrentSearchFilter(); + /** * Renders a tooltip. * diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java index 8b6aad935..97d46001e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/screen/ClickArea.java @@ -44,6 +44,20 @@ public interface ClickArea { @ApiStatus.NonExtendable interface ClickAreaContext { + static ClickAreaContext of(T screen, Point mouse) { + return new ClickAreaContext<>() { + @Override + public T getScreen() { + return screen; + } + + @Override + public Point getMousePosition() { + return mouse; + } + }; + } + T getScreen(); Point getMousePosition(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java index 5f7a2c1a4..985048b7a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java @@ -219,6 +219,21 @@ public interface ViewSearchBuilder { */ ViewSearchBuilder processingVisibilityHandlers(boolean processingVisibilityHandlers); + /** + * Force-all displays to the view search builder. + * + * @param displays the displays to add + * @return the {@link ViewSearchBuilder} for chaining + */ + ViewSearchBuilder addDisplays(Collection displays); + + /** + * Returns the collection of additional displays to show. + * + * @return the collection of additional displays to show. + */ + Collection getAdditionalDisplays(); + /** * Opens the view after the search is complete. * diff --git a/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java new file mode 100644 index 000000000..ca1e2ad41 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/networking/NetworkingHelper.java @@ -0,0 +1,56 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.common.networking; + +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.plugins.REIServerPlugin; +import me.shedaniel.rei.api.common.registry.Reloadable; + +public interface NetworkingHelper extends Reloadable { + static NetworkingHelper getInstance() { + return PluginManager.getServerInstance().get(NetworkingHelper.class); + } + + Client client(); + + interface Client { + boolean hasPermissionToUsePackets(); + + boolean hasOperatorPermission(); + + /** + * Returns whether the client can use delete items packets. + * + * @return whether the client can use delete items packets + */ + boolean canUseDeletePackets(); + + /** + * Returns whether the client can use move items packets. + * + * @return whether the client can use move items packets + */ + boolean canUseMovePackets(); + } +} diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java index 0791ec310..eeb03e5fb 100644 --- a/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java +++ b/api/src/main/java/me/shedaniel/rei/impl/client/ClientInternals.java @@ -40,7 +40,6 @@ import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.impl.client.provider.*; import me.shedaniel.rei.impl.common.Internals; import net.minecraft.ReportedException; -import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.item.TooltipFlag; @@ -66,9 +65,9 @@ public final class ClientInternals { private static final List OVERLAY_TICKERS = resolveServices(OverlayTicker.class); private static final AutoCraftingEvaluator AUTO_CRAFTING_EVALUATOR = resolveService(AutoCraftingEvaluator.class); private static final TooltipQueue TOOLTIP_QUEUE = resolveService(TooltipQueue.class); + private static final TooltipRenderer TOOLTIP_RENDERER = resolveService(TooltipRenderer.class); private static Function> favoriteEntryFromJson = (object) -> throwNotSetup(); private static Function clickAreaHandlerResult = (result) -> throwNotSetup(); - private static BiConsumer, TooltipComponent> clientTooltipComponentProvider = (tooltip, result) -> throwNotSetup(); private static BiFunction<@Nullable Point, Collection, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup(); private static TriFunction tooltipContextProvider = (point, texts, search) -> throwNotSetup(); private static Function tooltipEntryProvider = (component) -> throwNotSetup(); @@ -135,14 +134,14 @@ public final class ClientInternals { return clickAreaHandlerResult.apply(applicable); } - public static void getClientTooltipComponent(List tooltip, TooltipComponent component) { - clientTooltipComponentProvider.accept(tooltip, component); - } - public static Tooltip createTooltip(@Nullable Point point, Collection texts) { return tooltipProvider.apply(point, texts); } + public static TooltipRenderer getTooltipRenderer() { + return TOOLTIP_RENDERER; + } + public static TooltipContext createTooltipContext(Point point, @Nullable TooltipFlag flag, boolean isSearch) { return tooltipContextProvider.apply(point, flag, isSearch); } diff --git a/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java b/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java new file mode 100644 index 000000000..df510bee7 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/client/provider/TooltipRenderer.java @@ -0,0 +1,34 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.impl.client.provider; + +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public interface TooltipRenderer { + void renderTooltip(Screen screen, PoseStack matrices, Tooltip tooltip, int mouseX, int mouseY); +} -- cgit