diff options
author | Cow <cow@volloeko.de> | 2021-04-13 13:19:51 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2021-04-13 13:19:51 +0200 |
commit | 0c8a6a70e065e9176d617ff33a9b23774c1b19db (patch) | |
tree | e9668cfacf61dce49e6e3a1f150fad08c1d6a61e | |
parent | cc2b9c92404ed03661778aaae5477444a146ee9f (diff) | |
download | Cowlection-0c8a6a70e065e9176d617ff33a9b23774c1b19db.tar.gz Cowlection-0c8a6a70e065e9176d617ff33a9b23774c1b19db.tar.bz2 Cowlection-0c8a6a70e065e9176d617ff33a9b23774c1b19db.zip |
Added a search to the config gui
7 files changed, 228 insertions, 75 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index b082f69..2544a64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added Dungeons: Catacombs Master Mode support - `/moo stalk`: Added "Game Master" rank - Added mini-"tutorial" on how to open the config gui (to move the dungeon overlay) +- Added a search to `/moo config` ### Changed - Refined the comma representation of large numbers abbreviated with k, m, b diff --git a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java index f924774..b7edc46 100644 --- a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java +++ b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java @@ -130,7 +130,7 @@ public class MooCommand extends CommandBase { //region sub-commands: miscellaneous else if (args[0].equalsIgnoreCase("config")) { main.getConfig().theyOpenedTheConfigGui(); - displayGuiScreen(new MooConfigGui()); + displayGuiScreen(new MooConfigGui(buildString(args, 1))); } else if (args[0].equalsIgnoreCase("search")) { displayGuiScreen(new GuiSearch(main.getConfigDirectory(), CommandBase.buildString(args, 1))); } else if (args[0].equalsIgnoreCase("guiscale")) { @@ -1054,7 +1054,7 @@ public class MooCommand extends CommandBase { private void sendCommandUsage(ICommandSender sender) { IChatComponent usage = new MooChatComponent("➜ " + Cowlection.MODNAME + " commands:").gold().bold() .appendSibling(createCmdHelpEntry("config", "Open mod's configuration")) - .appendSibling(new MooChatComponent("\n").reset().white().appendText(EnumChatFormatting.DARK_GREEN + " ❢" + EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.ITALIC + " To move the Dungeons overlay: " + EnumChatFormatting.WHITE + "/" + getCommandName() + " config " + EnumChatFormatting.GRAY + "➡ " + EnumChatFormatting.WHITE + "SB Dungeons " + EnumChatFormatting.GRAY + "➡ " + EnumChatFormatting.WHITE + "Performance Overlay")) + .appendSibling(new MooChatComponent("\n").reset().white().appendText(EnumChatFormatting.DARK_GREEN + " ❢" + EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.ITALIC + " To move the Dungeons overlay: " + EnumChatFormatting.WHITE + "/" + getCommandName() + " config " + EnumChatFormatting.GRAY + "➡ " + EnumChatFormatting.WHITE + "SB Dungeons " + EnumChatFormatting.GRAY + "➡ " + EnumChatFormatting.WHITE + "Dungeon Performance Overlay")) .appendSibling(new MooChatComponent("\n").reset().gray().appendText(EnumChatFormatting.DARK_GREEN + " ❢" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + " Commands marked with §d§l⚷" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + " require a valid API key")) .appendSibling(createCmdHelpSection(1, "Best friends, friends & other players")) .appendSibling(createCmdHelpEntry("stalk", "Get info of player's status §d§l⚷")) diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java index 22db2c2..fba238b 100644 --- a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java +++ b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java @@ -488,8 +488,8 @@ public class MooConfig { Property propDungItemToolTipToggleKeyBinding = subCat.addConfigEntry(cfg.get(configCat.getConfigName(), "dungItemToolTipToggleKeyBinding", Keyboard.KEY_LSHIFT, "Key to toggle dungeon item tooltip")); - // Sub-Category: Performance Overlay - subCat = configCat.addSubCategory("Performance Overlay"); + // Sub-Category: Dungeon Performance Overlay + subCat = configCat.addSubCategory("Dungeon Performance Overlay"); subCat.addExplanations(EnumChatFormatting.UNDERLINE + "Keeps track of:", " ‣ skill score " + EnumChatFormatting.GRAY + "(reduced by deaths and failed puzzles)", " ‣ speed score " + EnumChatFormatting.GRAY + "(-2.2 points/minute when over 20 minutes)", diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfigCategory.java b/src/main/java/de/cowtipper/cowlection/config/MooConfigCategory.java index ea2eb37..f4cd469 100644 --- a/src/main/java/de/cowtipper/cowlection/config/MooConfigCategory.java +++ b/src/main/java/de/cowtipper/cowlection/config/MooConfigCategory.java @@ -114,6 +114,14 @@ public class MooConfigCategory { return guiSliderExtras.get(propertyKey); } + public MooConfigPreview getPreview(Property property) { + int propId = configEntries.indexOf(property); + if (propId > -1) { + return this.previews.get(propId + 1); + } + return null; + } + public Map<Integer, MooConfigPreview> getPreviews() { return previews; } diff --git a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java index 27e6914..3b18089 100644 --- a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java +++ b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigCategoryScrolling.java @@ -48,15 +48,25 @@ public class MooConfigCategoryScrolling extends GuiListExtended { */ private final NavigableMap<Integer, MooConfigPreview> listEntriesPreviews; - public MooConfigCategoryScrolling(MooConfigGui parent, Minecraft mc, MooConfigCategory currentConfigCategory, int marginLeft) { + private MooConfigCategoryScrolling(MooConfigGui parent, Minecraft mc, int marginLeft) { super(mc, parent.width - marginLeft, parent.height, 32, parent.height - 5, 20); this.parent = parent; setSlotXBoundsFromLeft(marginLeft); this.mc = mc; + listEntriesPreviews = new TreeMap<>(); explanations = new HashMap<>(); + listEntries = new ArrayList<>(); + } + + public MooConfigCategoryScrolling(MooConfigGui parent, Minecraft mc, String initialSearchQuery, int marginLeft) { + this(parent, mc, marginLeft); + showFilteredConfigEntries(initialSearchQuery); + } + + public MooConfigCategoryScrolling(MooConfigGui parent, Minecraft mc, MooConfigCategory currentConfigCategory, int marginLeft) { + this(parent, mc, marginLeft); - this.listEntries = new ArrayList<>(); for (MooConfigCategory.SubCategory subCategory : currentConfigCategory.getSubCategories()) { int subCategoryStartIndex = this.listEntries.size(); this.listEntries.add(new MooConfigCategoryScrolling.CategoryEntry(subCategory.getDisplayName(), !subCategory.getExplanations().isEmpty())); @@ -93,70 +103,137 @@ public class MooConfigCategoryScrolling extends GuiListExtended { // add config elements for (Property configEntry : subCategory.getConfigEntries()) { - int labelWidth = mc.fontRendererObj.getStringWidth(I18n.format(configEntry.getLanguageKey())); + addConfigEntryToGui(subCategory, configEntry); + } + } + } - if (labelWidth > this.maxListLabelWidth) { - this.maxListLabelWidth = labelWidth; + private void addConfigEntryToGui(MooConfigCategory.SubCategory subCategory, Property configEntry) { + int labelWidth = mc.fontRendererObj.getStringWidth(I18n.format(configEntry.getLanguageKey())); + + if (labelWidth > this.maxListLabelWidth) { + this.maxListLabelWidth = labelWidth; + } + + Property.Type type = configEntry.getType(); + if (configEntry.isList() && type == Property.Type.STRING && configEntry.equals(Cowlection.getInstance().getConfig().getTabCompletableNamesCommandsProperty())) { + this.listEntries.add(new GuiSwitchEntry("tabCompletableNamesCommands", "➡ modify", () -> + mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, + Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getTabCompletableNamesCommandsProperty())), + Cowlection.MODID, "cowlectionTabCompletableCommands", false, false, + EnumChatFormatting.GOLD + "Press 2x Done to save changes. " + EnumChatFormatting.RED + "Requires a game restart to take effect!")))); + return; + } else if (type == Property.Type.BOOLEAN) { + this.listEntries.add(new BooleanConfigEntry(configEntry)); + return; + } else if (type == Property.Type.INTEGER) { + if (configEntry.getLanguageKey() != null && configEntry.getLanguageKey().endsWith("KeyBinding")) { + // special case: key binding + this.listEntries.add(new KeyBindingConfigEntry(configEntry)); + return; + } else if (configEntry.isIntValue() && configEntry.getMinValue() != null && configEntry.getMaxValue() != null) { + // generic special case: int value with min & max value + this.listEntries.add(new NumberSliderConfigEntry(configEntry, + subCategory.getGuiSliderExtra(configEntry.getLanguageKey()))); + return; + } + } else if (type == Property.Type.STRING) { + if (configEntry.getLanguageKey().equals(Cowlection.MODID + ".config.isMooValid")) { + // special case: moo! + this.listEntries.add(new BooleanConfigEntry(configEntry)); + return; + } else if (configEntry.equals(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())) { + this.listEntries.add(new GuiSwitchEntry("mooCmdAlias", "➡ modify", () -> + mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, + Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())), + Cowlection.MODID, "cowlectionMooCmdAlias", false, false, + EnumChatFormatting.GOLD + "Press Done to save changes. " + EnumChatFormatting.RED + "Requires a game restart to take effect!")))); + return; + } else if (configEntry.equals(Cowlection.getInstance().getConfig().getTooltipAuctionHousePriceEachEnchantmentsProperty())) { + this.listEntries.add(new GuiSwitchEntry("tooltipAuctionHousePriceEachEnchantments", "➡ modify", () -> + mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, + Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getTooltipAuctionHousePriceEachEnchantmentsProperty())), + Cowlection.MODID, "cowlectionTooltipAuctionHousePriceEachEnchantments", false, false, + EnumChatFormatting.GOLD + "Press 2x Done to save changes. " + EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.BOLD + "Ultimate" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " and " + EnumChatFormatting.YELLOW + "Turbo-Crop" + EnumChatFormatting.RED + " enchants are always included!")))); + return; + } else if (configEntry.getValidValues() != null && configEntry.getValidValues().length > 0) { + if ("dungOverlayTextBorder".equals(configEntry.getName())) { + // special case: Dungeon Performance Overlay: show preview on button click + this.listEntries.add(new DungCycleConfigEntry(configEntry)); + } else { + this.listEntries.add(new CycleConfigEntry(configEntry)); } + return; + } + } + // type == Property.Type.DOUBLE + // type == Property.Type.COLOR // => ChatColorEntry#drawEntry + // type == Property.Type.MOD_ID + // + some other cases + throw new NotImplementedException("Unsupported config entry of type " + configEntry.getType() + (configEntry.isList() ? "-list" : "") + " (" + configEntry.getName() + ")"); + } - Property.Type type = configEntry.getType(); - if (configEntry.isList() && type == Property.Type.STRING && configEntry.equals(Cowlection.getInstance().getConfig().getTabCompletableNamesCommandsProperty())) { - this.listEntries.add(new GuiSwitchEntry("tabCompletableNamesCommands", "➡ modify", () -> - mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, - Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getTabCompletableNamesCommandsProperty())), - Cowlection.MODID, "cowlectionTabCompletableCommands", false, false, - EnumChatFormatting.GOLD + "Press 2x Done to save changes. " + EnumChatFormatting.RED + "Requires a game restart to take effect!")))); - continue; - } else if (type == Property.Type.BOOLEAN) { - this.listEntries.add(new BooleanConfigEntry(configEntry)); - continue; - } else if (type == Property.Type.INTEGER) { - if (configEntry.getLanguageKey() != null && configEntry.getLanguageKey().endsWith("KeyBinding")) { - // special case: key binding - this.listEntries.add(new KeyBindingConfigEntry(configEntry)); - continue; - } else if (configEntry.isIntValue() && configEntry.getMinValue() != null && configEntry.getMaxValue() != null) { - // generic special case: int value with min & max value - this.listEntries.add(new NumberSliderConfigEntry(configEntry, - subCategory.getGuiSliderExtra(configEntry.getLanguageKey()))); - continue; - } - } else if (type == Property.Type.STRING) { - if (configEntry.getLanguageKey().equals(Cowlection.MODID + ".config.isMooValid")) { - // special case: moo! - this.listEntries.add(new BooleanConfigEntry(configEntry)); - continue; - } else if (configEntry.equals(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())) { - this.listEntries.add(new GuiSwitchEntry("mooCmdAlias", "➡ modify", () -> - mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, - Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getMooCmdAliasProperty())), - Cowlection.MODID, "cowlectionMooCmdAlias", false, false, - EnumChatFormatting.GOLD + "Press Done to save changes. " + EnumChatFormatting.RED + "Requires a game restart to take effect!")))); - continue; - } else if (configEntry.equals(Cowlection.getInstance().getConfig().getTooltipAuctionHousePriceEachEnchantmentsProperty())) { - this.listEntries.add(new GuiSwitchEntry("tooltipAuctionHousePriceEachEnchantments", "➡ modify", () -> - mc.displayGuiScreen(new GuiConfig(MooConfigCategoryScrolling.this.parent, - Lists.newArrayList(new ConfigElement(Cowlection.getInstance().getConfig().getTooltipAuctionHousePriceEachEnchantmentsProperty())), - Cowlection.MODID, "cowlectionTooltipAuctionHousePriceEachEnchantments", false, false, - EnumChatFormatting.GOLD + "Press 2x Done to save changes. " + EnumChatFormatting.LIGHT_PURPLE + EnumChatFormatting.BOLD + "Ultimate" + EnumChatFormatting.RESET + EnumChatFormatting.RED + " and " + EnumChatFormatting.YELLOW + "Turbo-Crop" + EnumChatFormatting.RED + " enchants are always included!")))); - continue; - } else if (configEntry.getValidValues() != null && configEntry.getValidValues().length > 0) { - if ("dungOverlayTextBorder".equals(configEntry.getName())) { - // special case: Dung Performance Overlay: show preview on button click - this.listEntries.add(new DungCycleConfigEntry(configEntry)); + public void showFilteredConfigEntries(String searchQuery) { + listEntriesPreviews.clear(); + explanations.clear(); + listEntries.clear(); + maxListLabelWidth = 0; + + MooConfigCategory lastCategory = null; + MooConfigCategory.SubCategory lastSubCategory = null; + boolean hasLogSearchBeenAdded = false; + int entryNr = 0; + for (MooConfigCategory configCategory : MooConfig.getConfigCategories()) { + for (MooConfigCategory.SubCategory subCategory : configCategory.getSubCategories()) { + // add config elements + for (Property configEntry : subCategory.getConfigEntries()) { + // search for search term in config property sub-category name, display name, tooltip + if (StringUtils.containsIgnoreCase(subCategory.getDisplayName(), searchQuery) + || StringUtils.containsIgnoreCase(I18n.format(configEntry.getLanguageKey()), searchQuery) + || StringUtils.containsIgnoreCase(I18n.format(configEntry.getLanguageKey() + ".tooltip"), searchQuery)) { + if (configCategory != lastCategory) { + this.listEntries.add(new MooConfigCategoryScrolling.CategoryEntry("" + EnumChatFormatting.RESET + EnumChatFormatting.DARK_GRAY + "Config category: " + EnumChatFormatting.DARK_RED + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE + configCategory.getDisplayName(), false)); + lastCategory = configCategory; + ++entryNr; + } + if (subCategory != lastSubCategory) { + this.listEntries.add(new MooConfigCategoryScrolling.CategoryEntry(subCategory.getDisplayName(), !subCategory.getExplanations().isEmpty())); + // add explanations + this.explanations.put(entryNr, subCategory.getExplanations()); + + // add preview spacer for sub category + this.listEntriesPreviews.put(entryNr, null); + + lastSubCategory = subCategory; + ++entryNr; + } + // add control buttons to navigate to other guis + if ("Other settings".equals(subCategory.getDisplayName())) { + if (!hasLogSearchBeenAdded && Cowlection.getInstance().getConfig().getLogSearchProperties().contains(configEntry)) { + // don't add properties to main config gui, use this instead: + this.listEntries.add(new GuiSwitchEntry("gotoLogSearchConfig", "Log Search", () -> mc.displayGuiScreen(new GuiSearch(Cowlection.getInstance().getConfigDirectory(), "")))); + hasLogSearchBeenAdded = true; + } else if (hasLogSearchBeenAdded) { + // already added the replacement-entry, thus don't increase entry counter + --entryNr; + } } else { - this.listEntries.add(new CycleConfigEntry(configEntry)); + addConfigEntryToGui(subCategory, configEntry); + // add preview for this entry + MooConfigPreview preview = subCategory.getPreview(configEntry); + if (preview != null) { + this.listEntriesPreviews.put(entryNr, preview); + } } - continue; + ++entryNr; } } - // type == Property.Type.DOUBLE - // type == Property.Type.COLOR // => ChatColorEntry#drawEntry - // type == Property.Type.MOD_ID - // + some other cases - throw new NotImplementedException("Unsupported config entry of type " + configEntry.getType() + " (" + configEntry.getName() + ")"); } } + if (listEntries.isEmpty()) { + // no matching config entries found + this.listEntries.add(new ExplanationsEntry("" + EnumChatFormatting.RESET + EnumChatFormatting.RED + EnumChatFormatting.ITALIC + "no matching config entries found for '" + EnumChatFormatting.GOLD + searchQuery + EnumChatFormatting.RED + EnumChatFormatting.ITALIC + "'")); + } } protected int getSize() { @@ -385,7 +462,7 @@ public class MooConfigCategoryScrolling extends GuiListExtended { MooConfigCategoryScrolling.this.mc.fontRendererObj.drawString(EnumChatFormatting.DARK_GREEN + "❢", x + 2, yTextPos, 0xffffff); } // draw sub category label - int labelX = (int) (x + MooConfigCategoryScrolling.this.maxListLabelWidth * 0.75 - this.labelWidth / 2); + int labelX = Math.max((int) (x + MooConfigCategoryScrolling.this.maxListLabelWidth * 0.75 - this.labelWidth / 2), x + (hasExplanations ? 10 : 0)); MooConfigCategoryScrolling.this.mc.fontRendererObj.drawString(this.labelText, labelX, yTextPos, 0xffffff); } diff --git a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigGui.java b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigGui.java index e9af52c..aff5315 100644 --- a/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigGui.java +++ b/src/main/java/de/cowtipper/cowlection/config/gui/MooConfigGui.java @@ -5,11 +5,15 @@ import de.cowtipper.cowlection.config.MooConfig; import de.cowtipper.cowlection.config.MooConfigCategory; import de.cowtipper.cowlection.listener.PlayerListener; import de.cowtipper.cowlection.util.GuiHelper; +import net.minecraft.client.audio.SoundEventAccessorComposite; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StringUtils; import org.lwjgl.input.Keyboard; import java.io.IOException; @@ -25,6 +29,7 @@ import java.util.Arrays; */ public class MooConfigGui extends GuiScreen { public static long showDungeonPerformanceOverlayUntil; + private static final String searchPlaceholder = "" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "Search config"; public int menuWidth; private MooConfigMenuList menu; private int selectedMenuIndex = -1; @@ -35,9 +40,12 @@ public class MooConfigGui extends GuiScreen { */ private MooConfigCategoryScrolling currentConfigCategoryGui; private GuiButton btnClose; + private GuiTextField fieldSearchQuery; + private String searchQuery; - public MooConfigGui() { + public MooConfigGui(String searchQuery) { isOutsideOfSkyBlock = PlayerListener.registerSkyBlockListeners(); + this.searchQuery = searchQuery; } /** @@ -59,10 +67,21 @@ public class MooConfigGui extends GuiScreen { this.menu = new MooConfigMenuList(this, menuWidth); this.buttonList.add(this.btnClose = new GuiButton(6, this.width - 25, 3, 22, 20, EnumChatFormatting.RED + "X")); - - if (selectedMenuIndex < 0) { - // switch to 1st category if none is selected - selectConfigCategory(0); + this.fieldSearchQuery = new GuiTextField(42, this.fontRendererObj, 5, 11, 100, 15); + this.fieldSearchQuery.setMaxStringLength(42); + this.fieldSearchQuery.setText(searchPlaceholder); + if (selectedMenuIndex == -1) { + // no category selected yet: this isn't a resize + if (!StringUtils.isNullOrEmpty(searchQuery)) { + this.fieldSearchQuery.setText(searchQuery); + // switch to search + searchConfigEntries(); + } else { + // switch to 1st category + selectConfigCategory(0); + } + } else if (selectedMenuIndex == -42) { + this.fieldSearchQuery.setText(searchQuery); } } @@ -93,6 +112,15 @@ public class MooConfigGui extends GuiScreen { protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { if (mouseButton != 0 || (currentConfigCategoryGui != null && !this.currentConfigCategoryGui.mouseClicked(mouseX, mouseY, mouseButton))) { super.mouseClicked(mouseX, mouseY, mouseButton); + fieldSearchQuery.mouseClicked(mouseX, mouseY, mouseButton); + if (fieldSearchQuery.isFocused()) { + if (mouseButton == /* right click */ 1 + || (mouseButton == /* left click */ 0 && searchPlaceholder.equals(fieldSearchQuery.getText()))) { + // clear search query + fieldSearchQuery.setText(""); + searchConfigEntries(); + } + } } } @@ -114,7 +142,28 @@ public class MooConfigGui extends GuiScreen { if (keyCode == Keyboard.KEY_ESCAPE && (currentConfigCategoryGui == null || !currentConfigCategoryGui.isModifyingKeyBind())) { super.keyTyped(typedChar, keyCode); } else if (this.currentConfigCategoryGui != null) { - this.currentConfigCategoryGui.keyTyped(typedChar, keyCode); + if (this.fieldSearchQuery.isFocused() && this.fieldSearchQuery.textboxKeyTyped(typedChar, keyCode)) { + String queryText = fieldSearchQuery.getText(); + if (queryText.length() >= 3) { + String soundName = "mob." + queryText + ".say"; + SoundEventAccessorComposite sound = mc.getSoundHandler().getSound(new ResourceLocation(soundName)); + if (sound != null) { + mc.thePlayer.playSound(soundName, 0.5f, 1); + } + } + searchConfigEntries(); + } else { + this.currentConfigCategoryGui.keyTyped(typedChar, keyCode); + } + } + } + + private void searchConfigEntries() { + searchQuery = this.fieldSearchQuery.getText(); + // display search page if not already displayed + if (!selectConfigCategory(-42)) { + // was already searching before, update search results + this.currentConfigCategoryGui.showFilteredConfigEntries(searchQuery); } } @@ -127,7 +176,7 @@ public class MooConfigGui extends GuiScreen { this.menu.drawScreen(mouseX, mouseY, partialTicks); } - String guiTitle = "" + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE + Cowlection.MODNAME + " config" + (currentConfigCategory != null ? ":" + EnumChatFormatting.RESET + " " + currentConfigCategory.getDisplayName() : ""); + String guiTitle = "" + EnumChatFormatting.BOLD + EnumChatFormatting.UNDERLINE + Cowlection.MODNAME + " config:" + EnumChatFormatting.RESET + " " + (currentConfigCategory != null ? currentConfigCategory.getDisplayName() : "Search"); int guiTitleX = ((menu.getRight() + this.width) / 2) - this.fontRendererObj.getStringWidth(guiTitle) / 2; this.drawCenteredString(this.fontRendererObj, guiTitle, guiTitleX, 16, 0xFFFFFF); super.drawScreen(mouseX, mouseY, partialTicks); @@ -138,6 +187,12 @@ public class MooConfigGui extends GuiScreen { if (btnClose.isMouseOver()) { GuiHelper.drawHoveringText(Arrays.asList(EnumChatFormatting.RED + "Save & close settings", "" + EnumChatFormatting.GRAY + EnumChatFormatting.ITALIC + "Hint:" + EnumChatFormatting.RESET + " alternatively press ESC"), mouseX, mouseY, width, height, 300); } + fieldSearchQuery.drawTextBox(); + } + + @Override + public void updateScreen() { + fieldSearchQuery.updateCursorCounter(); } @Override @@ -152,15 +207,24 @@ public class MooConfigGui extends GuiScreen { /** * Select a config category via the menu */ - public void selectConfigCategory(int index) { + public boolean selectConfigCategory(int index) { if (index == this.selectedMenuIndex) { - return; + return false; } this.selectedMenuIndex = index; - this.currentConfigCategory = (index >= 0 && index <= MooConfig.getConfigCategories().size()) ? MooConfig.getConfigCategories().get(selectedMenuIndex) : null; + if (index >= 0 && index <= MooConfig.getConfigCategories().size()) { + this.currentConfigCategory = MooConfig.getConfigCategories().get(selectedMenuIndex); + // reset search to placeholder + this.fieldSearchQuery.setText(searchPlaceholder); + this.searchQuery = ""; + } else { + // show search results + this.currentConfigCategory = null; + } switchDisplayedConfigCategory(); Cowlection.getInstance().getConfig().syncFromGui(); + return true; } /** @@ -172,9 +236,12 @@ public class MooConfigGui extends GuiScreen { public void switchDisplayedConfigCategory() { if (currentConfigCategory == null) { - return; + // display search + currentConfigCategoryGui = new MooConfigCategoryScrolling(this, mc, searchQuery, menu.getRight() + 3); + } else { + // display one category + currentConfigCategoryGui = new MooConfigCategoryScrolling(this, mc, currentConfigCategory, menu.getRight() + 3); } - currentConfigCategoryGui = new MooConfigCategoryScrolling(this, mc, currentConfigCategory, menu.getRight() + 3); } @Override diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java index 69c794a..5e7036e 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java @@ -645,7 +645,7 @@ public class DungeonsListener { if (!MooConfig.hasOpenedConfigGui) { dungeonPerformanceEntries.add(EnumChatFormatting.RED + "Want to move me? " + EnumChatFormatting.LIGHT_PURPLE + "/moo config " + EnumChatFormatting.DARK_GRAY + "➡ " + EnumChatFormatting.WHITE + "SB Dungeons " - + EnumChatFormatting.DARK_GRAY + "➡ " + EnumChatFormatting.WHITE + "Performance Overlay"); + + EnumChatFormatting.DARK_GRAY + "➡ " + EnumChatFormatting.WHITE + "Dungeon Performance Overlay"); } FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; |