diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java index 9c1dcfdc0..875e0bd52 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java @@ -8,10 +8,7 @@ import net.minecraft.client.audio.SoundRegistry; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.gui.util.GuiCustomScroll; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.ICustomScrollListener; -import noppes.npcs.client.gui.util.SubGuiInterface; +import noppes.npcs.client.gui.util.*; import java.util.ArrayList; import java.util.HashMap; @@ -21,11 +18,14 @@ import java.util.Set; public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener{ private GuiCustomScroll scrollCategories; - private GuiCustomScroll scrollQuests; + private GuiCustomScroll scrollSounds; private String selectedDomain; public ResourceLocation selectedResource; + private String catSearch = ""; + private String soundSearch = ""; + private HashMap> domains = new HashMap>(); public GuiSoundSelection(String sound){ @@ -58,13 +58,13 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL @Override public void initGui(){ super.initGui(); - this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); - this.addButton(new GuiNpcButton(1, guiLeft + 160, guiTop + 212, 70, 20, "gui.play")); + this.addButton(new GuiNpcButton(2, guiLeft + xSize - 45, guiTop + ySize - 35, 40, 20, "gui.done")); + this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + ySize - 35, 70, 20, "gui.play")); getButton(1).enabled = selectedResource != null; if(scrollCategories == null){ - scrollCategories = new GuiCustomScroll(this,0); - scrollCategories.setSize(90, 200); + scrollCategories = new GuiCustomScroll(this,0, 0); + scrollCategories.setSize(90, 163); } scrollCategories.setList(Lists.newArrayList(domains.keySet())); if(selectedDomain != null) { @@ -72,23 +72,25 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL } scrollCategories.guiLeft = guiLeft + 4; - scrollCategories.guiTop = guiTop + 14; + scrollCategories.guiTop = guiTop + 4; this.addScroll(scrollCategories); + addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 4, guiTop + 169, 90, 20, catSearch)); - if(scrollQuests == null){ - scrollQuests = new GuiCustomScroll(this,1); - scrollQuests.setSize(250, 200); + if(scrollSounds == null){ + scrollSounds = new GuiCustomScroll(this,1, 0); + scrollSounds.setSize(265, 163); } if(selectedDomain != null) { - scrollQuests.setList(domains.get(selectedDomain)); + scrollSounds.setList(domains.get(selectedDomain)); } if(selectedResource != null) { - scrollQuests.setSelected(selectedResource.getResourcePath()); + scrollSounds.setSelected(selectedResource.getResourcePath()); } - scrollQuests.guiLeft = guiLeft + 95; - scrollQuests.guiTop = guiTop + 14; - this.addScroll(scrollQuests); + scrollSounds.guiLeft = guiLeft + 95; + scrollSounds.guiTop = guiTop + 4; + this.addScroll(scrollSounds); + addTextField(new GuiNpcTextField(66, this, fontRendererObj, guiLeft + 95, guiTop + 169, 265, 20, soundSearch)); } @Override @@ -116,11 +118,64 @@ public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollL if(guiCustomScroll.id == 0){ selectedDomain = guiCustomScroll.getSelected(); selectedResource = null; - scrollQuests.selected = -1; + scrollSounds.selected = -1; + scrollSounds.resetScroll(); + getTextField(66).setText(""); + soundSearch = ""; } if(guiCustomScroll.id == 1){ selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected()); } initGui(); } + + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(55) != null){ + if(getTextField(55).isFocused()){ + if(catSearch.equals(getTextField(55).getText())) + return; + catSearch = getTextField(55).getText().toLowerCase(); + scrollCategories.setList(getCatSearch()); + } + } + if(getTextField(66) != null){ + if(getTextField(66).isFocused()){ + if(soundSearch.equals(getTextField(66).getText())) + return; + soundSearch = getTextField(66).getText().toLowerCase(); + scrollSounds.setList(getSoundSearch()); + } + } + } + + private List getCatSearch(){ + if(catSearch.isEmpty()){ + return new ArrayList(this.domains.keySet()); + } + List list = new ArrayList(); + for(String name : this.domains.keySet()){ + if(name.toLowerCase().contains(catSearch)) + list.add(name); + } + return list; + } + + private List getSoundSearch(){ + if(selectedDomain == null){ + return new ArrayList(); + } + + if(soundSearch.isEmpty()){ + return new ArrayList(this.domains.get(selectedDomain)); + } + List list = new ArrayList(); + for(String name : this.domains.get(selectedDomain)){ + if(name.toLowerCase().contains(soundSearch)) + list.add(name); + } + return list; + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 81415e7d0..d13c2968a 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -370,4 +370,8 @@ public class GuiCustomScroll extends GuiScreen public boolean isMouseOver(int x, int y) { return x >= this.guiLeft && x <= this.guiLeft + this.xSize && y >= this.guiTop && y <= this.guiTop + this.ySize; } + + public void resetScroll(){ + scrollY = 0; + } }