Skip to content

Commit 9b17fd6

Browse files
committed
Inventory Search Options
1 parent 99e1212 commit 9b17fd6

File tree

10 files changed

+123
-17
lines changed

10 files changed

+123
-17
lines changed

runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,8 @@ public static class Functionality {
658658
@Comment("Declares whether subsets is enabled.")
659659
public boolean isSubsetsEnabled = false;
660660
public boolean allowInventoryHighlighting = true;
661+
public double inventoryHighlightingDarkenOpacity = 0.85;
662+
public double inventoryHighlightingOpacity = 1.0;
661663
public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE;
662664
}
663665

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static OptionCategory make(String key) {
5151
OptionCategory ACCESSIBILITY = make("accessibility")
5252
.add(ACCESSIBILITY_DISPLAY)
5353
.add(ACCESSIBILITY_WIDGETS)
54+
.add(ACCESSIBILITY_INVENTORY_SEARCH)
5455
.add(ACCESSIBILITY_FEATURES);
5556
OptionCategory FILTERING = make("filtering")
5657
.add(FILTERING_FILTERING)

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigGroups.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@ static <T> OptionGroup make(String id) {
6868
OptionGroup ACCESSIBILITY_WIDGETS = make("accessibility.widgets")
6969
.add(SCROLLBAR_VISIBILITY)
7070
.add(CLICKABLE_RECIPE_ARROWS);
71+
OptionGroup ACCESSIBILITY_INVENTORY_SEARCH = make("accessibility.inventory_search")
72+
.add(INVENTORY_SEARCH_MODE)
73+
.add(INVENTORY_SEARCH_DARKEN_OPACITY)
74+
.add(INVENTORY_SEARCH_OPACITY);
7175
OptionGroup ACCESSIBILITY_FEATURES = make("accessibility.features")
7276
.add(VANILLA_RECIPE_BOOK)
73-
.add(STATUS_EFFECTS_LOCATION)
74-
.add(INVENTORY_SEARCH);
77+
.add(STATUS_EFFECTS_LOCATION);
7578
OptionGroup FILTERING_FILTERING = make("filtering.filtering")
7679
.add(CATEGORIES)
7780
.add(CUSTOMIZED_FILTERING);

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigOptions.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
6161
translatable("config.rei.options." + id + ".desc"), bind, save);
6262
}
6363

