From d7ac83de715a29714d4d5764f1aedb17ae967c73 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 21 Jun 2022 23:38:52 +0800 Subject: Primitive implementation of collapsible entries --- .../rei/api/client/overlay/OverlayListWidget.java | 12 +++ .../rei/api/client/plugins/REIClientPlugin.java | 11 +++ .../registry/entry/CollapsibleEntryRegistry.java | 90 ++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 api/src/main/java/me/shedaniel/rei/api/client/registry/entry/CollapsibleEntryRegistry.java (limited to 'api/src/main/java') diff --git a/api/src/main/java/me/shedaniel/rei/api/client/overlay/OverlayListWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/overlay/OverlayListWidget.java index 0685af202..1fa784806 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/overlay/OverlayListWidget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/overlay/OverlayListWidget.java @@ -39,7 +39,19 @@ public interface OverlayListWidget { */ EntryStack getFocusedStack(); + /** + * Returns the currently visible stacks in the overlay list widget. + * + * @return the currently visible stacks + */ Stream> getEntries(); + /** + * Returns whether the mouse is within the overlay list widget, + * accounting for excluded areas. + * + * @param point the mouse position + * @return whether the mouse is within the overlay list widget + */ boolean containsMouse(Point point); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java index 9cf6cdbb1..d316994e9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/plugins/REIClientPlugin.java @@ -28,6 +28,7 @@ import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry; import me.shedaniel.rei.api.client.favorites.FavoriteEntryType; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.registry.screen.ExclusionZones; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; @@ -95,6 +96,16 @@ public interface REIClientPlugin extends REIPlugin { default void registerEntries(EntryRegistry registry) { } + /** + * Registers entries to collapse on the entry panel. + * + * @param registry the collapsible entry registry + */ + @ApiStatus.OverrideOnly + @ApiStatus.Experimental + default void registerCollapsibleEntries(CollapsibleEntryRegistry registry) { + } + /** * Registers favorite entry types. * diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/CollapsibleEntryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/CollapsibleEntryRegistry.java new file mode 100644 index 000000000..a85054848 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/entry/CollapsibleEntryRegistry.java @@ -0,0 +1,90 @@ +/* + * 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.registry.entry; + +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.entry.type.EntryType; +import me.shedaniel.rei.api.common.plugins.PluginManager; +import me.shedaniel.rei.api.common.registry.Reloadable; +import net.minecraft.tags.TagKey; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +/** + * Registry for grouping and collapsing {@link EntryStack}s. + *

+ * The easiest way to use this is to use the {@link me.shedaniel.rei.api.common.util.EntryIngredients#ofItemTag(TagKey)} + * and collect tags together. + */ +@ApiStatus.Experimental +public interface CollapsibleEntryRegistry extends Reloadable { + /** + * @return the {@link CollapsibleEntryRegistry} instance + */ + static CollapsibleEntryRegistry getInstance() { + return PluginManager.getClientInstance().get(CollapsibleEntryRegistry.class); + } + + /** + * Groups the given {@link EntryStack}s into a single entry in the entry panel. + * + * @param stacks the stacks to group + * @param the type of the stacks + */ + void group(List> stacks); + + /** + * Groups the given {@link EntryStack}s into a single entry in the entry panel. + * + * @param stacks the stacks to group + * @param the type of the stacks + */ + default void group(EntryStack... stacks) { + group(Arrays.asList(stacks)); + } + + /** + * Groups the matching {@link EntryStack}s via the given predicate into + * a single entry in the entry panel. + * + * @param predicate the predicate to match the stacks + */ + void group(Predicate> predicate); + + /** + * Groups the matching {@link EntryStack}s via the given predicate into + * a single entry in the entry panel. + * + * @param type the entry type to match + * @param predicate the predicate to match the stacks + * @param the type of the stacks + */ + default void group(EntryType type, Predicate> predicate) { + group(stack -> stack.getType() == type && predicate.test(stack.cast())); + } +} -- cgit