diff --git a/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java b/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java index 938627b..f765da8 100644 --- a/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java +++ b/src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java @@ -66,7 +66,8 @@ public void onInitialize() { // This fixes config not actually loading on initial startup... for some reason CONFIG.getScreen(null); - HUDS.add(new SkillHUD()); + HUDS.add(SkillHUDManager.INSTANCE.SKILL_HUD); + HUDS.add(SkillHUDManager.INSTANCE.SKILL_BAR); HUDS.add(new SpeedHUD()); HUDS.add(new DefenseHUD()); diff --git a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksConfig.java b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksConfig.java index 6f0170a..8780ed6 100644 --- a/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksConfig.java +++ b/src/main/java/wtf/cheeze/sbt/config/SkyblockTweaksConfig.java @@ -40,6 +40,7 @@ public class SkyblockTweaksConfig { .setPath(FabricLoader.getInstance().getConfigDir().resolve("skyblocktweaks-config.json")) .build()) .build(); + // TODO: Fix this, it's a mess right now public ConfigImpl config; public YetAnotherConfigLib YACLInstance = YetAnotherConfigLib.create(HANDLER, (defaults, configThing, builder) -> { diff --git a/src/main/java/wtf/cheeze/sbt/config/categories/Huds.java b/src/main/java/wtf/cheeze/sbt/config/categories/Huds.java index 4512641..e61afaa 100644 --- a/src/main/java/wtf/cheeze/sbt/config/categories/Huds.java +++ b/src/main/java/wtf/cheeze/sbt/config/categories/Huds.java @@ -70,7 +70,10 @@ public class Huds { public FpsHUD.Config fps = new FpsHUD.Config(); @SerialEntry - public SkillHUD.Config skills = new SkillHUD.Config(); + public SkillHUDManager.SkillHUD.Config skills = new SkillHUDManager.SkillHUD.Config(); + + @SerialEntry + public SkillHUDManager.SkillBar.Config skillBar = new SkillHUDManager.SkillBar.Config(); @SerialEntry public TickerHUD.Config ticker = new TickerHUD.Config(); @@ -79,7 +82,8 @@ public static ConfigCategory getCategory(ConfigImpl defaults, ConfigImpl config) return ConfigCategory.createBuilder() .name(Text.literal("HUDs")) .tooltip(Text.literal("Settings for various HUDs")) - .group(SkillHUD.Config.getGroup(defaults, config)) + .group(SkillHUDManager.SkillHUD.Config.getGroup(defaults, config)) + .group(SkillHUDManager.SkillBar.Config.getGroup(defaults, config)) .group(HealthHUD.Config.getGroup(defaults, config)) .group(HealthBar.Config.getGroup(defaults, config)) .group(ManaHUD.Config.getGroup(defaults, config)) diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java index 935a72e..882a0d1 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelBar.java @@ -42,8 +42,7 @@ public DrillFuelBar() { () -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.scale, () -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.anchor, () -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.color, - () -> SkyblockTweaks.DATA.maxDrillFuel, - () -> SkyblockTweaks.DATA.drillFuel, + () -> SkyblockTweaks.DATA.drillFuel / SkyblockTweaks.DATA.maxDrillFuel, x -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.x = (float) x, y -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.y = (float) y, scale -> SkyblockTweaks.CONFIG.config.huds.drillFuelBar.scale = (float) scale, diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java index 822e3a7..05e7a58 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/HealthBar.java @@ -42,13 +42,11 @@ public HealthBar() { () -> SkyblockTweaks.CONFIG.config.huds.healthBar.scale, () -> SkyblockTweaks.CONFIG.config.huds.healthBar.anchor, () -> SkyblockTweaks.DATA.health > SkyblockTweaks.DATA.maxHealth ? SkyblockTweaks.CONFIG.config.huds.healthBar.colorAbsorption : SkyblockTweaks.CONFIG.config.huds.healthBar.color, - () -> SkyblockTweaks.DATA.maxHealth, - () -> SkyblockTweaks.DATA.health, + () -> SkyblockTweaks.DATA.health / SkyblockTweaks.DATA.maxHealth, x -> SkyblockTweaks.CONFIG.config.huds.healthBar.x = (float) x, y -> SkyblockTweaks.CONFIG.config.huds.healthBar.y = (float) y, scale -> SkyblockTweaks.CONFIG.config.huds.healthBar.scale = (float) scale, anchor ->SkyblockTweaks.CONFIG.config.huds.healthBar.anchor= anchor - ); } diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java b/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java index 9d44756..eb51735 100644 --- a/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java +++ b/src/main/java/wtf/cheeze/sbt/features/huds/ManaBar.java @@ -42,8 +42,7 @@ public ManaBar() { () -> SkyblockTweaks.CONFIG.config.huds.manaBar.scale, () -> SkyblockTweaks.CONFIG.config.huds.manaBar.anchor, () -> SkyblockTweaks.CONFIG.config.huds.manaBar.color, - () -> SkyblockTweaks.DATA.maxMana, - () -> SkyblockTweaks.DATA.mana, + () -> SkyblockTweaks.DATA.mana / SkyblockTweaks.DATA.maxMana, x -> SkyblockTweaks.CONFIG.config.huds.manaBar.x = (float) x, y -> SkyblockTweaks.CONFIG.config.huds.manaBar.y = (float) y, scale -> SkyblockTweaks.CONFIG.config.huds.manaBar.scale = (float) scale, diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUD.java b/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUD.java deleted file mode 100644 index a431bc7..0000000 --- a/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUD.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (C) 2024 MisterCheezeCake - * - * This file is part of SkyblockTweaks. - * - * SkyblockTweaks is free software: you can redistribute it - * and/or modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * SkyblockTweaks is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with SkyblockTweaks. If not, see . - */ -package wtf.cheeze.sbt.features.huds; - -import dev.isxander.yacl3.api.NameableEnum; -import dev.isxander.yacl3.api.Option; -import dev.isxander.yacl3.api.OptionDescription; -import dev.isxander.yacl3.api.OptionGroup; -import dev.isxander.yacl3.api.controller.ColorControllerBuilder; -import dev.isxander.yacl3.api.controller.EnumControllerBuilder; -import dev.isxander.yacl3.config.v2.api.SerialEntry; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.minecraft.text.Text; -import wtf.cheeze.sbt.SkyblockTweaks; -import wtf.cheeze.sbt.config.ConfigImpl; -import wtf.cheeze.sbt.config.SkyblockTweaksConfig; -import wtf.cheeze.sbt.utils.NumberUtils; -import wtf.cheeze.sbt.utils.hud.HudInformation; -import wtf.cheeze.sbt.utils.hud.HudLine; -import wtf.cheeze.sbt.utils.hud.TextHUD; -import wtf.cheeze.sbt.utils.skyblock.IconDict; -import wtf.cheeze.sbt.utils.skyblock.SkyblockConstants; -import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils; - -import java.awt.*; - -public class SkillHUD extends TextHUD { - - private static final int PERSIST_TICKS = 60; - - private int timeLeft = 0; - private SkyblockConstants.Skills currentSkill; - private float gained = 0; - private float total = 0; - private float progress = 0; - private float percent = 0; - - - public SkillHUD() { - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (timeLeft > 0) { - timeLeft--; - } - }); - INFO = new HudInformation( - () -> SkyblockTweaks.CONFIG.config.huds.skills.x, - () -> SkyblockTweaks.CONFIG.config.huds.skills.y, - () -> SkyblockTweaks.CONFIG.config.huds.skills.scale, - () -> SkyblockTweaks.CONFIG.config.huds.skills.anchor, - x -> SkyblockTweaks.CONFIG.config.huds.skills.x = x, - y -> SkyblockTweaks.CONFIG.config.huds.skills.y = y, - scale -> SkyblockTweaks.CONFIG.config.huds.skills.scale = scale, - anchor -> SkyblockTweaks.CONFIG.config.huds.skills.anchor = anchor - ); - line = new HudLine( - () -> SkyblockTweaks.CONFIG.config.huds.skills.color, - () -> SkyblockTweaks.CONFIG.config.huds.skills.outlineColor, - () -> SkyblockTweaks.CONFIG.config.huds.skills.mode, - () -> { - if (timeLeft <= 0) return Text.literal("Skill HUD Placeholder Text"); - if (this.percent == 0) { - if (this.total == 0) { - return Text.literal("+" + gained + " (" + NumberUtils.formatNumber((int) progress, ",") + ")"); - } else { - if (SkyblockTweaks.CONFIG.config.huds.skills.skillMode == Mode.PERCENT) { - var base = "+" + gained + " (" + NumberUtils.formatPercent(progress, total) + ")"; - if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { - return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left"); - } else { - return Text.literal(base); - } - } else { - var base = "+" + gained + " (" + NumberUtils.formatNumber((int) progress, ",") + "/" + (SkyblockTweaks.CONFIG.config.huds.skills.abridgeDenominator ? NumberUtils.addKOrM((int) total, ",") : NumberUtils.formatNumber((int) total, ",")) + ")"; - if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { - return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left"); - } else { - return Text.literal(base); - } - } - } - } else { - if (SkyblockTweaks.CONFIG.config.huds.skills.skillMode == Mode.NUMBER) { - var level = tryAndGetSkillLevel(currentSkill); - if (level == -1) return Text.literal("+" + gained + " (" + percent + "%)"); - var table = getSkillTable(currentSkill); - var nextLevel = table[level]; - var progressLevel = (percent / 100) * nextLevel; - var base = "+" + gained + " (" + NumberUtils.formatNumber((int) progressLevel, ",") + "/" + (SkyblockTweaks.CONFIG.config.huds.skills.abridgeDenominator ? NumberUtils.addKOrM(nextLevel, ",") : NumberUtils.formatNumber(nextLevel, ",")) + ")"; - if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { - return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left"); - } else { - return Text.literal(base); - } - - } else { - var base = "+" + gained + " (" + percent + "%)"; - if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { - var level = tryAndGetSkillLevel(currentSkill); - if (level == -1) return Text.literal(base); - var table = getSkillTable(currentSkill); - var nextLevel = table[level]; - var progressLevel = (percent / 100) * nextLevel; - return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left"); - } else { - return Text.literal(base); - } - } - } - }, - () -> { - // This sometimes errors for a reason I cannot fathom - try { - return IconDict.SKILL_ICONS.getOrDefault(currentSkill, IconDict.DEFAULT_ICON); - } catch (Exception e) { - SkyblockTweaks.LOGGER.error("Error getting skill icon", e); - return IconDict.DEFAULT_ICON; - } - }, - () -> timeLeft > 0 - ); - } - - private static int tryAndGetSkillLevel(SkyblockConstants.Skills skill) { - var profile = SkyblockTweaks.PD.profiles.get(SkyblockTweaks.DATA.getCurrentProfileUnique()); - if (profile == null) return -1; - return profile.skillLevels.getOrDefault(skill, -1); - } - - private static int[] getSkillTable(SkyblockConstants.Skills skill) { - return switch (skill) { - case FARMING, FISHING, FORAGING, MINING, COMBAT, ENCHANTING, ALCHEMY, TAMING, CARPENTRY -> - SkyblockConstants.SKILL_LEVELS; - case RUNECRAFTING -> SkyblockConstants.RUNECRAFTING_LEVELS; - case SOCIAL -> SkyblockConstants.SOCIAL_LEVELS; - }; - } - - private static int actionsLeft(float gain, float prog, float tot) { - var remain = tot - prog; - return Math.round(remain / gain); - } - - @Override - public String getName() { - return "Skill HUD"; - } - - @Override - public boolean shouldRender(boolean fromHudScreen) { - if (!super.shouldRender(fromHudScreen)) return false; - if (timeLeft <= 0 && !fromHudScreen) return false; - return (SkyblockTweaks.DATA.inSB && SkyblockTweaks.CONFIG.config.huds.skills.enabled) || fromHudScreen; - } - - public void update(String skill, float gained, float percent) { - commonUpdate(skill, gained); - this.percent = percent; - this.total = 0; - this.progress = 0; - } - - public void update(String skill, float gained, float total, float progress) { - commonUpdate(skill, gained); - this.total = total; - this.progress = progress; - this.percent = 0; - } - - private void commonUpdate(String skill, float gained) { - timeLeft = PERSIST_TICKS; - currentSkill = SkyblockUtils.strictCastStringToSkill(skill); - this.gained = gained; - } - - public enum Mode implements NameableEnum { - HYPIXEL, - NUMBER, - PERCENT; - - @Override - public Text getDisplayName() { - return switch (this) { - case HYPIXEL -> Text.literal("Default"); - case NUMBER -> Text.literal("All Numbers"); - case PERCENT -> Text.literal("All Percent"); - }; - } - } - - public static class Config { - @SerialEntry - public boolean enabled = false; - - @SerialEntry - public Mode skillMode = Mode.HYPIXEL; - - @SerialEntry - public boolean actionsLeft = true; - - @SerialEntry - public boolean abridgeDenominator = true; - - @SerialEntry - public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; - - @SerialEntry // Not handled by YACL Gui - public float x = 0; - - @SerialEntry // Not handled by YACL Gui - public float y = 0.80f; - - @SerialEntry - public float scale = 1.0f; - - @SerialEntry - public int color = 43690; - - @SerialEntry - public int outlineColor = 0x000000; - - @SerialEntry - public AnchorPoint anchor = AnchorPoint.LEFT; - - public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { - var enabled = Option.createBuilder() - .name(Text.literal("Enable Skill Progress HUD")) - .description(OptionDescription.of(Text.literal("Enables the Skill Progress HUD"))) - .controller(SkyblockTweaksConfig::generateBooleanController) - .binding( - defaults.huds.skills.enabled, - () -> config.huds.skills.enabled, - value -> config.huds.skills.enabled = (Boolean) value - ) - .build(); - - var skillMode = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Mode")) - .description(OptionDescription.of(Text.literal("The mode of the Skill Progress HUD.\nDefault will show the progress based on how Hypixel does by default\nNumber always will show the progress as a number\nPercent will always show the progress as a percentage"))) - .controller(opt -> EnumControllerBuilder.create(opt).enumClass(Mode.class)) - .binding( - defaults.huds.skills.skillMode, - () -> config.huds.skills.skillMode, - value -> config.huds.skills.skillMode = value - ) - .build(); - - var actionsLeft = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Actions Left")) - .description(OptionDescription.of(Text.literal("Shows the amount of actions left to level up in the Skill Progress HUD"))) - .controller(SkyblockTweaksConfig::generateBooleanController) - .binding( - defaults.huds.skills.actionsLeft, - () -> config.huds.skills.actionsLeft, - value -> config.huds.skills.actionsLeft = (Boolean) value - ) - .build(); - var abridgeDenominator = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Abridge Denominator")) - .description(OptionDescription.of(Text.literal("Abridges the denominator in the Skill Progress HUD"))) - .controller(SkyblockTweaksConfig::generateBooleanController) - .binding( - defaults.huds.skills.abridgeDenominator, - () -> config.huds.skills.abridgeDenominator, - value -> config.huds.skills.abridgeDenominator = (Boolean) value - ) - .build(); - - var color = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Color")) - .description(OptionDescription.of(Text.literal("The color of the Skill Progress HUD"))) - .controller(ColorControllerBuilder::create) - .binding( - new Color(defaults.huds.skills.color), - () -> new Color(config.huds.skills.color), - value -> config.huds.skills.color = value.getRGB() - - ) - .build(); - var outline = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Outline Color")) - .description(OptionDescription.of(Text.literal("The outline color of the Skill Progress HUD"))) - .controller(ColorControllerBuilder::create) - .available(config.huds.skills.mode == HudLine.DrawMode.OUTLINE) - .binding( - new Color(defaults.huds.skills.outlineColor), - () -> new Color(config.huds.skills.outlineColor), - value -> config.huds.skills.outlineColor = value.getRGB() - - ) - .build(); - var mode = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Mode")) - .description(OptionDescription.of(Text.literal("The draw mode of the Skill Progress HUD. Pure will render without shadow, Shadow will render with a shadow, and Outline will render with an outline\n§4Warning: §cOutline mode is still a work in progress and can cause annoying visual bugs in menus."))) - .controller(SkyblockTweaksConfig::generateDrawModeController) - .binding( - defaults.huds.skills.mode, - () -> config.huds.skills.mode, - value -> { - config.huds.skills.mode = value; - outline.setAvailable(value == HudLine.DrawMode.OUTLINE); - } - ) - .build(); - var scale = Option.createBuilder() - .name(Text.literal("Skill Progress HUD Scale")) - .description(OptionDescription.of(Text.literal("The scale of the Skill Progress HUD"))) - .controller(SkyblockTweaksConfig::generateScaleController) - .binding( - defaults.huds.skills.scale, - () -> config.huds.skills.scale, - value -> config.huds.skills.scale = value - ) - .build(); - - return OptionGroup.createBuilder() - .name(Text.literal("Skill Progress HUD")) - .description(OptionDescription.of(Text.literal("Settings for the Skill Progress HUD"))) - .option(enabled) - .option(skillMode) - .option(actionsLeft) - .option(abridgeDenominator) - .option(mode) - .option(color) - .option(outline) - .option(scale) - .collapsed(true) - .build(); - } - } - -} - diff --git a/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java b/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java new file mode 100644 index 0000000..eaa1ed9 --- /dev/null +++ b/src/main/java/wtf/cheeze/sbt/features/huds/SkillHUDManager.java @@ -0,0 +1,440 @@ +package wtf.cheeze.sbt.features.huds; + +import dev.isxander.yacl3.api.NameableEnum; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.OptionDescription; +import dev.isxander.yacl3.api.OptionGroup; +import dev.isxander.yacl3.api.controller.ColorControllerBuilder; +import dev.isxander.yacl3.api.controller.EnumControllerBuilder; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.minecraft.text.Text; +import wtf.cheeze.sbt.SkyblockTweaks; +import wtf.cheeze.sbt.config.ConfigImpl; +import wtf.cheeze.sbt.config.SkyblockTweaksConfig; +import wtf.cheeze.sbt.utils.NumberUtils; +import wtf.cheeze.sbt.utils.TextUtils; +import wtf.cheeze.sbt.utils.hud.BarHUD; +import wtf.cheeze.sbt.utils.hud.HudInformation; +import wtf.cheeze.sbt.utils.hud.HudLine; +import wtf.cheeze.sbt.utils.hud.TextHUD; +import wtf.cheeze.sbt.utils.skyblock.IconDict; +import wtf.cheeze.sbt.utils.skyblock.SkyblockConstants; +import wtf.cheeze.sbt.utils.skyblock.SkyblockUtils; + +import java.awt.*; + +/** + * Manages the Skill HUD and Skill Bar, storing data and common functions, Singleton + */ +public class SkillHUDManager { + + public static final SkillHUDManager INSTANCE = new SkillHUDManager(); + + public final SkillHUD SKILL_HUD = new SkillHUD(); + public final SkillBar SKILL_BAR = new SkillBar(); + + private static final int PERSIST_TICKS = 60; + + private int timeLeft = 0; + private SkyblockConstants.Skills currentSkill; + private float gained = 0; + private float total = 0; + private float progress = 0; + private float percent = 0; + + public void update(String skillP, float gainedP, float percentP) { + commonUpdate(skillP, gainedP); + percent = percentP; + total = 0; + progress = 0; + } + + public void update(String skillP, float gainedP, float totalP, float progressP) { + commonUpdate(skillP, gainedP); + total = totalP; + progress = progressP; + percent = 0; + } + + private void commonUpdate(String skillP, float gainedP) { + timeLeft = PERSIST_TICKS; + currentSkill = SkyblockUtils.strictCastStringToSkill(skillP); + gained = gainedP; + } + + public class SkillHUD extends TextHUD { + public SkillHUD() { + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (timeLeft > 0) { + timeLeft--; + } + }); + INFO = new HudInformation( + () -> SkyblockTweaks.CONFIG.config.huds.skills.x, + () -> SkyblockTweaks.CONFIG.config.huds.skills.y, + () -> SkyblockTweaks.CONFIG.config.huds.skills.scale, + () -> SkyblockTweaks.CONFIG.config.huds.skills.anchor, + x -> SkyblockTweaks.CONFIG.config.huds.skills.x = x, + y -> SkyblockTweaks.CONFIG.config.huds.skills.y = y, + scale -> SkyblockTweaks.CONFIG.config.huds.skills.scale = scale, + anchor -> SkyblockTweaks.CONFIG.config.huds.skills.anchor = anchor + ); + line = new HudLine( + () -> SkyblockTweaks.CONFIG.config.huds.skills.color, + () -> SkyblockTweaks.CONFIG.config.huds.skills.outlineColor, + () -> SkyblockTweaks.CONFIG.config.huds.skills.mode, + () -> { + if (timeLeft <= 0) return Text.literal("Skill HUD Placeholder Text"); + if (percent == 0) { + if (total == 0) { + return Text.literal("+" + gained + " (" + NumberUtils.formatNumber((int) progress, ",") + ")"); + } else { + if (SkyblockTweaks.CONFIG.config.huds.skills.skillMode == Mode.PERCENT) { + var base = "+" + gained + " (" + NumberUtils.formatPercent(progress, total) + ")"; + if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { + return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left"); + } else { + return Text.literal(base); + } + } else { + var base = "+" + gained + " (" + NumberUtils.formatNumber((int) progress, ",") + "/" + (SkyblockTweaks.CONFIG.config.huds.skills.abridgeDenominator ? NumberUtils.addKOrM((int) total, ",") : NumberUtils.formatNumber((int) total, ",")) + ")"; + if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { + return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left"); + } else { + return Text.literal(base); + } + } + } + } else { + if (SkyblockTweaks.CONFIG.config.huds.skills.skillMode == Mode.NUMBER) { + var level = tryAndGetSkillLevel(currentSkill); + if (level == -1) return Text.literal("+" + gained + " (" + percent + "%)"); + var table = getSkillTable(currentSkill); + var nextLevel = table[level]; + var progressLevel = (percent / 100) * nextLevel; + var base = "+" + gained + " (" + NumberUtils.formatNumber((int) progressLevel, ",") + "/" + (SkyblockTweaks.CONFIG.config.huds.skills.abridgeDenominator ? NumberUtils.addKOrM(nextLevel, ",") : NumberUtils.formatNumber(nextLevel, ",")) + ")"; + if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { + return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left"); + } else { + return Text.literal(base); + } + + } else { + var base = "+" + gained + " (" + percent + "%)"; + if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) { + var level = tryAndGetSkillLevel(currentSkill); + if (level == -1) return Text.literal(base); + var table = getSkillTable(currentSkill); + var nextLevel = table[level]; + var progressLevel = (percent / 100) * nextLevel; + return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left"); + } else { + return Text.literal(base); + } + } + } + }, + () -> { + // This sometimes errors for a reason I cannot fathom + try { + return IconDict.SKILL_ICONS.getOrDefault(currentSkill, IconDict.DEFAULT_ICON); + } catch (Exception e) { + SkyblockTweaks.LOGGER.error("Error getting skill icon", e); + return IconDict.DEFAULT_ICON; + } + }, + () -> timeLeft > 0 + ); + } + + private static int tryAndGetSkillLevel(SkyblockConstants.Skills skill) { + var profile = SkyblockTweaks.PD.profiles.get(SkyblockTweaks.DATA.getCurrentProfileUnique()); + if (profile == null) return -1; + return profile.skillLevels.getOrDefault(skill, -1); + } + + private static int[] getSkillTable(SkyblockConstants.Skills skill) { + return switch (skill) { + case FARMING, FISHING, FORAGING, MINING, COMBAT, ENCHANTING, ALCHEMY, TAMING, CARPENTRY -> + SkyblockConstants.SKILL_LEVELS; + case RUNECRAFTING -> SkyblockConstants.RUNECRAFTING_LEVELS; + case SOCIAL -> SkyblockConstants.SOCIAL_LEVELS; + }; + } + + private static int actionsLeft(float gain, float prog, float tot) { + var remain = tot - prog; + return Math.round(remain / gain); + } + + @Override + public String getName() { + return TextUtils.SECTION + "3Skill HUD"; + } + + @Override + public boolean shouldRender(boolean fromHudScreen) { + if (!super.shouldRender(fromHudScreen)) return false; + if (timeLeft <= 0 && !fromHudScreen) return false; + return (SkyblockTweaks.DATA.inSB && SkyblockTweaks.CONFIG.config.huds.skills.enabled) || fromHudScreen; + } + + public enum Mode implements NameableEnum { + HYPIXEL, + NUMBER, + PERCENT; + + @Override + public Text getDisplayName() { + return switch (this) { + case HYPIXEL -> Text.literal("Default"); + case NUMBER -> Text.literal("All Numbers"); + case PERCENT -> Text.literal("All Percent"); + }; + } + } + + public static class Config { + @SerialEntry + public boolean enabled = false; + + @SerialEntry + public Mode skillMode = Mode.HYPIXEL; + + @SerialEntry + public boolean actionsLeft = true; + + @SerialEntry + public boolean abridgeDenominator = true; + + @SerialEntry + public HudLine.DrawMode mode = HudLine.DrawMode.SHADOW; + + @SerialEntry // Not handled by YACL Gui + public float x = 0; + + @SerialEntry // Not handled by YACL Gui + public float y = 0.80f; + + @SerialEntry + public float scale = 1.0f; + + @SerialEntry + public int color = 43690; + + @SerialEntry + public int outlineColor = 0x000000; + + @SerialEntry + public AnchorPoint anchor = AnchorPoint.LEFT; + + public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { + var enabled = Option.createBuilder() + .name(Text.literal("Enable Skill Progress HUD")) + .description(OptionDescription.of(Text.literal("Enables the Skill Progress HUD"))) + .controller(SkyblockTweaksConfig::generateBooleanController) + .binding( + defaults.huds.skills.enabled, + () -> config.huds.skills.enabled, + value -> config.huds.skills.enabled = (Boolean) value + ) + .build(); + + var skillMode = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Mode")) + .description(OptionDescription.of(Text.literal("The mode of the Skill Progress HUD.\nDefault will show the progress based on how Hypixel does by default\nNumber always will show the progress as a number\nPercent will always show the progress as a percentage"))) + .controller(opt -> EnumControllerBuilder.create(opt).enumClass(Mode.class)) + .binding( + defaults.huds.skills.skillMode, + () -> config.huds.skills.skillMode, + value -> config.huds.skills.skillMode = value + ) + .build(); + + var actionsLeft = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Actions Left")) + .description(OptionDescription.of(Text.literal("Shows the amount of actions left to level up in the Skill Progress HUD"))) + .controller(SkyblockTweaksConfig::generateBooleanController) + .binding( + defaults.huds.skills.actionsLeft, + () -> config.huds.skills.actionsLeft, + value -> config.huds.skills.actionsLeft = (Boolean) value + ) + .build(); + var abridgeDenominator = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Abridge Denominator")) + .description(OptionDescription.of(Text.literal("Abridges the denominator in the Skill Progress HUD"))) + .controller(SkyblockTweaksConfig::generateBooleanController) + .binding( + defaults.huds.skills.abridgeDenominator, + () -> config.huds.skills.abridgeDenominator, + value -> config.huds.skills.abridgeDenominator = (Boolean) value + ) + .build(); + + var color = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Color")) + .description(OptionDescription.of(Text.literal("The color of the Skill Progress HUD"))) + .controller(ColorControllerBuilder::create) + .binding( + new Color(defaults.huds.skills.color), + () -> new Color(config.huds.skills.color), + value -> config.huds.skills.color = value.getRGB() + + ) + .build(); + var outline = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Outline Color")) + .description(OptionDescription.of(Text.literal("The outline color of the Skill Progress HUD"))) + .controller(ColorControllerBuilder::create) + .available(config.huds.skills.mode == HudLine.DrawMode.OUTLINE) + .binding( + new Color(defaults.huds.skills.outlineColor), + () -> new Color(config.huds.skills.outlineColor), + value -> config.huds.skills.outlineColor = value.getRGB() + + ) + .build(); + var mode = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Mode")) + .description(OptionDescription.of(Text.literal("The draw mode of the Skill Progress HUD. Pure will render without shadow, Shadow will render with a shadow, and Outline will render with an outline\n§4Warning: §cOutline mode is still a work in progress and can cause annoying visual bugs in menus."))) + .controller(SkyblockTweaksConfig::generateDrawModeController) + .binding( + defaults.huds.skills.mode, + () -> config.huds.skills.mode, + value -> { + config.huds.skills.mode = value; + outline.setAvailable(value == HudLine.DrawMode.OUTLINE); + } + ) + .build(); + var scale = Option.createBuilder() + .name(Text.literal("Skill Progress HUD Scale")) + .description(OptionDescription.of(Text.literal("The scale of the Skill Progress HUD"))) + .controller(SkyblockTweaksConfig::generateScaleController) + .binding( + defaults.huds.skills.scale, + () -> config.huds.skills.scale, + value -> config.huds.skills.scale = value + ) + .build(); + + return OptionGroup.createBuilder() + .name(Text.literal("Skill Progress HUD")) + .description(OptionDescription.of(Text.literal("Settings for the Skill Progress HUD"))) + .option(enabled) + .option(skillMode) + .option(actionsLeft) + .option(abridgeDenominator) + .option(mode) + .option(color) + .option(outline) + .option(scale) + .collapsed(true) + .build(); + } + } + + } + public class SkillBar extends BarHUD { + public SkillBar() { + INFO = new HudInformation( + () -> SkyblockTweaks.CONFIG.config.huds.skillBar.x, + () -> SkyblockTweaks.CONFIG.config.huds.skillBar.y, + () -> SkyblockTweaks.CONFIG.config.huds.skillBar.scale, + () -> SkyblockTweaks.CONFIG.config.huds.skillBar.anchor, + () -> SkyblockTweaks.CONFIG.config.huds.skillBar.color, + () -> { + if (percent != 0) { + return percent/100f; + } else { + return progress / total; + } + }, + x -> SkyblockTweaks.CONFIG.config.huds.skillBar.x = (float) x, + y -> SkyblockTweaks.CONFIG.config.huds.skillBar.y = (float) y, + scale -> SkyblockTweaks.CONFIG.config.huds.skillBar.scale = (float) scale, + anchor -> SkyblockTweaks.CONFIG.config.huds.skillBar.anchor = anchor + + ); + } + + @Override + public String getName() { + return TextUtils.SECTION + "3Skill Progress Bar"; + } + + @Override + public boolean shouldRender(boolean fromHudScreen) { + if (!super.shouldRender(fromHudScreen)) return false; + if (timeLeft <= 0 && !fromHudScreen) return false; + // Don't display at max level + if (percent == 0 && total == 0 ) return false; + return (SkyblockTweaks.DATA.inSB && SkyblockTweaks.CONFIG.config.huds.skillBar.enabled) || fromHudScreen; + } + + public static class Config { + @SerialEntry + public boolean enabled = false; + + @SerialEntry // Not handled by YACL Gui + public float x = 0; + + @SerialEntry // Not handled by YACL Gui + public float y = 0.85f; + + @SerialEntry + public float scale = 1.0f; + + @SerialEntry + public int color = 43690; + + @SerialEntry + public AnchorPoint anchor = AnchorPoint.LEFT; + + public static OptionGroup getGroup(ConfigImpl defaults, ConfigImpl config) { + var enabled = Option.createBuilder() + .name(Text.literal("Enable Skill XP Bar")) + .description(OptionDescription.of(Text.literal("Enables the Skill XP Bar"))) + .controller(SkyblockTweaksConfig::generateBooleanController) + .binding( + defaults.huds.skillBar.enabled, + () -> config.huds.skillBar.enabled, + value -> config.huds.skillBar.enabled = (Boolean) value + ) + .build(); + + var color = Option.createBuilder() + .name(Text.literal("Skill XP Bar Color")) + .description(OptionDescription.of(Text.literal("The color of the Skill XP Bar"))) + .controller(ColorControllerBuilder::create) + .binding( + new Color(defaults.huds.skillBar.color), + () -> new Color(config.huds.skillBar.color), + value -> config.huds.skillBar.color = value.getRGB() + + ) + .build(); + var scale = Option.createBuilder() + .name(Text.literal("Skill XP Bar Scale")) + .description(OptionDescription.of(Text.literal("The scale of the Skill XP Bar"))) + .controller(SkyblockTweaksConfig::generateScaleController) + .binding( + defaults.huds.skillBar.scale, + () -> config.huds.skillBar.scale, + value -> config.huds.skillBar.scale = value + ) + .build(); + return OptionGroup.createBuilder() + .name(Text.literal("Skill XP Bar")) + .description(OptionDescription.of(Text.literal("Settings for the Skill XP Bar"))) + .option(enabled) + .option(color) + .option(scale) + .collapsed(true) + .build(); + } + } + } +} diff --git a/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java b/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java index c06e23a..5bc5506 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java +++ b/src/main/java/wtf/cheeze/sbt/utils/actionbar/ActionBarTransformer.java @@ -27,7 +27,7 @@ import wtf.cheeze.sbt.SkyblockTweaks; import wtf.cheeze.sbt.config.ConfigImpl; import wtf.cheeze.sbt.config.SkyblockTweaksConfig; -import wtf.cheeze.sbt.features.huds.SkillHUD; +import wtf.cheeze.sbt.features.huds.SkillHUDManager; import wtf.cheeze.sbt.utils.NumberUtils; import wtf.cheeze.sbt.utils.TextUtils; @@ -138,10 +138,10 @@ public static ActionBarData extractDataAndRunTransformation(String actionBarText String[] xp = matcher.group(3).split("/"); data.totalXP = NumberUtils.parseFloatWithKorM(xp[1]); data.nextLevelXP = NumberUtils.parseFloatWithKorM(xp[0]); - ((SkillHUD) SkyblockTweaks.HUDS.getFirst()).update(data.skillType, data.gainedXP, data.totalXP, data.nextLevelXP); + SkillHUDManager.INSTANCE.update(data.skillType, data.gainedXP, data.totalXP, data.nextLevelXP); } else { data.skillPercentage = Float.parseFloat(matcher.group(3).replace("%", "")); - ((SkillHUD) SkyblockTweaks.HUDS.getFirst()).update(data.skillType, data.gainedXP, data.skillPercentage); + SkillHUDManager.INSTANCE.update(data.skillType, data.gainedXP, data.skillPercentage); } } if (!SkyblockTweaks.CONFIG.config.actionBarFilters.hideSkill) { diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java b/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java index 588cf38..3360755 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java +++ b/src/main/java/wtf/cheeze/sbt/utils/hud/BarHUD.java @@ -43,13 +43,13 @@ public void render(DrawContext context, boolean fromHudScreen, boolean hovered) if (bounds.scale == 1.0f) { context.setShaderColor(colors.red, colors.green, colors.blue, 1.0f); context.drawTexture(UNFILLED, bounds.x, bounds.y, 0, 0, BAR_WIDTH, BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); - context.drawTexture(FILLED, bounds.x, bounds.y, 0, 0, calculateFill((float) INFO.getFillNum.get(), (float) INFO.getMaxNum.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); + context.drawTexture(FILLED, bounds.x, bounds.y, 0, 0, calculateFill((float) INFO.getFill.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); } else { RenderUtils.beginScale(context, bounds.scale); context.setShaderColor(colors.red, colors.green, colors.blue, 1.0f); context.drawTexture(UNFILLED, (int)(bounds.x/bounds.scale), (int)(bounds.y/bounds.scale), 0, 0, BAR_WIDTH, BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); - context.drawTexture(FILLED, (int)(bounds.x/bounds.scale), (int)(bounds.y/bounds.scale), 0, 0, calculateFill((float) INFO.getFillNum.get(), (float) INFO.getMaxNum.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); + context.drawTexture(FILLED, (int)(bounds.x/bounds.scale), (int)(bounds.y/bounds.scale), 0, 0, calculateFill((float) INFO.getFill.get()), BAR_HEIGHT, BAR_WIDTH, BAR_HEIGHT); context.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f); RenderUtils.endScale(context); } @@ -87,9 +87,9 @@ public BoundsRelative getCurrentBoundsRelative() { } } - private static int calculateFill(float current, float max) { - if (current >= max) return BAR_WIDTH; - var i = (int) (current / max * BAR_WIDTH); + private static int calculateFill(float percent) { + if (percent >= 1.0f) return BAR_WIDTH; + var i = (int) (percent * BAR_WIDTH); return i; } diff --git a/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java b/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java index d0b8a44..bc8df39 100644 --- a/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java +++ b/src/main/java/wtf/cheeze/sbt/utils/hud/HudInformation.java @@ -31,9 +31,7 @@ public class HudInformation { public Supplier getAnchorPoint; @Nullable - public Supplier getMaxNum; - @Nullable - public Supplier getFillNum; + public Supplier getFill; @Nullable public Supplier getColor; @@ -54,14 +52,13 @@ public HudInformation(Supplier xSupplier, Supplier ySupplier, Supp this.setScale = scaleConsumer; this.setAnchorPoint = anchorPointConsumer; } - public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Supplier colorSupplier, Supplier maxNumSupplier, Supplier fillNumSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { + public HudInformation(Supplier xSupplier, Supplier ySupplier, Supplier scaleSupplier, Supplier anchorPointSupplier, Supplier colorSupplier, Supplier fillSupplier, Consumer xConsumer, Consumer yConsumer, Consumer scaleConsumer, Consumer anchorPointConsumer) { this.getX = xSupplier; this.getY = ySupplier; this.getScale = scaleSupplier; this.getAnchorPoint = anchorPointSupplier; - this.getMaxNum = maxNumSupplier; - this.getFillNum = fillNumSupplier; + this.getFill = fillSupplier; this.getColor = colorSupplier; this.setX = xConsumer;