64+
static ComparableValue<Double>[] doubleRange(double start, double end, double step) {
65+
int length = (int) Math.ceil((end - start) / step + 1);
66+
ComparableValue<Double>[] result = new ComparableValue[length];
67+
for (int i = 0; i < length; i++) {
68+
result[i] = ComparableValue.ofDouble(Math.min(start + i * step, end));
69+
}
70+
return result;
71+
}
72+
6473
CompositeOption<AppearanceTheme> THEME = make("appearance.theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v)
6574
.enumOptions();
6675
CompositeOption<RecipeBorderType> RECIPE_BORDER = make("appearance.recipe_border", i -> i.appearance.recipeBorder, (i, v) -> i.appearance.recipeBorder = v)
@@ -141,12 +150,18 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
141150
.ofBoolean(translatable("config.rei.value.accessibility.scrollbar_visibility.when_scrolling"), translatable("config.rei.value.accessibility.scrollbar_visibility.always"));
142151
CompositeOption<Boolean> CLICKABLE_RECIPE_ARROWS = make("accessibility.clickable_recipe_arrows", i -> i.advanced.miscellaneous.clickableRecipeArrows, (i, v) -> i.advanced.miscellaneous.clickableRecipeArrows = v)
143152
.enabledDisabled();
153+
CompositeOption<Boolean> INVENTORY_SEARCH_MODE = make("accessibility.inventory_search_mode", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v)
154+
.enabledDisabled();
155+
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())
156+
.entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05))
157+
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
158+
CompositeOption<ComparableValue<Double>> INVENTORY_SEARCH_OPACITY = make("accessibility.inventory_search_opacity", i -> ComparableValue.ofDouble(i.functionality.inventoryHighlightingOpacity), (i, v) -> i.functionality.inventoryHighlightingOpacity = v.value())
159+
.entry(OptionValueEntry.options(doubleRange(0.0, 1.0, 0.05))
160+
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
144161
CompositeOption<Boolean> VANILLA_RECIPE_BOOK = make("accessibility.vanilla_recipe_book", i -> !i.functionality.disableRecipeBook, (i, v) -> i.functionality.disableRecipeBook = !v)
145162
.enabledDisabled();
146163
CompositeOption<Boolean> STATUS_EFFECTS_LOCATION = make("accessibility.status_effects_location", i -> i.functionality.leftSideMobEffects, (i, v) -> i.functionality.leftSideMobEffects = v)
147164
.ofBoolean(translatable("config.rei.value.accessibility.status_effects_location.right"), translatable("config.rei.value.accessibility.status_effects_location.left"));
148-
CompositeOption<Boolean> INVENTORY_SEARCH = make("accessibility.inventory_search", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v)
149-
.enabledDisabled();
150165
CompositeOption<ConfigureCategoriesScreen> CATEGORIES = make("filtering.categories", i -> {
151166
return new ConfigureCategoriesScreen(
152167
new HashMap<>(i.getFilteringQuickCraftCategories()),
@@ -183,7 +198,9 @@ static <T> CompositeOption<T> make(String id, Function<ConfigObjectImpl, T> bind
183198
.ofBoolean(translatable("config.rei.value.list.display_mode.paginated"), translatable("config.rei.value.list.display_mode.scrolled"));
184199
CompositeOption<EntryPanelOrderingConfig> ORDERING = make("list.ordering", i -> i.advanced.layout.entryPanelOrdering, (i, v) -> i.advanced.layout.entryPanelOrdering = v)
185200
.enumOptions();
186-
CompositeOption<Double> ZOOM = make("list.zoom", i -> i.advanced.accessibility.entrySize, (i, v) -> i.advanced.accessibility.entrySize = v);
201+
CompositeOption<ComparableValue<Double>> ZOOM = make("list.zoom", i -> ComparableValue.ofDouble(i.advanced.accessibility.entrySize), (i, v) -> i.advanced.accessibility.entrySize = v.value())
202+
.entry(OptionValueEntry.options(doubleRange(0.25, 4.0, 0.25))
203+
.overrideText(d -> literal("%.0f%%".formatted(d.value() * 100))));
187204
CompositeOption<Boolean> FOCUS_MODE = make("list.focus_mode", i -> i.appearance.isFocusModeZoomed, (i, v) -> i.appearance.isFocusModeZoomed = v)
188205
.ofBoolean(translatable("config.rei.value.list.focus_mode.highlighted"), translatable("config.rei.value.list.focus_mode.zoomed"));
189206
CompositeOption<CollapsibleConfigManager.CollapsibleConfigObject> COLLAPSIBLE_ENTRIES = make("list.collapsible_entries", i -> {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* This file is licensed under the MIT License, part of Roughly Enough Items.
3+
* Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
package me.shedaniel.rei.impl.client.gui.config.options;
25+
26+
import org.jetbrains.annotations.ApiStatus;
27+
28+
import java.util.Objects;
29+
import java.util.function.BiPredicate;
30+
31+
@ApiStatus.Internal
32+
public final class ComparableValue<T> {
33+
private final T value;
34+
private final BiPredicate<T, Object> equals;
35+
36+
private ComparableValue(T value, BiPredicate<T, Object> equals) {
37+
this.value = value;
38+
this.equals = equals;
39+
}
40+
41+
public static <T> ComparableValue<T> of(T value, BiPredicate<T, Object> equals) {
42+
return new ComparableValue<>(value, equals);
43+
}
44+
45+
public static ComparableValue<Float> ofFloat(float value) {
46+
return of(value, (a, b) -> b instanceof Float f && Math.abs(a - f) <= 0.001F);
47+
}
48+
49+
public static ComparableValue<Double> ofDouble(double value) {
50+
return of(value, (a, b) -> b instanceof Double d && Math.abs(a - d) <= 0.001D);
51+
}
52+
53+
public T value() {
54+
return value;
55+
}
56+
57+
@Override
58+
public boolean equals(Object obj) {
59+
if (obj instanceof ComparableValue) {
60+
return equals.test(value, ((ComparableValue<?>) obj).value);
61+
}
62+
63+
return false;
64+
}
65+
66+
@Override
67+
public int hashCode() {
68+
return Objects.hashCode(value);
69+
}
70+
}

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Component getOption(T value) {
8282
};
8383
}
8484

85-
static <T> OptionValueEntry<T> options(T... options) {
85+
static <T> OptionValueEntry.Selection<T> options(T... options) {
8686
return new Selection<>() {
8787
@Override
8888
public List<T> getOptions() {

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void render(PoseStack poses, int mouseX, int mouseY, float delta) {
309309
}
310310

311311
private void renderPreview(PoseStack poses, Rectangle panelBounds, float delta) {
312-
int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM));
312+
int entrySize = Mth.ceil(18 * access.get(AllREIConfigOptions.ZOOM).value());
313313
Rectangle overlayBounds;
314314
DisplayPanelLocation location = access.get(AllREIConfigOptions.LOCATION);
315315
PanelBoundary boundary = access.get(option);

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
import com.mojang.blaze3d.systems.RenderSystem;
2727
import com.mojang.blaze3d.vertex.PoseStack;
28+
import me.shedaniel.math.Color;
2829
import me.shedaniel.rei.api.common.util.EntryStacks;
30+
import me.shedaniel.rei.impl.client.config.ConfigManagerImpl;
2931
import me.shedaniel.rei.impl.client.gui.widget.entrylist.EntryListSearchManager;
3032
import net.minecraft.client.Minecraft;
3133
import net.minecraft.client.gui.GuiComponent;
@@ -34,6 +36,11 @@
3436

3537
public class EntryHighlighter extends GuiComponent {
3638
public static void render(PoseStack matrices) {
39+
float dimOpacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingDarkenOpacity;
40+
float opacity = (float) ConfigManagerImpl.getInstance().getConfig().functionality.inventoryHighlightingOpacity;
41+
int dimColor = Color.ofRGBA(20 / 255F, 20 / 255F, 20 / 255F, dimOpacity).getColor();
42+
int borderColor = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity).getColor();
43+
int color = Color.ofRGBA(0x5f / 255F, 0xff / 255F, 0x3b / 255F, opacity * 0x34 / 255F).getColor();
3744
RenderSystem.disableDepthTest();
3845
RenderSystem.colorMask(true, true, true, false);
3946
if (Minecraft.getInstance().screen instanceof AbstractContainerScreen<?> containerScreen) {
@@ -42,18 +49,18 @@ public static void render(PoseStack matrices) {
4249
if (!slot.hasItem() || !EntryListSearchManager.INSTANCE.matches(EntryStacks.of(slot.getItem()))) {
4350
matrices.pushPose();
4451
matrices.translate(0, 0, 500f);
45-
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0xdc202020, 0xdc202020, 0);
52+
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, dimColor, dimColor, 0);
4653
matrices.popPose();
4754
} else {
4855
matrices.pushPose();
4956
matrices.translate(0, 0, 200f);
50-
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0x345fff3b, 0x345fff3b, 0);
51-
52-
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);
53-
fillGradient(matrices, x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);
54-
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, 0xff5fff3b, 0xff5fff3b, 0);
55-
fillGradient(matrices, x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, 0xff5fff3b, 0xff5fff3b, 0);
56-
57+
fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, color, color, 0);
58+
59+
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x, y + slot.y + 16 + 1, borderColor, borderColor, 0);
60+
fillGradient(matrices, x + slot.x + 16, y + slot.y - 1, x + slot.x + 16 + 1, y + slot.y + 16 + 1, borderColor, borderColor, 0);
61+
fillGradient(matrices, x + slot.x - 1, y + slot.y - 1, x + slot.x + 16, y + slot.y, borderColor, borderColor, 0);
62+
fillGradient(matrices, x + slot.x - 1, y + slot.y + 16, x + slot.x + 16, y + slot.y + 16 + 1, borderColor, borderColor, 0);
63+
5764
matrices.popPose();
5865
}
5966
}

runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
173173
if (Screen.hasControlDown()) {
174174
ConfigObjectImpl config = ConfigManagerImpl.getInstance().getConfig();
175175
scaleIndicator.setAs(10.0D);
176-
if (config.setEntrySize(config.getEntrySize() + amount * 0.075)) {
176+
if (config.setEntrySize(config.getEntrySize() + Double.compare(amount, 0) * 0.05)) {
177177
ConfigManager.getInstance().saveConfig();
178178
REIRuntime.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay);
179179
return true;

runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,18 @@
357357
"config.rei.value.accessibility.scrollbar_visibility.never": "Always Invisible",
358358
"config.rei.options.accessibility.clickable_recipe_arrows": "Clickable Recipe Arrows",
359359
"config.rei.options.accessibility.clickable_recipe_arrows.desc": "Click on recipe arrows to see all recipes in the target category.",
360+
"config.rei.options.groups.accessibility.inventory_search": "Inventory Search",
361+
"config.rei.options.accessibility.inventory_search_mode": "Mode",
362+
"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.",
363+
"config.rei.options.accessibility.inventory_search_darken_opacity": "Dim Overlay Opacity",
364+
"config.rei.options.accessibility.inventory_search_darken_opacity.desc": "The opacity of the dark overlay for items not matching the search filter.",
365+
"config.rei.options.accessibility.inventory_search_opacity": "Highlight Opacity",
366+
"config.rei.options.accessibility.inventory_search_opacity.desc": "The opacity of the green overlay for items matching the search filter.",
360367
"config.rei.options.groups.accessibility.features": "Features",
361368
"config.rei.options.accessibility.vanilla_recipe_book": "Vanilla Recipe Book",
362369
"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.",
363370
"config.rei.options.accessibility.status_effects_location": "Status Effects Location",
364371
"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.",
365-
"config.rei.options.accessibility.inventory_search": "Inventory Search",
366372
"config.rei.value.accessibility.status_effects_location.left": "Left",
367373
"config.rei.value.accessibility.status_effects_location.right": "Right",
368374
"config.rei.options.groups.favorites.favorites": "Favorites",

0 commit comments

Comments
 (0)