From c027169dfe9503a9d913589eb322cc11ddad0baa Mon Sep 17 00:00:00 2001 From: shedaniel Date: Tue, 23 Mar 2021 00:02:16 +0800 Subject: Improve UncertainDisplayViewingScreen Signed-off-by: shedaniel --- .../api/gui/config/entry/FilteringRulesScreen.java | 2 +- .../gui/config/entry/RecipeScreenTypeEntry.java | 24 +- .../rei/gui/AbstractDisplayViewingScreen.java | 141 ++++++ .../rei/gui/AbstractRecipeViewingScreen.java | 141 ------ .../rei/gui/CompositeDisplayViewingScreen.java | 422 +++++++++++++++++ .../shedaniel/rei/gui/ContainerScreenOverlay.java | 2 +- .../rei/gui/DefaultDisplayViewingScreen.java | 515 +++++++++++++++++++++ .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 215 --------- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 515 --------------------- .../rei/gui/UncertainDisplayViewingScreen.java | 294 ++++++++++++ .../rei/gui/VillagerRecipeViewingScreen.java | 422 ----------------- .../rei/gui/plugin/DefaultRuntimePlugin.java | 12 +- .../gui/widget/DefaultDisplayChoosePageWidget.java | 211 +++++++++ .../rei/gui/widget/FavoritesListWidget.java | 2 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 211 --------- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 20 +- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 6 +- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 14 +- .../rei/impl/DynamicErrorFreeEntryListWidget.java | 2 +- .../me/shedaniel/rei/impl/widgets/PanelWidget.java | 4 +- 20 files changed, 1627 insertions(+), 1548 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/AbstractDisplayViewingScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/CompositeDisplayViewingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/DefaultDisplayViewingScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/UncertainDisplayViewingScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/widget/DefaultDisplayChoosePageWidget.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java (limited to 'runtime/src/main/java/me') diff --git a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringRulesScreen.java b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringRulesScreen.java index daffac707..5cf8a567b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringRulesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/api/gui/config/entry/FilteringRulesScreen.java @@ -45,7 +45,7 @@ import java.util.List; import java.util.Objects; import java.util.function.BiFunction; -import static me.shedaniel.rei.gui.RecipeViewingScreen.CHEST_GUI_TEXTURE; +import static me.shedaniel.rei.gui.DefaultDisplayViewingScreen.CHEST_GUI_TEXTURE; public class FilteringRulesScreen extends Screen { private final FilteringEntry entry; 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 3f32747e9..6da592c47 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.api.gui.config.RecipeScreenType; -import me.shedaniel.rei.gui.PreRecipeViewingScreen; +import me.shedaniel.rei.api.gui.config.DisplayScreenType; +import me.shedaniel.rei.gui.UncertainDisplayViewingScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.client.gui.components.AbstractButton; @@ -41,18 +41,18 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; -public class RecipeScreenTypeEntry extends TooltipListEntry { +public class RecipeScreenTypeEntry extends TooltipListEntry { private int width; - private final RecipeScreenType original; - private RecipeScreenType type; - private RecipeScreenType defaultValue; - private Consumer save; + private final DisplayScreenType original; + private DisplayScreenType type; + private DisplayScreenType defaultValue; + private Consumer save; private final AbstractWidget buttonWidget = new AbstractButton(0, 0, 0, 20, NarratorChatListener.NO_TITLE) { @Override public void onPress() { - Minecraft.getInstance().setScreen(new PreRecipeViewingScreen(getConfigScreen(), type, false, original -> { + Minecraft.getInstance().setScreen(new UncertainDisplayViewingScreen(getConfigScreen(), type, false, original -> { Minecraft.getInstance().setScreen(getConfigScreen()); - type = original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER; + type = original ? DisplayScreenType.ORIGINAL : DisplayScreenType.COMPOSITE; })); } @@ -65,7 +65,7 @@ public class RecipeScreenTypeEntry extends TooltipListEntry { private final List children = ImmutableList.of(buttonWidget); @SuppressWarnings("deprecation") - public RecipeScreenTypeEntry(int width, Component fieldName, RecipeScreenType type, RecipeScreenType defaultValue, Consumer save) { + public RecipeScreenTypeEntry(int width, Component fieldName, DisplayScreenType type, DisplayScreenType defaultValue, Consumer save) { super(fieldName, null); this.original = type; this.width = width; @@ -80,12 +80,12 @@ public class RecipeScreenTypeEntry extends TooltipListEntry { } @Override - public RecipeScreenType getValue() { + public DisplayScreenType getValue() { return type; } @Override - public Optional getDefaultValue() { + public Optional getDefaultValue() { return Optional.ofNullable(defaultValue); } diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractDisplayViewingScreen.java new file mode 100644 index 000000000..bfa985be7 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractDisplayViewingScreen.java @@ -0,0 +1,141 @@ +/* + * 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.Slot; +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.components.events.ContainerEventHandler; +import net.minecraft.client.gui.components.events.GuiEventListener; +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 AbstractDisplayViewingScreen 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 AbstractDisplayViewingScreen(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(Slot.INPUT, setupDisplay, noticeStack); + } + + protected void transformResultNotice(List setupDisplay, EntryStack noticeStack) { + transformNotice(Slot.OUTPUT, setupDisplay, noticeStack); + } + + private static void transformNotice(int marker, List setupDisplay, EntryStack noticeStack) { + if (noticeStack.isEmpty()) + return; + for (GuiEventListener widget : setupDisplay) { + if (widget instanceof EntryWidget) { + EntryWidget entry = (EntryWidget) widget; + if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { + EntryStack stack = CollectionUtils.findFirstOrNullEqualsExact(entry.getEntries(), noticeStack); + if (stack != null) { + entry.clearStacks(); + entry.entry(stack); + } + } + } else if (widget instanceof ContainerEventHandler) { + transformNotice(marker, ((ContainerEventHandler) widget).children(), noticeStack); + } + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java deleted file mode 100644 index c7fdcfc54..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/gui/AbstractRecipeViewingScreen.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.Slot; -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.components.events.ContainerEventHandler; -import net.minecraft.client.gui.components.events.GuiEventListener; -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(Slot.INPUT, setupDisplay, noticeStack); - } - - protected void transformResultNotice(List setupDisplay, EntryStack noticeStack) { - transformNotice(Slot.OUTPUT, setupDisplay, noticeStack); - } - - private static void transformNotice(int marker, List setupDisplay, EntryStack noticeStack) { - if (noticeStack.isEmpty()) - return; - for (GuiEventListener widget : setupDisplay) { - if (widget instanceof EntryWidget) { - EntryWidget entry = (EntryWidget) widget; - if (entry.getNoticeMark() == marker && entry.getEntries().size() > 1) { - EntryStack stack = CollectionUtils.findFirstOrNullEqualsExact(entry.getEntries(), noticeStack); - if (stack != null) { - entry.clearStacks(); - entry.entry(stack); - } - } - } else if (widget instanceof ContainerEventHandler) { - transformNotice(marker, ((ContainerEventHandler) widget).children(), noticeStack); - } - } - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/gui/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/gui/CompositeDisplayViewingScreen.java new file mode 100644 index 000000000..40826d9f3 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/gui/CompositeDisplayViewingScreen.java @@ -0,0 +1,422 @@ +/* + * 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 com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import me.shedaniel.clothconfig2.ClothConfigInitializer; +import me.shedaniel.clothconfig2.api.ScissorsHandler; +import me.shedaniel.clothconfig2.api.ScrollingContainer; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.math.impl.PointHelper; +import me.shedaniel.rei.api.registry.category.ButtonArea; +import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.config.ConfigObject; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.gui.DisplayRenderer; +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.EntryIngredient; +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.view.ViewSearchBuilder; +import me.shedaniel.rei.gui.widget.TabWidget; +import me.shedaniel.rei.impl.ClientHelperImpl; +import me.shedaniel.rei.impl.InternalWidgets; +import me.shedaniel.rei.impl.REIHelperImpl; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.client.resources.sounds.SimpleSoundInstance; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.util.Mth; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +@ApiStatus.Internal +public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen { + private final List widgets = Lists.newArrayList(); + private final List