From d9d2481b7feded6451a73f2dcb9cdae2681162b4 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:54:32 -0400 Subject: [PATCH 01/13] Attempt to fix AI Sprint --- .../npcs/ai/EntityAISprintToTarget.java | 57 +++++++------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/EntityAISprintToTarget.java b/src/main/java/noppes/npcs/ai/EntityAISprintToTarget.java index 1d615dff7..5449ba6a5 100644 --- a/src/main/java/noppes/npcs/ai/EntityAISprintToTarget.java +++ b/src/main/java/noppes/npcs/ai/EntityAISprintToTarget.java @@ -7,42 +7,27 @@ import noppes.npcs.entity.EntityNPCInterface; public class EntityAISprintToTarget extends EntityAIBase { - /** The entity that is leaping. */ - private EntityNPCInterface runner; + private EntityNPCInterface npc; - /** The entity that the leaper is leaping towards. */ - private EntityLivingBase runTarget; - - public EntityAISprintToTarget(EntityNPCInterface par1EntityLiving) - { - this.runner = par1EntityLiving; + public EntityAISprintToTarget(EntityNPCInterface par1EntityLiving){ + this.npc = par1EntityLiving; this.setMutexBits(AiMutex.PASSIVE); } - /** - * Returns whether the EntityAIBase should begin execution. - */ - public boolean shouldExecute() - { - this.runTarget = this.runner.getAttackTarget(); + @Override + public boolean shouldExecute(){ + EntityLivingBase runTarget = this.npc.getAttackTarget(); - if (this.runTarget == null) - { + if (runTarget == null || this.npc.getNavigator().noPath()){ return false; } - else if (this.runner.getNavigator().noPath()) - { - return false; - } - else - { - switch(this.runner.ai.onAttack) - { - case 0 : return !this.runner.isInRange(runTarget, 8)? (!this.runner.onGround ? false : true) : false; - case 2 : return this.runner.isInRange(runTarget, 7)? (!this.runner.onGround ? false : true) : false; - default : return false; - } + + switch(this.npc.ai.onAttack){ + case 0 : return !this.npc.isInRange(runTarget, 8)? (!this.npc.onGround ? false : true) : false; + case 2 : return this.npc.isInRange(runTarget, 7)? (!this.npc.onGround ? false : true) : false; + default : return false; } + } /** @@ -50,22 +35,22 @@ public class EntityAISprintToTarget extends EntityAIBase */ public boolean continueExecuting() { - return this.runner.isEntityAlive() && this.runner.onGround && this.runner.hurtTime <= 0 && (this.runner.motionX != 0.0D && this.runner.motionZ != 0.0D); + return this.npc.isEntityAlive() && this.npc.onGround && this.npc.hurtTime <= 0 && (this.npc.motionX != 0.0D && this.npc.motionZ != 0.0D); } /** * Execute a one shot task or start executing a continuous task */ - public void startExecuting() - { - this.runner.setSprinting(true); + @Override + public void startExecuting(){ + this.npc.setSprinting(true); } - + /** * Resets the task */ - public void resetTask() - { - this.runner.setSprinting(false); + @Override + public void resetTask(){ + this.npc.setSprinting(false); } } From 90b34127c395c16793efdbfeb3011c06d72ab6a8 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:54:44 -0400 Subject: [PATCH 02/13] AI World Lines Cooldown --- .../noppes/npcs/ai/EntityAIWorldLines.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/ai/EntityAIWorldLines.java b/src/main/java/noppes/npcs/ai/EntityAIWorldLines.java index 7b6b5e132..708564960 100644 --- a/src/main/java/noppes/npcs/ai/EntityAIWorldLines.java +++ b/src/main/java/noppes/npcs/ai/EntityAIWorldLines.java @@ -6,20 +6,25 @@ import noppes.npcs.entity.EntityNPCInterface; public class EntityAIWorldLines extends EntityAIBase { - private EntityNPCInterface npc; - public EntityAIWorldLines(EntityNPCInterface npc){ - this.npc = npc; + private EntityNPCInterface npc; + private int cooldown = 100; + + public EntityAIWorldLines(EntityNPCInterface npc){ + this.npc = npc; this.setMutexBits(AiMutex.PASSIVE); - } - - @Override - public boolean shouldExecute() { - return !npc.isAttacking() && !npc.isKilled() && npc.advanced.hasWorldLines() && npc.getRNG().nextInt(1900) == 1; - } - - public void startExecuting() - { - npc.saySurrounding(npc.advanced.getWorldLine()); } - + + @Override + public boolean shouldExecute() { + if(cooldown > 0){ + cooldown--; + } + return !npc.isAttacking() && !npc.isKilled() && npc.advanced.hasWorldLines() && npc.getRNG().nextInt(1800) == 1; + } + + public void startExecuting(){ + cooldown = 100; + npc.saySurrounding(npc.advanced.getWorldLine()); + } + } From 748cdccff46c8ff8b5467ae20138047f703eb733 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:55:00 -0400 Subject: [PATCH 03/13] Tactical Chance GUI Fix --- .../noppes/npcs/client/gui/mainmenu/GuiNpcAI.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java index 9fe3cd19c..f13e847b5 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAI.java @@ -23,7 +23,7 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG { super.initGui(); addLabel(new GuiNpcLabel(0,"ai.enemyresponse", guiLeft + 5, guiTop + 17)); - addButton(new GuiNpcButton(0,guiLeft + 86, guiTop + 10, 60, 20, new String[]{"gui.retaliate","gui.panic","gui.retreat","gui.nothing"} ,npc.ai.onAttack)); + addButton(new GuiNpcButton(0,guiLeft + 86, guiTop + 10, 60, 20, new String[]{"gui.retaliate","gui.panic","gui.retreat","gui.nothing"} ,npc.ai.onAttack)); addLabel(new GuiNpcLabel(1,"ai.door", guiLeft + 5, guiTop + 40)); addButton(new GuiNpcButton(1,guiLeft + 86, guiTop + 35, 60, 20, new String[]{"gui.break","gui.open","gui.disabled"} ,npc.ai.doorInteract)); addLabel(new GuiNpcLabel(12,"ai.swim", guiLeft + 5, guiTop + 65)); @@ -75,8 +75,8 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG { String label = ""; label = "gui.combatchance"; - addLabel(new GuiNpcLabel(21, label, guiLeft + 300, guiTop + 140)); - addTextField(new GuiNpcTextField(4,this, fontRendererObj, guiLeft + 380, guiTop + 135, 30, 20, ai.tacticalChance + "")); + addLabel(new GuiNpcLabel(21, label, guiLeft + 300, guiTop + 165)); + addTextField(new GuiNpcTextField(4,this, fontRendererObj, guiLeft + 380, guiTop + 160, 30, 20, ai.tacticalChance + "")); getTextField(4).integersOnly = true; getTextField(4).setMinMaxDefault(1, 100, 5); } @@ -91,7 +91,7 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG addLabel(new GuiNpcLabel(2,"ai.movement", guiLeft + 4, guiTop + 165)); addButton(new GuiNpcButton(2, guiLeft + 86, guiTop + 160, 60, 20, "selectServer.edit")); } - + @Override public void unFocused(GuiNpcTextField textfield){ if(textfield.id == 3){ @@ -104,7 +104,7 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG ai.distanceToMelee = textfield.getInteger(); } } - + @Override protected void actionPerformed(GuiButton guibutton) { @@ -154,9 +154,10 @@ public class GuiNpcAI extends GuiNPCInterface2 implements ITextfieldListener, IG } else if (button.id == 25) { ai.combatPolicy = EnumCombatPolicy.values()[button.getValue()]; + initGui(); } } - + @Override public void save() { Client.sendData(EnumPacketServer.MainmenuAISave, ai.writeToNBT(new NBTTagCompound())); From e4cf9da188defb5c0183b06a7e13fa6ba6a79fb5 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:55:33 -0400 Subject: [PATCH 04/13] Range Properties Reorganization - Changes up position of GUI components --- .../client/gui/SubGuiNpcRangeProperties.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java index 608a012ee..364eec0b6 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java @@ -9,7 +9,7 @@ public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfi { private DataStats stats; private GuiNpcSoundSelection gui; - + public SubGuiNpcRangeProperties(DataStats stats) { this.stats = stats; @@ -22,42 +22,50 @@ public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfi public void initGui(){ super.initGui(); int y = guiTop + 4; - addTextField(new GuiNpcTextField(1,this, fontRendererObj, guiLeft + 85, y, 50, 18, stats.accuracy+"")); + addTextField(new GuiNpcTextField(1,this, fontRendererObj, guiLeft + 80, y, 50, 18, stats.accuracy+"")); addLabel(new GuiNpcLabel(1,"stats.accuracy", guiLeft + 5, y + 5)); getTextField(1).integersOnly = true; getTextField(1).setMinMaxDefault(0, 100, 90); - addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.rangedRange+"")); + + addTextField(new GuiNpcTextField(8, this, fontRendererObj, guiLeft + 200, y, 50, 18, stats.shotCount + "")); + addLabel(new GuiNpcLabel(8, "stats.shotcount", guiLeft + 135, y + 5)); + getTextField(8).integersOnly = true; + getTextField(8).setMinMaxDefault(1, Integer.MAX_VALUE, 1); + + addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 80, y += 22, 50, 18, stats.rangedRange+"")); addLabel(new GuiNpcLabel(2,"stats.rangedrange", guiLeft + 5, y + 5)); getTextField(2).integersOnly = true; - getTextField(2).setMinMaxDefault(1, Integer.MAX_VALUE, 2); - addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.minDelay+"")); + getTextField(2).setMinMaxDefault(1, 64, 2); + + addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 80, y += 22, 50, 18, stats.minDelay+"")); addLabel(new GuiNpcLabel(3,"stats.mindelay", guiLeft + 5, y + 5)); getTextField(3).integersOnly = true; getTextField(3).setMinMaxDefault(1, Integer.MAX_VALUE, 20); - addTextField(new GuiNpcTextField(4,this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.maxDelay+"")); - addLabel(new GuiNpcLabel(4,"stats.maxdelay", guiLeft + 5, y + 5)); + + addTextField(new GuiNpcTextField(4,this, fontRendererObj, guiLeft + 200, y, 50, 18, stats.maxDelay+"")); + addLabel(new GuiNpcLabel(4,"stats.maxdelay", guiLeft + 135, y + 5)); getTextField(4).integersOnly = true; getTextField(4).setMinMaxDefault(1, Integer.MAX_VALUE, 20); - addTextField(new GuiNpcTextField(5, this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.fireRate + "")); - addLabel(new GuiNpcLabel(5, "stats.burstspeed", guiLeft + 5, y + 5)); + + addTextField(new GuiNpcTextField(6, this, fontRendererObj, guiLeft + 80, y += 22, 50, 18, stats.burstCount + "")); + addLabel(new GuiNpcLabel(6, "stats.burstcount", guiLeft + 5, y + 5)); + getTextField(6).integersOnly = true; + getTextField(6).setMinMaxDefault(1, Integer.MAX_VALUE, 20); + + addTextField(new GuiNpcTextField(5, this, fontRendererObj, guiLeft + 200, y , 50, 18, stats.fireRate + "")); + addLabel(new GuiNpcLabel(5, "stats.burstspeed", guiLeft + 135, y + 5)); getTextField(5).integersOnly = true; getTextField(5).setMinMaxDefault(0, Integer.MAX_VALUE, 0); - addTextField(new GuiNpcTextField(6, this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.burstCount + "")); - addLabel(new GuiNpcLabel(6, "stats.burstcount", guiLeft + 5, y + 5)); - getTextField(6).integersOnly = true; - getTextField(6).setMinMaxDefault(1, Integer.MAX_VALUE, 20); - addTextField(new GuiNpcTextField(7,this, fontRendererObj, guiLeft + 85, y += 22, 100, 20, stats.fireSound)); + + + addTextField(new GuiNpcTextField(7,this, fontRendererObj, guiLeft + 80, y += 22, 100, 20, stats.fireSound)); addLabel(new GuiNpcLabel(7, "stats.firesound:", guiLeft + 5, y + 5)); addButton(new GuiNpcButton(7, guiLeft + 187, y, 60, 20, "gui.select")); - addTextField(new GuiNpcTextField(8, this, fontRendererObj, guiLeft + 85, y += 22, 50, 18, stats.shotCount + "")); - addLabel(new GuiNpcLabel(8, "stats.shotcount", guiLeft + 5, y + 5)); - getTextField(8).integersOnly = true; - getTextField(8).setMinMaxDefault(1, Integer.MAX_VALUE, 1); addButton(new GuiNpcButtonYesNo(9, guiLeft + 100, y += 22, stats.aimWhileShooting)); addLabel(new GuiNpcLabel(9, "stats.aimWhileShooting", guiLeft + 5, y + 5)); - + addButton(new GuiNpcButton(66, guiLeft + 190, guiTop + 190, 60, 20, "gui.done")); } @@ -103,7 +111,7 @@ public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfi stats.shotCount = textfield.getInteger(); } } - + @Override public void elementClicked(){ getTextField(7).setText(gui.getSelected()); From 0f343b66a912af0cfdc31dce920d30b4537756cf Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:56:06 -0400 Subject: [PATCH 05/13] Small Fixes to AI Task handling priorities. Fix Dodge and Orbit to have better speeds --- .../npcs/entity/EntityNPCInterface.java | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 13b465433..5e6263725 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -675,18 +675,22 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } private void clearTasks(EntityAITasks tasks){ - Iterator iterator = tasks.taskEntries.iterator(); - List list = new ArrayList(tasks.taskEntries); - for (EntityAITaskEntry entityaitaskentry : list) - { - tasks.removeTask(entityaitaskentry.action); - } - tasks.taskEntries = new ArrayList(); + Iterator iterator = tasks.taskEntries.iterator(); + List list = new ArrayList(tasks.taskEntries); + for (EntityAITaskEntry entityaitaskentry : list) + { + try { + tasks.removeTask(entityaitaskentry.action); + } + catch(Throwable e) { + + } + } + tasks.taskEntries = new ArrayList(); } public void updateTasks() { if (worldObj == null || worldObj.isRemote) return; - aiLeap = aiAttackTarget = aiResponse = aiSprint = aiRange = null; clearTasks(tasks); clearTasks(targetTasks); @@ -707,11 +711,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } this.taskCount = 1; + this.addRegularEntries(); this.doorInteractType(); this.seekShelter(); this.setResponse(); this.setMoveType(); - this.addRegularEntries(); } private void removeTask(EntityAIBase task){ @@ -723,31 +727,29 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti * Branch task function for setting how an NPC responds to a threat */ public void setResponse(){ - removeTask(aiLeap); - removeTask(aiResponse); - removeTask(aiSprint); - removeTask(aiAttackTarget); - removeTask(aiRange); - aiLeap = aiAttackTarget = aiResponse = aiSprint = aiRange = null; + removeTask(aiLeap); + removeTask(aiResponse); + removeTask(aiSprint); + removeTask(aiAttackTarget); + removeTask(aiRange); + aiLeap = aiAttackTarget = aiResponse = aiSprint = aiRange = null; if (this.ai.canSprint) this.tasks.addTask(this.taskCount++, new EntityAISprintToTarget(this)); if (this.ai.onAttack == 1) this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIPanic(this, 1.2F)); - else if (this.ai.onAttack == 2) { this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); } - else if (this.ai.onAttack == 0) { this.setLeapTask(); if (this.inventory.getProjectile() == null || this.ai.useRangeMelee == 2) { switch(this.ai.tacticalVariant) { - case Dodge : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIZigZagTarget(this, 1.0D, this.ai.tacticalRadius)); break; - case Surround : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIOrbitTarget(this, 1.0D, this.ai.tacticalRadius, true)); break; + case Dodge : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIZigZagTarget(this, 1.2D, this.ai.tacticalRadius)); break; + case Surround : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIOrbitTarget(this, 1.2D, this.ai.tacticalRadius, true)); break; case HitNRun : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); break; case Ambush : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAmbushTarget(this, 1.2D, this.ai.tacticalRadius, false)); break; case Stalk : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIStalkTarget(this, this.ai.tacticalRadius)); break; @@ -760,7 +762,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti switch(this.ai.tacticalVariant) { case Dodge : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIDodgeShoot(this)); break; - case Surround : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIOrbitTarget(this, 1.0D, stats.rangedRange, false)); break; + case Surround : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIOrbitTarget(this, 1.2D, stats.rangedRange, false)); break; case HitNRun : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAvoidTarget(this)); break; case Ambush : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIAmbushTarget(this, 1.2D, this.ai.tacticalRadius, false)); break; case Stalk : this.tasks.addTask(this.taskCount++, aiResponse = new EntityAIStalkTarget(this, this.ai.tacticalRadius)); break; From 3dc60ec1a760fda9aa21a6de9e56f390a6f5d85f Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:58:35 -0400 Subject: [PATCH 06/13] GuiSoundSelection 1.12 Backports GuiSoundSelection from 1.12 - customScrollDoubleClicked (to be renamed) - Better GUI Selection Handling --- .../npcs/client/gui/roles/GuiNpcBard.java | 40 +- .../client/gui/select/GuiDialogSelection.java | 124 ++++++ .../client/gui/select/GuiQuestSelection.java | 124 ++++++ .../client/gui/select/GuiSoundSelection.java | 126 ++++++ .../gui/select/GuiTextureSelection.java | 376 ++++++++++++++++++ .../npcs/client/gui/util/GuiCustomScroll.java | 15 +- .../gui/util/ICustomScrollListener.java | 1 + 7 files changed, 785 insertions(+), 21 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java create mode 100644 src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java index e1b4522d0..3b5549f15 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java @@ -6,22 +6,20 @@ import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.GuiNpcSoundSelection; -import noppes.npcs.client.gui.util.GuiNPCInterface2; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcLabel; -import noppes.npcs.client.gui.util.GuiNpcTextField; +import noppes.npcs.client.gui.select.GuiSoundSelection; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobBard; -public class GuiNpcBard extends GuiNPCInterface2 -{ +public class GuiNpcBard extends GuiNPCInterface2 implements ISubGuiListener +{ private JobBard job; private GuiNpcSoundSelection gui; - + public GuiNpcBard(EntityNPCInterface npc) { - super(npc); + super(npc); job = (JobBard) npc.jobInterface; } @@ -36,7 +34,7 @@ public class GuiNpcBard extends GuiNPCInterface2 this.addButton(new GuiNpcButton(2, guiLeft + 75, guiTop + 71, new String[]{"gui.none","item.npcBanjo.name","item.npcViolin.name","item.npcGuitar.name","item.npcHarp.name","item.npcFrenchHorn.name"}, job.getInstrument().ordinal())); this.addButton(new GuiNpcButton(3, guiLeft + 75, guiTop + 92, new String[]{"bard.jukebox","bard.background"}, job.isStreamer?0:1)); - + addLabel(new GuiNpcLabel(2,"bard.ondistance", guiLeft + 60, guiTop + 143)); addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft+160, guiTop + 138, 40, 20, job.minRange + "")); getTextField(2).integersOnly = true; @@ -44,7 +42,7 @@ public class GuiNpcBard extends GuiNPCInterface2 addLabel(new GuiNpcLabel(4,"bard.hasoff", guiLeft + 60, guiTop + 166)); addButton(new GuiNpcButton(4, guiLeft + 160, guiTop + 161, 60, 20, new String[]{"gui.no","gui.yes"}, job.hasOffRange?1:0)); - + addLabel(new GuiNpcLabel(3,"bard.offdistance", guiLeft + 60, guiTop + 189)); addTextField(new GuiNpcTextField(3,this, this.fontRendererObj, guiLeft+160, guiTop + 184, 40, 20, job.maxRange + "")); getTextField(3).integersOnly = true; @@ -52,7 +50,7 @@ public class GuiNpcBard extends GuiNPCInterface2 getLabel(3).enabled = job.hasOffRange; getTextField(3).enabled = job.hasOffRange; - + } @Override public void elementClicked(){ @@ -64,12 +62,8 @@ public class GuiNpcBard extends GuiNPCInterface2 GuiNpcButton button = (GuiNpcButton) guibutton; if(button.id == 0) { - - gui = new GuiNpcSoundSelection(this, job.song); - NoppesUtil.openGUI(player, gui); - - job.song = ""; - MusicController.Instance.stopMusic(); + setSubGui(new GuiSoundSelection(job.song)); + MusicController.Instance.stopMusic(); } if(button.id == 1) { @@ -91,14 +85,14 @@ public class GuiNpcBard extends GuiNPCInterface2 job.hasOffRange = button.getValue() == 1; initGui(); } - + } @Override public void save() { job.minRange = getTextField(2).getInteger(); job.maxRange = getTextField(3).getInteger(); - + if(job.minRange > job.maxRange) job.maxRange = job.minRange; @@ -107,4 +101,12 @@ public class GuiNpcBard extends GuiNPCInterface2 } + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + job.song = gss.selectedResource.toString(); + getLabel(0).label = job.song; + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java new file mode 100644 index 000000000..0389d9ec1 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java @@ -0,0 +1,124 @@ +//package noppes.npcs.client.gui.select; +// +//import com.google.common.collect.Lists; +//import net.minecraft.client.gui.GuiButton; +//import noppes.npcs.client.gui.util.*; +//import noppes.npcs.controllers.DialogController; +//import noppes.npcs.controllers.data.Dialog; +//import noppes.npcs.controllers.data.DialogCategory; +// +//import java.util.HashMap; +// +//public class GuiDialogSelection extends SubGuiInterface implements ICustomScrollListener{ +// private HashMap categoryData = new HashMap(); +// private HashMap dialogData = new HashMap(); +// +// private GuiCustomScroll scrollCategories; +// private GuiCustomScroll scrollDialogs; +// +// private DialogCategory selectedCategory; +// public Dialog selectedDialog; +// +// private GuiSelectionListener listener; +// +// public GuiDialogSelection(int dialog){ +// drawDefaultBackground = false; +// title = ""; +// setBackground("menubg.png"); +// xSize = 366; +// ySize = 226; +// this.selectedDialog = DialogController.instance.dialogs.get(dialog); +// if(selectedDialog != null) { +// selectedCategory = selectedDialog.category; +// } +// } +// +// @Override +// public void initGui(){ +// super.initGui(); +// +// if(parent instanceof GuiSelectionListener){ +// listener = (GuiSelectionListener) parent; +// } +// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); +// this.addLabel(new GuiNpcLabel(1, "dialog.dialogs", guiLeft + 175, guiTop + 4)); +// +// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); +// +// HashMap categoryData = new HashMap(); +// HashMap dialogData = new HashMap(); +// +// for(DialogCategory category : DialogController.instance.categories.values()) { +// categoryData.put(category.title, category); +// } +// this.categoryData = categoryData; +// +// if(selectedCategory != null) { +// for(Dialog dialog : selectedCategory.dialogs.values()) { +// dialogData.put(dialog.title, dialog); +// } +// } +// this.dialogData = dialogData; +// +// if(scrollCategories == null){ +// scrollCategories = new GuiCustomScroll(this,0); +// scrollCategories.setSize(170, 200); +// } +// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); +// if(selectedCategory != null) { +// scrollCategories.setSelected(selectedCategory.title); +// } +// +// scrollCategories.guiLeft = guiLeft + 4; +// scrollCategories.guiTop = guiTop + 14; +// this.addScroll(scrollCategories); +// +// if(scrollDialogs == null){ +// scrollDialogs = new GuiCustomScroll(this,1); +// scrollDialogs.setSize(170, 200); +// } +// scrollDialogs.setList(Lists.newArrayList(dialogData.keySet())); +// if(selectedDialog != null) { +// scrollDialogs.setSelected(selectedDialog.title); +// } +// scrollDialogs.guiLeft = guiLeft + 175; +// scrollDialogs.guiTop = guiTop + 14; +// this.addScroll(scrollDialogs); +// } +// +// @Override +// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { +// if(guiCustomScroll.id == 0){ +// selectedCategory = categoryData.get(scrollCategories.getSelected()); +// selectedDialog = null; +// scrollDialogs.selected = -1; +// } +// if(guiCustomScroll.id == 1){ +// selectedDialog = dialogData.get(scrollDialogs.getSelected()); +// } +// initGui(); +// } +// +// @Override +// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { +// if(selectedDialog == null) +// return; +// if(listener != null) { +// listener.selected(selectedDialog.id, selectedDialog.title); +// } +// close(); +// } +// +// @Override +// protected void actionPerformed(GuiButton guibutton){ +// int id = guibutton.id; +// if(id == 2){ +// if(selectedDialog != null) { +// scrollDoubleClicked(null, null); +// } +// else { +// close(); +// } +// } +// } +//} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java new file mode 100644 index 000000000..0ba761347 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java @@ -0,0 +1,124 @@ +//package noppes.npcs.client.gui.select; +// +//import com.google.common.collect.Lists; +//import net.minecraft.client.gui.GuiButton; +//import noppes.npcs.client.gui.util.*; +//import noppes.npcs.controllers.QuestController; +//import noppes.npcs.controllers.data.Quest; +//import noppes.npcs.controllers.data.QuestCategory; +// +//import java.util.HashMap; +// +//public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollListener{ +// private HashMap categoryData = new HashMap(); +// private HashMap questData = new HashMap(); +// +// private GuiCustomScroll scrollCategories; +// private GuiCustomScroll scrollQuests; +// +// private QuestCategory selectedCategory; +// public Quest selectedQuest; +// +// private GuiSelectionListener listener; +// +// public GuiQuestSelection(int quest){ +// drawDefaultBackground = false; +// title = ""; +// setBackground("menubg.png"); +// xSize = 366; +// ySize = 226; +// this.selectedQuest = QuestController.instance.quests.get(quest); +// if(selectedQuest != null) { +// selectedCategory = selectedQuest.category; +// } +// } +// +// @Override +// public void initGui(){ +// super.initGui(); +// +// if(parent instanceof GuiSelectionListener){ +// listener = (GuiSelectionListener) parent; +// } +// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); +// this.addLabel(new GuiNpcLabel(1, "quest.quests", guiLeft + 175, guiTop + 4)); +// +// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); +// +// HashMap categoryData = new HashMap(); +// HashMap questData = new HashMap(); +// +// for(QuestCategory category : QuestController.instance.categories.values()) { +// categoryData.put(category.title, category); +// } +// this.categoryData = categoryData; +// +// if(selectedCategory != null) { +// for(Quest quest : selectedCategory.quests.values()) { +// questData.put(quest.title, quest); +// } +// } +// this.questData = questData; +// +// if(scrollCategories == null){ +// scrollCategories = new GuiCustomScroll(this,0); +// scrollCategories.setSize(170, 200); +// } +// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); +// if(selectedCategory != null) { +// scrollCategories.setSelected(selectedCategory.title); +// } +// +// scrollCategories.guiLeft = guiLeft + 4; +// scrollCategories.guiTop = guiTop + 14; +// this.addScroll(scrollCategories); +// +// if(scrollQuests == null){ +// scrollQuests = new GuiCustomScroll(this,1); +// scrollQuests.setSize(170, 200); +// } +// scrollQuests.setList(Lists.newArrayList(questData.keySet())); +// if(selectedQuest != null) { +// scrollQuests.setSelected(selectedQuest.title); +// } +// scrollQuests.guiLeft = guiLeft + 175; +// scrollQuests.guiTop = guiTop + 14; +// this.addScroll(scrollQuests); +// } +// +// @Override +// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { +// if(guiCustomScroll.id == 0){ +// selectedCategory = categoryData.get(scrollCategories.getSelected()); +// selectedQuest = null; +// scrollQuests.selected = -1; +// } +// if(guiCustomScroll.id == 1){ +// selectedQuest = questData.get(scrollQuests.getSelected()); +// } +// initGui(); +// } +// +// @Override +// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { +// if(selectedQuest == null) +// return; +// if(listener != null) { +// listener.selected(selectedQuest.id, selectedQuest.title); +// } +// close(); +// } +// +// @Override +// protected void actionPerformed(GuiButton guibutton){ +// int id = guibutton.id; +// if(id == 2){ +// if(selectedQuest != null) { +// scrollDoubleClicked(null, null); +// } +// else { +// close(); +// } +// } +// } +//} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java new file mode 100644 index 000000000..9c1dcfdc0 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiSoundSelection.java @@ -0,0 +1,126 @@ +package noppes.npcs.client.gui.select; + +import com.google.common.collect.Lists; +import cpw.mods.fml.relauncher.ReflectionHelper; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.SoundHandler; +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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +public class GuiSoundSelection extends SubGuiInterface implements ICustomScrollListener{ + + private GuiCustomScroll scrollCategories; + private GuiCustomScroll scrollQuests; + + private String selectedDomain; + public ResourceLocation selectedResource; + + private HashMap> domains = new HashMap>(); + + public GuiSoundSelection(String sound){ + drawDefaultBackground = false; + title = ""; + setBackground("menubg.png"); + xSize = 366; + ySize = 226; + + SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); + SoundRegistry registry = ReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4); + + Set set = registry.getKeys(); + for(ResourceLocation location : set){ + List list = domains.get(location.getResourceDomain()); + if(list == null) + domains.put(location.getResourceDomain(), list = new ArrayList()); + list.add(location.getResourcePath()); + domains.put(location.getResourceDomain(), list); + } + if(sound != null && !sound.isEmpty()){ + selectedResource = new ResourceLocation(sound); + selectedDomain = selectedResource.getResourceDomain(); + if(!domains.containsKey(selectedDomain)) { + selectedDomain = null; + } + } + } + + @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")); + getButton(1).enabled = selectedResource != null; + + if(scrollCategories == null){ + scrollCategories = new GuiCustomScroll(this,0); + scrollCategories.setSize(90, 200); + } + scrollCategories.setList(Lists.newArrayList(domains.keySet())); + if(selectedDomain != null) { + scrollCategories.setSelected(selectedDomain); + } + + scrollCategories.guiLeft = guiLeft + 4; + scrollCategories.guiTop = guiTop + 14; + this.addScroll(scrollCategories); + + if(scrollQuests == null){ + scrollQuests = new GuiCustomScroll(this,1); + scrollQuests.setSize(250, 200); + } + if(selectedDomain != null) { + scrollQuests.setList(domains.get(selectedDomain)); + } + if(selectedResource != null) { + scrollQuests.setSelected(selectedResource.getResourcePath()); + } + scrollQuests.guiLeft = guiLeft + 95; + scrollQuests.guiTop = guiTop + 14; + this.addScroll(scrollQuests); + + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + super.actionPerformed(guibutton); + if(guibutton.id == 1){ + MusicController.Instance.stopMusic(); + MusicController.Instance.playSound(selectedResource.toString(), (float)player.posX, (float)player.posY, (float)player.posZ); + } + if(guibutton.id == 2){ + close(); + } + } + + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { + if(selectedResource == null) + return; + close(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0){ + selectedDomain = guiCustomScroll.getSelected(); + selectedResource = null; + scrollQuests.selected = -1; + } + if(guiCustomScroll.id == 1){ + selectedResource = new ResourceLocation(selectedDomain, guiCustomScroll.getSelected()); + } + initGui(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java new file mode 100644 index 000000000..74e1ed521 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/select/GuiTextureSelection.java @@ -0,0 +1,376 @@ +//package noppes.npcs.client.gui.select; +// +//import com.google.common.collect.Lists; +//import net.minecraft.client.Minecraft; +//import net.minecraft.client.gui.GuiButton; +//import net.minecraft.client.resources.*; +//import net.minecraft.item.crafting.CraftingManager; +//import net.minecraft.util.ResourceLocation; +//import noppes.npcs.CustomNpcs; +//import noppes.npcs.LogWriter; +//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.entity.EntityNPCInterface; +// +//import java.io.File; +//import java.io.UnsupportedEncodingException; +//import java.net.URL; +//import java.net.URLDecoder; +//import java.nio.charset.StandardCharsets; +//import java.util.*; +//import java.util.zip.ZipEntry; +//import java.util.zip.ZipFile; +// +//public class GuiTextureSelection extends SubGuiInterface implements ICustomScrollListener{ +// +// private String up = "..<" + I18n.translateToLocal("gui.up") + ">.."; +// private GuiCustomScroll scrollCategories; +// private GuiCustomScroll scrollQuests; +// +// private String location = ""; +// private String selectedDomain; +// public ResourceLocation selectedResource; +// +// private HashMap> domains = new HashMap>(); +// private HashMap textures = new HashMap(); +// +// public GuiTextureSelection(EntityNPCInterface npc, String texture){ +// this.npc = npc; +// drawDefaultBackground = false; +// title = ""; +// setBackground("menubg.png"); +// xSize = 366; +// ySize = 226; +// +// SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager(); +// +// Map map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2); +// HashSet set = new HashSet(); +// for(String name: map.keySet()){ +// FallbackResourceManager manager = map.get(name); +// List list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 1); +// for(IResourcePack pack : list){ +// if(pack instanceof LegacyV2Adapter) { +// pack = ObfuscationReflectionHelper.getPrivateValue(LegacyV2Adapter.class, (LegacyV2Adapter)pack, 0);; +// } +// if(pack instanceof AbstractResourcePack){ +// AbstractResourcePack p = (AbstractResourcePack) pack; +// File file = p.resourcePackFile; +// if(file != null) +// set.add(file.getAbsolutePath()); +// } +// } +// } +// for(String file : set){ +// File f = new File(file); +// if(f.isDirectory()) { +// checkFolder(new File(f, "assets"), f.getAbsolutePath().length()); +// } +// else { +// progressFile(f); +// } +// } +// for (ModContainer mod : Loader.instance().getModList()) { +// if(mod.getSource().exists()) +// progressFile(mod.getSource()); +// } +// +// ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository(); +// repos.updateRepositoryEntriesAll(); +// List list = repos.getRepositoryEntries(); +// if(repos.getServerResourcePack() != null) { +// AbstractResourcePack p = (AbstractResourcePack) repos.getServerResourcePack(); +// File file = p.resourcePackFile; +// if(file != null) +// progressFile(file); +// } +// for(ResourcePackRepository.Entry entry : list) { +// File file = new File(repos.getDirResourcepacks(),entry.getResourcePackName()); +// if(file.exists()){ +// progressFile(file); +// } +// } +// checkFolder(new File(CustomNpcs.Dir,"assets"),CustomNpcs.Dir.getAbsolutePath().length()); +// +// URL url = DefaultResourcePack.class.getResource("/"); +// if(url != null) { +// File f = decodeFile(url.getFile()); +// if(f.isDirectory()) { +// checkFolder(new File(f,"assets"), url.getFile().length()); +// } +// else { +// progressFile(f); +// } +// } +// +// url = CraftingManager.class.getResource("/assets/.mcassetsroot"); +// if(url != null) { +// File f = decodeFile(url.getFile()); +// if(f.isDirectory()) { +// checkFolder(new File(f,"assets"), url.getFile().length()); +// } +// else { +// progressFile(f); +// } +// } +// +// if(texture != null && !texture.isEmpty()){ +// selectedResource = new ResourceLocation(texture); +// selectedDomain = selectedResource.getResourceDomain(); +// if(!domains.containsKey(selectedDomain)) { +// selectedDomain = null; +// } +// int i = selectedResource.getResourcePath().lastIndexOf('/'); +// location = selectedResource.getResourcePath().substring(0, i + 1); +// if(location.startsWith("textures/")){ +// location = location.substring(9); +// } +// } +// } +// private File decodeFile(String url) { +// if(url.startsWith("file:")) { +// url = url.substring(5); +// } +// url = url.replace('/', File.separatorChar); +// int i = url.indexOf('!'); +// if(i > 0) { +// url = url.substring(0, i); +// } +// try { +// url = URLDecoder.decode(url, StandardCharsets.UTF_8.name()); +// } catch (UnsupportedEncodingException e) { +// } +// return new File(url); +// } +// +// @Override +// public void initGui(){ +// super.initGui(); +// +// if(selectedDomain != null) { +// title = selectedDomain + ":" + location; +// } +// else { +// title = ""; +// } +// +// this.addButton(new GuiNpcButton(2, guiLeft + 264, guiTop + 170, 90, 20, "gui.done")); +// this.addButton(new GuiNpcButton(1, guiLeft + 264, guiTop + 190, 90, 20, "gui.cancel")); +// +// if(scrollCategories == null){ +// scrollCategories = new GuiCustomScroll(this,0); +// scrollCategories.setSize(120, 200); +// } +// +// if(selectedDomain == null) { +// scrollCategories.setList(Lists.newArrayList(domains.keySet())); +// if(selectedDomain != null) { +// scrollCategories.setSelected(selectedDomain); +// } +// } +// else { +// List list = new ArrayList(); +// list.add(up); +// List data = domains.get(selectedDomain); +// for(TextureData td : data) { +// if(location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) { +// String path = td.path.substring(location.length()); +// int i = path.indexOf('/'); +// if(i < 0) +// continue; +// path = path.substring(0, i); +// if(!path.isEmpty() && !list.contains(path)) { +// list.add(path); +// } +// } +// } +// scrollCategories.setList(list); +// } +// scrollCategories.guiLeft = guiLeft + 4; +// scrollCategories.guiTop = guiTop + 14; +// this.addScroll(scrollCategories); +// +// if(scrollQuests == null){ +// scrollQuests = new GuiCustomScroll(this,1); +// scrollQuests.setSize(130, 200); +// } +// if(selectedDomain != null) { +// textures.clear(); +// List data = domains.get(selectedDomain); +// List list = new ArrayList(); +// String loc = location; +// if(scrollCategories.hasSelected() && !scrollCategories.getSelected().equals(up)) { +// loc += scrollCategories.getSelected() + '/'; +// } +// for(TextureData td : data) { +// if(td.path.equals(loc) && !list.contains(td.name)) { +// list.add(td.name); +// textures.put(td.name, td); +// } +// } +// scrollQuests.setList(list); +// } +// if(selectedResource != null) { +// scrollQuests.setSelected(selectedResource.getResourcePath()); +// } +// scrollQuests.guiLeft = guiLeft + 125; +// scrollQuests.guiTop = guiTop + 14; +// this.addScroll(scrollQuests); +// +// } +// +// @Override +// protected void actionPerformed(GuiButton guibutton){ +// super.actionPerformed(guibutton); +// if(guibutton.id == 2){ +// npc.display.setSkinTexture(selectedResource.toString()); +// } +// npc.textureLocation = null; +// close(); +// parent.initGui(); +// } +// +// @Override +// public void drawScreen(int i, int j, float f){ +// super.drawScreen(i, j, f); +// +// npc.textureLocation = selectedResource; +// drawNpc(npc, guiLeft + 276, guiTop + 140, 2, 0); +// } +// +// +// @Override +// public void scrollClicked(int i, int j, int k, GuiCustomScroll scroll) { +// if(scroll == scrollQuests) { +// if(scroll.id == 1){ +// TextureData data = textures.get(scroll.getSelected()); +// selectedResource = new ResourceLocation(selectedDomain, data.absoluteName); +// } +// } +// else { +// initGui(); +// } +// } +// +// @Override +// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { +// if(scroll == scrollCategories) { +// if(selectedDomain == null) { +// selectedDomain = selection; +// } +// else if(selection.equals(up)) { +// int i = location.lastIndexOf('/', location.length() - 2); +// if(i < 0) { +// if(location.isEmpty()) { +// selectedDomain = null; +// } +// location = ""; +// } +// else { +// location = location.substring(0, i + 1); +// } +// } +// else { +// location = location + selection + '/'; +// } +// scrollCategories.selected = -1; +// scrollQuests.selected = -1; +// initGui(); +// } +// else { +// npc.display.setSkinTexture(selectedResource.toString()); +// close(); +// parent.initGui(); +// } +// } +// +// private void progressFile(File file){ +// try { +// if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) +// { +// ZipFile zip = new ZipFile(file); +// Enumeration entries = zip.entries(); +// while(entries.hasMoreElements()){ +// ZipEntry zipentry = entries.nextElement(); +// String entryName = zipentry.getName(); +// addFile(entryName); +// +// } +// zip.close(); +// } +// else if(file.isDirectory()){ +// int length = file.getAbsolutePath().length(); +// checkFolder(file,length); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// private void checkFolder(File file, int length){ +// File[] files = file.listFiles(); +// if(files == null){ +// return; +// } +// for(File f : files){ +// String name = null; +// try { +// name = f.getAbsolutePath().substring(length); +// name = name.replace("\\", "/"); +// if(!name.startsWith("/")) +// name = "/" + name; +// if(f.isDirectory()){ +// addFile(name + "/"); +// checkFolder(f, length); +// } +// else +// addFile(name); +// } +// catch(Throwable e) { +// LogWriter.error("error with: " + name, e); +// } +// } +// } +// private void addFile(String name) { +// name = name.toLowerCase(); +// if(name.startsWith("/")) { +// name = name.substring(1); +// } +// if(!name.startsWith("assets/") || !name.toLowerCase().endsWith(".png")) { +// return; +// } +// name = name.substring(7); +// int i = name.indexOf('/'); +// String domain = name.substring(0, i); +// name = name.substring(i + 10); +// +// List list = domains.get(domain); +// if(list == null) { +// domains.put(domain, list = new ArrayList()); +// } +// boolean contains = false; +// for(TextureData data : list) { +// if(data.absoluteName.equals(name)) { +// contains = true; +// break; +// } +// } +// if(!contains) +// list.add(new TextureData(domain, name)); +// } +// class TextureData{ +// String domain; +// String absoluteName; +// String name; +// String path; +// public TextureData(String domain, String absoluteName) { +// this.domain = domain; +// int i = absoluteName.lastIndexOf('/'); +// name = absoluteName.substring(i + 1); +// path = absoluteName.substring(0, i + 1); +// this.absoluteName = "textures/" + absoluteName; +// } +// } +//} 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 aae79e6a6..81415e7d0 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -36,6 +36,9 @@ public class GuiCustomScroll extends GuiScreen public boolean visible = true; private boolean selectable = true; + private int lastClickedItem; + private long lastClickedTime = 0; + public GuiCustomScroll(GuiScreen parent, int id) { width = 176; @@ -274,8 +277,16 @@ public class GuiCustomScroll extends GuiScreen selected = hover; hover = -1; } - if(listener != null) - listener.customScrollClicked(i, j, k,this); + + if(listener != null) { + long time = System.currentTimeMillis(); + listener.customScrollClicked(i, j, k, this); + if(selected >= 0 && selected == lastClickedItem && time - lastClickedTime < 500) { + listener.customScrollDoubleClicked(list.get(selected), this); + } + lastClickedTime = time; + lastClickedItem = selected; + } } private void drawScrollBar() diff --git a/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java b/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java index b761c0c8f..d47a0f5ab 100644 --- a/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java +++ b/src/main/java/noppes/npcs/client/gui/util/ICustomScrollListener.java @@ -6,4 +6,5 @@ public interface ICustomScrollListener { void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll); + default void customScrollDoubleClicked(String selection, GuiCustomScroll scroll){} } From 0e6932587607bc6a30cf66a51717351eceb07a86 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 01:58:56 -0400 Subject: [PATCH 07/13] Revert "Double the Compressed Sizes of Packets" This reverts commit f605bb932546ca4da54f307d962bedf1947e2707. --- src/main/java/noppes/npcs/Server.java | 68 ++++++--------------------- 1 file changed, 15 insertions(+), 53 deletions(-) diff --git a/src/main/java/noppes/npcs/Server.java b/src/main/java/noppes/npcs/Server.java index 3331dc1d6..ea7bbd697 100644 --- a/src/main/java/noppes/npcs/Server.java +++ b/src/main/java/noppes/npcs/Server.java @@ -14,11 +14,9 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.village.MerchantRecipeList; import noppes.npcs.constants.EnumPacketClient; -import java.io.*; +import java.io.IOException; import java.util.List; import java.util.Map; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; public class Server { @@ -100,60 +98,24 @@ public class Server { else if(ob instanceof NBTTagCompound) writeNBT(buffer, (NBTTagCompound) ob); } -// if(buffer.array().length >= 32767){ -// LogWriter.error("Packet " + enu + " was too big to be send"); -// return false; -// } - if(buffer.array().length >= Short.MAX_VALUE * 2){ - LogWriter.error("Packet " + enu + " was too big to be send"); - return false; - } - + if(buffer.array().length >= 32767){ + LogWriter.error("Packet " + enu + " was too big to be send"); + return false; + } return true; } -// public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException { -// byte[] bytes = CompressedStreamTools.compress(compound); -// buffer.writeShort((short)bytes.length); -// buffer.writeBytes(bytes); -// } + public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException { + byte[] bytes = CompressedStreamTools.compress(compound); + buffer.writeShort((short)bytes.length); + buffer.writeBytes(bytes); + } - -// public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException { -// byte[] bytes = new byte[buffer.readShort()]; -// buffer.readBytes(bytes); -// return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); -// } - - - public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException { - ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); - DataOutputStream dataoutputstream = new DataOutputStream(new GZIPOutputStream(bytearrayoutputstream)); - - try - { - CompressedStreamTools.write(compound, dataoutputstream); - } - finally - { - dataoutputstream.close(); - } - byte[] bytes = bytearrayoutputstream.toByteArray(); - buffer.writeInt(bytes.length); - buffer.writeBytes(bytes); - } - - public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException { - byte[] bytes = new byte[buffer.readInt()]; - buffer.readBytes(bytes); - DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)))); - try{ - return CompressedStreamTools.func_152457_a(bytes, NBTSizeTracker.field_152451_a); - } - finally{ - datainputstream.close(); - } - } + public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException { + byte[] bytes = new byte[buffer.readShort()]; + buffer.readBytes(bytes); + return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L)); + } public static void writeString(ByteBuf buffer, String s){ byte[] bytes = s.getBytes(Charsets.UTF_8); From cf48671315653016794a28d0981cbc4ba78e2a40 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 15:20:49 -0400 Subject: [PATCH 08/13] Fix Variable Names in QuestCat and DialogCat --- .../npcs/controllers/data/DialogCategory.java | 16 ++++++------ .../npcs/controllers/data/QuestCategory.java | 25 ++++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/noppes/npcs/controllers/data/DialogCategory.java b/src/main/java/noppes/npcs/controllers/data/DialogCategory.java index 3c6267ee8..27e02684e 100644 --- a/src/main/java/noppes/npcs/controllers/data/DialogCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/DialogCategory.java @@ -14,15 +14,15 @@ public class DialogCategory implements IDialogCategory { public int id = -1; public String title = ""; public HashMap dialogs; - + public DialogCategory(){ dialogs = new HashMap(); } - + public void readNBT(NBTTagCompound compound){ id = compound.getInteger("Slot"); title = compound.getString("Title"); - + NBTTagList dialogsList = compound.getTagList("Dialogs", 10); if(dialogsList != null){ for(int ii = 0; ii < dialogsList.tagCount(); ii++) @@ -37,15 +37,15 @@ public class DialogCategory implements IDialogCategory { } } - public NBTTagCompound writeNBT(NBTTagCompound nbtfactions) { - nbtfactions.setInteger("Slot", id); - nbtfactions.setString("Title", title); + public NBTTagCompound writeNBT(NBTTagCompound dialogCat) { + dialogCat.setInteger("Slot", id); + dialogCat.setString("Title", title); NBTTagList dialogs = new NBTTagList(); for(Dialog dialog : this.dialogs.values()){ dialogs.appendTag(dialog.writeToNBT(new NBTTagCompound())); } - nbtfactions.setTag("Dialogs", dialogs); - return nbtfactions; + dialogCat.setTag("Dialogs", dialogs); + return dialogCat; } public List dialogs() { diff --git a/src/main/java/noppes/npcs/controllers/data/QuestCategory.java b/src/main/java/noppes/npcs/controllers/data/QuestCategory.java index 05d0806b1..a9086efb2 100644 --- a/src/main/java/noppes/npcs/controllers/data/QuestCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/QuestCategory.java @@ -13,7 +13,7 @@ public class QuestCategory implements IQuestCategory { public HashMap quests; public int id = -1; public String title = ""; - + public QuestCategory(){ quests = new HashMap(); } @@ -21,11 +21,11 @@ public class QuestCategory implements IQuestCategory { public void readNBT(NBTTagCompound nbttagcompound) { id = nbttagcompound.getInteger("Slot"); title = nbttagcompound.getString("Title"); - NBTTagList dialogsList = nbttagcompound.getTagList("Dialogs", 10); - if(dialogsList != null){ - for(int ii = 0; ii < dialogsList.tagCount(); ii++) + NBTTagList questList = nbttagcompound.getTagList("Quests", 10); + if(questList != null){ + for(int ii = 0; ii < questList.tagCount(); ii++) { - NBTTagCompound nbttagcompound2 = dialogsList.getCompoundTagAt(ii); + NBTTagCompound nbttagcompound2 = questList.getCompoundTagAt(ii); Quest quest = new Quest(); quest.readNBT(nbttagcompound2); quest.category = this; @@ -37,16 +37,17 @@ public class QuestCategory implements IQuestCategory { public NBTTagCompound writeNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setInteger("Slot", id); nbttagcompound.setString("Title", title); - NBTTagList dialogs = new NBTTagList(); - for(int dialogId : quests.keySet()){ - Quest quest = quests.get(dialogId); - dialogs.appendTag(quest.writeToNBT(new NBTTagCompound())); + NBTTagList quests = new NBTTagList(); + for(int questID : this.quests.keySet()){ + Quest quest = this.quests.get(questID); + quests.appendTag(quest.writeToNBT(new NBTTagCompound())); } - - nbttagcompound.setTag("Dialogs", dialogs); - + + nbttagcompound.setTag("Quests", quests); + return nbttagcompound; } + public List quests() { return new ArrayList(this.quests.values()); From 487512368545e3a2b6067a2bf8b38ca8815e1a38 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 17:19:54 -0400 Subject: [PATCH 09/13] Fix Overlap Mouse Clicked --- .../npcs/client/gui/util/GuiNPCInterface2.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java index dfb5c767a..da766c681 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface2.java @@ -8,7 +8,7 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface { private ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png"); private GuiNpcMenu menu; - + public GuiNPCInterface2(EntityNPCInterface npc){ this(npc, -1); } @@ -17,29 +17,29 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface xSize = 420; ySize = 200; menu = new GuiNpcMenu(this, activeMenu, npc); - + } @Override public void initGui(){ super.initGui(); menu.initGui(guiLeft, guiTop, xSize); } - + @Override public void mouseClicked(int i, int j, int k){ - super.mouseClicked(i, j, k); if(!hasSubGui()) menu.mouseClicked(i, j, k); - } - + super.mouseClicked(i, j, k); + } + public void delete(){ npc.delete(); displayGuiScreen(null); mc.setIngameFocus(); } public abstract void save(); - + @Override public void drawScreen(int i, int j, float f) { @@ -47,7 +47,7 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface drawDefaultBackground(); //drawDefaultBackground drawBackground(); menu.drawElements(getFontRenderer(), i, j, mc, f); - + boolean bo = drawDefaultBackground; drawDefaultBackground = false; super.drawScreen(i, j, f); From 14b430089ed995c7d8db6d537f9f81388a11ba9c Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 21:03:08 -0400 Subject: [PATCH 10/13] GuiSoundSelection Scroll with Search Bars and Buttons --- .../client/gui/select/GuiSoundSelection.java | 93 +++++++++++++++---- .../npcs/client/gui/util/GuiCustomScroll.java | 4 + 2 files changed, 78 insertions(+), 19 deletions(-) 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; + } } From b3846e32c868f4426de3bf8b4d7efb076051fe89 Mon Sep 17 00:00:00 2001 From: Kam Date: Tue, 12 Mar 2024 21:36:14 -0400 Subject: [PATCH 11/13] Revamp Sound Selection Menu --- .../npcs/client/gui/GuiNPCLinesEdit.java | 82 ++++++----- .../npcs/client/gui/GuiNpcSoundSelection.java | 139 ------------------ .../npcs/client/gui/SubGuiNpcDialog.java | 22 +-- .../client/gui/SubGuiNpcRangeProperties.java | 29 ++-- .../client/gui/SubGuiNpcSoundSelection.java | 135 ----------------- .../client/gui/advanced/GuiNPCSoundsMenu.java | 40 ++--- .../npcs/client/gui/roles/GuiNpcBard.java | 7 - .../gui/roles/SubGuiNpcConversationLine.java | 34 +++-- 8 files changed, 108 insertions(+), 380 deletions(-) delete mode 100644 src/main/java/noppes/npcs/client/gui/GuiNpcSoundSelection.java delete mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcSoundSelection.java diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java b/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java index 8c3de8c99..aeb594147 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCLinesEdit.java @@ -4,10 +4,8 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.util.GuiNPCInterface2; -import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.client.gui.util.GuiNpcTextField; -import noppes.npcs.client.gui.util.IGuiData; +import noppes.npcs.client.gui.select.GuiSoundSelection; +import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.data.Lines; @@ -15,12 +13,12 @@ import noppes.npcs.entity.EntityNPCInterface; import java.util.HashMap; -public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData +public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData, ISubGuiListener, ITextfieldListener { private Lines lines; - private GuiNpcTextField field; - private GuiNpcSoundSelection gui; - + private int selectedId = -1; + private GuiSoundSelection gui; + public GuiNPCLinesEdit(EntityNPCInterface npc, Lines lines) { super(npc); @@ -35,57 +33,63 @@ public class GuiNPCLinesEdit extends GuiNPCInterface2 implements IGuiData String text = ""; String sound = ""; if(lines.lines.containsKey(i)){ - Line line = lines.lines.get(i); - text = line.text; - sound = line.sound; + Line line = lines.lines.get(i); + text = line.getText(); + sound = line.getSound(); } addTextField(new GuiNpcTextField(i,this, fontRendererObj, guiLeft + 4, guiTop + 4 + i * 24, 200, 20,text)); addTextField(new GuiNpcTextField(i + 8,this, fontRendererObj, guiLeft + 208, guiTop + 4 + i * 24, 146, 20,sound)); addButton(new GuiNpcButton(i, guiLeft + 358, guiTop + 4 + i * 24, 60, 20, "gui.select")); } - } protected void actionPerformed(GuiButton guibutton) { - GuiNpcButton button = (GuiNpcButton) guibutton; - field = getTextField(button.id + 8); - gui = new GuiNpcSoundSelection(this, field.getText()); - NoppesUtil.openGUI(player, gui); + GuiNpcButton button = (GuiNpcButton) guibutton; + selectedId = button.id + 8; + setSubGui(new GuiSoundSelection(getTextField(selectedId).getText())); } - @Override - public void elementClicked() { - field.setText(gui.getSelected()); - saveLines(); - } - @Override public void setGuiData(NBTTagCompound compound) { npc.advanced.readToNBT(compound); initGui(); } - - private void saveLines(){ - HashMap lines = new HashMap(); - for(int i = 0; i < 8; i++){ - GuiNpcTextField tf = getTextField(i); - GuiNpcTextField tf2 = getTextField(i + 8); - if(!tf.isEmpty()){ - Line line = new Line(); - line.text = tf.getText(); - line.sound = tf2.getText(); - lines.put(i, line); - } - - } - this.lines.lines = lines; - } - + + private void saveLines(){ + HashMap lines = new HashMap(); + for(int i = 0; i < 8; i++){ + GuiNpcTextField tf = getTextField(i); + GuiNpcTextField tf2 = getTextField(i + 8); + if(!tf.isEmpty() || !tf2.isEmpty()){ + Line line = new Line(); + line.setText(tf.getText()); + line.setSound(tf2.getText()); + lines.put(i, line); + } + + } + this.lines.lines = lines; + } + public void save() { saveLines(); Client.sendData(EnumPacketServer.MainmenuAdvancedSave, npc.advanced.writeToNBT(new NBTTagCompound())); } + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + getTextField(selectedId).setText(gss.selectedResource.toString()); + saveLines(); + initGui(); + } + } + @Override + public void unFocused(GuiNpcTextField textfield) { + saveLines(); + initGui(); + } } diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcSoundSelection.java b/src/main/java/noppes/npcs/client/gui/GuiNpcSoundSelection.java deleted file mode 100644 index cf0aa4412..000000000 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcSoundSelection.java +++ /dev/null @@ -1,139 +0,0 @@ -package noppes.npcs.client.gui; - -import cpw.mods.fml.common.ObfuscationReflectionHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.SoundHandler; -import net.minecraft.client.audio.SoundRegistry; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.gui.util.*; - -import java.util.*; - -public class GuiNpcSoundSelection extends GuiNPCInterface { - - public GuiNPCStringSlot slot; - public String domain; - private final GuiScreen parent; - public GuiSelectionListener listener; - - private String up = "..<" + StatCollector.translateToLocal("gui.up") + ">.."; - - private HashMap> domains = new HashMap>(); - - public GuiNpcSoundSelection(GuiScreen parent, String sound) - { - SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); - SoundRegistry registry = ObfuscationReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4); - - Set set = registry.getKeys(); - for(ResourceLocation location : set){ - List list = domains.get(location.getResourceDomain()); - if(list == null) - domains.put(location.getResourceDomain(), list = new ArrayList()); - list.add(location.getResourcePath()); - domains.put(location.getResourceDomain(), list); - } - drawDefaultBackground = false; - this.parent = parent; - if(parent instanceof GuiSelectionListener) - listener = (GuiSelectionListener) parent; - } - - public void initGui() - { - super.initGui(); - String ss = "Current domain: " + domain; - if(domain == null) - ss = "Select domain"; - addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff)); - - Collection col = domains.keySet(); - - if(domain != null){ - col = domains.get(domain); - if(!col.contains(up)) - col.add(up); - } - slot = new GuiNPCStringSlot(col, this, false, 18); - slot.registerScrollButtons(4, 5); - if(domain != null){ - this.addButton(new GuiNpcButton(1, width / 2 - 100, height - 27,198, 20, "gui.play")); - this.addButton(new GuiNpcButton(3, width / 2 - 100, height - 50,98, 20, "gui.done")); - } - else - this.addButton(new GuiNpcButton(4, width / 2 - 100, height - 50,98, 20, "gui.open")); - - this.addButton(new GuiNpcButton(2, width / 2 + 2, height - 50,98, 20, "gui.cancel")); - } - - public void drawScreen(int i, int j, float f) - { - slot.drawScreen(i, j, f); - super.drawScreen(i, j, f); - } - - public void doubleClicked() { - if(slot.selected == null || slot.selected.isEmpty()) - return; - if(slot.selected.equals(up)){ - domain = null; - initGui(); - } - else if(domain == null){ - domain = slot.selected; - initGui(); - } - else{ - if(parent instanceof GuiNPCInterface){ - ((GuiNPCInterface)parent).elementClicked(); - } - else if(this.parent instanceof GuiNPCInterface2){ - ((GuiNPCInterface2)parent).elementClicked(); - } - close(); - NoppesUtil.openGUI(player, parent); - } - } - - protected void actionPerformed(GuiButton guibutton) - { - super.actionPerformed(guibutton); - if(guibutton.id == 1){ - MusicController.Instance.stopMusic(); - MusicController.Instance.playSound(getSelected(), (float)player.posX, (float)player.posY, (float)player.posZ); - } - if(guibutton.id == 2){ - close(); - NoppesUtil.openGUI(player, parent); - } - if(guibutton.id == 3){ - if(slot.selected == null || slot.selected.equals(up)) - return; - doubleClicked(); - } - if(guibutton.id == 4){ - doubleClicked(); - } - } - public void save() { - - } - public void close() { - this.save(); - super.close(); - } - - - - public String getSelected(){ - if(slot.selected == null || slot.selected.isEmpty()) - return ""; - return domain + ":" + slot.selected; - } - -} diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java index 67b1e861b..a1dd989da 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java @@ -6,6 +6,7 @@ import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.global.GuiNPCManageDialogs; import noppes.npcs.client.gui.global.GuiNPCQuestSelection; +import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.Dialog; @@ -17,7 +18,6 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, public int dialogCategoryID; public Dialog dialog; private final GuiNPCManageDialogs parent; - private GuiNpcSoundSelection gui; private GuiNPCQuestSelection questSelection; public SubGuiNpcDialog(GuiNPCManageDialogs parent, Dialog dialog, int catId) @@ -79,7 +79,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, if(!dialog.mail.subject.isEmpty()) getButton(13).setDisplayText(dialog.mail.subject); } - + public void buttonEvent(GuiButton guibutton) { int id = guibutton.id; @@ -106,9 +106,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, initGui(); } if(id == 9 && dialog.id >= 0){ - gui = new GuiNpcSoundSelection(getParent(), getTextField(2).getText()); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiSoundSelection((getTextField(2).getText()))); } if(id == 10){ setSubGui(new SubGuiNpcCommand(dialog.command)); @@ -169,12 +167,14 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, else if(subgui instanceof SubGuiMailmanSendSetup){ initGui(); } - } - - @Override - public void elementClicked(){ - getTextField(2).setText(gui.getSelected()); - unFocused(getTextField(2)); + else if (subgui instanceof GuiSoundSelection){ + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + getTextField(2).setText(gss.selectedResource.toString()); + unFocused(getTextField(2)); + initGui(); + } + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java index 364eec0b6..3e0b73c0d 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcRangeProperties.java @@ -3,12 +3,13 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; import noppes.npcs.DataStats; import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; -public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfieldListener +public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfieldListener, ISubGuiListener { private DataStats stats; - private GuiNpcSoundSelection gui; + private GuiNpcTextField soundSelected = null; public SubGuiNpcRangeProperties(DataStats stats) { @@ -112,20 +113,13 @@ public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfi } } - @Override - public void elementClicked(){ - getTextField(7).setText(gui.getSelected()); - unFocused(getTextField(7)); - } - @Override protected void actionPerformed(GuiButton guibutton){ int id = guibutton.id; - if(id == 7) - { - gui = new GuiNpcSoundSelection(parent, getTextField(7).getText()); - NoppesUtil.openGUI(player, gui); - } + if(id == 7){ + soundSelected = getTextField(7); + setSubGui(new GuiSoundSelection(soundSelected.getText())); + } if(id == 66) { close(); @@ -134,4 +128,13 @@ public class SubGuiNpcRangeProperties extends SubGuiInterface implements ITextfi stats.aimWhileShooting = ((GuiNpcButtonYesNo)guibutton).getBoolean(); } } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + soundSelected.setText(gss.selectedResource.toString()); + unFocused(soundSelected); + } + } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcSoundSelection.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcSoundSelection.java deleted file mode 100644 index 10e4d2734..000000000 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcSoundSelection.java +++ /dev/null @@ -1,135 +0,0 @@ -package noppes.npcs.client.gui; - -import cpw.mods.fml.common.ObfuscationReflectionHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.audio.SoundHandler; -import net.minecraft.client.audio.SoundRegistry; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; -import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.gui.util.*; - -import java.util.*; - -public class SubGuiNpcSoundSelection extends SubGuiInterface { - - public GuiNPCStringSlot slot; - public String domain; - private final GuiScreen parent; - public GuiSelectionListener listener; - - private String up = "..<" + StatCollector.translateToLocal("gui.up") + ">.."; - - private HashMap> domains = new HashMap>(); - - public SubGuiNpcSoundSelection(GuiScreen parent, String sound) - { - SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); - SoundRegistry registry = ObfuscationReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4); - - Set set = registry.getKeys(); - for(ResourceLocation location : set){ - List list = domains.get(location.getResourceDomain()); - if(list == null) - domains.put(location.getResourceDomain(), list = new ArrayList()); - list.add(location.getResourcePath()); - domains.put(location.getResourceDomain(), list); - } - drawDefaultBackground = false; - this.parent = parent; - if(parent instanceof GuiSelectionListener) - listener = (GuiSelectionListener) parent; - } - - public void initGui() - { - super.initGui(); - String ss = "Current domain: " + domain; - if(domain == null) - ss = "Select domain"; - addLabel(new GuiNpcLabel(0,ss, width / 2 - (this.fontRendererObj.getStringWidth(ss)/2), 20, 0xffffff)); - - Collection col = domains.keySet(); - - if(domain != null){ - col = domains.get(domain); - if(!col.contains(up)) - col.add(up); - } - slot = new GuiNPCStringSlot(col, this, false, 18); - slot.registerScrollButtons(4, 5); - if(domain != null){ - this.addButton(new GuiNpcButton(1, width / 2 - 100, height - 27,198, 20, "gui.play")); - this.addButton(new GuiNpcButton(3, width / 2 - 100, height - 50,98, 20, "gui.done")); - } - else - this.addButton(new GuiNpcButton(4, width / 2 - 100, height - 50,98, 20, "gui.open")); - - this.addButton(new GuiNpcButton(2, width / 2 + 2, height - 50,98, 20, "gui.cancel")); - } - - public void drawScreen(int i, int j, float f) - { - slot.drawScreen(i, j, f); - super.drawScreen(i, j, f); - } - - public void doubleClicked() { - if(slot.selected == null || slot.selected.isEmpty()) - return; - if(slot.selected.equals(up)){ - domain = null; - initGui(); - } - else if(domain == null){ - domain = slot.selected; - initGui(); - } - else{ - if(parent instanceof GuiNPCInterface){ - ((GuiNPCInterface)parent).elementClicked(); - } - else if(this.parent instanceof GuiNPCInterface2){ - ((GuiNPCInterface2)parent).elementClicked(); - } - close(); - } - } - - protected void actionPerformed(GuiButton guibutton) - { - super.actionPerformed(guibutton); - if(guibutton.id == 1){ - MusicController.Instance.stopMusic(); - MusicController.Instance.playSound(getSelected(), (float)player.posX, (float)player.posY, (float)player.posZ); - } - if(guibutton.id == 2){ - close(); - } - if(guibutton.id == 3){ - if(slot.selected == null || slot.selected.equals(up)) - return; - doubleClicked(); - } - if(guibutton.id == 4){ - doubleClicked(); - } - } - public void save() { - - } - - public void close() { - this.save(); - super.close(); - } - - public String getSelected(){ - if(slot.selected == null || slot.selected.isEmpty()) - return ""; - return domain + ":" + slot.selected; - } - -} diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java index c178aff07..e9d69eb0d 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCSoundsMenu.java @@ -3,15 +3,13 @@ package noppes.npcs.client.gui.advanced; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNpcSoundSelection; +import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; -public class GuiNPCSoundsMenu extends GuiNPCInterface2 implements ITextfieldListener +public class GuiNPCSoundsMenu extends GuiNPCInterface2 implements ITextfieldListener, ISubGuiListener { - private GuiNpcSoundSelection gui; private GuiNpcTextField selectedField; public GuiNPCSoundsMenu(EntityNPCInterface npc){ super(npc); @@ -23,37 +21,36 @@ public class GuiNPCSoundsMenu extends GuiNPCInterface2 implements ITextfieldList addLabel(new GuiNpcLabel(0,"advanced.idlesound", guiLeft + 5, guiTop + 20)); addTextField(new GuiNpcTextField(0,this, fontRendererObj, guiLeft + 80, guiTop + 15, 200, 20, npc.advanced.idleSound)); addButton(new GuiNpcButton(0, guiLeft + 290, guiTop + 15, 80, 20, "gui.selectSound")); - + addLabel(new GuiNpcLabel(2,"advanced.angersound", guiLeft + 5, guiTop + 45)); addTextField(new GuiNpcTextField(2,this, fontRendererObj, guiLeft + 80, guiTop + 40, 200, 20, npc.advanced.angrySound)); addButton(new GuiNpcButton(2, guiLeft + 290, guiTop + 40, 80, 20, "gui.selectSound")); - + addLabel(new GuiNpcLabel(3,"advanced.hurtsound", guiLeft + 5, guiTop + 70)); addTextField(new GuiNpcTextField(3,this, fontRendererObj, guiLeft + 80, guiTop + 65, 200, 20, npc.advanced.hurtSound)); addButton(new GuiNpcButton(3, guiLeft + 290, guiTop + 65, 80, 20, "gui.selectSound")); - + addLabel(new GuiNpcLabel(4,"advanced.deathsound", guiLeft + 5, guiTop + 95)); addTextField(new GuiNpcTextField(4,this, fontRendererObj, guiLeft + 80, guiTop + 90, 200, 20, npc.advanced.deathSound)); addButton(new GuiNpcButton(4, guiLeft + 290, guiTop + 90, 80, 20, "gui.selectSound")); - + addLabel(new GuiNpcLabel(5,"advanced.stepsound", guiLeft + 5, guiTop + 120)); addTextField(new GuiNpcTextField(5,this, fontRendererObj, guiLeft + 80, guiTop + 115, 200, 20, npc.advanced.stepSound)); addButton(new GuiNpcButton(5, guiLeft + 290, guiTop + 115, 80, 20, "gui.selectSound")); addLabel(new GuiNpcLabel(6,"advanced.haspitch", guiLeft + 5, guiTop + 150)); addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 145, 80, 20, new String[]{"gui.no","gui.yes"}, npc.advanced.disablePitch?0:1)); - + } public void buttonEvent(GuiButton button){ if(button.id == 6) npc.advanced.disablePitch =((GuiNpcButton)button).getValue() == 0; else{ - selectedField = getTextField(button.id); - gui = new GuiNpcSoundSelection(this, selectedField.getText()); - NoppesUtil.openGUI(player, gui); + selectedField = getTextField(button.id); + setSubGui(new GuiSoundSelection(selectedField.getText())); } - + } @Override public void unFocused(GuiNpcTextField textfield) { @@ -68,13 +65,16 @@ public class GuiNPCSoundsMenu extends GuiNPCInterface2 implements ITextfieldList if(textfield.id == 5) npc.advanced.stepSound = textfield.getText(); } - - @Override - public void elementClicked(){ - selectedField.setText(gui.getSelected()); - unFocused(selectedField); - } - + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + selectedField.setText(gss.selectedResource.toString()); + unFocused(selectedField); + } + } + @Override public void save() { Client.sendData(EnumPacketServer.MainmenuAdvancedSave, npc.advanced.writeToNBT(new NBTTagCompound())); diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java index 3b5549f15..c643fc8a7 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcBard.java @@ -3,9 +3,7 @@ package noppes.npcs.client.gui.roles; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.controllers.MusicController; -import noppes.npcs.client.gui.GuiNpcSoundSelection; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; @@ -15,7 +13,6 @@ import noppes.npcs.roles.JobBard; public class GuiNpcBard extends GuiNPCInterface2 implements ISubGuiListener { private JobBard job; - private GuiNpcSoundSelection gui; public GuiNpcBard(EntityNPCInterface npc) { @@ -52,10 +49,6 @@ public class GuiNpcBard extends GuiNPCInterface2 implements ISubGuiListener getTextField(3).enabled = job.hasOffRange; } - @Override - public void elementClicked(){ - job.song = gui.getSelected(); - } protected void actionPerformed(GuiButton guibutton) { diff --git a/src/main/java/noppes/npcs/client/gui/roles/SubGuiNpcConversationLine.java b/src/main/java/noppes/npcs/client/gui/roles/SubGuiNpcConversationLine.java index 3aea5fa27..9d39db086 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/SubGuiNpcConversationLine.java +++ b/src/main/java/noppes/npcs/client/gui/roles/SubGuiNpcConversationLine.java @@ -1,15 +1,13 @@ package noppes.npcs.client.gui.roles; import net.minecraft.client.gui.GuiButton; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNpcSoundSelection; +import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; -public class SubGuiNpcConversationLine extends SubGuiInterface implements ITextfieldListener{ +public class SubGuiNpcConversationLine extends SubGuiInterface implements ITextfieldListener, ISubGuiListener { public String line; public String sound; - private GuiNpcSoundSelection gui; - + public SubGuiNpcConversationLine(String line, String sound){ this.line = line; this.sound = sound; @@ -21,31 +19,27 @@ public class SubGuiNpcConversationLine extends SubGuiInterface implements ITextf public void initGui(){ super.initGui(); - + addLabel(new GuiNpcLabel(0, "Line", guiLeft + 4, guiTop+ 10)); addTextField(new GuiNpcTextField(0, this, fontRendererObj, guiLeft + 4, guiTop + 22, 200, 20, line)); addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + 55, 90, 20, "Select Sound")); addButton(new GuiNpcButton(2, guiLeft + 96, guiTop + 55, 20, 20, "X")); addLabel(new GuiNpcLabel(1, sound, guiLeft + 4, guiTop + 81)); - + addButton(new GuiNpcButton(66, guiLeft + 162, guiTop + 192, 90, 20, "gui.done")); } - public void unFocused(GuiNpcTextField textfield) { - line = textfield.getText(); - } + @Override + public void unFocused(GuiNpcTextField textfield) { + line = textfield.getText(); + } @Override - public void elementClicked(){ - sound = gui.getSelected(); - } - protected void actionPerformed(GuiButton guibutton){ int id = guibutton.id; if(id == 1){ - gui = new GuiNpcSoundSelection(parent, sound); - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiSoundSelection(sound)); } if(id == 2){ sound = ""; @@ -56,4 +50,12 @@ public class SubGuiNpcConversationLine extends SubGuiInterface implements ITextf } } + @Override + public void subGuiClosed(SubGuiInterface subgui) { + GuiSoundSelection gss = (GuiSoundSelection) subgui; + if(gss.selectedResource != null) { + sound = gss.selectedResource.toString(); + } + } + } From 8c3b46d4f410083f6492ca1840e869a2835206bf Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 13 Mar 2024 03:33:46 -0400 Subject: [PATCH 12/13] Smaller Sync Packets for Quest / Dialog / Faction Data --- .../gui/global/GuiNPCManageDialogs.java | 5 - .../client/gui/global/GuiNPCManageQuest.java | 7 +- .../java/noppes/npcs/config/ConfigMain.java | 24 ++ .../java/noppes/npcs/constants/SyncType.java | 4 +- .../npcs/controllers/DialogController.java | 2 +- .../npcs/controllers/QuestController.java | 4 +- .../npcs/controllers/RecipeController.java | 4 - .../npcs/controllers/SyncController.java | 288 +++++++++++++----- .../npcs/controllers/data/DialogCategory.java | 11 + .../npcs/controllers/data/QuestCategory.java | 12 +- 10 files changed, 267 insertions(+), 94 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 8eb6abc88..7bf3ed03a 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -157,7 +157,6 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou int id = guibutton.id; // Edit Cat if(id == 6){ - saveType(false); if(category != null && category.id > -1){ setSubGui(new SubGuiEditText(category.title)); } @@ -167,7 +166,6 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou } // Add Cat if(id == 4){ - saveType(false); String name = "New"; while(catData.containsKey(name)) name += "_"; @@ -181,7 +179,6 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou } // Remove Cat if(id == 5){ - saveType(false); if(catData.containsKey(catScroll.getSelected())) { Client.sendData(EnumPacketServer.DialogCategoryRemove, category.id); clearCategory(); @@ -323,12 +320,10 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { if(guiCustomScroll.id == 0) { - saveType(false); getCategory(false); } if(guiCustomScroll.id == 1) { - saveType(false); getDialog(false); } } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java index 17b081ba4..11c292d66 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java @@ -161,7 +161,6 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, int id = guibutton.id; // Edit Cat if(id == 6){ - saveType(false); if(category != null && category.id > -1){ setSubGui(new SubGuiEditText(category.title)); } @@ -171,7 +170,6 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, } // Add Cat if(id == 4){ - saveType(false); String name = "New"; while(catData.containsKey(name)) name += "_"; @@ -185,7 +183,6 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, } // Remove Cat if(id == 5){ - saveType(false); if(catData.containsKey(catScroll.getSelected())) { Client.sendData(EnumPacketServer.QuestCategoryRemove, category.id); clearCategory(); @@ -302,7 +299,7 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, catData.put(category.title, category.id); catScroll.replace(old,category.title); } - saveType(false); + saveType(false); } } } @@ -327,12 +324,10 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { if(guiCustomScroll.id == 0) { - saveType(false); getCategory(false); } if(guiCustomScroll.id == 1) { - saveType(false); getQuest(false); } } diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index dd5f6e407..50a3ec37e 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -16,6 +16,7 @@ public class ConfigMain public final static String GENERAL = "General"; public final static String NPC = "NPC"; public final static String UPDATE = "Update"; + public final static String SYNC = "SYNC"; /** * General Main Properties @@ -110,6 +111,19 @@ public class ConfigMain public static Property TrackedQuestUpdateFrequencyProperty; public static int TrackedQuestUpdateFrequency = 5; + /** + * Sync Properties + **/ + + public static Property SyncQuestAutoProperty; + public static boolean SyncQuestAuto = true; + + public static Property SyncDialogAutoProperty; + public static boolean SyncDialogAuto = true; + + public static Property SyncFactionAutoProperty; + public static boolean SyncFactionAuto = true; + public static void init(File configFile) { config = new Configuration(configFile); @@ -202,6 +216,16 @@ public class ConfigMain TrackedQuestUpdateFrequencyProperty = config.get(UPDATE, "Tracked Quest Update Frequency", 5, "How often in seconds to update a players tracked quest. [Only applies to Item Quest currently]"); TrackedQuestUpdateFrequency = TrackedQuestUpdateFrequencyProperty.getInt(5); + // Sync + SyncQuestAutoProperty = config.get(SYNC, "Auto Sync Quest Data", true, "If enabled client will all Quest Data upon joining the world"); + SyncQuestAuto = SyncQuestAutoProperty.getBoolean(true); + + SyncDialogAutoProperty = config.get(SYNC, "Auto Sync Dialog Data", true, "If enabled client will all Dialog Data upon joining the world"); + SyncDialogAuto = SyncDialogAutoProperty.getBoolean(true); + + SyncFactionAutoProperty = config.get(SYNC, "Auto Sync Faction Data", true, "If enabled client will all Faction Data upon joining the world"); + SyncFactionAuto = SyncFactionAutoProperty.getBoolean(true); + // Convert to Legacy if(CustomNpcs.legacyExist){ EnableUpdateChecker = LegacyConfig.EnableUpdateChecker; diff --git a/src/main/java/noppes/npcs/constants/SyncType.java b/src/main/java/noppes/npcs/constants/SyncType.java index 031f73bc5..9cbdc289d 100644 --- a/src/main/java/noppes/npcs/constants/SyncType.java +++ b/src/main/java/noppes/npcs/constants/SyncType.java @@ -6,7 +6,5 @@ public class SyncType { public static final int QUEST_CATEGORY = 3; public static final int DIALOG = 4; public static final int DIALOG_CATEGORY = 5; - public static final int RECIPE_NORMAL = 6; - public static final int RECIPE_CARPENTRY = 7; - public static final int PLAYER_DATA = 8; + public static final int PLAYER_DATA = 6; } diff --git a/src/main/java/noppes/npcs/controllers/DialogController.java b/src/main/java/noppes/npcs/controllers/DialogController.java index e63bc8188..b25f88c91 100644 --- a/src/main/java/noppes/npcs/controllers/DialogController.java +++ b/src/main/java/noppes/npcs/controllers/DialogController.java @@ -230,7 +230,7 @@ public class DialogController implements IDialogHandler { dir.mkdirs(); } categories.put(category.id, category); - Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound())); + SyncController.updateDialogCat(category); } public void removeCategory(int category){ diff --git a/src/main/java/noppes/npcs/controllers/QuestController.java b/src/main/java/noppes/npcs/controllers/QuestController.java index f7441b784..e8ec57f7d 100644 --- a/src/main/java/noppes/npcs/controllers/QuestController.java +++ b/src/main/java/noppes/npcs/controllers/QuestController.java @@ -177,8 +177,8 @@ public class QuestController implements IQuestHandler { dir.mkdirs(); } categories.put(category.id, category); - Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound())); - } + SyncController.updateQuestCat(category); + } private boolean containsCategoryName(String name) { name = name.toLowerCase(); for(QuestCategory cat : categories.values()){ diff --git a/src/main/java/noppes/npcs/controllers/RecipeController.java b/src/main/java/noppes/npcs/controllers/RecipeController.java index 8fdec5df3..639c746ce 100644 --- a/src/main/java/noppes/npcs/controllers/RecipeController.java +++ b/src/main/java/noppes/npcs/controllers/RecipeController.java @@ -208,10 +208,6 @@ public class RecipeController implements IRecipeHandler { return null; globalRecipes.remove(recipe.id); anvilRecipes.remove(recipe.id); - if(recipe.isGlobal) - Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.RECIPE_NORMAL, id); - else - Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.RECIPE_CARPENTRY, id); saveCategories(); reloadGlobalRecipes(globalRecipes); return recipe; diff --git a/src/main/java/noppes/npcs/controllers/SyncController.java b/src/main/java/noppes/npcs/controllers/SyncController.java index 2265a6971..ad702bc80 100644 --- a/src/main/java/noppes/npcs/controllers/SyncController.java +++ b/src/main/java/noppes/npcs/controllers/SyncController.java @@ -4,14 +4,11 @@ import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import noppes.npcs.CustomNpcs; -import noppes.npcs.NBTTags; import noppes.npcs.Server; +import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.SyncType; import noppes.npcs.controllers.data.*; -import noppes.npcs.items.ItemScripted; import java.util.HashMap; @@ -21,58 +18,77 @@ public class SyncController { NBTTagList list = new NBTTagList(); NBTTagCompound compound = new NBTTagCompound(); - for(Faction faction : FactionController.getInstance().factions.values()){ - NBTTagCompound factioNBT = new NBTTagCompound(); - faction.writeNBT(factioNBT); - list.appendTag(factioNBT); - if(list.tagCount() > 20){ - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound); - list = new NBTTagList(); - } - } - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound); + //////////////////////////////////////////////////////////////////////////////// + // Faction Sync + if(ConfigMain.SyncFactionAuto){ + for(Faction faction : FactionController.getInstance().factions.values()){ + NBTTagCompound factioNBT = new NBTTagCompound(); + faction.writeNBT(factioNBT); + list.appendTag(factioNBT); + if(list.tagCount() > 20){ + compound = new NBTTagCompound(); + compound.setTag("Data", list); + Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound); + list = new NBTTagList(); + } + } + compound = new NBTTagCompound(); + compound.setTag("Data", list); + Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound); + } + //////////////////////////////////////////////////////////////////////////////// - for(QuestCategory category : QuestController.Instance.categories.values()){ - Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound())); - } - Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound()); + //////////////////////////////////////////////////////////////////////////////// + // Quest Sync + if(ConfigMain.SyncQuestAuto){ + for(QuestCategory category : QuestController.Instance.categories.values()){ + NBTTagCompound questCompound; + NBTTagList questList = new NBTTagList(); + for(int questID : category.quests.keySet()){ + Quest quest = category.quests.get(questID); + questList.appendTag(quest.writeToNBT(new NBTTagCompound())); + if(questList.tagCount() > 50){ + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound); + questList = new NBTTagList(); + } + } + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound); + } + Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound()); + } + //////////////////////////////////////////////////////////////////////////////// - for(DialogCategory category : DialogController.Instance.categories.values()){ - Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound())); - } - Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound()); - - list = new NBTTagList(); - for(RecipeCarpentry category : RecipeController.Instance.globalRecipes.values()){ - list.appendTag(category.writeNBT()); - if(list.tagCount() > 10){ - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.RECIPE_NORMAL, compound); - list = new NBTTagList(); - } - } - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.RECIPE_NORMAL, compound); - - list = new NBTTagList(); - for(RecipeCarpentry category : RecipeController.Instance.anvilRecipes.values()){ - list.appendTag(category.writeNBT()); - if(list.tagCount() > 10){ - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.RECIPE_CARPENTRY, compound); - list = new NBTTagList(); - } - } - compound = new NBTTagCompound(); - compound.setTag("Data", list); - Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.RECIPE_CARPENTRY, compound); + //////////////////////////////////////////////////////////////////////////////// + // Dialog Sync + if(ConfigMain.SyncDialogAuto){ + for(DialogCategory category : DialogController.Instance.categories.values()){ + NBTTagCompound dialogCompound; + NBTTagList dialogList = new NBTTagList(); + for(int dialogID : category.dialogs.keySet()){ + Dialog dialog = category.dialogs.get(dialogID); + dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound())); + if(dialogList.tagCount() > 50){ + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound); + dialogList = new NBTTagList(); + } + } + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound); + } + Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound()); + } + //////////////////////////////////////////////////////////////////////////////// PlayerData data = PlayerData.get(player); if(data != null) @@ -80,19 +96,99 @@ public class SyncController { } public static void syncAllDialogs() { - for(DialogCategory category : DialogController.Instance.categories.values()){ - Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound())); - } - Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound()); + if(ConfigMain.SyncDialogAuto){ + for(DialogCategory category : DialogController.Instance.categories.values()){ + NBTTagCompound dialogCompound; + NBTTagList dialogList = new NBTTagList(); + for(int dialogID : category.dialogs.keySet()){ + Dialog dialog = category.dialogs.get(dialogID); + dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound())); + if(dialogList.tagCount() > 50){ + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound); + dialogList = new NBTTagList(); + } + } + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound); + } + Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound()); + } } public static void syncAllQuests() { - for(QuestCategory category : QuestController.Instance.categories.values()){ - Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound())); - } - Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound()); + if(ConfigMain.SyncQuestAuto){ + for(QuestCategory category : QuestController.Instance.categories.values()){ + NBTTagCompound questCompound; + NBTTagList questList = new NBTTagList(); + for(int questID : category.quests.keySet()){ + Quest quest = category.quests.get(questID); + questList.appendTag(quest.writeToNBT(new NBTTagCompound())); + if(questList.tagCount() > 50){ + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound); + questList = new NBTTagList(); + } + } + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound); + } + Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound()); + } } + public static void updateQuestCat(QuestCategory questCategory) { + if(ConfigMain.SyncQuestAuto){ + NBTTagCompound questCompound; + NBTTagList questList = new NBTTagList(); + for(int questID : questCategory.quests.keySet()){ + Quest quest = questCategory.quests.get(questID); + questList.appendTag(quest.writeToNBT(new NBTTagCompound())); + if(questList.tagCount() > 50){ + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound); + questList = new NBTTagList(); + } + } + questCompound = new NBTTagCompound(); + questCompound.setTag("Data", questList); + questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound); + } + } + + public static void updateDialogCat(DialogCategory dialogCategory) { + if(ConfigMain.SyncDialogAuto){ + NBTTagCompound dialogCompound; + NBTTagList dialogList = new NBTTagList(); + for(int questID : dialogCategory.dialogs.keySet()){ + Dialog dialog = dialogCategory.dialogs.get(questID); + dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound())); + if(dialogList.tagCount() > 50){ + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound); + dialogList = new NBTTagList(); + } + } + dialogCompound = new NBTTagCompound(); + dialogCompound.setTag("Data", dialogList); + dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound())); + Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound); + } + } + public static void clientSync(int synctype, NBTTagCompound compound, boolean syncEnd) { if(synctype == SyncType.FACTION){ NBTTagList list = compound.getTagList("Data", 10); @@ -109,9 +205,21 @@ public class SyncController { } else if(synctype == SyncType.QUEST_CATEGORY){ if(!compound.hasNoTags()){ - QuestCategory category = new QuestCategory(); - category.readNBT(compound); - QuestController.Instance.categoriesSync.put(category.id, category); + QuestCategory category = new QuestCategory(); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + NBTTagList list = compound.getTagList("Data", 10); + if(QuestController.Instance.categoriesSync.containsKey(category.id)){ + category = QuestController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + } + for(int i = 0; i < list.tagCount(); i++) + { + Quest quest = new Quest(); + quest.readNBT(list.getCompoundTagAt(i)); + quest.category = category; + category.quests.put(quest.id, quest); + } + QuestController.Instance.categoriesSync.put(category.id, category); } if(syncEnd){ HashMap quests = new HashMap(); @@ -127,9 +235,21 @@ public class SyncController { } else if(synctype == SyncType.DIALOG_CATEGORY){ if(!compound.hasNoTags()){ - DialogCategory category = new DialogCategory(); - category.readNBT(compound); - DialogController.Instance.categoriesSync.put(category.id, category); + DialogCategory category = new DialogCategory(); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + NBTTagList list = compound.getTagList("Data", 10); + if(DialogController.Instance.categoriesSync.containsKey(category.id)){ + category = DialogController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + } + for(int i = 0; i < list.tagCount(); i++) + { + Dialog dialog = new Dialog(); + dialog.readNBT(list.getCompoundTagAt(i)); + dialog.category = category; + category.dialogs.put(dialog.id, dialog); + } + DialogController.Instance.categoriesSync.put(category.id, category); } if(syncEnd){ HashMap dialogs = new HashMap(); @@ -160,9 +280,21 @@ public class SyncController { category.dialogs.put(dialog.id, dialog); } else if(synctype == SyncType.DIALOG_CATEGORY){ - DialogCategory category = new DialogCategory(); - category.readNBT(compound); - DialogController.Instance.categories.put(category.id, category); + DialogCategory category = new DialogCategory(); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + NBTTagList list = compound.getTagList("Data", 10); + if(DialogController.Instance.categoriesSync.containsKey(category.id)){ + category = DialogController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + } + for(int i = 0; i < list.tagCount(); i++) + { + Dialog dialog = new Dialog(); + dialog.readNBT(list.getCompoundTagAt(i)); + dialog.category = category; + category.dialogs.put(dialog.id, dialog); + } + DialogController.Instance.categoriesSync.put(category.id, category); } else if(synctype == SyncType.QUEST){ QuestCategory category = QuestController.Instance.categories.get(buffer.readInt()); @@ -174,7 +306,19 @@ public class SyncController { } else if(synctype == SyncType.QUEST_CATEGORY){ QuestCategory category = new QuestCategory(); - category.readNBT(compound); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + NBTTagList list = compound.getTagList("Data", 10); + if(QuestController.Instance.categoriesSync.containsKey(category.id)){ + category = QuestController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(compound.getCompoundTag("CatNBT")); + } + for(int i = 0; i < list.tagCount(); i++) + { + Quest quest = new Quest(); + quest.readNBT(list.getCompoundTagAt(i)); + quest.category = category; + category.quests.put(quest.id, quest); + } QuestController.Instance.categories.put(category.id, category); } } diff --git a/src/main/java/noppes/npcs/controllers/data/DialogCategory.java b/src/main/java/noppes/npcs/controllers/data/DialogCategory.java index 27e02684e..7bac90e68 100644 --- a/src/main/java/noppes/npcs/controllers/data/DialogCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/DialogCategory.java @@ -48,6 +48,17 @@ public class DialogCategory implements IDialogCategory { return dialogCat; } + public NBTTagCompound writeSmallNBT(NBTTagCompound dialogCat) { + dialogCat.setInteger("Slot", id); + dialogCat.setString("Title", title); + return dialogCat; + } + + public void readSmallNBT(NBTTagCompound compound){ + id = compound.getInteger("Slot"); + title = compound.getString("Title"); + } + public List dialogs() { return new ArrayList(this.dialogs.values()); } diff --git a/src/main/java/noppes/npcs/controllers/data/QuestCategory.java b/src/main/java/noppes/npcs/controllers/data/QuestCategory.java index a9086efb2..8cf178971 100644 --- a/src/main/java/noppes/npcs/controllers/data/QuestCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/QuestCategory.java @@ -47,7 +47,17 @@ public class QuestCategory implements IQuestCategory { return nbttagcompound; } - + + public NBTTagCompound writeSmallNBT(NBTTagCompound nbttagcompound) { + nbttagcompound.setInteger("Slot", id); + nbttagcompound.setString("Title", title); + return nbttagcompound; + } + + public void readSmallNBT(NBTTagCompound nbttagcompound) { + id = nbttagcompound.getInteger("Slot"); + title = nbttagcompound.getString("Title"); + } public List quests() { return new ArrayList(this.quests.values()); From 94cdb68bcee15503a7c5e45b209092a0adbf7e46 Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 13 Mar 2024 03:57:17 -0400 Subject: [PATCH 13/13] Better Global Quest / Dialog Handling --- .../npcs/client/gui/global/GuiNPCManageDialogs.java | 9 ++++++++- .../noppes/npcs/client/gui/global/GuiNPCManageQuest.java | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 7bf3ed03a..5e61e605e 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -247,7 +247,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou boolean diagEnabled = dialogData != null; if(diagEnabled){ - if(!(dialog.id >= 0)){ + if(dialog == null ||!(dialog.id >= 0)){ diagEnabled = false; } } @@ -333,6 +333,13 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollGrou String selected = catScroll.getSelected(); if(!selected.equals(prevCatName) || override){ category = new DialogCategory(); + + dialogScroll.selected = -1; + dialogScroll.resetScroll(); + diagSearch = ""; + dialog = null; + getTextField(66).setText(""); + Client.sendData(EnumPacketServer.DialogCategoryGet, catData.get(selected)); setPrevCatName(selected); } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java index 11c292d66..0b3ec4ce5 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageQuest.java @@ -251,7 +251,7 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, boolean questEnabled = questData != null; if(questEnabled){ - if(!(quest.id >= 0)){ + if(quest == null || !(quest.id >= 0)){ questEnabled = false; } } @@ -337,6 +337,13 @@ public class GuiNPCManageQuest extends GuiNPCInterface2 implements IScrollGroup, String selected = catScroll.getSelected(); if(!selected.equals(prevCatName) || override){ category = new QuestCategory(); + + questScroll.selected = -1; + questScroll.resetScroll(); + questSearch = ""; + quest = null; + getTextField(66).setText(""); + Client.sendData(EnumPacketServer.QuestCategoryGet, catData.get(selected)); setPrevCatName(selected); }