Skip to content

Commit

Permalink
Improve search config options
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Nov 11, 2016
1 parent 872ab5f commit d66a438
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 50 deletions.
69 changes: 39 additions & 30 deletions src/main/java/mezz/jei/config/Config.java
Expand Up @@ -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;
Expand Down Expand Up @@ -126,10 +131,6 @@ public static boolean isDeleteItemsInCheatModeActive() {
return cheatItemsEnabled && SessionData.isJeiOnServer();
}

public static boolean isColorSearchEnabled() {
return colorSearchEnabled;
}

public static boolean isCenterSearchBarEnabled() {
return centerSearchBarEnabled;
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/mezz/jei/config/LocalizedConfiguration.java
Expand Up @@ -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;
Expand Down Expand Up @@ -62,17 +63,17 @@ public <T extends Enum<T>> 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];
}
}
Expand Down
Expand Up @@ -305,7 +305,7 @@ private static <V> List<String> getTooltip(Minecraft minecraft, V ingredient, II
}
}

if (Config.isColorSearchEnabled()) {
if (Config.getColorSearchMode() != Config.SearchMode.DISABLED) {
ColorNamer colorNamer = Internal.getColorNamer();

Iterable<Color> colors = ingredientHelper.getColors(ingredient);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/mezz/jei/util/IngredientListElement.java
Expand Up @@ -61,7 +61,7 @@ protected IngredientListElement(V ingredient, IIngredientHelper<V> ingredientHel

this.tooltipString = getTooltipString(ingredient, ingredientRenderer, modId, modName, displayName);

if (Config.isColorSearchEnabled()) {
if (Config.getColorSearchMode() != Config.SearchMode.DISABLED) {
Iterable<Color> colors = ingredientHelper.getColors(ingredient);
ColorNamer colorNamer = Internal.getColorNamer();
Collection<String> colorNames = colorNamer.getColorNames(colors);
Expand Down Expand Up @@ -96,23 +96,23 @@ protected IngredientListElement(V ingredient, IIngredientHelper<V> 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);
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/assets/jei/lang/en_US.lang
Expand Up @@ -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.
Expand Down

0 comments on commit d66a438

Please sign in to comment.