Added the NPC model to the animation middleman GUI, as well as logic for playing/pausing the animation.

This commit is contained in:
luisc committed 2023-11-08 11:58:55 -06:00
1 parent a3a5a4313f
commit 11626de55e
4 files changed
+252 -21

No files matched your search

@@ -6,24 +6,31 @@ import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.AnimationData;
import noppes.npcs.controllers.data.Frame;
import noppes.npcs.controllers.data.FramePart;
import noppes.npcs.entity.EntityNPCInterface;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData, ISubGuiListener
public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData, ISubGuiListener
{
private GuiCustomScroll scrollAnimations;
private HashMap<String,Integer> data = new HashMap<String,Integer>();
private Animation animation = new Animation();
public boolean playingAnimation = false;
private String selected = null;
private String search = "";
public GuiNPCManageAnimations(EntityNPCInterface npc)
{
super(npc);
this.xOffset = -148 + 70;
this.yOffset = -170 + 137;
Client.sendData(EnumPacketServer.AnimationsGet);
}
@@ -46,10 +53,41 @@ public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollD
if (animation.id == -1)
return;
addLabel(new GuiNpcLabel(10,"ID", guiLeft + 178, guiTop + 4));
addLabel(new GuiNpcLabel(11, animation.id + "", guiLeft + 178, guiTop + 14));
addLabel(new GuiNpcLabel(10,"ID", guiLeft + 368, guiTop + 54));
addLabel(new GuiNpcLabel(11, animation.id + "", guiLeft + 368, guiTop + 64));
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;
}
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));
}
}
}
@Override
public void drawScreen(int i, int j, float f) {
super.drawScreen(i, j, f);
}
@Override
public void keyTyped(char c, int i)
{
@@ -95,14 +133,37 @@ public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollD
initGui();
}
}
AnimationData data = npc.display.animationData;
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;
}
}
@Override
public void setGuiData(NBTTagCompound compound) {
this.animation = new Animation();
animation.readFromNBT(compound);
setSelected(animation.name);
this.playingAnimation = false;
initGui();
}
@@ -160,5 +221,4 @@ public class GuiNPCManageAnimations extends GuiNPCInterface2 implements IScrollD
@Override
public void subGuiClosed(SubGuiInterface subgui) {
}
}
@@ -0,0 +1,161 @@
package noppes.npcs.client.gui.util;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.client.EntityUtil;
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.entity.data.ModelData;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class GuiModelInterface2 extends GuiNPCInterface2{
public ModelData playerdata;
private static float rotation = 0;
private GuiNpcButton left,right,zoom,unzoom;
private static float zoomed = 60;
public int xOffset = 0;
public int yOffset = 0;
public EntityNPCInterface npc;
public GuiModelInterface2(EntityNPCInterface npc){
super(npc);
this.npc = npc;
playerdata = ((EntityCustomNpc)npc).modelData;
//xSize = 380;
drawDefaultBackground = false;
}
@Override
public void initGui() {
super.initGui();
addButton(unzoom = new GuiNpcButton(666, guiLeft + 148 + xOffset, guiTop + 200 + yOffset, 20, 20, "-"));
addButton(zoom = new GuiNpcButton(667, guiLeft + 214 + xOffset, guiTop + 200 + yOffset, 20, 20, "+"));
addButton(left = new GuiNpcButton(668, guiLeft + 170 + xOffset, guiTop + 200 + yOffset, 20, 20, "<"));
addButton(right = new GuiNpcButton(669, guiLeft + 192 + xOffset, guiTop + 200 + yOffset, 20, 20, ">"));
}
@Override
protected void actionPerformed(GuiButton btn) {
if(btn.id == 670){
close();
}
}
@Override
public boolean doesGuiPauseGame()
{
return false;
}
private long start = -1;
@Override
public void drawScreen(int par1, int par2, float par3)
{
if(Mouse.isButtonDown(0)){
if(left.mousePressed(mc, par1, par2))
rotation+=par3 * 2;
else if(right.mousePressed(mc, par1, par2))
rotation-=par3 * 2;
else if(zoom.mousePressed(mc, par1, par2))
zoomed+=par3 * 2;
else if(unzoom.mousePressed(mc, par1, par2) && zoomed > 10)
zoomed-=par3 * 2;
}
super.drawScreen(par1, par2, par3);
GL11.glColor4f(1, 1, 1, 1);
EntityLivingBase entity = playerdata.getEntity(npc);
if(entity == null)
entity = this.npc;
EntityUtil.Copy(npc, entity);
int l = guiLeft + 190 + xOffset;
int i1 = guiTop + 180 + yOffset;
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glPushMatrix();
GL11.glTranslatef(l, i1, 50F);
GL11.glScalef(-zoomed, zoomed, zoomed);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
float f2 = entity.renderYawOffset;
float f3 = entity.rotationYaw;
float f4 = entity.rotationPitch;
float f7 = entity.rotationYawHead;
float f5 = (float)(l) - par1;
float f6 = (float)(i1 - 50) - par2;
GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F);
RenderHelper.enableStandardItemLighting();
GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(-(float)Math.atan(f6 / 80F) * 20F, 1.0F, 0.0F, 0.0F);
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
entity.prevRotationYaw = entity.rotationYaw = (float)Math.atan(f5 / 80F) * 40F + rotation;
entity.rotationPitch = -(float)Math.atan(f6 / 80F) * 20F;
entity.prevRotationYawHead = entity.rotationYawHead = entity.rotationYaw;
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
RenderManager.instance.playerViewY = 180F;
try{
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
}
catch(Exception e){
playerdata.setEntityClass(null);
}
entity.prevRenderYawOffset = entity.renderYawOffset = f2;
entity.prevRotationYaw = entity.rotationYaw = f3;
entity.rotationPitch = f4;
entity.prevRotationYawHead = entity.rotationYawHead = f7;
GL11.glPopMatrix();
RenderHelper.disableStandardItemLighting();
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GL11.glDisable(GL11.GL_TEXTURE_2D);
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
@Override
protected void drawBackground() {
super.drawBackground();
int xPosGradient = guiLeft + 10;
int yPosGradient = guiTop + 10;
drawGradientRect(xPosGradient, yPosGradient, 200 + xPosGradient ,180 + yPosGradient, 0xc0101010, 0xd0101010);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public void keyTyped(char par1, int par2)
{
super.keyTyped(par1, par2);
if (par2 == 1)
{
close();
}
}
public void close(){
this.mc.displayGuiScreen((GuiScreen)null);
this.mc.setIngameFocus();
}
@Override
public void save() {
// TODO Auto-generated method stub
}
}
@@ -231,18 +231,7 @@ public abstract class GuiNPCInterface extends GuiScreen
drawDefaultBackground();
if(background != null && mc.renderEngine != null){
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft, guiTop, 0);
GL11.glScalef(bgScale*bgScaleX, bgScale*bgScaleY, bgScale*bgScaleZ);
mc.renderEngine.bindTexture(background);
if(xSize > 256){
drawTexturedModalRect(0, 0, 0, 0, 250, ySize);
drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize);
}
else
drawTexturedModalRect(0, 0, 0, 0, xSize, ySize);
GL11.glPopMatrix();
drawBackground();
}
drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff);
@@ -264,6 +253,22 @@ public abstract class GuiNPCInterface extends GuiScreen
if(subgui != null)
subgui.drawScreen(i,j,f);
}
protected void drawBackground() {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPushMatrix();
GL11.glTranslatef(guiLeft, guiTop, 0);
GL11.glScalef(bgScale*bgScaleX, bgScale*bgScaleY, bgScale*bgScaleZ);
mc.renderEngine.bindTexture(background);
if(xSize > 256){
drawTexturedModalRect(0, 0, 0, 0, 250, ySize);
drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize);
}
else
drawTexturedModalRect(0, 0, 0, 0, xSize, ySize);
GL11.glPopMatrix();
}
public FontRenderer getFontRenderer() {
return this.fontRendererObj;
}
@@ -45,10 +45,7 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface
{
if(drawDefaultBackground)
drawDefaultBackground(); //drawDefaultBackground
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(background);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, 200, 220);
drawTexturedModalRect(guiLeft + xSize-230, guiTop, 26, 0, 230, 220);
drawBackground();
menu.drawElements(getFontRenderer(), i, j, mc, f);
boolean bo = drawDefaultBackground;
@@ -56,4 +53,12 @@ public abstract class GuiNPCInterface2 extends GuiNPCInterface
super.drawScreen(i, j, f);
drawDefaultBackground = bo;
}
@Override
protected void drawBackground() {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(background);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, 200, 220);
drawTexturedModalRect(guiLeft + xSize-230, guiTop, 26, 0, 230, 220);
}
}