Skip to content

Commit

Permalink
Tweaked Text Handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterCheezeCake committed Sep 7, 2024
1 parent c3f3eef commit 3faf67a
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ replay_*.log
*.jfr

scripts/
# Don't include dev mixins
src/main/java/wtf/cheeze/sbt/mixin/dev
sbtdev.mixins.json
# still a draft
CONTRIBUTING.md
1 change: 0 additions & 1 deletion src/main/java/wtf/cheeze/sbt/SkyblockTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import wtf.cheeze.sbt.utils.*;
import wtf.cheeze.sbt.utils.actionbar.ActionBarTransformer;
import wtf.cheeze.sbt.utils.hud.HUD;
import wtf.cheeze.sbt.utils.render.RenderUtils;
import wtf.cheeze.sbt.utils.skyblock.ModAPIUtils;
import wtf.cheeze.sbt.utils.skyblock.ProfileManager;
import wtf.cheeze.sbt.utils.skyblock.SkyblockData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CoordinatesHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.coordinates.color,
() -> SkyblockTweaks.CONFIG.config.huds.coordinates.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.coordinates.mode,
() -> String.format("X: %s Y: %s Z: %s" , NumberUtils.formattedRound(SkyblockTweaks.mc.player.getX(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces), NumberUtils.formattedRound(SkyblockTweaks.mc.player.getY(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces), NumberUtils.formattedRound(SkyblockTweaks.mc.player.getZ(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces))
() -> Text.literal(String.format("X: %s Y: %s Z: %s" , NumberUtils.formattedRound(SkyblockTweaks.mc.player.getX(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces), NumberUtils.formattedRound(SkyblockTweaks.mc.player.getY(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces), NumberUtils.formattedRound(SkyblockTweaks.mc.player.getZ(), SkyblockTweaks.CONFIG.config.huds.coordinates.decimalPlaces)))
);
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public DamageReductionHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.dr.color,
() -> SkyblockTweaks.CONFIG.config.huds.dr.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.dr.mode,
() -> NumberUtils.round(SkyblockTweaks.DATA.damageReduction(), 1) + "%"
() -> Text.literal(NumberUtils.round(SkyblockTweaks.DATA.damageReduction(), 1) + "%")
);

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/DefenseHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public DefenseHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.defense.color,
() -> SkyblockTweaks.CONFIG.config.huds.defense.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.defense.mode,
() -> NumberUtils.formatNumber(SkyblockTweaks.DATA.defense, SkyblockTweaks.CONFIG.config.huds.defense.separator)+ (SkyblockTweaks.CONFIG.config.huds.defense.icon ? "❈" : "")
() -> Text.literal(NumberUtils.formatNumber(SkyblockTweaks.DATA.defense, SkyblockTweaks.CONFIG.config.huds.defense.separator)+ (SkyblockTweaks.CONFIG.config.huds.defense.icon ? "❈" : ""))
);
}
@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/wtf/cheeze/sbt/features/huds/DrillFuelHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public DrillFuelHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.drillFuel.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.drillFuel.mode,
() ->
(NumberUtils.formatNumber((int) SkyblockTweaks.DATA.drillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator))
Text.literal((NumberUtils.formatNumber((int) SkyblockTweaks.DATA.drillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator))
+ "/"
+ (SkyblockTweaks.CONFIG.config.huds.drillFuel.abridgeSecondNumber ? NumberUtils.addKOrM((int) SkyblockTweaks.DATA.maxDrillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator) : NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxDrillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator))
+ (SkyblockTweaks.CONFIG.config.huds.drillFuel.abridgeSecondNumber ? NumberUtils.addKOrM((int) SkyblockTweaks.DATA.maxDrillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator) : NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxDrillFuel, SkyblockTweaks.CONFIG.config.huds.drillFuel.separator)))
);
}
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/EhpHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public EhpHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.ehp.color,
() -> SkyblockTweaks.CONFIG.config.huds.ehp.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.ehp.mode,
() -> NumberUtils.formatNumber((int) SkyblockTweaks.DATA.effectiveHealth(), SkyblockTweaks.CONFIG.config.huds.ehp.separator) + (SkyblockTweaks.CONFIG.config.huds.ehp.icon ? "❤" : "")
() -> Text.literal(NumberUtils.formatNumber((int) SkyblockTweaks.DATA.effectiveHealth(), SkyblockTweaks.CONFIG.config.huds.ehp.separator) + (SkyblockTweaks.CONFIG.config.huds.ehp.icon ? "❤" : ""))
);

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/FpsHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public FpsHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.fps.color,
() -> SkyblockTweaks.CONFIG.config.huds.fps.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.fps.mode,
() -> SkyblockTweaks.CONFIG.config.huds.fps.reverse ? "FPS: " + SkyblockTweaks.mc.getCurrentFps() : SkyblockTweaks.mc.getCurrentFps() + " FPS"
() -> Text.literal(SkyblockTweaks.CONFIG.config.huds.fps.reverse ? "FPS: " + SkyblockTweaks.mc.getCurrentFps() : SkyblockTweaks.mc.getCurrentFps() + " FPS")

);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/HealthHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public HealthHUD() {
() -> SkyblockTweaks.DATA.health > SkyblockTweaks.DATA.maxHealth ? SkyblockTweaks.CONFIG.config.huds.health.colorAbsorption : SkyblockTweaks.CONFIG.config.huds.health.color,
() -> SkyblockTweaks.CONFIG.config.huds.health.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.health.mode,
() -> NumberUtils.formatNumber((int) SkyblockTweaks.DATA.health, SkyblockTweaks.CONFIG.config.huds.health.separator) + "/" + NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxHealth, SkyblockTweaks.CONFIG.config.huds.health.separator) + (SkyblockTweaks.CONFIG.config.huds.health.icon ? "❤" : "")
() -> Text.literal(NumberUtils.formatNumber((int) SkyblockTweaks.DATA.health, SkyblockTweaks.CONFIG.config.huds.health.separator) + "/" + NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxHealth, SkyblockTweaks.CONFIG.config.huds.health.separator) + (SkyblockTweaks.CONFIG.config.huds.health.icon ? "❤" : ""))
);
}
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/ManaHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public ManaHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.mana.color,
() -> SkyblockTweaks.CONFIG.config.huds.mana.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.mana.mode,
() -> NumberUtils.formatNumber((int) SkyblockTweaks.DATA.mana, SkyblockTweaks.CONFIG.config.huds.mana.separator) + "/" + NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxMana, SkyblockTweaks.CONFIG.config.huds.mana.separator) + (SkyblockTweaks.CONFIG.config.huds.mana.icon ? "✎" : "")
() -> Text.literal(NumberUtils.formatNumber((int) SkyblockTweaks.DATA.mana, SkyblockTweaks.CONFIG.config.huds.mana.separator) + "/" + NumberUtils.formatNumber((int) SkyblockTweaks.DATA.maxMana, SkyblockTweaks.CONFIG.config.huds.mana.separator) + (SkyblockTweaks.CONFIG.config.huds.mana.icon ? "✎" : ""))
);
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public OverflowManaHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.overflowMana.color,
() -> SkyblockTweaks.CONFIG.config.huds.overflowMana.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.overflowMana.mode,
() -> NumberUtils.formatNumber((int) SkyblockTweaks.DATA.overflowMana, SkyblockTweaks.CONFIG.config.huds.overflowMana.separator) + (SkyblockTweaks.CONFIG.config.huds.overflowMana.icon ? "ʬ" : "")
() -> Text.literal(NumberUtils.formatNumber((int) SkyblockTweaks.DATA.overflowMana, SkyblockTweaks.CONFIG.config.huds.overflowMana.separator) + (SkyblockTweaks.CONFIG.config.huds.overflowMana.icon ? "ʬ" : ""))
);

}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/wtf/cheeze/sbt/features/huds/RealTimeHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public RealTimeHUD() {
amPM = SkyblockTweaks.CONFIG.config.huds.time.amPM ? "AM" : "";
if (hour == 0) hour = 12;
}
return String.format("%d:%02d%s %s", hour, minute, secondString, amPM);
return Text.literal(String.format("%d:%02d%s %s", hour, minute, secondString, amPM));
} else {
return String.format("%02d:%02d%s", hour, minute, secondString);
return Text.literal(String.format("%02d:%02d%s", hour, minute, secondString));
}
}
);
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/wtf/cheeze/sbt/features/huds/SkillHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,52 +73,52 @@ public SkillHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.skills.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.skills.mode,
() -> {
if (timeLeft <= 0) return "Skill HUD Placeholder Text";
if (timeLeft <= 0) return Text.literal("Skill HUD Placeholder Text");
if (this.percent == 0) {
if (this.total == 0) {
return "+" + gained + " (" + NumberUtils.formatNumber((int) progress, ",") + ")";
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 base + " - " + actionsLeft(gained, progress, total) + " Left";
return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left");
} else {
return base;
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 base + " - " + actionsLeft(gained, progress, total) + " Left";
return Text.literal(base + " - " + actionsLeft(gained, progress, total) + " Left");
} else {
return base;
return Text.literal(base);
}
}
}
} else {
if (SkyblockTweaks.CONFIG.config.huds.skills.skillMode == Mode.NUMBER) {
var level = tryAndGetSkillLevel(currentSkill);
if (level == -1) return "+" + gained + " (" + percent + ")%";
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 base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left";
return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left");
} else {
return base;
return Text.literal(base);
}

} else {
var base = "+" + gained + " (" + percent + "%)";
if (SkyblockTweaks.CONFIG.config.huds.skills.actionsLeft) {
var level = tryAndGetSkillLevel(currentSkill);
if (level == -1) return base;
if (level == -1) return Text.literal(base);
var table = getSkillTable(currentSkill);
var nextLevel = table[level];
var progressLevel = (percent / 100) * nextLevel;
return base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left";
return Text.literal(base + " - " + actionsLeft(gained, progressLevel, nextLevel) + " Left");
} else {
return base;
return Text.literal(base);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/wtf/cheeze/sbt/features/huds/SpeedHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SpeedHUD() {
() -> SkyblockTweaks.CONFIG.config.huds.speed.color,
() -> SkyblockTweaks.CONFIG.config.huds.speed.outlineColor,
() -> SkyblockTweaks.CONFIG.config.huds.speed.mode,
() -> (SkyblockTweaks.DATA.getSpeed()+"").split("\\.")[0] + "%"
() -> Text.literal((SkyblockTweaks.DATA.getSpeed()+"").split("\\.")[0] + "%")
);
}
@Override
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/wtf/cheeze/sbt/utils/hud/HudLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public class HudLine {
public Supplier<Integer> color;
public Supplier<Integer> outlineColor;
public Supplier<DrawMode> mode;
public Supplier<String> text;
public Supplier<Text> text;
public Supplier<Boolean> useIcon;

@Nullable
// Make sure not to create a new instance of HudIcon every time you call this
public Supplier<HudIcon> icon;

public HudLine(Supplier<Integer> getColor, Supplier<Integer> getOutlineColor, Supplier<DrawMode> getMode, Supplier<String> getText) {
public HudLine(Supplier<Integer> getColor, Supplier<Integer> getOutlineColor, Supplier<DrawMode> getMode, Supplier<Text> getText) {
this.color = getColor;
this.outlineColor = getOutlineColor;
this.text = getText;
Expand All @@ -29,7 +29,7 @@ public HudLine(Supplier<Integer> getColor, Supplier<Integer> getOutlineColor, Su

}

public HudLine(Supplier<Integer> getColor, Supplier<Integer> getOutlineColor, Supplier<DrawMode> getMode, Supplier<String> getText, Supplier<HudIcon> icon, Supplier<Boolean> useIcon) {
public HudLine(Supplier<Integer> getColor, Supplier<Integer> getOutlineColor, Supplier<DrawMode> getMode, Supplier<Text> getText, Supplier<HudIcon> icon, Supplier<Boolean> useIcon) {
this.color = getColor;
this.outlineColor = getOutlineColor;
this.text = getText;
Expand All @@ -50,9 +50,9 @@ public void render(DrawContext context, int x, int y, float scale) {
case OUTLINE:
if (useIcon.get()) {
icon.get().render(context, (int) (x /scale), (int) (y /scale));
RenderUtils.drawStringWithOutline(context, Text.literal(text.get()), x + (int) (10 * scale), y, color.get(), outlineColor.get(), scale, true);
RenderUtils.drawStringWithOutline(context, text.get(), x + (int) (10 * scale), y, color.get(), outlineColor.get(), scale, true);
} else {
RenderUtils.drawStringWithOutline(context, Text.literal(text.get()), x, y, color.get(), outlineColor.get(), scale, true);
RenderUtils.drawStringWithOutline(context, text.get(), x, y, color.get(), outlineColor.get(), scale, true);
}
}
}
Expand All @@ -63,9 +63,9 @@ private void render(DrawContext context, int x, int y, float scale, boolean shad
int i = (int) (1 * scale);
// context.fill(x - i, y - i, x + RenderUtils.getStringWidth(text.get()) + 10, y + 9, 1694433280);
icon.get().render(context, (int) (x /scale), (int) (y /scale));
RenderUtils.drawString(context, Text.literal(text.get()), x + (int) (10 * scale), y, color.get(), shadow, scale, true);
RenderUtils.drawString(context, text.get(), x + (int) (10 * scale), y, color.get(), shadow, scale, true);
} else {
RenderUtils.drawString(context, Text.literal(text.get()), x, y, color.get(), shadow, scale, true);
RenderUtils.drawString(context, text.get(), x, y, color.get(), shadow, scale, true);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/wtf/cheeze/sbt/utils/render/RenderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static int getStringWidth(String text) {
public static int getRelativeStringWidth(String text) {
return (int) (SkyblockTweaks.mc.textRenderer.getWidth(text) / MinecraftClient.getInstance().getWindow().getScaledWidth());
}
public static int getRelativeStringWidth(Text text) {
return (int) (SkyblockTweaks.mc.textRenderer.getWidth(text) / MinecraftClient.getInstance().getWindow().getScaledWidth());
}

public static Color3f getColor3f(int color) {
return new Color3f(color);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"mixins": [
"skyblocktweaks.mixins.json"

],
"depends": {
"fabricloader": ">=0.15.11",
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/skyblocktweaks.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"DrawContextMixin",
"HandledScreenMixin",
"InGameHudMixin",
"InventoryScreenMixin"
"InventoryScreenMixin",
"dev.YggdrasilServicesKeyInfoMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 3faf67a

Please sign in to comment.