From 996969bd2cf51de78ec998abe76b3da64ec454be Mon Sep 17 00:00:00 2001 From: Kam Date: Thu, 4 May 2023 16:13:59 -0400 Subject: [PATCH] Remodel Tag Setup to have search bar and better organize Tag Information --- .../client/gui/advanced/GuiNPCTagSetup.java | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java index 47836488d..f2a8af5c7 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCTagSetup.java @@ -1,6 +1,7 @@ package noppes.npcs.client.gui.advanced; import net.minecraft.client.gui.GuiButton; +import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; @@ -9,6 +10,7 @@ import noppes.npcs.client.Client; import noppes.npcs.client.gui.SubGuiNpcFactionOptions; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.RecipeController; import noppes.npcs.entity.EntityNPCInterface; import java.util.*; @@ -17,8 +19,9 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus { private GuiCustomScroll scrollTags; private GuiCustomScroll npcTags; - private HashMap data = new HashMap<>(); - private final ArrayList tagNames = new ArrayList<>(); + private final ArrayList allTags = new ArrayList<>(); + private ArrayList tagNames = new ArrayList<>(); + private String search = ""; public GuiNPCTagSetup(EntityNPCInterface npc) { @@ -31,19 +34,20 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus { super.initGui(); - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 54, guiTop + 11)); + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.allTags"), guiLeft + 22, guiTop + 11)); if(scrollTags == null){ scrollTags = new GuiCustomScroll(this,0); - scrollTags.setSize(120, 180); + scrollTags.setSize(150, 155); } - scrollTags.guiLeft = guiLeft + 50; + scrollTags.guiLeft = guiLeft + 20; scrollTags.guiTop = guiTop + 24; this.addScroll(scrollTags); + addTextField(new GuiNpcTextField(4, this, fontRendererObj, guiLeft + 20, guiTop + 24 + 160, 150, 20, search)); - addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 254, guiTop + 11)); + addLabel(new GuiNpcLabel(2, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 252, guiTop + 11)); if(npcTags == null){ npcTags = new GuiCustomScroll(this,1); - npcTags.setSize(120, 180); + npcTags.setSize(150, 180); } npcTags.guiLeft = guiLeft + 250; npcTags.guiTop = guiTop + 24; @@ -64,7 +68,7 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus } if (guibutton.id == 12) { tagNames.clear(); - tagNames.addAll(data.keySet()); + tagNames.addAll(allTags); } if (guibutton.id == 11 && npcTags.hasSelected()) { tagNames.remove(npcTags.getSelected()); @@ -78,8 +82,9 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus @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(); } @@ -117,4 +122,27 @@ public class GuiNPCTagSetup extends GuiNPCInterface2 implements IScrollData,ICus tagCompound.setTag("TagNames",tagList); 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; + } }