mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-17 19:15:13 +00:00
Add back search mode settings and add ingame setting for prefixes
This commit is contained in:
1 parent
87f71b6ef9
commit
9feb9d72ce
9 files changed
+337
-59
No files matched your search
@@ -139,7 +139,7 @@ public class ItemList {
|
||||
@Override
|
||||
public boolean matches(ItemStack item) {
|
||||
for (ItemFilter filter : filters) try {
|
||||
if (filter != null && filter.matches(item)) return true;
|
||||
if (filter.matches(item)) return true;
|
||||
} catch (Exception e) {
|
||||
NEIClientConfig.logger.error("Exception filtering " + item + " with " + filter, e);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import static codechicken.lib.gui.GuiDraw.drawString;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -182,105 +185,312 @@ public class NEIClientConfig {
|
||||
tag.getTag("inventory.search.quoteDropItemName").setComment("Quote Drop Item Name").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.search.quoteDropItemName", true));
|
||||
|
||||
tag.getTag("inventory.search.modNameSearchMode").setComment("Search mode for Mod Names").getIntValue(1);
|
||||
API.addOption(new OptionCycled("inventory.search.modNameSearchMode", 3, true));
|
||||
|
||||
String preModName = tag.getTag("inventory.search.modNameSearchPrefix").setComment(
|
||||
"Search prefix for Mod Names (leave empty to always search for Mod Names, enter anything longer than one character to disable)")
|
||||
.getValue("@");
|
||||
if (preModName.length() != 1) {
|
||||
logger.warn("Search prefix inventory.search.modNameSearchPrefix has invalid length! Resetting to default.");
|
||||
preModName = "@";
|
||||
tag.getTag("inventory.search.modNameSearchPrefix").setValue(preModName);
|
||||
}
|
||||
API.addOption(new OptionTextField("inventory.search.modNameSearchPrefix") {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawString(getPrefix(), 10, 6, -1);
|
||||
textField.w = 60;
|
||||
textField.x = slot.slotWidth() - textField.w;
|
||||
textField.draw(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String s) {
|
||||
if (s.length() == 1) {
|
||||
return !Arrays.asList(
|
||||
getTag("inventory.search.tooltipSearchPrefix").getValue(),
|
||||
getTag("inventory.search.identifierSearchPrefix").getValue(),
|
||||
getTag("inventory.search.oreDictSearchPrefix").getValue(),
|
||||
getTag("inventory.search.subsetsSearchPrefix").getValue()).contains(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextField createTextField() {
|
||||
return new DefaultOptionTextField() {
|
||||
|
||||
@Override
|
||||
public int getTextColour() {
|
||||
return isValidValue(text()) ? 0xFF55FF : 0xAA0000;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.tooltipSearchMode").setComment("Search mode for Tooltips").getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.tooltipSearchMode", 3, true));
|
||||
|
||||
String preTooltip = tag.getTag("inventory.search.tooltipSearchPrefix").setComment(
|
||||
"Search mode for Tooltips (leave empty to always search for Tooltips, enter anything longer than one character to disable)")
|
||||
.getValue("");
|
||||
if (preTooltip.length() == 1 && preTooltip.equals(preModName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.tooltipSearchPrefix conflicts with inventory.search.modNameSearchPrefix ({})! Resetting to default.",
|
||||
preTooltip);
|
||||
preTooltip = "";
|
||||
tag.getTag("inventory.search.tooltipSearchPrefix").setValue(preTooltip);
|
||||
.getValue("#");
|
||||
if (preTooltip.length() == 1) {
|
||||
if (preTooltip.equals(preModName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.tooltipSearchPrefix conflicts with inventory.search.modNameSearchPrefix ({})! Resetting to default.",
|
||||
preTooltip);
|
||||
preTooltip = "#";
|
||||
tag.getTag("inventory.search.tooltipSearchPrefix").setValue(preTooltip);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Search prefix inventory.search.tooltipSearchPrefix has invalid length! Resetting to default.");
|
||||
preModName = "#";
|
||||
tag.getTag("inventory.search.tooltipSearchPrefix").setValue(preModName);
|
||||
}
|
||||
API.addOption(new OptionTextField("inventory.search.tooltipSearchPrefix") {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawString(getPrefix(), 10, 6, -1);
|
||||
textField.w = 60;
|
||||
textField.x = slot.slotWidth() - textField.w;
|
||||
textField.draw(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String s) {
|
||||
if (s.length() == 1) {
|
||||
return !Arrays.asList(
|
||||
getTag("inventory.search.modNameSearchPrefix").getValue(),
|
||||
getTag("inventory.search.identifierSearchPrefix").getValue(),
|
||||
getTag("inventory.search.oreDictSearchPrefix").getValue(),
|
||||
getTag("inventory.search.subsetsSearchPrefix").getValue()).contains(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextField createTextField() {
|
||||
return new DefaultOptionTextField() {
|
||||
|
||||
@Override
|
||||
public int getTextColour() {
|
||||
return isValidValue(text()) ? 0xFFFF55 : 0xAA0000;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.identifierSearchMode").setComment("Search mode for identifier (prefix: &)")
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.identifierSearchMode", 3, true));
|
||||
|
||||
String preIdentifier = tag.getTag("inventory.search.identifierSearchPrefix").setComment(
|
||||
"Search mode for identifier (leave empty to always search for identifier, enter anything longer than one character to disable)")
|
||||
.getValue("");
|
||||
.getValue("&");
|
||||
if (preIdentifier.length() == 1) {
|
||||
if (preIdentifier.equals(preModName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.identifierSearchPrefix conflicts with inventory.search.modNameSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preIdentifier = "";
|
||||
preIdentifier = "&";
|
||||
tag.getTag("inventory.search.identifierSearchPrefix").setValue(preIdentifier);
|
||||
} else if (preIdentifier.equals(preTooltip)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.identifierSearchPrefix conflicts with inventory.search.tooltipSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preIdentifier = "";
|
||||
preIdentifier = "&";
|
||||
tag.getTag("inventory.search.identifierSearchPrefix").setValue(preIdentifier);
|
||||
}
|
||||
} else {
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.identifierSearchPrefix has invalid length! Resetting to default.");
|
||||
preModName = "&";
|
||||
tag.getTag("inventory.search.identifierSearchPrefix").setValue(preModName);
|
||||
}
|
||||
API.addOption(new OptionTextField("inventory.search.identifierSearchPrefix") {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawString(getPrefix(), 10, 6, -1);
|
||||
textField.w = 60;
|
||||
textField.x = slot.slotWidth() - textField.w;
|
||||
textField.draw(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String s) {
|
||||
if (s.length() == 1) {
|
||||
return !Arrays.asList(
|
||||
getTag("inventory.search.modNameSearchPrefix").getValue(),
|
||||
getTag("inventory.search.tooltipSearchPrefix").getValue(),
|
||||
getTag("inventory.search.oreDictSearchPrefix").getValue(),
|
||||
getTag("inventory.search.subsetsSearchPrefix").getValue()).contains(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextField createTextField() {
|
||||
return new DefaultOptionTextField() {
|
||||
|
||||
@Override
|
||||
public int getTextColour() {
|
||||
return isValidValue(text()) ? 0xFFAA00 : 0xAA0000;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.oreDictSearchMode").setComment("Search mode for Tag Names (prefix: $)")
|
||||
.getIntValue(0);
|
||||
API.addOption(new OptionCycled("inventory.search.oreDictSearchMode", 3, true));
|
||||
|
||||
String preODName = tag.getTag("inventory.search.oreDictSearchPrefix").setComment(
|
||||
"Search mode for Ore Dictionary Tags (leave empty to always search for Ore Dictionary Tags, enter anything longer than one character to disable)")
|
||||
.getValue("");
|
||||
.getValue("$");
|
||||
if (preODName.length() == 1) {
|
||||
if (preODName.equals(preModName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.oreDictSearchPrefix conflicts with inventory.search.modNameSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preODName = "";
|
||||
preODName = "$";
|
||||
tag.getTag("inventory.search.oreDictSearchPrefix").setValue(preODName);
|
||||
} else if (preODName.equals(preTooltip)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.oreDictSearchPrefix conflicts with inventory.search.tooltipSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preODName = "";
|
||||
preODName = "$";
|
||||
tag.getTag("inventory.search.oreDictSearchPrefix").setValue(preODName);
|
||||
} else if (preODName.equals(preIdentifier)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.oreDictSearchPrefix conflicts with inventory.search.identifierSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preODName = "";
|
||||
preODName = "$";
|
||||
tag.getTag("inventory.search.oreDictSearchPrefix").setValue(preODName);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Search prefix inventory.search.oreDictSearchPrefix has invalid length! Resetting to default.");
|
||||
preModName = "$";
|
||||
tag.getTag("inventory.search.oreDictSearchPrefix").setValue(preModName);
|
||||
}
|
||||
API.addOption(new OptionTextField("inventory.search.oreDictSearchPrefix") {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawString(getPrefix(), 10, 6, -1);
|
||||
textField.w = 60;
|
||||
textField.x = slot.slotWidth() - textField.w;
|
||||
textField.draw(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String s) {
|
||||
if (s.length() == 1) {
|
||||
return !Arrays.asList(
|
||||
getTag("inventory.search.modNameSearchPrefix").getValue(),
|
||||
getTag("inventory.search.tooltipSearchPrefix").getValue(),
|
||||
getTag("inventory.search.identifierSearchPrefix").getValue(),
|
||||
getTag("inventory.search.subsetsSearchPrefix").getValue()).contains(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextField createTextField() {
|
||||
return new DefaultOptionTextField() {
|
||||
|
||||
@Override
|
||||
public int getTextColour() {
|
||||
return isValidValue(text()) ? 0x55FFFF : 0xAA0000;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("inventory.search.subsetsSearchMode").setComment("Search mode for Item Subsets (prefix: %)")
|
||||
.getIntValue(2);
|
||||
API.addOption(new OptionCycled("inventory.search.subsetsSearchMode", 3, true));
|
||||
|
||||
String preSubset = tag.getTag("inventory.search.subsetsSearchPrefix").setComment(
|
||||
"Search mode for Item Subsets (leave empty to always search for Item Subsets, enter anything longer than one character to disable)")
|
||||
.getValue("DISABLE");
|
||||
.getValue("%");
|
||||
if (preSubset.length() == 1) {
|
||||
if (preSubset.equals(preModName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.subsetsSearchPrefix conflicts with inventory.search.modNameSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preSubset = "";
|
||||
preSubset = "%";
|
||||
tag.getTag("inventory.search.subsetsSearchPrefix").setValue(preSubset);
|
||||
} else if (preSubset.equals(preTooltip)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.subsetsSearchPrefix conflicts with inventory.search.tooltipSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preSubset = "";
|
||||
preSubset = "%";
|
||||
tag.getTag("inventory.search.subsetsSearchPrefix").setValue(preSubset);
|
||||
} else if (preSubset.equals(preIdentifier)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.subsetsSearchPrefix conflicts with inventory.search.identifierSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preSubset = "";
|
||||
preSubset = "%";
|
||||
tag.getTag("inventory.search.subsetsSearchPrefix").setValue(preSubset);
|
||||
} else if (preSubset.equals(preODName)) {
|
||||
// conflicting prefix char
|
||||
logger.warn(
|
||||
"Search prefix inventory.search.subsetsSearchPrefix conflicts with inventory.search.oreDictSearchPrefix ({})! Resetting to default.",
|
||||
preIdentifier);
|
||||
preSubset = "";
|
||||
preSubset = "%";
|
||||
tag.getTag("inventory.search.subsetsSearchPrefix").setValue(preSubset);
|
||||
}
|
||||
} else {
|
||||
logger.warn("Search prefix inventory.search.subsetsSearchPrefix has invalid length! Resetting to default.");
|
||||
preModName = "%";
|
||||
tag.getTag("inventory.search.subsetsSearchPrefix").setValue(preModName);
|
||||
}
|
||||
API.addOption(new OptionTextField("inventory.search.subsetsSearchPrefix") {
|
||||
|
||||
@Override
|
||||
public void draw(int mousex, int mousey, float frame) {
|
||||
drawString(getPrefix(), 10, 6, -1);
|
||||
textField.w = 60;
|
||||
textField.x = slot.slotWidth() - textField.w;
|
||||
textField.draw(mousex, mousey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(String s) {
|
||||
if (s.length() == 1) {
|
||||
return !Arrays.asList(
|
||||
getTag("inventory.search.modNameSearchPrefix").getValue(),
|
||||
getTag("inventory.search.tooltipSearchPrefix").getValue(),
|
||||
getTag("inventory.search.identifierSearchPrefix").getValue(),
|
||||
getTag("inventory.search.oreDictSearchPrefix").getValue()).contains(s);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TextField createTextField() {
|
||||
return new DefaultOptionTextField() {
|
||||
|
||||
@Override
|
||||
public int getTextColour() {
|
||||
return isValidValue(text()) ? 0xAA00AA : 0xAA0000;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
tag.getTag("inventory.bookmarks.enabled").setComment("Enable/Disable Bookmark Panel").getBooleanValue(true);
|
||||
API.addOption(new OptionToggleButton("inventory.bookmarks.enabled", true));
|
||||
|
||||
@@ -75,10 +75,7 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
@Override
|
||||
public char getPrefix() {
|
||||
String prefix = NEIClientConfig.getStringSetting("inventory.search." + this.name + "SearchPrefix");
|
||||
if (prefix.length() == 1) {
|
||||
return prefix.charAt(0);
|
||||
}
|
||||
return this.defaultPrefix;
|
||||
return prefix.length() == 0 ? this.defaultPrefix : prefix.charAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,8 +85,7 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode
|
||||
.fromString(NEIClientConfig.getStringSetting("inventory.search." + this.name + "SearchPrefix"));
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search." + this.name + "SearchMode"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ public class SearchTokenParser {
|
||||
PREFIX,
|
||||
NEVER;
|
||||
|
||||
public static SearchMode fromString(String value) {
|
||||
return switch (value.length()) {
|
||||
public static SearchMode fromInt(int value) {
|
||||
return switch (value) {
|
||||
case 0 -> ALWAYS;
|
||||
case 1 -> PREFIX;
|
||||
default -> NEVER;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
|
||||
if (slot < sorted.size()) {
|
||||
SubsetTag tag = sorted.get(slot);
|
||||
if (NEIClientUtils.shiftKey()) {
|
||||
codechicken.nei.LayoutManager.searchField.setText("%" + tag.fullname);
|
||||
LayoutManager.searchField.setText("%" + tag.fullname);
|
||||
} else if (button == 0 && count >= 2) {
|
||||
SubsetWidget.showOnly(tag);
|
||||
} else {
|
||||
@@ -94,7 +94,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
|
||||
Rectangle4i r = new Rectangle4i(x, y, w, getSlotHeight(slot));
|
||||
if (slot < sorted.size()) {
|
||||
SubsetTag tag = sorted.get(slot);
|
||||
codechicken.nei.LayoutManager.getLayoutStyle()
|
||||
LayoutManager.getLayoutStyle()
|
||||
.drawSubsetTag(tag.displayName(), x, y, r.w, r.h, tag.state.state, r.contains(mx, my));
|
||||
} else {
|
||||
ItemStack stack = state.items.get(slot - sorted.size());
|
||||
@@ -103,8 +103,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
|
||||
int itemx = w / 2 - 8;
|
||||
int itemy = 1;
|
||||
|
||||
codechicken.nei.LayoutManager.getLayoutStyle()
|
||||
.drawSubsetTag(null, x, y, r.w, r.h, hidden ? 0 : 2, false);
|
||||
LayoutManager.getLayoutStyle().drawSubsetTag(null, x, y, r.w, r.h, hidden ? 0 : 2, false);
|
||||
|
||||
GuiContainerManager.drawItem(x + itemx, y + itemy, stack);
|
||||
if (new Rectangle4i(itemx, itemy, 16, 16).contains(mx, my)) SubsetWidget.hoverStack = stack;
|
||||
@@ -382,10 +381,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
|
||||
|
||||
public char getPrefix() {
|
||||
String prefix = NEIClientConfig.getStringSetting("inventory.search.subsetsSearchPrefix");
|
||||
if (prefix.length() == 1) {
|
||||
return prefix.charAt(0);
|
||||
}
|
||||
return '%';
|
||||
return prefix.length() == 0 ? '%' : prefix.charAt(0);
|
||||
}
|
||||
|
||||
public EnumChatFormatting getHighlightedColor() {
|
||||
@@ -394,7 +390,7 @@ public class SubsetWidget extends Button implements ItemFilterProvider, ItemsLoa
|
||||
|
||||
@Override
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.fromString(NEIClientConfig.getStringSetting("inventory.search.subsetsSearchPrefix"));
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search.subsetsSearchMode"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,30 +11,10 @@ import codechicken.nei.config.GuiOptionList.OptionScrollSlot;
|
||||
|
||||
public class OptionTextField extends Option {
|
||||
|
||||
private TextField textField = new TextField("test") {
|
||||
|
||||
@Override
|
||||
public void onTextChange(String oldText) {
|
||||
if (focused() && isValidValue(text())) if (!defaulting() || !text().equals(getTag().getValue())) // don't
|
||||
// override
|
||||
// global
|
||||
// if text
|
||||
// hasn't
|
||||
// changed
|
||||
getTag().setValue(text());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus(boolean focus) {
|
||||
if (!focus && !isValidValue(text())) setText(renderTag().getValue());
|
||||
|
||||
super.setFocus(focus);
|
||||
}
|
||||
};
|
||||
protected final TextField textField = createTextField();
|
||||
|
||||
public OptionTextField(String name) {
|
||||
super(name);
|
||||
textField.h = 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,4 +72,30 @@ public class OptionTextField extends Option {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user