Skip to content

Commit

Permalink
Inventory Search Options
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Sep 23, 2024
1 parent 99e1212 commit 9b17fd6
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ public static class Functionality {
@Comment("Declares whether subsets is enabled.")
public boolean isSubsetsEnabled = false;
public boolean allowInventoryHighlighting = true;
public double inventoryHighlightingDarkenOpacity = 0.85;
public double inventoryHighlightingOpacity = 1.0;
public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static OptionCategory make(String key) {
OptionCategory ACCESSIBILITY = make("accessibility")
.add(ACCESSIBILITY_DISPLAY)
.add(ACCESSIBILITY_WIDGETS)
.add(ACCESSIBILITY_INVENTORY_SEARCH)
.add(ACCESSIBILITY_FEATURES);
OptionCategory FILTERING = make("filtering")
.add(FILTERING_FILTERING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ static <T> OptionGroup make(String id) {
OptionGroup ACCESSIBILITY_WIDGETS = make("accessibility.widgets")
.add(SCROLLBAR_VISIBILITY)
.add(CLICKABLE_RECIPE_ARROWS);
OptionGroup ACCESSIBILITY_INVENTORY_SEARCH = make("accessibility.inventory_search")
.add(INVENTORY_SEARCH_MODE)
.add(INVENTORY_SEARCH_DARKEN_OPACITY)
.add(INVENTORY_SEARCH_OPACITY);
OptionGroup ACCESSIBILITY_FEATURES = make("accessibility.features")
.add(VANILLA_RECIPE_BOOK)
.add(STATUS_EFFECTS_LOCATION)
.add(INVENTORY_SEARCH);
.add(STATUS_EFFECTS_LOCATION);
OptionGroup FILTERING_FILTERING = make("filtering.filtering")
.add(CATEGORIES)
.add(CUSTOMIZED_FILTERING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
translatable("config.rei.options." + id + ".desc"), bind, save);
}

static ComparableValue<Double>[] doubleRange(double start, double end, double step) {
int length = (int) Math.ceil((end - start) / step + 1);
ComparableValue<Double>[] result = new ComparableValue[length];
for (int i = 0; i < length; i++) {
result[i] = ComparableValue.ofDouble(Math.min(start + i * step, end));
}
return result;
}

CompositeOption<AppearanceTheme> THEME = make("appearance.theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v)
.enumOptions();
CompositeOption<RecipeBorderType> RECIPE_BORDER = make("appearance.recipe_border", i -> i.appearance.recipeBorder, (i, v) -> i.appearance.recipeBorder = v)
Expand Down Expand Up @@ -141,12 +150,18 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
.ofBoolean(translatable("config.rei.value.accessibility.scrollbar_visibility.when_scrolling"), translatable("config.rei.value.accessibility.scrollbar_visibility.always"));
CompositeOption<Boolean> CLICKABLE_RECIPE_ARROWS = make("accessibility.clickable_recipe_arrows", i -> i.advanced.miscellaneous.clickableRecipeArrows, (i, v) -> i.advanced.miscellaneous.clickableRecipeArrows = v)
.enabledDisabled();
CompositeOption<Boolean> INVENTORY_SEARCH_MODE = make("accessibility.inventory_search_mode", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v)
.enabledDisabled();
CompositeOption<ComparableValue<Double>> INVENTORY_SEARCH_DARKEN_OPACITY = make("accessibility.inventory_search_darken_opacity", i -> ComparableValue.ofDouble(i.functionality.inventoryHighlightingDarkenOpacity), (i, v) -> i.functionality.inventoryHighlightingDarkenOpacity = v.value())
.entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05))
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
CompositeOption<ComparableValue<Double>> INVENTORY_SEARCH_OPACITY = make("accessibility.inventory_search_opacity", i -> ComparableValue.ofDouble(i.functionality.inventoryHighlightingOpacity), (i, v) -> i.functionality.inventoryHighlightingOpacity = v.value())
.entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05))
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
CompositeOption<Boolean> VANILLA_RECIPE_BOOK = make("accessibility.vanilla_recipe_book", i -> !i.functionality.disableRecipeBook, (i, v) -> i.functionality.disableRecipeBook = !v)
.enabledDisabled();
CompositeOption<Boolean> STATUS_EFFECTS_LOCATION = make("accessibility.status_effects_location", i -> i.functionality.leftSideMobEffects, (i, v) -> i.functionality.leftSideMobEffects = v)
.ofBoolean(translatable("config.rei.value.accessibility.status_effects_location.right"), translatable("config.rei.value.accessibility.status_effects_location.left"));
CompositeOption<Boolean> INVENTORY_SEARCH = make("accessibility.inventory_search", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v)
.enabledDisabled();
CompositeOption<ConfigureCategoriesScreen> CATEGORIES = make("filtering.categories", i -> {
return new ConfigureCategoriesScreen(
new HashMap<>(i.getFilteringQuickCraftCategories()),
Expand Down Expand Up @@ -183,7 +198,9 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
.ofBoolean(translatable("config.rei.value.list.display_mode.paginated"), translatable("config.rei.value.list.display_mode.scrolled"));
CompositeOption<EntryPanelOrderingConfig> ORDERING = make("list.ordering", i -> i.advanced.layout.entryPanelOrdering, (i, v) -> i.advanced.layout.entryPanelOrdering = v)
.enumOptions();
CompositeOption<Double> ZOOM = make("list.zoom", i -> i.advanced.accessibility.entrySize, (i, v) -> i.advanced.accessibility.entrySize = v);
CompositeOption<ComparableValue<Double>> ZOOM = make("list.zoom", i -> ComparableValue.ofDouble(i.advanced.accessibility.entrySize), (i, v) -> i.advanced.accessibility.entrySize = v.value())
.entry(OptionValueEntry.options(doubleRange(0.25, 4.0, 0.25))
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
CompositeOption<Boolean> FOCUS_MODE = make("list.focus_mode", i -> i.appearance.isFocusModeZoomed, (i, v) -> i.appearance.isFocusModeZoomed = v)
.ofBoolean(translatable("config.rei.value.list.focus_mode.highlighted"), translatable("config.rei.value.list.focus_mode.zoomed"));
CompositeOption<CollapsibleConfigManager.CollapsibleConfigObject> COLLAPSIBLE_ENTRIES = make("list.collapsible_entries", i -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.gui.config.options;

import org.jetbrains.annotations.ApiStatus;

import java.util.Objects;
import java.util.function.BiPredicate;

@ApiStatus.Internal
public final class ComparableValue<T> {
private final T value;
private final BiPredicate<T, Object> equals;

private ComparableValue(T value, BiPredicate<T, Object> equals) {
this.value = value;
this.equals = equals;
}

public static <T> ComparableValue<T> of(T value, BiPredicate<T, Object> equals) {
return new ComparableValue<>(value, equals);
}

public static ComparableValue<Float> ofFloat(float value) {
return of(value, (a, b) -> b instanceof Float f && Math.abs(a - f) <= 0.001F);
}

public static ComparableValue<Double> ofDouble(double value) {
return of(value, (a, b) -> b instanceof Double d && Math.abs(a - d) <= 0.001D);
}

public T value() {
return value;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof ComparableValue) {
return equals.test(value, ((ComparableValue<?>) obj).value);
}

return false;
}

@Override
public int hashCode() {
return Objects.hashCode(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public Component getOption(T value) {
};
}

static <T> OptionValueEntry<T> options(T... options) {
static <T> OptionValueEntry.Selection<T> options(T... options) {
return new Selection<>() {
@Override
public List<T> getOptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
}

private void renderPreview(PoseStack poses, Rectangle panelBounds, float delta) {
int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM));
int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM).value());
Rectangle overlayBounds;
DisplayPanelLocation location = access.get(AllREIConfigOptions.LOCATION);
PanelBoundary boundary = access.get(option);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import me.shedaniel.math.Color;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListSearchManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
Expand All @@ -34,6 +36,11 @@

public class EntryHighlighter extends GuiComponent {
public static void render(PoseStack matrices) {
float dimOpacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingDarkenOpacity;
float opacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingOpacity;
int dimColor = Color.ofRGBA(20 / 255F, 20 / 255F, 20 / 255F, dimOpacity).getColor();
int borderColor = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity).getColor();
int color = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity * 0x34 / 255F).getColor();
RenderSystem.disableDepthTest();
RenderSystem.colorMask(true, true, true, false);
if (Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> containerScreen) {
Expand All @@ -42,18 +49,18 @@ public static void render(PoseStack matrices) {
if (!slot.hasItem() || !EntryListSearchManager.INSTANCE.matches(EntryStacks.of(slot.getItem()))) {
matrices.pushPose();
matrices.translate(0, 0, 500f);
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0xdc202020, 0xdc202020, 0);
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, dimColor, dimColor, 0);
matrices.popPose();
} else {
matrices.pushPose();
matrices.translate(0, 0, 200f);
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0x345fff3b, 0x345fff3b, 0);

fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);
fillGradient(matrices, x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, 0xff5fff3b, 0xff5fff3b, 0);
fillGradient(matrices, x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);

fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, color, color, 0);
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, borderColor, borderColor, 0);
fillGradient(matrices, x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, borderColor, borderColor, 0);
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, borderColor, borderColor, 0);
fillGradient(matrices, x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, borderColor, borderColor, 0);
matrices.popPose();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
if (Screen.hasControlDown()) {
ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig();
scaleIndicator.setAs(10.0D);
if (config.setEntrySize(config.getEntrySize() + amount * 0.075)) {
if (config.setEntrySize(config.getEntrySize() + Double.compare(amount, 0) * 0.05)) {
ConfigManager.getInstance().saveConfig();
REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,18 @@
"config.rei.value.accessibility.scrollbar_visibility.never": "Always Invisible",
"config.rei.options.accessibility.clickable_recipe_arrows": "Clickable Recipe Arrows",
"config.rei.options.accessibility.clickable_recipe_arrows.desc": "Click on recipe arrows to see all recipes in the target category.",
"config.rei.options.groups.accessibility.inventory_search": "Inventory Search",
"config.rei.options.accessibility.inventory_search_mode": "Mode",
"config.rei.options.accessibility.inventory_search_mode.desc": "Inventory Search allows you to search for items in your inventory. This can be useful for finding items in your inventory quickly.\nDouble click the search bar to toggle this feature.",
"config.rei.options.accessibility.inventory_search_darken_opacity": "Dim Overlay Opacity",
"config.rei.options.accessibility.inventory_search_darken_opacity.desc": "The opacity of the dark overlay for items not matching the search filter.",
"config.rei.options.accessibility.inventory_search_opacity": "Highlight Opacity",
"config.rei.options.accessibility.inventory_search_opacity.desc": "The opacity of the green overlay for items matching the search filter.",
"config.rei.options.groups.accessibility.features": "Features",
"config.rei.options.accessibility.vanilla_recipe_book": "Vanilla Recipe Book",
"config.rei.options.accessibility.vanilla_recipe_book.desc": "Toggle the vanilla recipe book. This option is not designed for Modpack developers, as users should be the one to decide whether to use the vanilla recipe book.",
"config.rei.options.accessibility.status_effects_location": "Status Effects Location",
"config.rei.options.accessibility.status_effects_location.desc": "The location of the status effects. By vanilla, the status effects are placed on the right, but this can be changed to the left.",
"config.rei.options.accessibility.inventory_search": "Inventory Search",
"config.rei.value.accessibility.status_effects_location.left": "Left",
"config.rei.value.accessibility.status_effects_location.right": "Right",
"config.rei.options.groups.favorites.favorites": "Favorites",
Expand Down

0 comments on commit 9b17fd6

Please sign in to comment.