Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/any-prefix' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed Aug 28, 2024
2 parents 77cb90b + 9fd16c6 commit 3c14adb
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 343 deletions.
311 changes: 37 additions & 274 deletions src/main/java/codechicken/nei/NEIClientConfig.java

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/main/java/codechicken/nei/SearchField.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public static class SearchParserProvider implements ISearchParserProvider {

protected final Function<Pattern, ItemFilter> createFilter;
protected final String name;
protected final char defaultPrefix;
protected final char prefix;
protected final EnumChatFormatting highlightedColor;

public SearchParserProvider(char defaultPrefix, String name, EnumChatFormatting highlightedColor,
public SearchParserProvider(char prefix, String name, EnumChatFormatting highlightedColor,
Function<Pattern, ItemFilter> createFilter) {
this.defaultPrefix = defaultPrefix;
this.prefix = prefix;
this.name = name;
this.highlightedColor = highlightedColor;
this.createFilter = createFilter;
Expand All @@ -74,8 +74,7 @@ protected ItemFilter createFilter(Pattern pattern) {

@Override
public char getPrefix() {
String prefix = NEIClientConfig.getStringSetting("inventory.search." + this.name + "SearchPrefix");
return prefix.length() == 0 ? this.defaultPrefix : prefix.charAt(0);
return this.prefix;
}

@Override
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/codechicken/nei/SearchTokenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -20,6 +19,8 @@
import codechicken.nei.ItemList.NegatedItemFilter;
import codechicken.nei.ItemList.NothingItemFilter;
import codechicken.nei.api.ItemFilter;
import gnu.trove.map.TCharCharMap;
import gnu.trove.map.hash.TCharCharHashMap;

public class SearchTokenParser {

Expand Down Expand Up @@ -71,6 +72,7 @@ public void clear() {

protected final List<ISearchParserProvider> searchProviders;
protected final ProvidersCache providersCache = new ProvidersCache();
protected final TCharCharMap prefixRedefinitions = new TCharCharHashMap();

public SearchTokenParser(List<ISearchParserProvider> searchProviders) {
this.searchProviders = searchProviders;
Expand Down Expand Up @@ -109,7 +111,9 @@ protected List<ISearchParserProvider> getProviders() {

public ISearchParserProvider getProvider(char ch) {
return getProviders().stream()
.filter(provider -> provider.getSearchMode() == SearchMode.PREFIX && provider.getPrefix() == ch)
.filter(
provider -> provider.getSearchMode() == SearchMode.PREFIX
&& getRedefinedPrefix(provider.getPrefix()) == ch)
.findFirst().orElse(null);
}

Expand All @@ -128,18 +132,24 @@ public ItemFilter getFilter(String filterText) {
}

public Pattern getSplitPattern() {
StringJoiner prefixes = new StringJoiner("");
prefixes.add(String.valueOf('\0'));
StringBuilder prefixes = new StringBuilder().append('\0');

for (ISearchParserProvider provider : getProviders()) {
if (provider.getSearchMode() == SearchMode.PREFIX) {
prefixes.add(String.valueOf(provider.getPrefix()));
prefixes.append(getRedefinedPrefix(provider.getPrefix()));
}
}

return Pattern.compile("((-*)([" + Pattern.quote(prefixes.toString()) + "]*)(\\\".*?(?:\\\"|$)|\\S+))");
}

private char getRedefinedPrefix(char prefix) {
if (this.prefixRedefinitions.containsKey(prefix)) {
return this.prefixRedefinitions.get(prefix);
}
return prefix;
}

private ItemFilter parseSearchText(String filterText) {

if (filterText.isEmpty()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/codechicken/nei/SubsetWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ public ItemFilter getFilter(String searchText) {
}

public char getPrefix() {
String prefix = NEIClientConfig.getStringSetting("inventory.search.subsetsSearchPrefix");
return prefix.length() == 0 ? '%' : prefix.charAt(0);
return '%';
}

public EnumChatFormatting getHighlightedColor() {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/codechicken/nei/api/ItemInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,6 @@ private static void addSearchProviders() {
API.addSearchProvider(
new SearchParserProvider('\0', "default", EnumChatFormatting.RESET, PatternItemFilter::new) {

@Override
public char getPrefix() {
return defaultPrefix;
}

@Override
public SearchMode getSearchMode() {
return SearchMode.ALWAYS;
Expand Down
47 changes: 20 additions & 27 deletions src/main/java/codechicken/nei/config/OptionTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@

public class OptionTextField extends Option {

protected final TextField textField = createTextField();
protected final TextField textField = new TextField("test") {

{
this.h = 20;
}

@Override
public void onTextChange(String oldText) {
// don't override global if text hasn't changed
if (focused() && isValidValue(text()) && (!defaulting() || !text().equals(getTag().getValue()))) {
getTag().setValue(text());
}
}

@Override
public void setFocus(boolean focus) {
if (!focus && !isValidValue(text())) setText(renderTag().getValue());
super.setFocus(focus);
}
};

public OptionTextField(String name) {
super(name);
Expand Down Expand Up @@ -72,30 +91,4 @@ public boolean isValidInput(String s) {
public boolean isValidValue(String s) {
return true;
}

protected TextField createTextField() {
return new DefaultOptionTextField();
}

protected class DefaultOptionTextField extends TextField {

public DefaultOptionTextField() {
super("test");
this.h = 20;
}

@Override
public void onTextChange(String oldText) {
// don't override global if text hasn't changed
if (focused() && isValidValue(text()) && (!defaulting() || !text().equals(getTag().getValue()))) {
getTag().setValue(text());
}
}

@Override
public void setFocus(boolean focus) {
if (!focus && !isValidValue(text())) setText(renderTag().getValue());
super.setFocus(focus);
}
}
}
15 changes: 5 additions & 10 deletions src/main/resources/assets/nei/lang/de_DE.lang
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,24 @@ nei.options.inventory.search.patternMode.1=Erweitert
nei.options.inventory.search.patternMode.2=Regex
nei.options.inventory.search.modNameSearchMode=Modname Suchmodus
nei.options.inventory.search.modNameSearchMode.0=Immer
nei.options.inventory.search.modNameSearchMode.1=Präfix
nei.options.inventory.search.modNameSearchMode.1=Präfix: %s
nei.options.inventory.search.modNameSearchMode.2=Nie
nei.options.inventory.search.modNameSearchPrefix=Modname Suchpräfix
nei.options.inventory.search.tooltipSearchMode=Tooltip Suchmodus
nei.options.inventory.search.tooltipSearchMode.0=Immer
nei.options.inventory.search.tooltipSearchMode.1=Präfix
nei.options.inventory.search.tooltipSearchMode.1=Präfix: %s
nei.options.inventory.search.tooltipSearchMode.2=Nie
nei.options.inventory.search.tooltipSearchPrefix=Tooltip Suchpräfix
nei.options.inventory.search.identifierSearchMode=Identifikator Suchmodus
nei.options.inventory.search.identifierSearchMode.0=Immer
nei.options.inventory.search.identifierSearchMode.1=Präfix
nei.options.inventory.search.identifierSearchMode.1=Präfix: %s
nei.options.inventory.search.identifierSearchMode.2=Nie
nei.options.inventory.search.identifierSearchPrefix=Identifier Suchpräfix
nei.options.inventory.search.oreDictSearchMode=OreDict Suchmodus
nei.options.inventory.search.oreDictSearchMode.0=Immer
nei.options.inventory.search.oreDictSearchMode.1=Präfix
nei.options.inventory.search.oreDictSearchMode.1=Präfix: %s
nei.options.inventory.search.oreDictSearchMode.2=Nie
nei.options.inventory.search.oreDictSearchPrefix=OreDict Suchpräfix
nei.options.inventory.search.subsetsSearchMode=Item-SubSet Suchmodus
nei.options.inventory.search.subsetsSearchMode.0=Immer
nei.options.inventory.search.subsetsSearchMode.1=Präfix
nei.options.inventory.search.subsetsSearchMode.1=Präfix: %s
nei.options.inventory.search.subsetsSearchMode.2=Nie
nei.options.inventory.search.subsetsSearchPrefix=Item-SubSet Suchpräfix
nei.options.inventory.utilities=Nützliches
nei.options.inventory.utilities.tip=Wähle Inhalte für den Mehrzweckmodus
nei.options.inventory.utilities.time=Zeit
Expand Down
25 changes: 10 additions & 15 deletions src/main/resources/assets/nei/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -225,31 +225,26 @@ nei.options.inventory.search.patternMode.2=Regex
nei.options.inventory.search.quoteDropItemName=Quote Drop Item Name
nei.options.inventory.search.quoteDropItemName.true=Yes
nei.options.inventory.search.quoteDropItemName.false=No
nei.options.inventory.search.modNameSearchMode=Mod Name Search Mode
nei.options.inventory.search.modNameSearchMode=Mod Name Search
nei.options.inventory.search.modNameSearchMode.0=Always
nei.options.inventory.search.modNameSearchMode.1=Prefix
nei.options.inventory.search.modNameSearchMode.1=Prefix: %s
nei.options.inventory.search.modNameSearchMode.2=Never
nei.options.inventory.search.modNameSearchPrefix=Mod Name Search Prefix
nei.options.inventory.search.tooltipSearchMode=Tooltip Search Mode
nei.options.inventory.search.tooltipSearchMode=Tooltip Search
nei.options.inventory.search.tooltipSearchMode.0=Always
nei.options.inventory.search.tooltipSearchMode.1=Prefix
nei.options.inventory.search.tooltipSearchMode.1=Prefix: %s
nei.options.inventory.search.tooltipSearchMode.2=Never
nei.options.inventory.search.tooltipSearchPrefix=Tooltip Search Prefix
nei.options.inventory.search.identifierSearchMode=Identifier Search Mode
nei.options.inventory.search.identifierSearchMode=Resource ID Search
nei.options.inventory.search.identifierSearchMode.0=Always
nei.options.inventory.search.identifierSearchMode.1=Prefix
nei.options.inventory.search.identifierSearchMode.1=Prefix: %s
nei.options.inventory.search.identifierSearchMode.2=Never
nei.options.inventory.search.identifierSearchPrefix=Identifier Search Prefix
nei.options.inventory.search.oreDictSearchMode=OreDict Search Mode
nei.options.inventory.search.oreDictSearchMode=OreDict Search
nei.options.inventory.search.oreDictSearchMode.0=Always
nei.options.inventory.search.oreDictSearchMode.1=Prefix
nei.options.inventory.search.oreDictSearchMode.1=Prefix: %s
nei.options.inventory.search.oreDictSearchMode.2=Never
nei.options.inventory.search.oreDictSearchPrefix=OreDict Search Prefix
nei.options.inventory.search.subsetsSearchMode=Item Subset Search Mode
nei.options.inventory.search.subsetsSearchMode=Item Subsets Search
nei.options.inventory.search.subsetsSearchMode.0=Always
nei.options.inventory.search.subsetsSearchMode.1=Prefix
nei.options.inventory.search.subsetsSearchMode.1=Prefix: %s
nei.options.inventory.search.subsetsSearchMode.2=Never
nei.options.inventory.search.subsetsSearchPrefix=Item Subset Search Prefix
nei.options.inventory.guirecipe.creativeTabStyle=Creative or JEI tab style
nei.options.inventory.guirecipe.creativeTabStyle.true=Creative
nei.options.inventory.guirecipe.creativeTabStyle.false=JEI
Expand Down

0 comments on commit 3c14adb

Please sign in to comment.