diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java index 2c24abd26..ad5cc9795 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcMobSpawnerAdd.java @@ -8,31 +8,48 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import noppes.npcs.client.Client; import noppes.npcs.client.controllers.ClientCloneController; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Tag; +import noppes.npcs.controllers.data.TagMap; import noppes.npcs.entity.EntityNPCInterface; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.UUID; +import java.util.*; -public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ISubGuiListener{ +public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ISubGuiListener { private Entity toClone; private NBTTagCompound compound; private static boolean serverSide = false; private static int tab = 1; + public boolean isNPC = false; + + // Selected Tags to Add + public static HashSet addTags; + public static ArrayList allTags = new ArrayList<>(); + public static HashMap tagMap = new HashMap<>(); public GuiNpcMobSpawnerAdd(NBTTagCompound compound){ this.toClone = EntityList.createEntityFromNBT(compound, Minecraft.getMinecraft().theWorld); this.compound = compound; + if(toClone instanceof EntityNPCInterface){ + isNPC = true; + } setBackground("menubg.png"); xSize = 256; ySize = 216; closeOnEsc = true; + + if(addTags == null){ + addTags = new HashSet<>(); + } + if(isNPC){ + Client.sendData(EnumPacketServer.CloneAllTagsShort); + } } @Override @@ -52,9 +69,12 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 70, 80, 20, "gui.save")); addButton(new GuiNpcButton(1, guiLeft + 86, guiTop + 70, 80, 20, "gui.cancel")); - if(toClone instanceof EntityNPCInterface){ + if(isNPC){ addButton(new GuiNpcButton(4, guiLeft + 4, guiTop + 120, 99, 20, "cloner.wandTags")); addButton(new GuiNpcButton(5, guiLeft + 106, guiTop + 120, 99, 20, "cloner.npcTags")); + if(addTags.size() > 0){ + addLabel(new GuiNpcLabel(6, "cloner.wandtagsapplied", guiLeft + 10, guiTop + 160)); + } } } @@ -84,10 +104,12 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall serverSide = ((GuiNpcButton)guibutton).getValue() == 1; } if (id == 4) { - this.setSubGui(new SubGuiClonerQuickTags(this)); + if(isNPC){ + this.setSubGui(new SubGuiClonerQuickTags(this)); + } } if (id == 5) { - if(toClone instanceof EntityNPCInterface){ + if(isNPC){ this.setSubGui(new SubGuiClonerNPCTags((EntityNPCInterface) toClone)); } } @@ -98,10 +120,17 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall public void confirmClicked(boolean confirm, int id){ if(confirm){ String name = getTextField(0).getText(); - if(!serverSide) - ClientCloneController.Instance.addClone(compound, name, tab); - else - Client.sendData(EnumPacketServer.CloneSave, name, tab); + NBTTagCompound extraTags = new NBTTagCompound(); + if(isNPC && addTags.size() > 0){ + extraTags = setTempTags(); + } + if(!serverSide){ + ClientCloneController.Instance.addClone(compound, name, tab, extraTags); + } + else{ + Client.sendData(EnumPacketServer.CloneSave, name, tab, extraTags); + } + close(); } else @@ -114,7 +143,6 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall } - @Override public void setGuiData(NBTTagCompound compound) { if(compound.hasKey("NameExists")){ @@ -123,14 +151,44 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall else confirmClicked(true, 0); } + else if (compound.hasKey("ShortTags")) { + NBTTagList validTags = compound.getTagList("ShortTags", 10); + tagMap.clear(); + allTags.clear(); + if(validTags != null){ + for(int j = 0; j < validTags.tagCount(); j++) + { + NBTTagCompound tagStructure = validTags.getCompoundTagAt(j); + Tag tag = new Tag(); + tag.readShortNBT(tagStructure); + tagMap.put(tag.name, tag.uuid); + } + allTags.addAll(tagMap.keySet()); + allTags.sort(String.CASE_INSENSITIVE_ORDER); + } + initGui(); + } } @Override public void subGuiClosed(SubGuiInterface subgui) { - if (subgui instanceof SubGuiClonerQuickTags) { - SubGuiClonerQuickTags filterGui = (SubGuiClonerQuickTags) subgui; - // filter = filterGui.filterScroll.getSelectedList(); - } initGui(); } + + public NBTTagCompound setTempTags(){ + NBTTagCompound nbtTagCompound = new NBTTagCompound(); + NBTTagList nbtTagList = new NBTTagList(); + for (String name : addTags) { + if(tagMap.containsKey(name)){ + nbtTagList.appendTag(new NBTTagString(tagMap.get(name).toString())); + } + else { + addTags.remove(name); + } + } + nbtTagCompound.setTag("TempTagUUIDs", nbtTagList); + + return nbtTagCompound; + } + } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java index 3fd43958e..fc9331318 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiClonerQuickTags.java @@ -1,59 +1,101 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.StatCollector; -import noppes.npcs.client.gui.util.GuiCustomScroll; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcLabel; -import noppes.npcs.client.gui.util.SubGuiInterface; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Tag; +import noppes.npcs.controllers.data.TagMap; -import java.util.ArrayList; -import java.util.HashSet; +import java.util.*; -public class SubGuiClonerQuickTags extends SubGuiInterface +public class SubGuiClonerQuickTags extends SubGuiInterface implements IScrollData { public GuiNpcMobSpawnerAdd parent; - public ArrayList allTags = new ArrayList<>(); - public HashSet filter; - public GuiCustomScroll filterScroll; + public GuiCustomScroll quickScroll = new GuiCustomScroll(this,0); + private static String quickSearch = ""; public SubGuiClonerQuickTags(GuiNpcMobSpawnerAdd par){ this.parent = par; setBackground("menubg.png"); xSize = 305; - ySize = 200; + ySize = 220; closeOnEsc = true; } public void initGui(){ super.initGui(); - if(filterScroll == null){ - filterScroll = new GuiCustomScroll(this,0); - filterScroll.setSize(140, 180); - } - filterScroll.guiLeft = guiLeft + 4; - filterScroll.guiTop = guiTop + 14; - filterScroll.setList(this.allTags); - filterScroll.multipleSelection = true; - filterScroll.setSelectedList(this.filter); - this.addScroll(filterScroll); + quickScroll.clear(); + quickScroll.setSize(140, 166); + quickScroll.guiLeft = guiLeft + 4; + quickScroll.guiTop = guiTop + 19; + quickScroll.multipleSelection = true; + quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); + this.addScroll(quickScroll); + + addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.wandtags"), guiLeft + 7, guiTop + 7)); + addScroll(quickScroll); + addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 190, 140, 20, quickSearch)); + addButton(new GuiNpcButton(10, guiLeft + 150, guiTop + 20, 120, 20, "gui.selectAll")); addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 120, 20, "gui.deselectAll")); - addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("tags.taglessEntries") + ":", guiLeft + 150, guiTop + 72)); - getButton(12).width = 60; - getButton(12).height = 20; + addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 175, 60, 20, "gui.done")); + + getSelected(); } protected void actionPerformed(GuiButton guibutton){ if (guibutton.id == 10) { - HashSet hashSet = new HashSet<>(this.allTags); - filterScroll.setSelectedList(hashSet); + GuiNpcMobSpawnerAdd.addTags = new HashSet<>(parent.allTags); + quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); } if (guibutton.id == 11) { - filterScroll.setSelectedList(new HashSet<>()); + GuiNpcMobSpawnerAdd.addTags = new HashSet<>(); + quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags); } if (guibutton.id == 66) { close(); } } + + public void getSelected(){ + quickScroll.setList(getQuickTags()); + } + + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(2) != null){ + if(quickSearch.equals(getTextField(2).getText())) + return; + quickSearch = getTextField(2).getText().toLowerCase(); + quickScroll.setList(getQuickTags()); + } + } + + private List getQuickTags(){ + if(quickSearch.isEmpty()){ + return new ArrayList(parent.allTags); + } + List list = new ArrayList(); + for(String name : this.parent.allTags){ + if(name.toLowerCase().contains(quickSearch)) + list.add(name); + } + return list; + } + + @Override + public void setData(Vector list, HashMap data) { + + } + + @Override + public void setSelected(String selected) { + + } } \ No newline at end of file