diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-06-21 23:38:52 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-06-28 03:21:12 +0800 |
| commit | d7ac83de715a29714d4d5764f1aedb17ae967c73 (patch) | |
| tree | 8890c0c8fdce20bef23e2e6721d253047d81a174 /api/src/main/java/me/shedaniel | |
| parent | fbf63f0d545597676aae46729739b1b13f41452f (diff) | |
| download | RoughlyEnoughItems-d7ac83de715a29714d4d5764f1aedb17ae967c73.tar.gz RoughlyEnoughItems-d7ac83de715a29714d4d5764f1aedb17ae967c73.tar.bz2 RoughlyEnoughItems-d7ac83de715a29714d4d5764f1aedb17ae967c73.zip | |
Primitive implementation of collapsible entries
Diffstat (limited to 'api/src/main/java/me/shedaniel')
3 files changed, 113 insertions, 0 deletions
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<EntryStack<?>> 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; @@ -96,6 +97,16 @@ public interface REIClientPlugin extends REIPlugin<REIClientPlugin> { } /** + * 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. * * @param registry the registry 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. + * <p> + * 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<REIClientPlugin> { + /** + * @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 <T> the type of the stacks + */ + <T> void group(List<? extends EntryStack<? extends T>> stacks); + + /** + * Groups the given {@link EntryStack}s into a single entry in the entry panel. + * + * @param stacks the stacks to group + * @param <T> the type of the stacks + */ + default <T> void group(EntryStack<? extends T>... 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<? extends EntryStack<?>> 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 <T> the type of the stacks + */ + default <T> void group(EntryType<T> type, Predicate<EntryStack<T>> predicate) { + group(stack -> stack.getType() == type && predicate.test(stack.cast())); + } +} |
