Animation GUI Move to similar style menu. [Sub Gui not implemented yet]

This commit is contained in:
Kam committed 2023-11-01 21:39:08 -04:00
1 parent 7713970f77
commit f6e8370ba3
10 files changed
+790 -552

No files matched your search

@@ -87,6 +87,14 @@ public class NoppesUtilServer {
sendScrollData(player, map);
}
public static void sendAnimationDataAll(EntityPlayerMP player) {
Map<String,Integer> map = new HashMap<String,Integer>();
for(Animation animation : AnimationController.getInstance().animations.values()){
map.put(animation.name, animation.id);
}
sendScrollData(player, map);
}
public static void sendTagDataAll(EntityPlayerMP player) {
Map<String,Integer> map = new HashMap<String,Integer>();
for(Tag tag : TagController.getInstance().tags.values()){
@@ -935,42 +935,26 @@ public class PacketHandlerServer{
//NoppesUtilServer.sendRoleData(player, npc);
}
}
else if(type == EnumPacketServer.AnimationListGet) {
Server.sendData(player, EnumPacketClient.SCROLL_LIST, new ArrayList<>(AnimationController.Instance.animations.keySet()));
else if(type == EnumPacketServer.AnimationsGet){
NoppesUtilServer.sendAnimationDataAll(player);
}
else if(type == EnumPacketServer.AnimationGet) {
String animationName = Server.readString(buffer);
Animation animation = (Animation) AnimationController.Instance.get(animationName);
if (animation != null) {
Server.sendData(player, EnumPacketClient.GUI_DATA, animation.writeToNBT());
}
else if(type == EnumPacketServer.AnimationGet){
Animation animation = (Animation) AnimationController.getInstance().get(buffer.readInt());
NBTTagCompound compound = animation.writeToNBT();
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
else if (type == EnumPacketServer.AnimationAdd) {
String name = "Animation";
if (AnimationController.Instance.has(name)) {
name += "_";
int i = 1;
while (AnimationController.Instance.has(name + i)) {
i++;
}
name += i;
}
Animation animation = new Animation(name);
animation.save();
Server.sendData(player, EnumPacketClient.SCROLL_LIST, new ArrayList<>(AnimationController.Instance.animations.keySet()));
else if(type == EnumPacketServer.AnimationRemove){
AnimationController.getInstance().delete(buffer.readInt());
NoppesUtilServer.sendAnimationDataAll(player);
NBTTagCompound compound = (new Animation()).writeToNBT();
Server.sendData(player, EnumPacketClient.GUI_DATA, compound);
}
else if (type == EnumPacketServer.AnimationDelete) {
String animationName = Server.readString(buffer);
AnimationController.Instance.delete(animationName);
Server.sendData(player, EnumPacketClient.SCROLL_LIST, new ArrayList<>(AnimationController.Instance.animations.keySet()));
}
else if (type == EnumPacketServer.AnimationSave) {
String prevName = Server.readString(buffer);
AnimationController.Instance.delete(prevName);
else if(type == EnumPacketServer.AnimationSave){
Animation animation = new Animation();
animation.readFromNBT(Server.readNBT(buffer));
animation.save();
Server.sendData(player, EnumPacketClient.SCROLL_LIST, new ArrayList<>(AnimationController.Instance.animations.keySet()));
AnimationController.getInstance().saveAnimation(animation);
NoppesUtilServer.sendAnimationDataAll(player);
Server.sendData(player, EnumPacketClient.GUI_DATA, animation.writeToNBT());
}
else
blockPackets(type, buffer, player);
@@ -260,7 +260,8 @@ public class ClientProxy extends CommonProxy {
animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
}
return new GuiNPCManageAnimations(animNpc);
} else if (gui == EnumGuiType.ManageLinked)
}
else if (gui == EnumGuiType.ManageLinked)
return new GuiNPCManageLinkedNpc(npc);
else if (gui == EnumGuiType.ManageTransport)
@@ -2,516 +2,163 @@ package noppes.npcs.client.gui.global;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.Vector;
public class GuiNPCManageAnimations extends GuiModelInterface implements IScrollData, ITextfieldListener, ICustomScrollListener, IGuiData {
private Animation animation = null;
public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData, ISubGuiListener
{
private GuiCustomScroll scrollAnimations;
private HashMap<String,Integer> data = new HashMap<String,Integer>();
private Animation animation = new Animation();
private String selected = null;
private String search = "";
private EnumAnimationPart editingPart = EnumAnimationPart.HEAD;
private int editingMode = 0;
private int frameIndex = 0;
public boolean playingAnimation = false;
private Frame prevFrame;
private GuiCustomScroll scroll;
private String prevSelected = "";
private long prevTick;
public GuiNPCManageAnimations(EntityNPCInterface npc) {
super((EntityCustomNpc) npc);
Client.sendData(EnumPacketServer.AnimationListGet);
xOffset -= 20;
yOffset = -45;
AnimationData data = npc.display.animationData;
data.setEnabled(true);
}
@Override
public void initGui() {
super.initGui();
if(scroll == null)
scroll = new GuiCustomScroll(this,0);
scroll.setSize(100, 175);
scroll.guiLeft = guiLeft - 20;
scroll.guiTop = guiTop + 15;
this.addScroll(scroll);
this.addButton(new GuiNpcButton(1,guiLeft - 20, guiTop - 5, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 30, guiTop - 5, 45, 20, "gui.remove"));
if (animation != null) {
frameIndex = animation.frames.size() > 0 ? frameIndex % animation.frames.size() : 0;
Frame editingFrame = this.editingFrame();
if (editingFrame != null) {
if (editingFrame != prevFrame && prevFrame != null) {
HashMap<EnumAnimationPart,FramePart> frameParts = prevFrame.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
if (editingFrame.frameParts.containsKey(entry.getKey())) {
FramePart part = editingFrame.frameParts.get(entry.getKey());
FramePart prevPart = prevFrame.frameParts.get(entry.getKey());
part.prevRotations = prevPart.prevRotations;
part.prevPivots = prevPart.prevPivots;
part.partialRotationTick = prevPart.partialRotationTick;
part.partialPivotTick = prevPart.partialPivotTick;
}
}
}
}
prevFrame = editingFrame;
FramePart editingPart = this.editingPart();
AnimationData data = npc.display.animationData;
if (!playingAnimation) {
data.animation = new Animation();
data.animation.smooth = animation.smooth;
data.animation.renderTicks = animation.renderTicks;
data.animation.loop = 0;
if (editingFrame != null) {
data.animation.frames.add(editingFrame);
}
}
for (Frame frame : animation.frames) {
frame.parent = animation;
if (!frame.isCustomized()) {
frame.speed = animation.speed;
frame.smooth = animation.smooth;
frame.renderTicks = animation.renderTicks;
}
for (Map.Entry<EnumAnimationPart,FramePart> entry : frame.frameParts.entrySet()) {
FramePart part = entry.getValue();
part.parent = animation;
if (!part.isCustomized()) {
part.speed = frame.speed;
part.smooth = frame.smooth;
}
}
}
editingMode %= 3;
if (animation.loop >= animation.frames.size()) {
animation.loop = -1;
}
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 9 + 145, guiTop + 180, 0xFFFFFF));
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 + 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));
String animTexture = "customnpcs:textures/gui/animation.png";
if (data.animation != null && data.animation.frames.size() > 0) {
if (!this.playingAnimation || data.animation.paused) {//Play
this.addLabel(new GuiNpcLabel(90, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft - 15, guiTop + 206, 0xFFFFFF));
if (data.animation.paused) {
this.addLabel(new GuiNpcLabel(94, "", guiLeft + 21, guiTop + 206, 0xFFFFFF));
}
this.addButton(new GuiTexturedButton(91, "", guiLeft + 35, guiTop + 200, 11, 20, animTexture, 18, 71));
} else {//Pause
this.addLabel(new GuiNpcLabel(90, "animation.playing", guiLeft - 15, guiTop + 206, 0xFFFFFF));
this.addLabel(new GuiNpcLabel(94, "", guiLeft + 20, guiTop + 206, 0xFFFFFF));
this.addButton(new GuiTexturedButton(92, "", guiLeft + 35, guiTop + 200, 14, 20, animTexture, 0, 71));
}
if (this.playingAnimation) {//Stop
this.addButton(new GuiTexturedButton(93, "", guiLeft + 55, guiTop + 200, 14, 20, animTexture, 33, 71));
}
}
if (editingMode == 0) {
//name - textfield
// Send the old animation name (string selected on the scroll).
// On the server side, if the new animation's name is different from the old one but already exists,
// do not change the name (set the name to the old animation name after the animation is read from NBT).
this.addTextField(new GuiNpcTextField(30, this, guiLeft + 270, guiTop + 18, 100, 15, animation.name));
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 44, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 310, guiTop + 40, 30, 15, animation.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0,Float.MAX_VALUE,1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 64, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 58, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, animation.smooth));
//
//ticks - button
this.addLabel(new GuiNpcLabel(35, "animation.tickType", guiLeft + 270, guiTop + 104, 0xFFFFFF));
this.addButton(new GuiNpcButton(36, guiLeft + 325, guiTop + 98, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, animation.renderTicks ? 0 : 1));
//
//loop - button
this.addLabel(new GuiNpcLabel(37, "animation.loopStart", guiLeft + 270, guiTop + 84, 0xFFFFFF));
this.addButton(new GuiNpcButton(38, guiLeft + 325, guiTop + 78, 75, 20, animation.loop == -1 ? "No Looping" : "Frame " + animation.loop));
//
//whileStanding - button
this.addLabel(new GuiNpcLabel(39, "animation.whileStanding", guiLeft + 270, guiTop + 124, 0xFFFFFF));
this.addButton(new GuiNpcButton(40, guiLeft + 345, guiTop + 118, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileStanding ? 0 : 1));
//
//whileAttacking - button
this.addLabel(new GuiNpcLabel(41, "animation.whileAttacking", guiLeft + 270, guiTop + 144, 0xFFFFFF));
this.addButton(new GuiNpcButton(42, guiLeft + 345, guiTop + 138, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileAttacking ? 0 : 1));
//
//whileMoving - button
this.addLabel(new GuiNpcLabel(43, "animation.whileMoving", guiLeft + 270, guiTop + 164, 0xFFFFFF));
this.addButton(new GuiNpcButton(44, guiLeft + 345, guiTop + 158, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileMoving ? 0 : 1));
} else if (editingFrame != null) {
if (editingMode == 1) {
//
//duration - textfield
this.addLabel(new GuiNpcLabel(50, "animation.duration", guiLeft + 270, guiTop + 25, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(51, this, guiLeft + 330, guiTop + 21, 30, 15, editingFrame.duration + ""));
this.getTextField(51).integersOnly = true;
this.getTextField(51).setMinMaxDefaultFloat(0, Integer.MAX_VALUE, 10);
//
//customized - button, enables all the following options.
this.addLabel(new GuiNpcLabel(52, "animation.customized", guiLeft + 270, guiTop + 44, 0xFFFFFF));
this.addButton(new GuiNpcButton(53, guiLeft + 325, guiTop + 38, 30, 20, new String[]{"gui.yes", "gui.no"}, editingFrame.isCustomized() ? 0 : 1));
if (editingFrame.isCustomized()) {
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 64, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 330, guiTop + 60, 30, 15, editingFrame.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 84, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 78, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingFrame.smooth));
//
//ticks - button
this.addLabel(new GuiNpcLabel(35, "animation.tickType", guiLeft + 270, guiTop + 104, 0xFFFFFF));
this.addButton(new GuiNpcButton(36, guiLeft + 325, guiTop + 98, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, editingFrame.renderTicks ? 0 : 1));
}
} else if (editingMode == 2) {
//
//6 body part textured buttons
//Add/remove part button
// 6 custom GUI textured buttons for each body part determine "this.currentPart (enum)".
// If the current frame doesn't have that part, the button will say "Add part"
// otherwise, the button will say "Remove", and more options for editing the part become available:
//
//Head
this.addButton(new GuiTexturedButton(60, "",guiLeft + 270, guiTop + 18,22,23, animTexture,0,0));
//Body
this.addButton(new GuiTexturedButton(61, "",guiLeft + 270, guiTop + 43,22,23, animTexture,24,0));
//Right Arm
this.addButton(new GuiTexturedButton(62, "",guiLeft + 261, guiTop + 43,8,23, animTexture,48,0));
//Left Arm
this.addButton(new GuiTexturedButton(63, "",guiLeft + 296, guiTop + 43,8,23, animTexture,48,0));
//Right Leg
this.addButton(new GuiTexturedButton(64, "",guiLeft + 271, guiTop + 68,10,23, animTexture,58,0));
//Left Leg
this.addButton(new GuiTexturedButton(65, "",guiLeft + 282, guiTop + 68,10,23, animTexture,58,0));
//Full Body
this.addButton(new GuiTexturedButton(66, "",guiLeft + 310, guiTop + 20,17,23, animTexture,70,0));
for (int i = 0; i < 7; i++) {
if (this.buttons.containsKey(60 + i)) {
((GuiTexturedButton) this.getButton(60 + i)).scale = 1.2F;
if (!editingFrame.frameParts.containsKey(EnumAnimationPart.values()[i])) {
((GuiTexturedButton) this.getButton(60 + i)).textureX += 96;
}
}
}
if (editingPart != null) {
//remove part button
this.addLabel(new GuiNpcLabel(67, editingPart.part.name(), guiLeft + 320, guiTop + 60, 0xFFFFFF));
this.addButton(new GuiNpcButton(68, guiLeft + 315, guiTop + 75, 60, 20, "gui.remove"));
//
//rotation - 3 textfields
this.addLabel(new GuiNpcLabel(70, "animation.rotations", guiLeft + 270, guiTop + 105, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(71, this, guiLeft + 270, guiTop + 117, 35, 15, editingPart.rotation[0] + ""));
this.getTextField(71).floatsOnly = true;
this.getTextField(71).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(72, this, guiLeft + 310, guiTop + 117, 35, 15, editingPart.rotation[1] + ""));
this.getTextField(72).floatsOnly = true;
this.getTextField(72).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(73, this, guiLeft + 350, guiTop + 117, 35, 15, editingPart.rotation[2] + ""));
this.getTextField(73).floatsOnly = true;
this.getTextField(73).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
//
//pivot - 3 textfields
this.addLabel(new GuiNpcLabel(80, "animation.pivots", guiLeft + 270, guiTop + 137, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(81, this, guiLeft + 270, guiTop + 149, 35, 15, editingPart.pivot[0] + ""));
this.getTextField(81).floatsOnly = true;
this.getTextField(81).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(82, this, guiLeft + 310, guiTop + 149, 35, 15, editingPart.pivot[1] + ""));
this.getTextField(82).floatsOnly = true;
this.getTextField(82).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(83, this, guiLeft + 350, guiTop + 149, 35, 15, editingPart.pivot[2] + ""));
this.getTextField(83).floatsOnly = true;
this.getTextField(83).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
//
//customized - button, enables all the following options.
this.addLabel(new GuiNpcLabel(52, "animation.customized", guiLeft + 270, guiTop + 174, 0xFFFFFF));
this.addButton(new GuiNpcButton(53, guiLeft + 325, guiTop + 168, 30, 20, new String[]{"gui.yes", "gui.no"}, editingPart.isCustomized() ? 0 : 1));
if (editingPart.isCustomized()) {
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 194, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 330, guiTop + 190, 30, 15, editingPart.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 214, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 208, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingPart.smooth));
}
}
}
} else {
this.addLabel(new GuiNpcLabel(50, "animation.addFrame", guiLeft + 270, guiTop + 100, 0xFFFFFF));
}
}
}
private Frame editingFrame() {
if (this.animation == null || this.frameIndex >= this.animation.frames.size()) {
return null;
}
return animation.frames.get(this.frameIndex);
}
private FramePart editingPart() {
Frame editingFrame = this.editingFrame();
if (this.animation == null || editingFrame == null) {
return null;
}
return editingFrame.frameParts.get(this.editingPart);
}
@Override
protected void actionPerformed(GuiButton guibutton){
super.actionPerformed(guibutton);
Frame editingFrame = this.editingFrame();
FramePart part = this.editingPart();
int value = ((GuiNpcButton)guibutton).getValue();
AnimationData data = npc.display.animationData;
if (guibutton.id == 1) {
Client.sendData(EnumPacketServer.AnimationAdd);
frameIndex = 0;
} else if (guibutton.id == 2 && scroll.getSelected() != null) {
Client.sendData(EnumPacketServer.AnimationDelete, scroll.getSelected());
this.playingAnimation = false;
data.animation = null;
animation = null;
frameIndex = 0;
} else 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));
}
} else if (guibutton.id == 12) {
animation.frames.remove(frameIndex);
} 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 == 16) {
frameIndex++;
} else if (guibutton.id == 20) {
editingMode++;
} else if (guibutton.id >= 60 && guibutton.id <= 66) {//Animation part buttons
EnumAnimationPart enumPart = EnumAnimationPart.values()[guibutton.id-60];
if (editingFrame != null && !editingFrame.frameParts.containsKey(enumPart)) {
FramePart framePart = new FramePart(enumPart);
framePart.prevRotations = new float[]{0, 0, 0};
editingFrame.addPart(framePart);
}
this.editingPart = enumPart;
} else if (guibutton.id == 68 && editingFrame != null) {
editingFrame.removePart(this.editingPart.name());
} else if (guibutton.id == 53 && editingFrame != null) {
if (editingMode == 1) {
editingFrame.setCustomized(!editingFrame.isCustomized());
} else if (editingMode == 2 && part != null) {
part.setCustomized(!part.isCustomized());
}
} else if (guibutton.id == 34) {
if (editingMode == 0) {
animation.smooth = (byte) value;
} else if (editingMode == 1 && editingFrame != null) {
editingFrame.smooth = (byte) value;
} else if (editingMode == 2 && part != null) {
part.smooth = (byte) value;
}
} else if (guibutton.id == 36) {
if (editingMode == 0) {
animation.renderTicks = value == 0;
} else if (editingMode == 1 && editingFrame != null) {
editingFrame.renderTicks = value == 0;
}
} else if (guibutton.id == 38) {
animation.loop++;
} else if (guibutton.id == 40) {
animation.whileStanding = value == 0;
} else if (guibutton.id == 42) {
animation.whileAttacking = value == 0;
} else if (guibutton.id == 44) {
animation.whileMoving = value == 0;
} else if (guibutton.id == 91) {
if (!this.playingAnimation || !data.isActive()) {
animation.currentFrame = 0;
animation.currentFrameTime = 0;
for (Frame frame : animation.frames) {
for (FramePart framePart : frame.frameParts.values()) {
framePart.prevRotations = new float[]{0,0,0};
framePart.prevPivots = new float[]{0, 0, 0};
}
}
}
this.playingAnimation = true;
data.animation = animation;
data.animation.paused = false;
} else if (guibutton.id == 92) {
data.animation.paused = true;
} else if (guibutton.id == 93) {
this.playingAnimation = false;
data.animation.paused = false;
}
initGui();
}
@Override
public void drawScreen(int par1, int par2, float par3)
public GuiNPCManageAnimations(EntityNPCInterface npc)
{
super.drawScreen(par1,par2,par3);
AnimationData data = npc.display.animationData;
if (!data.isActive() && this.playingAnimation) {
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(94);
if (label != null) {
label.label += ".";
if (label.label.length()%4 == 0) {
label.label = "";
}
}
}
prevTick = time;
super(npc);
Client.sendData(EnumPacketServer.AnimationsGet);
}
public void initGui()
{
super.initGui();
this.addButton(new GuiNpcButton(0,guiLeft + 368, guiTop + 8, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(1,guiLeft + 368, guiTop + 32, 45, 20, "gui.remove"));
if(scrollAnimations == null){
scrollAnimations = new GuiCustomScroll(this,0);
scrollAnimations.setSize(143, 185);
}
scrollAnimations.guiLeft = guiLeft + 220;
scrollAnimations.guiTop = guiTop + 4;
addScroll(scrollAnimations);
addTextField(new GuiNpcTextField(55, this, fontRendererObj, guiLeft + 220, guiTop + 4 + 3 + 185, 143, 20, search));
if (animation.id == -1)
return;
addLabel(new GuiNpcLabel(10,"ID", guiLeft + 178, guiTop + 4));
addLabel(new GuiNpcLabel(11, animation.id + "", guiLeft + 178, guiTop + 14));
}
@Override
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(getTextField(55) != null){
if(getTextField(55).isFocused()){
if(search.equals(getTextField(55).getText()))
return;
search = getTextField(55).getText().toLowerCase();
scrollAnimations.setList(getSearchList());
}
}
}
private List<String> getSearchList(){
if(search.isEmpty()){
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.data.keySet()){
if(name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
@Override
protected void actionPerformed(GuiButton guibutton){
GuiNpcButton button = (GuiNpcButton) guibutton;
if(button.id == 0){
save();
String name = "New";
while(data.containsKey(name))
name += "_";
Animation animation = new Animation(-1, name);
Client.sendData(EnumPacketServer.AnimationSave, animation.writeToNBT());
}
if(button.id == 1){
if(data.containsKey(scrollAnimations.getSelected())) {
Client.sendData(EnumPacketServer.AnimationRemove, data.get(selected));
scrollAnimations.clear();
animation = new Animation();
initGui();
}
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0) {
if (animation != null) {
if (!prevSelected.isEmpty()) {
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
}
}
Client.sendData(EnumPacketServer.AnimationGet, scroll.getSelected());
frameIndex = 0;
prevSelected = scroll.getSelected();
}
}
@Override
public void setGuiData(NBTTagCompound compound) {
this.animation = new Animation();
animation.readFromNBT(compound);
setSelected(animation.name);
initGui();
}
@Override
public void unFocused(GuiNpcTextField textfield) {
String text = textfield.getText();
Frame frame = this.editingFrame();
FramePart part = this.editingPart();
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
String name = scrollAnimations.getSelected();
this.data = data;
scrollAnimations.setList(getSearchList());
if(name != null)
scrollAnimations.setSelected(name);
}
@Override
public void setSelected(String selected) {
this.selected = selected;
scrollAnimations.setSelected(selected);
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) {
if(guiCustomScroll.id == 0)
{
save();
selected = scrollAnimations.getSelected();
Client.sendData(EnumPacketServer.AnimationGet, data.get(selected));
}
}
public void save() {
if(selected != null && data.containsKey(selected) && animation != null){
Client.sendData(EnumPacketServer.AnimationSave, animation.writeToNBT());
}
}
@Override
public void unFocused(GuiNpcTextField guiNpcTextField) {
if(animation.id == -1)
return;
if(guiNpcTextField.id == 0) {
String name = guiNpcTextField.getText();
if(!name.isEmpty() && !data.containsKey(name)){
String old = animation.name;
data.remove(animation.name);
animation.name = name;
data.put(animation.name, animation.id);
selected = name;
scrollAnimations.replace(old, animation.name);
}
}
}
if (textfield.id == 30 && !text.isEmpty()) {
String nameText = text.replaceAll("[^a-zA-Z0-9_-]", "_");
if (!scroll.getList().contains(nameText)) {
animation.name = nameText;
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
} 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();
} else if (editingMode == 1 && frame != null) {
frame.speed = textfield.getFloat();
} else if (editingMode == 2 && part != null) {
part.speed = textfield.getFloat();
}
} else if (textfield.id == 51 && frame != null) {
frame.duration = textfield.getInteger();
} else if (textfield.id >= 71 && textfield.id <= 73 && part != null) {
part.rotation[textfield.id-71] = textfield.getFloat();
} else if (textfield.id >= 81 && textfield.id <= 83 && part != null) {
part.pivot[textfield.id-81] = textfield.getFloat();
}
}
@Override
public void subGuiClosed(SubGuiInterface subgui) {
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
scroll.setList(list);
initGui();
}
@Override
public void setSelected(String selected) {
}
@Override
public void setGuiData(NBTTagCompound compound) {
this.animation = new Animation();
animation.readFromNBT(compound);
npc.display.animationData.animation = animation;
this.playingAnimation = false;
npc.display.animationData.animation.paused = false;
initGui();
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
if (animation != null) {
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
}
}
}
@@ -0,0 +1,517 @@
package noppes.npcs.client.gui.global;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
public class GuiNPCManageAnimationsOLD extends GuiModelInterface implements IScrollData, ITextfieldListener, ICustomScrollListener, IGuiData {
private Animation animation = null;
private EnumAnimationPart editingPart = EnumAnimationPart.HEAD;
private int editingMode = 0;
private int frameIndex = 0;
public boolean playingAnimation = false;
private Frame prevFrame;
private GuiCustomScroll scroll;
private String prevSelected = "";
private long prevTick;
public GuiNPCManageAnimationsOLD(EntityNPCInterface npc) {
super((EntityCustomNpc) npc);
Client.sendData(EnumPacketServer.AnimationsGet);
xOffset -= 20;
yOffset = -45;
AnimationData data = npc.display.animationData;
data.setEnabled(true);
}
@Override
public void initGui() {
super.initGui();
if(scroll == null)
scroll = new GuiCustomScroll(this,0);
scroll.setSize(100, 175);
scroll.guiLeft = guiLeft - 20;
scroll.guiTop = guiTop + 15;
this.addScroll(scroll);
this.addButton(new GuiNpcButton(1,guiLeft - 20, guiTop - 5, 45, 20, "gui.add"));
this.addButton(new GuiNpcButton(2,guiLeft + 30, guiTop - 5, 45, 20, "gui.remove"));
if (animation != null) {
frameIndex = animation.frames.size() > 0 ? frameIndex % animation.frames.size() : 0;
Frame editingFrame = this.editingFrame();
if (editingFrame != null) {
if (editingFrame != prevFrame && prevFrame != null) {
HashMap<EnumAnimationPart,FramePart> frameParts = prevFrame.frameParts;
for (Map.Entry<EnumAnimationPart,FramePart> entry : frameParts.entrySet()) {
if (editingFrame.frameParts.containsKey(entry.getKey())) {
FramePart part = editingFrame.frameParts.get(entry.getKey());
FramePart prevPart = prevFrame.frameParts.get(entry.getKey());
part.prevRotations = prevPart.prevRotations;
part.prevPivots = prevPart.prevPivots;
part.partialRotationTick = prevPart.partialRotationTick;
part.partialPivotTick = prevPart.partialPivotTick;
}
}
}
}
prevFrame = editingFrame;
FramePart editingPart = this.editingPart();
AnimationData data = npc.display.animationData;
if (!playingAnimation) {
data.animation = new Animation();
data.animation.smooth = animation.smooth;
data.animation.renderTicks = animation.renderTicks;
data.animation.loop = 0;
if (editingFrame != null) {
data.animation.frames.add(editingFrame);
}
}
for (Frame frame : animation.frames) {
frame.parent = animation;
if (!frame.isCustomized()) {
frame.speed = animation.speed;
frame.smooth = animation.smooth;
frame.renderTicks = animation.renderTicks;
}
for (Map.Entry<EnumAnimationPart,FramePart> entry : frame.frameParts.entrySet()) {
FramePart part = entry.getValue();
part.parent = animation;
if (!part.isCustomized()) {
part.speed = frame.speed;
part.smooth = frame.smooth;
}
}
}
editingMode %= 3;
if (animation.loop >= animation.frames.size()) {
animation.loop = -1;
}
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 9 + 145, guiTop + 180, 0xFFFFFF));
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 + 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));
String animTexture = "customnpcs:textures/gui/animation.png";
if (data.animation != null && data.animation.frames.size() > 0) {
if (!this.playingAnimation || data.animation.paused) {//Play
this.addLabel(new GuiNpcLabel(90, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft - 15, guiTop + 206, 0xFFFFFF));
if (data.animation.paused) {
this.addLabel(new GuiNpcLabel(94, "", guiLeft + 21, guiTop + 206, 0xFFFFFF));
}
this.addButton(new GuiTexturedButton(91, "", guiLeft + 35, guiTop + 200, 11, 20, animTexture, 18, 71));
} else {//Pause
this.addLabel(new GuiNpcLabel(90, "animation.playing", guiLeft - 15, guiTop + 206, 0xFFFFFF));
this.addLabel(new GuiNpcLabel(94, "", guiLeft + 20, guiTop + 206, 0xFFFFFF));
this.addButton(new GuiTexturedButton(92, "", guiLeft + 35, guiTop + 200, 14, 20, animTexture, 0, 71));
}
if (this.playingAnimation) {//Stop
this.addButton(new GuiTexturedButton(93, "", guiLeft + 55, guiTop + 200, 14, 20, animTexture, 33, 71));
}
}
if (editingMode == 0) {
//name - textfield
// Send the old animation name (string selected on the scroll).
// On the server side, if the new animation's name is different from the old one but already exists,
// do not change the name (set the name to the old animation name after the animation is read from NBT).
this.addTextField(new GuiNpcTextField(30, this, guiLeft + 270, guiTop + 18, 100, 15, animation.name));
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 44, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 310, guiTop + 40, 30, 15, animation.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0,Float.MAX_VALUE,1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 64, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 58, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, animation.smooth));
//
//ticks - button
this.addLabel(new GuiNpcLabel(35, "animation.tickType", guiLeft + 270, guiTop + 104, 0xFFFFFF));
this.addButton(new GuiNpcButton(36, guiLeft + 325, guiTop + 98, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, animation.renderTicks ? 0 : 1));
//
//loop - button
this.addLabel(new GuiNpcLabel(37, "animation.loopStart", guiLeft + 270, guiTop + 84, 0xFFFFFF));
this.addButton(new GuiNpcButton(38, guiLeft + 325, guiTop + 78, 75, 20, animation.loop == -1 ? "No Looping" : "Frame " + animation.loop));
//
//whileStanding - button
this.addLabel(new GuiNpcLabel(39, "animation.whileStanding", guiLeft + 270, guiTop + 124, 0xFFFFFF));
this.addButton(new GuiNpcButton(40, guiLeft + 345, guiTop + 118, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileStanding ? 0 : 1));
//
//whileAttacking - button
this.addLabel(new GuiNpcLabel(41, "animation.whileAttacking", guiLeft + 270, guiTop + 144, 0xFFFFFF));
this.addButton(new GuiNpcButton(42, guiLeft + 345, guiTop + 138, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileAttacking ? 0 : 1));
//
//whileMoving - button
this.addLabel(new GuiNpcLabel(43, "animation.whileMoving", guiLeft + 270, guiTop + 164, 0xFFFFFF));
this.addButton(new GuiNpcButton(44, guiLeft + 345, guiTop + 158, 30, 20, new String[]{"gui.yes", "gui.no"}, animation.whileMoving ? 0 : 1));
} else if (editingFrame != null) {
if (editingMode == 1) {
//
//duration - textfield
this.addLabel(new GuiNpcLabel(50, "animation.duration", guiLeft + 270, guiTop + 25, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(51, this, guiLeft + 330, guiTop + 21, 30, 15, editingFrame.duration + ""));
this.getTextField(51).integersOnly = true;
this.getTextField(51).setMinMaxDefaultFloat(0, Integer.MAX_VALUE, 10);
//
//customized - button, enables all the following options.
this.addLabel(new GuiNpcLabel(52, "animation.customized", guiLeft + 270, guiTop + 44, 0xFFFFFF));
this.addButton(new GuiNpcButton(53, guiLeft + 325, guiTop + 38, 30, 20, new String[]{"gui.yes", "gui.no"}, editingFrame.isCustomized() ? 0 : 1));
if (editingFrame.isCustomized()) {
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 64, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 330, guiTop + 60, 30, 15, editingFrame.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 84, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 78, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingFrame.smooth));
//
//ticks - button
this.addLabel(new GuiNpcLabel(35, "animation.tickType", guiLeft + 270, guiTop + 104, 0xFFFFFF));
this.addButton(new GuiNpcButton(36, guiLeft + 325, guiTop + 98, 75, 20, new String[]{"animation.renderTicks", "animation.mcTicks"}, editingFrame.renderTicks ? 0 : 1));
}
} else if (editingMode == 2) {
//
//6 body part textured buttons
//Add/remove part button
// 6 custom GUI textured buttons for each body part determine "this.currentPart (enum)".
// If the current frame doesn't have that part, the button will say "Add part"
// otherwise, the button will say "Remove", and more options for editing the part become available:
//
//Head
this.addButton(new GuiTexturedButton(60, "",guiLeft + 270, guiTop + 18,22,23, animTexture,0,0));
//Body
this.addButton(new GuiTexturedButton(61, "",guiLeft + 270, guiTop + 43,22,23, animTexture,24,0));
//Right Arm
this.addButton(new GuiTexturedButton(62, "",guiLeft + 261, guiTop + 43,8,23, animTexture,48,0));
//Left Arm
this.addButton(new GuiTexturedButton(63, "",guiLeft + 296, guiTop + 43,8,23, animTexture,48,0));
//Right Leg
this.addButton(new GuiTexturedButton(64, "",guiLeft + 271, guiTop + 68,10,23, animTexture,58,0));
//Left Leg
this.addButton(new GuiTexturedButton(65, "",guiLeft + 282, guiTop + 68,10,23, animTexture,58,0));
//Full Body
this.addButton(new GuiTexturedButton(66, "",guiLeft + 310, guiTop + 20,17,23, animTexture,70,0));
for (int i = 0; i < 7; i++) {
if (this.buttons.containsKey(60 + i)) {
((GuiTexturedButton) this.getButton(60 + i)).scale = 1.2F;
if (!editingFrame.frameParts.containsKey(EnumAnimationPart.values()[i])) {
((GuiTexturedButton) this.getButton(60 + i)).textureX += 96;
}
}
}
if (editingPart != null) {
//remove part button
this.addLabel(new GuiNpcLabel(67, editingPart.part.name(), guiLeft + 320, guiTop + 60, 0xFFFFFF));
this.addButton(new GuiNpcButton(68, guiLeft + 315, guiTop + 75, 60, 20, "gui.remove"));
//
//rotation - 3 textfields
this.addLabel(new GuiNpcLabel(70, "animation.rotations", guiLeft + 270, guiTop + 105, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(71, this, guiLeft + 270, guiTop + 117, 35, 15, editingPart.rotation[0] + ""));
this.getTextField(71).floatsOnly = true;
this.getTextField(71).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(72, this, guiLeft + 310, guiTop + 117, 35, 15, editingPart.rotation[1] + ""));
this.getTextField(72).floatsOnly = true;
this.getTextField(72).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(73, this, guiLeft + 350, guiTop + 117, 35, 15, editingPart.rotation[2] + ""));
this.getTextField(73).floatsOnly = true;
this.getTextField(73).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
//
//pivot - 3 textfields
this.addLabel(new GuiNpcLabel(80, "animation.pivots", guiLeft + 270, guiTop + 137, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(81, this, guiLeft + 270, guiTop + 149, 35, 15, editingPart.pivot[0] + ""));
this.getTextField(81).floatsOnly = true;
this.getTextField(81).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(82, this, guiLeft + 310, guiTop + 149, 35, 15, editingPart.pivot[1] + ""));
this.getTextField(82).floatsOnly = true;
this.getTextField(82).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
this.addTextField(new GuiNpcTextField(83, this, guiLeft + 350, guiTop + 149, 35, 15, editingPart.pivot[2] + ""));
this.getTextField(83).floatsOnly = true;
this.getTextField(83).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0);
//
//customized - button, enables all the following options.
this.addLabel(new GuiNpcLabel(52, "animation.customized", guiLeft + 270, guiTop + 174, 0xFFFFFF));
this.addButton(new GuiNpcButton(53, guiLeft + 325, guiTop + 168, 30, 20, new String[]{"gui.yes", "gui.no"}, editingPart.isCustomized() ? 0 : 1));
if (editingPart.isCustomized()) {
//
//speed - textfield
this.addLabel(new GuiNpcLabel(31, "stats.speed", guiLeft + 270, guiTop + 194, 0xFFFFFF));
this.addTextField(new GuiNpcTextField(32, this, guiLeft + 330, guiTop + 190, 30, 15, editingPart.speed + ""));
this.getTextField(32).floatsOnly = true;
this.getTextField(32).setMinMaxDefaultFloat(0, Float.MAX_VALUE, 1.0F);
//
//smooth - button
this.addLabel(new GuiNpcLabel(33, "animation.smoothing", guiLeft + 270, guiTop + 214, 0xFFFFFF));
this.addButton(new GuiNpcButton(34, guiLeft + 325, guiTop + 208, 60, 20, new String[]{"animation.smooth", "animation.linear", "gui.none"}, editingPart.smooth));
}
}
}
} else {
this.addLabel(new GuiNpcLabel(50, "animation.addFrame", guiLeft + 270, guiTop + 100, 0xFFFFFF));
}
}
}
private Frame editingFrame() {
if (this.animation == null || this.frameIndex >= this.animation.frames.size()) {
return null;
}
return animation.frames.get(this.frameIndex);
}
private FramePart editingPart() {
Frame editingFrame = this.editingFrame();
if (this.animation == null || editingFrame == null) {
return null;
}
return editingFrame.frameParts.get(this.editingPart);
}
@Override
protected void actionPerformed(GuiButton guibutton){
super.actionPerformed(guibutton);
Frame editingFrame = this.editingFrame();
FramePart part = this.editingPart();
int value = ((GuiNpcButton)guibutton).getValue();
AnimationData data = npc.display.animationData;
if (guibutton.id == 1) {
// Client.sendData(EnumPacketServer.AnimationAdd);
frameIndex = 0;
} else if (guibutton.id == 2 && scroll.getSelected() != null) {
Client.sendData(EnumPacketServer.AnimationRemove, scroll.getSelected());
this.playingAnimation = false;
data.animation = null;
animation = null;
frameIndex = 0;
} else 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));
}
} else if (guibutton.id == 12) {
animation.frames.remove(frameIndex);
} 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 == 16) {
frameIndex++;
} else if (guibutton.id == 20) {
editingMode++;
} else if (guibutton.id >= 60 && guibutton.id <= 66) {//Animation part buttons
EnumAnimationPart enumPart = EnumAnimationPart.values()[guibutton.id-60];
if (editingFrame != null && !editingFrame.frameParts.containsKey(enumPart)) {
FramePart framePart = new FramePart(enumPart);
framePart.prevRotations = new float[]{0, 0, 0};
editingFrame.addPart(framePart);
}
this.editingPart = enumPart;
} else if (guibutton.id == 68 && editingFrame != null) {
editingFrame.removePart(this.editingPart.name());
} else if (guibutton.id == 53 && editingFrame != null) {
if (editingMode == 1) {
editingFrame.setCustomized(!editingFrame.isCustomized());
} else if (editingMode == 2 && part != null) {
part.setCustomized(!part.isCustomized());
}
} else if (guibutton.id == 34) {
if (editingMode == 0) {
animation.smooth = (byte) value;
} else if (editingMode == 1 && editingFrame != null) {
editingFrame.smooth = (byte) value;
} else if (editingMode == 2 && part != null) {
part.smooth = (byte) value;
}
} else if (guibutton.id == 36) {
if (editingMode == 0) {
animation.renderTicks = value == 0;
} else if (editingMode == 1 && editingFrame != null) {
editingFrame.renderTicks = value == 0;
}
} else if (guibutton.id == 38) {
animation.loop++;
} else if (guibutton.id == 40) {
animation.whileStanding = value == 0;
} else if (guibutton.id == 42) {
animation.whileAttacking = value == 0;
} else if (guibutton.id == 44) {
animation.whileMoving = value == 0;
} else if (guibutton.id == 91) {
if (!this.playingAnimation || !data.isActive()) {
animation.currentFrame = 0;
animation.currentFrameTime = 0;
for (Frame frame : animation.frames) {
for (FramePart framePart : frame.frameParts.values()) {
framePart.prevRotations = new float[]{0,0,0};
framePart.prevPivots = new float[]{0, 0, 0};
}
}
}
this.playingAnimation = true;
data.animation = animation;
data.animation.paused = false;
} else if (guibutton.id == 92) {
data.animation.paused = true;
} else if (guibutton.id == 93) {
this.playingAnimation = false;
data.animation.paused = false;
}
initGui();
}
@Override
public void drawScreen(int par1, int par2, float par3)
{
super.drawScreen(par1,par2,par3);
AnimationData data = npc.display.animationData;
if (!data.isActive() && this.playingAnimation) {
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(94);
if (label != null) {
label.label += ".";
if (label.label.length()%4 == 0) {
label.label = "";
}
}
}
prevTick = time;
}
}
@Override
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
if (scroll.id == 0) {
if (animation != null) {
if (!prevSelected.isEmpty()) {
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
}
}
Client.sendData(EnumPacketServer.AnimationGet, scroll.getSelected());
frameIndex = 0;
prevSelected = scroll.getSelected();
}
}
@Override
public void unFocused(GuiNpcTextField textfield) {
String text = textfield.getText();
Frame frame = this.editingFrame();
FramePart part = this.editingPart();
if (textfield.id == 30 && !text.isEmpty()) {
String nameText = text.replaceAll("[^a-zA-Z0-9_-]", "_");
if (!scroll.getList().contains(nameText)) {
animation.name = nameText;
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
} 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();
} else if (editingMode == 1 && frame != null) {
frame.speed = textfield.getFloat();
} else if (editingMode == 2 && part != null) {
part.speed = textfield.getFloat();
}
} else if (textfield.id == 51 && frame != null) {
frame.duration = textfield.getInteger();
} else if (textfield.id >= 71 && textfield.id <= 73 && part != null) {
part.rotation[textfield.id-71] = textfield.getFloat();
} else if (textfield.id >= 81 && textfield.id <= 83 && part != null) {
part.pivot[textfield.id-81] = textfield.getFloat();
}
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
scroll.setList(list);
initGui();
}
@Override
public void setSelected(String selected) {
}
@Override
public void setGuiData(NBTTagCompound compound) {
this.animation = new Animation();
animation.readFromNBT(compound);
npc.display.animationData.animation = animation;
this.playingAnimation = false;
npc.display.animationData.animation.paused = false;
initGui();
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
if (animation != null) {
Client.sendData(EnumPacketServer.AnimationSave, prevSelected, animation.writeToNBT());
}
}
}
@@ -83,7 +83,7 @@ public enum EnumPacketServer {
MovingPathSave(CustomNpcsPermissions.TOOL_PATHER,true), MovingPathGet(true),
DialogNpcGet,
AnimationListGet, AnimationGet, AnimationAdd, AnimationDelete, AnimationSave,
AnimationsGet, AnimationGet, AnimationRemove, AnimationSave,
RecipesGet, RecipeGet, QuestOpenGui, PlayerDataGet, QuestLogToServer,
@@ -4,15 +4,18 @@ import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.api.handler.IAnimationHandler;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.Faction;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
import java.util.*;
public class AnimationController implements IAnimationHandler {
public HashMap<String, Animation> animations;
public HashMap<Integer, Animation> animations;
public static AnimationController Instance;
private int lastUsedID = 0;
public AnimationController() {
Instance = this;
@@ -44,7 +47,7 @@ public class AnimationController implements IAnimationHandler {
Animation animation = new Animation();
animation.name = file.getName().substring(0, file.getName().length() - 5);
animation.readFromNBT(NBTJsonUtil.LoadFile(file));
animations.put(animation.name,animation);
animations.put(animation.id, animation);
} catch(Exception e) {
LogWriter.error("Error loading: " + file.getAbsolutePath(), e);
}
@@ -56,9 +59,35 @@ public class AnimationController implements IAnimationHandler {
return new File(CustomNpcs.getWorldSaveDirectory(), "animations");
}
public IAnimation saveAnimation(IAnimation animation){
animations.put(animation.getName(), (Animation) animation);
public int getUnusedId(){
if(lastUsedID == 0){
for(int catid : animations.keySet()){
if(catid > lastUsedID)
lastUsedID = catid;
}
}
lastUsedID++;
return lastUsedID;
}
public IAnimation saveAnimation(IAnimation animation){
if(animation.getID() < 0){
animation.setID(getUnusedId());
while(hasName(animation.getName()))
animation.setName(animation.getName() + "_");
}
else{
Animation existing = animations.get(animation.getID());
if(existing != null && !existing.name.equals(animation.getName()))
while(hasName(animation.getName()))
animation.setName(animation.getName() + "_");
}
animations.remove(animation.getID());
animations.put(animation.getID(), (Animation) animation);
// Save Animation File
File dir = this.getDir();
if(!dir.exists())
dir.mkdirs();
@@ -74,30 +103,64 @@ public class AnimationController implements IAnimationHandler {
} catch (Exception e) {
LogWriter.except(e);
}
return animations.get(animation.getName());
return animations.get(animation.getID());
}
public boolean hasName(String newName) {
if(newName.trim().isEmpty())
return true;
for(Animation animation : animations.values())
if(animation.name.equals(newName))
return true;
return false;
}
public void delete(String name) {
if(!this.animations.containsKey(name))
return;
File dir = this.getDir();
for (File file : dir.listFiles()) {
if (!file.isFile() || !file.getName().endsWith(".json"))
continue;
if (file.getName().equals(name+".json")) {
file.delete();
break;
Animation delete = getAnimationFromName(name);
if(delete != null){
Animation foundAnimation = this.animations.remove(delete.getID());
if(foundAnimation != null && foundAnimation.name != null){
File dir = this.getDir();
for (File file : dir.listFiles()) {
if (!file.isFile() || !file.getName().endsWith(".json"))
continue;
if (file.getName().equals(foundAnimation.name+".json")) {
file.delete();
break;
}
}
}
}
}
public void delete(int id) {
if(!this.animations.containsKey(id))
return;
Animation foundAnimation = this.animations.remove(id);
if(foundAnimation != null && foundAnimation.name != null){
File dir = this.getDir();
for (File file : dir.listFiles()) {
if (!file.isFile() || !file.getName().endsWith(".json"))
continue;
if (file.getName().equals(foundAnimation.name+".json")) {
file.delete();
break;
}
}
}
this.animations.remove(name);
}
public boolean has(String name) {
return this.animations.containsKey(name);
return getAnimationFromName(name) != null;
}
public IAnimation get(String name) {
return this.animations.get(name);
return getAnimationFromName(name);
}
public IAnimation get(int id) {
return this.animations.get(id);
}
public IAnimation[] getAnimations() {
@@ -106,7 +169,7 @@ public class AnimationController implements IAnimationHandler {
}
public Animation getAnimationFromName(String animation){
for (Map.Entry<String,Animation> entryAnimation : AnimationController.getInstance().animations.entrySet()){
for (Map.Entry<Integer,Animation> entryAnimation : AnimationController.getInstance().animations.entrySet()){
if (entryAnimation.getValue().name.equalsIgnoreCase(animation)){
return entryAnimation.getValue();
}
@@ -10,15 +10,18 @@ import noppes.npcs.constants.EnumAnimationPart;
import noppes.npcs.controllers.AnimationController;
import java.util.ArrayList;
import java.util.UUID;
public class Animation implements IAnimation {
public int id = -1; // Only for internal usage, does not save
public ArrayList<Frame> frames = new ArrayList<>();
public int currentFrame = 0;
public int currentFrameTime = 0;
public String name;
public String name = "";
public float speed = 1.0F;
public byte smooth = 0;
public int loop = -1; //If greater than 0 and less than the amount of frames, the animation will begin looping when it reaches this frame.
@@ -33,14 +36,17 @@ public class Animation implements IAnimation {
public Animation(){}
public Animation(String name){
public Animation(int id, String name){
this.name = name;
this.id = id;
}
public Animation(String name, float speed, byte smooth){
public Animation(int id, String name, float speed, byte smooth){
this.name = name;
this.speed = speed;
this.smooth = smooth;
this.id = id;
}
public IFrame currentFrame() {
@@ -155,7 +161,18 @@ public class Animation implements IAnimation {
return AnimationController.Instance.saveAnimation(this);
}
@Override
public int getID() {
return id;
}
@Override
public void setID(int newID) {
id = newID;
}
public void readFromNBT(NBTTagCompound compound){
id = compound.getInteger("ID");
name = compound.getString("Name");
speed = compound.getFloat("Speed");
smooth = compound.getByte("Smooth");
@@ -181,6 +198,7 @@ public class Animation implements IAnimation {
public NBTTagCompound writeToNBT(){
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("ID", id);
compound.setString("Name", name);
compound.setFloat("Speed", speed);
compound.setByte("Smooth", smooth);
@@ -606,11 +606,11 @@ public class NpcAPI extends AbstractNpcAPI {
}
public IAnimation createAnimation(String name) {
return new Animation(name);
return new Animation(-1, name);
}
public IAnimation createAnimation(String name, float speed, byte smooth) {
return new Animation(name, speed, smooth);
return new Animation(-1, name, speed, smooth);
}
public IFrame createFrame(int duration) {