فهرست منبع

Implement search modes and make tooltip always enabled by default.
Close #452

Signed-off-by: shedaniel <daniel@shedaniel.me>

shedaniel 4 سال پیش
والد
کامیت
89e3598657

+ 6 - 0
RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java

@@ -193,4 +193,10 @@ public interface ConfigObject {
     
     @ApiStatus.Experimental
     SyntaxHighlightingMode getSyntaxHighlightingMode();
+    
+    SearchMode getTooltipSearchMode();
+    
+    SearchMode getTagSearchMode();
+    
+    SearchMode getModSearchMode();
 }

+ 44 - 0
RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/gui/config/SearchMode.java

@@ -0,0 +1,44 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020 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.gui.config;
+
+import me.shedaniel.clothconfig2.gui.entries.SelectionListEntry;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.api.Environment;
+import net.minecraft.client.resources.language.I18n;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Locale;
+
+@Environment(EnvType.CLIENT)
+public enum SearchMode implements SelectionListEntry.Translatable {
+    ALWAYS,
+    PREFIX,
+    NEVER;
+    
+    @Override
+    public @NotNull String getKey() {
+        return I18n.get("config.roughlyenoughitems.search_mode." + name().toLowerCase(Locale.ROOT));
+    }
+}

+ 21 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java

@@ -366,6 +366,21 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
         return appearance.syntaxHighlightingMode;
     }
     
+    @Override
+    public SearchMode getTooltipSearchMode() {
+        return advanced.search.tooltipSearch;
+    }
+    
+    @Override
+    public SearchMode getTagSearchMode() {
+        return advanced.search.tagSearch;
+    }
+    
+    @Override
+    public SearchMode getModSearchMode() {
+        return advanced.search.modSearch;
+    }
+    
     @Retention(RetentionPolicy.RUNTIME)
     @Target({ElementType.FIELD})
     @interface DontApplyFieldName {}
