From a4bca9912622e7229044814ee15b33d8e0b83124 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 18 Mar 2025 06:18:35 +0200 Subject: [PATCH] New cursor handler --- .../noppes/npcs/client/ClientTickHandler.java | 3 ++ .../util/animation/AnimationGraphEditor.java | 16 +++++++--- .../client/gui/util/animation/Cursors.java | 30 ++++++++++++++---- .../gui/util/animation/GridPointManager.java | 7 ++-- .../util/animation/ViewportGraphEditor.java | 2 +- .../customnpcs/textures/gui/cursors.png | Bin 667 -> 814 bytes 6 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/main/java/noppes/npcs/client/ClientTickHandler.java b/src/main/java/noppes/npcs/client/ClientTickHandler.java index 46af7df1a..b90e25c6d 100644 --- a/src/main/java/noppes/npcs/client/ClientTickHandler.java +++ b/src/main/java/noppes/npcs/client/ClientTickHandler.java @@ -22,6 +22,7 @@ import noppes.npcs.client.gui.hud.CompassHudComponent; import noppes.npcs.client.gui.hud.EnumHudComponent; import noppes.npcs.client.gui.hud.HudComponent; 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.constants.MarkType; import noppes.npcs.controllers.data.MarkData; @@ -86,6 +87,8 @@ public class ClientTickHandler { PacketClient.sendClient(new ScreenSizePacket(mc.displayWidth, mc.displayHeight)); } + Cursors.tick(); + if (mc.theWorld == null) return; diff --git a/src/main/java/noppes/npcs/client/gui/util/animation/AnimationGraphEditor.java b/src/main/java/noppes/npcs/client/gui/util/animation/AnimationGraphEditor.java index ad117ad4f..4e6d1661a 100644 --- a/src/main/java/noppes/npcs/client/gui/util/animation/AnimationGraphEditor.java +++ b/src/main/java/noppes/npcs/client/gui/util/animation/AnimationGraphEditor.java @@ -1,7 +1,6 @@ package noppes.npcs.client.gui.util.animation; import noppes.npcs.client.gui.util.GuiNPCInterface; -import noppes.npcs.client.gui.util.GuiUtil; import noppes.npcs.client.gui.util.animation.panel.PanelActiveFrame; import noppes.npcs.client.gui.util.animation.panel.PanelFrameType; import noppes.npcs.constants.animation.EnumFrameType; @@ -25,24 +24,31 @@ public class AnimationGraphEditor extends ViewportGraphEditor { } public void drawScreen(int mouseX, int mouseY, float partialTicks, int wheel) { - frameTypePanel.draw(); - activeFramePanel.draw(); + 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); - activeFramePanel.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); - activeFramePanel.keyTyped(c, i); + if (pointManager.selectedPoint != null) + activeFramePanel.keyTyped(c, i); pointManager.keyTyped(c, i); } diff --git a/src/main/java/noppes/npcs/client/gui/util/animation/Cursors.java b/src/main/java/noppes/npcs/client/gui/util/animation/Cursors.java index 9bb46c59c..df38c06ad 100644 --- a/src/main/java/noppes/npcs/client/gui/util/animation/Cursors.java +++ b/src/main/java/noppes/npcs/client/gui/util/animation/Cursors.java @@ -9,14 +9,17 @@ 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); + 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) { + Cursors(int offsetX, int offsetY, int textureX, int textureY, int width, int height, float scale) { this.textureX = textureX; this.textureY = textureY; @@ -24,25 +27,29 @@ public enum Cursors { 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; - float scale = 0.5f; 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); } - public static Cursors currentCursor; + private static Cursors currentCursor; + public static Supplier condition; - public static void setCursor(Cursors cursor) { + public static void setCursor(Cursors cursor, Supplier con) { try { Cursor c = null; if (cursor != null) @@ -51,10 +58,21 @@ public enum Cursors { } catch (LWJGLException e) { } currentCursor = cursor; + condition = con; } public static void reset() { - setCursor(null); + 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"); diff --git a/src/main/java/noppes/npcs/client/gui/util/animation/GridPointManager.java b/src/main/java/noppes/npcs/client/gui/util/animation/GridPointManager.java index 59de4fcd9..cf4405d2c 100644 --- a/src/main/java/noppes/npcs/client/gui/util/animation/GridPointManager.java +++ b/src/main/java/noppes/npcs/client/gui/util/animation/GridPointManager.java @@ -75,11 +75,10 @@ public class GridPointManager { if (isFreeTransforming) { selectedPoint.set(ftGrabX, ftGrabY); ftGrabX = ftGrabY = 0; - Cursors.reset(); } else { ftGrabX = selectedPoint.worldX; ftGrabY = selectedPoint.worldY; - Cursors.setCursor(Cursors.MOVE); + Cursors.setCursor(Cursors.MOVE, () -> selectedPoint != null && isFreeTransforming); } isFreeTransforming = !isFreeTransforming; @@ -96,7 +95,7 @@ public class GridPointManager { if (button == 0 && isFreeTransforming) { selectedPoint.updateKey(); - Cursors.reset(); + // Cursors.reset(); isFreeTransforming = false; } @@ -291,8 +290,6 @@ public class GridPointManager { if (selectedPoint != null) selectedPoint.draw(mouseX, mouseY, partialTicks); - if (Cursors.currentCursor != null) - Cursors.currentCursor.draw(mouseX, mouseY); GL11.glDisable(GL11.GL_SCISSOR_TEST); diff --git a/src/main/java/noppes/npcs/client/gui/util/animation/ViewportGraphEditor.java b/src/main/java/noppes/npcs/client/gui/util/animation/ViewportGraphEditor.java index 73ee81992..335f4cc8f 100644 --- a/src/main/java/noppes/npcs/client/gui/util/animation/ViewportGraphEditor.java +++ b/src/main/java/noppes/npcs/client/gui/util/animation/ViewportGraphEditor.java @@ -69,7 +69,7 @@ public class ViewportGraphEditor { } public void close() { - if (Cursors.currentCursor != null) + if (Cursors.currentCursor() != null) Cursors.reset(); } } diff --git a/src/main/resources/assets/customnpcs/textures/gui/cursors.png b/src/main/resources/assets/customnpcs/textures/gui/cursors.png index fac8d5be3e877d8638aabe9b9a52d467bd6c6c6c..33a8f9db5d1a7f28b310b81945db4d385bc0bf81 100644 GIT binary patch delta 531 zcmV+u0_^>p1+E5=Nq@os01mf#T7y#g;2hjMKCcyy# z;b-i;zrX#AajB+FnmQqlS>9k*X+?ovrX@U&WZAI|xA(QNdWG}cDsEJ{w$KfdcBqeV92VfdJ+7S$t1N-Nq->5(^R0x9#Z|LCJ_{6 zS+;d(azI-H1GC%h>L}69yMQS1oZETz@6H8!E+6u7<-mS?{A@Z{NC1O`LRhHpT0HCFZ=!e*meTFQl3`zQ}Dl6B!Qy%<6;2x z)I+S|r$9c5_N9_VJM92~KFenS`Tah1pWzGu1}P_jOM!jM9Fw5|;T!+}0RFk6_zQom VRHIk6Q0o8y002ovPDHLkV1lI~3_Sn< delta 377 zcmV-<0fzpr2Ac(tNq@rt01m?e$8V@)0006oNkl7xV7zNPK0VH690rB_# zFNhdZZm>~6RM4er!Z}i82fJ+dGchjBE4$sUold81+VT?c2@?9nV$sHOxl{z;Q|$Nq zTllLKf$esy2*8*f4u`w&&*$^fyB2|rm#M&jeU@Ro|J{BKd9K{oehs{H05DShqrh49SF6?SnLn>P z3Jl}$@+k1>bZXA$bJs?W1p_1JzX9RH)qQ{(ej9%9VG?@32n3Tc0_2lG0tXrJCz|FP X;UN=R_Ia2800000NkvXXu0mjf@=Cd(