From de461fde691f593b85ffeae837b5b419a9abf7cc Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 9 Mar 2021 23:17:05 +0800 Subject: Use AbstractRecipeViewingScreen and remove static from ScreenHelper Signed-off-by: shedaniel --- .../main/java/me/shedaniel/rei/PluginDetector.java | 23 ++ .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 36 ++- .../rei/RoughlyEnoughItemsInitializer.java | 2 +- .../me/shedaniel/rei/RoughlyEnoughItemsState.java | 1 - .../rei/api/gui/config/entry/FilteringScreen.java | 18 +- .../gui/config/entry/RecipeScreenTypeEntry.java | 2 +- .../rei/gui/AbstractRecipeViewingScreen.java | 136 +++++++++++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 159 +++++++------ .../me/shedaniel/rei/gui/CurrentDraggingStack.java | 25 +- .../me/shedaniel/rei/gui/OverlaySearchField.java | 6 +- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 9 +- .../shedaniel/rei/gui/RecipeDisplayExporter.java | 2 +- .../java/me/shedaniel/rei/gui/RecipeScreen.java | 7 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 181 +++++---------- .../gui/SearchFilterSyntaxHighlightingScreen.java | 6 +- .../rei/gui/VillagerRecipeViewingScreen.java | 81 ++----- .../java/me/shedaniel/rei/gui/modules/Menu.java | 8 +- .../entries/EntryStackSubsetsMenuEntry.java | 18 +- .../rei/gui/modules/entries/GameModeMenuEntry.java | 3 +- .../gui/modules/entries/SubSubsetsMenuEntry.java | 16 +- .../rei/gui/modules/entries/WeatherMenuEntry.java | 3 +- .../rei/gui/plugin/DefaultRuntimePlugin.java | 33 +-- .../rei/gui/plugin/entry/ItemEntryDefinition.java | 2 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 13 +- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 15 +- .../rei/gui/widget/FavoritesListWidget.java | 12 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 4 +- .../me/shedaniel/rei/gui/widget/TabWidget.java | 7 +- .../me/shedaniel/rei/impl/AbstractEntryStack.java | 4 +- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 4 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 6 +- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 2 +- .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 4 +- .../me/shedaniel/rei/impl/InternalWidgets.java | 20 +- .../me/shedaniel/rei/impl/PluginManagerImpl.java | 2 +- .../java/me/shedaniel/rei/impl/REIHelperImpl.java | 235 +++++++++++++++++++ .../java/me/shedaniel/rei/impl/ScreenHelper.java | 257 --------------------- .../java/me/shedaniel/rei/impl/SearchArgument.java | 4 +- .../rei/impl/filtering/FilteringContextImpl.java | 2 +- .../rei/impl/filtering/FilteringResult.java | 2 +- .../impl/filtering/rules/ManualFilteringRule.java | 2 +- .../impl/filtering/rules/SearchFilteringRule.java | 4 +- .../rei/impl/registry/CategoryRegistryImpl.java | 19 +- .../me/shedaniel/rei/impl/search/MatchStatus.java | 2 +- .../widgets/FillRectangleDrawableConsumer.java | 5 +- .../me/shedaniel/rei/impl/widgets/PanelWidget.java | 5 +- .../rei/impl/widgets/TextFieldWidget.java | 7 +- .../shedaniel/rei/tests/plugin/REITestPlugin.java | 4 +- 48 files changed, 737 insertions(+), 681 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/REIHelperImpl.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/ScreenHelper.java (limited to 'runtime/src/main') diff --git a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java index 5e6de2399..528e279a6 100644 --- a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java +++ b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java @@ -1,3 +1,26 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 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; import me.shedaniel.architectury.annotations.ExpectPlatform; diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index c668dc282..15bee847e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -74,7 +74,6 @@ import net.minecraft.client.gui.screens.recipebook.GhostRecipe; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.gui.screens.recipebook.RecipeUpdateListener; import net.minecraft.client.resources.language.I18n; -import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.TextComponent; @@ -392,7 +391,6 @@ public class RoughlyEnoughItemsCore { return hasPermissionToUsePackets() || Minecraft.getInstance().gameMode.hasInfiniteItems(); } - @SuppressWarnings("deprecation") public void onInitializeClient() { IssuesDetector.detect(); registerClothEvents(); @@ -456,8 +454,9 @@ public class RoughlyEnoughItemsCore { if (!decider.isHandingScreen(screen)) continue; InteractionResult result = decider.shouldScreenBeOverlaid(screen); - if (result != InteractionResult.PASS) - return result == InteractionResult.FAIL || REIHelper.getInstance().getPreviousContainerScreen() == null; + if (result != InteractionResult.PASS) { + return result == InteractionResult.FAIL || REIHelper.getInstance().getPreviousScreen() == null; + } } } catch (ConcurrentModificationException ignored) { } @@ -477,12 +476,11 @@ public class RoughlyEnoughItemsCore { return InteractionResult.PASS; });*/ GuiEvent.INIT_POST.register((screen, widgets, children) -> { + REIHelperImpl.getInstance().setPreviousScreen(screen); if (shouldReturn(screen)) return; if (screen instanceof InventoryScreen && client.gameMode.hasInfiniteItems()) return; - if (screen instanceof AbstractContainerScreen) - ScreenHelper.setPreviousContainerScreen((AbstractContainerScreen) screen); boolean alreadyAdded = false; for (GuiEventListener element : Lists.newArrayList(children)) if (ContainerScreenOverlay.class.isAssignableFrom(element.getClass())) @@ -491,14 +489,14 @@ public class RoughlyEnoughItemsCore { else alreadyAdded = true; if (!alreadyAdded) - children.add(ScreenHelper.getLastOverlay(true, false)); + children.add(REIHelper.getInstance().getOverlay(true).get()); }); ClientScreenInputEvent.MOUSE_CLICKED_PRE.register((minecraftClient, screen, mouseX, mouseY, button) -> { isLeftModePressed = true; - if (ScreenHelper.getOptionalOverlay().isPresent()) + if (REIHelper.getInstance().getOverlay().isPresent()) if (screen instanceof CreativeModeInventoryScreen) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseClicked(mouseX, mouseY, button)) { - screen.setFocused(ScreenHelper.getLastOverlay()); + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseClicked(mouseX, mouseY, button)) { + screen.setFocused(REIHelper.getInstance().getOverlay().get()); if (button == 0) screen.setDragging(true); return InteractionResult.SUCCESS; @@ -509,8 +507,8 @@ public class RoughlyEnoughItemsCore { isLeftModePressed = false; if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.getOptionalOverlay().isPresent()) - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseReleased(mouseX, mouseY, button)) { + if (REIHelper.getInstance().getOverlay().isPresent()) + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseReleased(mouseX, mouseY, button)) { return InteractionResult.SUCCESS; } return InteractionResult.PASS; @@ -518,29 +516,29 @@ public class RoughlyEnoughItemsCore { ClientScreenInputEvent.MOUSE_SCROLLED_PRE.register((minecraftClient, screen, mouseX, mouseY, amount) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.isOverlayVisible() && ScreenHelper.getLastOverlay().mouseScrolled(mouseX, mouseY, amount)) + if (REIHelper.getInstance().isOverlayVisible() && REIHelper.getInstance().getOverlay().get().mouseScrolled(mouseX, mouseY, amount)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); ClientScreenInputEvent.CHAR_TYPED_PRE.register((minecraftClient, screen, character, keyCode) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (ScreenHelper.getLastOverlay().charTyped(character, keyCode)) + if (REIHelper.getInstance().getOverlay().get().charTyped(character, keyCode)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); GuiEvent.RENDER_POST.register((screen, matrices, mouseX, mouseY, delta) -> { if (shouldReturn(screen)) return; - ScreenHelper.getLastOverlay().render(matrices, mouseX, mouseY, delta); - if (!ScreenHelper.isOverlayVisible()) + REIHelper.getInstance().getOverlay().get().render(matrices, mouseX, mouseY, delta); + if (!REIHelper.getInstance().isOverlayVisible()) return; - ScreenHelper.getLastOverlay().lateRender(matrices, mouseX, mouseY, delta); + ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).lateRender(matrices, mouseX, mouseY, delta); }); ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((minecraftClient, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> { if (shouldReturn(screen)) return InteractionResult.PASS; - if (screen instanceof AbstractContainerScreen && ScreenHelper.getLastOverlay().mouseDragged(mouseX1, mouseY1, button, mouseX2, mouseY2)) + if (screen instanceof AbstractContainerScreen && REIHelper.getInstance().getOverlay().get().mouseDragged(mouseX1, mouseY1, button, mouseX2, mouseY2)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); @@ -554,7 +552,7 @@ public class RoughlyEnoughItemsCore { } if (screen.getFocused() != null && screen.getFocused() instanceof EditBox || (screen.getFocused() instanceof RecipeBookComponent && ((RecipeBookComponent) screen.getFocused()).searchBox != null && ((RecipeBookComponent) screen.getFocused()).searchBox.isFocused())) return InteractionResult.PASS; - if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) + if (REIHelper.getInstance().getOverlay().get().keyPressed(i, i1, i2)) return InteractionResult.SUCCESS; return InteractionResult.PASS; }); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 7308fbb38..dfe52a3a2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -49,7 +49,7 @@ public class RoughlyEnoughItemsInitializer { initializeEntryPoint("me.shedaniel.rei.RoughlyEnoughItemsCore"); initializeEntryPoint("me.shedaniel.rei.REIModMenuEntryPoint"); initializeEntryPoint("me.shedaniel.rei.impl.ClientHelperImpl"); - initializeEntryPoint("me.shedaniel.rei.impl.ScreenHelper"); + initializeEntryPoint("me.shedaniel.rei.impl.REIHelperImpl"); } initializeEntryPoint("me.shedaniel.rei.impl.ErrorDisplayer"); diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java index 4f8c42bec..c827b50d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsState.java @@ -25,7 +25,6 @@ package me.shedaniel.rei; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.architectury.utils.Env; -import net.fabricmc.api.EnvType; import net.minecraft.util.Tuple; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java index f5d5464a2..cdd1b5add 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringScreen.java @@ -26,7 +26,10 @@ package me.shedaniel.rei.api.gui.config.entry; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.*; +import com.mojang.blaze3d.vertex.BufferBuilder; +import com.mojang.blaze3d.vertex.DefaultVertexFormat; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.Tesselator; import com.mojang.math.Matrix4f; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; @@ -36,13 +39,13 @@ import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.ConfigObject; -import me.shedaniel.rei.api.registry.entry.EntryRegistry; -import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.gui.widgets.Tooltip; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.entry.EntryRegistry; +import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.gui.OverlaySearchField; import me.shedaniel.rei.gui.widget.EntryWidget; -import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.SearchArgument; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; @@ -262,7 +265,7 @@ public class FilteringScreen extends Screen { this.backButton.render(matrices, mouseX, mouseY, delta); if (tooltip != null) { - ScreenHelper.getLastOverlay().renderTooltip(matrices, tooltip); + ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).renderTooltip(matrices, tooltip); } this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); @@ -378,10 +381,7 @@ public class FilteringScreen extends Screen { return true; } } - if (backButton.mouseClicked(double_1, double_2, int_1)) { - return true; - } - return false; + return backButton.mouseClicked(double_1, double_2, int_1); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java index ed3aff6b7..3f32747e9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/RecipeScreenTypeEntry.java @@ -27,8 +27,8 @@ import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.clothconfig2.gui.entries.TooltipListEntry; -import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.api.gui.config.RecipeScreenType; +import me.shedaniel.rei.gui.PreRecipeViewingScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.AbstractButton; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java new file mode 100644 index 000000000..fd8007d19 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java @@ -0,0 +1,136 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 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.gui; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.gui.widgets.Widget; +import me.shedaniel.rei.api.ingredient.EntryStack; +import me.shedaniel.rei.api.registry.display.Display; +import me.shedaniel.rei.api.registry.display.DisplayCategory; +import me.shedaniel.rei.api.util.CollectionUtils; +import me.shedaniel.rei.gui.widget.EntryWidget; +import me.shedaniel.rei.impl.ClientHelperImpl; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; + +public abstract class AbstractRecipeViewingScreen extends Screen implements RecipeScreen { + protected final Map, List> categoryMap; + protected final List> categories; + protected EntryStack ingredientStackToNotice = EntryStack.empty(); + protected EntryStack resultStackToNotice = EntryStack.empty(); + protected int selectedCategoryIndex = 0; + protected int tabsPerPage; + protected Rectangle bounds; + + protected AbstractRecipeViewingScreen(Map, List> categoryMap, @Nullable ResourceLocation category, int tabsPerPage) { + super(NarratorChatListener.NO_TITLE); + this.categoryMap = categoryMap; + this.categories = Lists.newArrayList(categoryMap.keySet()); + this.tabsPerPage = tabsPerPage; + if (category != null) { + for (int i = 0; i < categories.size(); i++) { + if (categories.get(i).getIdentifier().equals(category)) { + this.selectedCategoryIndex = i; + break; + } + } + } + } + + @Override + public Rectangle getBounds() { + return bounds; + } + + @Override + public void addIngredientStackToNotice(EntryStack stack) { + this.ingredientStackToNotice = stack; + } + + @Override + public void addResultStackToNotice(EntryStack stack) { + this.resultStackToNotice = stack; + } + + @Override + public boolean isPauseScreen() { + return false; + } + + @Override + public ResourceLocation getCurrentCategory() { + return getSelectedCategory().getIdentifier(); + } + + public DisplayCategory getSelectedCategory() { + return (DisplayCategory) categories.get(selectedCategoryIndex); + } + + protected void previousCategory() { + int currentCategoryIndex = selectedCategoryIndex; + currentCategoryIndex--; + if (currentCategoryIndex < 0) + currentCategoryIndex = categories.size() - 1; + ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getIdentifier(), ingredientStackToNotice, resultStackToNotice); + } + + protected void nextCategory() { + int currentCategoryIndex = selectedCategoryIndex; + currentCategoryIndex++; + if (currentCategoryIndex >= categories.size()) + currentCategoryIndex = 0; + ClientHelperImpl.getInstance().openRecipeViewingScreen(categoryMap, categories.get(currentCategoryIndex).getIdentifier(), ingredientStackToNotice, resultStackToNotice); + } + + protected void transformIngredientNotice(List setupDisplay, EntryStack noticeStack) { + transformNotice(1, setupDisplay, noticeStack); + } + + protected void transformResultNotice(List setupDisplay, EntryStack noticeStack) { + transformNotice(2, setupDisplay, noticeStack); + } + + private static void transformNotice(int marker, List setupDisplay, EntryStack noticeStack) { + if (noticeStack.isEmpty()) + return; + for (Widget widget : setupDisplay) { + if (widget instanceof EntryWidget) { + EntryWidget entry = (EntryWidget) widget; + if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { + EntryStack stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.getEntries(), noticeStack); + if (stack != null) { + entry.clearStacks(); + entry.entry(stack); + } + } + } + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index e44a56f18..2daf4db4f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.gui; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -34,28 +35,37 @@ import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.favorites.FavoriteEntry; +import me.shedaniel.rei.api.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.gui.drag.DraggableStack; import me.shedaniel.rei.api.gui.drag.DraggableStackProvider; import me.shedaniel.rei.api.gui.drag.DraggableStackVisitor; import me.shedaniel.rei.api.gui.drag.DraggingContext; -import me.shedaniel.rei.api.gui.widgets.*; +import me.shedaniel.rei.api.gui.widgets.Button; +import me.shedaniel.rei.api.gui.widgets.Tooltip; +import me.shedaniel.rei.api.gui.widgets.Widget; +import me.shedaniel.rei.api.gui.widgets.Widgets; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.ingredient.util.EntryStacks; -import me.shedaniel.rei.api.favorites.FavoriteEntry; -import me.shedaniel.rei.api.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.registry.category.CategoryRegistry; import me.shedaniel.rei.api.registry.screen.ClickArea; import me.shedaniel.rei.api.registry.screen.DisplayBoundsProvider; import me.shedaniel.rei.api.registry.screen.OverlayDecider; import me.shedaniel.rei.api.registry.screen.ScreenRegistry; +import me.shedaniel.rei.api.util.CollectionUtils; import me.shedaniel.rei.api.util.ImmutableLiteralText; import me.shedaniel.rei.api.view.ViewSearchBuilder; import me.shedaniel.rei.gui.modules.Menu; import me.shedaniel.rei.gui.modules.entries.GameModeMenuEntry; import me.shedaniel.rei.gui.modules.entries.WeatherMenuEntry; -import me.shedaniel.rei.gui.widget.*; -import me.shedaniel.rei.impl.*; -import me.shedaniel.rei.api.util.CollectionUtils; +import me.shedaniel.rei.gui.widget.EntryListWidget; +import me.shedaniel.rei.gui.widget.EntryWidget; +import me.shedaniel.rei.gui.widget.FavoritesListWidget; +import me.shedaniel.rei.gui.widget.LateRenderable; +import me.shedaniel.rei.impl.ClientHelperImpl; +import me.shedaniel.rei.impl.InternalWidgets; +import me.shedaniel.rei.impl.REIHelperImpl; +import me.shedaniel.rei.impl.Weather; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; @@ -85,7 +95,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; @ApiStatus.Internal -public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverlay { +public class ContainerScreenOverlay extends REIOverlay { private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private static final List TOOLTIPS = Lists.newArrayList(); private static final List AFTER_RENDER = Lists.newArrayList(); @@ -101,6 +111,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Nullable private ContainerScreenOverlay.OverlayMenu overlayMenu = null; + public Set> inventoryStacks = Sets.newHashSet(); + public static EntryListWidget getEntryListWidget() { return ENTRY_LIST_WIDGET; } @@ -110,6 +122,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl return favoritesListWidget; } + public static ContainerScreenOverlay getInstance() { + return (ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get(); + } + private static class OverlayMenu { @NotNull private UUID uuid; @@ -146,7 +162,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl private void proceedOpenMenuOrElse(UUID uuid, Runnable runnable, Consumer orElse) { if (overlayMenu == null || !overlayMenu.uuid.equals(uuid)) { - removeOverlayMenu(); + closeOverlayMenu(); runnable.run(); } else { orElse.accept(this.overlayMenu); @@ -159,14 +175,15 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @ApiStatus.Internal @Nullable - public Menu getSubsetsMenu() { + public Menu getOverlayMenu() { if (isMenuOpened(Menu.SUBSETS)) return this.overlayMenu.menu; throw new IllegalStateException("Subsets menu accessed when subsets are not opened!"); } @ApiStatus.Internal - public void removeOverlayMenu() { + @Override + public void closeOverlayMenu() { OverlayMenu tmpOverlayMenu = this.overlayMenu; if (tmpOverlayMenu != null) AFTER_RENDER.add(() -> this.widgets.remove(tmpOverlayMenu.wrappedMenu)); @@ -195,7 +212,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl this.shouldReload = false; //Update Variables this.children().clear(); - this.removeOverlayMenu(); + this.closeOverlayMenu(); this.window = Minecraft.getInstance().getWindow(); this.bounds = ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); widgets.add(ENTRY_LIST_WIDGET); @@ -206,13 +223,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl favoritesListWidget.favoritePanel.resetRows(); widgets.add(favoritesListWidget); } - ENTRY_LIST_WIDGET.updateArea(ScreenHelper.getSearchField() == null ? "" : ScreenHelper.getSearchField().getText()); - if (ScreenHelper.getSearchField() == null) { - ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0)); - } - ScreenHelper.getSearchField().getBounds().setBounds(getSearchFieldArea()); - this.widgets.add(ScreenHelper.getSearchField()); - ScreenHelper.getSearchField().setResponder(s -> ENTRY_LIST_WIDGET.updateSearch(s, false)); + ENTRY_LIST_WIDGET.updateArea(REIHelperImpl.getSearchField() == null ? "" : REIHelperImpl.getSearchField().getText()); + REIHelperImpl.getSearchField().getBounds().setBounds(getSearchFieldArea()); + this.widgets.add(REIHelperImpl.getSearchField()); + REIHelperImpl.getSearchField().setResponder(s -> ENTRY_LIST_WIDGET.updateSearch(s, false)); if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { widgets.add(leftButton = Widgets.createButton(new Rectangle(bounds.x, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableComponent("text.rei.left_arrow")) .onClick(button -> { @@ -245,7 +259,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); return; } - ConfigManager.getInstance().openConfigScreen(REIHelper.getInstance().getPreviousContainerScreen()); + ConfigManager.getInstance().openConfigScreen(REIHelper.getInstance().getPreviousScreen()); }) .onRender((matrices, button) -> { if (ClientHelper.getInstance().isCheating() && RoughlyEnoughItemsCore.hasOperatorPermission()) { @@ -293,7 +307,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl menu.menuStartPoint.x -= menu.getBounds().width - button.getBounds().width; openMenu(Menu.GAME_TYPE, menu, point -> button.isFocused() && button.containsMouse(PointHelper.ofMouse())); } else { - removeOverlayMenu(); + closeOverlayMenu(); } } } @@ -316,7 +330,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl menu.menuStartPoint.x -= menu.getBounds().width - button.getBounds().width; openMenu(Menu.WEATHER, menu, point -> button.isFocused() && button.containsMouse(PointHelper.ofMouse())); } else { - removeOverlayMenu(); + closeOverlayMenu(); } } } @@ -337,7 +351,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl proceedOpenMenuOrElse(Menu.SUBSETS, () -> { openMenu(Menu.SUBSETS, Menu.createSubsetsMenuFromRegistry(new Point(subsetsButtonBounds.x, subsetsButtonBounds.getMaxY())), point -> true); }, menu -> { - removeOverlayMenu(); + closeOverlayMenu(); }); }), 0, 0, 600))); } @@ -359,7 +373,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl .focusable(false) .onClick(button -> { ConfigManager.getInstance().toggleCraftableOnly(); - ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText(), true); + ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); }) .onRender((matrices, button) -> button.setTint(ConfigManager.getInstance().isCraftableOnlyEnabled() ? 939579655 : 956235776)) .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) @@ -382,7 +396,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } } - private static class RecipeViewingScreenDraggable extends Widget implements DraggableStackProvider{ + private static class RecipeViewingScreenDraggable extends Widget implements DraggableStackProvider { @Nullable @Override public DraggableStack getHoveredStack(DraggingContext context, double mouseX, double mouseY) { @@ -390,22 +404,22 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl if (widget instanceof EntryWidget) { if (widget.containsMouse(mouseX, mouseY)) { return new DraggableStack() { - EntryStack stack = ((EntryWidget)widget).getCurrentEntry().copy().rewrap(); + EntryStack stack = ((EntryWidget) widget).getCurrentEntry().copy().rewrap(); @Override public EntryStack getStack() { return stack; } - + @Override public void drag() { - + } - + @Override public void release(boolean accepted) { if (!accepted) { - context.registerRenderBackToPosition(this, () -> new Point(((EntryWidget) widget).getBounds().x - 8, ((EntryWidget) widget).getBounds().y - 8)); + context.renderBackToPosition(this, () -> new Point(((EntryWidget) widget).getBounds().x - 8, ((EntryWidget) widget).getBounds().y - 8)); } } }; @@ -414,12 +428,12 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } return null; } - + @Override public void render(PoseStack poseStack, int i, int j, float f) { - + } - + @Override public List children() { return Collections.emptyList(); @@ -427,18 +441,16 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } private Rectangle getSubsetsButtonBounds() { + // TODO rely on the screen registry if (ConfigObject.getInstance().isSubsetsEnabled()) { - if (Minecraft.getInstance().screen instanceof RecipeViewingScreen) { - RecipeViewingScreen widget = (RecipeViewingScreen) Minecraft.getInstance().screen; + if (Minecraft.getInstance().screen instanceof AbstractRecipeViewingScreen) { + AbstractRecipeViewingScreen widget = (AbstractRecipeViewingScreen) Minecraft.getInstance().screen; return new Rectangle(widget.getBounds().x, 3, widget.getBounds().width, 18); } - if (Minecraft.getInstance().screen instanceof VillagerRecipeViewingScreen) { - VillagerRecipeViewingScreen widget = (VillagerRecipeViewingScreen) Minecraft.getInstance().screen; - return new Rectangle(widget.bounds.x, 3, widget.bounds.width, 18); - } AbstractContainerScreen containerScreen = REIHelper.getInstance().getPreviousContainerScreen(); - if (containerScreen != null) + if (containerScreen != null) { return new Rectangle(containerScreen.leftPos, 3, containerScreen.imageWidth, 18); + } } return null; } @@ -480,7 +492,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl int widthRemoved = 1; if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; - SearchFieldLocation searchFieldLocation = ScreenHelper.getContextualSearchFieldLocation(); + SearchFieldLocation searchFieldLocation = REIHelper.getInstance().getContextualSearchFieldLocation(); switch (searchFieldLocation) { case TOP_SIDE: return getTopSideSearchFieldArea(widthRemoved); @@ -541,7 +553,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { if (shouldReload) { - ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText(), true); + ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); init(); } else { for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(minecraft.screen.getClass())) { @@ -553,9 +565,9 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } if (ConfigManager.getInstance().isCraftableOnlyEnabled()) { Set> currentStacks = ClientHelperImpl.getInstance()._getInventoryItemsTypes(); - if (!currentStacks.equals(ScreenHelper.inventoryStacks)) { - ScreenHelper.inventoryStacks = currentStacks; - ENTRY_LIST_WIDGET.updateSearch(ScreenHelper.getSearchField().getText(), true); + if (!currentStacks.equals(this.inventoryStacks)) { + this.inventoryStacks = currentStacks; + ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); } } if (OverlaySearchField.isHighlighting) { @@ -594,8 +606,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } public void lateRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (ScreenHelper.isOverlayVisible()) { - ScreenHelper.getSearchField().laterRender(matrices, mouseX, mouseY, delta); + if (REIHelper.getInstance().isOverlayVisible()) { + REIHelperImpl.getSearchField().laterRender(matrices, mouseX, mouseY, delta); for (Widget widget : widgets) { if (widget instanceof LateRenderable && (overlayMenu == null || overlayMenu.wrappedMenu != widget)) widget.render(matrices, mouseX, mouseY, delta); @@ -646,7 +658,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl } public void renderWidgets(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return; if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { leftButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1); @@ -660,7 +672,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return false; if (overlayMenu != null && overlayMenu.wrappedMenu.mouseScrolled(mouseX, mouseY, amount)) return true; @@ -692,15 +704,15 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (ScreenHelper.isOverlayVisible()) { - if (ScreenHelper.getSearchField().keyPressed(keyCode, scanCode, modifiers)) + if (REIHelper.getInstance().isOverlayVisible()) { + if (REIHelperImpl.getSearchField().keyPressed(keyCode, scanCode, modifiers)) return true; for (GuiEventListener listener : widgets) - if (listener != ScreenHelper.getSearchField() && listener.keyPressed(keyCode, scanCode, modifiers)) + if (listener != REIHelperImpl.getSearchField() && listener.keyPressed(keyCode, scanCode, modifiers)) return true; } if (ConfigObject.getInstance().getHideKeybind().matchesKey(keyCode, scanCode)) { - ScreenHelper.toggleOverlayVisible(); + REIHelper.getInstance().toggleOverlayVisible(); return true; } EntryStack stack = ScreenRegistry.getInstance().getFocusedStack(Minecraft.getInstance().screen); @@ -717,17 +729,17 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ConfigManager.getInstance().saveConfig(); FavoritesListWidget favoritesListWidget = ContainerScreenOverlay.getFavoritesListWidget(); if (favoritesListWidget != null) - favoritesListWidget.updateSearch(ContainerScreenOverlay.getEntryListWidget(), ScreenHelper.getSearchField().getText()); + favoritesListWidget.updateSearch(ContainerScreenOverlay.getEntryListWidget(), REIHelperImpl.getSearchField().getText()); return true; } } - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return false; if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesKey(keyCode, scanCode)) { - ScreenHelper.getSearchField().setFocused(true); - setFocused(ScreenHelper.getSearchField()); - ScreenHelper.getSearchField().keybindFocusTime = System.currentTimeMillis(); - ScreenHelper.getSearchField().keybindFocusKey = keyCode; + REIHelperImpl.getSearchField().setFocused(true); + setFocused(REIHelperImpl.getSearchField()); + REIHelperImpl.getSearchField().keybindFocusTime = System.currentTimeMillis(); + REIHelperImpl.getSearchField().keybindFocusKey = keyCode; return true; } return false; @@ -735,12 +747,12 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public boolean charTyped(char char_1, int int_1) { - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return false; - if (ScreenHelper.getSearchField().charTyped(char_1, int_1)) + if (REIHelperImpl.getSearchField().charTyped(char_1, int_1)) return true; for (GuiEventListener listener : widgets) - if (listener != ScreenHelper.getSearchField() && listener.charTyped(char_1, int_1)) + if (listener != REIHelperImpl.getSearchField() && listener.charTyped(char_1, int_1)) return true; return false; } @@ -753,7 +765,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (ConfigObject.getInstance().getHideKeybind().matchesMouse(button)) { - ScreenHelper.toggleOverlayVisible(); + REIHelper.getInstance().toggleOverlayVisible(); return true; } EntryStack stack = ScreenRegistry.getInstance().getFocusedStack(Minecraft.getInstance().screen); @@ -770,11 +782,11 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl ConfigManager.getInstance().saveConfig(); FavoritesListWidget favoritesListWidget = ContainerScreenOverlay.getFavoritesListWidget(); if (favoritesListWidget != null) - favoritesListWidget.updateSearch(ContainerScreenOverlay.getEntryListWidget(), ScreenHelper.getSearchField().getText()); + favoritesListWidget.updateSearch(ContainerScreenOverlay.getEntryListWidget(), REIHelper.getInstance().getSearchTextField().getText()); return true; } } - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return false; if (overlayMenu != null) { if (overlayMenu.wrappedMenu.mouseClicked(mouseX, mouseY, button)) { @@ -782,10 +794,10 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl else this.setFocused(null); if (button == 0) this.setDragging(true); - ScreenHelper.getSearchField().setFocused(false); + REIHelperImpl.getSearchField().setFocused(false); return true; } else if (!overlayMenu.inBounds.test(new Point(mouseX, mouseY))) { - removeOverlayMenu(); + closeOverlayMenu(); } } if (ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { @@ -795,7 +807,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl public Screen getScreen() { return screen; } - + @Override public Point getMousePosition() { return new Point(mouseX, mouseY); @@ -814,14 +826,14 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl if (button == 0) this.setDragging(true); if (!(element instanceof OverlaySearchField)) - ScreenHelper.getSearchField().setFocused(false); + REIHelperImpl.getSearchField().setFocused(false); return true; } if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesMouse(button)) { - ScreenHelper.getSearchField().setFocused(true); - setFocused(ScreenHelper.getSearchField()); - ScreenHelper.getSearchField().keybindFocusTime = -1; - ScreenHelper.getSearchField().keybindFocusKey = -1; + REIHelperImpl.getSearchField().setFocused(true); + setFocused(REIHelperImpl.getSearchField()); + REIHelperImpl.getSearchField().keybindFocusTime = -1; + REIHelperImpl.getSearchField().keybindFocusKey = -1; return true; } return false; @@ -829,7 +841,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl @Override public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) { - if (!ScreenHelper.isOverlayVisible()) + if (!REIHelper.getInstance().isOverlayVisible()) return false; return (this.getFocused() != null && this.isDragging() && int_1 == 0) && this.getFocused().mouseDragged(double_1, double_2, int_1, double_3, double_4); } @@ -838,6 +850,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds implements REIOverl return bounds.contains(mouseX, mouseY) && isNotInExclusionZones(mouseX, mouseY); } + @Override public boolean isNotInExclusionZones(double mouseX, double mouseY) { for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(Minecraft.getInstance().screen.getClass())) { InteractionResult in = decider.isInZone(mouseX, mouseY); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/CurrentDraggingStack.java b/runtime/src/main/java/me/shedaniel/rei/gui/CurrentDraggingStack.java index 6f464100e..9a71db41d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/CurrentDraggingStack.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/CurrentDraggingStack.java @@ -1,3 +1,26 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 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.gui; import com.mojang.blaze3d.vertex.PoseStack; @@ -108,7 +131,7 @@ public class CurrentDraggingStack extends Widget implements LateRenderable, Drag } @Override - public void registerRenderBackToPosition(DraggableStack stack, Supplier position) { + public void renderBackToPosition(DraggableStack stack, Supplier position) { } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java b/runtime/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java index 347c98507..f7a898b5b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java @@ -31,14 +31,14 @@ import me.shedaniel.math.Color; import me.shedaniel.math.Point; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.ConfigObject; +import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.gui.config.SyntaxHighlightingMode; -import me.shedaniel.rei.impl.widgets.TextFieldWidget; import me.shedaniel.rei.impl.OverlaySearchFieldSyntaxHighlighter; -import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.TextTransformations; import me.shedaniel.rei.impl.search.Argument; import me.shedaniel.rei.impl.search.ArgumentsRegistry; import me.shedaniel.rei.impl.search.TextArgument; +import me.shedaniel.rei.impl.widgets.TextFieldWidget; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.language.I18n; @@ -232,7 +232,7 @@ public class OverlaySearchField extends TextFieldWidget implements TextFieldWidg @Override public boolean containsMouse(double mouseX, double mouseY) { - return (!isMain || ScreenHelper.getLastOverlay().isNotInExclusionZones(mouseX, mouseY)) && super.containsMouse(mouseX, mouseY); + return (!isMain || REIHelper.getInstance().getOverlay().get().isNotInExclusionZones(mouseX, mouseY)) && super.containsMouse(mouseX, mouseY); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index 30ae6b1d5..21551702f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -30,11 +30,11 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWi import me.shedaniel.clothconfig2.impl.EasingMethod; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.gui.widgets.Widgets; +import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.gui.config.RecipeScreenType; import me.shedaniel.rei.api.gui.widgets.Widget; import me.shedaniel.rei.api.gui.widgets.WidgetWithBounds; -import me.shedaniel.rei.impl.ScreenHelper; +import me.shedaniel.rei.api.gui.widgets.Widgets; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; @@ -162,8 +162,9 @@ public class PreRecipeViewingScreen extends Screen { public boolean keyPressed(int int_1, int int_2, int int_3) { if (int_1 == 256 || this.minecraft.options.keyInventory.matches(int_1, int_2)) { Minecraft.getInstance().setScreen(parent); - if (parent instanceof AbstractContainerScreen) - ScreenHelper.getLastOverlay().init(); + if (parent instanceof AbstractContainerScreen) { + REIHelper.getInstance().getOverlay().get().queueReloadOverlay(); + } return true; } return super.keyPressed(int_1, int_2, int_3); diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java index 578187b30..5f4446e62 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java @@ -30,8 +30,8 @@ import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.gui.toast.ExportRecipeIdentifierToast; import me.shedaniel.rei.api.gui.widgets.Widget; +import me.shedaniel.rei.gui.toast.ExportRecipeIdentifierToast; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.events.GuiEventListener; diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java index dc91068fd..d34eb18a4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeScreen.java @@ -23,21 +23,20 @@ package me.shedaniel.rei.gui; +import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.ingredient.EntryStack; import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.ApiStatus; @ApiStatus.Internal public interface RecipeScreen { - @ApiStatus.Internal + Rectangle getBounds(); + void addIngredientStackToNotice(EntryStack stack); - @ApiStatus.Internal void addResultStackToNotice(EntryStack stack); - @ApiStatus.Internal ResourceLocation getCurrentCategory(); - @ApiStatus.Internal void recalculateCategoryPage(); } \ No newline at end of file diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 4fd96d390..b849b20ba 100644 --- a/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -33,31 +33,32 @@ import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.ButtonAreaSupplier; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.ConfigObject; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.gui.widgets.Button; +import me.shedaniel.rei.api.gui.widgets.Panel; +import me.shedaniel.rei.api.gui.widgets.Widget; +import me.shedaniel.rei.api.gui.widgets.Widgets; import me.shedaniel.rei.api.ingredient.EntryIngredient; import me.shedaniel.rei.api.ingredient.EntryStack; import me.shedaniel.rei.api.registry.category.CategoryRegistry; import me.shedaniel.rei.api.registry.display.Display; import me.shedaniel.rei.api.registry.display.DisplayCategory; -import me.shedaniel.rei.api.registry.display.DisplayRegistry; +import me.shedaniel.rei.api.util.CollectionUtils; import me.shedaniel.rei.api.util.ImmutableLiteralText; -import me.shedaniel.rei.api.gui.widgets.Button; -import me.shedaniel.rei.api.gui.widgets.Panel; -import me.shedaniel.rei.api.gui.widgets.Widgets; import me.shedaniel.rei.api.view.ViewSearchBuilder; import me.shedaniel.rei.gui.widget.EntryWidget; import me.shedaniel.rei.gui.widget.RecipeChoosePageWidget; import me.shedaniel.rei.gui.widget.TabWidget; -import me.shedaniel.rei.api.gui.widgets.Widget; import me.shedaniel.rei.impl.ClientHelperImpl; import me.shedaniel.rei.impl.InternalWidgets; -import me.shedaniel.rei.impl.ScreenHelper; +import me.shedaniel.rei.impl.REIHelperImpl; import me.shedaniel.rei.impl.widgets.PanelWidget; -import me.shedaniel.rei.api.util.CollectionUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.sounds.SimpleSoundInstance; @@ -77,21 +78,16 @@ import java.util.Optional; import java.util.function.Supplier; @ApiStatus.Internal -public class RecipeViewingScreen extends Screen implements RecipeScreen { +public class RecipeViewingScreen extends AbstractRecipeViewingScreen { public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); private final List preWidgets = Lists.newArrayList(); private final List widgets = Lists.newArrayList(); private final Map> recipeBounds = Maps.newHashMap(); private final List tabs = Lists.newArrayList(); - private final Map, List> categoriesMap; - private final List> categories; - private final DisplayCategory selectedCategory; public int page; public int categoryPages = -1; public boolean choosePageActivated = false; public RecipeChoosePageWidget recipeChoosePageWidget; - private int tabsPerPage = 5; - private Rectangle bounds; @Nullable private Panel workingStationsBaseWidget; private Button recipeBack, recipeNext, categoryBack, categoryNext; @@ -99,64 +95,8 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { private EntryStack resultStackToNotice = EntryStack.empty(); public RecipeViewingScreen(Map, List> categoriesMap, @Nullable ResourceLocation category) { - super(NarratorChatListener.NO_TITLE); + super(categoriesMap, category, 5); this.bounds = new Rectangle(0, 0, 176, 150); - this.categoriesMap = categoriesMap; - this.categories = Lists.newArrayList(categoriesMap.keySet()); - DisplayCategory selected = categories.get(0); - if (category != null) { - for (DisplayCategory displayCategory : categories) { - if (displayCategory.getIdentifier().equals(category)) { - selected = displayCategory; - break; - } - } - } - this.selectedCategory = (DisplayCategory) selected; - } - - @ApiStatus.Internal - static void transformIngredientNotice(List setupDisplay, EntryStack noticeStack) { - transformNotice(1, setupDisplay, noticeStack); - } - - @ApiStatus.Internal - static void transformResultNotice(List setupDisplay, EntryStack noticeStack) { - transformNotice(2, setupDisplay, noticeStack); - } - - private static void transformNotice(int marker, List setupDisplay, EntryStack noticeStack) { - if (noticeStack.isEmpty()) - return; - for (Widget widget : setupDisplay) { - if (widget instanceof EntryWidget) { - EntryWidget entry = (EntryWidget) widget; - if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { - EntryStack stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.getEntries(), noticeStack); - if (stack != null) { - entry.clearStacks(); - entry.entry(stack); - } - } - } - } - } - - @ApiStatus.Internal - @Override - public void addIngredientStackToNotice(EntryStack stack) { - this.ingredientStackToNotice = stack; - } - - @ApiStatus.Internal - @Override - public void addResultStackToNotice(EntryStack stack) { - this.resultStackToNotice = stack; - } - - @Override - public ResourceLocation getCurrentCategory() { - return selectedCategory.getIdentifier(); } @Override @@ -197,24 +137,19 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { if (element.keyPressed(keyCode, scanCode, modifiers)) return true; if (keyCode == 256 || this.minecraft.options.keyInventory.matches(keyCode, scanCode)) { - Minecraft.getInstance().setScreen(REIHelper.getInstance().getPreviousContainerScreen()); + Minecraft.getInstance().setScreen(REIHelper.getInstance().getPreviousScreen()); return true; } if (keyCode == 259) { - if (ScreenHelper.hasLastRecipeScreen()) - minecraft.setScreen(ScreenHelper.getLastRecipeScreen()); + if (REIHelperImpl.getInstance().hasLastRecipeScreen()) + minecraft.setScreen(REIHelperImpl.getInstance().getLastRecipeScreen()); else - minecraft.setScreen(REIHelper.getInstance().getPreviousContainerScreen()); + minecraft.setScreen(REIHelper.getInstance().getPreviousScreen());