diff options
| author | shedaniel <daniel@shedaniel.me> | 2023-02-01 02:18:42 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2024-04-16 00:38:18 +0900 |
| commit | 8b8ded201bda1597bb8bacdda7f9882d6026976f (patch) | |
| tree | d8cc138c113ba3c2ee1074df886ed7db64d81eee | |
| parent | 45bffbf6342f77da096f12f967db6b4553e34d0f (diff) | |
| download | RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.tar.gz RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.tar.bz2 RoughlyEnoughItems-8b8ded201bda1597bb8bacdda7f9882d6026976f.zip | |
Close #1249
20 files changed, 1524 insertions, 235 deletions
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 d016b9152..681356a99 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 @@ -47,6 +47,8 @@ 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; @@ -59,17 +61,24 @@ 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.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.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen; -import me.shedaniel.rei.impl.client.gui.performance.entry.PerformanceEntry; +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; @@ -89,6 +98,7 @@ import net.minecraft.network.chat.TextColor; 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.*; @@ -153,6 +163,7 @@ public class ConfigManagerImpl implements ConfigManager { InternalLogger.getInstance().info("Config loaded"); saveConfig(); FavoritesConfigManager.getInstance().syncFrom(this); + CollapsibleConfigManager.getInstance().syncFrom(this); } public static Jankson buildJankson(Jankson.Builder builder) { @@ -414,9 +425,46 @@ public class ConfigManagerImpl implements ConfigManager { )) .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)); + })).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(); + })); builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.advanced")).getEntries().add(0, feedbackEntry); - builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.advanced")).getEntries().add(0, new ReloadPluginsEntry(220)); - builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.advanced")).getEntries().add(0, new PerformanceEntry(220)); + builder.getOrCreateCategory(Component.translatable("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))); + } else { + super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isSelected, delta); + } + } + }); + builder.getOrCreateCategory(Component.translatable("config.roughlyenoughitems.advanced")).getEntries().add(0, new ButtonsConfigEntry(220, + Triple.of(new TranslatableComponent("text.rei.performance"), $ -> {}, $ -> { + Minecraft.getInstance().setScreen(new PerformanceScreen(Minecraft.getInstance().screen)); + }))); } ConfigAddonRegistryImpl addonRegistry = (ConfigAddonRegistryImpl) ConfigAddonRegistry.getInstance(); if (!addonRegistry.getAddons().isEmpty()) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/collapsible/CollapsibleConfigManager.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/collapsible/CollapsibleConfigManager.java new file mode 100644 index 000000000..edcca423d --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/collapsible/CollapsibleConfigManager.java @@ -0,0 +1,102 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 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.collapsible; + +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.Config; +import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; +import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Jankson; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; +import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionResult; +import org.jetbrains.annotations.ApiStatus; + +import java.util.ArrayList; +import java.util.List; + +import static me.shedaniel.rei.impl.client.config.ConfigManagerImpl.buildJankson; + +@ApiStatus.Internal +public class CollapsibleConfigManager { + private static final CollapsibleConfigManager INSTANCE = new CollapsibleConfigManager(); + private CollapsibleConfigObject object; + + public CollapsibleConfigManager() { + AutoConfig.register(CollapsibleConfigObject.class, (definition, configClass) -> new JanksonConfigSerializer<>(definition, configClass, buildJankson(Jankson.builder()))); + } + + public static CollapsibleConfigManager getInstance() { + return INSTANCE; + } + + public void saveConfig() { + AutoConfig.getConfigHolder(CollapsibleConfigObject.class).registerLoadListener((configHolder, configObject) -> { + object = configObject; + return InteractionResult.PASS; + }); + AutoConfig.getConfigHolder(CollapsibleConfigObject.class).save(); + } + + public CollapsibleConfigObject getConfig() { + if (object == null) { + object = AutoConfig.getConfigHolder(CollapsibleConfigObject.class).getConfig(); + } + return object; + } + + public void syncFrom(ConfigManagerImpl manager) { + manager.saveConfig(); + this.saveConfig(); + } + + @Config(name = "roughlyenoughitems/collapsible") + @Environment(EnvType.CLIENT) + public static final class CollapsibleConfigObject implements ConfigData { + public List<ResourceLocation> disabledGroups = new ArrayList<>(); + public List<CustomGroup> customGroups = new ArrayList<>(); + } + + public static final class CustomGroup { + public ResourceLocation id = new ResourceLocation("missingno"); + public String name = "Invalid"; + public List<EntryStackProvider<?>> stacks = new ArrayList<>(); + + public CustomGroup() { + } + + public CustomGroup(ResourceLocation id, String name, List<EntryStackProvider<?>> stacks) { + this.id = id; + this.name = name; + this.stacks = stacks; + } + + public CustomGroup copy() { + return new CustomGroup(this.id, this.name, new ArrayList<>(this.stacks)); + } + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java index 7f6031fe8..707c1eca5 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/performance/entry/PerformanceEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ButtonsConfigEntry.java @@ -21,13 +21,11 @@ * SOFTWARE. */ -package me.shedaniel.rei.impl.client.gui.performance.entry; +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.impl.client.gui.performance.PerformanceScreen; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.components.Button; @@ -35,23 +33,40 @@ 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 PerformanceEntry extends AbstractConfigListEntry<Unit> { - private int width; - private AbstractWidget buttonWidget = new Button(0, 0, 0, 20, Component.empty(), button -> { - Minecraft.getInstance().setScreen(new PerformanceScreen(Minecraft.getInstance().screen)); - }); - private List<AbstractWidget> children = ImmutableList.of(buttonWidget); +public class ButtonsConfigEntry extends AbstractConfigListEntry<Unit> { + private final int width; + private final List<AbstractWidget> children; + private boolean edited; + private Runnable saveRunnable = () -> {}; - public PerformanceEntry(int width) { + public ButtonsConfigEntry(int width, Triple<Component, Consumer<Button>, Consumer<Runnable>>... buttons) { super(Component.empty(), false); this.width = width; - buttonWidget.setMessage(Component.translatable("text.rei.performance")); + 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 @@ -66,18 +81,20 @@ public class PerformanceEntry extends AbstractConfigListEntry<Unit> { @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(); - 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); + 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 @@ -89,4 +106,9 @@ public class PerformanceEntry extends AbstractConfigListEntry<Unit> { public List<? extends NarratableEntry> 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 438359cd5..3f2f220ac 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 @@ -78,6 +78,11 @@ public class FilteringAddRuleScreen extends Screen { this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); } + @Override + public void onClose() { + this.minecraft.setScreen(parent); + } + public static class RulesList extends DynamicElementListWidget<RuleEntry> { private boolean inFocus; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesScreen.java index b9f63385d..5bb6a98a9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringCategoriesScreen.java @@ -76,6 +76,11 @@ public class FilteringCategoriesScreen extends Screen { this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); } + @Override + public void onClose() { + this.minecraft.setScreen(parent); + } + private static class ListWidget extends DynamicElementListWidget<ListEntry> { private boolean inFocus; 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 6d899d5a5..015f5703a 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 @@ -37,6 +37,7 @@ import me.shedaniel.rei.impl.client.entry.filtering.FilteringContextType; import me.shedaniel.rei.impl.client.entry.filtering.rules.ManualFilteringRule; import me.shedaniel.rei.impl.client.entry.filtering.rules.SearchFilteringRuleType; import me.shedaniel.rei.impl.client.gui.InternalTextures; +import me.shedaniel.rei.impl.client.gui.screen.generic.OptionEntriesScreen; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.common.entry.type.FilteringLogic; import me.shedaniel.rei.impl.common.util.HashedEntryStackWrapper; @@ -105,6 +106,11 @@ public class FilteringRulesScreen extends Screen { this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); } + @Override + public void onClose() { + this.minecraft.setScreen(parent); + } + public static class RulesList extends DynamicElementListWidget<RuleEntry> { private boolean inFocus; @@ -261,26 +267,26 @@ public class FilteringRulesScreen extends Screen { } private static <Cache> Function<Screen, Screen> placeholderScreen(FilteringRule<Cache> r) { - class PlaceholderScreen extends FilteringRuleOptionsScreen<FilteringRule<Cache>> { + class PlaceholderScreen extends OptionEntriesScreen { public PlaceholderScreen(Screen parent) { - super(r, parent); + super(new TranslatableComponent("config.roughlyenoughitems.filteringRulesScreen"), parent); } @Override - public void addEntries(Consumer<RuleEntry> entryConsumer) { + public void addEntries(Consumer<ListEntry> entryConsumer) { addEmpty(entryConsumer, 10); Function<Boolean, Component> function = bool -> { return Component.translatable("rule.roughlyenoughitems.filtering.search.show." + bool); }; Map<FilteringContextType, Set<HashedEntryStackWrapper>> stacks = FilteringLogic.hidden(List.of(r), false, false, EntryRegistry.getInstance().getEntryStacks().collect(Collectors.toList())); - entryConsumer.accept(new SubRulesEntry(rule, () -> function.apply(true), - Collections.singletonList(new SearchFilteringRuleType.EntryStacksRuleEntry(rule, + entryConsumer.accept(new SubListEntry(() -> function.apply(true), + Collections.singletonList(new SearchFilteringRuleType.EntryStacksRuleEntry( Suppliers.ofInstance(CollectionUtils.map(stacks.get(FilteringContextType.SHOWN), stack -> (EntryWidget) Widgets.createSlot(new Rectangle(0, 0, 18, 18)).disableBackground().entry(stack.unwrap().normalize()))))))); addEmpty(entryConsumer, 10); - entryConsumer.accept(new SubRulesEntry(rule, () -> function.apply(false), - Collections.singletonList(new SearchFilteringRuleType.EntryStacksRuleEntry(rule, + entryConsumer.accept(new SubListEntry(() -> function.apply(false), + Collections.singletonList(new SearchFilteringRuleType.EntryStacksRuleEntry( Suppliers.ofInstance(CollectionUtils.map(stacks.get(FilteringContextType.HIDDEN), stack -> (EntryWidget) Widgets.createSlot(new Rectangle(0, 0, 18, 18)).disableBackground().entry(stack.unwrap().normalize()))))))); } 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 063c6765e..fe310f282 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 @@ -163,6 +163,12 @@ public class FilteringScreen extends Screen { this.searchField.isMain = false; } + @Override + public void onClose() { + this.minecraft.setScreen(parent); + this.parent = null; + } + private static Rectangle updateInnerBounds(Rectangle bounds) { int width = Math.max(Mth.floor((bounds.width - 2 - 6) / (float) entrySize()), 1); return new Rectangle((int) (bounds.getCenterX() - width * entrySize() / 2f), bounds.y + 5, width * entrySize(), bounds.height); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.java deleted file mode 100644 index adcd084ea..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/ReloadPluginsEntry.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.api.AbstractConfigListEntry; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; -import me.shedaniel.rei.api.common.plugins.PluginManager; -import me.shedaniel.rei.impl.client.gui.screen.ConfigReloadingScreen; -import me.shedaniel.rei.impl.client.search.argument.Argument; -import net.minecraft.client.Minecraft; -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.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import net.minecraft.util.Unit; -import org.jetbrains.annotations.ApiStatus; - -import java.util.List; -import java.util.Optional; - -@ApiStatus.Internal -public class ReloadPluginsEntry extends AbstractConfigListEntry<Unit> { - private int width; - private AbstractWidget reloadPluginsButton = new Button(0, 0, 0, 20, Component.empty(), button -> { - RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); - RoughlyEnoughItemsCoreClient.reloadPlugins(null, null); - }) { - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (PluginManager.areAnyReloading()) { - Screen screen = Minecraft.getInstance().screen; - Minecraft.getInstance().setScreen(new ConfigReloadingScreen(Component.translatable("text.rei.config.is.reloading"), PluginManager::areAnyReloading, () -> Minecraft.getInstance().setScreen(screen), null)); - } else { - super.render(matrices, mouseX, mouseY, delta); - } - } - }; - private AbstractWidget reloadSearchButton = new Button(0, 0, 0, 20, Component.empty(), button -> { - Argument.resetCache(true); - }); - private List<AbstractWidget> children = ImmutableList.of(reloadPluginsButton, reloadSearchButton); - - public ReloadPluginsEntry(int width) { - super(Component.empty(), false); - this.width = width; - reloadPluginsButton.setMessage(Component.translatable("text.rei.reload_config")); - reloadSearchButton.setMessage(Component.translatable("text.rei.reload_search")); - } - - @Override - public Unit getValue() { - return Unit.INSTANCE; - } - - @Override - public Optional<Unit> 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); - Window window = Minecraft.getInstance().getWindow(); - this.reloadPluginsButton.active = this.isEditable(); - this.reloadPluginsButton.y = y; - this.reloadPluginsButton.setWidth(width / 2 - 2); - this.reloadPluginsButton.x = x + entryWidth / 2 - width / 2; - this.reloadPluginsButton.render(matrices, mouseX, mouseY, delta); - this.reloadSearchButton.active = this.isEditable() && Argument.hasCache(); - this.reloadSearchButton.y = y; - this.reloadSearchButton.setWidth(width / 2 - 2); - this.reloadSearchButton.x = x + entryWidth / 2 + 2; - this.reloadSearchButton.render(matrices, mouseX, mouseY, delta); - } - - @Override - public List<? extends GuiEventListener> children() { - return children; - } - - @Override - public List<? extends NarratableEntry> narratables() { - return children; - } -} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java index 9ffb425d8..b2fe82b92 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/entry/filtering/rules/SearchFilteringRuleType.java @@ -26,13 +26,12 @@ package me.shedaniel.rei.impl.client.entry.filtering.rules; import com.google.common.collect.Lists; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.entry.filtering.FilteringRule; import me.shedaniel.rei.api.client.entry.filtering.FilteringRuleType; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.client.config.entries.FilteringRuleOptionsScreen; +import me.shedaniel.rei.impl.client.gui.screen.generic.OptionEntriesScreen; |
