aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-31 22:23:45 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-31 22:23:45 +0200
commit92685b6cc55c7f289978a7274f1d37abab739e57 (patch)
tree6508042c3091a041b3af32567a3def4298e3ba37 /src/main/java/de
parentf9c6242980a2cb7ee1cb9b68898d9a621bce89ee (diff)
downloadSkyblocker-92685b6cc55c7f289978a7274f1d37abab739e57.tar.gz
Skyblocker-92685b6cc55c7f289978a7274f1d37abab739e57.tar.bz2
Skyblocker-92685b6cc55c7f289978a7274f1d37abab739e57.zip
clean up progress bar
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/profileviewer/rework/pages/SkillWidget.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/rework/pages/SkillWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/rework/pages/SkillWidget.java
index cd19b2b0..11ae7cbc 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/rework/pages/SkillWidget.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/rework/pages/SkillWidget.java
@@ -11,6 +11,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext;
+import net.minecraft.text.Style;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
@@ -21,6 +22,9 @@ import java.util.List;
import java.util.Locale;
import java.util.OptionalInt;
+import static de.hysky.skyblocker.utils.Formatters.INTEGER_NUMBERS;
+import static de.hysky.skyblocker.utils.Formatters.SHORT_INTEGER_NUMBERS;
+
final class SkillWidget implements ProfileViewerWidget {
private static final Identifier ICON_DATA_TEXTURE = Identifier.of(SkyblockerMod.NAMESPACE, "textures/gui/profile_viewer/icon_data_widget.png");
private static final Identifier BAR_FILL = Identifier.of(SkyblockerMod.NAMESPACE, "bars/bar_fill");
@@ -61,30 +65,40 @@ final class SkillWidget implements ProfileViewerWidget {
// TODO: add helper for hover selection
if (mouseX > x + 30 && mouseX < x + 105 && mouseY > y + 14 && mouseY < y + 21) {
- StringBuilder bar = new StringBuilder("§3§l§m");
- int filledBar = (int) Math.round(levelInfo.fill * 14);
- for (int j = 1; j <= 14; j++) {
- if (j <= filledBar) {
- bar.append("§2§l§m ");
- } else {
- bar.append("§f§l§m ");
- }
- }
-
List<Text> tooltipText = new ArrayList<>();
tooltipText.add(Text.literal(skill.getName() + " " + levelInfo.level).formatted(Formatting.GREEN));
if (levelInfo.level < skillCap) {
tooltipText.add(Text.literal("Progress to Level " + (levelInfo.level + 1) + ":").formatted(Formatting.GRAY));
- tooltipText.add(Text.literal((bar) + "§r " + Formatters.INTEGER_NUMBERS.format(levelInfo.nextLevelXP - levelInfo.levelXP) + "/" + Formatters.SHORT_INTEGER_NUMBERS.format(levelInfo.nextLevelXP)).formatted(Formatting.YELLOW));
- tooltipText.add(Text.literal("XP till " + (levelInfo.level + 1) + ": §e" + Formatters.INTEGER_NUMBERS.format(levelInfo.nextLevelXP - levelInfo.levelXP)).formatted(Formatting.GRAY));
+ tooltipText.add(Text.literal("")
+ .append(formatBar(levelInfo.fill, 15, Formatting.DARK_GREEN, Formatting.GRAY))
+ .append(" ")
+ .append(INTEGER_NUMBERS.format(levelInfo.nextLevelXP - levelInfo.levelXP))
+ .append("/")
+ .append(SHORT_INTEGER_NUMBERS.format(levelInfo.nextLevelXP))
+ .formatted(Formatting.YELLOW));
+ tooltipText.add(
+ Text.literal("XP till " + (levelInfo.level + 1) + ": ")
+ .append(Text.literal(INTEGER_NUMBERS.format(levelInfo.nextLevelXP - levelInfo.levelXP)).formatted(Formatting.YELLOW))
+ .formatted(Formatting.GRAY));
} else {
tooltipText.add(Text.literal("Progress: §6MAXED").formatted(Formatting.GRAY));
}
- tooltipText.add(Text.literal("§7Total XP: §r" + Formatters.INTEGER_NUMBERS.format(levelInfo.xp)).formatted(Formatting.YELLOW));
+ tooltipText.add(Text.literal("§7Total XP: §r" + INTEGER_NUMBERS.format(levelInfo.xp)).formatted(Formatting.YELLOW));
drawContext.drawTooltip(textRenderer, tooltipText, mouseX, mouseY);
}
}
+ private static Text formatBar(double percentage, int total, Formatting filledStyle, Formatting emptyStyle) {
+ return formatBar((int) Math.round(percentage * total), total, filledStyle, emptyStyle);
+ }
+
+ private static Text formatBar(int filled, int total, Formatting filledStyle, Formatting emptyStyle) {
+ assert filled <= total;
+ return Text.literal("")
+ .append(Text.literal(" ".repeat(filled)).formatted(filledStyle, Formatting.STRIKETHROUGH, Formatting.BOLD))
+ .append(Text.literal(" ".repeat(total - filled)).formatted(emptyStyle, Formatting.STRIKETHROUGH, Formatting.BOLD));
+ }
+
@Override
public int getHeight() {
return HEIGHT;