PanelFrameType type value boxes functionality

This commit is contained in:
bigguy345 committed 2025-03-15 03:32:17 +02:00
1 parent 54a45fbeb8
commit a9e19294f8
4 files changed
+67 -8

No files matched your search

@@ -45,5 +45,11 @@ public class AnimationGraphEditor extends ViewportGraphEditor {
public EnumFrameType getSelectedType() {
return frameTypePanel.selectedElement.type;
}
public void setSelectedType(EnumFrameType type) {
frameTypePanel.list.forEach(element -> {
if(element.type == type)
frameTypePanel.selectedElement = element;
});
}
}
@@ -41,8 +41,11 @@ public class GridPointManager {
keys.SELECT_POINT.setTask((pressType) -> {
if (pressType == KeyPreset.PRESS) {
forEachActive((pointType, point) -> {
if (point.isMouseAbove(grid.mouseX, grid.mouseY))
if (point.isMouseAbove(grid.mouseX, grid.mouseY)) {
setSelectedPoint(point);
graph.setSelectedType(pointType);
}
});
}
});
@@ -63,7 +66,7 @@ public class GridPointManager {
keys.DELETE_POINT.setTask((pressType) -> {
if ((pressType == KeyPreset.PRESS) && selectedPoint != null && !grid.isDragging) {
deletePoint(graph.getSelectedType(), selectedPoint.worldX);
deletePoint(selectedPoint.type, selectedPoint.worldX);
}
});
@@ -103,6 +106,12 @@ public class GridPointManager {
});
}
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));
}
@@ -115,6 +124,7 @@ public class GridPointManager {
}
points.put(point.worldX, point);
updateTypeValues(point.worldX);
return point;
}
@@ -124,6 +134,7 @@ public class GridPointManager {
return;
Point point = points.remove(x);
updateTypeValues(x);
if (point == selectedPoint)
setSelectedPoint(null);
}
@@ -136,6 +147,7 @@ public class GridPointManager {
return points.get(x);
}
public TreeMap<Double, Point> pointsOf(EnumFrameType type) {
return typePoints.get(type);
}
@@ -197,11 +209,11 @@ public class GridPointManager {
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(2F);
GL11.glLineWidth(3F);
GL11.glPushMatrix();
GL11.glTranslatef(grid.startX, grid.startY, 0);
from.type.getColor().glColor();
from.type.getColor().multiply(from.type == graph.getSelectedType() ? 1 : 0.55f).glColor();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawing(GL11.GL_LINE_STRIP);
@@ -247,6 +259,8 @@ public class GridPointManager {
drawEasedCurve(point, getNext(point));
point.draw(mouseX, mouseY, partialTicks);
});
if (selectedPoint != null)
selectedPoint.draw(mouseX, mouseY, partialTicks);
if (Cursors.currentCursor != null)
Cursors.currentCursor.draw(mouseX, mouseY);
@@ -305,10 +319,12 @@ public class GridPointManager {
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) {
@@ -385,7 +401,7 @@ public class GridPointManager {
isDragging = false;
if (isDragging)
worldX = (int) Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX));
setX(Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX)));
//Expand clip boundary
GuiUtil.setScissorClip(grid.startX, grid.startY - grid.yAxisHeight, grid.parent.width, grid.parent.height + grid.yAxisHeight);
@@ -467,11 +483,17 @@ public class GridPointManager {
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) {
worldX = (int) Math.round(grid.worldX(GuiUtil.preciseMouseX() - grid.startX));
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);
}
@@ -4,9 +4,11 @@ import net.minecraft.client.Minecraft;
import noppes.npcs.client.gui.util.GuiNpcTextField;
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.constants.animation.EnumFrameType;
import noppes.npcs.util.ValueUtil;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
@@ -35,6 +37,16 @@ public class PanelFrameType {
selectedElement = list.get(0);
}
public void updateTypeValues(double playheadX) {
list.forEach(e -> {
String value = "0";
GridPointManager.Point p = graph.pointManager.getPoint(e.type, playheadX);
if (p != null)
value = ValueUtil.format(p.worldY);
e.text.setText(value);
});
}
public void initGui(int startX, int startY, int endX, int endY) {
this.startX = startX;
@@ -99,8 +111,10 @@ public class PanelFrameType {
public Element(EnumFrameType key) {
this.type = key;
text = new GuiNpcTextField(0, graph.parent, 0, 0, 45, 10, "400");
text = new GuiNpcTextField(0, graph.parent, 0, 0, 45, 10, "0");
text.setEnableBackgroundDrawing(false);
text.setDoublesOnly();
text.setMinMaxDefaultDouble(0, 1000000000, 0);
}
public boolean isMouseAbove(int mouseX, int mouseY) {
@@ -201,11 +215,24 @@ public class PanelFrameType {
public void keyTyped(char c, int typedKey) {
if (typedKey == 28)
cancelEdit();
else
else {
String prev = text.getText();
text.textboxKeyTyped(c, typedKey);
String newText = text.getText();
if (typedKey != 14 && !newText.equals(prev)) { //backspace
try {
Double.parseDouble(text.getText());
} catch (NumberFormatException var6) {
text.setText(prev);
}
}
}
}
public void cancelEdit() {
String s = text.getText();
text.setText(s.isEmpty() ? "0" : ValueUtil.format(text.getDouble()));
graph.pointManager.addPoint(type, graph.pointManager.playhead.worldX, text.getDouble());
text.setFocused(false);
isEditing = false;
}
@@ -56,4 +56,8 @@ public class ValueUtil {
return max;
return given;
}
public static String format(double value) {
return (value % 1 == 0) ? String.format("%.0f", value) : String.format("%.2f", value);
}
}