mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 19:54:26 +00:00
Compare commits
16
Commits
dialog-editor
...
easing
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff33ebfe8d | ||
|
|
5f04b6fa69 | ||
|
|
a4bca99126 | ||
|
|
a7d1b9cd1f | ||
|
|
56c4d3e7f1 | ||
|
|
1f44ea5987 | ||
|
|
cb8a78e82b | ||
|
|
04d37623eb | ||
|
|
1a4f513fb3 | ||
|
|
e187b62348 | ||
|
|
a9e19294f8 | ||
|
|
54a45fbeb8 | ||
|
|
435ff3f5de | ||
|
|
8b92c04c45 | ||
|
|
32e828f2c8 | ||
|
|
689db91622 |
No files matched your search
@@ -3,7 +3,6 @@ package kamkeel.npcs.command.profile;
|
|||||||
import net.minecraft.command.CommandException;
|
import net.minecraft.command.CommandException;
|
||||||
import net.minecraft.command.ICommandSender;
|
import net.minecraft.command.ICommandSender;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.util.ChatComponentTranslation;
|
|
||||||
import noppes.npcs.CustomNpcsPermissions;
|
import noppes.npcs.CustomNpcsPermissions;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|||||||
@@ -292,6 +292,7 @@ public class ClientProxy extends CommonProxy {
|
|||||||
animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
|
animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
|
||||||
save = false;
|
save = false;
|
||||||
}
|
}
|
||||||
|
animNpc.display.setName("Animation Dude");
|
||||||
return new GuiNPCManageAnimations(animNpc, save);
|
return new GuiNPCManageAnimations(animNpc, save);
|
||||||
} else if (gui == EnumGuiType.ManageLinked)
|
} else if (gui == EnumGuiType.ManageLinked)
|
||||||
return new GuiNPCManageLinked(npc);
|
return new GuiNPCManageLinked(npc);
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import noppes.npcs.client.gui.hud.CompassHudComponent;
|
|||||||
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
import noppes.npcs.client.gui.hud.EnumHudComponent;
|
||||||
import noppes.npcs.client.gui.hud.HudComponent;
|
import noppes.npcs.client.gui.hud.HudComponent;
|
||||||
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
import noppes.npcs.client.gui.player.inventory.GuiCNPCInventory;
|
||||||
|
import noppes.npcs.client.gui.util.animation.Cursors;
|
||||||
import noppes.npcs.client.renderer.RenderNPCInterface;
|
import noppes.npcs.client.renderer.RenderNPCInterface;
|
||||||
import noppes.npcs.constants.MarkType;
|
import noppes.npcs.constants.MarkType;
|
||||||
import noppes.npcs.controllers.data.MarkData;
|
import noppes.npcs.controllers.data.MarkData;
|
||||||
@@ -86,6 +87,8 @@ public class ClientTickHandler {
|
|||||||
PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth, mc.displayHeight));
|
PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth, mc.displayHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cursors.tick();
|
||||||
|
|
||||||
if (mc.theWorld == null)
|
if (mc.theWorld == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import noppes.npcs.client.gui.SubGuiAnimationFrame;
|
|||||||
import noppes.npcs.client.gui.SubGuiAnimationOptions;
|
import noppes.npcs.client.gui.SubGuiAnimationOptions;
|
||||||
import noppes.npcs.client.gui.SubGuiColorSelector;
|
import noppes.npcs.client.gui.SubGuiColorSelector;
|
||||||
import noppes.npcs.client.gui.util.*;
|
import noppes.npcs.client.gui.util.*;
|
||||||
|
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||||
import noppes.npcs.constants.EnumAnimationPart;
|
import noppes.npcs.constants.EnumAnimationPart;
|
||||||
|
import noppes.npcs.constants.animation.EnumFrameType;
|
||||||
import noppes.npcs.controllers.data.Animation;
|
import noppes.npcs.controllers.data.Animation;
|
||||||
import noppes.npcs.controllers.data.AnimationData;
|
import noppes.npcs.controllers.data.AnimationData;
|
||||||
import noppes.npcs.controllers.data.Frame;
|
import noppes.npcs.controllers.data.Frame;
|
||||||
@@ -34,6 +36,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
private final GuiScreen parent;
|
private final GuiScreen parent;
|
||||||
private long prevTick;
|
private long prevTick;
|
||||||
|
|
||||||
|
|
||||||
private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3];
|
private final GuiNpcSlider[] rotationSliders = new GuiNpcSlider[3];
|
||||||
private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3];
|
private final GuiNpcSlider[] pivotSliders = new GuiNpcSlider[3];
|
||||||
|
|
||||||
@@ -42,12 +45,18 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
private final int visibleFrames = 25;
|
private final int visibleFrames = 25;
|
||||||
private boolean overrideFrame = false;
|
private boolean overrideFrame = false;
|
||||||
|
|
||||||
|
public AnimationGraphEditor graphEditor;
|
||||||
|
public GuiNpcButton toggleGraph;
|
||||||
|
private boolean toggleGraphEditor = true;
|
||||||
|
|
||||||
public GuiNPCEditAnimation(GuiScreen parent, Animation animation, EntityNPCInterface npc) {
|
public GuiNPCEditAnimation(GuiScreen parent, Animation animation, EntityNPCInterface npc) {
|
||||||
super((EntityCustomNpc) npc);
|
super((EntityCustomNpc) npc);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.followMouse = false;
|
this.followMouse = false;
|
||||||
xOffset = 0;
|
xOffset = 0;
|
||||||
yOffset = -21;
|
yOffset = -21;
|
||||||
|
maxZoom = 120;
|
||||||
|
drawRenderButtons = false;
|
||||||
|
|
||||||
this.animation = animation;
|
this.animation = animation;
|
||||||
AnimationData data = npc.display.animationData;
|
AnimationData data = npc.display.animationData;
|
||||||
@@ -61,6 +70,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
this.pivotSliders[i] = new GuiNpcSlider(this, 95 + i, guiLeft + bodyPartX, guiTop + bodyPartY + 115 + (20 * i), 0.5F);
|
this.pivotSliders[i] = new GuiNpcSlider(this, 95 + i, guiLeft + bodyPartX, guiTop + bodyPartY + 115 + (20 * i), 0.5F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphEditor = new AnimationGraphEditor(this);
|
||||||
this.frameSlider = new GuiNpcSlider(this, 350, 0, 0, 0.0F);
|
this.frameSlider = new GuiNpcSlider(this, 350, 0, 0, 0.0F);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +78,17 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
public void initGui() {
|
public void initGui() {
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
|
||||||
if (animation == null) return;
|
if (animation == null)
|
||||||
|
return;
|
||||||
|
yOffset = -21;
|
||||||
|
|
||||||
|
addButton(toggleGraph = new GuiNpcButton(777, guiLeft - 80, guiTop - 2 + 84, 70, 20, "Toggle Graph"));
|
||||||
|
if (toggleGraphEditor) {
|
||||||
|
yOffset = -80;
|
||||||
|
graphEditor.initGui(guiLeft - 10, guiTop + 120, guiLeft - 10 + xSize, guiTop + 135 + 105);
|
||||||
|
addGraphEditor(0, graphEditor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
frameIndex = !animation.frames.isEmpty() ? frameIndex % animation.frames.size() : 0;
|
frameIndex = !animation.frames.isEmpty() ? frameIndex % animation.frames.size() : 0;
|
||||||
this.updateSliders();
|
this.updateSliders();
|
||||||
@@ -98,20 +118,18 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
data.animation.smooth = animation.smooth;
|
data.animation.smooth = animation.smooth;
|
||||||
data.animation.loop = 0;
|
data.animation.loop = 0;
|
||||||
if (editingFrame != null) {
|
if (editingFrame != null) {
|
||||||
data.animation.frames.add(editingFrame);
|
data.animation.addFrame(editingFrame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (Frame frame : animation.frames) {
|
for (Frame frame : animation.frames) {
|
||||||
frame.parent = animation;
|
|
||||||
if (!frame.isCustomized()) {
|
if (!frame.isCustomized()) {
|
||||||
frame.speed = animation.speed;
|
frame.speed = animation.speed;
|
||||||
frame.smooth = animation.smooth;
|
frame.smooth = animation.smooth;
|
||||||
}
|
}
|
||||||
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
|
for (Map.Entry<EnumAnimationPart, FramePart> entry : frame.frameParts.entrySet()) {
|
||||||
FramePart part = entry.getValue();
|
FramePart part = entry.getValue();
|
||||||
part.parent = animation;
|
|
||||||
if (!part.isCustomized()) {
|
if (!part.isCustomized()) {
|
||||||
part.speed = frame.speed;
|
part.speed = frame.speed;
|
||||||
part.smooth = frame.smooth;
|
part.smooth = frame.smooth;
|
||||||
@@ -129,37 +147,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
overrideFrame = false;
|
overrideFrame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 40, guiTop + 176 - 10, 0xFFFFFF));
|
|
||||||
this.addButton(new GuiNpcButton(11, guiLeft - 10, guiTop + 189 - 10, 45, 20, "gui.add"));
|
|
||||||
if (!animation.frames.isEmpty()) {
|
|
||||||
this.addButton(new GuiNpcButton(12, guiLeft + 35, guiTop + 189 - 10, 45, 20, "gui.remove"));
|
|
||||||
this.addButton(new GuiNpcButton(13, guiLeft + 80, guiTop + 189 - 10, 45, 20, "gui.copy"));
|
|
||||||
this.addButton(new GuiNpcButton(14, guiLeft - 10, guiTop + 210 - 3, 20, 20, "<"));
|
|
||||||
this.addTextField(new GuiNpcTextField(15, this, guiLeft + 15, guiTop + 212 - 3, 20, 17, frameIndex + ""));
|
|
||||||
this.getTextField(15).integersOnly = true;
|
|
||||||
this.getTextField(15).setMinMaxDefault(0, animation.frames.size() - 1, frameIndex);
|
|
||||||
this.addButton(new GuiNpcButton(16, guiLeft + 40, guiTop + 210 - 3, 20, 20, ">"));
|
|
||||||
}
|
|
||||||
|
|
||||||
int playPauseX = 330;
|
|
||||||
int playPauseY = 10;
|
|
||||||
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(210, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
|
||||||
if (data.animation.paused) {
|
|
||||||
this.addLabel(new GuiNpcLabel(211, "", guiLeft + playPauseX + 21, guiTop + playPauseY + 203, 0xFFFFFF));
|
|
||||||
}
|
|
||||||
this.addButton(new GuiTexturedButton(200, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 11, 20, animTexture, 18, 71));
|
|
||||||
} else {//Pause
|
|
||||||
this.addLabel(new GuiNpcLabel(212, "animation.playing", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
|
||||||
this.addLabel(new GuiNpcLabel(213, "", guiLeft + playPauseX + 20, guiTop + playPauseY + 203, 0xFFFFFF));
|
|
||||||
this.addButton(new GuiTexturedButton(201, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 14, 20, animTexture, 0, 71));
|
|
||||||
}
|
|
||||||
if (this.playingAnimation) {//Stop
|
|
||||||
this.addButton(new GuiTexturedButton(202, "", guiLeft + playPauseX + 55, guiTop + playPauseY + 197, 14, 20, animTexture, 33, 71));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -194,6 +181,41 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
if (!toggleGraphEditor) {
|
||||||
|
int guiLeft = this.guiLeft;
|
||||||
|
this.addLabel(new GuiNpcLabel(10, "animation.frames", guiLeft + 40, guiTop + 176 - 10, 0xFFFFFF));
|
||||||
|
this.addButton(new GuiNpcButton(11, guiLeft - 10, guiTop + 189 - 10, 45, 20, "gui.add"));
|
||||||
|
if (!animation.frames.isEmpty()) {
|
||||||
|
this.addButton(new GuiNpcButton(12, guiLeft + 35, guiTop + 189 - 10, 45, 20, "gui.remove"));
|
||||||
|
this.addButton(new GuiNpcButton(13, guiLeft + 80, guiTop + 189 - 10, 45, 20, "gui.copy"));
|
||||||
|
this.addButton(new GuiNpcButton(14, guiLeft - 10, guiTop + 210 - 3, 20, 20, "<"));
|
||||||
|
this.addTextField(new GuiNpcTextField(15, this, guiLeft + 15, guiTop + 212 - 3, 20, 17, frameIndex + ""));
|
||||||
|
this.getTextField(15).integersOnly = true;
|
||||||
|
this.getTextField(15).setMinMaxDefault(0, animation.frames.size() - 1, frameIndex);
|
||||||
|
this.addButton(new GuiNpcButton(16, guiLeft + 40, guiTop + 210 - 3, 20, 20, ">"));
|
||||||
|
}
|
||||||
|
|
||||||
|
int playPauseX = 330;
|
||||||
|
int playPauseY = 10;
|
||||||
|
|
||||||
|
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(210, data.animation.paused ? "animation.paused" : "animation.stopped", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||||
|
if (data.animation.paused) {
|
||||||
|
this.addLabel(new GuiNpcLabel(211, "", guiLeft + playPauseX + 21, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||||
|
}
|
||||||
|
this.addButton(new GuiTexturedButton(200, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 11, 20, animTexture, 18, 71));
|
||||||
|
} else {//Pause
|
||||||
|
this.addLabel(new GuiNpcLabel(212, "animation.playing", guiLeft + playPauseX - 15, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||||
|
this.addLabel(new GuiNpcLabel(213, "", guiLeft + playPauseX + 20, guiTop + playPauseY + 203, 0xFFFFFF));
|
||||||
|
this.addButton(new GuiTexturedButton(201, "", guiLeft + playPauseX + 35, guiTop + playPauseY + 197, 14, 20, animTexture, 0, 71));
|
||||||
|
}
|
||||||
|
if (this.playingAnimation) {//Stop
|
||||||
|
this.addButton(new GuiTexturedButton(202, "", guiLeft + playPauseX + 55, guiTop + playPauseY + 197, 14, 20, animTexture, 33, 71));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (editingFrame != null) {
|
if (editingFrame != null) {
|
||||||
int frameX = animationX;
|
int frameX = animationX;
|
||||||
int frameY = playPauseY + 100;
|
int frameY = playPauseY + 100;
|
||||||
@@ -358,10 +380,12 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + 210, 6, 20, animTexture, 0, 71));
|
this.addButton(new GuiTexturedButton(300 + i, "", guiLeft + 130 + i * 7, guiTop + 210, 6, 20, animTexture, 0, 71));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateSliders() {
|
private void updateSliders() {
|
||||||
FramePart part = this.editingPart();
|
FramePart part = this.editingPart();
|
||||||
if (part == null) return;
|
if (part == null)
|
||||||
|
return;
|
||||||
|
|
||||||
float[] rotations = part.getRotations();
|
float[] rotations = part.getRotations();
|
||||||
float[] pivots = part.getPivots();
|
float[] pivots = part.getPivots();
|
||||||
@@ -391,6 +415,22 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
return editingFrame.frameParts.get(this.editingPart);
|
return editingFrame.frameParts.get(this.editingPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMouseOverRenderer(int x, int y) {
|
||||||
|
if (!allowRotate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Center of the entity rendering
|
||||||
|
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||||
|
int centerY = guiTop + 80 + yOffset; // Matches i1 in drawScreen()
|
||||||
|
|
||||||
|
// Define separate buffers for X and Y axes
|
||||||
|
int xBuffer = 75; // Horizontal buffer
|
||||||
|
int yBuffer = 120; // Vertical buffer
|
||||||
|
|
||||||
|
// Check if the mouse is within the buffer area
|
||||||
|
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton guibutton) {
|
protected void actionPerformed(GuiButton guibutton) {
|
||||||
super.actionPerformed(guibutton);
|
super.actionPerformed(guibutton);
|
||||||
@@ -406,9 +446,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
updateFrameSlider();
|
updateFrameSlider();
|
||||||
} else if (guibutton.id == 13 && editingFrame != null) {
|
} else if (guibutton.id == 13 && editingFrame != null) {
|
||||||
if (frameIndex < animation.frames.size() - 1) {
|
if (frameIndex < animation.frames.size() - 1) {
|
||||||
animation.frames.add(frameIndex + 1, editingFrame.copy());
|
animation.addFrame(frameIndex + 1, editingFrame.copy());
|
||||||
} else {
|
} else {
|
||||||
animation.frames.add(editingFrame.copy());
|
animation.addFrame(editingFrame.copy());
|
||||||
}
|
}
|
||||||
this.frameIndex = frameIndex + 1;
|
this.frameIndex = frameIndex + 1;
|
||||||
updateFrameSlider();
|
updateFrameSlider();
|
||||||
@@ -491,6 +531,10 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (guibutton == toggleGraph) {
|
||||||
|
toggleGraphEditor = !toggleGraphEditor;
|
||||||
|
}
|
||||||
|
|
||||||
initGui();
|
initGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,9 +544,9 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
|
|
||||||
private void addFrame(Frame frame) {
|
private void addFrame(Frame frame) {
|
||||||
if (frameIndex < animation.frames.size() - 1) {
|
if (frameIndex < animation.frames.size() - 1) {
|
||||||
animation.frames.add(frameIndex + 1, frame);
|
animation.addFrame(frameIndex + 1, frame);
|
||||||
} else {
|
} else {
|
||||||
animation.frames.add(frame);
|
animation.addFrame(frame);
|
||||||
}
|
}
|
||||||
this.frameIndex = frameIndex + 1;
|
this.frameIndex = frameIndex + 1;
|
||||||
updateFrameSlider();
|
updateFrameSlider();
|
||||||
@@ -510,7 +554,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int par1, int par2, float par3) {
|
public void drawScreen(int par1, int par2, float par3) {
|
||||||
super.drawScreen(par1, par2, par3);
|
|
||||||
AnimationData data = npc.display.animationData;
|
AnimationData data = npc.display.animationData;
|
||||||
if (!data.isActive() && this.playingAnimation) {
|
if (!data.isActive() && this.playingAnimation) {
|
||||||
this.playingAnimation = false;
|
this.playingAnimation = false;
|
||||||
@@ -518,6 +561,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
} else if (data.isActive()) {
|
} else if (data.isActive()) {
|
||||||
long time = mc.theWorld.getTotalWorldTime();
|
long time = mc.theWorld.getTotalWorldTime();
|
||||||
if (time != prevTick) {
|
if (time != prevTick) {
|
||||||
|
npc.display.animationData.increaseTime();
|
||||||
GuiNpcLabel label = this.getLabel(213);
|
GuiNpcLabel label = this.getLabel(213);
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
label.label += ".";
|
label.label += ".";
|
||||||
@@ -529,6 +573,8 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
prevTick = time;
|
prevTick = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
super.drawScreen(par1, par2, par3);
|
||||||
|
|
||||||
for (int i = 0; i < this.visibleFrames; i++) {
|
for (int i = 0; i < this.visibleFrames; i++) {
|
||||||
if (getButton(300 + i) != null) {
|
if (getButton(300 + i) != null) {
|
||||||
GuiTexturedButton button = (GuiTexturedButton) getButton(300 + i);
|
GuiTexturedButton button = (GuiTexturedButton) getButton(300 + i);
|
||||||
@@ -564,7 +610,7 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
animation.name = text.replaceAll("[^a-zA-Z0-9_-]", "_");
|
animation.name = text.replaceAll("[^a-zA-Z0-9_-]", "_");
|
||||||
} else if (textfield.id == 15 && animation != null && animation.frames.size() > 0) {
|
} else if (textfield.id == 15 && animation != null && animation.frames.size() > 0) {
|
||||||
animation.frames.remove(frameIndex);
|
animation.frames.remove(frameIndex);
|
||||||
animation.frames.add(textfield.getInteger(), frame);
|
animation.addFrame(textfield.getInteger(), frame);
|
||||||
frameIndex = textfield.getInteger();
|
frameIndex = textfield.getInteger();
|
||||||
overrideFrame = true;
|
overrideFrame = true;
|
||||||
initGui();
|
initGui();
|
||||||
@@ -575,14 +621,25 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
} else if (textfield.id == 51 && frame != null) {
|
} else if (textfield.id == 51 && frame != null) {
|
||||||
frame.duration = textfield.getInteger();
|
frame.duration = textfield.getInteger();
|
||||||
} else if (textfield.id >= 70 && textfield.id <= 73 && part != null) {
|
} else if (textfield.id >= 70 && textfield.id <= 73 && part != null) {
|
||||||
part.rotation[textfield.id - 70] = textfield.getFloat();
|
int index = textfield.id - 70;
|
||||||
|
float value = textfield.getFloat();
|
||||||
|
part.rotation[index] = value;
|
||||||
|
part.addValue(EnumFrameType.values()[index], value);
|
||||||
this.updateSliders();
|
this.updateSliders();
|
||||||
} else if (textfield.id >= 80 && textfield.id <= 83 && part != null) {
|
} else if (textfield.id >= 80 && textfield.id <= 83 && part != null) {
|
||||||
part.pivot[textfield.id - 80] = textfield.getFloat();
|
int index = textfield.id - 80;
|
||||||
|
float value = textfield.getFloat();
|
||||||
|
part.pivot[index] = value;
|
||||||
|
part.addValue(EnumFrameType.values()[3 + index], value);
|
||||||
this.updateSliders();
|
this.updateSliders();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onGuiClosed() {
|
||||||
|
super.onGuiClosed();
|
||||||
|
graphEditor.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
if (!this.hasSubGui()) {
|
if (!this.hasSubGui()) {
|
||||||
@@ -618,13 +675,17 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
}
|
}
|
||||||
if (id >= 90 && id < 93) {
|
if (id >= 90 && id < 93) {
|
||||||
int value = (int) (360.0F * 2.0F * (guiNpcSlider.sliderValue - 0.5F));
|
int value = (int) (360.0F * 2.0F * (guiNpcSlider.sliderValue - 0.5F));
|
||||||
part.rotation[id - 90] = value;
|
int index = id - 90;
|
||||||
|
part.rotation[index] = value;
|
||||||
|
part.addValue(EnumFrameType.values()[index], value);
|
||||||
guiNpcSlider.setString(value + "");
|
guiNpcSlider.setString(value + "");
|
||||||
}
|
}
|
||||||
if (id >= 95 && id < 98) {
|
if (id >= 95 && id < 98) {
|
||||||
int value = (int) (100.0F * (guiNpcSlider.sliderValue - 0.5F));
|
int value = (int) (100.0F * (guiNpcSlider.sliderValue - 0.5F));
|
||||||
guiNpcSlider.setString(value + "");
|
guiNpcSlider.setString(value + "");
|
||||||
part.pivot[id - 95] = value;
|
int index = id - 95;
|
||||||
|
part.pivot[index] = value;
|
||||||
|
part.addValue(EnumFrameType.values()[3 + index], value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -648,7 +709,12 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(char par1, int par2) {
|
public void keyTyped(char par1, int par2) {
|
||||||
|
boolean old = closeOnEsc;
|
||||||
|
if (graphEditor.presetOverlay.showOverlay)
|
||||||
|
closeOnEsc = false;
|
||||||
|
|
||||||
super.keyTyped(par1, par2);
|
super.keyTyped(par1, par2);
|
||||||
|
closeOnEsc = old;
|
||||||
|
|
||||||
if (GuiScreen.isCtrlKeyDown() && par2 != 29 && !GuiNpcTextField.isFieldActive()) {
|
if (GuiScreen.isCtrlKeyDown() && par2 != 29 && !GuiNpcTextField.isFieldActive()) {
|
||||||
switch (par2) {
|
switch (par2) {
|
||||||
@@ -660,7 +726,6 @@ public class GuiNPCEditAnimation extends GuiModelInterface implements ITextfield
|
|||||||
case 47:
|
case 47:
|
||||||
if (copiedFrame != null) {
|
if (copiedFrame != null) {
|
||||||
Frame frame = new Frame(10);
|
Frame frame = new Frame(10);
|
||||||
frame.parent = this.animation;
|
|
||||||
frame.readFromNBT(copiedFrame.writeToNBT());
|
frame.readFromNBT(copiedFrame.writeToNBT());
|
||||||
this.addFrame(frame);
|
this.addFrame(frame);
|
||||||
this.initGui();
|
this.initGui();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
this.setSave(save);
|
this.setSave(save);
|
||||||
this.xOffset = -148 + 70;
|
this.xOffset = -148 + 70;
|
||||||
this.yOffset = -170 + 137;
|
this.yOffset = -170 + 137;
|
||||||
|
maxZoom = 120;
|
||||||
PacketClient.sendClient(new AnimationsGetPacket());
|
PacketClient.sendClient(new AnimationsGetPacket());
|
||||||
|
|
||||||
AnimationData data = npc.display.animationData;
|
AnimationData data = npc.display.animationData;
|
||||||
@@ -73,9 +74,8 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
|
|
||||||
if (this.animation.frames.size() > 0) {
|
if (this.animation.frames.size() > 0) {
|
||||||
Frame firstFrame = new Frame();
|
Frame firstFrame = new Frame();
|
||||||
firstFrame.parent = data.animation;
|
|
||||||
firstFrame.readFromNBT(this.animation.frames.get(0).writeToNBT());
|
|
||||||
data.animation.addFrame(firstFrame);
|
data.animation.addFrame(firstFrame);
|
||||||
|
firstFrame.readFromNBT(this.animation.frames.get(0).writeToNBT());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,8 +104,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int par1, int par2, float par3) {
|
public void drawScreen(int par1, int par2, float partialTicks) {
|
||||||
super.drawScreen(par1, par2, par3);
|
|
||||||
AnimationData data = npc.display.animationData;
|
AnimationData data = npc.display.animationData;
|
||||||
if (!data.isActive() && this.playingAnimation) {
|
if (!data.isActive() && this.playingAnimation) {
|
||||||
this.playingAnimation = false;
|
this.playingAnimation = false;
|
||||||
@@ -113,6 +112,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
} else if (data.isActive()) {
|
} else if (data.isActive()) {
|
||||||
long time = mc.theWorld.getTotalWorldTime();
|
long time = mc.theWorld.getTotalWorldTime();
|
||||||
if (time != prevTick) {
|
if (time != prevTick) {
|
||||||
|
npc.display.animationData.increaseTime();
|
||||||
GuiNpcLabel label = this.getLabel(94);
|
GuiNpcLabel label = this.getLabel(94);
|
||||||
if (label != null) {
|
if (label != null) {
|
||||||
label.label += ".";
|
label.label += ".";
|
||||||
@@ -123,6 +123,7 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
}
|
}
|
||||||
prevTick = time;
|
prevTick = time;
|
||||||
}
|
}
|
||||||
|
super.drawScreen(par1, par2, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -276,4 +277,20 @@ public class GuiNPCManageAnimations extends GuiModelInterface2 implements IScrol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMouseOverRenderer(int x, int y) {
|
||||||
|
if (!allowRotate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Center of the entity rendering
|
||||||
|
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||||
|
int centerY = guiTop + 130 + yOffset; // Matches i1 in drawScreen()
|
||||||
|
|
||||||
|
// Define separate buffers for X and Y axes
|
||||||
|
int xBuffer = 100; // Horizontal buffer
|
||||||
|
int yBuffer = 90; // Vertical buffer
|
||||||
|
|
||||||
|
// Check if the mouse is within the buffer area
|
||||||
|
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,12 +10,10 @@ import net.minecraft.nbt.NBTTagList;
|
|||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import noppes.npcs.NBTTags;
|
import noppes.npcs.NBTTags;
|
||||||
import noppes.npcs.NoppesStringUtils;
|
import noppes.npcs.NoppesStringUtils;
|
||||||
import noppes.npcs.client.NoppesUtil;
|
|
||||||
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
||||||
import noppes.npcs.client.gui.util.*;
|
import noppes.npcs.client.gui.util.*;
|
||||||
import noppes.npcs.constants.EnumScriptType;
|
import noppes.npcs.constants.EnumScriptType;
|
||||||
import noppes.npcs.controllers.ScriptContainer;
|
import noppes.npcs.controllers.ScriptContainer;
|
||||||
import noppes.npcs.controllers.ScriptController;
|
|
||||||
import noppes.npcs.controllers.data.LinkedItem;
|
import noppes.npcs.controllers.data.LinkedItem;
|
||||||
import noppes.npcs.controllers.data.LinkedItemScript;
|
import noppes.npcs.controllers.data.LinkedItemScript;
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class GuiModelInterface extends GuiNPCInterface {
|
|||||||
private GuiNpcButton left, right, zoom, unzoom;
|
private GuiNpcButton left, right, zoom, unzoom;
|
||||||
|
|
||||||
private static float zoomed = 60;
|
private static float zoomed = 60;
|
||||||
public float minSize = 10, maxSize = 100;
|
public float minZoom = 10, maxZoom = 100;
|
||||||
|
|
||||||
public int xOffset = 0, xOffsetButton = 0;
|
public int xOffset = 0, xOffsetButton = 0;
|
||||||
public int yOffset = 0, yOffsetButton = 0;
|
public int yOffset = 0, yOffsetButton = 0;
|
||||||
@@ -98,16 +98,16 @@ public class GuiModelInterface extends GuiNPCInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int par1, int par2, float par3) {
|
public void drawScreen(int par1, int par2, float partialTicks) {
|
||||||
if (Mouse.isButtonDown(0)) {
|
if (Mouse.isButtonDown(0) && drawRenderButtons) {
|
||||||
if (this.left.mousePressed(this.mc, par1, par2)) {
|
if (this.left.mousePressed(this.mc, par1, par2)) {
|
||||||
rotation += par3 * 1.5F;
|
rotation += partialTicks * 1.5F;
|
||||||
} else if (this.right.mousePressed(this.mc, par1, par2)) {
|
} else if (this.right.mousePressed(this.mc, par1, par2)) {
|
||||||
rotation -= par3 * 1.5F;
|
rotation -= partialTicks * 1.5F;
|
||||||
} else if (this.zoom.mousePressed(this.mc, par1, par2) && zoomed < maxSize) {
|
} else if (this.zoom.mousePressed(this.mc, par1, par2) && zoomed < maxZoom) {
|
||||||
zoomed += par3 * 1.0F;
|
zoomed += partialTicks * 1.0F;
|
||||||
} else if (this.unzoom.mousePressed(this.mc, par1, par2) && zoomed > minSize) {
|
} else if (this.unzoom.mousePressed(this.mc, par1, par2) && zoomed > minZoom) {
|
||||||
zoomed -= par3 * 1.0F;
|
zoomed -= partialTicks * 1.0F;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,10 +118,10 @@ public class GuiModelInterface extends GuiNPCInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoomed > maxSize)
|
if (zoomed > maxZoom)
|
||||||
zoomed = maxSize;
|
zoomed = maxZoom;
|
||||||
if (zoomed < minSize)
|
if (zoomed < minZoom)
|
||||||
zoomed = minSize;
|
zoomed = minZoom;
|
||||||
|
|
||||||
if (hasSubGui() && !drawNPConSub)
|
if (hasSubGui() && !drawNPConSub)
|
||||||
return;
|
return;
|
||||||
@@ -156,13 +156,13 @@ public class GuiModelInterface extends GuiNPCInterface {
|
|||||||
GL11.glRotatef(-(float) Math.atan(f6 / 800F) * 20F, 1.0F, 0.0F, 0.0F);
|
GL11.glRotatef(-(float) Math.atan(f6 / 800F) * 20F, 1.0F, 0.0F, 0.0F);
|
||||||
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
||||||
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
||||||
entity.rotationPitch = followMouse ? -(float) Math.atan(f6 / 40F) * 20F : 0;
|
entity.rotationPitch = entity.prevRotationPitch = followMouse ? -(float) Math.atan(f6 / 40F) * 20F : 0;
|
||||||
entity.prevRotationYawHead = entity.rotationYawHead = followMouse ? entity.rotationYaw : rotation;
|
entity.prevRotationYawHead = entity.rotationYawHead = followMouse ? entity.rotationYaw : rotation;
|
||||||
GL11.glTranslatef(0.0F, entity.yOffset, 1F);
|
GL11.glTranslatef(0.0F, entity.yOffset, 1F);
|
||||||
RenderManager.instance.playerViewY = 180F;
|
RenderManager.instance.playerViewY = 180F;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
|
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
playerdata.setEntityClass(null);
|
playerdata.setEntityClass(null);
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ public class GuiModelInterface extends GuiNPCInterface {
|
|||||||
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslatef(0.0F, 0f, 500.065F);
|
GL11.glTranslatef(0.0F, 0f, 500.065F);
|
||||||
super.drawScreen(par1, par2, par3);
|
super.drawScreen(par1, par2, partialTicks);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
postRender(entity);
|
postRender(entity);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
|||||||
private GuiNpcButton left, right, zoom, unzoom;
|
private GuiNpcButton left, right, zoom, unzoom;
|
||||||
|
|
||||||
private static float zoomed = 60;
|
private static float zoomed = 60;
|
||||||
|
public float minZoom = 10, maxZoom = 100;
|
||||||
|
public boolean allowRotate = true;
|
||||||
|
|
||||||
public int xOffset = 0;
|
public int xOffset = 0;
|
||||||
public int yOffset = 0;
|
public int yOffset = 0;
|
||||||
@@ -60,21 +62,50 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
|||||||
|
|
||||||
private long start = -1;
|
private long start = -1;
|
||||||
|
|
||||||
|
public boolean isMouseOverRenderer(int x, int y) {
|
||||||
|
if (!allowRotate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Center of the entity rendering
|
||||||
|
int centerX = guiLeft + 190 + xOffset; // Matches l in drawScreen()
|
||||||
|
int centerY = guiTop + 180 + yOffset; // Matches i1 in drawScreen()
|
||||||
|
|
||||||
|
// Define separate buffers for X and Y axes
|
||||||
|
int xBuffer = 100; // Horizontal buffer
|
||||||
|
int yBuffer = 150; // Vertical buffer
|
||||||
|
|
||||||
|
// Check if the mouse is within the buffer area
|
||||||
|
return mouseX >= centerX - xBuffer && mouseX <= centerX + xBuffer && mouseY >= centerY - yBuffer && mouseY <= centerY + yBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int par1, int par2, float par3) {
|
public void drawScreen(int par1, int par2, float partialTicks) {
|
||||||
if (Mouse.isButtonDown(0)) {
|
if (Mouse.isButtonDown(0)) {
|
||||||
if (left.mousePressed(mc, par1, par2))
|
if (left.mousePressed(mc, par1, par2))
|
||||||
rotation += par3 * 2;
|
rotation += partialTicks * 2;
|
||||||
else if (right.mousePressed(mc, par1, par2))
|
else if (right.mousePressed(mc, par1, par2))
|
||||||
rotation -= par3 * 2;
|
rotation -= partialTicks * 2;
|
||||||
else if (zoom.mousePressed(mc, par1, par2))
|
else if (zoom.mousePressed(mc, par1, par2))
|
||||||
zoomed += par3 * 2;
|
zoomed += partialTicks * 2;
|
||||||
else if (unzoom.mousePressed(mc, par1, par2) && zoomed > 10)
|
else if (unzoom.mousePressed(mc, par1, par2) && zoomed > 10)
|
||||||
zoomed -= par3 * 2;
|
zoomed -= partialTicks * 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.drawScreen(par1, par2, par3);
|
if (isMouseOverRenderer(par1, par2)) {
|
||||||
|
zoomed += Mouse.getDWheel() * 0.035f;
|
||||||
|
if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) {
|
||||||
|
rotation -= Mouse.getDX() * 0.75f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zoomed > maxZoom)
|
||||||
|
zoomed = maxZoom;
|
||||||
|
if (zoomed < minZoom)
|
||||||
|
zoomed = minZoom;
|
||||||
|
|
||||||
|
super.drawScreen(par1, par2, partialTicks);
|
||||||
|
|
||||||
GL11.glColor4f(1, 1, 1, 1);
|
GL11.glColor4f(1, 1, 1, 1);
|
||||||
|
|
||||||
@@ -105,13 +136,13 @@ public class GuiModelInterface2 extends GuiNPCInterface2 {
|
|||||||
GL11.glRotatef(-(float) Math.atan(f6 / 80F) * 20F, 1.0F, 0.0F, 0.0F);
|
GL11.glRotatef(-(float) Math.atan(f6 / 80F) * 20F, 1.0F, 0.0F, 0.0F);
|
||||||
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
entity.prevRenderYawOffset = entity.renderYawOffset = rotation;
|
||||||
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation;
|
||||||
entity.rotationPitch = -(float) Math.atan(f6 / 80F) * 20F;
|
entity.rotationPitch = entity.prevRotationPitch = -(float) Math.atan(f6 / 80F) * 20F;
|
||||||
entity.prevRotationYawHead = entity.rotationYawHead = entity.rotationYaw;
|
entity.prevRotationYawHead = entity.rotationYawHead = entity.rotationYaw;
|
||||||
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
|
GL11.glTranslatef(0.0F, entity.yOffset, 0.0F);
|
||||||
RenderManager.instance.playerViewY = 180F;
|
RenderManager.instance.playerViewY = 180F;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
|
RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, partialTicks);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
playerdata.setEntityClass(null);
|
playerdata.setEntityClass(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
import net.minecraft.util.StatCollector;
|
import net.minecraft.util.StatCollector;
|
||||||
import noppes.npcs.client.CustomNpcResourceListener;
|
import noppes.npcs.client.CustomNpcResourceListener;
|
||||||
import noppes.npcs.client.TextBlockClient;
|
import noppes.npcs.client.TextBlockClient;
|
||||||
|
import noppes.npcs.client.gui.util.animation.ViewportGraphEditor;
|
||||||
import noppes.npcs.entity.EntityNPCInterface;
|
import noppes.npcs.entity.EntityNPCInterface;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
@@ -37,6 +38,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
protected HashMap<Integer, GuiNpcSlider> sliders = new HashMap<Integer, GuiNpcSlider>();
|
protected HashMap<Integer, GuiNpcSlider> sliders = new HashMap<Integer, GuiNpcSlider>();
|
||||||
protected HashMap<Integer, GuiScreen> extra = new HashMap<Integer, GuiScreen>();
|
protected HashMap<Integer, GuiScreen> extra = new HashMap<Integer, GuiScreen>();
|
||||||
protected HashMap<Integer, GuiScrollWindow> scrollWindows = new HashMap<>();
|
protected HashMap<Integer, GuiScrollWindow> scrollWindows = new HashMap<>();
|
||||||
|
protected HashMap<Integer, ViewportGraphEditor> graphEditors = new HashMap<>();
|
||||||
protected HashMap<Integer, GuiDiagram> diagrams = new HashMap<>();
|
protected HashMap<Integer, GuiDiagram> diagrams = new HashMap<>();
|
||||||
|
|
||||||
public static boolean resizingActive = false;
|
public static boolean resizingActive = false;
|
||||||
@@ -92,6 +94,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
scrolls.clear();
|
scrolls.clear();
|
||||||
sliders.clear();
|
sliders.clear();
|
||||||
scrollWindows.clear();
|
scrollWindows.clear();
|
||||||
|
graphEditors.clear();
|
||||||
diagrams.clear();
|
diagrams.clear();
|
||||||
Keyboard.enableRepeatEvents(true);
|
Keyboard.enableRepeatEvents(true);
|
||||||
}
|
}
|
||||||
@@ -106,6 +109,13 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
tf.updateCursorCounter();
|
tf.updateCursorCounter();
|
||||||
}
|
}
|
||||||
super.updateScreen();
|
super.updateScreen();
|
||||||
|
|
||||||
|
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values())
|
||||||
|
guiScrollableComponent.updateScreen();
|
||||||
|
|
||||||
|
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||||
|
graphEditor.updateScreen();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +130,10 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
scrollWindows.put(id, gui);
|
scrollWindows.put(id, gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addGraphEditor(int id, ViewportGraphEditor graph) {
|
||||||
|
graphEditors.put(id, graph);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a GuiDiagram to the interface.
|
* Adds a GuiDiagram to the interface.
|
||||||
* The diagram is initialized with the current resolution and cached.
|
* The diagram is initialized with the current resolution and cached.
|
||||||
@@ -145,6 +159,9 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
guiScrollableComponent.mouseClicked(i, j, k);
|
guiScrollableComponent.mouseClicked(i, j, k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||||
|
graphEditor.mouseClicked(i, j, k);
|
||||||
|
|
||||||
if (k == 0) {
|
if (k == 0) {
|
||||||
for (GuiCustomScroll scroll : new ArrayList<GuiCustomScroll>(scrolls.values())) {
|
for (GuiCustomScroll scroll : new ArrayList<GuiCustomScroll>(scrolls.values())) {
|
||||||
scroll.mouseClicked(i, j, k);
|
scroll.mouseClicked(i, j, k);
|
||||||
@@ -168,6 +185,10 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
subgui.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
subgui.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (GuiScrollWindow window : scrollWindows.values())
|
||||||
|
window.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||||
|
|
||||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,9 +223,11 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
for (GuiNpcTextField tf : textfields.values())
|
for (GuiNpcTextField tf : textfields.values())
|
||||||
tf.textboxKeyTyped(c, i);
|
tf.textboxKeyTyped(c, i);
|
||||||
|
|
||||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values())
|
||||||
guiScrollableComponent.keyTyped(c, i);
|
guiScrollableComponent.keyTyped(c, i);
|
||||||
}
|
|
||||||
|
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||||
|
graphEditor.keyTyped(c, i);
|
||||||
|
|
||||||
// Fixes closing sub with escape closes all of its parents
|
// Fixes closing sub with escape closes all of its parents
|
||||||
boolean enoughTimeSinceSubClosed = Minecraft.getSystemTime() - timeClosedSubGui > 50;
|
boolean enoughTimeSinceSubClosed = Minecraft.getSystemTime() - timeClosedSubGui > 50;
|
||||||
@@ -310,16 +333,22 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
for (GuiNpcTextField tf : textfields.values()) {
|
for (GuiNpcTextField tf : textfields.values()) {
|
||||||
tf.drawTextBox(i, j);
|
tf.drawTextBox(i, j);
|
||||||
}
|
}
|
||||||
|
int wheel = Mouse.getDWheel();
|
||||||
for (GuiCustomScroll scroll : scrolls.values()) {
|
for (GuiCustomScroll scroll : scrolls.values()) {
|
||||||
scroll.updateSubGUI(subGui);
|
scroll.updateSubGUI(subGui);
|
||||||
scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? Mouse.getDWheel() : 0);
|
scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? wheel : 0);
|
||||||
}
|
}
|
||||||
for (GuiScreen gui : extra.values())
|
for (GuiScreen gui : extra.values())
|
||||||
gui.drawScreen(i, j, f);
|
gui.drawScreen(i, j, f);
|
||||||
|
|
||||||
// Draw scrollable windows.
|
// Draw scrollable windows.
|
||||||
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) {
|
||||||
guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i, j) ? Mouse.getDWheel() : 0);
|
guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i, j) ? wheel : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ViewportGraphEditor graphEditor : graphEditors.values())
|
||||||
|
graphEditor.drawScreen(i, j, f, wheel);
|
||||||
|
|
||||||
for (GuiDiagram diagram : diagrams.values()) {
|
for (GuiDiagram diagram : diagrams.values()) {
|
||||||
diagram.drawDiagram(i, j, subGui);
|
diagram.drawDiagram(i, j, subGui);
|
||||||
}
|
}
|
||||||
@@ -442,7 +471,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
float f4 = entity.rotationPitch;
|
float f4 = entity.rotationPitch;
|
||||||
float f7 = entity.rotationYawHead;
|
float f7 = entity.rotationYawHead;
|
||||||
float f5 = (float) (guiLeft + x) - mouseX;
|
float f5 = (float) (guiLeft + x) - mouseX;
|
||||||
float f6 = (float) ((guiTop + y) - 50 * scale * zoomed) - mouseY;
|
float f6 = (guiTop + y) - 50 * scale * zoomed - mouseY;
|
||||||
int orientation = 0;
|
int orientation = 0;
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
orientation = npc.ais.orientation;
|
orientation = npc.ais.orientation;
|
||||||
@@ -484,8 +513,8 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
|||||||
public void openLink(String link) {
|
public void openLink(String link) {
|
||||||
try {
|
try {
|
||||||
Class oclass = Class.forName("java.awt.Desktop");
|
Class oclass = Class.forName("java.awt.Desktop");
|
||||||
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]);
|
Object object = oclass.getMethod("getDesktop", new Class[0]).invoke(null);
|
||||||
oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new Object[]{new URI(link)});
|
oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new URI(link));
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
|||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
public abstract class GuiNPCInterface2 extends GuiNPCInterface {
|
public abstract class GuiNPCInterface2 extends GuiNPCInterface {
|
||||||
private ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png");
|
private final ResourceLocation background = new ResourceLocation("customnpcs:textures/gui/menubg.png");
|
||||||
private GuiNpcMenu menu;
|
private final GuiNpcMenu menu;
|
||||||
|
|
||||||
public GuiNPCInterface2(EntityNPCInterface npc) {
|
public GuiNPCInterface2(EntityNPCInterface npc) {
|
||||||
this(npc, -1);
|
this(npc, -1);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.GuiTextField;
|
import net.minecraft.client.gui.GuiTextField;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
|
||||||
public class GuiNpcTextField extends GuiTextField {
|
public class GuiNpcTextField extends GuiTextField {
|
||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
@@ -19,7 +20,9 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
protected static GuiNpcTextField activeTextfield = null;
|
protected static GuiNpcTextField activeTextfield = null;
|
||||||
public boolean canEdit = true;
|
public boolean canEdit = true;
|
||||||
|
|
||||||
private final int[] allowedSpecialChars = {14, 211, 203, 205};
|
private String floatingPrecision = "%.4f"; //4 decimal places
|
||||||
|
|
||||||
|
private final int[] allowedSpecialChars = {0, 1, 3, 14, 8, 22, 24, 199, 211, 203, 205, 207, 211};
|
||||||
|
|
||||||
public GuiNpcTextField(int id, GuiScreen parent, FontRenderer fontRenderer, int i, int j, int k, int l, String s) {
|
public GuiNpcTextField(int id, GuiScreen parent, FontRenderer fontRenderer, int i, int j, int k, int l, String s) {
|
||||||
super(fontRenderer, i, j, k, l);
|
super(fontRenderer, i, j, k, l);
|
||||||
@@ -40,14 +43,16 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected boolean charAllowed(char c, int i) {
|
protected boolean charAllowed(char c, int i) {
|
||||||
if (!integersOnly || Character.isDigit(c))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (integersOnly && getText().isEmpty() && c == '-')
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (int j : allowedSpecialChars)
|
for (int j : allowedSpecialChars)
|
||||||
if (j == i)
|
if (j == c)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
String s = getText();
|
||||||
|
boolean isNumbersOnly = integersOnly || floatsOnly || doublesOnly;
|
||||||
|
boolean isDecimal = !integersOnly && c == '.' && !s.contains(".");
|
||||||
|
boolean isNegative = isNumbersOnly && c == '-' && (getSelectionEnd() == 0 || !s.contains("-") && getCursorPosition() == 0);
|
||||||
|
|
||||||
|
if (!isNumbersOnly || isNegative || isDecimal || Character.isDigit(c))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -118,7 +123,7 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
activeTextfield = this;
|
activeTextfield = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unFocused() {
|
public void toDefaults() {
|
||||||
if (integersOnly && !doublesOnly && !floatsOnly) {
|
if (integersOnly && !doublesOnly && !floatsOnly) {
|
||||||
if (isEmpty() || !isInteger())
|
if (isEmpty() || !isInteger())
|
||||||
setText(def + "");
|
setText(def + "");
|
||||||
@@ -127,6 +132,9 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
else if (getInteger() > max)
|
else if (getInteger() > max)
|
||||||
setText(max + "");
|
setText(max + "");
|
||||||
} else if (doublesOnly && !floatsOnly) {
|
} else if (doublesOnly && !floatsOnly) {
|
||||||
|
if (floatingPrecision != null)
|
||||||
|
setText(ValueUtil.format(floatingPrecision, getDouble()));
|
||||||
|
|
||||||
if (isEmpty() || !isDouble())
|
if (isEmpty() || !isDouble())
|
||||||
setText(defDouble + "");
|
setText(defDouble + "");
|
||||||
else if (getDouble() < minDouble)
|
else if (getDouble() < minDouble)
|
||||||
@@ -134,6 +142,9 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
else if (getDouble() > maxDouble)
|
else if (getDouble() > maxDouble)
|
||||||
setText(maxDouble + "");
|
setText(maxDouble + "");
|
||||||
} else if (floatsOnly) {
|
} else if (floatsOnly) {
|
||||||
|
if (floatingPrecision != null)
|
||||||
|
setText(ValueUtil.format(floatingPrecision, getFloat()));
|
||||||
|
|
||||||
if (isEmpty() || !isFloat())
|
if (isEmpty() || !isFloat())
|
||||||
setText(defFloat + "");
|
setText(defFloat + "");
|
||||||
else if (getFloat() < minFloat)
|
else if (getFloat() < minFloat)
|
||||||
@@ -141,6 +152,10 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
else if (getFloat() > maxFloat)
|
else if (getFloat() > maxFloat)
|
||||||
setText(maxFloat + "");
|
setText(maxFloat + "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unFocused() {
|
||||||
|
toDefaults();
|
||||||
setCursorPositionZero();
|
setCursorPositionZero();
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
listener.unFocused(this);
|
listener.unFocused(this);
|
||||||
@@ -155,22 +170,25 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
super.drawTextBox();
|
super.drawTextBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinMaxDefault(int min, int max, int def) {
|
public GuiNpcTextField setMinMaxDefault(int min, int max, int def) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
this.def = def;
|
this.def = def;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinMaxDefaultDouble(double min, double max, double def) {
|
public GuiNpcTextField setMinMaxDefaultDouble(double min, double max, double def) {
|
||||||
minDouble = min;
|
minDouble = min;
|
||||||
maxDouble = max;
|
maxDouble = max;
|
||||||
defDouble = def;
|
defDouble = def;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMinMaxDefaultFloat(float min, float max, float def) {
|
public GuiNpcTextField setMinMaxDefaultFloat(float min, float max, float def) {
|
||||||
minFloat = min;
|
minFloat = min;
|
||||||
maxFloat = max;
|
maxFloat = max;
|
||||||
defFloat = def;
|
defFloat = def;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unfocus() {
|
public static void unfocus() {
|
||||||
@@ -200,5 +218,26 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFloatingPrecision(int decimalPlaces) {
|
||||||
|
floatingPrecision = "%." + decimalPlaces + "f";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInt(int value) {
|
||||||
|
setText(ValueUtil.clamp(value, min, max) + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFloat(float value) {
|
||||||
|
value = ValueUtil.clamp(value, minFloat, maxFloat);
|
||||||
|
setText(ValueUtil.format(floatingPrecision, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDouble(double value) {
|
||||||
|
value = ValueUtil.clamp(value, minDouble, maxDouble);
|
||||||
|
setText(ValueUtil.format(floatingPrecision, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNumbersOnly() {
|
||||||
|
return integersOnly || floatsOnly || doublesOnly;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -113,6 +113,9 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
|||||||
public void mouseEvent(int i, int j, int k) {
|
public void mouseEvent(int i, int j, int k) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void actionPerformed(GuiButton guibutton) {
|
protected void actionPerformed(GuiButton guibutton) {
|
||||||
@@ -266,7 +269,7 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
|||||||
super.drawDefaultBackground();
|
super.drawDefaultBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setClip(int x, int y, int width, int height) {
|
public void setClip(int x, int y, int width, int height) {
|
||||||
if (scaledResolution == null)
|
if (scaledResolution == null)
|
||||||
return;
|
return;
|
||||||
int scaleFactor = scaledResolution.getScaleFactor();
|
int scaleFactor = scaledResolution.getScaleFactor();
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package noppes.npcs.client.gui.util;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.ScaledResolution;
|
||||||
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
public class GuiUtil {
|
||||||
|
|
||||||
|
public static void setScissorClip(int x, int y, int width, int height) {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
int scale = res.getScaleFactor();
|
||||||
|
|
||||||
|
|
||||||
|
// Adjust position to Top-Left origin (OpenGL window/screen space uses bottom-left origin)
|
||||||
|
y = mc.displayHeight - y * scale;
|
||||||
|
height *= scale;
|
||||||
|
|
||||||
|
// Set clip
|
||||||
|
GL11.glScissor(x * scale, y - height, width * scale, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawHorizontalLine(double y, double startX, double endX, int color) {
|
||||||
|
if (endX < startX) {
|
||||||
|
double i1 = startX;
|
||||||
|
startX = endX;
|
||||||
|
endX = i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawRectD(startX, y, endX + 1, y + 1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawVerticalLine(double x, double startY, double endY, int color) {
|
||||||
|
if (endY < startY) {
|
||||||
|
double i1 = startY;
|
||||||
|
startY = endY;
|
||||||
|
endY = i1;
|
||||||
|
}
|
||||||
|
|
||||||
|
drawRectD(x, startY + 1, x + 1, endY, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawRectD(double left, double top, double right, double bottom) {
|
||||||
|
double j1;
|
||||||
|
|
||||||
|
if (left < right) {
|
||||||
|
j1 = left;
|
||||||
|
left = right;
|
||||||
|
right = j1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (top < bottom) {
|
||||||
|
j1 = top;
|
||||||
|
top = bottom;
|
||||||
|
bottom = j1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||||
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
tessellator.addVertex(left, bottom, 0.0D);
|
||||||
|
tessellator.addVertex(right, bottom, 0.0D);
|
||||||
|
tessellator.addVertex(right, top, 0.0D);
|
||||||
|
tessellator.addVertex(left, top, 0.0D);
|
||||||
|
tessellator.draw();
|
||||||
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void drawRectD(double left, double top, double right, double bottom, int color) {
|
||||||
|
float f3 = (float) (color >> 24 & 255) / 255.0F;
|
||||||
|
float f = (float) (color >> 16 & 255) / 255.0F;
|
||||||
|
float f1 = (float) (color >> 8 & 255) / 255.0F;
|
||||||
|
float f2 = (float) (color & 255) / 255.0F;
|
||||||
|
GL11.glColor4f(f, f1, f2, f3);
|
||||||
|
drawRectD(left, top, right, bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawGradientRect(int left, int top, int right, int bottom, int startColor, int endColor) {
|
||||||
|
double zLevel = 0;
|
||||||
|
|
||||||
|
float f = (float) (startColor >> 24 & 255) / 255.0F;
|
||||||
|
float f1 = (float) (startColor >> 16 & 255) / 255.0F;
|
||||||
|
float f2 = (float) (startColor >> 8 & 255) / 255.0F;
|
||||||
|
float f3 = (float) (startColor & 255) / 255.0F;
|
||||||
|
float f4 = (float) (endColor >> 24 & 255) / 255.0F;
|
||||||
|
float f5 = (float) (endColor >> 16 & 255) / 255.0F;
|
||||||
|
float f6 = (float) (endColor >> 8 & 255) / 255.0F;
|
||||||
|
float f7 = (float) (endColor & 255) / 255.0F;
|
||||||
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
|
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
|
||||||
|
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
tessellator.setColorRGBA_F(f1, f2, f3, f);
|
||||||
|
tessellator.addVertex(right, top, zLevel);
|
||||||
|
tessellator.addVertex(left, top, zLevel);
|
||||||
|
tessellator.setColorRGBA_F(f5, f6, f7, f4);
|
||||||
|
tessellator.addVertex(left, bottom, zLevel);
|
||||||
|
tessellator.addVertex(right, bottom, zLevel);
|
||||||
|
tessellator.draw();
|
||||||
|
GL11.glShadeModel(GL11.GL_FLAT);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void drawTexturedModalRect(double x, double y, double width, double height, int textureX, int textureY) {
|
||||||
|
double zLevel = 0;
|
||||||
|
float f = 1 / 256f;
|
||||||
|
float f1 = 1 / 256f;
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
tessellator.startDrawingQuads();
|
||||||
|
tessellator.addVertexWithUV(x + 0, y + height, zLevel, (float) (textureX) * f, (float) (textureY + height) * f1);
|
||||||
|
tessellator.addVertexWithUV(x + width, y + height, zLevel, (float) (textureX + width) * f, (float) (textureY + height) * f1);
|
||||||
|
tessellator.addVertexWithUV(x + width, y + 0, zLevel, (float) (textureX + width) * f, (float) (textureY) * f1);
|
||||||
|
tessellator.addVertexWithUV(x + 0, y + 0, zLevel, (float) (textureX) * f, (float) (textureY) * f1);
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMouse(int guiX, int guiY) {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
|
||||||
|
int factor = scaledResolution.getScaleFactor();
|
||||||
|
|
||||||
|
Mouse.setCursorPosition(guiX * factor, mc.displayHeight - (guiY * factor));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMouseX(int guiX) {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
|
||||||
|
int factor = scaledResolution.getScaleFactor();
|
||||||
|
Mouse.setCursorPosition(guiX * factor, Mouse.getY());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMouseY(int guiY) {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
|
||||||
|
int factor = scaledResolution.getScaleFactor();
|
||||||
|
Mouse.setCursorPosition(Mouse.getX(), mc.displayHeight - (guiY * factor));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double preciseMouseX() {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
|
||||||
|
double width = scaledResolution.getScaledWidth();
|
||||||
|
return Mouse.getX() * width / mc.displayWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double preciseMouseY() {
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ScaledResolution scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||||
|
|
||||||
|
double height = scaledResolution.getScaledHeight();
|
||||||
|
return height - Mouse.getY() * height / mc.displayHeight - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||||
|
import noppes.npcs.client.gui.util.animation.panel.PanelActiveFrame;
|
||||||
|
import noppes.npcs.client.gui.util.animation.panel.PanelFrameType;
|
||||||
|
import noppes.npcs.constants.animation.EnumFrameType;
|
||||||
|
|
||||||
|
public class AnimationGraphEditor extends ViewportGraphEditor {
|
||||||
|
|
||||||
|
public GridPointManager pointManager;
|
||||||
|
public PanelFrameType frameTypePanel = new PanelFrameType(this);
|
||||||
|
public PanelActiveFrame activeFramePanel = new PanelActiveFrame(this);
|
||||||
|
|
||||||
|
public AnimationGraphEditor(GuiNPCInterface parent) {
|
||||||
|
super(parent);
|
||||||
|
pointManager = new GridPointManager(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui(int startX, int startY, int endX, int endY) {
|
||||||
|
super.initGui(startX, startY, endX, endY);
|
||||||
|
frameTypePanel.initGui(startX - 70, startY, startX, startY + 78);
|
||||||
|
activeFramePanel.initGui(startX - 70, startY + 79, startX, endY-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||||
|
frameTypePanel.draw(wheel);
|
||||||
|
if (pointManager.selectedPoint != null)
|
||||||
|
activeFramePanel.draw(wheel);
|
||||||
|
grid.draw(mouseX, mouseY, partialTicks, wheel);
|
||||||
|
pointManager.draw(mouseX, mouseY, partialTicks);
|
||||||
|
presetOverlay.draw(mouseX, mouseY, wheel);
|
||||||
|
|
||||||
|
if (Cursors.currentCursor() != null)
|
||||||
|
Cursors.currentCursor().draw(mouseX, mouseY);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
super.mouseClicked(mouseX, mouseY, button);
|
||||||
|
frameTypePanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
if (pointManager.selectedPoint != null)
|
||||||
|
activeFramePanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
pointManager.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
super.keyTyped(c, i);
|
||||||
|
frameTypePanel.keyTyped(c, i);
|
||||||
|
if (pointManager.selectedPoint != null)
|
||||||
|
activeFramePanel.keyTyped(c, i);
|
||||||
|
pointManager.keyTyped(c, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnumFrameType getSelectedType() {
|
||||||
|
return frameTypePanel.selectedElement.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedType(EnumFrameType type) {
|
||||||
|
frameTypePanel.list.forEach(element -> {
|
||||||
|
if(element.type == type)
|
||||||
|
frameTypePanel.selectedElement = element;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.LWJGLException;
|
||||||
|
import org.lwjgl.input.Cursor;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public enum Cursors {
|
||||||
|
|
||||||
|
MOVE(0, 0, 0, 0, 19, 19, 0.5f), SLIDE(0, 0, 0, 20, 16, 8, 0.66f), EMPTY(0, 0, 0, 0, 0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
public int offsetX, offsetY, textureX, textureY, width, height;
|
||||||
|
public float scale;
|
||||||
|
|
||||||
|
Cursors(int offsetX, int offsetY, int textureX, int textureY, int width, int height, float scale) {
|
||||||
|
|
||||||
|
this.textureX = textureX;
|
||||||
|
this.textureY = textureY;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.offsetX = -width / 2;
|
||||||
|
this.offsetY = offsetY;
|
||||||
|
this.scale = scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(double mouseX, double mouseY) {
|
||||||
|
offsetX = width / 2;
|
||||||
|
offsetY = height / 2;
|
||||||
|
double screenX = (mouseX / scale - offsetX);
|
||||||
|
double screenY = (mouseY / scale - offsetY);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
GL11.glColor4f(1, 1, 1, 1);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||||
|
GuiUtil.drawTexturedModalRect(screenX, screenY, width, height, textureX, textureY);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Cursors currentCursor;
|
||||||
|
public static Supplier<Boolean> condition;
|
||||||
|
|
||||||
|
public static void setCursor(Cursors cursor, Supplier<Boolean> con) {
|
||||||
|
try {
|
||||||
|
Cursor c = null;
|
||||||
|
if (cursor != null)
|
||||||
|
c = new Cursor(1, 1, 0, 0, 1, BufferUtils.createIntBuffer(1), null);
|
||||||
|
Mouse.setNativeCursor(c);
|
||||||
|
} catch (LWJGLException e) {
|
||||||
|
}
|
||||||
|
currentCursor = cursor;
|
||||||
|
condition = con;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
setCursor(null, null);
|
||||||
|
condition = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void tick() {
|
||||||
|
if (condition != null && !condition.get())
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Cursors currentCursor() {
|
||||||
|
return currentCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/cursors.png");
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,393 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
|
|
||||||
|
public class Grid {
|
||||||
|
ViewportGraphEditor parent;
|
||||||
|
public int startX, startY, width, height; // Positioning
|
||||||
|
public int endX, endY; // Positioning
|
||||||
|
public int yAxisHeight = 12;
|
||||||
|
|
||||||
|
public int mouseX, mouseY;
|
||||||
|
|
||||||
|
public float zoomX = 20f, targetZoomX = 20f, zoomY = 1f, targetZoomY = 1f; //Zoom smoothness
|
||||||
|
public float panX = 0, panY = 0, targetPanX, targetPanY; // pan offsets
|
||||||
|
public int startPanX, startPanY;
|
||||||
|
public boolean smoothenPanX, smoothenPanY;
|
||||||
|
public int subDivisionX = 1, subDivisionY = 2;
|
||||||
|
|
||||||
|
public boolean isDragging, isResetting;
|
||||||
|
public boolean centerAroundMouse = true;
|
||||||
|
|
||||||
|
public Grid(ViewportGraphEditor parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keys() {
|
||||||
|
GraphEditorKeyPresets keys = parent.keys;
|
||||||
|
|
||||||
|
keys.RESET_GRID.setTask((pressType) -> {
|
||||||
|
if (pressType == KeyPreset.PRESS) {
|
||||||
|
if (!isResetting) {
|
||||||
|
if (xDown()) {
|
||||||
|
targetPanX = 0;
|
||||||
|
targetZoomX = 20;
|
||||||
|
smoothenPanX = true;
|
||||||
|
} else if (yDown()) {
|
||||||
|
targetPanY = -((height) * subDivisionY / 2);
|
||||||
|
targetZoomY = 1.0f;
|
||||||
|
smoothenPanY = true;
|
||||||
|
} else {
|
||||||
|
targetPanY = -((height) * subDivisionY / 2);
|
||||||
|
targetPanX = 0;
|
||||||
|
targetZoomX = 20;
|
||||||
|
targetZoomY = 1.0f;
|
||||||
|
smoothenPanX = smoothenPanY = true;
|
||||||
|
}
|
||||||
|
isResetting = true;
|
||||||
|
centerAroundMouse = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keys.PAN_GRID.setTask((pressType) -> {
|
||||||
|
if (pressType == KeyPreset.PRESS) {
|
||||||
|
isDragging = true;
|
||||||
|
startPanX = mouseX;
|
||||||
|
startPanY = mouseY;
|
||||||
|
} else if (pressType == KeyPreset.RELEASE)
|
||||||
|
isDragging = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(int startX, int startY, int endX, int endY) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
|
||||||
|
this.width = endX - this.startX;
|
||||||
|
this.height = endY - this.startY;
|
||||||
|
|
||||||
|
panY = -(height * subDivisionY / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||||
|
this.mouseX = mouseX;
|
||||||
|
this.mouseY = mouseY;
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// Panning
|
||||||
|
|
||||||
|
if (isDragging && parent.isWithin(mouseX, mouseY) && !isResetting) {
|
||||||
|
if (xDown())
|
||||||
|
panX -= (mouseX - startPanX) / zoomX;
|
||||||
|
else if (yDown())
|
||||||
|
panY -= (mouseY - startPanY) / zoomY;
|
||||||
|
else {
|
||||||
|
panX -= (mouseX - startPanX) / zoomX;
|
||||||
|
panY -= (mouseY - startPanY) / zoomY * subDivisionY;
|
||||||
|
}
|
||||||
|
startPanX = mouseX;
|
||||||
|
startPanY = mouseY;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// Zoom logic
|
||||||
|
if (wheel != 0 && !parent.presetOverlay.showOverlay&& isMouseOver(mouseX,mouseY)) {
|
||||||
|
float xRate = zoomX < 15 ? 1.1f : 1.25f;
|
||||||
|
float yRate = zoomY < 15 ? 1.1f : 1.25f;
|
||||||
|
|
||||||
|
if (xDown())
|
||||||
|
targetZoomX = ValueUtil.clamp(wheel > 0 ? targetZoomX * xRate : targetZoomX / xRate, 0.025f, 100);
|
||||||
|
else if (yDown())
|
||||||
|
targetZoomY = ValueUtil.clamp(wheel > 0 ? targetZoomY * yRate : targetZoomY / yRate, 0.025f, 100);
|
||||||
|
else {
|
||||||
|
targetZoomX = ValueUtil.clamp(wheel > 0 ? targetZoomX * xRate : targetZoomX / xRate, 0.025f, 100);
|
||||||
|
targetZoomY = ValueUtil.clamp(wheel > 0 ? targetZoomY * yRate : targetZoomY / yRate, 0.025f, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zoomX != targetZoomX || zoomY != targetZoomY)
|
||||||
|
zoom(mouseX, mouseY, wheel);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
// Reset logic
|
||||||
|
if (isResetting) {
|
||||||
|
if (zoomX == targetZoomX && zoomY == targetZoomY && (smoothenPanX ? panX == targetPanX : smoothenPanY ? panY == targetPanY : true)) {
|
||||||
|
isResetting = smoothenPanX = smoothenPanY = false;
|
||||||
|
centerAroundMouse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
float rate = 0.1f;
|
||||||
|
if (smoothenPanX && panX != targetPanX) {
|
||||||
|
panX = ValueUtil.lerp(panX, targetPanX, rate);
|
||||||
|
if (Math.abs(panX - targetPanX) < 0.1)
|
||||||
|
panX = targetPanX;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (smoothenPanY && panY != targetPanY) {
|
||||||
|
panY = ValueUtil.lerp(panY, targetPanY, rate);
|
||||||
|
if (Math.abs(panY - targetPanY) < 0.1)
|
||||||
|
panY = targetPanY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
Gui.drawRect(startX, startY - yAxisHeight, endX, startY, 0xFF161616); //header
|
||||||
|
GuiUtil.drawGradientRect(startX, startY, endX, endY, 0xFF303030, 0xFF303030);
|
||||||
|
|
||||||
|
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||||
|
GuiUtil.setScissorClip(startX, startY, width, height);
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
drawLines(mouseX, mouseY);
|
||||||
|
GL11.glDepthMask(true);
|
||||||
|
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||||
|
return mouseX >= startX && mouseX <= startX + width && mouseY >= startY && mouseY <= startY + height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void zoom(int mouseX, int mouseY, int wheel) {
|
||||||
|
///////////////////////////////////////////////////////
|
||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//Zooms in on mouse point
|
||||||
|
double beforeWorldX = worldX(mouseX - startX);
|
||||||
|
double beforeWorldY = worldY(mouseY - startY);
|
||||||
|
|
||||||
|
float rate = isResetting ? 0.1f : 0.05f;
|
||||||
|
zoomX = ValueUtil.lerp(zoomX, targetZoomX, rate);
|
||||||
|
zoomY = ValueUtil.lerp(zoomY, targetZoomY, rate);
|
||||||
|
|
||||||
|
// Snap to exact target value
|
||||||
|
if (Math.abs(zoomX - targetZoomX) < 0.001)
|
||||||
|
zoomX = targetZoomX;
|
||||||
|
if (Math.abs(zoomY - targetZoomY) < 0.001)
|
||||||
|
zoomY = targetZoomY;
|
||||||
|
|
||||||
|
double afterWorldX = worldX(mouseX - startX);
|
||||||
|
double afterWorldY = worldY(mouseY - startY);
|
||||||
|
|
||||||
|
if (centerAroundMouse) {
|
||||||
|
if (xDown())
|
||||||
|
panX += beforeWorldX - afterWorldX;
|
||||||
|
else if (yDown())
|
||||||
|
panY += beforeWorldY - afterWorldY;
|
||||||
|
else {
|
||||||
|
panX += beforeWorldX - afterWorldX;
|
||||||
|
panY += beforeWorldY - afterWorldY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawLines(int mouseX, int mouseY) {
|
||||||
|
int darkGray = 0xFF1a1a1a; // Major grid
|
||||||
|
int lightGray = 0xFF2a2a2a; // Minor grid
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Vertical
|
||||||
|
double stepX = getStepX();
|
||||||
|
double firstGridX = Math.floor((panX) / stepX) * stepX;
|
||||||
|
for (double x = firstGridX, i = 0; x <= worldX(endX); x += stepX / 5, i++) {
|
||||||
|
boolean isMajor = i % 5 == 0;
|
||||||
|
double screenX = screenX(x);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(startX, 0, 0);
|
||||||
|
|
||||||
|
GuiUtil.drawVerticalLine(screenX, startY, endY, isMajor ? darkGray : lightGray);
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Expand boundaries of scissor clip
|
||||||
|
GuiUtil.setScissorClip(startX, startY - yAxisHeight, width, height + yAxisHeight);
|
||||||
|
for (double x = firstGridX; x <= worldX(endX); x += stepX)
|
||||||
|
drawXValue((int) screenX(x), (int) x);
|
||||||
|
|
||||||
|
//Reset clip
|
||||||
|
GuiUtil.setScissorClip(startX, startY, width, height);
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Horizontal
|
||||||
|
double stepY = getStepY();
|
||||||
|
double firstGridY = Math.floor((panY) / stepY) * stepY;
|
||||||
|
for (double y = firstGridY, i = 0; y <= worldY(endY); y += stepY / 5, i++) {
|
||||||
|
boolean isMajor = i % 5 == 0;
|
||||||
|
double screenY = screenY(y);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(0, startY, 0);
|
||||||
|
GuiUtil.drawHorizontalLine(screenY, startX, endX, isMajor ? darkGray : lightGray);
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (double y = firstGridY; y <= worldY(endY); y += stepY)
|
||||||
|
drawYValue((int) screenY(y), (int) -y);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getStepX() {
|
||||||
|
double stepSize = 0;
|
||||||
|
if (zoomX < 0.1) // 0-1000
|
||||||
|
stepSize = 1000;
|
||||||
|
else if (zoomX < 0.2) // 0-500
|
||||||
|
stepSize = 500;
|
||||||
|
else if (zoomX < 0.5) // 0-200
|
||||||
|
stepSize = 200;
|
||||||
|
else if (zoomX <= 1) // 0-100
|
||||||
|
stepSize = 100;
|
||||||
|
else if (zoomX < 1.5) //0-50
|
||||||
|
stepSize = 50;
|
||||||
|
else if (zoomX < 3) //0-20
|
||||||
|
stepSize = 20;
|
||||||
|
else if (zoomX < 4.5) //0-10
|
||||||
|
stepSize = 10;
|
||||||
|
else if (zoomX < 10) //0-5
|
||||||
|
stepSize = 5;
|
||||||
|
else if (zoomX < 18) //0-2 For Default reset
|
||||||
|
stepSize = 2;
|
||||||
|
else if (zoomX <= 100) //0-1
|
||||||
|
stepSize = 1;
|
||||||
|
return stepSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getStepY() {
|
||||||
|
double stepSize = 0;
|
||||||
|
if (zoomY < 0.1) // 0-1000
|
||||||
|
stepSize = 1000;
|
||||||
|
else if (zoomY < 0.2) // 0-500
|
||||||
|
stepSize = 500;
|
||||||
|
else if (zoomY < 0.5) // 0-200
|
||||||
|
stepSize = 200;
|
||||||
|
else if (zoomY < 0.9) // 0-100 For Default reset
|
||||||
|
stepSize = 100;
|
||||||
|
else if (zoomY < 1.5) //0-50
|
||||||
|
stepSize = 50;
|
||||||
|
else if (zoomY < 3) //0-20
|
||||||
|
stepSize = 20;
|
||||||
|
else if (zoomY < 4.5) //0-10
|
||||||
|
stepSize = 10;
|
||||||
|
else if (zoomY < 10) //0-5
|
||||||
|
stepSize = 5;
|
||||||
|
else if (zoomY < 20) //0-2
|
||||||
|
stepSize = 2;
|
||||||
|
else if (zoomY <= 100) //0-1
|
||||||
|
stepSize = 1;
|
||||||
|
return stepSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawXValue(int screenX, int value) {
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
float scale = 0.75f;
|
||||||
|
int adjustedX = (int) ((screenX + 1) / scale); // Offset to the left of grid line
|
||||||
|
int adjustedY = (int) ((startY - yAxisHeight + 4) / scale); // Adjust Y position
|
||||||
|
|
||||||
|
GL11.glTranslatef(startX, 0, 1f);
|
||||||
|
GL11.glScalef(scale, scale, 1f);
|
||||||
|
parent.drawString(String.valueOf(value), adjustedX, adjustedY, 0xFFA0A0A0);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawYValue(int screenY, int value) {
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
float scale = 0.5f;
|
||||||
|
int adjustedX = (int) ((startX + 10) / scale); // Offset to the left of grid line
|
||||||
|
int adjustedY = (int) ((screenY - 1) / scale); // Adjust Y position
|
||||||
|
|
||||||
|
GL11.glTranslatef(0, startY, 1f);
|
||||||
|
GL11.glScalef(scale, scale, 1f);
|
||||||
|
parent.drawString(String.valueOf(value), adjustedX, adjustedY, 0xFFFFFF);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean xDown() {
|
||||||
|
return parent.keys.LOCK_X.isDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean yDown() {
|
||||||
|
return parent.keys.LOCK_Y.isDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Double
|
||||||
|
public double worldX(double screenX) {
|
||||||
|
return screenX * subDivisionX / zoomX + panX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double worldY(double screenY) {
|
||||||
|
return screenY * subDivisionY / zoomY + panY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenX(double worldX) {
|
||||||
|
return (worldX - panX) * zoomX / subDivisionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenY(double worldY) {
|
||||||
|
return (worldY - panY) * zoomY / subDivisionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Float
|
||||||
|
public double worldX(float screenX) {
|
||||||
|
return screenX * subDivisionX / zoomX + panX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double worldY(float screenY) {
|
||||||
|
return screenY * subDivisionY / zoomY + panY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenX(float worldX) {
|
||||||
|
return (worldX - panX) * zoomX / subDivisionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenY(float worldY) {
|
||||||
|
return (worldY - panY) * zoomY / subDivisionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Int
|
||||||
|
public double worldX(int screenX) {
|
||||||
|
return screenX * subDivisionX / zoomX + panX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double worldY(int screenY) {
|
||||||
|
return screenY * subDivisionY / zoomY + panY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenX(int worldX) {
|
||||||
|
return (worldX - panX) * zoomX / subDivisionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenY(int worldY) {
|
||||||
|
return (worldY - panY) * zoomY / subDivisionY;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,527 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
import noppes.npcs.constants.animation.EnumFrameType;
|
||||||
|
import noppes.npcs.util.Ease;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
public class GridPointManager {
|
||||||
|
public AnimationGraphEditor graph;
|
||||||
|
public Grid grid;
|
||||||
|
public GraphEditorKeyPresets keys;
|
||||||
|
|
||||||
|
public HashMap<EnumFrameType, TreeMap<Double, Point>> typePoints = new HashMap<>();
|
||||||
|
public List<Point> highlightedPoints = new ArrayList<>();
|
||||||
|
public Point selectedPoint;
|
||||||
|
public Playhead playhead = new Playhead(0);
|
||||||
|
|
||||||
|
public boolean isFreeTransforming;
|
||||||
|
public double ftGrabX, ftGrabY; //where point is grabbed on free transforming
|
||||||
|
|
||||||
|
public GridPointManager(AnimationGraphEditor graph) {
|
||||||
|
this.graph = graph;
|
||||||
|
this.grid = graph.grid;
|
||||||
|
keys = grid.parent.keys;
|
||||||
|
keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keys() {
|
||||||
|
|
||||||
|
keys.SELECT_POINT.setTask((pressType) -> {
|
||||||
|
if (pressType == KeyPreset.PRESS) {
|
||||||
|
forEachActive((pointType, point) -> {
|
||||||
|
if (point.isMouseAbove(grid.mouseX, grid.mouseY)) {
|
||||||
|
setSelectedPoint(point);
|
||||||
|
graph.setSelectedType(pointType);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keys.ADD_POINT.setTask((pressType) -> {
|
||||||
|
if (pressType == KeyPreset.PRESS) {
|
||||||
|
// if (!highlightedTypes.contains(type))
|
||||||
|
// highlightedTypes.add(type);
|
||||||
|
|
||||||
|
TreeMap<Double, Point> points = pointsOf(graph.getSelectedType());
|
||||||
|
Point point = points != null ? points.get((double) playhead.worldX) : null; //check if it exists
|
||||||
|
if (point == null)
|
||||||
|
point = addPoint(graph.getSelectedType(), playhead.worldX, 0); // worldX(mouseX - startX), worldY(mouseY - startY)
|
||||||
|
|
||||||
|
setSelectedPoint(point);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keys.DELETE_POINT.setTask((pressType) -> {
|
||||||
|
if ((pressType == KeyPreset.PRESS) && selectedPoint != null && !grid.isDragging) {
|
||||||
|
deletePoint(selectedPoint.type, selectedPoint.worldX);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keys.FREE_TRANSFORM.setTask((pressType) -> {
|
||||||
|
if (pressType == KeyPreset.PRESS && selectedPoint != null) {
|
||||||
|
if (isFreeTransforming) {
|
||||||
|
selectedPoint.set(ftGrabX, ftGrabY);
|
||||||
|
ftGrabX = ftGrabY = 0;
|
||||||
|
} else {
|
||||||
|
ftGrabX = selectedPoint.worldX;
|
||||||
|
ftGrabY = selectedPoint.worldY;
|
||||||
|
Cursors.setCursor(Cursors.MOVE, () -> selectedPoint != null && isFreeTransforming);
|
||||||
|
}
|
||||||
|
|
||||||
|
isFreeTransforming = !isFreeTransforming;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
if (button == 0 && selectedPoint != null && !isFreeTransforming) {
|
||||||
|
if (grid.parent.isWithin(mouseX, mouseY) && !selectedPoint.isMouseAbove(mouseX, mouseY))
|
||||||
|
setSelectedPoint(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button == 0 && isFreeTransforming) {
|
||||||
|
selectedPoint.updateKey();
|
||||||
|
// Cursors.reset();
|
||||||
|
isFreeTransforming = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
playhead.mouseClicked(mouseX, mouseY, button);
|
||||||
|
forEachActive((type, point) -> {
|
||||||
|
point.mouseClicked(mouseX, mouseY, button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTypeValues(double x) {
|
||||||
|
// if (x != playhead.worldX)
|
||||||
|
// return;
|
||||||
|
graph.frameTypePanel.updateTypeValues(playhead.worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point addPoint(EnumFrameType type, double x, double y) {
|
||||||
|
return addPoint(type, new Point(type, x, y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point addPoint(EnumFrameType type, Point point) {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null) {
|
||||||
|
points = new TreeMap<>();
|
||||||
|
typePoints.put(type, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
points.put(point.worldX, point);
|
||||||
|
updateTypeValues(point.worldX);
|
||||||
|
return point;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deletePoint(EnumFrameType type, double x) {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Point point = points.remove(x);
|
||||||
|
updateTypeValues(x);
|
||||||
|
if (point == selectedPoint)
|
||||||
|
setSelectedPoint(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getPoint(EnumFrameType type, double x) {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return points.get(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public TreeMap<Double, Point> pointsOf(EnumFrameType type) {
|
||||||
|
return typePoints.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEach(BiConsumer<EnumFrameType, Point> consumer) {
|
||||||
|
for (Map.Entry<EnumFrameType, TreeMap<Double, Point>> entry : typePoints.entrySet()) {
|
||||||
|
EnumFrameType type = entry.getKey();
|
||||||
|
|
||||||
|
|
||||||
|
for (Map.Entry<Double, Point> points : entry.getValue().entrySet()) {
|
||||||
|
Point point = points.getValue();
|
||||||
|
consumer.accept(type, point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forEachActive(BiConsumer<EnumFrameType, Point> consumer) {
|
||||||
|
for (Map.Entry<EnumFrameType, TreeMap<Double, Point>> entry : typePoints.entrySet()) {
|
||||||
|
EnumFrameType type = entry.getKey();
|
||||||
|
|
||||||
|
// if (!highlightedTypes.contains(type))
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
for (Map.Entry<Double, Point> points : entry.getValue().entrySet()) {
|
||||||
|
Point point = points.getValue();
|
||||||
|
consumer.accept(type, point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedPoint(Point point) {
|
||||||
|
if (selectedPoint != null)
|
||||||
|
selectedPoint.highlighted = false;
|
||||||
|
|
||||||
|
this.selectedPoint = point;
|
||||||
|
|
||||||
|
if (point != null)
|
||||||
|
point.highlighted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getPrevious(Point point) {
|
||||||
|
return getPrevious(point.type, point.worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getPrevious(EnumFrameType type, double x) {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Map.Entry<Double, Point> entry = points.lowerEntry(x);
|
||||||
|
if (entry != null)
|
||||||
|
return entry.getValue();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getNext(Point point) {
|
||||||
|
return getNext(point.type, point.worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getNext(EnumFrameType type, double x) {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
Map.Entry<Double, Point> entry = points.higherEntry(x);
|
||||||
|
if (entry != null)
|
||||||
|
return entry.getValue();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getValueBetweenPointsAt(Point from, Point to, double at) {
|
||||||
|
float lerpFactor = (float) ((at - from.worldX) / (to.worldX - from.worldX));
|
||||||
|
return - ValueUtil.lerp(from.worldY, to.worldY, Ease.INOUTQUINT.apply(lerpFactor));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawEasedCurve(Point from, Point to) {
|
||||||
|
if (from == null || to == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||||
|
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||||
|
GL11.glLineWidth(3F);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(grid.startX, grid.startY, 0);
|
||||||
|
from.type.getColor().multiply(from.type == graph.getSelectedType() ? 1 : 0.55f).glColor();
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.instance;
|
||||||
|
tessellator.startDrawing(GL11.GL_LINE_STRIP);
|
||||||
|
|
||||||
|
|
||||||
|
for (float t = 0; t <= 1; t += 0.01) {
|
||||||
|
float easedT = Ease.INOUTQUINT.apply(t);
|
||||||
|
double xt = ValueUtil.lerp(from.screenX() + 0.5, to.screenX() + 0.5, t);
|
||||||
|
double yt = ValueUtil.lerp(from.screenY() + 0.5, to.screenY() + 0.5, easedT);
|
||||||
|
|
||||||
|
tessellator.addVertex(xt, yt, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
GL11.glLineWidth(1F);
|
||||||
|
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
|
||||||
|
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Free transform logic
|
||||||
|
if (isFreeTransforming && selectedPoint != null) {
|
||||||
|
boolean shift = KeyPreset.isShiftKeyDown();
|
||||||
|
if (grid.xDown())
|
||||||
|
selectedPoint.setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||||
|
else if (grid.yDown()) {
|
||||||
|
double value = grid.worldY(GuiUtil.preciseMouseY() - grid.startY);
|
||||||
|
selectedPoint.setY(shift ? (int) value : value);
|
||||||
|
} else {
|
||||||
|
double y = grid.worldY(GuiUtil.preciseMouseY() - grid.startY);
|
||||||
|
selectedPoint.set(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)), shift ? (int) y : y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
playhead.draw(mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
forEachActive((type, point) -> {
|
||||||
|
drawEasedCurve(point, getNext(point));
|
||||||
|
point.draw(mouseX, mouseY, partialTicks);
|
||||||
|
});
|
||||||
|
if (selectedPoint != null)
|
||||||
|
selectedPoint.draw(mouseX, mouseY, partialTicks);
|
||||||
|
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Pans grid while free transforming
|
||||||
|
// MUST BE DONE AT THE VERY END -> CHANGES CURSOR POSITION WITHOUT
|
||||||
|
// CHANGING GuiScreen.drawScreen(mouseX,mouseY) VALUES
|
||||||
|
if (isFreeTransforming) {
|
||||||
|
if (mouseX < grid.startX) {
|
||||||
|
int deltaX = mouseX - grid.startX;
|
||||||
|
grid.panX += deltaX / grid.zoomX;
|
||||||
|
GuiUtil.setMouseX(grid.startX - 1);
|
||||||
|
}
|
||||||
|
if (mouseX > grid.endX) {
|
||||||
|
int deltaX = mouseX - grid.endX;
|
||||||
|
grid.panX += (deltaX / grid.zoomX);
|
||||||
|
GuiUtil.setMouseX(grid.endX + 1);
|
||||||
|
}
|
||||||
|
if (mouseY < grid.startY) {
|
||||||
|
int deltaY = mouseY - grid.startY;
|
||||||
|
grid.panY += deltaY / grid.zoomY;
|
||||||
|
GuiUtil.setMouseY(grid.startY);
|
||||||
|
}
|
||||||
|
if (mouseY > grid.endY) {
|
||||||
|
int deltaY = mouseY - grid.endY;
|
||||||
|
grid.panY += deltaY / grid.zoomY;
|
||||||
|
GuiUtil.setMouseY(grid.endY + 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int key) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/animation.png");
|
||||||
|
|
||||||
|
public class Point {
|
||||||
|
public EnumFrameType type;
|
||||||
|
public double worldX, worldY;
|
||||||
|
public boolean highlighted;
|
||||||
|
|
||||||
|
public double previousX;
|
||||||
|
|
||||||
|
public Point(EnumFrameType type, double worldX, double worldY) {
|
||||||
|
this.type = type;
|
||||||
|
this.worldX = previousX = worldX;
|
||||||
|
this.worldY = worldY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(double x) {
|
||||||
|
worldX = (int) x;
|
||||||
|
updateTypeValues(worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(double y) {
|
||||||
|
worldY = y;
|
||||||
|
updateTypeValues(worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(double x, double y) {
|
||||||
|
setX(x);
|
||||||
|
setY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateKey() {
|
||||||
|
TreeMap<Double, Point> points = pointsOf(type);
|
||||||
|
if (points == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
points.remove(previousX);
|
||||||
|
points.put(worldX, this);
|
||||||
|
previousX = worldX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
float scale = 0.1f;
|
||||||
|
int textureWidth = 32, textureHeight = 32;
|
||||||
|
float offsetX = (textureHeight / 2) * scale - 0.5f, offsetY = (textureHeight / 2) * scale - 0.5f;
|
||||||
|
double screenX = screenX() / scale, screenY = screenY() / scale;
|
||||||
|
|
||||||
|
grid.parent.mc.getTextureManager().bindTexture(TEXTURE);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
new Color(highlighted ? 0xffbe33 : 0xbfbfbf, 1).glColor();
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(grid.startX - offsetX, grid.startY - offsetY, 0);
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
GuiUtil.drawTexturedModalRect(screenX, screenY, textureWidth, textureHeight, 256 - textureWidth, 256 - textureHeight);
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
int rMX = mouseX - grid.startX, rMY = mouseY - grid.startY; //relative to grid
|
||||||
|
float scale = 0.1f;
|
||||||
|
float textureWidth = (32), textureHeight = (32);
|
||||||
|
float offsetX = (textureWidth / 2) * scale - 0.5f, offsetY = (textureHeight / 2) * scale - 0.5f;
|
||||||
|
|
||||||
|
int screenX = (int) (screenX() - offsetX);
|
||||||
|
int screenY = (int) ((screenY()) - offsetY);
|
||||||
|
|
||||||
|
return rMX >= screenX && rMX < screenX + textureWidth * scale && rMY >= screenY && rMY < screenY + textureHeight * scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenX() {
|
||||||
|
|
||||||
|
return grid.screenX(worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenY() {
|
||||||
|
return grid.screenY(worldY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Playhead {
|
||||||
|
public int worldX;
|
||||||
|
public boolean isDragging;
|
||||||
|
|
||||||
|
public Playhead(int currentX) {
|
||||||
|
this.worldX = currentX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
// Dragging
|
||||||
|
if (isDragging && !Mouse.isButtonDown(0))
|
||||||
|
isDragging = false;
|
||||||
|
|
||||||
|
if (isDragging)
|
||||||
|
setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||||
|
|
||||||
|
//Expand clip boundary
|
||||||
|
GuiUtil.setScissorClip(grid.startX, grid.startY - grid.yAxisHeight, grid.width, grid.height + grid.yAxisHeight);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Head lines
|
||||||
|
double screenX = screenX();
|
||||||
|
float height = grid.endY - grid.startY;
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslated(grid.startX + screenX, grid.startY, 0);
|
||||||
|
GL11.glDepthMask(false);
|
||||||
|
GuiUtil.drawVerticalLine(-1, 0, height, 0xFF212121);
|
||||||
|
GuiUtil.drawVerticalLine(0, -5, height, 0xFF4772b3);
|
||||||
|
GuiUtil.drawVerticalLine(1, 0, height, 0xFF212121);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Head texture
|
||||||
|
FontRenderer fontRenderer = grid.parent.getFontRenderer();
|
||||||
|
float textureScaleX = 0.5f, textureScaleY = 0.5f;
|
||||||
|
|
||||||
|
// Texture width dynamically scales with string width
|
||||||
|
int defaultWidth = 6, width = fontRenderer.getStringWidth(worldX + "");
|
||||||
|
if (width / defaultWidth > 1)
|
||||||
|
textureScaleX += width / defaultWidth * 0.125;
|
||||||
|
|
||||||
|
int textureWidth = 25, textureHeight = 17;
|
||||||
|
float offset = (textureWidth / 2) * textureScaleX;
|
||||||
|
float screenY = grid.startY - grid.yAxisHeight;
|
||||||
|
|
||||||
|
grid.parent.mc.getTextureManager().bindTexture(TEXTURE);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
new Color(0x426dae, 1).glColor();
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(grid.startX, 0, 0);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(-offset, 0, 0);
|
||||||
|
GL11.glScalef(textureScaleX, textureScaleY, 1);
|
||||||
|
|
||||||
|
GuiUtil.drawTexturedModalRect(screenX / textureScaleX, (screenY + 2) / textureScaleY, textureWidth, textureHeight, 228, 199);
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Head value
|
||||||
|
float vScale = 0.75f;
|
||||||
|
double valueScreenX = (screenX + 1) / vScale;
|
||||||
|
double valueScreenY = (screenY + 4) / vScale;
|
||||||
|
GL11.glScalef(vScale, vScale, 1);
|
||||||
|
grid.parent.drawString(String.valueOf(worldX), (int) valueScreenX, (int) valueScreenY, 0xFFccd7e9);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//Reset clip
|
||||||
|
GuiUtil.setScissorClip(grid.startX, grid.startY, grid.width, grid.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
int rMX = mouseX - grid.startX, rMY = mouseY - grid.startY; //relative to grid
|
||||||
|
float scale = 0.5f;
|
||||||
|
float textureWidth = (25 * scale), textureHeight = (17 * scale);
|
||||||
|
float offsetX = (textureWidth / 2) * scale;
|
||||||
|
|
||||||
|
int screenX = (int) Math.round(screenX() - (offsetX / scale));
|
||||||
|
int screenY = -grid.yAxisHeight + 2;
|
||||||
|
|
||||||
|
return rMX >= screenX && rMX <= screenX + textureWidth && rMY >= screenY && rMY < screenY + textureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
|
||||||
|
if (button == 0 && mouseX >= grid.startX && mouseX <= grid.endX && mouseY >= grid.startY - grid.yAxisHeight && mouseY <= grid.startY) {
|
||||||
|
setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
|
||||||
|
updateTypeValues(worldX);
|
||||||
|
isDragging = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(double x) {
|
||||||
|
this.worldX = (int) x;
|
||||||
|
updateTypeValues(worldX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double screenX() {
|
||||||
|
return grid.screenX(worldX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.KeyPresetManager;
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OverlayKeyPresetViewer {
|
||||||
|
public static final ResourceLocation TEXTURE = new ResourceLocation("customnpcs:textures/gui/keypreset_highres.png");
|
||||||
|
|
||||||
|
public int startX, startY, endX, endY, width, height;
|
||||||
|
public int mouseX, mouseY;
|
||||||
|
public boolean showOverlay;
|
||||||
|
|
||||||
|
public int elementSpacing = 5, yStartSpacing = 5;
|
||||||
|
public float scale = 0.75f;
|
||||||
|
public Scrollable scroll = new Scrollable();
|
||||||
|
|
||||||
|
public KeyPresetManager manager;
|
||||||
|
public OverlayButton viewButton = new OverlayButton();
|
||||||
|
public LinkedList<PresetElement> list = new LinkedList<>();
|
||||||
|
|
||||||
|
private final FontRenderer font = Minecraft.getMinecraft().fontRenderer;
|
||||||
|
|
||||||
|
public OverlayKeyPresetViewer(KeyPresetManager manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
|
||||||
|
manager.keys.forEach((key) -> {
|
||||||
|
PresetElement element = new PresetElement(key);
|
||||||
|
list.add(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui(int startX, int startY, int endX, int endY) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
this.width = endX - startX;
|
||||||
|
this.height = endY - startY;
|
||||||
|
scroll.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, int wheel) {
|
||||||
|
this.mouseX = mouseX;
|
||||||
|
this.mouseY = mouseY;
|
||||||
|
boolean aboveButton = viewButton.isMouseAbove(mouseX, mouseY);
|
||||||
|
boolean aboveOverlay = isMouseAbove(mouseX, mouseY);
|
||||||
|
|
||||||
|
if (aboveButton)
|
||||||
|
showOverlay = true;
|
||||||
|
|
||||||
|
if (showOverlay) {
|
||||||
|
drawOverlay(wheel);
|
||||||
|
|
||||||
|
if (!aboveOverlay && !aboveButton)
|
||||||
|
showOverlay = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
viewButton.drawButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawOverlay(int wheel) {
|
||||||
|
scroll.update(wheel);
|
||||||
|
|
||||||
|
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||||
|
GuiUtil.drawGradientRect(startX, startY, endX, endY, 0x88000000, 0x88303030);
|
||||||
|
if (scroll.maxScroll > 0)
|
||||||
|
scroll.drawBar();
|
||||||
|
|
||||||
|
GuiUtil.setScissorClip(startX, startY, scroll.maxScroll > 0 ? width - scroll.barWidth : width, height);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef((startX + 2), startY + yStartSpacing - scroll.scrollY, 0);
|
||||||
|
|
||||||
|
for (int i = 0, height = 0; i < list.size(); i++) {
|
||||||
|
PresetElement element = list.get(i);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
GL11.glTranslatef(0, Math.round(height / scale), 0);
|
||||||
|
element.drawDescription();
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
element.drawBox(height);
|
||||||
|
height += element.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
if (!showOverlay)
|
||||||
|
return;
|
||||||
|
|
||||||
|
list.forEach((element) -> {
|
||||||
|
if (element.isEditing)
|
||||||
|
element.keyTyped(i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
if (!showOverlay)
|
||||||
|
return;
|
||||||
|
|
||||||
|
list.forEach((element) -> {
|
||||||
|
if (!element.isMouseAboveBox(mouseX, mouseY)) {
|
||||||
|
if (element.isEditing)
|
||||||
|
element.cancelEdit();
|
||||||
|
} else
|
||||||
|
element.boxClicked(button);
|
||||||
|
|
||||||
|
if (element.isMouseAboveReset(mouseX, mouseY) && !element.key.isDefault()) {
|
||||||
|
element.key.defaultState.writeTo(element.key.currentState);
|
||||||
|
manager.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
if (scroll.isMouseDragging)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth() {
|
||||||
|
return (int) (width / scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Scrollable {
|
||||||
|
private float scrollY, targetScrollY, maxScroll;
|
||||||
|
private int totalHeight, scrollbarHeight, barWidth = 2;
|
||||||
|
private float heightFactor, scrollFactor;
|
||||||
|
|
||||||
|
private boolean isMouseDragging;
|
||||||
|
private int startDragY;
|
||||||
|
|
||||||
|
public Scrollable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
totalHeight = 0;
|
||||||
|
for (PresetElement element : list)
|
||||||
|
totalHeight += element.getHeight();
|
||||||
|
|
||||||
|
totalHeight -= yStartSpacing;
|
||||||
|
scroll.maxScroll = Math.max(0, totalHeight - height);
|
||||||
|
|
||||||
|
heightFactor = height / totalHeight;
|
||||||
|
scrollbarHeight = Math.max((int) (height * heightFactor), 20);
|
||||||
|
scrollFactor = (height - yStartSpacing - scrollbarHeight) / maxScroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(int wheel) {
|
||||||
|
if (wheel != 0 && isMouseAbove(mouseX, mouseY))
|
||||||
|
targetScrollY = ValueUtil.clamp(targetScrollY - wheel / 15, 0, maxScroll);
|
||||||
|
|
||||||
|
|
||||||
|
if (Mouse.isButtonDown(0)) {
|
||||||
|
if (!isMouseDragging && isMouseAboveBar(mouseX, mouseY)) {
|
||||||
|
isMouseDragging = true;
|
||||||
|
startDragY = (int) (mouseY - scrollY * scrollFactor);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
isMouseDragging = false;
|
||||||
|
|
||||||
|
if (isMouseDragging)
|
||||||
|
scrollY = targetScrollY = ValueUtil.clamp((mouseY - startDragY) / scrollFactor, 0, maxScroll);
|
||||||
|
|
||||||
|
if (scrollY != targetScrollY) {
|
||||||
|
scrollY = ValueUtil.lerp(scrollY, targetScrollY, 0.1f);
|
||||||
|
|
||||||
|
if (Math.abs(scrollY - targetScrollY) < 0.001) // Snap to exact target value
|
||||||
|
scrollY = targetScrollY;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollY = ValueUtil.clamp(scrollY, 0, maxScroll);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawBar() {
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(endX - barWidth - 2, startY + yStartSpacing + scrollY * scrollFactor, 0);
|
||||||
|
GuiUtil.drawRectD(0, 0, barWidth, scrollbarHeight, (isMouseAboveBar(mouseX, mouseY) || isMouseDragging) ? 0xffbababa : 0xff767676);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAboveBar(int mouseX, int mouseY) {
|
||||||
|
int barX = endX - barWidth - 2;
|
||||||
|
int barY = (int) (startY + yStartSpacing + scrollY * scrollFactor);
|
||||||
|
|
||||||
|
return mouseX >= barX && mouseX < barX + barWidth && mouseY >= barY && mouseY < barY + scrollbarHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PresetElement {
|
||||||
|
public KeyPreset key;
|
||||||
|
public boolean isEditing;
|
||||||
|
public float boxScreenX, boxScreenY;
|
||||||
|
|
||||||
|
public KeyPreset.KeyState newState = new KeyPreset.KeyState();
|
||||||
|
|
||||||
|
public PresetElement(KeyPreset key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawDescription() {
|
||||||
|
String name = String.format("> %s", key.name);
|
||||||
|
font.drawString(name, 0, 0, 0xffffff);
|
||||||
|
|
||||||
|
if (!key.shouldConflict)
|
||||||
|
font.drawString("(Conflict-free)", font.getStringWidth(name) + 5, 0, 0xface40);
|
||||||
|
|
||||||
|
String description = String.format("- %s", key.description);
|
||||||
|
font.drawSplitString(description, 9, font.FONT_HEIGHT, getMaxStringWidth() - 9, 0x888888);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawBox(int offsetY) {
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
//Box texture
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glColor4f(1, 1, 1, 1);
|
||||||
|
float boxScaleX = 1.75f;
|
||||||
|
float boxWidth = 32 * boxScaleX;
|
||||||
|
boxScreenX = getMaxStringWidth() * scale + 8; //remove scaling from maxStringWidth
|
||||||
|
GL11.glScalef(boxScaleX, 1, 0);
|
||||||
|
|
||||||
|
if (isEditing)
|
||||||
|
new Color(0x4772b3, 1).glColor();
|
||||||
|
else if (isMouseAboveBox(mouseX, mouseY))
|
||||||
|
new Color(0x656565, 1).glColor();
|
||||||
|
else
|
||||||
|
new Color(0x545454, 1).glColor();
|
||||||
|
GuiUtil.drawTexturedModalRect(boxScreenX / boxScaleX, boxScreenY = offsetY - 5, 32, 20, 0, 492);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
//Reset box
|
||||||
|
boolean isDefault = key.isDefault();
|
||||||
|
float resetWidth = 10;
|
||||||
|
float resetScreenX = boxScreenX + boxWidth + 2;
|
||||||
|
|
||||||
|
if (isMouseAboveReset(mouseX, mouseY) && !isDefault)
|
||||||
|
new Color(0x656565, 1).glColor();
|
||||||
|
else
|
||||||
|
new Color(0x545454, 1).glColor();
|
||||||
|
GuiUtil.drawTexturedModalRect(resetScreenX, boxScreenY, 10, 20, 33, 492);
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
//Key name
|
||||||
|
String name = getBoxKeyName();
|
||||||
|
float nameWidth = font.getStringWidth(name);
|
||||||
|
float nameScale = scale;
|
||||||
|
float nameBoxRatio = nameWidth * scale / boxWidth;
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
if (nameBoxRatio > 0.9) {
|
||||||
|
nameScale /= nameWidth / boxWidth / 1.2f;
|
||||||
|
GL11.glTranslatef(0, nameBoxRatio * 0.5f, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
float nameX = boxScreenX + boxWidth / 2 - (nameWidth / 2 * nameScale);
|
||||||
|
float nameY = offsetY + 11.5f - (font.FONT_HEIGHT / 2);
|
||||||
|
GL11.glScalef(nameScale, nameScale, 1);
|
||||||
|
GL11.glTranslatef(nameX / nameScale, nameY / nameScale, 1);
|
||||||
|
font.drawStringWithShadow(name, 0, 0, conflicts() ? 0xff5555 : 0xffffffff);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
//Reset letter
|
||||||
|
char letter = 'X';
|
||||||
|
float letterX = resetScreenX + (resetWidth / 2) - (font.getCharWidth(letter) / 2 * scale) + 0.25f;
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
GL11.glTranslatef(letterX / scale, nameY / scale, 1);
|
||||||
|
font.drawStringWithShadow(String.valueOf(letter), 0, 0, isDefault ? 0xff8a8a8a : 0xffffffff);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
}
|
||||||
|
|
||||||
|
public void boxClicked(int button) {
|
||||||
|
if (isEditing)
|
||||||
|
setKey(-100 + button);
|
||||||
|
else if (button == 0)
|
||||||
|
isEditing = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(int typedKey) {
|
||||||
|
if (typedKey == 1) {
|
||||||
|
setKey(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
newState.setState(newState.keyCode, KeyPreset.isCtrlKeyDown(), KeyPreset.isAltKeyDown(), KeyPreset.isShiftKeyDown());
|
||||||
|
if (KeyPreset.isNotCtrlAltShift(typedKey))
|
||||||
|
setKey(typedKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(int keyCode) {
|
||||||
|
if (keyCode == 0)
|
||||||
|
newState.clear();
|
||||||
|
|
||||||
|
newState.keyCode = keyCode;
|
||||||
|
newState.writeTo(key.currentState);
|
||||||
|
cancelEdit();
|
||||||
|
manager.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancelEdit() {
|
||||||
|
newState.clear();
|
||||||
|
isEditing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean conflicts() {
|
||||||
|
return list.stream().anyMatch(element -> key.shouldConflict && element.key.shouldConflict && element.key != this.key && element.key.equals(this.key));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBoxKeyName() {
|
||||||
|
if (isEditing) {
|
||||||
|
String modifiers = "";
|
||||||
|
if (KeyPreset.isCtrlKeyDown())
|
||||||
|
modifiers += "CTRL ";
|
||||||
|
if (KeyPreset.isAltKeyDown())
|
||||||
|
modifiers += "ALT ";
|
||||||
|
if (KeyPreset.isShiftKeyDown())
|
||||||
|
modifiers += "SHIFT ";
|
||||||
|
|
||||||
|
return !modifiers.isEmpty() ? modifiers : "Press a key";
|
||||||
|
}
|
||||||
|
|
||||||
|
return key.currentState.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAboveBox(int mouseX, int mouseY) {
|
||||||
|
mouseX -= startX + 2;
|
||||||
|
mouseY -= startY + 5 - scroll.scrollY;
|
||||||
|
|
||||||
|
float boxScaleX = 1.75f;
|
||||||
|
float screenY = boxScreenY + 10;
|
||||||
|
|
||||||
|
return mouseX >= boxScreenX && mouseX < boxScreenX + 32 * boxScaleX && mouseY >= screenY && mouseY < screenY + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAboveReset(int mouseX, int mouseY) {
|
||||||
|
mouseX -= startX + 2;
|
||||||
|
mouseY -= startY + 5 - scroll.scrollY;
|
||||||
|
|
||||||
|
float boxScaleX = 1.75f;
|
||||||
|
float resetWidth = 10, boxWidth = 32 * boxScaleX;
|
||||||
|
float screenX = boxScreenX + boxWidth + 2;
|
||||||
|
float screenY = boxScreenY + 10;
|
||||||
|
|
||||||
|
return mouseX >= screenX && mouseX < screenX + resetWidth && mouseY >= screenY && mouseY < screenY + 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight() {
|
||||||
|
List<String> wrappedDescription = font.listFormattedStringToWidth(String.format("- %s", key.description), getMaxStringWidth());
|
||||||
|
|
||||||
|
int nameHeight = font.FONT_HEIGHT;
|
||||||
|
int translations = font.FONT_HEIGHT;
|
||||||
|
int descriptionHeight = wrappedDescription.size() * (font.FONT_HEIGHT);
|
||||||
|
|
||||||
|
return Math.round((nameHeight + descriptionHeight + translations) * scale) + elementSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStringWidth() {
|
||||||
|
return (int) (getWidth() * 2.5f / 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OverlayButton {
|
||||||
|
public int startX, startY, endX, width, height;
|
||||||
|
public int textureWidth = 252, textureHeight = 109;
|
||||||
|
public float scale = 0.25f;
|
||||||
|
|
||||||
|
public OverlayButton() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui(int endX, int startY) {
|
||||||
|
this.endX = endX;
|
||||||
|
this.startY = startY;
|
||||||
|
|
||||||
|
startX = (int) (endX - textureWidth * scale / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawButton() {
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(TEXTURE);
|
||||||
|
|
||||||
|
double screenX = startX / scale, screenY = startY / scale;
|
||||||
|
int oldMinFilter = GL11.glGetTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER);
|
||||||
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
float color = 0.55f;
|
||||||
|
GL11.glColor4f(color, color, color, 1);
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
GuiUtil.drawTexturedModalRect(screenX, screenY, textureWidth, textureHeight, 0, 0);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, oldMinFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
return mouseX >= startX && mouseX < startX + textureWidth * scale / 2 && mouseY >= startY - 4 && mouseY < startY + textureHeight * scale / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.GraphEditorKeyPresets;
|
||||||
|
|
||||||
|
public class ViewportGraphEditor {
|
||||||
|
public Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
public GuiNPCInterface parent;
|
||||||
|
|
||||||
|
public int startX, startY, endX, endY, width, height;
|
||||||
|
|
||||||
|
public GraphEditorKeyPresets keys = new GraphEditorKeyPresets();
|
||||||
|
public OverlayKeyPresetViewer presetOverlay = new OverlayKeyPresetViewer(keys);
|
||||||
|
|
||||||
|
public Grid grid = new Grid(this);
|
||||||
|
|
||||||
|
public ViewportGraphEditor(GuiNPCInterface parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui(int startX, int startY, int endX, int endY) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
this.width = endX - this.startX;
|
||||||
|
this.height = endY - this.startY;
|
||||||
|
|
||||||
|
grid.init(this.startX, this.startY, endX, endY);
|
||||||
|
presetOverlay.initGui(endX - (width / 2) - 37, startY + (height / 4), endX, endY);
|
||||||
|
presetOverlay.viewButton.initGui(endX + 1, endY + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateScreen() {
|
||||||
|
keys.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks, int wheel) {
|
||||||
|
grid.draw(mouseX, mouseY, partialTicks, wheel);
|
||||||
|
presetOverlay.draw(mouseX, mouseY, wheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
grid.mouseClicked(mouseX, mouseY, button);
|
||||||
|
presetOverlay.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
grid.keyTyped(c, i);
|
||||||
|
presetOverlay.keyTyped(c, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWithin(int mouseX, int mouseY) {
|
||||||
|
if (parent.hasSubGui())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return mouseX >= startX && mouseX <= startX + width && mouseY >= startY && mouseY <= startY + height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawString(String text, int x, int y, int color) {
|
||||||
|
parent.drawCenteredString(getFontRenderer(), text, x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FontRenderer getFontRenderer() {
|
||||||
|
return parent.getFontRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
if (Cursors.currentCursor() != null)
|
||||||
|
Cursors.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.keys;
|
||||||
|
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
public class GraphEditorKeyPresets extends KeyPresetManager {
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
//Grid controls
|
||||||
|
public final KeyPreset PAN_GRID = add("Pan Grid").setDefaultState(KeyPreset.RIGHT_MOUSE, false, false, false).setDescription("Holding pans the grid with mouse cursor");
|
||||||
|
public final KeyPreset LOCK_X = add("Lock X Axis").setDefaultState(Keyboard.KEY_X, false, false, false).setDescription("Holding locks the X axis while zooming or panning").shouldConflict(false);
|
||||||
|
public final KeyPreset LOCK_Y = add("Lock Y Axis").setDefaultState(Keyboard.KEY_Y, false, false, false).setDescription("Holding locks the Y axis while zooming or panning").shouldConflict(false);
|
||||||
|
public final KeyPreset RESET_GRID = add("Reset Grid").setDefaultState(Keyboard.KEY_R, false, false, false).setDescription("Resets the grid's XY scale and translation to the origins");
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
//Grid Point controls
|
||||||
|
public final KeyPreset SELECT_POINT = add("Select Point").setDefaultState(KeyPreset.LEFT_MOUSE, false, false, false).setDescription("Select point under cursor");
|
||||||
|
public final KeyPreset ADD_POINT = add("Add Point").setDefaultState(Keyboard.KEY_Z, false, false, false).setDescription("Add a new point at the play-head's X");
|
||||||
|
public final KeyPreset DELETE_POINT = add("Delete Point").setDefaultState(Keyboard.KEY_X, true, false, false).setDescription("Delete selected point");
|
||||||
|
public final KeyPreset FREE_TRANSFORM = add("Free Transform").setDefaultState(Keyboard.KEY_G, false, false, false).setDescription("Freely transform the selected point with the mouse").markDone(this);
|
||||||
|
|
||||||
|
public GraphEditorKeyPresets() {
|
||||||
|
super("graph_editor");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,249 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.keys;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.settings.GameSettings;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class KeyPreset {
|
||||||
|
/**
|
||||||
|
* @field SINGLE_PRESS => on releasing before 5 ticks press time
|
||||||
|
* @field PRESS_RELEASE => on pressing and releasing
|
||||||
|
*/
|
||||||
|
public static final int PRESS = 0, HOLD = 1, RELEASE = 2, SINGLE_PRESS = 3, PRESS_RELEASE = 4;
|
||||||
|
|
||||||
|
public KeyState defaultState = new KeyState();
|
||||||
|
public KeyState currentState = new KeyState();
|
||||||
|
|
||||||
|
public String name, description;
|
||||||
|
public boolean shouldConflict = true;
|
||||||
|
public Consumer<Integer> task;
|
||||||
|
|
||||||
|
public int pressTime;
|
||||||
|
public boolean isDown;
|
||||||
|
|
||||||
|
|
||||||
|
public KeyPreset(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset setDefaultState(int keyCode, boolean hasCtrl, boolean hasAlt, boolean hasShift) {
|
||||||
|
defaultState.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||||
|
currentState.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset setTask(Consumer<Integer> task) {
|
||||||
|
this.task = task;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset shouldConflict(boolean shouldConflict) {
|
||||||
|
this.shouldConflict = shouldConflict;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
int keyCode = keyCode();
|
||||||
|
if (keyCode == -1 || keyCode == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
boolean isDown = isMouseKey() ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
|
||||||
|
isDown = isDown && (hasCtrl() ? isCtrlKeyDown() : true) && (hasAlt() ? isAltKeyDown() : true && (hasShift() ? isShiftKeyDown() : true));
|
||||||
|
|
||||||
|
setDown(isDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDown(boolean down) {
|
||||||
|
if (down && !isDown)
|
||||||
|
onAction(PRESS, PRESS_RELEASE);
|
||||||
|
|
||||||
|
if (!down && isDown) {
|
||||||
|
if (pressTime <= 5)
|
||||||
|
onAction(SINGLE_PRESS);
|
||||||
|
|
||||||
|
onAction(RELEASE, PRESS_RELEASE);
|
||||||
|
pressTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDown || down) //to fire in both press & release
|
||||||
|
onAction(HOLD);
|
||||||
|
|
||||||
|
if (isDown)
|
||||||
|
pressTime++;
|
||||||
|
|
||||||
|
this.isDown = down;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset onAction(int... pressTypes) {
|
||||||
|
if (task != null) {
|
||||||
|
for (int pressType : pressTypes)
|
||||||
|
this.task.accept(pressType);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefault() {
|
||||||
|
return currentState.equals(defaultState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseKey() {
|
||||||
|
return keyCode() < -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int keyCode() {
|
||||||
|
return currentState.keyCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCtrl() {
|
||||||
|
return currentState.hasCtrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAlt() {
|
||||||
|
return currentState.hasAlt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasShift() {
|
||||||
|
return currentState.hasShift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKeyName() {
|
||||||
|
return currentState.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
currentState.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//call on the last key added, to load saved presets
|
||||||
|
public KeyPreset markDone(KeyPresetManager manager) {
|
||||||
|
manager.load();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeToNbt(NBTTagCompound c) {
|
||||||
|
c.setTag(name, currentState.writeToNbt());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNbt(NBTTagCompound compound) {
|
||||||
|
currentState.readFromNbt(compound.getCompoundTag(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object preset) {
|
||||||
|
if (preset == this)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (preset instanceof KeyPreset) {
|
||||||
|
KeyPreset key = (KeyPreset) preset;
|
||||||
|
return key.currentState.equals(currentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static class KeyState {
|
||||||
|
public int keyCode = -1;
|
||||||
|
public boolean hasCtrl, hasAlt, hasShift;
|
||||||
|
|
||||||
|
public void setState(int keyCode, boolean hasCtrl, boolean hasAlt, boolean hasShift) {
|
||||||
|
this.keyCode = keyCode;
|
||||||
|
this.hasCtrl = hasCtrl;
|
||||||
|
this.hasAlt = hasAlt;
|
||||||
|
this.hasShift = hasShift;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFrom(KeyState state) {
|
||||||
|
keyCode = state.keyCode;
|
||||||
|
hasCtrl = state.hasCtrl;
|
||||||
|
hasShift = state.hasShift;
|
||||||
|
hasAlt = state.hasAlt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeTo(KeyState state) {
|
||||||
|
state.setState(keyCode, hasCtrl, hasAlt, hasShift);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasState() {
|
||||||
|
return keyCode != -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
this.keyCode = -1;
|
||||||
|
hasCtrl = hasAlt = hasShift = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object preset) {
|
||||||
|
if (preset == this)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (preset instanceof KeyState) {
|
||||||
|
KeyState state = (KeyState) preset;
|
||||||
|
return state.keyCode == keyCode && state.hasCtrl == hasCtrl && state.hasAlt == hasAlt && state.hasShift == hasShift;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound writeToNbt() {
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
compound.setInteger("keyCode", keyCode);
|
||||||
|
compound.setBoolean("hasCtrl", hasCtrl);
|
||||||
|
compound.setBoolean("hasShift", hasShift);
|
||||||
|
compound.setBoolean("hasAlt", hasAlt);
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNbt(NBTTagCompound compound) {
|
||||||
|
this.keyCode = compound.getInteger("keyCode");
|
||||||
|
this.hasCtrl = compound.getBoolean("hasCtrl");
|
||||||
|
this.hasShift = compound.getBoolean("hasShift");
|
||||||
|
this.hasAlt = compound.getBoolean("hasAlt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
int code = keyCode;
|
||||||
|
String name = "";
|
||||||
|
|
||||||
|
if (code == LEFT_MOUSE)
|
||||||
|
name = "Left Mouse";
|
||||||
|
else if (code == RIGHT_MOUSE)
|
||||||
|
name = "Right Mouse";
|
||||||
|
else if (code == MIDDLE_MOUSE)
|
||||||
|
name = "Middle Mouse";
|
||||||
|
else {
|
||||||
|
name = code == -1 ? "" : GameSettings.getKeyDisplayString(code);
|
||||||
|
if (name.contains("Button"))
|
||||||
|
name = name.replace("Button", "Mouse");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (hasCtrl ? "CTRL " : "") + (hasAlt ? "ALT " : "") + (hasShift ? "SHIFT " : "") + name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final int LEFT_MOUSE = -100, RIGHT_MOUSE = -99, MIDDLE_MOUSE = -98, MOUSE_4 = -97, MOUSE_5 = -96;
|
||||||
|
|
||||||
|
public static boolean isCtrlKeyDown() {
|
||||||
|
return Minecraft.isRunningOnMac ? Keyboard.isKeyDown(219) || Keyboard.isKeyDown(220) : Keyboard.isKeyDown(29) || Keyboard.isKeyDown(157);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAltKeyDown() {
|
||||||
|
return Keyboard.isKeyDown(56) || Keyboard.isKeyDown(184);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isShiftKeyDown() {
|
||||||
|
return Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNotCtrlAltShift(int key) {
|
||||||
|
return key != 219 && key != 220 && key != 29 && key != 157 && key != 42 && key != 54 && key != 56 && key != 184;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.keys;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import noppes.npcs.CustomNpcs;
|
||||||
|
import noppes.npcs.LogWriter;
|
||||||
|
import noppes.npcs.util.NBTJsonUtil;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class KeyPresetManager {
|
||||||
|
public List<KeyPreset> keys = new ArrayList<>();
|
||||||
|
public String fileName;
|
||||||
|
|
||||||
|
public KeyPresetManager(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyPreset add(String name) {
|
||||||
|
KeyPreset preset = new KeyPreset(name);
|
||||||
|
keys.add(preset);
|
||||||
|
return preset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
for (KeyPreset key : keys)
|
||||||
|
key.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
try {
|
||||||
|
File dir = getDir();
|
||||||
|
File file = new File(dir, fileName + ".json");
|
||||||
|
if (!file.exists())
|
||||||
|
return;
|
||||||
|
|
||||||
|
NBTTagCompound compound = NBTJsonUtil.LoadFile(file);
|
||||||
|
for (KeyPreset key : keys)
|
||||||
|
key.readFromNbt(compound);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogWriter.except(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
try {
|
||||||
|
File dir = getDir();
|
||||||
|
String filename = fileName + ".json";
|
||||||
|
|
||||||
|
File newFile = new File(dir, filename + "_new");
|
||||||
|
File originalFile = new File(dir, filename);
|
||||||
|
|
||||||
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
|
for (KeyPreset key : keys)
|
||||||
|
key.writeToNbt(compound);
|
||||||
|
|
||||||
|
NBTJsonUtil.SaveFile(newFile, compound);
|
||||||
|
|
||||||
|
if (originalFile.exists())
|
||||||
|
originalFile.delete();
|
||||||
|
|
||||||
|
newFile.renameTo(originalFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LogWriter.except(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDir() {
|
||||||
|
File dir = new File(CustomNpcs.Dir, "keypresets");
|
||||||
|
if (!dir.exists())
|
||||||
|
dir.mkdir();
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.panel;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||||
|
import noppes.npcs.client.gui.util.animation.GridPointManager;
|
||||||
|
import noppes.npcs.client.gui.util.animation.OverlayKeyPresetViewer;
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
public class PanelActiveFrame {
|
||||||
|
public AnimationGraphEditor graph;
|
||||||
|
|
||||||
|
public int startX, startY, endX, endY, width, height;
|
||||||
|
public float scale = 0.6f;
|
||||||
|
|
||||||
|
public PanelTextBox frame = new PanelTextBox() {
|
||||||
|
public void finishEdit(byte operation) {
|
||||||
|
super.finishEdit(operation);
|
||||||
|
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||||
|
if (p != null) {
|
||||||
|
p.setX(text.getDouble());
|
||||||
|
p.updateKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.setDoublesOnly(0, 0, 9999);
|
||||||
|
|
||||||
|
public PanelTextBox value = new PanelTextBox() {
|
||||||
|
public void finishEdit(byte operation) {
|
||||||
|
super.finishEdit(operation);
|
||||||
|
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||||
|
if (p != null)
|
||||||
|
p.setY(-text.getDouble());
|
||||||
|
}
|
||||||
|
}.setDoublesOnly(0, -9999, 9999);
|
||||||
|
|
||||||
|
public PanelActiveFrame(AnimationGraphEditor graph) {
|
||||||
|
this.graph = graph;
|
||||||
|
frame.text.width = value.text.width = 70;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initGui(int startX, int startY, int endX, int endY) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
this.width = endX - startX;
|
||||||
|
this.height = endY - startY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
frame.type(c, i);
|
||||||
|
value.type(c, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
frame.click(mouseX - startX, mouseY - startY, button);
|
||||||
|
value.click(mouseX - startX, mouseY - startY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int wheel) {
|
||||||
|
int mouseX = graph.parent.mouseX, mouseY = graph.parent.mouseY;
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(startX, startY + 1, 0);
|
||||||
|
// GuiUtil.drawRectD(0, 0, width - 1, height, 0xff3d3d3d);
|
||||||
|
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
new Color(0X2D2D2D,0.75F).glColor();
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(OverlayKeyPresetViewer.TEXTURE);
|
||||||
|
GuiUtil.drawTexturedModalRect(0, -38, 88, 77, 44, 435);
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glRotatef(-90,0,0,1);
|
||||||
|
graph.getFontRenderer().drawString("Active frame", -62, -14, 0xdddddd);
|
||||||
|
GuiUtil.drawHorizontalLine(-6,-62,-2,0xffdddddd);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
// GL11.glTranslatef(0, 17, 0);
|
||||||
|
graph.getFontRenderer().drawString("Easing", 9, 3, 0xb1b1b1);
|
||||||
|
GL11.glTranslatef(0, 17, 0);
|
||||||
|
graph.getFontRenderer().drawString("-Type", 9, 0, 0xb1b1b1);
|
||||||
|
GL11.glTranslatef(0, 18, 0);
|
||||||
|
graph.getFontRenderer().drawString("Frame", 9, 0, 0xb1b1b1);
|
||||||
|
|
||||||
|
GL11.glTranslatef(0, 15, 0);
|
||||||
|
graph.getFontRenderer().drawString("Value", 9, 0, 0xb1b1b1);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
GridPointManager.Point p = graph.pointManager.selectedPoint;
|
||||||
|
if (p != null) {
|
||||||
|
if (!frame.isEditing())
|
||||||
|
frame.text.setText(ValueUtil.format(p.worldX));
|
||||||
|
if (!value.isEditing())
|
||||||
|
value.text.setText(ValueUtil.format(-p.worldY));
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.screenX = 29; //remove scaling from maxStringWidth
|
||||||
|
frame.screenY = 11;
|
||||||
|
frame.boxScaleX = 1.2f;
|
||||||
|
frame.textScale = scale;
|
||||||
|
|
||||||
|
boolean isAboveFrame = frame.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||||
|
frame.boxColor = new Color(frame.isEditing() ? 0x111111 : isAboveFrame ? 0x797979 : 0x545454);
|
||||||
|
frame.draw(mouseX - startX,mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||||
|
|
||||||
|
value.screenX = 29; //remove scaling from maxStringWidth
|
||||||
|
value.screenY = 20;
|
||||||
|
value.boxScaleX = 1.2f;
|
||||||
|
value.textScale = scale;
|
||||||
|
boolean isAboveValue = value.isMouseAbove(mouseX - startX, mouseY - startY);
|
||||||
|
value.boxColor = new Color(value.isEditing() ? 0x111111 : isAboveValue ? 0x797979 : 0x545454);
|
||||||
|
value.draw(mouseX - startX, mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.panel;
|
||||||
|
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.AnimationGraphEditor;
|
||||||
|
import noppes.npcs.client.gui.util.animation.GridPointManager;
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
import noppes.npcs.constants.animation.EnumFrameType;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PanelFrameType {
|
||||||
|
public AnimationGraphEditor graph;
|
||||||
|
|
||||||
|
public int startX, startY, endX, endY, width, height;
|
||||||
|
public float scale = 0.6f;
|
||||||
|
public int elementHeight = 11, elementSpacing = 2;
|
||||||
|
|
||||||
|
public LinkedList<Element> list = new LinkedList<>();
|
||||||
|
public Element selectedElement;
|
||||||
|
public List<EnumFrameType> highlightedTypes = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
|
public PanelFrameType(AnimationGraphEditor graph) {
|
||||||
|
this.graph = graph;
|
||||||
|
|
||||||
|
for (EnumFrameType type : EnumFrameType.values())
|
||||||
|
list.add(new Element(type));
|
||||||
|
|
||||||
|
selectedElement = list.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTypeValues(double playheadX) {
|
||||||
|
list.forEach(e -> {
|
||||||
|
String value = "0";
|
||||||
|
GridPointManager.Point onHead = graph.pointManager.getPoint(e.type, playheadX);
|
||||||
|
if (onHead != null)
|
||||||
|
value = ValueUtil.format(onHead.worldY != 0 ? -onHead.worldY : 0);
|
||||||
|
else {
|
||||||
|
GridPointManager.Point beforeHead = graph.pointManager.getPrevious(e.type, playheadX);
|
||||||
|
GridPointManager.Point afterHead = graph.pointManager.getNext(e.type, playheadX);
|
||||||
|
if (beforeHead != null && afterHead != null) {
|
||||||
|
double easedValue = graph.pointManager.getValueBetweenPointsAt(beforeHead, afterHead, playheadX);
|
||||||
|
value = ValueUtil.format(easedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e.box.text.setText(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void initGui(int startX, int startY, int endX, int endY) {
|
||||||
|
this.startX = startX;
|
||||||
|
this.startY = startY;
|
||||||
|
this.endX = endX;
|
||||||
|
this.endY = endY;
|
||||||
|
this.width = endX - startX;
|
||||||
|
this.height = endY - startY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int wheel) {
|
||||||
|
GuiUtil.drawRectD(startX - 1, startY, endX, endY, 0xff1d1d1d);
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(startX, startY + 1, 0);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
Element element = list.get(i);
|
||||||
|
element.draw(i, wheel);
|
||||||
|
}
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void keyTyped(char c, int i) {
|
||||||
|
list.forEach((element) -> {
|
||||||
|
element.box.type(c, i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
list.forEach((element) -> {
|
||||||
|
if (element.isMouseAbove(mouseX, mouseY) && button == 0)
|
||||||
|
selectedElement = element;
|
||||||
|
|
||||||
|
element.box.click(mouseX - startX, mouseY - startY, button);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
return mouseX >= startX && mouseX < endX && mouseY >= startY && mouseY < endY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Element {
|
||||||
|
public EnumFrameType type;
|
||||||
|
public float elementStartY;
|
||||||
|
|
||||||
|
public PanelTextBox box = new PanelTextBox() {
|
||||||
|
public void finishEdit(byte operation) {
|
||||||
|
super.finishEdit(operation);
|
||||||
|
graph.pointManager.setSelectedPoint(graph.pointManager.addPoint(type, graph.pointManager.playhead.worldX, -text.getDouble()));
|
||||||
|
}
|
||||||
|
}.setDoublesOnly(0, -9999, 9999);
|
||||||
|
|
||||||
|
public Element(EnumFrameType key) {
|
||||||
|
this.type = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
mouseX -= startX;
|
||||||
|
mouseY -= startY;
|
||||||
|
|
||||||
|
return mouseX >= 0 && mouseX < box.screenX - 3 && mouseY >= elementStartY && mouseY < elementStartY + elementHeight + elementSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int index, int wheel) {
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
//Type names
|
||||||
|
elementStartY = index * (elementHeight + elementSpacing) / 1;
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glTranslatef(0, elementStartY, 0);
|
||||||
|
GuiUtil.drawRectD(0, 0, width - 1, elementHeight, 0xaa000000); //type black bg
|
||||||
|
|
||||||
|
boolean selected = selectedElement == this;
|
||||||
|
type.getColor().multiply(selected ? 1 : 0.5f).glColor();
|
||||||
|
GuiUtil.drawRectD(0, 0, 3, elementHeight); //type color
|
||||||
|
|
||||||
|
GL11.glScalef(scale, scale, 1);
|
||||||
|
GL11.glTranslatef(0, elementHeight / 2, 0);
|
||||||
|
String name = String.format("%s", type.toString());
|
||||||
|
int color = selected ? 0xd79520 : isMouseAbove(graph.grid.mouseX, graph.grid.mouseY) ? 0xffffff : 0x9a9a9a;
|
||||||
|
|
||||||
|
graph.getFontRenderer().drawString(name, 7, 0, color);
|
||||||
|
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
//Box
|
||||||
|
boolean isEditing = box.isEditing();
|
||||||
|
box.screenX = width / 1.25F * scale + 8; //remove scaling from maxStringWidth
|
||||||
|
box.screenY = elementStartY - 7.5f;
|
||||||
|
box.textScale = scale;
|
||||||
|
boolean isAboveFrame = box.isMouseAbove(graph.grid.mouseX - startX, graph.grid.mouseY - startY);
|
||||||
|
|
||||||
|
if (graph.pointManager.getPoint(type, graph.pointManager.playhead.worldX) != null)
|
||||||
|
box.boxColor = isEditing ? new Color(0x83752a).multiply(0.65f) : new Color(isAboveFrame ? 0xd1b727 : 0x83752a);
|
||||||
|
else
|
||||||
|
box.boxColor = isEditing ? new Color(0x467d2a).multiply(0.65f) : new Color(isAboveFrame ? 0x5fc729 : 0x467d2a);
|
||||||
|
|
||||||
|
box.draw(graph.grid.mouseX - startX, graph.grid.mouseY - startY, graph.mc.fontRenderer, wheel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package noppes.npcs.client.gui.util.animation.panel;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||||
|
import noppes.npcs.client.gui.util.GuiUtil;
|
||||||
|
import noppes.npcs.client.gui.util.animation.OverlayKeyPresetViewer;
|
||||||
|
import noppes.npcs.client.gui.util.animation.keys.KeyPreset;
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
public class PanelTextBox {
|
||||||
|
|
||||||
|
public int mouseX, mouseY;
|
||||||
|
public float screenX, screenY, textScreenX, textScale;
|
||||||
|
public float boxScaleX = 0.85f, boxScaleY = 0.85f;
|
||||||
|
public GuiNpcTextField text;
|
||||||
|
public Color boxColor;
|
||||||
|
|
||||||
|
private boolean isEditing;
|
||||||
|
|
||||||
|
private FontRenderer font;
|
||||||
|
|
||||||
|
public PanelTextBox() {
|
||||||
|
text = new GuiNpcTextField(0, null, 0, 0, 45, 10, "0");
|
||||||
|
text.setEnableBackgroundDrawing(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PanelTextBox setDoublesOnly(double def, double min, double max) {
|
||||||
|
text.setDoublesOnly();
|
||||||
|
text.setMinMaxDefaultDouble(min, max, def);
|
||||||
|
text.setFloatingPrecision(2);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY, FontRenderer font, int wheel) {
|
||||||
|
this.mouseX = mouseX;
|
||||||
|
this.mouseY = mouseY;
|
||||||
|
|
||||||
|
if (this.font == null)
|
||||||
|
this.font = font;
|
||||||
|
|
||||||
|
if (Mouse.isButtonDown(0) && isEditing && text.isFocused())
|
||||||
|
setCursorPositionToMouse(mouseX);
|
||||||
|
|
||||||
|
boolean mouseAbove = isMouseAbove(mouseX, mouseY);
|
||||||
|
if (mouseAbove && wheel != 0) {
|
||||||
|
if (text.isDouble()) {
|
||||||
|
double presets = KeyPreset.isAltKeyDown() ? 45 : KeyPreset.isCtrlKeyDown() ? 10 : KeyPreset.isShiftKeyDown() ? 0.1 : 1;
|
||||||
|
double value = text.getDouble() + Math.copySign(presets, wheel);
|
||||||
|
text.setDouble(value);
|
||||||
|
finishEdit(M_WHEEL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
//Box texture
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(OverlayKeyPresetViewer.TEXTURE);
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
float boxWidth = 32 * boxScaleX;
|
||||||
|
GL11.glScalef(boxScaleX, boxScaleY, 0);
|
||||||
|
|
||||||
|
//Box grey background
|
||||||
|
new Color(0x3d3d3d, 1).glColor();
|
||||||
|
// GuiUtil.drawTexturedModalRect(screenX / boxScaleX, screenY / boxScaleY, 32, 20, 0, 492);
|
||||||
|
|
||||||
|
//Box color
|
||||||
|
if (boxColor != null)
|
||||||
|
boxColor.glColor();
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
float s = 0.945f, s2 = 0.875f;
|
||||||
|
GL11.glScalef(s, s2, 0);
|
||||||
|
GuiUtil.drawTexturedModalRect(screenX / boxScaleX / s + 1, screenY / boxScaleY / s2 + 2.25f, 32, 20, 0, 492);
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
|
||||||
|
////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////
|
||||||
|
// Box text
|
||||||
|
float textWidth = font.getStringWidth(text.getText());
|
||||||
|
float textX = screenX + 2;
|
||||||
|
float centeredTextX = (screenX) + boxWidth / 2 - textWidth / 2 * textScale;
|
||||||
|
textScreenX = text.isFocused() || textWidth * textScale >= boxWidth ? textX : centeredTextX;
|
||||||
|
|
||||||
|
GL11.glPushMatrix();
|
||||||
|
GL11.glScalef(textScale, textScale, 1);
|
||||||
|
GL11.glTranslatef(textScreenX / textScale, (screenY + 10.5f) / textScale, 0);
|
||||||
|
text.drawTextBox();
|
||||||
|
GL11.glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMouseAbove(int mouseX, int mouseY) {
|
||||||
|
float screenY = (this.screenY + 9);
|
||||||
|
|
||||||
|
return mouseX >= screenX && mouseX < screenX + 32 * boxScaleX && mouseY >= screenY && mouseY < screenY + 10 * boxScaleY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCursorPositionToMouse(int mouseX) {
|
||||||
|
int relativeMX = (int) (mouseX - textScreenX);
|
||||||
|
int pos = relativeMX > 0 ? 1 : -1;
|
||||||
|
|
||||||
|
text.setCursorPosition(font.trimStringToWidth(text.getText(), (int) (relativeMX / textScale)).length() + text.lineScrollOffset + pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEditing() {
|
||||||
|
return isEditing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte ENTER_KEY = 0, CLICK_OUT = 1, M_WHEEL = 2;
|
||||||
|
|
||||||
|
public void finishEdit(byte operation) {
|
||||||
|
if (operation == M_WHEEL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
text.toDefaults();
|
||||||
|
text.setFocused(false);
|
||||||
|
isEditing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void type(char c, int i) {
|
||||||
|
if (!isEditing())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (i == 28) {
|
||||||
|
finishEdit(ENTER_KEY);
|
||||||
|
} else
|
||||||
|
text.textboxKeyTyped(c, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void click(int mouseX, int mouseY, int button) {
|
||||||
|
if (!isMouseAbove(mouseX, mouseY)) {
|
||||||
|
if (isEditing())
|
||||||
|
finishEdit(CLICK_OUT);
|
||||||
|
} else {
|
||||||
|
if (button == 0) {
|
||||||
|
text.setFocused(true);
|
||||||
|
text.setCursorPositionEnd();
|
||||||
|
isEditing = true;
|
||||||
|
} else if (button == 1) {
|
||||||
|
text.setText(text.isNumbersOnly() ? "0" : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package noppes.npcs.client.utils;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
public class Color {
|
||||||
|
public int color;
|
||||||
|
public float alpha;
|
||||||
|
|
||||||
|
public Color(int color) {
|
||||||
|
setColor(color, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color(int color, float alpha) {
|
||||||
|
setColor(color, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color(int red, int green, int blue, float alpha) {
|
||||||
|
setColor(red, green, blue, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int color, float alpha) {
|
||||||
|
this.color = color;
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int red, int green, int blue, float alpha) {
|
||||||
|
this.color = (red << 16) + (green << 8) + blue;
|
||||||
|
this.alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color lerpRGBA(Color color1, Color color2, float fraction) {
|
||||||
|
fraction = Math.min(fraction, 1f);
|
||||||
|
int red = (int) (color1.getRed() + ((color2.getRed() - color1.getRed()) * fraction));
|
||||||
|
int green = (int) (color1.getGreen() + ((color2.getGreen() - color1.getGreen()) * fraction));
|
||||||
|
int blue = (int) (color1.getBlue() + ((color2.getBlue() - color1.getBlue()) * fraction));
|
||||||
|
float newAlpha = color1.alpha + ((color2.alpha - color1.alpha) * fraction);
|
||||||
|
int newColor = (red << 16) + (green << 8) + blue;
|
||||||
|
return new Color(newColor, newAlpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color lerpRGBA(Color color2, float fraction) {
|
||||||
|
return Color.lerpRGBA(this, color2, fraction);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color multiply(float multi) {
|
||||||
|
if (multi == 1)
|
||||||
|
return this.clone();
|
||||||
|
|
||||||
|
int r = (int) ((getRed() * multi));
|
||||||
|
int g = (int) ((getGreen() * multi));
|
||||||
|
int b = (int) ((getBlue() * multi));
|
||||||
|
float a = alpha * multi;
|
||||||
|
return new Color((r << 16) + (g << 8) + b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public void glColor() {
|
||||||
|
GL11.glColor4f(getRedF(), getGreenF(), getBlueF(), alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound writeToNBT(NBTTagCompound compound, String name) {
|
||||||
|
compound.setInteger(name + "Color", color);
|
||||||
|
compound.setFloat(name + "Alpha", alpha);
|
||||||
|
|
||||||
|
return compound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readFromNBT(NBTTagCompound compound, String name) {
|
||||||
|
setColor(compound.getInteger(name + "Color"), compound.getFloat(name + "Alpha"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRed() {
|
||||||
|
return (color >> 16 & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getRedF() {
|
||||||
|
return (float) (color >> 16 & 0xFF) / 255f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getGreen() {
|
||||||
|
return (color >> 8 & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getGreenF() {
|
||||||
|
return (float) (color >> 8 & 0xFF) / 255f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBlue() {
|
||||||
|
return (color & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBlueF() {
|
||||||
|
return (float) (color & 0xFF) / 255f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getColor(int color) {
|
||||||
|
String str;
|
||||||
|
for (str = Integer.toHexString(color); str.length() < 6; str = "0" + str) {
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getColor(int color, float alpha) {
|
||||||
|
String str = getColor(color);
|
||||||
|
return str + " | " + (int) (alpha * 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color clone() {
|
||||||
|
return new Color(color, alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package noppes.npcs.constants.animation;
|
||||||
|
|
||||||
|
import noppes.npcs.client.utils.Color;
|
||||||
|
|
||||||
|
public enum EnumFrameType {
|
||||||
|
ROTATION_X(0xffff3352), ROTATION_Y(0xff8bdc00), ROTATION_Z(0xff2890ff), PIVOT_X(0xffff00), PIVOT_Y(0x00ffff), PIVOT_Z(0xff00ff);
|
||||||
|
|
||||||
|
public int color;
|
||||||
|
|
||||||
|
EnumFrameType(int color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return new Color(color, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,6 +54,14 @@ public class Animation implements IAnimation {
|
|||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasFrame(int index) {
|
||||||
|
return index >= 0 && index < frames.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFrame getFrame(int index) {
|
||||||
|
return hasFrame(index) ? frames.get(index) : null;
|
||||||
|
}
|
||||||
|
|
||||||
public IFrame currentFrame() {
|
public IFrame currentFrame() {
|
||||||
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
|
return currentFrame < frames.size() ? frames.get(currentFrame) : null;
|
||||||
}
|
}
|
||||||
@@ -76,12 +84,22 @@ public class Animation implements IAnimation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IAnimation addFrame(IFrame frame) {
|
public IAnimation addFrame(IFrame frame) {
|
||||||
this.frames.add((Frame) frame);
|
return addFrame((Frame) frame);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAnimation addFrame(int index, IFrame frame) {
|
public IAnimation addFrame(int index, IFrame frame) {
|
||||||
this.frames.add(index, (Frame) frame);
|
return addFrame(index, (Frame) frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAnimation addFrame(Frame frame) {
|
||||||
|
frame.setParent(this);
|
||||||
|
this.frames.add(frame);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IAnimation addFrame(int index, Frame frame) {
|
||||||
|
frame.setParent(this);
|
||||||
|
this.frames.add(index, frame);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +210,7 @@ public class Animation implements IAnimation {
|
|||||||
for (int i = 0; i < list.tagCount(); i++) {
|
for (int i = 0; i < list.tagCount(); i++) {
|
||||||
NBTTagCompound item = list.getCompoundTagAt(i);
|
NBTTagCompound item = list.getCompoundTagAt(i);
|
||||||
Frame frame = new Frame();
|
Frame frame = new Frame();
|
||||||
frame.parent = this;
|
frame.setParent(this);
|
||||||
frame.readFromNBT(item);
|
frame.readFromNBT(item);
|
||||||
frames.add(frame);
|
frames.add(frame);
|
||||||
}
|
}
|
||||||
@@ -230,6 +248,18 @@ public class Animation implements IAnimation {
|
|||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCurrentTick() {
|
||||||
|
int time = 0;
|
||||||
|
for (int i = 0; i < this.frames.size(); i++) {
|
||||||
|
if (i >= this.currentFrame) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
time += this.frames.get(i).getDuration();
|
||||||
|
}
|
||||||
|
time += this.currentFrameTime;
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean increaseTime() {
|
public boolean increaseTime() {
|
||||||
if (paused)
|
if (paused)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ import noppes.npcs.constants.EnumAnimationPart;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class Frame implements IFrame {
|
public class Frame implements IFrame {
|
||||||
public Animation parent;
|
private Animation parent;
|
||||||
public HashMap<EnumAnimationPart, FramePart> frameParts = new HashMap<>();
|
public HashMap<EnumAnimationPart, FramePart> frameParts = new HashMap<>();
|
||||||
public int duration = 0;
|
public int duration = 0;
|
||||||
|
|
||||||
@@ -36,16 +35,42 @@ public class Frame implements IFrame {
|
|||||||
this.customized = true;
|
this.customized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getStartTick() {
|
||||||
|
int time = 0;
|
||||||
|
for (int i = 0; i < parent.frames.size(); i++) {
|
||||||
|
Frame f = parent.frames.get(i);
|
||||||
|
if (f == this)
|
||||||
|
break;
|
||||||
|
|
||||||
|
time += f.getDuration();
|
||||||
|
}
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParent(Animation parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Animation getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
public HashMap<EnumAnimationPart, FramePart> getFrameMap() {
|
public HashMap<EnumAnimationPart, FramePart> getFrameMap() {
|
||||||
return frameParts;
|
return frameParts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPart(EnumAnimationPart key, FramePart frame) {
|
||||||
|
frame.setParent(parent);
|
||||||
|
frameParts.put(key, frame);
|
||||||
|
}
|
||||||
|
|
||||||
public IFramePart[] getParts() {
|
public IFramePart[] getParts() {
|
||||||
return frameParts.values().toArray(new IFramePart[0]);
|
return frameParts.values().toArray(new IFramePart[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IFrame addPart(IFramePart partConfig) {
|
public IFrame addPart(IFramePart partConfig) {
|
||||||
this.frameParts.put(((FramePart) partConfig).getPart(), (FramePart) partConfig);
|
((FramePart) partConfig).setParent(parent);
|
||||||
|
addPart(((FramePart) partConfig).getPart(), (FramePart) partConfig);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,6 +175,7 @@ public class Frame implements IFrame {
|
|||||||
for (int i = 0; i < list.tagCount(); i++) {
|
for (int i = 0; i < list.tagCount(); i++) {
|
||||||
NBTTagCompound item = list.getCompoundTagAt(i);
|
NBTTagCompound item = list.getCompoundTagAt(i);
|
||||||
FramePart framePart = new FramePart();
|
FramePart framePart = new FramePart();
|
||||||
|
framePart.setParent(parent);
|
||||||
framePart.readFromNBT(item);
|
framePart.readFromNBT(item);
|
||||||
if (!framePart.customized) {
|
if (!framePart.customized) {
|
||||||
framePart.smooth = this.smooth;
|
framePart.smooth = this.smooth;
|
||||||
@@ -184,7 +210,7 @@ public class Frame implements IFrame {
|
|||||||
Frame frame = new Frame(this.duration);
|
Frame frame = new Frame(this.duration);
|
||||||
HashMap<EnumAnimationPart, FramePart> frameParts = this.frameParts;
|
HashMap<EnumAnimationPart, FramePart> frameParts = this.frameParts;
|
||||||
for (Map.Entry<EnumAnimationPart, FramePart> entry : frameParts.entrySet()) {
|
for (Map.Entry<EnumAnimationPart, FramePart> entry : frameParts.entrySet()) {
|
||||||
frame.frameParts.put(entry.getKey(), entry.getValue().copy());
|
frame.addPart(entry.getKey(), entry.getValue().copy());
|
||||||
}
|
}
|
||||||
frame.parent = this.parent;
|
frame.parent = this.parent;
|
||||||
frame.duration = this.duration;
|
frame.duration = this.duration;
|
||||||
|
|||||||
@@ -6,13 +6,22 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import noppes.npcs.api.handler.data.IFramePart;
|
import noppes.npcs.api.handler.data.IFramePart;
|
||||||
import noppes.npcs.client.ClientEventHandler;
|
import noppes.npcs.client.ClientEventHandler;
|
||||||
import noppes.npcs.constants.EnumAnimationPart;
|
import noppes.npcs.constants.EnumAnimationPart;
|
||||||
|
import noppes.npcs.constants.animation.EnumFrameType;
|
||||||
|
import noppes.npcs.util.Ease;
|
||||||
|
import noppes.npcs.util.ValueUtil;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class FramePart implements IFramePart {
|
public class FramePart implements IFramePart {
|
||||||
|
|
||||||
public Animation parent;
|
public Animation parent;
|
||||||
public EnumAnimationPart part;
|
public EnumAnimationPart part;
|
||||||
public float[] rotation = {0, 0, 0};
|
public float[] rotation = {0, 0, 0};
|
||||||
public float[] pivot = {0, 0, 0};
|
public float[] pivot = {0, 0, 0};
|
||||||
|
|
||||||
|
public HashMap<EnumFrameType, Value> values = new HashMap<>();
|
||||||
|
|
||||||
boolean customized = false;
|
boolean customized = false;
|
||||||
|
|
||||||
public float speed = 1.0F;
|
public float speed = 1.0F;
|
||||||
@@ -32,6 +41,14 @@ public class FramePart implements IFramePart {
|
|||||||
this.part = part;
|
this.part = part;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setParent(Animation parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Animation getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
public EnumAnimationPart getPart() {
|
public EnumAnimationPart getPart() {
|
||||||
return part;
|
return part;
|
||||||
}
|
}
|
||||||
@@ -114,11 +131,27 @@ public class FramePart implements IFramePart {
|
|||||||
public void readFromNBT(NBTTagCompound compound) {
|
public void readFromNBT(NBTTagCompound compound) {
|
||||||
part = EnumAnimationPart.valueOf(compound.getString("Part"));
|
part = EnumAnimationPart.valueOf(compound.getString("Part"));
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (compound.hasKey("Rotation" + i)) {
|
||||||
rotation[i] = compound.getFloat("Rotation" + i);
|
rotation[i] = compound.getFloat("Rotation" + i);
|
||||||
|
addValue(EnumFrameType.values()[i], rotation[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if (compound.hasKey("Pivot" + i)) {
|
||||||
pivot[i] = compound.getFloat("Pivot" + i);
|
pivot[i] = compound.getFloat("Pivot" + i);
|
||||||
|
addValue(EnumFrameType.values()[3 + i], rotation[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compound.hasKey("Rotation0")) {
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
rotation[i] = compound.getFloat("Rotation" + i);
|
||||||
|
addValue(EnumFrameType.values()[i], rotation[i]);
|
||||||
|
pivot[i] = compound.getFloat("Pivot" + i);
|
||||||
|
addValue(EnumFrameType.values()[3 + i], rotation[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Customized = TRUE if Speed or Smooth Exist
|
// Customized = TRUE if Speed or Smooth Exist
|
||||||
if (compound.hasKey("Speed")) {
|
if (compound.hasKey("Speed")) {
|
||||||
@@ -129,6 +162,15 @@ public class FramePart implements IFramePart {
|
|||||||
customized = true;
|
customized = true;
|
||||||
smooth = compound.getByte("Smooth");
|
smooth = compound.getByte("Smooth");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (EnumFrameType type : EnumFrameType.values()) {
|
||||||
|
String name = type.toString().toLowerCase();
|
||||||
|
if (compound.hasKey(name)) {
|
||||||
|
NBTTagCompound cmpd = compound.getCompoundTag(name);
|
||||||
|
Ease easing = Ease.valueOf(cmpd.getString("easing"));
|
||||||
|
addValue(type, cmpd.getFloat("value"), easing);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTTagCompound writeToNBT() {
|
public NBTTagCompound writeToNBT() {
|
||||||
@@ -141,6 +183,11 @@ public class FramePart implements IFramePart {
|
|||||||
compound.setFloat("Pivot" + i, pivot[i]);
|
compound.setFloat("Pivot" + i, pivot[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<EnumFrameType, Value> entry : values.entrySet()) {
|
||||||
|
EnumFrameType type = entry.getKey();
|
||||||
|
compound.setTag(type.toString().toLowerCase(), entry.getValue().writeToNBT());
|
||||||
|
}
|
||||||
|
|
||||||
if (customized) {
|
if (customized) {
|
||||||
compound.setFloat("Speed", speed);
|
compound.setFloat("Speed", speed);
|
||||||
compound.setByte("Smooth", smooth);
|
compound.setByte("Smooth", smooth);
|
||||||
@@ -165,31 +212,73 @@ public class FramePart implements IFramePart {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
float pi = (float) Math.PI / 180;
|
float pi = (float) Math.PI / 180;
|
||||||
if (this.smooth == 2) {
|
if (this.partialRotationTick != ClientEventHandler.partialRenderTick) {
|
||||||
|
this.partialRotationTick = ClientEventHandler.partialRenderTick;
|
||||||
|
boolean newLogic = true;
|
||||||
|
if (newLogic && parent != null) {
|
||||||
|
Frame next = (Frame) parent.getFrame(parent.currentFrame + 1);
|
||||||
|
if (next != null) {
|
||||||
|
FramePart nextPart = next.frameParts.get(part);
|
||||||
|
if (nextPart != null) {
|
||||||
|
float value = Ease.OUTBOUNCE.apply(getInterpolationValue());
|
||||||
|
this.prevRotations[0] = ValueUtil.lerp(values.get(EnumFrameType.ROTATION_X).value * pi, nextPart.values.get(EnumFrameType.ROTATION_X).value * pi, value);
|
||||||
|
this.prevRotations[1] = ValueUtil.lerp(values.get(EnumFrameType.ROTATION_Y).value * pi, nextPart.values.get(EnumFrameType.ROTATION_Y).value * pi, value);
|
||||||
|
this.prevRotations[2] = ValueUtil.lerp(values.get(EnumFrameType.ROTATION_Z).value * pi, nextPart.values.get(EnumFrameType.ROTATION_Z).value * pi, value);
|
||||||
|
|
||||||
|
this.prevRotations[0] = ValueUtil.lerp(this.rotation[0] * pi, nextPart.rotation[0] * pi, value);
|
||||||
|
this.prevRotations[1] = ValueUtil.lerp(this.rotation[1] * pi, nextPart.rotation[1] * pi, value);
|
||||||
|
this.prevRotations[2] = ValueUtil.lerp(this.rotation[2] * pi, nextPart.rotation[2] * pi, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else { /**
|
||||||
|
* Smoothing 0 - Interpolated => equivalent to {@link Ease#INSINE}
|
||||||
|
*/
|
||||||
|
float value = Math.abs(speed) / 20f;
|
||||||
|
this.prevRotations[0] = ValueUtil.lerp(this.prevRotations[0], this.rotation[0] * pi, value);
|
||||||
|
this.prevRotations[1] = ValueUtil.lerp(this.prevRotations[1], this.rotation[1] * pi, value);
|
||||||
|
this.prevRotations[2] = ValueUtil.lerp(this.prevRotations[2], this.rotation[2] * pi, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getInterpolationValue() { // a 0-1 that lerps between currentFrame startTick and nextFrame startTick
|
||||||
|
float currentTick = parent.getCurrentTick();
|
||||||
|
if (currentTick == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Frame current = parent.frames.get(parent.currentFrame);
|
||||||
|
float partialTicks = parent.paused ? 0 : partialRotationTick;
|
||||||
|
currentTick += partialTicks;
|
||||||
|
float ratio = (currentTick - current.getStartTick()) / current.duration; //
|
||||||
|
|
||||||
|
System.out.println("currentTick " + currentTick + ", interp_value " + ratio);
|
||||||
|
return ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Smoothing 2 - None => equivalent to {@link Ease#CONSTANT}
|
||||||
|
*/
|
||||||
|
public void constant() {
|
||||||
|
float pi = (float) Math.PI / 180;
|
||||||
this.prevRotations[0] = this.rotation[0] * pi;
|
this.prevRotations[0] = this.rotation[0] * pi;
|
||||||
this.prevRotations[1] = this.rotation[1] * pi;
|
this.prevRotations[1] = this.rotation[1] * pi;
|
||||||
this.prevRotations[2] = this.rotation[2] * pi;
|
this.prevRotations[2] = this.rotation[2] * pi;
|
||||||
} else if (this.partialRotationTick != ClientEventHandler.partialRenderTick) {
|
}
|
||||||
this.partialRotationTick = ClientEventHandler.partialRenderTick;
|
|
||||||
if (this.smooth == 0) {
|
/**
|
||||||
this.prevRotations[0] = (this.rotation[0] * pi - this.prevRotations[0]) * Math.abs(this.speed) / 10f + this.prevRotations[0];
|
* Smoothing 1 - Linear => equivalent to {@link Ease#LINEAR}
|
||||||
this.prevRotations[1] = (this.rotation[1] * pi - this.prevRotations[1]) * Math.abs(this.speed) / 10f + this.prevRotations[1];
|
*/
|
||||||
this.prevRotations[2] = (this.rotation[2] * pi - this.prevRotations[2]) * Math.abs(this.speed) / 10f + this.prevRotations[2];
|
public void linear() {
|
||||||
} else {
|
float pi = (float) Math.PI / 180;
|
||||||
int directionX = Float.compare(this.rotation[0] * pi, this.prevRotations[0]);
|
int directionX = Float.compare(this.rotation[0] * pi, this.prevRotations[0]);
|
||||||
this.prevRotations[0] += directionX * this.speed / 10f;
|
this.prevRotations[0] += directionX * this.speed / 10f;
|
||||||
this.prevRotations[0] = directionX == 1 ?
|
this.prevRotations[0] = directionX == 1 ? Math.min(this.rotation[0] * pi, this.prevRotations[0]) : Math.max(this.rotation[0] * pi, this.prevRotations[0]);
|
||||||
Math.min(this.rotation[0] * pi, this.prevRotations[0]) : Math.max(this.rotation[0] * pi, this.prevRotations[0]);
|
|
||||||
int directionY = Float.compare(this.rotation[1] * pi, this.prevRotations[1]);
|
int directionY = Float.compare(this.rotation[1] * pi, this.prevRotations[1]);
|
||||||
this.prevRotations[1] += directionY * this.speed / 10f;
|
this.prevRotations[1] += directionY * this.speed / 10f;
|
||||||
this.prevRotations[1] = directionY == 1 ?
|
this.prevRotations[1] = directionY == 1 ? Math.min(this.rotation[1] * pi, this.prevRotations[1]) : Math.max(this.rotation[1] * pi, this.prevRotations[1]);
|
||||||
Math.min(this.rotation[1] * pi, this.prevRotations[1]) : Math.max(this.rotation[1] * pi, this.prevRotations[1]);
|
|
||||||
int directionZ = Float.compare(this.rotation[2] * pi, this.prevRotations[2]);
|
int directionZ = Float.compare(this.rotation[2] * pi, this.prevRotations[2]);
|
||||||
this.prevRotations[2] += directionZ * this.speed / 10f;
|
this.prevRotations[2] += directionZ * this.speed / 10f;
|
||||||
this.prevRotations[2] = directionZ == 1 ?
|
this.prevRotations[2] = directionZ == 1 ? Math.min(this.rotation[2] * pi, this.prevRotations[2]) : Math.max(this.rotation[2] * pi, this.prevRotations[2]);
|
||||||
Math.min(this.rotation[2] * pi, this.prevRotations[2]) : Math.max(this.rotation[2] * pi, this.prevRotations[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
@@ -210,16 +299,13 @@ public class FramePart implements IFramePart {
|
|||||||
} else {
|
} else {
|
||||||
int directionX = Float.compare(this.pivot[0], this.prevPivots[0]);
|
int directionX = Float.compare(this.pivot[0], this.prevPivots[0]);
|
||||||
this.prevPivots[0] += directionX * this.speed / 10f;
|
this.prevPivots[0] += directionX * this.speed / 10f;
|
||||||
this.prevPivots[0] = directionX == 1 ?
|
this.prevPivots[0] = directionX == 1 ? Math.min(this.pivot[0], this.prevPivots[0]) : Math.max(this.pivot[0], this.prevPivots[0]);
|
||||||
Math.min(this.pivot[0], this.prevPivots[0]) : Math.max(this.pivot[0], this.prevPivots[0]);
|
|
||||||
int directionY = Float.compare(this.pivot[1], this.prevPivots[1]);
|
int directionY = Float.compare(this.pivot[1], this.prevPivots[1]);
|
||||||
this.prevPivots[1] += directionY * this.speed / 10f;
|
this.prevPivots[1] += directionY * this.speed / 10f;
|
||||||
this.prevPivots[1] = directionY == 1 ?
|
this.prevPivots[1] = directionY == 1 ? Math.min(this.pivot[1], this.prevPivots[1]) : Math.max(this.pivot[1], this.prevPivots[1]);
|
||||||
Math.min(this.pivot[1], this.prevPivots[1]) : Math.max(this.pivot[1], this.prevPivots[1]);
|
|
||||||
int directionZ = Float.compare(this.pivot[2], this.prevPivots[2]);
|
int directionZ = Float.compare(this.pivot[2], this.prevPivots[2]);
|
||||||
this.prevPivots[2] += directionZ * this.speed / 10f;
|
this.prevPivots[2] += directionZ * this.speed / 10f;
|
||||||
this.prevPivots[2] = directionZ == 1 ?
|
this.prevPivots[2] = directionZ == 1 ? Math.min(this.pivot[2], this.prevPivots[2]) : Math.max(this.pivot[2], this.prevPivots[2]);
|
||||||
Math.min(this.pivot[2], this.prevPivots[2]) : Math.max(this.pivot[2], this.prevPivots[2]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,4 +324,53 @@ public class FramePart implements IFramePart {
|
|||||||
this.prevRotations[1] = this.rotation[1] * pi;
|
this.prevRotations[1] = this.rotation[1] * pi;
|
||||||
this.prevRotations[2] = this.rotation[2] * pi;
|
this.prevRotations[2] = this.rotation[2] * pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IFramePart addValue(String type, float value) {
|
||||||
|
addValue(EnumFrameType.valueOf(type.toUpperCase()), value, Ease.INSINE);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFramePart addValue(String type, float value, String easing) {
|
||||||
|
addValue(EnumFrameType.valueOf(type.toUpperCase()), value, Ease.valueOf(easing.toUpperCase()));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addValue(EnumFrameType type, float value) {
|
||||||
|
addValue(type, value, Ease.INSINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addValue(EnumFrameType type, float value, Ease ease) {
|
||||||
|
Value val = new Value(value, ease);
|
||||||
|
|
||||||
|
if (!values.containsKey(type))
|
||||||
|
values.put(type, val);
|
||||||
|
else
|
||||||
|
values.replace(type, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEase(EnumFrameType type, Ease ease) {
|
||||||
|
if (values.containsKey(type))
|
||||||
|
values.get(type).easing = ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Value {
|
||||||
|
public float value;
|
||||||
|
public Ease easing;
|
||||||
|
|
||||||
|
public Value(float value, Ease ease) {
|
||||||
|
this.value = value;
|
||||||
|
this.easing = ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Value(float value) {
|
||||||
|
this(value, Ease.INOUTSINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound writeToNBT() {
|
||||||
|
NBTTagCompound cmpd = new NBTTagCompound();
|
||||||
|
cmpd.setFloat("value", value);
|
||||||
|
cmpd.setString("easing", easing.toString());
|
||||||
|
return cmpd;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,8 @@ public class MagicCycle implements IMagicCycle {
|
|||||||
public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
|
public EnumDiagramLayout layout = EnumDiagramLayout.CIRCULAR;
|
||||||
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
|
public HashMap<Integer, MagicAssociation> associations = new HashMap<>();
|
||||||
|
|
||||||
public MagicCycle(){}
|
public MagicCycle() {
|
||||||
|
}
|
||||||
|
|
||||||
public void readNBT(NBTTagCompound compound) {
|
public void readNBT(NBTTagCompound compound) {
|
||||||
id = compound.getInteger("ID");
|
id = compound.getInteger("ID");
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package noppes.npcs.util;
|
||||||
|
|
||||||
|
public enum Ease {
|
||||||
|
LINEAR(0, f -> f, "ease."), CONSTANT(1, f -> 0f, "ease."),
|
||||||
|
INSINE(2, Easing::inSine, "ease."), OUTSINE(3, Easing::outSine, "ease."), INOUTSINE(4, Easing::inOutSine, "ease."),
|
||||||
|
INCUBIC(5, Easing::inCubic, "ease."), OUTCUBIC(6, Easing::outCubic, "ease."), INOUTCUBIC(7, Easing::inOutCubic, "ease."),
|
||||||
|
INQUAD(8, Easing::inQuad, "ease."), OUTQUAD(9, Easing::outQuad, "ease."), INOUTQUAD(10, Easing::inOutQuad, "ease."),
|
||||||
|
INQUART(11, Easing::inQuart, "ease."), OUTQUART(12, Easing::outQuart, "ease."), INOUTQUART(13, Easing::inOutQuart, "ease."),
|
||||||
|
INQUINT(14, Easing::inQuint, "ease."), OUTQUINT(15, Easing::outQuint, "ease."), INOUTQUINT(16, Easing::inOutQuint, "ease."),
|
||||||
|
INEXPO(17, Easing::inExpo, "ease."), OUTEXPO(18, Easing::outExpo, "ease."), INOUTEXPO(19, Easing::inOutExpo, "ease."),
|
||||||
|
INCIRC(20, Easing::inCirc, "ease."), OUTCIRC(21, Easing::outCirc, "ease."), INOUTCIRC(22, Easing::inOutCirc, "ease."),
|
||||||
|
INBACK(23, Easing::inBack, "ease."), OUTBACK(24, Easing::outBack, "ease."), INOUTBACK(25, Easing::inOutBack, "ease."),
|
||||||
|
INELASTIC(26, Easing::inElastic, "ease."), OUTELASTIC(27, Easing::outElastic, "ease."), INOUTELASTIC(28, Easing::inOutElastic, "ease."),
|
||||||
|
INBOUNCE(29, Easing::inBounce, "ease."), OUTBOUNCE(30, Easing::outBack, "ease."), INOUTBOUNCE(31, Easing::inOutBounce, "ease.");
|
||||||
|
|
||||||
|
final byte id;
|
||||||
|
private final EasingFunction impl;
|
||||||
|
public String lang;
|
||||||
|
|
||||||
|
Ease(byte id, EasingFunction impl, String lang) {
|
||||||
|
this.id = id;
|
||||||
|
this.impl = impl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ease(int id, EasingFunction impl, String lang) {
|
||||||
|
this((byte) id, impl, "ease.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply the easing
|
||||||
|
*
|
||||||
|
* @param f float between 0 and 1
|
||||||
|
* @return ease(f)
|
||||||
|
*/
|
||||||
|
public float apply(float f) {
|
||||||
|
return impl.invoke(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
//To be able to send these as bytes instead of String names.
|
||||||
|
public static Ease getEase(byte b) {
|
||||||
|
for (Ease ease : Ease.values()) {
|
||||||
|
if (ease.id == b) return ease;
|
||||||
|
}
|
||||||
|
return LINEAR;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ease getFromOld(byte smoothing) {
|
||||||
|
switch (smoothing) {
|
||||||
|
case 1:
|
||||||
|
return LINEAR;
|
||||||
|
case 2:
|
||||||
|
return CONSTANT;
|
||||||
|
default:
|
||||||
|
return INSINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface EasingFunction {
|
||||||
|
float invoke(float f);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
package noppes.npcs.util;
|
||||||
|
|
||||||
|
public class Easing {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Easing functions from easings.net
|
||||||
|
* All function have a string codename
|
||||||
|
* EasingFromString
|
||||||
|
* <p>
|
||||||
|
* All function needs an input between 0 and 1
|
||||||
|
* <p>
|
||||||
|
* Just use {@link Ease#apply(float)}
|
||||||
|
*/
|
||||||
|
public static float easingFromEnum(Ease type, float f) {
|
||||||
|
return type != null ? type.apply(f) : f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Ease easeFromString(String string) {
|
||||||
|
try {
|
||||||
|
if (string.equals("step"))
|
||||||
|
return Ease.CONSTANT;
|
||||||
|
if (string.substring(0, 4).equalsIgnoreCase("EASE")) {
|
||||||
|
string = string.substring(4);
|
||||||
|
}
|
||||||
|
return Ease.valueOf(string.toUpperCase());
|
||||||
|
} catch (Exception exception) {
|
||||||
|
//Main.log(Level.ERROR, "Ease name unknown: \"" + string + "\" using linear", true);
|
||||||
|
//Main.log(Level.WARN, exception.toString());
|
||||||
|
return Ease.LINEAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final float c1 = 1.70158f;
|
||||||
|
private static final float c2 = c1 * 1.525f;
|
||||||
|
private static final float c3 = c1 + 1;
|
||||||
|
private static final float c4 = (float) ((2 * Math.PI) / 3);
|
||||||
|
private static final float c5 = (float) ((2 * Math.PI) / 4.5);
|
||||||
|
private static final float n1 = 7.5625f;
|
||||||
|
private static final float d1 = 2.75f;
|
||||||
|
|
||||||
|
public static float inSine(float f) {
|
||||||
|
return (float) (1 - Math.cos((f * Math.PI) / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outSine(float f) {
|
||||||
|
return (float) (Math.sin((f * Math.PI) / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutSine(float f) {
|
||||||
|
return (float) (-(Math.cos(Math.PI * f) - 1) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inCubic(float f) {
|
||||||
|
return f * f * f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outCubic(float f) {
|
||||||
|
return (float) (1 - Math.pow(1 - f, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutCubic(float x) {
|
||||||
|
return (float) ((x < 0.5) ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inQuad(float x) {
|
||||||
|
return (x * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outQuad(float x) {
|
||||||
|
return (1 - (1 - x) * (1 - x));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutQuad(float x) {
|
||||||
|
return (float) ((x < 0.5) ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inQuart(float x) {
|
||||||
|
return (x * x * x * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outQuart(float x) {
|
||||||
|
return (float) (1 - Math.pow(1 - x, 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutQuart(float x) {
|
||||||
|
return (float) (x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inQuint(float x) {
|
||||||
|
return (x * x * x * x * x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outQuint(float x) {
|
||||||
|
return (float) (1 - Math.pow(1 - x, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutQuint(float x) {
|
||||||
|
return (float) (x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inExpo(float x) {
|
||||||
|
return (float) (x == 0 ? 0 : Math.pow(2, 10 * x - 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outExpo(float x) {
|
||||||
|
return (float) (x == 1 ? 1 : 1 - Math.pow(2, -10 * x));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutExpo(float x) {
|
||||||
|
return (float) (x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inCirc(float x) {
|
||||||
|
return (float) (1 - Math.sqrt(1 - Math.pow(x, 2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outCirc(float x) {
|
||||||
|
return (float) (Math.sqrt(1 - Math.pow(x - 1, 2)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutCirc(float x) {
|
||||||
|
return (float) (x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inBack(float x) {
|
||||||
|
return c3 * x * x * x - c1 * x * x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outBack(float x) {
|
||||||
|
return (float) (1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutBack(float x) {
|
||||||
|
return (float) (x < 0.5 ? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2 : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inElastic(float x) {
|
||||||
|
return (float) (x == 0 ? 0 : x == 1 ? 1 : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outElastic(float x) {
|
||||||
|
return (float) (x == 0 ? 0 : x == 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutElastic(float x) {
|
||||||
|
return (float) (x == 0 ? 0 : x == 1 ? 1 : x < 0.5 ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2 : (Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5)) / 2 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inBounce(float x) {
|
||||||
|
return 1 - outBounce(1 - x);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float outBounce(float x) {
|
||||||
|
if (x < 1 / d1) {
|
||||||
|
return n1 * x * x;
|
||||||
|
} else if (x < 2 / d1) {
|
||||||
|
return (float) (n1 * (x -= 1.5 / d1) * x + 0.75);
|
||||||
|
} else if (x < 2.5 / d1) {
|
||||||
|
return (float) (n1 * (x -= 2.25 / d1) * x + 0.9375);
|
||||||
|
} else {
|
||||||
|
return (float) (n1 * (x -= 2.625 / d1) * x + 0.984375);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float inOutBounce(float x) {
|
||||||
|
return x < 0.5 ? (1 - outBounce(1 - 2 * x)) / 2 : (1 + outBounce(2 * x - 1)) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
package noppes.npcs.util;
|
package noppes.npcs.util;
|
||||||
|
|
||||||
public class ValueUtil {
|
public class ValueUtil {
|
||||||
|
public static float lerp(float start, float end, float delta) {
|
||||||
|
return start + delta * (end - start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double lerp(double start, double end, double delta) {
|
||||||
|
return start + delta * (end - start);
|
||||||
|
}
|
||||||
|
|
||||||
public static float clamp(float given, float min, float max) {
|
public static float clamp(float given, float min, float max) {
|
||||||
if (given < min)
|
if (given < min)
|
||||||
return min;
|
return min;
|
||||||
@@ -48,4 +56,16 @@ public class ValueUtil {
|
|||||||
return max;
|
return max;
|
||||||
return given;
|
return given;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String format(double value) {
|
||||||
|
return (value % 1 == 0) ? String.format("%.0f", value) : String.format("%.2f", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String format(String precision, float value) {
|
||||||
|
return (value % 1 == 0) ? String.format("%.0f", value) : String.format(precision, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String format(String precision, double value) {
|
||||||
|
return (value % 1 == 0) ? String.format("%.0f", value) : String.format(precision, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,3 +21,5 @@ public net.minecraft.entity.EntityLivingBase func_82166_i()I # getArmSwingAnimat
|
|||||||
public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker
|
public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker
|
||||||
# MusicTicker
|
# MusicTicker
|
||||||
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
||||||
|
#lineScrollOffset
|
||||||
|
public net.minecraft.client.gui.GuiTextField field_146225_q
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 9.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 814 B |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Reference in new issue
Block a user