From ab5e4c25b4938a00c87029b3b692bb78f5a14017 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 4 Sep 2024 16:20:49 +0900 Subject: [PATCH] Inventory Search Options --- .../impl/client/config/ConfigObjectImpl.java | 2 + .../options/AllREIConfigCategories.java | 1 + .../config/options/AllREIConfigGroups.java | 7 +- .../config/options/AllREIConfigOptions.java | 23 +++++- .../gui/config/options/ComparableValue.java | 70 +++++++++++++++++++ .../gui/config/options/OptionValueEntry.java | 2 +- .../PanelBoundariesConfiguration.java | 2 +- .../client/gui/widget/EntryHighlighter.java | 23 +++--- .../gui/widget/entrylist/EntryListWidget.java | 2 +- .../assets/roughlyenoughitems/lang/en_us.json | 8 ++- 10 files changed, 123 insertions(+), 17 deletions(-) create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java 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 7840fa6cd..41e91b7c9 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 @@ -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; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java index 40e94ae10..0749f11a8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/AllREIConfigCategories.java @@ -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) 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 b206fd6e5..474132b8e 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 @@ -68,10 +68,13 @@ static 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); 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 97119df2e..30a673e38 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 @@ -60,6 +60,15 @@ static CompositeOption make(String id, Function bind translatable("config.rei.options." + id + ".desc"), bind, save); } + static ComparableValue[] doubleRange(double start, double end, double step) { + int length = (int) Math.ceil((end - start) / step + 1); + ComparableValue[] result = new ComparableValue[length]; + for (int i = 0; i < length; i++) { + result[i] = ComparableValue.ofDouble(Math.min(start + i * step, end)); + } + return result; + } + CompositeOption THEME = make("appearance.theme", i -> i.appearance.theme, (i, v) -> i.appearance.theme = v) .enumOptions(); CompositeOption RECIPE_BORDER = make("appearance.recipe_border", i -> i.appearance.recipeBorder, (i, v) -> i.appearance.recipeBorder = v) @@ -140,12 +149,18 @@ static CompositeOption make(String id, Function bind .ofBoolean(translatable("config.rei.value.accessibility.scrollbar_visibility.when_scrolling"), translatable("config.rei.value.accessibility.scrollbar_visibility.always")); CompositeOption CLICKABLE_RECIPE_ARROWS = make("accessibility.clickable_recipe_arrows", i -> i.advanced.miscellaneous.clickableRecipeArrows, (i, v) -> i.advanced.miscellaneous.clickableRecipeArrows = v) .enabledDisabled(); + CompositeOption INVENTORY_SEARCH_MODE = make("accessibility.inventory_search_mode", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v) + .enabledDisabled(); + CompositeOption> 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> 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 VANILLA_RECIPE_BOOK = make("accessibility.vanilla_recipe_book", i -> !i.functionality.disableRecipeBook, (i, v) -> i.functionality.disableRecipeBook = !v) .enabledDisabled(); CompositeOption 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 INVENTORY_SEARCH = make("accessibility.inventory_search", i -> i.functionality.allowInventoryHighlighting, (i, v) -> i.functionality.allowInventoryHighlighting = v) - .enabledDisabled(); CompositeOption CATEGORIES = make("filtering.categories", i -> { return new ConfigureCategoriesScreen( new HashMap<>(i.getFilteringQuickCraftCategories()), @@ -182,7 +197,9 @@ static CompositeOption make(String id, Function bind .ofBoolean(translatable("config.rei.value.list.display_mode.paginated"), translatable("config.rei.value.list.display_mode.scrolled")); CompositeOption ORDERING = make("list.ordering", i -> i.advanced.layout.entryPanelOrdering, (i, v) -> i.advanced.layout.entryPanelOrdering = v) .enumOptions(); - CompositeOption ZOOM = make("list.zoom", i -> i.advanced.accessibility.entrySize, (i, v) -> i.advanced.accessibility.entrySize = v); + CompositeOption> 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 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 COLLAPSIBLE_ENTRIES = make("list.collapsible_entries", i -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java new file mode 100644 index 000000000..d3cea57a3 --- /dev/null +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/ComparableValue.java @@ -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 { + private final T value; + private final BiPredicate equals; + + private ComparableValue(T value, BiPredicate equals) { + this.value = value; + this.equals = equals; + } + + public static ComparableValue of(T value, BiPredicate equals) { + return new ComparableValue<>(value, equals); + } + + public static ComparableValue ofFloat(float value) { + return of(value, (a, b) -> b instanceof Float f && Math.abs(a - f) <= 0.001F); + } + + public static ComparableValue 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); + } +} diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java index d1ef77787..fa058a1d9 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/OptionValueEntry.java @@ -82,7 +82,7 @@ public Component getOption(T value) { }; } - static OptionValueEntry options(T... options) { + static OptionValueEntry.Selection options(T... options) { return new Selection<>() { @Override public List getOptions() { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java index 0322a25ae..fb397c376 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/config/options/configure/PanelBoundariesConfiguration.java @@ -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); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java index 5d4145062..f683ab162 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/EntryHighlighter.java @@ -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; @@ -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) { @@ -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(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java index eedba9509..43626c21c 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/widget/entrylist/EntryListWidget.java @@ -172,7 +172,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; 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 5568968b6..af68baab0 100755 --- a/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json +++ b/runtime/src/main/resources/assets/roughlyenoughitems/lang/en_us.json @@ -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",