Skip to content

Commit

Permalink
Close #913
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Apr 15, 2024
1 parent 86e2071 commit f4da1a8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ static ConfigObject getInstance() {
*/
boolean isEntryListWidgetScrolled();

@ApiStatus.Experimental
boolean isHidingEntryPanelIfIdle();

/**
* Returns whether REI should append mod names to tooltips.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
@ApiStatus.Internal
@Config(name = "roughlyenoughitems/config")
@Environment(EnvType.CLIENT)
@SuppressWarnings("FieldMayBeFinal")
public class ConfigObjectImpl implements ConfigObject, ConfigData {
@ConfigEntry.Category("basics") @ConfigEntry.Gui.TransitiveObject @DontApplyFieldName
public Basics basics = new Basics();
Expand Down Expand Up @@ -139,6 +140,15 @@ public void setEntryListWidgetScrolled(boolean scrollingEntryListWidget) {
appearance.scrollingEntryListWidget = scrollingEntryListWidget;
}

@Override
public boolean isHidingEntryPanelIfIdle() {
return appearance.hideEntryPanelIfIdle;
}

public void setHidingEntryPanelIfIdle(boolean hideEntryPanelIfIdle) {
appearance.hideEntryPanelIfIdle = hideEntryPanelIfIdle;
}

@Override
public boolean shouldAppendModNames() {
return advanced.tooltips.appendModNames;
Expand Down Expand Up @@ -625,6 +635,7 @@ public static class Appearance {
@Comment("Declares the appearance of recipe's border.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
private RecipeBorderType recipeBorder = RecipeBorderType.DEFAULT;
@Comment("Declares whether entry panel is scrolled.") private boolean scrollingEntryListWidget = false;
@Comment("Declares whether entry panel should be invisible when not searching") private boolean hideEntryPanelIfIdle = false;

public static class Layout {
@Comment("Declares the position of the search field.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import dev.architectury.utils.value.BooleanValue;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.REIRuntime;
import me.shedaniel.rei.api.client.config.ConfigManager;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry;
Expand Down Expand Up @@ -115,6 +116,13 @@ private static Collection<FavoriteMenuEntry> menuEntries(MenuAccess access) {
entries.add(new SubMenuEntry(new TranslatableComponent("text.rei.config.menu.search_field.input_method"), createInputMethodEntries(access, applicableInputMethods)));
}

entries.add(ToggleMenuEntry.of(new TranslatableComponent("text.rei.config.menu.search_field.hide_entry_panel_idle"),
config::isHidingEntryPanelIfIdle,
hideEntryPanelIfIdle -> {
config.setHidingEntryPanelIfIdle(hideEntryPanelIfIdle);
REIRuntime.getInstance().getOverlay().orElseThrow().queueReloadSearch();
}));

return entries;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import me.shedaniel.rei.api.client.gui.config.EntryPanelOrdering;
import me.shedaniel.rei.api.client.registry.entry.CollapsibleEntryRegistry;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.client.search.SearchFilter;
import me.shedaniel.rei.api.client.view.Views;
import me.shedaniel.rei.api.common.entry.EntryStack;
import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes;
Expand Down Expand Up @@ -67,7 +68,7 @@ public class EntryListSearchManager {

public static final EntryListSearchManager INSTANCE = new EntryListSearchManager();

private final AsyncSearchManager searchManager = new AsyncSearchManager(((EntryRegistryImpl) EntryRegistry.getInstance())::getPreFilteredComplexList, () -> {
private final AsyncSearchManager searchManager = new AsyncSearchManager(EntryListSearchManager::getAllEntriesContextually, () -> {
boolean checkCraftable = ConfigManager.getInstance().isCraftableOnlyEnabled();
LongSet workingItems = checkCraftable ? new LongOpenHashSet() : null;
if (checkCraftable) {
Expand All @@ -78,6 +79,14 @@ public class EntryListSearchManager {
return checkCraftable ? stack -> workingItems.contains(stack.hashExact()) : stack -> true;
}, HashedEntryStackWrapper::normalize);

private static List<EntryStack<?>> getAllEntriesContextually(SearchFilter filter) {
if (ConfigObject.getInstance().isHidingEntryPanelIfIdle() && filter.getFilter().isEmpty()) {
return List.of();
}

return EntryRegistry.getInstance().getPreFilteredList();
}

public void update(String searchTerm, boolean ignoreLastSearch, Consumer<List</*EntryStack<?> | CollapsedStack*/ Object>> update) {
Stopwatch stopwatch = Stopwatch.createStarted();
if (ignoreLastSearch) searchManager.markDirty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.function.*;

public class AsyncSearchManager {
private static final ExecutorService EXECUTOR_SERVICE = new ThreadCreator("REI-AsyncSearchManager").asService(Math.min(3, Runtime.getRuntime().availableProcessors()));
private final Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider;
private final Function<SearchFilter, List<? extends HashedEntryStackWrapper>> stacksProvider;
private final Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier;
private final UnaryOperator<HashedEntryStackWrapper> transformer;
private volatile Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last;
public volatile ExecutorTuple executor;
public volatile SearchFilter filter;

public AsyncSearchManager(Supplier<List<? extends HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
public AsyncSearchManager(Function<SearchFilter, List<? extends HashedEntryStackWrapper>> stacksProvider, Supplier<Predicate<HashedEntryStackWrapper>> additionalPredicateSupplier, UnaryOperator<HashedEntryStackWrapper> transformer) {
this.stacksProvider = stacksProvider;
this.additionalPredicateSupplier = additionalPredicateSupplier;
this.transformer = transformer;
Expand Down Expand Up @@ -123,7 +120,7 @@ public CompletableFuture<Map.Entry<List<HashedEntryStackWrapper>, SearchFilter>>
Map.Entry<List<HashedEntryStackWrapper>, SearchFilter> last;
last = this.last;
return get(this.filter, this.additionalPredicateSupplier.get(), this.transformer,
this.stacksProvider.get(), last, this, executor, steps)
this.stacksProvider.apply(filter), last, this, executor, steps)
.thenApply(entry -> {
this.last = entry;
return entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"text.rei.config.menu.config": "More Options...",
"text.rei.config.menu.search_field.position": "Search Field Position...",
"text.rei.config.menu.search_field.input_method": "Input Methods...",
"text.rei.config.menu.search_field.hide_entry_panel_idle": "Hide Entries when not Searching",
"category.rei.crafting": "Crafting",
"category.rei.smelting": "Smelting",
"category.rei.smelting.fuel": "Fuel",
Expand Down Expand Up @@ -334,6 +335,9 @@
"config.roughlyenoughitems.scrollingEntryListWidget": "Entry List Action:",
"config.roughlyenoughitems.scrollingEntryListWidget.boolean.true": "Scrolled",
"config.roughlyenoughitems.scrollingEntryListWidget.boolean.false": "Paginated",
"config.roughlyenoughitems.hideEntryPanelIfIdle": "Entry List When Not Searching:",
"config.roughlyenoughitems.hideEntryPanelIfIdle.boolean.true": "Invisible",
"config.roughlyenoughitems.hideEntryPanelIfIdle.boolean.false": "Visible",
"config.roughlyenoughitems.horizontalEntriesBoundaries": "Horizontal Entries Boundaries:",
"config.roughlyenoughitems.verticalEntriesBoundaries": "Vertical Entries Boundaries:",
"config.roughlyenoughitems.horizontalEntriesBoundariesColumns": "Entries Columns Limit:",
Expand Down

0 comments on commit f4da1a8

Please sign in to comment.