diff options
author | Wyvest <45589059+Wyvest@users.noreply.github.com> | 2022-07-21 04:04:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-20 20:04:48 +0100 |
commit | f06946c01b2c8f210b398a16610c260eca093a8b (patch) | |
tree | 22bda7a5e9b0a1e7370ff2b1e74fc7c9e4035379 /src/main/java/cc/polyfrost/oneconfig/utils | |
parent | ff2ead62333e90b61e05c8cb6a91f692fcf30805 (diff) | |
download | OneConfig-f06946c01b2c8f210b398a16610c260eca093a8b.tar.gz OneConfig-f06946c01b2c8f210b398a16610c260eca093a8b.tar.bz2 OneConfig-f06946c01b2c8f210b398a16610c260eca093a8b.zip |
HUD Improvements, 1.16 port, fix NanoVG with ARM (#52)
* egg 1
* separate Hud from background stuff
* 1984
This reverts commit 9ae517d57bbd495d30d35cb1cbfe81a03556e6bd.
* hitboxes woo!!!!!
* Revert "hitboxes woo!!!!!"
This reverts commit 405d32d17df3c83f2e79eddf0de853f7279767a6.
* padding
* allow position to go slightly off the screen
* stop using ints for ABSOLUTELY EVERYTHING, DIAMOND ...
fix vigilance compat not setting color
* start on new pos system
* some stuff
* finish new position system
* api momento
* 1.16.2 fabric port
* start on hud gui
* temp remove 1.16.2 fabric since it doesn't compile
* fix fabric build
* hud gui stuff
* apiDump
* fix fabric build 2
* so true
* selecting stuff
* scaling + other small things
* More protecting
* fix nanovg not working with macOS ARM
move OneConfig.preLaunch to OneConfigInit
* clean up OneUIScreen
make kotlin version of TestNanoVGGui
* make keybinds have runnable by default
* rollback keybind things
* merge master into hud-improvements (#55)
* Release workflow (#53)
* release workflow
* update normal version to hash
* fix
* fix naming
* fix some stuff
* fix version thing
* switch to number from hash
* Release workflow (#54)
* release workflow
* update normal version to hash
* fix
* fix naming
* fix some stuff
* fix version thing
* switch to number from hash
* Maybe epic fixo
* gotta love those Java principles
* Revert "gotta love those Java principles", wrong branch
This reverts commit 333d8b2ad8941790c13c4bfe0777fbd203d463e5.
* start on snapping
* Finish snapping
* stop including mixin by default on legacy versions
this breaks builds if the mod itself does not use mixin
* merge draw and drawExample
* fix gradle publish
* Some fixes
* Api DUmpidy
* Help subcommand impovments (#59)
* Made the overall look of the "help" subcommand better + added the ability to change the colour for the command overall + each individual SubCommand
* Made the alliases show batter + added support for to show subcommand aliasses
* mr deliverer didnt reply but whatever, added a space between command/subcommand and alliasses
Co-authored-by: pinkulu <pinkulumc@gmail.com>
* fix file not overwriting
toJavaColor
* Fix full shadow not scaling correctly
Co-authored-by: DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>
Co-authored-by: nxtdaydelivery <12willettsh@gmail.com>
Co-authored-by: pinkulu <56201697+pinkulu@users.noreply.github.com>
Co-authored-by: pinkulu <pinkulumc@gmail.com>
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
7 files changed, 71 insertions, 59 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index 6582eaa..9466841 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -22,9 +22,9 @@ public final class InputUtils { * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(int x, int y, int width, int height, boolean ignoreBlock) { - int mouseX = mouseX(); - int mouseY = mouseY(); + public static boolean isAreaHovered(float x, float y, float width, float height, boolean ignoreBlock) { + float mouseX = mouseX(); + float mouseY = mouseY(); return (ignoreBlock || blockScissors.size() == 0 || !shouldBlock(mouseX, mouseY)) && mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; } @@ -33,7 +33,7 @@ public final class InputUtils { * * @return true if mouse is over region, false if not. */ - public static boolean isAreaHovered(int x, int y, int width, int height) { + public static boolean isAreaHovered(float x, float y, float width, float height) { return isAreaHovered(x, y, width, height, false); } @@ -46,9 +46,9 @@ public final class InputUtils { * @param height the height of the region * @param ignoreBlock if true, will ignore * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaHovered(int, int, int, int) + * @see InputUtils#isAreaHovered(float, float, float, float) */ - public static boolean isAreaClicked(int x, int y, int width, int height, boolean ignoreBlock) { + public static boolean isAreaClicked(float x, float y, float width, float height, boolean ignoreBlock) { return isAreaHovered(x, y, width, height, ignoreBlock) && isClicked(false); } @@ -60,9 +60,9 @@ public final class InputUtils { * @param width the width of the region * @param height the height of the region * @return true if the mouse is clicked and is over the region, false if not - * @see InputUtils#isAreaClicked(int, int, int, int, boolean) + * @see InputUtils#isAreaClicked(float, float, float, float, boolean) */ - public static boolean isAreaClicked(int x, int y, int width, int height) { + public static boolean isAreaClicked(float x, float y, float width, float height) { return isAreaClicked(x, y, width, height, false); } @@ -95,9 +95,9 @@ public final class InputUtils { * * @return the current mouse X position */ - public static int mouseX() { - if (OneConfigGui.INSTANCE == null) return (int) Platform.getMousePlatform().getMouseX(); //todo stop casting and actually use doubles - return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); + public static float mouseX() { + if (OneConfigGui.INSTANCE == null) return (float) Platform.getMousePlatform().getMouseX(); + return (float) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } /** @@ -109,9 +109,9 @@ public final class InputUtils { * * @return the current mouse Y position */ - public static int mouseY() { - if (OneConfigGui.INSTANCE == null) return (int) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); - return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); + public static float mouseY() { + if (OneConfigGui.INSTANCE == null) return (float) (UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())); + return (float) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } /** @@ -122,7 +122,7 @@ public final class InputUtils { * @param width Width * @param height Height */ - public static Scissor blockInputArea(int x, int y, int width, int height) { + public static Scissor blockInputArea(float x, float y, float width, float height) { Scissor scissor = new Scissor(new Scissor(x, y, width, height)); blockScissors.add(scissor); return scissor; @@ -160,7 +160,7 @@ public final class InputUtils { return blockScissors.size() > 0; } - private static boolean shouldBlock(int x, int y) { + private static boolean shouldBlock(float x, float y) { for (Scissor block : blockScissors) { if (block.isInScissor(x, y)) return true; } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java index 16a2f8d..14a40c1 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/CommandManager.java @@ -1,5 +1,6 @@ package cc.polyfrost.oneconfig.utils.commands; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.annotations.Command; import cc.polyfrost.oneconfig.utils.commands.annotations.Main; import cc.polyfrost.oneconfig.utils.commands.annotations.SubCommand; @@ -63,7 +64,8 @@ public class CommandManager { if (clazz.isAnnotationPresent(Command.class)) { final Command annotation = clazz.getAnnotation(Command.class); - final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() ? "Main command for " + annotation.value() : annotation.description(), null); + final InternalCommand root = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description().trim().isEmpty() + ? "Main command for " + annotation.value() : annotation.description(), annotation.color(), null); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class) && method.getParameterCount() == 0) { root.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, root)); @@ -79,7 +81,7 @@ public class CommandManager { for (Class<?> clazz : classes) { if (clazz.isAnnotationPresent(SubCommand.class)) { SubCommand annotation = clazz.getAnnotation(SubCommand.class); - InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), parent); + InternalCommand command = new InternalCommand(annotation.value(), annotation.aliases(), annotation.description(), annotation.color() == ChatColor.RESET ? parent.color : annotation.color(), parent); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(Main.class)) { command.invokers.add(new InternalCommand.InternalCommandInvoker(annotation.value(), annotation.aliases(), method, command)); @@ -103,15 +105,17 @@ public class CommandManager { public final String name; public final String[] aliases; public final String description; + public final ChatColor color; public final ArrayList<InternalCommandInvoker> invokers = new ArrayList<>(); public final InternalCommand parent; public final ArrayList<InternalCommand> children = new ArrayList<>(); - public InternalCommand(String name, String[] aliases, String description, InternalCommand parent) { + public InternalCommand(String name, String[] aliases, String description, ChatColor color, InternalCommand parent) { this.name = name; this.aliases = aliases; this.description = description; this.parent = parent; + this.color = color; } public boolean isValid(String name, boolean tabCompletion) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java index 1ab356c..617694c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/PlatformCommandManager.java @@ -13,18 +13,19 @@ public abstract class PlatformCommandManager { //TODO: someone make the help command actually look nice lmao protected String sendHelpCommand(CommandManager.InternalCommand root) { StringBuilder builder = new StringBuilder(); - builder.append(ChatColor.GOLD).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(ChatColor.GOLD).append(":\n"); - if (!root.description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(root.description); - } - for (CommandManager.InternalCommand command : root.children) { - runThroughCommandsHelp(root.name, command, builder); - } - builder.append("\n").append(ChatColor.GOLD).append("Aliases: ").append(ChatColor.BOLD); + builder.append(root.color).append("Help for ").append(ChatColor.BOLD).append(root.name).append(ChatColor.RESET).append(root.color); int index = 0; for (String alias : root.aliases) { + if(index == 0) builder.append(" ("); ++index; - builder.append(alias).append(index < root.aliases.length ? ", " : ""); + builder.append("/").append(alias).append(index < root.aliases.length ? ", " : ")"); + } + builder.append(":\n"); + if (!root.description.isEmpty()) { + builder.append("\n").append(root.color).append("/").append(root.name).append(": ").append(ChatColor.BOLD).append(root.description); + } + for (CommandManager.InternalCommand command : root.children) { + runThroughCommandsHelp(root.name, command, builder); } builder.append("\n"); return builder.toString(); @@ -36,12 +37,12 @@ public abstract class PlatformCommandManager { if (declaringClass.isAnnotationPresent(SubCommand.class)) { String description = declaringClass.getAnnotation(SubCommand.class).description(); if (!description.isEmpty()) { - builder.append("\n").append(ChatColor.GOLD).append("Description: ").append(ChatColor.BOLD).append(description); + builder.append("\n"); } } } for (CommandManager.InternalCommand.InternalCommandInvoker invoker : command.invokers) { - builder.append("\n").append(ChatColor.GOLD).append("/").append(append).append(" ").append(command.name); + builder.append("\n").append(command.color).append("/").append(append).append(" ").append(command.name); for (Parameter parameter : invoker.method.getParameters()) { String name = parameter.getName(); if (parameter.isAnnotationPresent(Name.class)) { @@ -49,8 +50,14 @@ public abstract class PlatformCommandManager { } builder.append(" <").append(name).append(">"); } + int index = 0; + for (String alias : command.aliases) { + if(index == 0) builder.append(" ("); + ++index; + builder.append(alias).append(index < command.aliases.length ? ", " : ")"); + } if (!command.description.trim().isEmpty()) { - builder.append(": ").append(ChatColor.BOLD).append(command.description); + builder.append(": ").append(ChatColor.BOLD).append(command.color).append(command.description); } } for (CommandManager.InternalCommand subCommand : command.children) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java index 41909c0..2bbf0bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/Command.java @@ -1,6 +1,7 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; import cc.polyfrost.oneconfig.internal.command.OneConfigCommand; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; import cc.polyfrost.oneconfig.utils.commands.CommandManager; import cc.polyfrost.oneconfig.utils.commands.arguments.ArgumentParser; @@ -108,6 +109,13 @@ public @interface Command { String description() default ""; /** + * The color of the command. + * + * @return The color of the command. + */ + ChatColor color() default ChatColor.GOLD; + + /** * Whether the command generates a help command. */ boolean helpCommand() default true; diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java index 1bfbd53..eddca3c 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/commands/annotations/SubCommand.java @@ -1,5 +1,7 @@ package cc.polyfrost.oneconfig.utils.commands.annotations; +import cc.polyfrost.oneconfig.libs.universal.ChatColor; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -34,4 +36,11 @@ public @interface SubCommand { * @return The description of the command. */ String description() default ""; + + /** + * The color of the command. + * + * @return The color of the command. + */ + ChatColor color() default ChatColor.RESET; } diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java index 63203e4..969654e 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/GuiUtils.java @@ -24,7 +24,6 @@ public final class GuiUtils { * Displays a screen after a tick, preventing mouse sync issues. * * @param screen the screen to display. - * @deprecated Not actually deprecated, but should not be used. */ @Deprecated public static void displayScreen(Object screen) { diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java index 2dd961e..6a64251 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/gui/OneUIScreen.java @@ -37,16 +37,12 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { } @Override - public void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public final void onDrawScreen(@NotNull UMatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { super.onDrawScreen(matrixStack, mouseX, mouseY, partialTicks); RenderManager.setupAndDraw(ignoreMinecraftScale(), vg -> draw(vg, partialTicks)); mouseDown = Platform.getMousePlatform().isButtonDown(0); } - /** - * This method is called when the screen is first opened. You can use it to set variables, initialize things, etc. - */ - public abstract void onScreenOpen(); /** * Use this method to draw things on the screen. It is called every render tick, and has a handy <code>vg</code> (NanoVG context) that can be used with the {@link RenderManager} to draw things. @@ -59,18 +55,7 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { public abstract void draw(long vg, float partialTicks); /** - * This method is called when the screen is closed. You can use it to clean up things, etc. - */ - @Override - public abstract void onScreenClose(); - - @Override - public void initScreen(int width, int height) { - onScreenOpen(); - } - - /** - * Use this method to set weather or not to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. + * Use this method to set whether to use the Minecraft scale on the GUI. Its default is true, and that is recommended for the NanoVG rendering. */ public boolean ignoreMinecraftScale() { return true; @@ -79,42 +64,37 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { /** * Get the current x position of the mouse. */ - public int getMouseX() { + protected float getMouseX() { return InputUtils.mouseX(); } /** * Get the current y position of the mouse. */ - public int getMouseY() { + protected float getMouseY() { return InputUtils.mouseY(); } - @Override - public void onMouseClicked(double mouseX, double mouseY, int mouseButton) { - super.onMouseClicked(mouseX, mouseY, mouseButton); - } - /** * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) * * @param ignoreBlockClicks whether to ignore the current click blocker. */ - public boolean isClicked(boolean ignoreBlockClicks) { + protected boolean isClicked(boolean ignoreBlockClicks) { return mouseDown && !Platform.getMousePlatform().isButtonDown(0) && (!blockClicks || ignoreBlockClicks); } /** * Retrieve the click status of the mouse. This method uses a boolean to store the status of the mouse, so it will only return true once per click. (very useful) */ - public boolean isClicked() { + protected boolean isClicked() { return isClicked(false); } /** * Retrieve weather or not the mouse is currently down. Will constantly return true if its clicked. See {@link #isClicked()} for a method that only executes once per tick. */ - public boolean isMouseDown() { + protected boolean isMouseDown() { return Platform.getMousePlatform().isButtonDown(0); } @@ -131,4 +111,9 @@ public abstract class OneUIScreen extends UScreen implements GuiPause { public boolean isBlockingClicks() { return blockClicks; } + + @Override + public boolean doesGuiPauseGame() { + return false; + } } |