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 +++++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.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) -- cgit