diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index 2c24abd26..fe9d3cb62 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -88,7 +88,7 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall } if (id == 5) { if(toClone instanceof EntityNPCInterface){ - this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone)); + this.setSubGui(new SubGuiClonerNPCTags()); } } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java index 3a8741fc4..3c76b3950 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerNPCTags.java @@ -12,18 +12,18 @@ import noppes.npcs.entity.EntityNPCInterface; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Vector; public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,IScrollData,ICustomScrollListener { - private final EntityNPCInterface npc; private GuiCustomScroll scrollTags; private GuiCustomScroll npcTags; - private HashMap data = new HashMap<>(); + private final ArrayList allTags = new ArrayList<>(); private final ArrayList tagNames = new ArrayList<>(); + private String search = ""; - public SubGuiClonerNPCTags(EntityNPCInterface npc) + public SubGuiClonerNPCTags() { - this.npc = npc; Client.sendData(EnumPacketServer.TagsGet); Client.sendData(EnumPacketServer.NpcTagsGet); setBackground("menubg.png"); @@ -36,32 +36,34 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc { super.initGui(); - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 5, guiTop + 11)); + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 10, guiTop + 11)); if(scrollTags == null){ scrollTags = new GuiCustomScroll(this,0); - scrollTags.setSize(100, 180); + scrollTags.setSize(110, 155); } - scrollTags.guiLeft = guiLeft + 5; + scrollTags.guiLeft = guiLeft + 10; scrollTags.guiTop = guiTop + 24; this.addScroll(scrollTags); + addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 10, guiTop + 24 + 160, 110, 20, search)); - addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 190, guiTop + 11)); + addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 185, guiTop + 11)); if(npcTags == null){ npcTags = new GuiCustomScroll(this,1); - npcTags.setSize(100, 180); + npcTags.setSize(110, 180); } - npcTags.guiLeft = guiLeft + 190; + npcTags.guiLeft = guiLeft + 185; npcTags.guiTop = guiTop + 24; npcTags.setList(tagNames); this.addScroll(npcTags); - addButton(new GuiNpcButton(10, guiLeft + 120, guiTop + 90, 55, 20, ">")); - addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 112, 55, 20, "<")); + addButton(new GuiNpcButton(66, guiLeft + 125, guiTop + 24, 55, 20, "gui.save")); - addButton(new GuiNpcButton(12, guiLeft + 120, guiTop + 140, 55, 20, ">>")); - addButton(new GuiNpcButton(13, guiLeft + 120, guiTop + 162, 55, 20, "<<")); + addButton(new GuiNpcButton(10, guiLeft + 125, guiTop + 90, 55, 20, ">")); + addButton(new GuiNpcButton(11, guiLeft + 125, guiTop + 112, 55, 20, "<")); + + addButton(new GuiNpcButton(12, guiLeft + 125, guiTop + 140, 55, 20, ">>")); + addButton(new GuiNpcButton(13, guiLeft + 125, guiTop + 162, 55, 20, "<<")); - addButton(new GuiNpcButton(66, guiLeft + 120, guiTop + 50, 55, 20, "gui.save")); } @Override @@ -71,7 +73,7 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc } if (guibutton.id == 12) { tagNames.clear(); - tagNames.addAll(data.keySet()); + tagNames.addAll(allTags); } if (guibutton.id == 11 && npcTags.hasSelected()) { tagNames.remove(npcTags.getSelected()); @@ -88,8 +90,9 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc @Override public void setData(Vector list, HashMap data) { - this.data = data; - scrollTags.setList(list); + allTags.addAll(data.keySet()); + allTags.sort(String.CASE_INSENSITIVE_ORDER); + scrollTags.setList(allTags); initGui(); } @@ -118,6 +121,7 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { } + @Override public void save() { NBTTagCompound tagCompound = new NBTTagCompound(); NBTTagList tagList = new NBTTagList(); @@ -128,6 +132,29 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc Client.sendData(EnumPacketServer.TagSet, tagCompound); } + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(4) != null){ + if(search.equals(getTextField(4).getText())) + return; + search = getTextField(4).getText().toLowerCase(); + scrollTags.setList(getSearchList()); + } + } + + private List getSearchList(){ + if(search.isEmpty()){ + return new ArrayList(allTags); + } + List list = new ArrayList(); + for(String name : this.allTags){ + if(name.toLowerCase().contains(search)) + list.add(name); + } + return list; + } + @Override public void close() { save();