From fb91ed996b01f986492de4007cb86be5e68ad192 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 28 Aug 2022 20:48:46 +0900 Subject: More internal changes --- .../rei/impl/client/gui/hints/HintProvider.java | 3 +- .../rei/impl/client/gui/menu/MenuAccess.java | 51 ++++++++++++++++++++++ .../rei/impl/client/search/AsyncSearchManager.java | 7 +++ .../rei/impl/client/util/InternalEntryBounds.java | 12 +++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java create mode 100644 shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java (limited to 'shared-internals/src') diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java index 66a9f6a20..475e48f44 100644 --- a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java @@ -27,6 +27,7 @@ import me.shedaniel.math.Color; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; import me.shedaniel.rei.impl.common.Internals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -52,7 +53,7 @@ public interface HintProvider { Color getColor(); - List getButtons(); + List getButtons(MenuAccess access); record HintButton(Component name, Consumer action) {} } diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java new file mode 100644 index 000000000..79daeb3f0 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java @@ -0,0 +1,51 @@ +/* + * 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.gui.menu; + +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; + +import java.util.Collection; +import java.util.UUID; +import java.util.function.Predicate; +import java.util.function.Supplier; + +public interface MenuAccess { + boolean isOpened(UUID uuid); + + boolean isAnyOpened(); + + boolean isInBounds(UUID uuid); + + void open(UUID uuid, Rectangle selfBounds, Supplier> menuSupplier); + + void open(UUID uuid, Rectangle selfBounds, Supplier> menuSupplier, Predicate or, Predicate and); + + void openOrClose(UUID uuid, Rectangle selfBounds, Supplier> menuSupplier); + + boolean isValidPoint(Point point); + + void close(); +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java index eab390d90..be9216e72 100644 --- a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java @@ -29,6 +29,7 @@ import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -152,4 +153,10 @@ public class AsyncSearchManager implements SearchManager { public boolean matches(EntryStack stack) { return filter.test(stack); } + + @Override + @Nullable + public SearchFilter getSearchFilter() { + return filter; + } } diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java new file mode 100644 index 000000000..30569d0a0 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java @@ -0,0 +1,12 @@ +package me.shedaniel.rei.impl.client.util; + +import me.shedaniel.rei.api.client.config.ConfigObject; +import net.minecraft.util.Mth; + +public class InternalEntryBounds { + private static final int SIZE = 18; + + public static int entrySize() { + return Mth.ceil(SIZE * ConfigObject.getInstance().getEntrySize()); + } +} -- cgit