From f35b5a32ac4b5f45de90246c23e053874fb289ee Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Thu, 9 Nov 2023 23:07:52 -0600 Subject: [PATCH] made animation timeline buttons clickable. when paused, clicking the buttons will take you to that point in the animation. --- .../gui/global/GuiNPCEditAnimation.java | 50 +++++++++++++------ .../npcs/controllers/data/Animation.java | 11 ++++ .../npcs/controllers/data/FramePart.java | 15 ++++++ 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java index bd9ba5c02..008c567da 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCEditAnimation.java @@ -28,15 +28,15 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield private int frameIndex = 0; public boolean playingAnimation = false; private Frame prevFrame; - private GuiScreen parent; + private final GuiScreen parent; private long prevTick; private static int partEditMode; private static int sliderSelection = 0; - private GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3]; - private GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3]; + private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3]; + private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3]; - private GuiNpcSlider frameSlider; + private final GuiNpcSlider frameSlider; public GuiNPCEditAnimation(GuiScreen parent, Animation animation, EntityNPCInterface npc) { super((EntityCustomNpc) npc); @@ -66,6 +66,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield if (animation == null) return; frameIndex = !animation.frames.isEmpty() ? frameIndex % animation.frames.size() : 0; + this.updateSliders(); Frame editingFrame = this.editingFrame(); if (editingFrame != null) { @@ -346,14 +347,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield this.frameSlider.width = 63; for (int i = 0; i < 25; i++) { - this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + playPauseY + 200, 6, 20, animTexture, 0, 71)); - GuiTexturedButton button = (GuiTexturedButton) getButton(300 + i); - if (i == this.frameIndex) { - button.yPosition -= 5; - button.color = 0x00FF00; - } else if (i >= this.animation.frames.size()) { - button.color = 0x0; - } + this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + 207, 6, 20, animTexture, 0, 71)); } } @@ -478,6 +472,20 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield setSubGui(new SubGuiAnimationFrame(editingFrame)); } + if (guibutton.id >= 300 && guibutton.id < 325 && (!this.playingAnimation || this.animation.paused)) { + int frameClicked = guibutton.id - 300; + if (frameClicked < this.animation.frames.size()) { + this.frameIndex = frameClicked; + } + if (this.playingAnimation) { + this.animation.currentFrame = this.frameIndex; + this.animation.setPausedValues(); + initGui(); + this.animation.setPausedValues(); + return; + } + } + initGui(); } @@ -496,7 +504,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield if (currentFrame != null && !currentFrame.renderTicks) { data.animation.increaseTime(); } - GuiNpcLabel label = this.getLabel(94); + GuiNpcLabel label = this.getLabel(213); if (label != null) { label.label += "."; if (label.label.length()%4 == 0) { @@ -506,6 +514,20 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield } prevTick = time; } + + for (int i = 0; i < 25; i++) { + if (getButton(300 + i) != null) { + GuiTexturedButton button = (GuiTexturedButton) getButton(300 + i); + if (i >= this.animation.frames.size()) { + button.color = 0x0; + } else { + if (i == this.frameIndex) { + button.color = 0x00FF00; + } + button.yPosition = i == this.animation.currentFrame && this.playingAnimation ? guiTop + 200 : guiTop + 207; + } + } + } } @Override @@ -550,7 +572,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield @Override public void mouseDragged(GuiNpcSlider guiNpcSlider) { FramePart part = this.editingPart(); - if (part == null) { + if (part == null || this.mc == null) { return; } int id = guiNpcSlider.id; diff --git a/src/main/java/noppes/npcs/controllers/data/Animation.java b/src/main/java/noppes/npcs/controllers/data/Animation.java index 9c13d5d0b..f19ad04d8 100644 --- a/src/main/java/noppes/npcs/controllers/data/Animation.java +++ b/src/main/java/noppes/npcs/controllers/data/Animation.java @@ -251,4 +251,15 @@ public class Animation implements IAnimation { } } } + + @SideOnly(Side.CLIENT) + public void setPausedValues() { + this.currentFrameTime = 0; + Frame frame = (Frame) this.currentFrame(); + for (EnumAnimationPart part : EnumAnimationPart.values()) { + if (frame.frameParts.containsKey(part)) { + frame.frameParts.get(part).setPausedValues(); + } + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/FramePart.java b/src/main/java/noppes/npcs/controllers/data/FramePart.java index fb197f89c..57b8a5424 100644 --- a/src/main/java/noppes/npcs/controllers/data/FramePart.java +++ b/src/main/java/noppes/npcs/controllers/data/FramePart.java @@ -221,4 +221,19 @@ public class FramePart implements IFramePart { } } } + + @SideOnly(Side.CLIENT) + public void setPausedValues() { + this.partialRotationTick = ClientEventHandler.partialRenderTick; + this.partialPivotTick = ClientEventHandler.partialRenderTick; + + this.prevPivots[0] = this.pivot[0]; + this.prevPivots[1] = this.pivot[1]; + this.prevPivots[2] = this.pivot[2]; + + float pi = (float) Math.PI / 180; + this.prevRotations[0] = this.rotation[0] * pi; + this.prevRotations[1] = this.rotation[1] * pi; + this.prevRotations[2] = this.rotation[2] * pi; + } }