@@ -491,6 +506,12 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData {
             @Comment("Declares whether REI should search async.") private boolean asyncSearch = true;
             @Comment("Declares how many entries should be grouped one async search.") @ConfigEntry.BoundedDiscrete(min = 25, max = 400)
             private int asyncSearchPartitionSize = 100;
+            @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
+            private SearchMode tooltipSearch = SearchMode.ALWAYS;
+            @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) 
+            private SearchMode tagSearch = SearchMode.PREFIX;
+            @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
+            private SearchMode modSearch = SearchMode.PREFIX;
         }
         
         public static class Commands {

+ 10 - 8
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/OverlaySearchFieldSyntaxHighlighter.java

@@ -56,14 +56,16 @@ public class OverlaySearchFieldSyntaxHighlighter implements Consumer<String> {
             }
             
             @Override
-            public void addPart(SearchArgument<?, ?> argument, Collection<IntRange> grammarRanges, int index) {
-                int argIndex = ArgumentsRegistry.ARGUMENT_LIST.indexOf(argument.getArgument()) * 2 + 1;
-                for (int i = argument.start(); i < argument.end(); i++) {
-                    highlighted[i] = (byte) argIndex;
-                }
-                for (IntRange grammarRange : grammarRanges) {
-                    for (int i = grammarRange.getMinInclusive(); i <= grammarRange.getMaxInclusive(); i++) {
-                        highlighted[i + index] = (byte) (argIndex + 1);
+            public void addPart(SearchArgument<?, ?> argument, boolean usingGrammar, Collection<IntRange> grammarRanges, int index) {
+                if (usingGrammar) {
+                    int argIndex = ArgumentsRegistry.ARGUMENT_LIST.indexOf(argument.getArgument()) * 2 + 1;
+                    for (int i = argument.start(); i < argument.end(); i++) {
+                        highlighted[i] = (byte) argIndex;
+                    }
+                    for (IntRange grammarRange : grammarRanges) {
+                        for (int i = grammarRange.getMinInclusive(); i <= grammarRange.getMaxInclusive(); i++) {
+                            highlighted[i + index] = (byte) (argIndex + 1);
+                        }
                     }
                 }
             }

+ 5 - 3
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/SearchArgument.java

@@ -28,6 +28,7 @@ import com.google.common.collect.Lists;
 import me.shedaniel.math.Point;
 import me.shedaniel.rei.api.EntryStack;
 import me.shedaniel.rei.api.widgets.Tooltip;
+import me.shedaniel.rei.gui.config.SearchMode;
 import me.shedaniel.rei.impl.search.AlwaysMatchingArgument;
 import me.shedaniel.rei.impl.search.Argument;
 import me.shedaniel.rei.impl.search.ArgumentsRegistry;
@@ -89,8 +90,8 @@ public class SearchArgument<T, R> {
         void addQuote(int index);
         
         void addSplitter(int index);
-    
-        void addPart(SearchArgument<?, ?> argument, Collection<IntRange> grammarRanges, int index);
+        
+        void addPart(SearchArgument<?, ?> argument, boolean usingGrammar, Collection<IntRange> grammarRanges, int index);
     }
     
     @ApiStatus.Internal
@@ -109,6 +110,7 @@ public class SearchArgument<T, R> {
             while (terms.find()) {
                 String term = MoreObjects.firstNonNull(terms.group(1), terms.group(2));
                 for (Argument<?, ?> argument : ArgumentsRegistry.ARGUMENT_LIST) {
+                    if (argument.getSearchMode() == SearchMode.NEVER) continue;
                     MatchStatus status = argument.matchesArgumentPrefix(term);
                     if (status.isMatched()) {
                         SearchArgument<?, ?> searchArgument;
@@ -124,7 +126,7 @@ public class SearchArgument<T, R> {
                             arguments.add(searchArgument = new SearchArgument<>(argument, status.getText(), !status.isInverted(), terms.start(2) + tokenStartIndex, terms.end(2) + tokenStartIndex, !status.shouldPreserveCasing()));
                         }
                         if (sink != null) {
-                            sink.addPart(searchArgument, status.grammarRanges(), terms.start() + tokenStartIndex);
+                            sink.addPart(searchArgument, status.isUsingGrammar(), status.grammarRanges(), terms.start() + tokenStartIndex);
                         }
                         break;
                     }

+ 19 - 1
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/Argument.java

@@ -24,6 +24,7 @@
 package me.shedaniel.rei.impl.search;
 
 import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.gui.config.SearchMode;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.network.chat.Style;
@@ -50,8 +51,25 @@ public abstract class Argument<T, R> {
         return Style.EMPTY;
     }
     
+    public SearchMode getSearchMode() {
+        return SearchMode.PREFIX;
+    }
+    
     public MatchStatus matchesArgumentPrefix(String text) {
-        String prefix = getPrefix();
+        MatchStatus status = checkMatchPrefix(text, getPrefix());
+        if (status.isMatched()) {
+            return status;
+        } else if (getSearchMode() == SearchMode.ALWAYS) {
+            status = checkMatchPrefix(text, "");
+            if (status.isMatched()) {
+                status.notUsingGrammar();
+            }
+            return status;
+        }
+        return MatchStatus.unmatched();
+    }
+    
+    private MatchStatus checkMatchPrefix(String text, String prefix) {
         if (prefix == null) return MatchStatus.unmatched();
         if (text.startsWith("-" + prefix)) return MatchStatus.invertMatched(text.substring(1 + prefix.length())).grammar(0, prefix.length() + 1);
         if (text.startsWith(prefix + "-")) return MatchStatus.invertMatched(text.substring(1 + prefix.length())).grammar(0, prefix.length() + 1);

+ 10 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/MatchStatus.java

@@ -39,6 +39,7 @@ public final class MatchStatus {
     @Nullable
     private final String text;
     private final boolean preserveCasing;
+    private boolean usingGrammar = true;
     private final List<IntRange> grammarRanges = new ArrayList<>();
     
     private MatchStatus(MatchType type, @Nullable String text, boolean preserveCasing) {
@@ -97,6 +98,15 @@ public final class MatchStatus {
         return type == MatchType.INVERT_MATCHED;
     }
     
+    public MatchStatus notUsingGrammar() {
+        usingGrammar = false;
+        return this;
+    }
+    
+    public boolean isUsingGrammar() {
+        return usingGrammar;
+    }
+    
     public boolean shouldPreserveCasing() {
         return preserveCasing;
     }

+ 7 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/ModArgument.java

@@ -24,7 +24,9 @@
 package me.shedaniel.rei.impl.search;
 
 import me.shedaniel.rei.api.ClientHelper;
+import me.shedaniel.rei.api.ConfigObject;
 import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.gui.config.SearchMode;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.network.chat.Style;
@@ -55,6 +57,11 @@ public final class ModArgument extends Argument<Unit, ModArgument.@Nullable ModI
         return "@";
     }
     
+    @Override
+    public SearchMode getSearchMode() {
+        return ConfigObject.getInstance().getModSearchMode();
+    }
+    
     @Override
     public boolean matches(Mutable<@Nullable ModInfoPair> data, EntryStack stack, String searchText, Unit filterData) {
         if (data.getValue() == null) {

+ 2 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/RegexArgument.java

@@ -23,7 +23,9 @@
 
 package me.shedaniel.rei.impl.search;
 
+import me.shedaniel.rei.api.ConfigObject;
 import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.gui.config.SearchMode;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.network.chat.Style;

+ 7 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/TagArgument.java

@@ -23,7 +23,9 @@
 
 package me.shedaniel.rei.impl.search;
 
+import me.shedaniel.rei.api.ConfigObject;
 import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.gui.config.SearchMode;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
 import net.minecraft.client.Minecraft;
@@ -62,6 +64,11 @@ public final class TagArgument extends Argument<Unit, String[]> {
         return STYLE;
     }
     
+    @Override
+    public SearchMode getSearchMode() {
+        return ConfigObject.getInstance().getTagSearchMode();
+    }
+    
     @Override
     public boolean matches(Mutable<String[]> data, EntryStack stack, String searchText, Unit filterData) {
         if (data.getValue() == null) {

+ 7 - 0
RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/search/TooltipArgument.java

@@ -23,7 +23,9 @@
 
 package me.shedaniel.rei.impl.search;
 
+import me.shedaniel.rei.api.ConfigObject;
 import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.gui.config.SearchMode;
 import me.shedaniel.rei.impl.SearchArgument;
 import net.fabricmc.api.EnvType;
 import net.fabricmc.api.Environment;
@@ -58,6 +60,11 @@ public final class TooltipArgument extends Argument<Unit, String> {
         return STYLE;
     }
     
+    @Override
+    public SearchMode getSearchMode() {
+        return ConfigObject.getInstance().getTooltipSearchMode();
+    }
+    
     @Override
     public boolean matches(Mutable<String> data, EntryStack stack, String searchText, Unit filterData) {
         if (data.getValue() == null) {

+ 1 - 1
gradle.properties

@@ -1,5 +1,5 @@
 org.gradle.jvmargs=-Xmx3G
-base_version=5.10
+base_version=5.11
 supported_version=1.16.4/5
 minecraft_version=1.16.5
 fabricloader_version=0.11.1

+ 6 - 0
src/main/resources/assets/roughlyenoughitems/lang/en_us.json

@@ -171,6 +171,12 @@
   "config.roughlyenoughitems.accessibility.displayPanelLocation": "Entry Panel Position:",
   "config.roughlyenoughitems.accessibility.displayPanelLocation.left": "Left Side",
   "config.roughlyenoughitems.accessibility.displayPanelLocation.right": "Right Side",
+  "config.roughlyenoughitems.search.tooltipSearch": "Tooltip Search (#):",
+  "config.roughlyenoughitems.search.tagSearch": "Tag Search ($):",
+  "config.roughlyenoughitems.search.modSearch": "Mod Search (@):",
+  "config.roughlyenoughitems.search_mode.always": "Always Enabled",
+  "config.roughlyenoughitems.search_mode.prefix": "While Using Prefix",
+  "config.roughlyenoughitems.search_mode.never": "Always Disabled",
   "config.roughlyenoughitems.layout.debugRenderTimeRequired": "Entry Panel Debug Mode:",
   "config.roughlyenoughitems.search.debugSearchTimeRequired": "Search Debug Mode:",
   "config.roughlyenoughitems.accessibility.resizeDynamically": "Resize Dynamically:",