From 4d396d1644261c1abede823910431adf5dea5734 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 3 Nov 2023 20:44:55 +0800 Subject: [PATCH] Remove old config logic, replace with new Config GUI completely --- .../impl/client/config/ConfigManagerImpl.java | 223 +----------------- .../impl/client/config/ConfigObjectImpl.java | 165 ++++++------- .../config/entries/ButtonsConfigEntry.java | 115 --------- .../entries/FilteringAddRuleScreen.java | 13 +- .../client/config/entries/FilteringEntry.java | 93 +------- .../config/entries/FilteringRulesScreen.java | 30 +-- .../config/entries/FilteringScreen.java | 17 +- .../config/entries/NoFilteringEntry.java | 96 -------- .../config/entries/RecipeScreenTypeEntry.java | 115 --------- .../SearchFilterSyntaxHighlightingEntry.java | 117 --------- .../client/config/entries/TitleTextEntry.java | 87 ------- .../config/options/AllREIConfigGroups.java | 1 + .../config/options/AllREIConfigOptions.java | 17 +- .../assets/roughlyenoughitems/lang/en_us.json | 32 ++- 14 files changed, 160 insertions(+), 961 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index 05b56b26f..e5f58682a 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -23,32 +23,20 @@ package me.shedaniel.rei.impl.client.config; -import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import dev.architectury.hooks.client.screen.ScreenHooks; import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.annotation.ConfigEntry; import me.shedaniel.autoconfig.gui.ConfigScreenProvider; -import me.shedaniel.autoconfig.gui.registry.GuiRegistry; import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; -import me.shedaniel.autoconfig.util.Utils; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Jankson; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonNull; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonObject; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.JsonPrimitive; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.api.DeserializationException; -import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; -import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; import me.shedaniel.clothconfig2.api.Modifier; import me.shedaniel.clothconfig2.api.ModifierKeyCode; -import me.shedaniel.clothconfig2.gui.entries.KeyCodeEntry; -import me.shedaniel.clothconfig2.gui.entries.TextListEntry; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.addon.ConfigAddonRegistry; @@ -58,53 +46,30 @@ import me.shedaniel.rei.api.client.entry.filtering.FilteringRuleTypeRegistry; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.CheatingMode; -import me.shedaniel.rei.api.client.gui.config.DisplayScreenType; -import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.api.common.util.ImmutableTextComponent; import me.shedaniel.rei.impl.client.REIRuntimeImpl; import me.shedaniel.rei.impl.client.config.addon.ConfigAddonRegistryImpl; import me.shedaniel.rei.impl.client.config.collapsible.CollapsibleConfigManager; -import me.shedaniel.rei.impl.client.config.entries.*; +import me.shedaniel.rei.impl.client.config.entries.ConfigAddonsEntry; import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen; -import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen; -import me.shedaniel.rei.impl.client.gui.performance.PerformanceScreen; -import me.shedaniel.rei.impl.client.gui.screen.ConfigReloadingScreen; -import me.shedaniel.rei.impl.client.gui.screen.collapsible.CollapsibleEntriesScreen; -import me.shedaniel.rei.impl.client.search.argument.Argument; import me.shedaniel.rei.impl.common.InternalLogger; -import me.shedaniel.rei.impl.common.entry.type.collapsed.CollapsibleEntryRegistryImpl; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.minecraft.ChatFormatting; import net.minecraft.ResourceLocationException; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.screens.Screen; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.nbt.TagParser; -import net.minecraft.network.chat.*; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; import net.minecraft.world.InteractionResult; -import org.apache.commons.lang3.tuple.Triple; import org.jetbrains.annotations.ApiStatus; -import java.util.*; -import java.util.function.Consumer; - -import static me.shedaniel.autoconfig.util.Utils.getUnsafely; -import static me.shedaniel.autoconfig.util.Utils.setUnsafely; +import java.util.Locale; @ApiStatus.Internal @Environment(EnvType.CLIENT) @@ -115,38 +80,6 @@ public class ConfigManagerImpl implements ConfigManager { public ConfigManagerImpl() { AutoConfig.register(ConfigObjectImpl.class, (definition, configClass) -> new JanksonConfigSerializer<>(definition, configClass, buildJankson(Jankson.builder()))); - GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ConfigObjectImpl.class); - guiRegistry.registerPredicateProvider((i13n, field, config, defaults, guiProvider) -> { - if (field.isAnnotationPresent(ConfigEntry.Gui.Excluded.class)) - return Collections.emptyList(); - KeyCodeEntry entry = ConfigEntryBuilder.create().startModifierKeyCodeField(new TranslatableComponent(i13n), getUnsafely(field, config, ModifierKeyCode.unknown())).setModifierDefaultValue(() -> getUnsafely(field, defaults)).setModifierSaveConsumer(newValue -> setUnsafely(field, config, newValue)).build(); - return Collections.singletonList(entry); - }, field -> field.getType() == ModifierKeyCode.class); - guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> { - ConfigObjectImpl.UsePercentage bounds = field.getAnnotation(ConfigObjectImpl.UsePercentage.class); - return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(new TranslatableComponent(i13n), Mth.ceil(Utils.getUnsafely(field, config, 0.0) * 100), Mth.ceil(bounds.min() * 100), Mth.ceil(bounds.max() * 100)).setDefaultValue(() -> Mth.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> { - setUnsafely(field, config, newValue / 100d); - }).setTextGetter(integer -> new TextComponent(bounds.prefix() + String.format("%d%%", integer))).build()); - }, (field) -> field.getType() == Double.TYPE || field.getType() == Double.class, ConfigObjectImpl.UsePercentage.class); - - guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> - Collections.singletonList(new RecipeScreenTypeEntry(220, new TranslatableComponent(i13n), getUnsafely(field, config, DisplayScreenType.UNSET), getUnsafely(field, defaults), type -> setUnsafely(field, config, type))) - , (field) -> field.getType() == DisplayScreenType.class, ConfigObjectImpl.UseSpecialRecipeTypeScreen.class); - guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> - Collections.singletonList(new SearchFilterSyntaxHighlightingEntry(new TranslatableComponent(i13n), getUnsafely(field, config, SyntaxHighlightingMode.COLORFUL), getUnsafely(field, defaults), type -> setUnsafely(field, config, type))) - , (field) -> field.getType() == SyntaxHighlightingMode.class, ConfigObjectImpl.UseSpecialSearchFilterSyntaxHighlightingScreen.class); - guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> { - List> value = CollectionUtils.map(Utils.>>getUnsafely(field, config, new ArrayList<>()), EntryStackProvider::provide); - List> defaultValue = CollectionUtils.map(Utils.>>getUnsafely(field, defaults), EntryStackProvider::provide); - Consumer>> saveConsumer = (newValue) -> { - setUnsafely(field, config, CollectionUtils.map(newValue, EntryStackProvider::ofStack)); - }; - return REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null ? - Collections.singletonList(new NoFilteringEntry(220, value, defaultValue, saveConsumer)) - : - Collections.singletonList(new FilteringEntry(220, value, ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules, defaultValue, saveConsumer, list -> ((ConfigObjectImpl.Advanced.Filtering) config).filteringRules = Lists.newArrayList(list))); - } - , (field) -> field.getType() == List.class, ConfigObjectImpl.UseFilteringScreen.class); InternalLogger.getInstance().info("Config loaded"); saveConfig(); FavoritesConfigManager.getInstance().syncFrom(this); @@ -356,162 +289,16 @@ public void toggleCraftableOnly() { @SuppressWarnings("deprecation") @Override public Screen getConfigScreen(Screen parent) { - if (Screen.hasShiftDown()) return new REIConfigScreen(parent); - class EmptyEntry extends AbstractConfigListEntry { - private final int height; - - public EmptyEntry(int height) { - super(new TextComponent(UUID.randomUUID().toString()), false); - this.height = height; - } - - public int getItemHeight() { - return this.height; - } - - public Object getValue() { - return null; - } - - public Optional getDefaultValue() { - return Optional.empty(); - } - - public boolean isMouseInside(int mouseX, int mouseY, int x, int y, int entryWidth, int entryHeight) { - return false; - } - - public void save() { - } - - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) { - } - - public List children() { - return Collections.emptyList(); - } - - public List narratables() { - return Collections.emptyList(); - } - } + if (true) return new REIConfigScreen(parent); try { ConfigScreenProvider provider = (ConfigScreenProvider) AutoConfig.getConfigScreen(ConfigObjectImpl.class, parent); - provider.setI13nFunction(manager -> "config.roughlyenoughitems"); - provider.setOptionFunction((baseI13n, field) -> field.isAnnotationPresent(ConfigObjectImpl.DontApplyFieldName.class) ? baseI13n : String.format("%s.%s", baseI13n, field.getName())); - provider.setCategoryFunction((baseI13n, categoryName) -> String.format("%s.%s", baseI13n, categoryName)); provider.setBuildFunction(builder -> { - if (Minecraft.getInstance().getConnection() != null && Minecraft.getInstance().getConnection().getRecipeManager() != null) { - TextListEntry feedbackEntry = ConfigEntryBuilder.create().startTextDescription( - new TranslatableComponent("text.rei.feedback", new TranslatableComponent("text.rei.feedback.link") - .withStyle(style -> style - .withColor(TextColor.fromRgb(0xff1fc3ff)) - .withUnderlined(true) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://forms.gle/5tdnK5WN1wng78pV8")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://forms.gle/5tdnK5WN1wng78pV8"))) - )) - .withStyle(ChatFormatting.GRAY) - ).build(); - CollapsibleConfigManager.CollapsibleConfigObject collapsibleConfigObject = new CollapsibleConfigManager.CollapsibleConfigObject(); - collapsibleConfigObject.disabledGroups.addAll(CollapsibleConfigManager.getInstance().getConfig().disabledGroups); - collapsibleConfigObject.customGroups.addAll(CollectionUtils.map(CollapsibleConfigManager.getInstance().getConfig().customGroups, CollapsibleConfigManager.CustomGroup::copy)); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.functionality")).getEntries().add(0, new ButtonsConfigEntry(220, - Triple.of(new TranslatableComponent("text.rei.collapsible.entries"), $ -> {}, editedSink -> { - // Minecraft.getInstance().setScreen(new CollapsibleEntriesScreen(Minecraft.getInstance().screen, collapsibleConfigObject, editedSink)); - })) { - @Override - public boolean isEditable() { - return !(REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null); - } - }.withSaveRunnable(() -> { - CollapsibleConfigManager.CollapsibleConfigObject actualConfig = CollapsibleConfigManager.getInstance().getConfig(); - actualConfig.disabledGroups.clear(); - actualConfig.disabledGroups.addAll(collapsibleConfigObject.disabledGroups); - actualConfig.customGroups.clear(); - actualConfig.customGroups.addAll(collapsibleConfigObject.customGroups); - CollapsibleConfigManager.getInstance().saveConfig(); - ((CollapsibleEntryRegistryImpl) CollapsibleEntryRegistry.getInstance()).recollectCustomEntries(); - })); - ConfigureCategoriesScreen filteringScreen = new ConfigureCategoriesScreen( - new HashMap<>(getConfig().getFilteringQuickCraftCategories()), - new HashSet<>(getConfig().getHiddenCategories()), - new ArrayList<>(getConfig().getCategoryOrdering()) - ); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.functionality")).getEntries().add(0, new ButtonsConfigEntry(220, - Triple.of(new TranslatableComponent("config.roughlyenoughitems.configureCategories"), $ -> {}, editedSink -> { - filteringScreen.parent = Minecraft.getInstance().screen; - filteringScreen.editedSink = editedSink; - Minecraft.getInstance().setScreen(filteringScreen); - })) { - @Override - public boolean isEditable() { - return !(REIRuntime.getInstance().getPreviousContainerScreen() == null || Minecraft.getInstance().getConnection() == null || Minecraft.getInstance().getConnection().getRecipeManager() == null); - } - }.withSaveRunnable(() -> { - getConfig().setFilteringQuickCraftCategories(filteringScreen.getFilteringQuickCraftCategories()); - getConfig().setHiddenCategories(filteringScreen.getHiddenCategories()); - getConfig().setCategoryOrdering(filteringScreen.getCategoryOrdering()); - })); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, feedbackEntry); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ButtonsConfigEntry(220, - Triple.of(new TranslatableComponent("text.rei.reload_config"), $ -> {}, $ -> { - RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); - RoughlyEnoughItemsCoreClient.reloadPlugins(null, null); - }), - Triple.of(new TranslatableComponent("text.rei.reload_search"), button -> { - button.active = button.active && Argument.hasCache(); - }, $ -> { - Argument.resetCache(true); - })) { - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - if (PluginManager.areAnyReloading()) { - Screen screen = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(new TranslatableComponent("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen), null)); - } else { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - } - } - }); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.advanced")).getEntries().add(0, new ButtonsConfigEntry(220, - Triple.of(new TranslatableComponent("text.rei.performance"), $ -> {}, $ -> { - Screen s = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new PerformanceScreen(() -> Minecraft.getInstance().setScreen(s))); - }))); - } ConfigAddonRegistryImpl addonRegistry = (ConfigAddonRegistryImpl) ConfigAddonRegistry.getInstance(); if (!addonRegistry.getAddons().isEmpty()) { - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, new EmptyEntry(4)); builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, new ConfigAddonsEntry(220)); } - TextListEntry supportText = ConfigEntryBuilder.create().startTextDescription( - new TranslatableComponent("text.rei.support.me.desc", - new TranslatableComponent("text.rei.support.me.patreon") - .withStyle(style -> style - .withColor(TextColor.fromRgb(0xff1fc3ff)) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://patreon.com/shedaniel")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://patreon.com/shedaniel"))) - ), - new TranslatableComponent("text.rei.support.me.bisect") - .withStyle(style -> style - .withColor(TextColor.fromRgb(0xff1fc3ff)) - .withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.bisecthosting.com/shedaniel")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ImmutableTextComponent("https://www.bisecthosting.com/shedaniel"))) - ) - ) - .withStyle(ChatFormatting.GRAY) - ).build(); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, new EmptyEntry(4)); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, supportText); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, new TitleTextEntry(new TranslatableComponent("text.rei.support.me"))); - builder.getOrCreateCategory(new TranslatableComponent("config.roughlyenoughitems.basics")).getEntries().add(0, new EmptyEntry(4)); - return builder.setAfterInitConsumer(screen -> { - ScreenHooks.addRenderableWidget(screen, new Button(screen.width - 104, 4, 100, 20, new TranslatableComponent("text.rei.credits"), button -> { - CreditsScreen creditsScreen = new CreditsScreen(screen); - Minecraft.getInstance().setScreen(creditsScreen); - })); - }).setSavingRunnable(() -> { + return builder.setSavingRunnable(() -> { saveConfig(); EntryRegistry.getInstance().refilter(); REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); 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 a1a94e88c..b08ad02ef 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 @@ -26,7 +26,6 @@ import com.mojang.blaze3d.platform.InputConstants; import me.shedaniel.autoconfig.ConfigData; import me.shedaniel.autoconfig.annotation.Config; -import me.shedaniel.autoconfig.annotation.ConfigEntry; import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Comment; import me.shedaniel.clothconfig2.api.Modifier; import me.shedaniel.clothconfig2.api.ModifierKeyCode; @@ -47,10 +46,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import java.util.*; @ApiStatus.Internal @@ -58,13 +53,9 @@ @Environment(EnvType.CLIENT) @SuppressWarnings("FieldMayBeFinal") public class ConfigObjectImpl implements ConfigObject, ConfigData { - @ConfigEntry.Category("basics") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName public Basics basics = new Basics(); - @ConfigEntry.Category("appearance") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName public Appearance appearance = new Appearance(); - @ConfigEntry.Category("functionality") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName public Functionality functionality = new Functionality(); - @ConfigEntry.Category("advanced") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName public Advanced advanced = new Advanced(); @Override @@ -80,7 +71,7 @@ public void setOverlayVisible(boolean overlayVisible) { @Override public boolean isCheating() { return basics.cheating == CheatingMode.ON || (basics.cheating == CheatingMode.WHEN_CREATIVE && Minecraft.getInstance().gameMode != null - && Minecraft.getInstance().gameMode.getPlayerMode() == GameType.CREATIVE); + && Minecraft.getInstance().gameMode.getPlayerMode() == GameType.CREATIVE); } @Override @@ -596,49 +587,20 @@ public SearchMode getModSearchMode() { return advanced.search.modSearch; } - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface DontApplyFieldName {} - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UseSpecialRecipeTypeScreen {} - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UseSpecialSearchFilterSyntaxHighlightingScreen {} - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UseFilteringScreen {} - - @Retention(RetentionPolicy.RUNTIME) - @Target({ElementType.FIELD}) - @interface UsePercentage { - double min(); - - double max(); - - String prefix() default "Size: "; - } - public static class Basics { - @ConfigEntry.Gui.Excluded public List favorites = new ArrayList<>(); - @ConfigEntry.Gui.Excluded public List hiddenFavorites = new ArrayList<>(); - @ConfigEntry.Gui.Excluded public List displayHistory = new ArrayList<>(); - @Comment("Declares whether cheating mode is on.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public List favorites = new ArrayList<>(); + public List hiddenFavorites = new ArrayList<>(); + public List displayHistory = new ArrayList<>(); public CheatingMode cheating = CheatingMode.OFF; public boolean favoritesEnabled = true; public boolean reduceMotion = false; - @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) public KeyBindings keyBindings = new KeyBindings(); - @Comment("Declares whether REI is visible.") @ConfigEntry.Gui.Excluded public boolean overlayVisible = true; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @Comment("Declares whether REI is visible.") + public boolean overlayVisible = true; public ItemCheatingStyle cheatingStyle = ItemCheatingStyle.GRAB; } public static class KeyBindings { - @ConfigEntry.Gui.Excluded public boolean useNativeKeybinds; public ModifierKeyCode recipeKeybind = ModifierKeyCode.of(InputConstants.Type.KEYSYM.getOrCreate(InputConstants.KEY_R), Modifier.none()); public ModifierKeyCode usageKeybind = ModifierKeyCode.of(InputConstants.Type.KEYSYM.getOrCreate(InputConstants.KEY_U), Modifier.none()); @@ -653,123 +615,128 @@ public static class KeyBindings { } public static class Appearance { - @UseSpecialRecipeTypeScreen public DisplayScreenType recipeScreenType = DisplayScreenType.UNSET; - @Comment("Declares the appearance of REI windows.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public DisplayScreenType recipeScreenType = DisplayScreenType.UNSET; + @Comment("Declares the appearance of REI windows.") public AppearanceTheme theme = AppearanceTheme.LIGHT; - @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) public Layout layout = new Layout(); - @Comment("Declares the appearance of recipe's border.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @Comment("Declares the appearance of recipe's border.") public RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT; - @Comment("Declares whether entry panel is scrolled.") public boolean scrollingEntryListWidget = false; - @Comment("Declares whether entry panel should be invisible when not searching") public boolean hideEntryPanelIfIdle = false; + @Comment("Declares whether entry panel is scrolled.") + public boolean scrollingEntryListWidget = false; + @Comment("Declares whether entry panel should be invisible when not searching") + public boolean hideEntryPanelIfIdle = false; public static class Layout { - @Comment("Declares the position of the search field.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @Comment("Declares the position of the search field.") public SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER; - @Comment("Declares the position of the config button.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @Comment("Declares the position of the config button.") public ConfigButtonPosition configButtonLocation = ConfigButtonPosition.LOWER; - @Comment("Declares whether the craftable filter button is enabled.") public boolean showCraftableOnlyButton = true; + @Comment("Declares whether the craftable filter button is enabled.") + public boolean showCraftableOnlyButton = true; } - @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") public double horizontalEntriesBoundaries = 1.0; - @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") public double verticalEntriesBoundaries = 1.0; + public double horizontalEntriesBoundaries = 1.0; + public double verticalEntriesBoundaries = 1.0; public int horizontalEntriesBoundariesColumns = 50; public int verticalEntriesBoundariesRows = 1000; public double horizontalEntriesBoundariesAlignment = 1.0; public double verticalEntriesBoundariesAlignment = 0.5; - @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") public double favoritesHorizontalEntriesBoundaries = 1.0; + public double favoritesHorizontalEntriesBoundaries = 1.0; public int favoritesHorizontalEntriesBoundariesColumns = 50; - @UseSpecialSearchFilterSyntaxHighlightingScreen public SyntaxHighlightingMode syntaxHighlightingMode = SyntaxHighlightingMode.COLORFUL; + public SyntaxHighlightingMode syntaxHighlightingMode = SyntaxHighlightingMode.COLORFUL; public boolean isFocusModeZoomed = false; } public static class Functionality { - @ConfigEntry.Gui.Excluded @Nullable public ResourceLocation inputMethod = null; - @Comment("Declares whether REI should remove the recipe book.") public boolean disableRecipeBook = false; - @Comment("Declares whether mob effects should be on the left side instead of the right side.") public boolean leftSideMobEffects = false; - @Comment("Declares whether subsets is enabled.") public boolean isSubsetsEnabled = false; + @Nullable + public ResourceLocation inputMethod = null; + @Comment("Declares whether REI should remove the recipe book.") + public boolean disableRecipeBook = false; + @Comment("Declares whether mob effects should be on the left side instead of the right side.") + public boolean leftSideMobEffects = false; + @Comment("Declares whether subsets is enabled.") + public boolean isSubsetsEnabled = false; public boolean allowInventoryHighlighting = true; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; } public static class Advanced { - @ConfigEntry.Gui.CollapsibleObject public Tooltips tooltips = new Tooltips(); - @ConfigEntry.Gui.CollapsibleObject public Layout layout = new Layout(); - @ConfigEntry.Gui.CollapsibleObject public Accessibility accessibility = new Accessibility(); - @ConfigEntry.Gui.CollapsibleObject public Search search = new Search(); - @ConfigEntry.Gui.CollapsibleObject public Commands commands = new Commands(); - @ConfigEntry.Gui.CollapsibleObject public Miscellaneous miscellaneous = new Miscellaneous(); - @ConfigEntry.Gui.CollapsibleObject(startExpanded = true) public Filtering filtering = new Filtering(); public static class Tooltips { - @Comment("Declares whether REI should append mod names to entries.") public boolean appendModNames = true; - @Comment("Declares whether favorites tooltip should be displayed.") public boolean displayFavoritesTooltip = false; - @ConfigEntry.Gui.Excluded public boolean displayIMEHints = true; + @Comment("Declares whether REI should append mod names to entries.") + public boolean appendModNames = true; + @Comment("Declares whether favorites tooltip should be displayed.") + public boolean displayFavoritesTooltip = false; + public boolean displayIMEHints = true; } public static class Layout { @Comment("The ordering of the items on the entry panel.") - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public EntryPanelOrderingConfig entryPanelOrdering = EntryPanelOrderingConfig.REGISTRY_ASCENDING; - @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 2, max = 99) + @Comment("Declares the maximum amount of recipes displayed in a page if possible.") public int maxRecipesPerPage = 8; - @Comment("Declares the maximum amount of recipes displayed in a page if possible.") @ConfigEntry.BoundedDiscrete(min = 100, max = 1000) + @Comment("Declares the maximum amount of recipes displayed in a page if possible.") public int maxRecipesPageHeight = 300; - @Comment("Declares whether entry rendering time should be debugged.") public boolean debugRenderTimeRequired = false; - @Comment("Merges displays with equal contents under 1 display.") public boolean mergeDisplayUnderOne = true; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + @Comment("Declares whether entry rendering time should be debugged.") + public boolean debugRenderTimeRequired = false; + @Comment("Merges displays with equal contents under 1 display.") + public boolean mergeDisplayUnderOne = true; public FavoriteAddWidgetMode favoriteAddWidgetMode = FavoriteAddWidgetMode.ALWAYS_VISIBLE; } public static class Accessibility { - @UsePercentage(min = 0.25, max = 4.0) public double entrySize = 1.0; - @Comment("Declares the position of the entry panel.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) + public double entrySize = 1.0; + @Comment("Declares the position of the entry panel.") public DisplayPanelLocation displayPanelLocation = DisplayPanelLocation.RIGHT; - @Comment("Declares how the scrollbar in composite screen should act.") public boolean compositeScrollBarPermanent = false; + @Comment("Declares how the scrollbar in composite screen should act.") + public boolean compositeScrollBarPermanent = false; public boolean toastDisplayedOnCopyIdentifier = true; - @Comment("Declares whether REI should use compact tabs for categories.") public boolean useCompactTabs = true; - @Comment("Declares whether REI should use compact tab buttons for categories.") public boolean useCompactTabButtons = false; + @Comment("Declares whether REI should use compact tabs for categories.") + public boolean useCompactTabs = true; + @Comment("Declares whether REI should use compact tab buttons for categories.") + public boolean useCompactTabButtons = false; } public static class Search { - @Comment("Declares whether search time should be debugged.") public boolean debugSearchTimeRequired = false; - @Comment("Declares whether REI should search async.") public boolean asyncSearch = true; - @Comment("Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400) + @Comment("Declares whether search time should be debugged.") + public boolean debugSearchTimeRequired = false; + @Comment("Declares whether REI should search async.") + public boolean asyncSearch = true; + @Comment("Declares how many entries should be grouped one async search.") public int asyncSearchPartitionSize = 100; public boolean patchAsyncThreadCrash = true; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public SearchMode tooltipSearch = SearchMode.ALWAYS; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public SearchMode tagSearch = SearchMode.PREFIX; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public SearchMode identifierSearch = SearchMode.ALWAYS; - @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) public SearchMode modSearch = SearchMode.PREFIX; } public static class Commands { - @Comment("Declares the command used to change gamemode.") public String gamemodeCommand = "/gamemode {gamemode}"; - @Comment("Declares the command used in servers to cheat items.") public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; - @Comment("Declares the command used to change weather.") public String weatherCommand = "/weather {weather}"; - @Comment("Declares the command used to change time.") public String timeCommand = "/time set {time}"; + @Comment("Declares the command used to change gamemode.") + public String gamemodeCommand = "/gamemode {gamemode}"; + @Comment("Declares the command used in servers to cheat items.") + public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; + @Comment("Declares the command used to change weather.") + public String weatherCommand = "/weather {weather}"; + @Comment("Declares the command used to change time.") + public String timeCommand = "/time set {time}"; } public static class Miscellaneous { - @Comment("Declares whether arrows in containers should be clickable.") public boolean clickableRecipeArrows = true; + @Comment("Declares whether arrows in containers should be clickable.") + public boolean clickableRecipeArrows = true; public boolean registerRecipesInAnotherThread = true; public boolean newFastEntryRendering = true; - @ConfigEntry.Gui.PrefixText public boolean cachingFastEntryRendering = false; public boolean cachingDisplayLookup = true; - @ConfigEntry.Gui.Excluded public CategorySettings categorySettings = new CategorySettings(); + public CategorySettings categorySettings = new CategorySettings(); public static class CategorySettings { public Map, Boolean> filteringQuickCraftCategories = new HashMap<>(); @@ -779,9 +746,9 @@ public static class CategorySettings { } public static class Filtering { - @UseFilteringScreen public List> filteredStacks = new ArrayList<>(); + public List> filteredStacks = new ArrayList<>(); public boolean shouldFilterDisplays = true; - @ConfigEntry.Gui.Excluded public List> filteringRules = new ArrayList<>(); + public List> filteringRules = new ArrayList<>(); } } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java deleted file mode 100644 index 8a0338b18..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.config.entries; - -import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import net.minecraft.util.Unit; -import org.apache.commons.lang3.tuple.Triple; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Arrays; -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -@ApiStatus.Internal -public class ButtonsConfigEntry extends AbstractConfigListEntry { - private final int width; - private final List children; - private boolean edited; - private Runnable saveRunnable = () -> {}; - - public ButtonsConfigEntry(int width, Triple, Consumer>... buttons) { - super(NarratorChatListener.NO_TITLE, false); - this.width = width; - this.children = Arrays.stream(buttons).map(pair -> { - return (AbstractWidget) new Button(0, 0, 0, 20, pair.getLeft(), button -> { - pair.getRight().accept(() -> this.edited = true); - }) { - @Override - public void render(PoseStack poses, int mouseX, int mouseY, float delta) { - pair.getMiddle().accept(this); - super.render(poses, mouseX, mouseY, delta); - } - }; - }).toList(); - } - - public ButtonsConfigEntry withSaveRunnable(Runnable runnable) { - this.saveRunnable = runnable; - return this; - } - - @Override - public Unit getValue() { - return Unit.INSTANCE; - } - - @Override - public Optional getDefaultValue() { - return Optional.of(Unit.INSTANCE); - } - - @Override - public void save() { - this.saveRunnable.run(); - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - Window window = Minecraft.getInstance().getWindow(); - for (AbstractWidget widget : this.children) { - widget.active = this.isEditable(); - widget.y = y; - widget.setWidth(width / this.children.size() - (this.children.size() == 1 ? 0 : 2)); - widget.x = x + entryWidth / 2 - width / 2 + (widget.getWidth() + 2) * this.children.indexOf(widget); - widget.render(matrices, mouseX, mouseY, delta); - } - } - - @Override - public List children() { - return children; - } - - @Override - public List narratables() { - return children; - } - - @Override - public boolean isEdited() { - return edited; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java index a1bc2f2c6..484d60676 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringAddRuleScreen.java @@ -46,13 +46,13 @@ import java.util.function.Function; public class FilteringAddRuleScreen extends Screen { - private final FilteringEntry entry; + private final List> rules; private RulesList rulesList; Screen parent; - public FilteringAddRuleScreen(FilteringEntry entry) { + public FilteringAddRuleScreen(List> rules) { super(new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen.new")); - this.entry = entry; + this.rules = rules; } @Override @@ -68,7 +68,7 @@ public void init() { rulesList = addWidget(new RulesList(minecraft, width, height, 30, height, BACKGROUND_LOCATION)); for (FilteringRuleType rule : FilteringRuleTypeRegistry.getInstance()) { if (!rule.isSingular()) - rulesList.addItem(new DefaultRuleEntry(parent, entry, rule.createNew(), null)); + rulesList.addItem(new DefaultRuleEntry(parent, rules, rule.createNew(), null)); } rulesList.selectItem(rulesList.children().get(0)); } @@ -155,13 +155,12 @@ public static class DefaultRuleEntry extends RuleEntry { private final Button addButton; private final Function screenFunction; - public DefaultRuleEntry(Screen parent, FilteringEntry entry, FilteringRule rule, Function screenFunction) { + public DefaultRuleEntry(Screen parent, List> rules, FilteringRule rule, Function screenFunction) { super(rule); this.screenFunction = (screenFunction == null ? ((FilteringRuleType>) rule.getType()).createEntryScreen(rule) : screenFunction); addButton = new Button(0, 0, 20, 20, Component.nullToEmpty(" + "), button -> { - entry.edited = true; Minecraft.getInstance().setScreen(this.screenFunction.apply(parent)); - entry.rules.add(0, rule); + rules.add(0, rule); }); addButton.active = this.screenFunction != null; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java index d315c393c..2edcf23da 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringEntry.java @@ -23,94 +23,25 @@ package me.shedaniel.rei.impl.client.config.entries; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; import me.shedaniel.rei.api.client.entry.filtering.FilteringRule; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.TranslatableComponent; import org.jetbrains.annotations.ApiStatus; import java.util.*; -import java.util.function.Consumer; @ApiStatus.Internal -public class FilteringEntry extends AbstractConfigListEntry>> { - private int width; - Consumer>> saveConsumer; - Consumer>> rulesSaveConsumer; - List> defaultValue; - Set> configFiltered; - List> rules; - boolean edited = false; - final FilteringScreen filteringScreen = new FilteringScreen(this); - final FilteringRulesScreen filteringRulesScreen = new FilteringRulesScreen(this); - private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, new TranslatableComponent("config.roughlyenoughitems.filteringScreen"), button -> { - filteringRulesScreen.parent = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(filteringRulesScreen); - }); - private final List children = ImmutableList.of(buttonWidget); - - public FilteringEntry(int width, List> configFiltered, List> rules, List> defaultValue, Consumer>> saveConsumer, Consumer>> rulesSaveConsumer) { - super(NarratorChatListener.NO_TITLE, false); - this.width = width; - this.configFiltered = new TreeSet<>(Comparator.comparing(EntryStacks::hashExact)); - this.configFiltered.addAll(configFiltered); - this.rules = Lists.newArrayList(rules); - this.defaultValue = defaultValue; - this.saveConsumer = saveConsumer; - this.rulesSaveConsumer = rulesSaveConsumer; - } - - @Override - public List> getValue() { - return Lists.newArrayList(configFiltered); - } - - @Override - public Optional>> getDefaultValue() { - return Optional.ofNullable(defaultValue); - } - - @Override - public void save() { - saveConsumer.accept(getValue()); - rulesSaveConsumer.accept(rules); - this.edited = false; - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - Window window = Minecraft.getInstance().getWindow(); - this.buttonWidget.active = this.isEditable(); - this.buttonWidget.y = y; - this.buttonWidget.x = x + entryWidth / 2 - width / 2; - this.buttonWidget.setWidth(width); - this.buttonWidget.render(matrices, mouseX, mouseY, delta); - } - - @Override - public List children() { - return children; - } - - @Override - public List narratables() { - return children; - } - - @Override - public boolean isEdited() { - return super.isEdited() || edited; +public record FilteringEntry( + Set> configFiltered, + List> rules, + FilteringScreen filteringScreen, + FilteringRulesScreen filteringRulesScreen +) { + public static FilteringEntry of(List> configFiltered, List> rules) { + TreeSet> set = new TreeSet<>(Comparator.comparing(EntryStacks::hashExact)); + set.addAll(configFiltered); + ArrayList> list = new ArrayList<>(rules); + FilteringScreen filteringScreen = new FilteringScreen(set); + return new FilteringEntry(set, list, filteringScreen, new FilteringRulesScreen(filteringScreen, list)); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java index cc56c93d5..62fac4b2b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringRulesScreen.java @@ -61,13 +61,15 @@ import java.util.stream.Collectors; public class FilteringRulesScreen extends Screen { - private final FilteringEntry entry; + private final FilteringScreen filteringScreen; + private final List> rules; private RulesList rulesList; - Screen parent; + public Screen parent; - public FilteringRulesScreen(FilteringEntry entry) { + public FilteringRulesScreen(FilteringScreen filteringScreen, List> rules) { super(new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen")); - this.entry = entry; + this.filteringScreen = filteringScreen; + this.rules = rules; } @Override @@ -83,20 +85,20 @@ public void init() { { Component addText = new TextComponent(" + "); addRenderableWidget(new Button(width - 4 - 20, 4, 20, 20, addText, button -> { - FilteringAddRuleScreen screen = new FilteringAddRuleScreen(entry); + FilteringAddRuleScreen screen = new FilteringAddRuleScreen(rules); screen.parent = this; minecraft.setScreen(screen); })); } rulesList = addWidget(new RulesList(minecraft, width, height, 30, height, BACKGROUND_LOCATION)); - for (int i = entry.rules.size() - 1; i >= 0; i--) { - FilteringRule rule = entry.rules.get(i); + for (int i = rules.size() - 1; i >= 0; i--) { + FilteringRule rule = rules.get(i); if (rule instanceof ManualFilteringRule) - rulesList.addItem(new DefaultRuleEntry(rule, entry, (screen) -> { - entry.filteringScreen.parent = screen; - return entry.filteringScreen; + rulesList.addItem(new DefaultRuleEntry(rule, rules, (screen) -> { + filteringScreen.parent = screen; + return filteringScreen; })); - else rulesList.addItem(new DefaultRuleEntry(rule, entry, null)); + else rulesList.addItem(new DefaultRuleEntry(rule, rules, null)); } rulesList.selectItem(rulesList.children().get(0)); } @@ -199,11 +201,10 @@ public static class DefaultRuleEntry extends RuleEntry { private final Button deleteButton; private final Function screenFunction; - public DefaultRuleEntry(FilteringRule rule, FilteringEntry entry, Function screenFunction) { + public DefaultRuleEntry(FilteringRule rule, List> rules, Function screenFunction) { super(rule); this.screenFunction = Objects.requireNonNullElseGet(screenFunction == null ? ((FilteringRuleType>) rule.getType()).createEntryScreen(rule) : screenFunction, () -> placeholderScreen(rule)); configureButton = new Button(0, 0, 20, 20, Component.nullToEmpty(null), button -> { - entry.edited = true; Minecraft.getInstance().setScreen(this.screenFunction.apply(Minecraft.getInstance().screen)); }) { @Override @@ -217,8 +218,7 @@ protected void renderBg(PoseStack matrices, Minecraft client, int mouseX, int mo Component deleteText = new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen.delete"); deleteButton = new Button(0, 0, Minecraft.getInstance().font.width(deleteText) + 10, 20, deleteText, button -> { final Screen screen = Minecraft.getInstance().screen; - entry.edited = true; - entry.rules.remove(rule); + rules.remove(rule); screen.init(Minecraft.getInstance(), screen.width, screen.height); }); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index 63be77f0c..38fba06a9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -87,14 +87,15 @@ public int getScrollBarX(int maxX) { }; Screen parent; - private FilteringEntry filteringEntry; + private Set> configFiltered; private Tooltip tooltip = null; private List> entryStacks = null; private Rectangle innerBounds; private List entries = Collections.emptyList(); private List elements = Collections.emptyList(); - private record PointPair(Point firstPoint, @Nullable Point secondPoint) {} + private record PointPair(Point firstPoint, @Nullable Point secondPoint) { + } private List points = new ArrayList<>(); @@ -108,9 +109,9 @@ private record PointPair(Point firstPoint, @Nullable Point secondPoint) {} private SearchFilter lastFilter = SearchFilter.matchAll(); - public FilteringScreen(FilteringEntry filteringEntry) { + public FilteringScreen(Set> configFiltered) { super(new TranslatableComponent("config.roughlyenoughitems.filteringScreen")); - this.filteringEntry = filteringEntry; + this.configFiltered = configFiltered; this.searchField = new OverlaySearchField(0, 0, 0, 0); { Component selectAllText = new TranslatableComponent("config.roughlyenoughitems.filteredEntries.selectAll"); @@ -133,8 +134,7 @@ public FilteringScreen(FilteringEntry filteringEntry) { FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); if (entry.isSelected() && !entry.isFiltered()) { - filteringEntry.configFiltered.add(stack); - filteringEntry.edited = true; + configFiltered.add(stack); entry.dirty = true; } } @@ -147,8 +147,7 @@ public FilteringScreen(FilteringEntry filteringEntry) { EntryStack stack = entryStacks.get(i); FilteringListEntry entry = entries.get(i); entry.getBounds().y = entry.backupY - scrolling.scrollAmountInt(); - if (entry.isSelected() && filteringEntry.configFiltered.remove(stack)) { - filteringEntry.edited = true; + if (entry.isSelected() && configFiltered.remove(stack)) { entry.dirty = true; } } @@ -491,7 +490,7 @@ public boolean isSelected() { public boolean isFiltered() { if (dirty) { - filtered = filteringEntry.configFiltered.contains(getCurrentEntry()); + filtered = configFiltered.contains(getCurrentEntry()); dirty = false; } return filtered; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java deleted file mode 100644 index 27068f031..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/NoFilteringEntry.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.config.entries; - -import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; -import me.shedaniel.rei.api.common.entry.EntryStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.TranslatableComponent; -import org.jetbrains.annotations.ApiStatus; - -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -@ApiStatus.Internal -public class NoFilteringEntry extends AbstractConfigListEntry>> { - private int width; - private Consumer>> saveConsumer; - private List> defaultValue; - private List> configFiltered; - private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, new TranslatableComponent("config.roughlyenoughitems.filteredEntries.loadWorldFirst"), button -> {}); - private final List children = ImmutableList.of(buttonWidget); - - public NoFilteringEntry(int width, List> configFiltered, List> defaultValue, Consumer>> saveConsumer) { - super(NarratorChatListener.NO_TITLE, false); - this.width = width; - this.configFiltered = configFiltered; - this.defaultValue = defaultValue; - this.saveConsumer = saveConsumer; - } - - @Override - public List> getValue() { - return configFiltered; - } - - @Override - public Optional>> getDefaultValue() { - return Optional.ofNullable(defaultValue); - } - - @Override - public void save() { - saveConsumer.accept(getValue()); - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - Window window = Minecraft.getInstance().getWindow(); - this.buttonWidget.active = false; - this.buttonWidget.y = y; - this.buttonWidget.x = x + entryWidth / 2 - width / 2; - this.buttonWidget.setWidth(width); - this.buttonWidget.render(matrices, mouseX, mouseY, delta); - } - - @Override - public List children() { - return children; - } - - @Override - public List narratables() { - return children; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java deleted file mode 100644 index 2f5ce90c0..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/RecipeScreenTypeEntry.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.config.entries; - -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.client.gui.config.DisplayScreenType; -import me.shedaniel.rei.impl.client.gui.screen.UncertainDisplayViewingScreen; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; - -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -public class RecipeScreenTypeEntry extends TooltipListEntry { - private int width; - private final DisplayScreenType original; - private DisplayScreenType type; - private DisplayScreenType defaultValue; - private Consumer save; - private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, button -> { - Minecraft.getInstance().setScreen(new UncertainDisplayViewingScreen(getConfigScreen(), type, false, original -> { - Minecraft.getInstance().setScreen(getConfigScreen()); - type = original ? DisplayScreenType.ORIGINAL : DisplayScreenType.COMPOSITE; - })); - }) { - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - setMessage(new TranslatableComponent("config.roughlyenoughitems.recipeScreenType.config", type.toString())); - super.render(matrices, mouseX, mouseY, delta); - } - }; - private final List children = ImmutableList.of(buttonWidget); - - @SuppressWarnings("deprecation") - public RecipeScreenTypeEntry(int width, Component fieldName, DisplayScreenType type, DisplayScreenType defaultValue, Consumer save) { - super(fieldName, null); - this.original = type; - this.width = width; - this.type = type; - this.defaultValue = defaultValue; - this.save = save; - } - - @Override - public boolean isEdited() { - return super.isEdited() || getValue() != original; - } - - @Override - public DisplayScreenType getValue() { - return type; - } - - @Override - public Optional getDefaultValue() { - return Optional.ofNullable(defaultValue); - } - - @Override - public void save() { - save.accept(type); - } - - @Override - public List children() { - return children; - } - - @Override - public List narratables() { - return children; - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - Window window = Minecraft.getInstance().getWindow(); - this.buttonWidget.active = this.isEditable(); - this.buttonWidget.y = y; - this.buttonWidget.x = x + entryWidth / 2 - width / 2; - this.buttonWidget.setWidth(width); - this.buttonWidget.render(matrices, mouseX, mouseY, delta); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java deleted file mode 100644 index ef7ddb9e9..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/SearchFilterSyntaxHighlightingEntry.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.config.entries; - -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.client.gui.config.SyntaxHighlightingMode; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; - -import java.util.List; -import java.util.Optional; -import java.util.function.Consumer; - -public class SearchFilterSyntaxHighlightingEntry extends TooltipListEntry { - private final SyntaxHighlightingMode original; - private SyntaxHighlightingMode type; - private SyntaxHighlightingMode defaultValue; - private Consumer save; - private final AbstractWidget buttonWidget = new Button(0, 0, 0, 20, NarratorChatListener.NO_TITLE, $ -> { - type = SyntaxHighlightingMode.values()[(type.ordinal() + 1) % SyntaxHighlightingMode.values().length]; - }) { - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - setMessage(new TextComponent(type.toString())); - super.render(matrices, mouseX, mouseY, delta); - } - }; - private final List children = ImmutableList.of(buttonWidget); - - @SuppressWarnings("deprecation") - public SearchFilterSyntaxHighlightingEntry(Component fieldName, SyntaxHighlightingMode type, SyntaxHighlightingMode defaultValue, Consumer save) { - super(fieldName, null); - this.original = type; - this.type = type; - this.defaultValue = defaultValue; - this.save = save; - } - - @Override - public boolean isEdited() { - return super.isEdited() || getValue() != original; - } - - @Override - public SyntaxHighlightingMode getValue() { - return type; - } - - @Override - public Optional getDefaultValue() { - return Optional.ofNullable(defaultValue); - } - - @Override - public void save() { - save.accept(type); - } - - @Override - public List children() { - return children; - } - - @Override - public List narratables() { - return children; - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - Window window = Minecraft.getInstance().getWindow(); - this.buttonWidget.active = this.isEditable(); - this.buttonWidget.y = y; - Component displayedFieldName = this.getDisplayedFieldName(); - if (Minecraft.getInstance().font.isBidirectional()) { - Minecraft.getInstance().font.drawShadow(matrices, displayedFieldName.getVisualOrderText(), window.getGuiScaledWidth() - x - Minecraft.getInstance().font.width(displayedFieldName), y + 6, 16777215); - this.buttonWidget.x = x; - } else { - Minecraft.getInstance().font.drawShadow(matrices, displayedFieldName.getVisualOrderText(), x, y + 6, this.getPreferredTextColor()); - this.buttonWidget.x = x + entryWidth - 150; - } - - this.buttonWidget.setWidth(150); - this.buttonWidget.render(matrices, mouseX, mouseY, delta); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java deleted file mode 100644 index 411277353..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/TitleTextEntry.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 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.impl.client.config.entries; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; -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.narration.NarratableEntry; -import net.minecraft.network.chat.Component; -import net.minecraft.util.Unit; -import org.jetbrains.annotations.ApiStatus; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -@ApiStatus.Internal -public class TitleTextEntry extends AbstractConfigListEntry { - private Component text; - - public TitleTextEntry(Component text) { - super(NarratorChatListener.NO_TITLE, false); - this.text = text; - } - - @Override - public Unit getValue() { - return Unit.INSTANCE; - } - - @Override - public Optional getDefaultValue() { - return Optional.of(Unit.INSTANCE); - } - - @Override - public void save() { - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); - matrices.pushPose(); - matrices.translate(x + entryWidth / 2F - Minecraft.getInstance().font.width(text) * 1.5F / 2F, y + 5, 1.0F); - matrices.scale(1.5F, 1.5F, 1.0F); - Minecraft.getInstance().font.drawShadow(matrices, text, 0.0F, 0.0F, -1); - matrices.popPose(); - } - - @Override - public int getItemHeight() { - return 26; - } - - @Override - public List children() { - return Collections.emptyList(); - } - - @Override - public List narratables() { - return Collections.emptyList(); - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java index a15e86f60..0ceb610b8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java @@ -97,6 +97,7 @@ static OptionGroup make(String id) { .add(IDENTIFIER_SEARCH); OptionGroup SEARCH_ADVANCED = make("search.advanced"); OptionGroup FILTERING_FILTERING = make("filtering.filtering") + .add(CATEGORIES) .add(CUSTOMIZED_FILTERING); OptionGroup FILTERING_ADVANCED = make("filtering.advanced") .add(FILTER_DISPLAYS) diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java index c4a00b17d..a68311686 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java @@ -26,6 +26,7 @@ import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.gui.config.*; import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -33,6 +34,7 @@ import me.shedaniel.rei.impl.client.config.ConfigObjectImpl; import me.shedaniel.rei.impl.client.config.collapsible.CollapsibleConfigManager; import me.shedaniel.rei.impl.client.config.entries.ConfigureCategoriesScreen; +import me.shedaniel.rei.impl.client.config.entries.FilteringEntry; import me.shedaniel.rei.impl.client.gui.config.REIConfigScreen; import me.shedaniel.rei.impl.client.gui.config.options.configure.PanelBoundariesConfiguration; import me.shedaniel.rei.impl.client.gui.performance.PerformanceScreen; @@ -176,7 +178,7 @@ static CompositeOption make(String id, Function bind CompositeOption IDENTIFIER_SEARCH = make("search.identifier_search", i -> i.advanced.search.identifierSearch, (i, v) -> i.advanced.search.identifierSearch = v) .enumOptions(); // TODO: ASYNC_SEARCH - CompositeOption CUSTOMIZED_FILTERING = make("filtering.customized_filtering", i -> { + CompositeOption CATEGORIES = make("filtering.categories", i -> { return new ConfigureCategoriesScreen( new HashMap<>(i.getFilteringQuickCraftCategories()), new HashSet<>(i.getHiddenCategories()), @@ -191,6 +193,19 @@ static CompositeOption make(String id, Function bind screen.parent = Minecraft.getInstance().screen; Minecraft.getInstance().setScreen(screen); }).requiresLevel(); + CompositeOption CUSTOMIZED_FILTERING = make("filtering.customized_filtering", i -> { + return FilteringEntry.of( + CollectionUtils.map(i.advanced.filtering.filteredStacks, EntryStackProvider::provide), + i.advanced.filtering.filteringRules + ); + }, (i, entry) -> { + i.advanced.filtering.filteredStacks = CollectionUtils.map(entry.configFiltered(), EntryStackProvider::ofStack); + i.advanced.filtering.filteringRules = new ArrayList<>(entry.rules()); + }).configure((access, option, onClose) -> { + FilteringEntry entry = access.get(option); + entry.filteringRulesScreen().parent = Minecraft.getInstance().screen; + Minecraft.getInstance().setScreen(entry.filteringRulesScreen()); + }).requiresLevel(); CompositeOption FILTER_DISPLAYS = make("filtering.filter_displays", i -> i.advanced.filtering.shouldFilterDisplays, (i, v) -> i.advanced.filtering.shouldFilterDisplays = v) .enabledDisabled(); CompositeOption MERGE_DISPLAYS = make("filtering.merge_displays", i -> i.advanced.layout.mergeDisplayUnderOne, (i, v) -> i.advanced.layout.mergeDisplayUnderOne = v) diff --git a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json index 25fb4d9c9..7a408b64b 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -405,6 +405,8 @@ "config.rei.options.search.async_search.partition_size": "Partition Size", "config.rei.options.search.async_search.patch_thread_crash": "Patch Thread Crash", "config.rei.options.groups.filtering.filtering": "Filtering", + "config.rei.options.filtering.categories": "Manage Categories", + "config.rei.options.filtering.categories.desc": "Reorder, toggle, and configure categories. This is useful for organizing entries, and hiding entries you do not need.", "config.rei.options.filtering.customized_filtering": "Customized Filtering", "config.rei.options.filtering.customized_filtering.desc": "Create filtering rules to hide / show specific entries from the entry list.", "config.rei.options.groups.filtering.advanced": "Advanced", @@ -458,5 +460,33 @@ "config.rei.texts.configure": "Configure...", "config.rei.texts.details": "Details...", "config.rei.texts.reload": "Reload...", - "config.rei.texts.requires_level": "Load Level First!" + "config.rei.texts.requires_level": "Load Level First!", + "config.roughlyenoughitems.configureCategories.title": "Configuring Categories", + "config.roughlyenoughitems.configureCategories.visibility.true": "Enabled", + "config.roughlyenoughitems.configureCategories.visibility.false": "Disabled", + "config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure.title": "Configuring Quick Craft Categories", + "config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure.toggle": "Toggle", + "config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure.true": "Available for Quick Craft", + "config.roughlyenoughitems.filtering.filteringQuickCraftCategories.configure.false": "Excluded from Quick Craft", + "config.roughlyenoughitems.filteringScreen": "Customized Filtering", + "config.roughlyenoughitems.filteringRulesScreen": "Customized Filtering Rules", + "config.roughlyenoughitems.filteringRulesScreen.new": "Create Filtering Rule", + "config.roughlyenoughitems.filteringRulesScreen.delete": "Delete", + "config.roughlyenoughitems.filteringRulesScreen.hint": "Try Dragging!", + "config.roughlyenoughitems.filteredEntries.selectAll": "Select All", + "config.roughlyenoughitems.filteredEntries.selectNone": "Unselect All", + "config.roughlyenoughitems.filteredEntries.hide": "Hide Selected", + "config.roughlyenoughitems.filteredEntries.show": "Show Selected", + "rule.roughlyenoughitems.filtering.manual": "Manual Filtering", + "rule.roughlyenoughitems.filtering.manual.subtitle": "Manually select what to hide and show.", + "rule.roughlyenoughitems.filtering.search": "Search Filtering", + "rule.roughlyenoughitems.filtering.search.subtitle": "Filter using search filters.", + "rule.roughlyenoughitems.filtering.search.filter": "Search Filter:", + "rule.roughlyenoughitems.filtering.search.show": "Show / Hide:", + "rule.roughlyenoughitems.filtering.search.show.true": "Show", + "rule.roughlyenoughitems.filtering.search.show.false": "Hide", + "rule.roughlyenoughitems.filtering.basic": "Basic Plugin Filtering", + "rule.roughlyenoughitems.filtering.basic.subtitle": "Filter entries by REI plugins. This is not configurable here.", + "rule.roughlyenoughitems.filtering.hide.tag": "Tag Filtering", + "rule.roughlyenoughitems.filtering.hide.tag.subtitle": "Filter entries by 'c:hidden_from_recipe_viewers'. This is not configurable here." }