From f06946c01b2c8f210b398a16610c260eca093a8b Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Thu, 21 Jul 2022 04:04:48 +0900 Subject: 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 * 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 --- src/main/java/cc/polyfrost/oneconfig/hud/Hud.java | 208 ++++++---------------- 1 file changed, 59 insertions(+), 149 deletions(-) (limited to 'src/main/java/cc/polyfrost/oneconfig/hud/Hud.java') diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java index 05a4f76..a8c51bd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/Hud.java @@ -2,11 +2,9 @@ package cc.polyfrost.oneconfig.hud; import cc.polyfrost.oneconfig.config.Config; import cc.polyfrost.oneconfig.config.annotations.Switch; -import cc.polyfrost.oneconfig.config.core.OneColor; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.platform.Platform; -import cc.polyfrost.oneconfig.renderer.RenderManager; /** * Represents a HUD element in OneConfig. @@ -15,7 +13,7 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * If you simply want to display text, extend {@link TextHud} or {@link SingleTextHud}, * whichever applies to the use case. Then, override the required methods. *

- * If you want to display something else, extend this class and override {@link Hud#getWidth(float)}, {@link Hud#getHeight(float)}, and {@link Hud#draw(UMatrixStack, int, int, float)} with the width, height, and the drawing code respectively. + * If you want to display something else, extend this class and override {@link Hud#getWidth(float, boolean)}, {@link Hud#getHeight(float, boolean)}, and {@link Hud#draw(UMatrixStack, float, float, float, boolean)} with the width, height, and the drawing code respectively. *

*

* It should also be noted that additional options to the HUD can be added simply by declaring them. @@ -39,50 +37,10 @@ import cc.polyfrost.oneconfig.renderer.RenderManager; * * } */ public abstract class Hud { - public boolean enabled; + protected boolean enabled; transient private Config config; - public boolean rounded; - public boolean border; - public OneColor bgColor; - public OneColor borderColor; - public float cornerRadius; - public float borderSize; - public double xUnscaled; - public double yUnscaled; - public float scale; - public float paddingX; - public float paddingY; - - /** - * @param enabled If the hud is enabled - * @param x X-coordinate of hud on a 1080p display - * @param y Y-coordinate of hud on a 1080p display - * @param scale Scale of the hud - * @param rounded If the corner is rounded or not - * @param cornerRadius Radius of the corner - * @param paddingX Horizontal background padding - * @param paddingY Vertical background padding - * @param bgColor Background color - * @param border If the hud has a border or not - * @param borderSize Thickness of the border - * @param borderColor The color of the border - */ - public Hud(boolean enabled, int x, int y, float scale, boolean rounded, int cornerRadius, int paddingX, int paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { - this.enabled = enabled; - this.scale = scale; - this.rounded = rounded; - this.cornerRadius = cornerRadius; - this.paddingX = paddingX; - this.paddingY = paddingY; - this.bgColor = bgColor; - this.border = border; - this.borderSize = borderSize; - this.borderColor = borderColor; - if (x / 1920d <= 0.5d) xUnscaled = x / 1920d; - else xUnscaled = (x + getWidth(scale)) / 1920d; - if (y / 1080d <= 0.5d) yUnscaled = y / 1080d; - else yUnscaled = (y + getHeight(scale)) / 1090d; - } + public final Position position; + protected float scale; /** * @param enabled If the hud is enabled @@ -90,8 +48,10 @@ public abstract class Hud { * @param y Y-coordinate of hud on a 1080p display * @param scale Scale of the hud */ - public Hud(boolean enabled, int x, int y, int scale) { - this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + public Hud(boolean enabled, float x, float y, float scale) { + this.enabled = enabled; + this.scale = scale; + position = new Position(x, y, getWidth(scale, true), getHeight(scale, true)); } /** @@ -99,153 +59,103 @@ public abstract class Hud { * @param x X-coordinate of hud on a 1080p display * @param y Y-coordinate of hud on a 1080p display */ - public Hud(boolean enabled, int x, int y) { - this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + public Hud(boolean enabled, float x, float y) { + this(enabled, x, y, 1); } /** * @param enabled If the hud is enabled */ public Hud(boolean enabled) { - this(enabled, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + this(enabled, 0, 0, 1); } - /** - * Function called when drawing the hud - * - * @param x Top left x-coordinate of the hud - * @param y Top left y-coordinate of the hud - * @param scale Scale of the hud - */ - public abstract void draw(UMatrixStack matrices, int x, int y, float scale); + public Hud() { + this(false, 0, 0, 1); + } /** - * Function called when drawing the example version of the hud. - * This is used in for example, the hud editor gui. + * Function called when drawing the hud * - * @param x Top left x-coordinate of the hud - * @param y Top left y-coordinate of the hud - * @param scale Scale of the hud + * @param matrices The UMatrixStack used for rendering in higher versions + * @param x Top left x-coordinate of the hud + * @param y Top left y-coordinate of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form */ - public void drawExample(UMatrixStack matrices, int x, int y, float scale) { - draw(matrices, x, y, scale); - } + protected abstract void draw(UMatrixStack matrices, float x, float y, float scale, boolean example); /** - * @param scale Scale of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form * @return The width of the hud */ - public abstract int getWidth(float scale); + protected abstract float getWidth(float scale, boolean example); /** - * @param scale Scale of the hud + * @param scale Scale of the hud + * @param example If the HUD is being rendered in example form * @return The height of the hud */ - public abstract int getHeight(float scale); - - /** - * @param scale Scale of the hud - * @return The width of the example version of the hud - */ - public int getExampleWidth(float scale) { - return getWidth(scale); - } - - /** - * @param scale Scale of the hud - * @return The height of the example version of the hud - */ - public int getExampleHeight(float scale) { - return getHeight(scale); - } + protected abstract float getHeight(float scale, boolean example); /** - * @return If the background should be drawn + * Function to do things before rendering anything + * + * @param example If the HUD is being rendered in example form */ - public boolean drawBackground() { - return true; + protected void preRender(boolean example) { } /** * Draw the background, the hud and all childed huds, used by HudCore - * - * @param x X-coordinate - * @param y Y-coordinate - * @param scale Scale of the hud - * @param background If background should be drawn or not */ - public void drawAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { - if (!showInGuis && Platform.getGuiPlatform().getCurrentScreen() != null && !(Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui)) return; - if (!showInChat && Platform.getGuiPlatform().isInChat()) return; - if (!showInDebug && Platform.getGuiPlatform().isInDebug()) return; - if (background && drawBackground()) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - draw(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + public void drawAll(UMatrixStack matrices, boolean example) { + if (!example && !shouldShow()) return; + preRender(example); + position.setSize(getWidth(scale, example), getHeight(scale, example)); + draw(matrices, position.getX(), position.getY(), scale, example); } - /** - * Draw example version of the background, the hud and all childed huds, used by HudGui - * - * @param x X-coordinate - * @param y Y-coordinate - * @param scale Scale of the hud - * @param background If background should be drawn or not - */ - public void drawExampleAll(UMatrixStack matrices, float x, float y, float scale, boolean background) { - if (background) drawBackground(x, y, getWidth(scale), getHeight(scale), scale); - drawExample(matrices, (int) (x + paddingX * scale / 2f), (int) (y + paddingY * scale / 2f), scale); + protected boolean shouldShow() { + if (!showInGuis && Platform.getGuiPlatform().getCurrentScreen() != null && !(Platform.getGuiPlatform().getCurrentScreen() instanceof OneConfigGui)) + return false; + if (!showInChat && Platform.getGuiPlatform().isInChat()) return false; + return showInDebug || !Platform.getGuiPlatform().isInDebug(); } /** - * Draw example version of the background, the hud and all childed huds, used by HudGui - * - * @param x X-coordinate - * @param y Y-coordinate - * @param width Width of the hud - * @param height Height of the hud - * @param scale Scale of the hud + * @return If the hud is enabled */ - private void drawBackground(float x, float y, float width, float height, float scale) { - RenderManager.setupAndDraw(true, (vg) -> { - if (rounded) { - RenderManager.drawRoundedRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB(), cornerRadius * scale); - if (border) - RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), cornerRadius * scale, borderSize * scale); - } else { - RenderManager.drawRect(vg, x, y, (width + paddingX * scale), (height + paddingY * scale), bgColor.getRGB()); - if (border) - RenderManager.drawHollowRoundRect(vg, x - borderSize * scale, y - borderSize * scale, (width + paddingX * scale) + borderSize * scale, (height + paddingY * scale) + borderSize * scale, borderColor.getRGB(), 0, borderSize * scale); - } - }); + public boolean isEnabled() { + return enabled && (config == null || config.enabled); } /** - * @param screenWidth width of the screen - * @return X-coordinate of the hud + * Set the config to disable accordingly, intended for internal use + * + * @param config The config instance */ - public float getXScaled(int screenWidth) { - if (xUnscaled <= 0.5) - return (int) (screenWidth * xUnscaled); - return (float) (screenWidth - (1d - xUnscaled) * screenWidth - (getWidth(scale) + paddingX * scale)); + public void setConfig(Config config) { + this.config = config; } /** - * @param screenHeight height of the screen - * @return Y-coordinate of the hud + * @return The scale of the Hud */ - public float getYScaled(int screenHeight) { - if (yUnscaled <= 0.5) return (int) (screenHeight * yUnscaled); - return (float) (screenHeight - (1d - yUnscaled) * screenHeight - (getHeight(scale) + paddingY * scale)); + public float getScale() { + return scale; } /** - * @return If the hud is enabled + * Set a new scale value + * + * @param scale The new scale + * @param example If the HUD is being rendered in example form */ - public boolean isEnabled() { - return enabled && (config == null || config.enabled); - } - - public void setConfig(Config config) { - this.config = config; + public void setScale(float scale, boolean example) { + this.scale = scale; + position.updateSizePosition(getWidth(scale, example), getHeight(scale, example)); } @Switch( -- cgit