diff --git a/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexicon.java b/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexicon.java index 7a0606d2e..ce9806114 100644 --- a/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexicon.java +++ b/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexicon.java @@ -250,9 +250,13 @@ public class GuiLexicon extends GuiScreen { } } + boolean closeScreenOnInvKey() { + return true; + } + @Override protected void keyTyped(char par1, int par2) { - if(mc.gameSettings.keyBindInventory.getKeyCode() == par2) { + if(closeScreenOnInvKey() && mc.gameSettings.keyBindInventory.getKeyCode() == par2) { mc.displayGuiScreen(null); mc.setIngameFocus(); } diff --git a/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexiconIndex.java b/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexiconIndex.java index dc2a5a6d5..e6f8c07af 100644 --- a/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexiconIndex.java +++ b/MODSRC/vazkii/botania/client/gui/lexicon/GuiLexiconIndex.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.List; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiTextField; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; @@ -38,7 +39,8 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { GuiButton leftButton, rightButton, backButton; GuiLexicon parent; - + GuiTextField searchField; + List entriesToDisplay = new ArrayList(); public GuiLexiconIndex(LexiconCategory category) { @@ -63,17 +65,29 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { buttonList.add(backButton = new GuiButtonBack(12, left + guiWidth / 2 - 8, top + guiHeight + 2)); buttonList.add(leftButton = new GuiButtonPage(13, left, top + guiHeight - 10, false)); buttonList.add(rightButton = new GuiButtonPage(14, left + guiWidth - 18, top + guiHeight - 10, true)); - + + searchField = new GuiTextField(fontRendererObj, left + guiWidth / 2 + 28, top + guiHeight + 6, 200, 10); + searchField.setCanLoseFocus(false); + searchField.setFocused(true); + searchField.setEnableBackgroundDrawing(false); + + updateAll(); + } + + void updateAll() { + buildEntries(); + updatePageButtons(); + populateIndex(); + } + + void buildEntries() { entriesToDisplay.clear(); ILexicon lex = (ILexicon) stackUsed.getItem(); for(LexiconEntry entry : category == null ? BotaniaAPI.getAllEntries() : category.entries) { - if(lex.isKnowledgeUnlocked(stackUsed, entry.getKnowledgeType())) + if(lex.isKnowledgeUnlocked(stackUsed, entry.getKnowledgeType()) && StatCollector.translateToLocal(entry.getUnlocalizedName()).toLowerCase().contains(searchField.getText().toLowerCase().trim())) entriesToDisplay.add(entry); } Collections.sort(entriesToDisplay); - - updatePageButtons(); - populateIndex(); } @Override @@ -86,6 +100,18 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { else button.displayString = ""; } } + + @Override + public void drawScreen(int par1, int par2, float par3) { + super.drawScreen(par1, par2, par3); + + if(!searchField.getText().isEmpty()) { + mc.renderEngine.bindTexture(texture); + drawTexturedModalRect(searchField.xPosition - 13, searchField.yPosition - 3, 86, 180, 12, 12); + + searchField.drawTextBox(); + } + } @Override protected void actionPerformed(GuiButton par1GuiButton) { @@ -111,14 +137,18 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { break; default : int index = par1GuiButton.id + page * 12; - if(index >= entriesToDisplay.size()) - return; - - LexiconEntry entry = entriesToDisplay.get(index); - mc.displayGuiScreen(new GuiLexiconEntry(entry, this)); - ClientTickHandler.notifyPageChange(); + openEntry(index); } } + + void openEntry(int index) { + if(index >= entriesToDisplay.size()) + return; + + LexiconEntry entry = entriesToDisplay.get(index); + mc.displayGuiScreen(new GuiLexiconEntry(entry, this)); + ClientTickHandler.notifyPageChange(); + } public void updatePageButtons() { leftButton.enabled = page != 0; @@ -151,6 +181,7 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { protected void mouseClicked(int par1, int par2, int par3) { super.mouseClicked(par1, par2, par3); + searchField.mouseClicked(par1, par2, par3); fx = par1; if(par3 == 1) back(); @@ -169,6 +200,11 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { else if(w > 0) prevPage(); } + + @Override + boolean closeScreenOnInvKey() { + return false; + } @Override protected void keyTyped(char par1, int par2) { @@ -176,13 +212,19 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented { prevPage(); else if(par2 == 205 || par2 == 208 || par2 == 209) // Right, Down Page Down nextPage(); - else if(par2 == 14) // Backspace + else if(par2 == 14 && searchField.getText().isEmpty()) // Backspace back(); else if(par2 == 199) { // Home mc.displayGuiScreen(new GuiLexicon()); ClientTickHandler.notifyPageChange(); - } - + } else if(par2 == 28 && entriesToDisplay.size() == 1) // Enter + openEntry(0); + + String search = searchField.getText(); + searchField.textboxKeyTyped(par1, par2); + if(!searchField.getText().equalsIgnoreCase(search)) + updateAll(); + super.keyTyped(par1, par2); } diff --git a/resources/assets/botania/textures/gui/lexicon.png b/resources/assets/botania/textures/gui/lexicon.png index 4cb1a5356..4787609fc 100644 Binary files a/resources/assets/botania/textures/gui/lexicon.png and b/resources/assets/botania/textures/gui/lexicon.png differ