From 79e13dfade74768abb9a129efc49ab52ba95a74d Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 19 Feb 2023 13:46:37 -0600 Subject: [PATCH] Changes to the animation GUI and part/frame saving. --- src/api | 2 +- src/main/java/noppes/npcs/AnimationData.java | 2 +- .../gui/global/GuiNPCManageAnimations.java | 27 ++++++++++++++----- .../noppes/npcs/controllers/data/Frame.java | 15 +++++++++++ .../npcs/controllers/data/FramePart.java | 12 ++++++++- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/api b/src/api index ee24240f3..d43bfd724 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit ee24240f3b6fd8e54c0ac750508676c64703f585 +Subproject commit d43bfd72427542d3fbb37ef49895aca37d4ea237 diff --git a/src/main/java/noppes/npcs/AnimationData.java b/src/main/java/noppes/npcs/AnimationData.java index fff9e2e3d..0912c1b9b 100644 --- a/src/main/java/noppes/npcs/AnimationData.java +++ b/src/main/java/noppes/npcs/AnimationData.java @@ -25,7 +25,7 @@ public class AnimationData implements IAnimationData { public void updateClient() { NBTTagCompound compound = new NBTTagCompound(); compound = this.writeToNBT(compound); - compound.setTag("Animation",this.animation.writeToNBT()); + compound.setTag("Animation",this.animation == null ? new NBTTagCompound() : this.animation.writeToNBT()); if (parent instanceof PlayerData) { Server.sendToAll(EnumPacketClient.UPDATE_ANIMATIONS, compound, ((PlayerData) parent).player.getCommandSenderName()); } else if (parent instanceof DataDisplay) { diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java index b5343f45b..aca2ec8a4 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageAnimations.java @@ -113,12 +113,15 @@ public class GuiNPCManageAnimations extends GuiModelInterface implements IScroll this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 9 + 145, guiTop + 180, 0xFFFFFF)); - this.addButton(new GuiNpcButton(11, guiLeft - 20 + 145, guiTop + 191, 45, 20, "gui.add")); + this.addButton(new GuiNpcButton(11, guiLeft - 45 + 150, guiTop + 189, 45, 20, "gui.add")); if (animation.frames.size() > 0) { - this.addButton(new GuiNpcButton(12, guiLeft + 30 + 145, guiTop + 191, 45, 20, "gui.remove")); - this.addButton(new GuiNpcButton(13, guiLeft - 3 + 145, guiTop + 210, 20, 20, "<")); - this.addButton(new GuiNpcButton(14, guiLeft + 17 + 145, guiTop + 210, 20, 20, "" + frameIndex)); - this.addButton(new GuiNpcButton(15, guiLeft + 37 + 145, guiTop + 210, 20, 20, ">")); + this.addButton(new GuiNpcButton(12, guiLeft + 150, guiTop + 189, 45, 20, "gui.remove")); + this.addButton(new GuiNpcButton(13, guiLeft + 45 + 150, guiTop + 189, 45, 20, "gui.copy")); + this.addButton(new GuiNpcButton(14, guiLeft - 8 + 145, guiTop + 210, 20, 20, "<")); + this.addTextField(new GuiNpcTextField(15, this, guiLeft + 17 + 145, guiTop + 212, 20, 17, frameIndex + "")); + this.getTextField(15).integersOnly = true; + this.getTextField(15).setMinMaxDefault(0, animation.frames.size() - 1, frameIndex); + this.addButton(new GuiNpcButton(16, guiLeft + 42 + 145, guiTop + 210, 20, 20, ">")); } this.addButton(new GuiNpcButton(20, guiLeft + 290, guiTop - 5, 75, 20, new String[]{"animation.animation", "animation.frame", "animation.framePart"}, editingMode)); @@ -331,12 +334,18 @@ public class GuiNPCManageAnimations extends GuiModelInterface implements IScroll } } else if (guibutton.id == 12) { animation.frames.remove(frameIndex); - } else if (guibutton.id == 13) { + } else if (guibutton.id == 13 && editingFrame != null) { + if (frameIndex < animation.frames.size() - 1) { + animation.frames.add(frameIndex + 1, editingFrame.copy()); + } else { + animation.frames.add(editingFrame.copy()); + } + } else if (guibutton.id == 14) { frameIndex--; if (frameIndex == -1) { frameIndex = animation.frames.size() - 1; } - } else if (guibutton.id == 14 || guibutton.id == 15) { + } else if (guibutton.id == 16) { frameIndex++; } else if (guibutton.id == 20) { editingMode++; @@ -457,6 +466,10 @@ public class GuiNPCManageAnimations extends GuiModelInterface implements IScroll } else { textfield.setText(animation.name); } + } else if (textfield.id == 15 && animation != null && animation.frames.size() > 0) { + animation.frames.remove(frameIndex); + animation.frames.add(textfield.getInteger(),frame); + frameIndex = textfield.getInteger(); } else if (textfield.id == 32) { if (editingMode == 0) { animation.speed = textfield.getFloat(); diff --git a/src/main/java/noppes/npcs/controllers/data/Frame.java b/src/main/java/noppes/npcs/controllers/data/Frame.java index 9fbf9b0fe..5e8bc9df9 100644 --- a/src/main/java/noppes/npcs/controllers/data/Frame.java +++ b/src/main/java/noppes/npcs/controllers/data/Frame.java @@ -165,4 +165,19 @@ public class Frame implements IFrame { compound.setTag("FrameParts", list); return compound; } + + public Frame copy() { + Frame frame = new Frame(this.duration); + HashMap frameParts = this.frameParts; + for (Map.Entry entry : frameParts.entrySet()) { + frame.frameParts.put(entry.getKey(),entry.getValue().copy()); + } + frame.parent = this.parent; + frame.duration = this.duration; + frame.customized = this.customized; + frame.speed = this.speed; + frame.smooth = this.smooth; + frame.renderTicks = this.renderTicks; + return frame; + } } diff --git a/src/main/java/noppes/npcs/controllers/data/FramePart.java b/src/main/java/noppes/npcs/controllers/data/FramePart.java index 7426899a0..fb197f89c 100644 --- a/src/main/java/noppes/npcs/controllers/data/FramePart.java +++ b/src/main/java/noppes/npcs/controllers/data/FramePart.java @@ -20,7 +20,7 @@ public class FramePart implements IFramePart { public byte smooth = 0; //Client-sided fields (unsaved) - public float[] prevRotations = {(float) Math.PI,(float) Math.PI,(float) Math.PI}; + public float[] prevRotations = {0,0,0}; public float[] prevPivots = {0,0,0}; public float partialRotationTick; public float partialPivotTick; @@ -147,6 +147,16 @@ public class FramePart implements IFramePart { return compound; } + public FramePart copy() { + FramePart part = new FramePart(this.part); + part.rotation = new float[]{this.rotation[0],this.rotation[1],this.rotation[2]}; + part.pivot = new float[]{this.pivot[0],this.pivot[1],this.pivot[2]}; + part.customized = this.customized; + part.speed = this.speed; + part.smooth = this.smooth; + return part; + } + @SideOnly(Side.CLIENT) public void interpolateAngles() { if (parent != null && parent.paused)