diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-08-26 16:58:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-26 16:58:52 +0200 |
commit | 8c6863a0c554ab75e8967618d6a0b90aaa4562f2 (patch) | |
tree | c59c4792b5652d66ca704db4a0f9d8ebb45b4723 /src/main/java | |
parent | daed9569a0f1d2231c4f824f6cffd72d5f8ae8bd (diff) | |
download | OneConfig-8c6863a0c554ab75e8967618d6a0b90aaa4562f2.tar.gz OneConfig-8c6863a0c554ab75e8967618d6a0b90aaa4562f2.tar.bz2 OneConfig-8c6863a0c554ab75e8967618d6a0b90aaa4562f2.zip |
Hud stuff (#119)
* Commit @Wyvest here
* Api moment
Diffstat (limited to 'src/main/java')
4 files changed, 69 insertions, 14 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java index 3fc1007..503dddd 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/BasicHud.java @@ -31,6 +31,7 @@ import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; import cc.polyfrost.oneconfig.renderer.RenderManager; public abstract class BasicHud extends Hud { + protected boolean background; protected boolean rounded; protected boolean border; protected OneColor bgColor; @@ -45,6 +46,7 @@ public abstract class BasicHud extends Hud { * @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 background If the HUD should have a background * @param rounded If the corner is rounded or not * @param cornerRadius Radius of the corner * @param paddingX Horizontal background padding @@ -54,8 +56,9 @@ public abstract class BasicHud extends Hud { * @param borderSize Thickness of the border * @param borderColor The color of the border */ - public BasicHud(boolean enabled, float x, float y, float scale, boolean rounded, float cornerRadius, float paddingX, float paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { + public BasicHud(boolean enabled, float x, float y, float scale, boolean background, boolean rounded, float cornerRadius, float paddingX, float paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { super(enabled, x, y, scale); + this.background = background; this.rounded = rounded; this.cornerRadius = cornerRadius; this.paddingX = paddingX; @@ -74,7 +77,7 @@ public abstract class BasicHud extends Hud { * @param scale Scale of the hud */ public BasicHud(boolean enabled, float x, float y, float scale) { - this(enabled, x, y, scale, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + this(enabled, x, y, scale, true, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); } /** @@ -83,18 +86,18 @@ public abstract class BasicHud extends Hud { * @param y Y-coordinate of hud on a 1080p display */ public BasicHud(boolean enabled, float x, float y) { - this(enabled, x, y, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + this(enabled, x, y, 1, true, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); } /** * @param enabled If the hud is enabled */ public BasicHud(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, true, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); } public BasicHud() { - this(false, 0, 0, 1, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + this(false, 0, 0, 1, true, false, 2, 5, 5, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); } @Override @@ -102,7 +105,7 @@ public abstract class BasicHud extends Hud { if (!example && !shouldShow()) return; preRender(example); position.setSize(getWidth(scale, example) + paddingX * scale * 2f, getHeight(scale, example) + paddingY * scale * 2f); - if (shouldDrawBackground()) + if (shouldDrawBackground() && background) drawBackground(position.getX(), position.getY(), position.getWidth(), position.getHeight(), scale); draw(matrices, position.getX() + paddingX * scale, position.getY() + paddingY * scale, scale, example); } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java index 2bc99bd..caff4a6 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/HUDUtils.java @@ -76,17 +76,27 @@ public class HUDUtils { options.add(new ConfigSwitch(fields.get("enabled"), hud, "Enabled", category, subcategory, 2)); options.addAll(ConfigUtils.getClassOptions(hud)); if (hud instanceof BasicHud) { + options.add(new ConfigCheckbox(fields.get("background"), hud, "Background", category, subcategory, 1)); options.add(new ConfigCheckbox(fields.get("rounded"), hud, "Rounded corners", category, subcategory, 1)); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border); options.add(new ConfigCheckbox(fields.get("border"), hud, "Outline/border", category, subcategory, 1)); options.add(new ConfigColorElement(fields.get("bgColor"), hud, "Background color:", category, subcategory, 1, true)); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background); options.add(new ConfigColorElement(fields.get("borderColor"), hud, "Border color:", category, subcategory, 1, true)); options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border); options.add(new ConfigSlider(fields.get("cornerRadius"), hud, "Corner radius:", category, subcategory, 0, 10, 0)); options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).rounded); options.add(new ConfigSlider(fields.get("borderSize"), hud, "Border thickness:", category, subcategory, 0, 10, 0)); options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).border); - options.add(new ConfigSlider(fields.get("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0)); - options.add(new ConfigSlider(fields.get("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0)); + if (hud instanceof SingleTextHud) { + options.add(new ConfigSlider(fields.get("paddingX"), hud, "Width", category, subcategory, 50, 72, 0)); + options.add(new ConfigSlider(fields.get("paddingY"), hud, "Height", category, subcategory, 10, 22, 0)); + } else { + options.add(new ConfigSlider(fields.get("paddingX"), hud, "X-Padding", category, subcategory, 0, 50, 0)); + options.add(new ConfigSlider(fields.get("paddingY"), hud, "Y-Padding", category, subcategory, 0, 50, 0)); + } + options.get(options.size() - 2).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border); + options.get(options.size() - 1).addDependency(() -> ((BasicHud) hud).background || ((BasicHud) hud).border); } for (BasicOption option : options) { if (option.name.equals("Enabled")) continue; diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java index ac95af4..8ad93de 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/SingleTextHud.java @@ -29,18 +29,38 @@ package cc.polyfrost.oneconfig.hud; import cc.polyfrost.oneconfig.config.annotations.Dropdown; import cc.polyfrost.oneconfig.config.annotations.Switch; import cc.polyfrost.oneconfig.config.annotations.Text; +import cc.polyfrost.oneconfig.config.core.OneColor; +import cc.polyfrost.oneconfig.libs.universal.UMatrixStack; -import java.util.Collections; import java.util.List; public abstract class SingleTextHud extends TextHud { - public SingleTextHud(String title, boolean enabled) { - this(title, enabled, 0, 0); + /** + * @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 background If the HUD should have a background + * @param rounded If the corner is rounded or not + * @param cornerRadius Radius of the corner + * @param width The width + * @param height The height + * @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 SingleTextHud(String title, boolean enabled, float x, float y, float scale, boolean background, boolean rounded, float cornerRadius, float width, float height, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { + super(enabled, x, y, scale, background, rounded, cornerRadius, width, height, bgColor, border, borderSize, borderColor); + this.title = title; } public SingleTextHud(String title, boolean enabled, int x, int y) { - super(enabled, x, y); - this.title = title; + this(title, enabled, x, y, 1f, true, false, 2, 56, 18, new OneColor(0, 0, 0, 120), false, 2, new OneColor(0, 0, 0)); + } + + public SingleTextHud(String title, boolean enabled) { + this(title, enabled, 0, 0); } /** @@ -60,6 +80,24 @@ public abstract class SingleTextHud extends TextHud { } @Override + public void drawAll(UMatrixStack matrices, boolean example) { + if (!example && !shouldShow()) return; + preRender(example); + float contentWidth = getWidth(scale, example); + float contentHeight = getHeight(scale, example); + position.setSize(Math.max(contentWidth, paddingX * scale), Math.max(contentHeight, paddingY * scale)); + if (shouldDrawBackground() && background) + drawBackground(position.getX(), position.getY(), position.getWidth(), position.getHeight(), scale); + draw( + matrices, + position.getX() + position.getWidth() / 2f - contentWidth / 2f, + position.getY() + position.getHeight() / 2f - contentHeight / 2f, + scale, + example + ); + } + + @Override protected void getLines(List<String> lines, boolean example) { lines.add(getCompleteText(getText(example))); } diff --git a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java index 6b91a7b..b5d1356 100644 --- a/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java +++ b/src/main/java/cc/polyfrost/oneconfig/hud/TextHud.java @@ -43,7 +43,6 @@ import java.util.List; public abstract class TextHud extends BasicHud { protected transient List<String> lines = new ArrayList<>(); - private transient int width; @Color( name = "Text Color" @@ -56,6 +55,11 @@ public abstract class TextHud extends BasicHud { ) protected int textType = 0; + public TextHud(boolean enabled, float x, float y, float scale, boolean background, boolean rounded, float cornerRadius, float paddingX, float paddingY, OneColor bgColor, boolean border, float borderSize, OneColor borderColor) { + super(enabled, x, y, scale, background, rounded, cornerRadius, paddingX, paddingY, bgColor, border, borderSize, borderColor); + EventManager.INSTANCE.register(new TickHandler()); + } + public TextHud(boolean enabled, int x, int y) { super(enabled, x, y); EventManager.INSTANCE.register(new TickHandler()); |