Revert "Revert Animation Events"

This reverts commit 1ffddd3ce9.
This commit is contained in:
Kam committed 2024-08-22 16:47:07 -04:00
1 parent 2689127787
commit 4113bcc6e9
31 files changed
+694 -206

No files matched your search

@@ -23,14 +23,16 @@ import java.util.Map;
public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfieldListener, ISliderListener, ISubGuiListener {
private final Animation animation;
private static int partEditMode;
private static int sliderSelection = 0;
private static Frame copiedFrame;
private EnumAnimationPart editingPart = EnumAnimationPart.HEAD;
private int frameIndex = 0;
public boolean playingAnimation = false;
private Frame prevFrame;
private final GuiScreen parent;
private long prevTick;
private static int partEditMode;
private static int sliderSelection = 0;
private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3];
private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3];
@@ -49,7 +51,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
this.animation = animation;
AnimationData data = npc.display.animationData;
data.animation = animation;
data.setAnimation(animation);
data.setEnabled(true);
int bodyPartX = 280;
@@ -92,9 +94,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
AnimationData data = npc.display.animationData;
if (!playingAnimation) {
data.animation = new Animation();
data.setAnimation(new Animation());
data.animation.smooth = animation.smooth;
data.animation.renderTicks = animation.renderTicks;
data.animation.tickDuration = 50;
data.animation.loop = 0;
if (editingFrame != null) {
data.animation.frames.add(editingFrame);
@@ -107,7 +109,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
if (!frame.isCustomized()) {
frame.speed = animation.speed;
frame.smooth = animation.smooth;
frame.renderTicks = animation.renderTicks;
frame.tickDuration = animation.tickDuration();
}
for (Map.Entry<EnumAnimationPart,FramePart> entry : frame.frameParts.entrySet()) {
FramePart part = entry.getValue();
@@ -401,13 +403,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
AnimationData data = npc.display.animationData;
if (guibutton.id == 11) {
if (frameIndex < animation.frames.size() - 1) {
animation.frames.add(frameIndex + 1, new Frame(10));
} else {
animation.frames.add(new Frame(10));
}
this.frameIndex = frameIndex + 1;
updateFrameSlider();
this.addFrame();
} else if (guibutton.id == 12) {
animation.frames.remove(frameIndex);
updateFrameSlider();
@@ -475,7 +471,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
}
}
this.playingAnimation = true;
data.animation = animation;
data.setAnimation(this.animation);
data.animation.paused = false;
} else if (guibutton.id == 201) {
data.animation.paused = true;
@@ -501,6 +497,20 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
initGui();
}
private void addFrame() {
this.addFrame(new Frame(10));
}
private void addFrame(Frame frame) {
if (frameIndex < animation.frames.size() - 1) {
animation.frames.add(frameIndex + 1, frame);
} else {
animation.frames.add(frame);
}
this.frameIndex = frameIndex + 1;
updateFrameSlider();
}
@Override
public void drawScreen(int par1, int par2, float par3)
{
@@ -510,12 +520,8 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
this.playingAnimation = false;
initGui();
} else if (data.isActive()) {
Frame currentFrame = (Frame) data.animation.currentFrame();
long time = mc.theWorld.getTotalWorldTime();
if (time != prevTick) {
if (currentFrame != null && !currentFrame.renderTicks) {
data.animation.increaseTime();
}
GuiNpcLabel label = this.getLabel(213);
if (label != null) {
label.label += ".";
@@ -643,4 +649,28 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
editingFrame.setColorMarker(((SubGuiColorSelector) subgui).color);
}
}
@Override
public void keyTyped(char par1, int par2) {
super.keyTyped(par1, par2);
if (GuiScreen.isCtrlKeyDown() && par2 != 29 && !GuiNpcTextField.isFieldActive()) {
switch (par2) {
case 46:
if (this.editingFrame() != null) {
copiedFrame = this.editingFrame();
}
break;
case 47:
if (copiedFrame != null) {
Frame frame = new Frame(10);
frame.parent = this.animation;
frame.readFromNBT(copiedFrame.writeToNBT());
this.addFrame(frame);
this.initGui();
}
break;
}
}
}
}