From d66a4384a9bbf63608962859cae84cda9169f0ab Mon Sep 17 00:00:00 2001 From: mezz Date: Thu, 10 Nov 2016 19:35:05 -0800 Subject: [PATCH] Improve search config options --- src/main/java/mezz/jei/config/Config.java | 69 +++++++++++-------- .../jei/config/LocalizedConfiguration.java | 7 +- .../gui/ingredients/GuiIngredientFast.java | 2 +- .../mezz/jei/util/IngredientListElement.java | 12 ++-- src/main/resources/assets/jei/lang/en_US.lang | 20 +++--- 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/src/main/java/mezz/jei/config/Config.java b/src/main/java/mezz/jei/config/Config.java index f2b1c0d8d..d4dc54d71 100644 --- a/src/main/java/mezz/jei/config/Config.java +++ b/src/main/java/mezz/jei/config/Config.java @@ -43,17 +43,22 @@ public class Config { // advanced private static boolean debugModeEnabled = false; - private static boolean colorSearchEnabled = false; private static boolean centerSearchBarEnabled = false; private static final String defaultModNameFormatFriendly = "blue italic"; private static String modNameFormat = parseFriendlyModNameFormat(defaultModNameFormatFriendly); // search - private static boolean prefixRequiredForModNameSearch = true; - private static boolean prefixRequiredForTooltipSearch = false; - private static boolean prefixRequiredForOreDictSearch = true; - private static boolean prefixRequiredForCreativeTabSearch = true; - private static boolean prefixRequiredForColorSearch = true; + private static final SearchMode defaultModNameSearchMode = SearchMode.REQUIRE_PREFIX; + private static final SearchMode defaultTooltipSearchMode = SearchMode.ENABLED; + private static final SearchMode defaultOreDictSearchMode = SearchMode.REQUIRE_PREFIX; + private static final SearchMode defaultCreativeTabSearchMode = SearchMode.REQUIRE_PREFIX; + private static final SearchMode defaultColorSearchMode = SearchMode.DISABLED; + + private static SearchMode modNameSearchMode = defaultModNameSearchMode; + private static SearchMode tooltipSearchMode = defaultTooltipSearchMode; + private static SearchMode oreDictSearchMode = defaultOreDictSearchMode; + private static SearchMode creativeTabSearchMode = defaultCreativeTabSearchMode; + private static SearchMode colorSearchMode = defaultColorSearchMode; // per-world private static final boolean defaultOverlayEnabled = true; @@ -126,10 +131,6 @@ public static boolean isDeleteItemsInCheatModeActive() { return cheatItemsEnabled && SessionData.isJeiOnServer(); } - public static boolean isColorSearchEnabled() { - return colorSearchEnabled; - } - public static boolean isCenterSearchBarEnabled() { return centerSearchBarEnabled; } @@ -138,24 +139,28 @@ public static String getModNameFormat() { return modNameFormat; } - public static boolean isPrefixRequiredForModNameSearch() { - return prefixRequiredForModNameSearch; + public static SearchMode getModNameSearchMode() { + return modNameSearchMode; + } + + public static SearchMode getTooltipSearchMode() { + return tooltipSearchMode; } - public static boolean isPrefixRequiredForTooltipSearch() { - return prefixRequiredForTooltipSearch; + public static SearchMode getOreDictSearchMode() { + return oreDictSearchMode; } - public static boolean isPrefixRequiredForOreDictSearch() { - return prefixRequiredForOreDictSearch; + public static SearchMode getCreativeTabSearchMode() { + return creativeTabSearchMode; } - public static boolean isPrefixRequiredForCreativeTabSearch() { - return prefixRequiredForCreativeTabSearch; + public static SearchMode getColorSearchMode() { + return colorSearchMode; } - public static boolean isPrefixRequiredForColorSearch() { - return prefixRequiredForColorSearch; + public enum SearchMode { + ENABLED, REQUIRE_PREFIX, DISABLED } public static boolean setFilterText(String filterText) { @@ -295,11 +300,19 @@ private static boolean syncConfig() { config.removeCategory(interfaceCategory); } - prefixRequiredForModNameSearch = config.getBoolean(CATEGORY_SEARCH, "atPrefixRequiredForModName", prefixRequiredForModNameSearch); - prefixRequiredForTooltipSearch = config.getBoolean(CATEGORY_SEARCH, "prefixRequiredForTooltipSearch", prefixRequiredForTooltipSearch); - prefixRequiredForOreDictSearch = config.getBoolean(CATEGORY_SEARCH, "prefixRequiredForOreDictSearch", prefixRequiredForOreDictSearch); - prefixRequiredForCreativeTabSearch = config.getBoolean(CATEGORY_SEARCH, "prefixRequiredForCreativeTabSearch", prefixRequiredForCreativeTabSearch); - prefixRequiredForColorSearch = config.getBoolean(CATEGORY_SEARCH, "prefixRequiredForColorSearch", prefixRequiredForColorSearch); + ConfigCategory searchCategory = config.getCategory(CATEGORY_SEARCH); + searchCategory.remove("atPrefixRequiredForModName"); + searchCategory.remove("prefixRequiredForTooltipSearch"); + searchCategory.remove("prefixRequiredForOreDictSearch"); + searchCategory.remove("prefixRequiredForCreativeTabSearch"); + searchCategory.remove("prefixRequiredForColorSearch"); + + SearchMode[] searchModes = SearchMode.values(); + modNameSearchMode = config.getEnum("modNameSearchMode", CATEGORY_SEARCH, defaultModNameSearchMode, searchModes); + tooltipSearchMode = config.getEnum("tooltipSearchMode", CATEGORY_SEARCH, defaultTooltipSearchMode, searchModes); + oreDictSearchMode = config.getEnum("oreDictSearchMode", CATEGORY_SEARCH, defaultOreDictSearchMode, searchModes); + creativeTabSearchMode = config.getEnum("creativeTabSearchMode", CATEGORY_SEARCH, defaultCreativeTabSearchMode, searchModes); + colorSearchMode = config.getEnum("colorSearchMode", CATEGORY_SEARCH, defaultColorSearchMode, searchModes); if (config.getCategory(CATEGORY_SEARCH).hasChanged()) { needsReload = true; } @@ -310,11 +323,7 @@ private static boolean syncConfig() { categoryAdvanced.remove("hideLaggyModelsEnabled"); categoryAdvanced.remove("hideMissingModelsEnabled"); categoryAdvanced.remove("debugItemEnabled"); - - colorSearchEnabled = config.getBoolean(CATEGORY_ADVANCED, "colorSearchEnabled", colorSearchEnabled); - if (categoryAdvanced.get("colorSearchEnabled").hasChanged()) { - needsReload = true; - } + categoryAdvanced.remove("colorSearchEnabled"); centerSearchBarEnabled = config.getBoolean(CATEGORY_ADVANCED, "centerSearchBarEnabled", centerSearchBarEnabled); diff --git a/src/main/java/mezz/jei/config/LocalizedConfiguration.java b/src/main/java/mezz/jei/config/LocalizedConfiguration.java index 3f3c6feb2..8e93592e5 100644 --- a/src/main/java/mezz/jei/config/LocalizedConfiguration.java +++ b/src/main/java/mezz/jei/config/LocalizedConfiguration.java @@ -2,6 +2,7 @@ import java.io.File; import java.util.Arrays; +import java.util.Locale; import mezz.jei.util.Translator; import net.minecraftforge.common.config.Configuration; @@ -62,17 +63,17 @@ public > T getEnum(String name, String category, T defaultValu String[] validValues = new String[validEnumValues.length]; for (int i = 0; i < validEnumValues.length; i++) { T enumValue = validEnumValues[i]; - validValues[i] = enumValue.name(); + validValues[i] = enumValue.name().toLowerCase(Locale.ENGLISH); } prop.setValidValues(validValues); prop.setLanguageKey(langKey); - prop.setComment(comment + " [" + defaultLocalized + ": " + defaultValue + "] [" + validLocalized + ": " + Arrays.toString(prop.getValidValues()) + ']'); + prop.setComment(comment + "\n[" + defaultLocalized + ": " + defaultValue.name().toLowerCase(Locale.ENGLISH) + "]\n[" + validLocalized + ": " + Arrays.toString(prop.getValidValues()) + ']'); String stringValue = prop.getString(); T enumValue = defaultValue; for (int i = 0; i < validValues.length; i++) { - if (stringValue.equals(validValues[i])) { + if (stringValue.equalsIgnoreCase(validValues[i])) { enumValue = validEnumValues[i]; } } diff --git a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFast.java b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFast.java index 8f666a122..95430e7e4 100644 --- a/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFast.java +++ b/src/main/java/mezz/jei/gui/ingredients/GuiIngredientFast.java @@ -305,7 +305,7 @@ private static List getTooltip(Minecraft minecraft, V ingredient, II } } - if (Config.isColorSearchEnabled()) { + if (Config.getColorSearchMode() != Config.SearchMode.DISABLED) { ColorNamer colorNamer = Internal.getColorNamer(); Iterable colors = ingredientHelper.getColors(ingredient); diff --git a/src/main/java/mezz/jei/util/IngredientListElement.java b/src/main/java/mezz/jei/util/IngredientListElement.java index e2a5638ce..5d59d54b1 100644 --- a/src/main/java/mezz/jei/util/IngredientListElement.java +++ b/src/main/java/mezz/jei/util/IngredientListElement.java @@ -61,7 +61,7 @@ protected IngredientListElement(V ingredient, IIngredientHelper ingredientHel this.tooltipString = getTooltipString(ingredient, ingredientRenderer, modId, modName, displayName); - if (Config.isColorSearchEnabled()) { + if (Config.getColorSearchMode() != Config.SearchMode.DISABLED) { Iterable colors = ingredientHelper.getColors(ingredient); ColorNamer colorNamer = Internal.getColorNamer(); Collection colorNames = colorNamer.getColorNames(colors); @@ -96,23 +96,23 @@ protected IngredientListElement(V ingredient, IIngredientHelper ingredientHel StringBuilder searchStringBuilder = new StringBuilder(displayName); - if (!Config.isPrefixRequiredForModNameSearch()) { + if (Config.getModNameSearchMode() == Config.SearchMode.ENABLED) { searchStringBuilder.append(' ').append(this.modNameString); } - if (!Config.isPrefixRequiredForTooltipSearch()) { + if (Config.getTooltipSearchMode() == Config.SearchMode.ENABLED) { searchStringBuilder.append(' ').append(this.tooltipString); } - if (!Config.isPrefixRequiredForOreDictSearch()) { + if (Config.getOreDictSearchMode() == Config.SearchMode.ENABLED) { searchStringBuilder.append(' ').append(this.oreDictString); } - if (!Config.isPrefixRequiredForCreativeTabSearch()) { + if (Config.getCreativeTabSearchMode() == Config.SearchMode.ENABLED) { searchStringBuilder.append(' ').append(this.creativeTabsString); } - if (!Config.isPrefixRequiredForColorSearch()) { + if (Config.getColorSearchMode() == Config.SearchMode.ENABLED) { searchStringBuilder.append(' ').append(this.colorString); } diff --git a/src/main/resources/assets/jei/lang/en_US.lang b/src/main/resources/assets/jei/lang/en_US.lang index 00d36e293..75790131d 100644 --- a/src/main/resources/assets/jei/lang/en_US.lang +++ b/src/main/resources/assets/jei/lang/en_US.lang @@ -54,16 +54,16 @@ config.jei.interface.recipeAnimationsEnabled.comment=Show recipe animations (fur config.jei.search=Search Options config.jei.search.comment=Options relating to the search bar. -config.jei.search.atPrefixRequiredForModName=Require @ for Mod Name -config.jei.search.atPrefixRequiredForModName.comment=Require "@" in front of a word to search by mod name. -config.jei.search.prefixRequiredForTooltipSearch=Require # for Tooltip -config.jei.search.prefixRequiredForTooltipSearch.comment=Require "#" in front of a word to search tooltips. -config.jei.search.prefixRequiredForOreDictSearch=Require $ for Ore Dictionary -config.jei.search.prefixRequiredForOreDictSearch.comment=Require "$" in front of a word to search ore dictionary names. -config.jei.search.prefixRequiredForCreativeTabSearch=Require %% for Creative Tab Name -config.jei.search.prefixRequiredForCreativeTabSearch.comment=Require "%" in front of a word to search creative tab names. -config.jei.search.prefixRequiredForColorSearch=Require ^ for Colors -config.jei.search.prefixRequiredForColorSearch.comment=Require "^" in front of a word to search item colors. +config.jei.search.modNameSearchMode=@ModName +config.jei.search.modNameSearchMode.comment=Search mode for Mod Names (prefix: @) +config.jei.search.tooltipSearchMode=#Tooltip +config.jei.search.tooltipSearchMode.comment=Search mode for Tooltips (prefix: #) +config.jei.search.oreDictSearchMode=$OreDictionary +config.jei.search.oreDictSearchMode.comment=Search mode for Ore Dictionary Names (prefix: $) +config.jei.search.creativeTabSearchMode=%%CreativeTab +config.jei.search.creativeTabSearchMode.comment=Search mode for Creative Tab Names (prefix: %) +config.jei.search.colorSearchMode=^Color +config.jei.search.colorSearchMode.comment=Search mode for Item Colors (prefix: ^) config.jei.advanced=Advanced config.jei.advanced.comment=Advanced config options to change the way JEI functions.