From 750492c9d3fdaf4129679f2e459a9ea040bdd964 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sat, 5 Nov 2022 01:27:03 +0800 Subject: New tab buttons --- .../rei/impl/client/config/ConfigObjectImpl.java | 2 +- .../gui/screen/AbstractDisplayViewingScreen.java | 37 ++++- .../gui/screen/CompositeDisplayViewingScreen.java | 82 +--------- .../gui/screen/DefaultDisplayViewingScreen.java | 70 +------- .../impl/client/gui/widget/TabContainerWidget.java | 179 +++++++++++++++++++++ .../rei/impl/client/gui/widget/TabWidget.java | 41 +++-- .../rei/impl/client/search/AsyncSearchManager.java | 2 +- 7 files changed, 243 insertions(+), 170 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/TabContainerWidget.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index 746e11b54..42d08935f 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -683,7 +683,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares how the scrollbar in composite screen should act.") private boolean compositeScrollBarPermanent = false; private boolean toastDisplayedOnCopyIdentifier = true; @Comment("Declares whether REI should use compact tabs for categories.") private boolean useCompactTabs = true; - @Comment("Declares whether REI should use compact tab buttons for categories.") private boolean useCompactTabButtons = false; + @Comment("Declares whether REI should use compact tab buttons for categories.") @ConfigEntry.Gui.Excluded private boolean useCompactTabButtons = false; } public static class Search { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java index d509877a3..877d6c357 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/AbstractDisplayViewingScreen.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.impl.client.gui.screen; import com.google.common.collect.Lists; import me.shedaniel.architectury.fluid.FluidStack; +import dev.architectury.utils.value.IntValue; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigObject; @@ -67,17 +68,17 @@ import java.util.function.UnaryOperator; public abstract class AbstractDisplayViewingScreen extends Screen implements DisplayScreen { protected final Map, List> categoryMap; protected final List> categories; + protected final TabContainerWidget tabs = new TabContainerWidget(); protected List> ingredientStackToNotice = new ArrayList<>(); protected List> resultStackToNotice = new ArrayList<>(); protected int selectedCategoryIndex = 0; - protected int tabsPerPage; + protected int categoryPages = -1; protected Rectangle bounds; - protected AbstractDisplayViewingScreen(Map, List> categoryMap, @Nullable CategoryIdentifier category, int tabsPerPage) { + protected AbstractDisplayViewingScreen(Map, List> categoryMap, @Nullable CategoryIdentifier category) { super(NarratorChatListener.NO_TITLE); this.categoryMap = categoryMap; this.categories = Lists.newArrayList(categoryMap.keySet()); - this.tabsPerPage = tabsPerPage; if (category != null) { selectCategory(category, false); } @@ -96,12 +97,42 @@ public abstract class AbstractDisplayViewingScreen extends Screen implements Dis } recalculateCategoryPage(); + this.tabs.updateScroll(categories, selectedCategoryIndex, !init ? 0 : 300); if (init) { init(); } } + @Override + public void recalculateCategoryPage() { + this.categoryPages = -1; + } + + protected void initTabs() { + this.tabs.init(new Rectangle(bounds.x, bounds.y - 28, bounds.width, 28), categories, new IntValue() { + @Override + public void accept(int value) { + AbstractDisplayViewingScreen.this.categoryPages = value; + } + + @Override + public int getAsInt() { + return AbstractDisplayViewingScreen.this.categoryPages; + } + }, new IntValue() { + @Override + public void accept(int value) { + AbstractDisplayViewingScreen.this.selectCategory(categories.get(value).getCategoryIdentifier()); + } + + @Override + public int getAsInt() { + return selectedCategoryIndex; + } + }, AbstractDisplayViewingScreen.this::init); + } + @Override public List children() { List children = super.children(); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java index 9da61f102..e5489261a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/CompositeDisplayViewingScreen.java @@ -43,20 +43,15 @@ import me.shedaniel.rei.api.client.view.ViewSearchBuilder; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryIngredient; -import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.REIRuntimeImpl; -import me.shedaniel.rei.impl.client.gui.InternalTextures; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; -import me.shedaniel.rei.impl.client.gui.widget.TabWidget; import me.shedaniel.rei.impl.display.DisplaySpec; 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.sounds.SimpleSoundInstance; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; -import net.minecraft.sounds.SoundEvents; import net.minecraft.util.Mth; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -71,7 +66,6 @@ public class CompositeDisplayViewingScreen extends AbstractDisplayViewingScreen private final List widgets = Lists.newArrayList(); private final List