From 69a855f33483c3a5273f6f337c95fb51aad5d2b4 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 26 Feb 2020 00:35:20 +0800 Subject: improved notice filtering Signed-off-by: shedaniel --- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 38 +++++++++++++++++----- .../me/shedaniel/rei/gui/StackToNoticeScreen.java | 13 ++++++++ .../rei/gui/VillagerRecipeViewingScreen.java | 18 +++++++--- .../me/shedaniel/rei/gui/widget/EntryWidget.java | 23 +++++++++++++ .../me/shedaniel/rei/impl/ClientHelperImpl.java | 23 ++++++++----- .../rei/plugin/brewing/DefaultBrewingCategory.java | 12 +++---- .../plugin/campfire/DefaultCampfireCategory.java | 4 +-- .../composting/DefaultCompostingCategory.java | 4 +-- .../rei/plugin/cooking/DefaultCookingCategory.java | 4 +-- .../plugin/crafting/DefaultCraftingCategory.java | 4 +-- .../rei/plugin/fuel/DefaultFuelCategory.java | 2 +- .../information/DefaultInformationCategory.java | 2 +- .../stonecutting/DefaultStoneCuttingCategory.java | 4 +-- .../plugin/stripping/DefaultStrippingCategory.java | 4 +-- 14 files changed, 112 insertions(+), 43 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/gui/StackToNoticeScreen.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 8b73d7603..45757a4cd 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -39,7 +39,7 @@ import java.util.*; import java.util.function.Supplier; @ApiStatus.Internal -public class RecipeViewingScreen extends Screen { +public class RecipeViewingScreen extends Screen implements StackToNoticeScreen { public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); private final List preWidgets; @@ -59,7 +59,8 @@ public class RecipeViewingScreen extends Screen { @Nullable private CategoryBaseWidget workingStationsBaseWidget; private RecipeCategory selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; - private EntryStack mainStackToNotice = EntryStack.empty(); + private EntryStack ingredientStackToNotice = EntryStack.empty(); + private EntryStack resultStackToNotice = EntryStack.empty(); public RecipeViewingScreen(Map, List> categoriesMap) { super(new LiteralText("")); @@ -80,14 +81,24 @@ public class RecipeViewingScreen extends Screen { this.choosePageActivated = false; } - static void transformNotice(List setupDisplay, EntryStack mainStackToNotice) { - if (mainStackToNotice.isEmpty()) + @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.entries().size() > 1) { - EntryStack stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.entries(), mainStackToNotice); + if (entry.getNoticeMark() == marker && entry.entries().size() > 1) { + EntryStack stack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(entry.entries(), noticeStack); if (stack != null) { entry.clearStacks(); entry.entry(stack); @@ -97,8 +108,16 @@ public class RecipeViewingScreen extends Screen { } } - public void addMainStackToNotice(EntryStack stack) { - this.mainStackToNotice = stack; + @ApiStatus.Internal + @Override + public void addIngredientStackToNotice(EntryStack stack) { + this.ingredientStackToNotice = stack; + } + + @ApiStatus.Internal + @Override + public void addResultStackToNotice(EntryStack stack) { + this.resultStackToNotice = stack; } @Nullable @@ -271,7 +290,8 @@ public class RecipeViewingScreen extends Screen { int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get()); final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().y - 2 + 36 + recipeHeight * i + 4 * i, displayWidth, recipeHeight); List setupDisplay = selectedCategory.setupDisplay(displaySupplier, displayBounds); - transformNotice(setupDisplay, mainStackToNotice); + transformIngredientNotice(setupDisplay, ingredientStackToNotice); + transformResultNotice(setupDisplay, resultStackToNotice); recipeBounds.put(displayBounds, setupDisplay); this.widgets.addAll(setupDisplay); if (supplier.isPresent() && supplier.get().get(displayBounds) != null) diff --git a/src/main/java/me/shedaniel/rei/gui/StackToNoticeScreen.java b/src/main/java/me/shedaniel/rei/gui/StackToNoticeScreen.java new file mode 100644 index 000000000..3101df21d --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/StackToNoticeScreen.java @@ -0,0 +1,13 @@ +package me.shedaniel.rei.gui; + +import me.shedaniel.rei.api.EntryStack; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public interface StackToNoticeScreen { + @ApiStatus.Internal + void addIngredientStackToNotice(EntryStack stack); + + @ApiStatus.Internal + void addResultStackToNotice(EntryStack stack); +} \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 133827ee2..10f2d21f6 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -40,7 +40,7 @@ import java.util.Map; import java.util.Optional; @ApiStatus.Internal -public class VillagerRecipeViewingScreen extends Screen { +public class VillagerRecipeViewingScreen extends Screen implements StackToNoticeScreen { private final Map, List> categoryMap; private final List> categories; @@ -60,7 +60,8 @@ public class VillagerRecipeViewingScreen extends Screen { private long scrollBarAlphaFutureTime = -1; private boolean draggingScrollBar; private int tabsPage; - private EntryStack mainStackToNotice = EntryStack.empty(); + private EntryStack ingredientStackToNotice = EntryStack.empty(); + private EntryStack resultStackToNotice = EntryStack.empty(); public VillagerRecipeViewingScreen(Map, List> map) { super(new LiteralText("")); @@ -85,8 +86,14 @@ public class VillagerRecipeViewingScreen extends Screen { }); } - public void addMainStackToNotice(EntryStack stack) { - this.mainStackToNotice = stack; + @Override + public void addIngredientStackToNotice(EntryStack stack) { + ingredientStackToNotice = stack; + } + + @Override + public void addResultStackToNotice(EntryStack stack) { + resultStackToNotice = stack; } @Override @@ -138,7 +145,8 @@ public class VillagerRecipeViewingScreen extends Screen { Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); List setupDisplay = category.setupDisplay(() -> display, recipeBounds); - RecipeViewingScreen.transformNotice(setupDisplay, mainStackToNotice); + RecipeViewingScreen.transformIngredientNotice(setupDisplay, ingredientStackToNotice); + RecipeViewingScreen.transformResultNotice(setupDisplay, resultStackToNotice); this.widgets.addAll(setupDisplay); Optional supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(category); if (supplier.isPresent() && supplier.get().get(recipeBounds) != null) diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java index 99aa3dd6a..58fe953e4 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java @@ -23,6 +23,7 @@ import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; +import org.jetbrains.annotations.ApiStatus; import java.util.*; @@ -31,6 +32,8 @@ public class EntryWidget extends WidgetWithBounds { protected static final Identifier RECIPE_GUI = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); protected static final Identifier RECIPE_GUI_DARK = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer_dark.png"); + @ApiStatus.Internal + private byte noticeMark = 0; protected boolean highlight = true; protected boolean tooltips = true; protected boolean background = true; @@ -56,6 +59,26 @@ public class EntryWidget extends WidgetWithBounds { return new EntryWidget(point); } + public EntryWidget unmarkInputOrOutput() { + noticeMark = 0; + return this; + } + + public EntryWidget markIsInput() { + noticeMark = 1; + return this; + } + + public EntryWidget markIsOutput() { + noticeMark = 2; + return this; + } + + @ApiStatus.Internal + public byte getNoticeMark() { + return noticeMark; + } + public EntryWidget disableInteractions() { return interactable(false); } diff --git a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index 2eb18a6ee..1e8b59921 100644 --- a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -15,6 +15,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsNetwork; import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen; +import me.shedaniel.rei.gui.StackToNoticeScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.utils.CollectionUtils; @@ -37,6 +38,7 @@ import net.minecraft.util.Lazy; import net.minecraft.util.PacketByteBuf; import net.minecraft.util.registry.Registry; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.time.LocalDateTime; @@ -156,7 +158,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { public boolean executeRecipeKeyBind(EntryStack stack) { Map, List> map = RecipeHelper.getInstance().getRecipesFor(stack); if (map.keySet().size() > 0) - openRecipeViewingScreen(map, stack); + openRecipeViewingScreen(map, null, stack); return map.keySet().size() > 0; } @@ -164,7 +166,7 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { public boolean executeUsageKeyBind(EntryStack stack) { Map, List> map = RecipeHelper.getInstance().getUsagesFor(stack); if (map.keySet().size() > 0) - openRecipeViewingScreen(map, stack); + openRecipeViewingScreen(map, stack, null); return map.keySet().size() > 0; } @@ -212,25 +214,28 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public void openRecipeViewingScreen(Map, List> map) { - openRecipeViewingScreen(map, null); + openRecipeViewingScreen(map, null, null); } - public void openRecipeViewingScreen(Map, List> map, EntryStack notice) { + @ApiStatus.Internal + public void openRecipeViewingScreen(Map, List> map, @Nullable EntryStack ingredientNotice, @Nullable EntryStack resultNotice) { Screen screen; if (ConfigObject.getInstance().getRecipeScreenType() == RecipeScreenType.VILLAGER) { screen = new VillagerRecipeViewingScreen(map); - if (notice != null) - ((VillagerRecipeViewingScreen) screen).addMainStackToNotice(notice); } else if (ConfigObject.getInstance().getRecipeScreenType() == RecipeScreenType.UNSET) { screen = new PreRecipeViewingScreen(ScreenHelper.getLastContainerScreen(), RecipeScreenType.UNSET, true, original -> { ConfigObject.getInstance().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); ConfigManager.getInstance().saveConfig(); - openRecipeViewingScreen(map, notice); + openRecipeViewingScreen(map, ingredientNotice, resultNotice); }); } else { screen = new RecipeViewingScreen(map); - if (notice != null) - ((RecipeViewingScreen) screen).addMainStackToNotice(notice); + } + if (screen instanceof StackToNoticeScreen) { + if (ingredientNotice != null) + ((StackToNoticeScreen) screen).addIngredientStackToNotice(ingredientNotice); + if (resultNotice != null) + ((StackToNoticeScreen) screen).addResultStackToNotice(resultNotice); } ScreenHelper.storeRecipeScreen(MinecraftClient.getInstance().currentScreen); MinecraftClient.getInstance().openScreen(screen); diff --git a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java index 201b47658..86a771f73 100644 --- a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java @@ -56,12 +56,12 @@ public class DefaultBrewingCategory implements RecipeCategory slots = Lists.newArrayList(); for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) - slots.add(EntryWidget.create(startPoint.x + 1 + x * 18, startPoint.y + 1 + y * 18)); + slots.add(EntryWidget.create(startPoint.x + 1 + x * 18, startPoint.y + 1 + y * 18).markIsInput()); for (int i = 0; i < input.size(); i++) { if (recipeDisplaySupplier.get() instanceof DefaultShapedDisplay) { if (!input.get(i).isEmpty()) @@ -78,7 +78,7 @@ public class DefaultCraftingCategory implements TransferRecipeCategory { minecraft.textRenderer.draw(I18n.translate("category.rei.fuel.time.items", burnItems), bounds.x + 26, bounds.getMaxY() - 15, ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040); } })); - widgets.add(EntryWidget.create(bounds.x + 6, startPoint.y + 18).entries(recipeDisplaySupplier.get().getInputEntries().get(0))); + widgets.add(EntryWidget.create(bounds.x + 6, startPoint.y + 18).entries(recipeDisplaySupplier.get().getInputEntries().get(0)).markIsInput()); return widgets; } diff --git a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java index 11dba92f4..2e4ed144e 100644 --- a/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/information/DefaultInformationCategory.java @@ -100,7 +100,7 @@ public class DefaultInformationCategory implements RecipeCategory widgets = Lists.newArrayList(); widgets.add(LabelWidget.create(new Point(bounds.getCenterX(), bounds.y + 3), display.getName().asFormattedString()).noShadow().color(ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 0xFF404040)); - widgets.add(EntryWidget.create(bounds.getCenterX() - 8, bounds.y + 15).entries(display.getEntryStacks())); + widgets.add(EntryWidget.create(bounds.getCenterX() - 8, bounds.y + 15).entries(display.getEntryStacks()).markIsInput()); Rectangle rectangle = new Rectangle(bounds.getCenterX() - (bounds.width / 2), bounds.y + 35, bounds.width, bounds.height - 40); widgets.add(new SlotBaseWidget(rectangle)); widgets.add(new ScrollableTextWidget(rectangle, display.getTexts())); diff --git a/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java b/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java index 5819157b1..f8eb6051a 100644 --- a/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java @@ -51,8 +51,8 @@ public class DefaultStoneCuttingCategory implements RecipeCategory