diff options
author | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-01-19 12:45:35 +0300 |
---|---|---|
committer | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-01-21 09:37:49 +0300 |
commit | c0358d05116de2a90eee72ea64177a336a2cfbf3 (patch) | |
tree | e757895045b378aaf797d8b7e8f73bf9f66ed45f /src/main | |
parent | 05518642cfdff4defe45a09c3fd52381c7b23c11 (diff) | |
download | Skyblocker-c0358d05116de2a90eee72ea64177a336a2cfbf3.tar.gz Skyblocker-c0358d05116de2a90eee72ea64177a336a2cfbf3.tar.bz2 Skyblocker-c0358d05116de2a90eee72ea64177a336a2cfbf3.zip |
Changed Score text into a translatable and fixed score going off screen borders
Cleaned up the formatScore method to make sure all scores and letter rankings are equally wide, thereby making the text not move as score changes or go off screen borders when the location is set on a narrower score and a wider score is to be displayed.
Diffstat (limited to 'src/main')
3 files changed, 17 insertions, 9 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMapConfigScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMapConfigScreen.java index b832f12d..0f42c495 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMapConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonMapConfigScreen.java @@ -40,7 +40,7 @@ public class DungeonMapConfigScreen extends Screen { public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { int mapSize = (int) (128 * SkyblockerConfigManager.get().locations.dungeons.mapScaling); float scoreScaling = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreScaling; - int scoreWidth = (int) (textRenderer.getWidth("Score: 300 (S+)") * scoreScaling); + int scoreWidth = (int) (textRenderer.getWidth(DungeonScoreHUD.getFormattedScoreText()) * scoreScaling); int scoreHeight = (int) (textRenderer.fontHeight * scoreScaling); if (RenderHelper.pointIsInArea(mouseX, mouseY, mapX, mapY, mapX + mapSize, mapY + mapSize) && button == 0) { mapX = (int) Math.max(Math.min(mouseX - (mapSize >> 1), this.width - mapSize), 0); @@ -57,7 +57,7 @@ public class DungeonMapConfigScreen extends Screen { if (button == 1) { mapX = 2; mapY = 2; - scoreX = Math.max((int) ((mapX + (64 * SkyblockerConfigManager.get().locations.dungeons.mapScaling)) - textRenderer.getWidth("Score: 300 (S+)") * SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreScaling / 2), 0); + scoreX = Math.max((int) ((mapX + (64 * SkyblockerConfigManager.get().locations.dungeons.mapScaling)) - textRenderer.getWidth(DungeonScoreHUD.getFormattedScoreText()) * SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreScaling / 2), 0); scoreY = (int) (mapY + (128 * SkyblockerConfigManager.get().locations.dungeons.mapScaling) + 4); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java index eedbf020..1dfb1b95 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/DungeonScoreHUD.java @@ -11,6 +11,9 @@ public class DungeonScoreHUD { private DungeonScoreHUD() { } + //This is 4+5 wide, needed to offset the extra width from bold numbers (3×1 wide) in S+ and the "+" (6 wide) so that it doesn't go off the screen if the score is S+ and the hud element is at the right edge of the screen + private static final Text extraSpace = Text.literal(" ").append(Text.literal(" ").formatted(Formatting.BOLD)); + public static void render(DrawContext context) { int x = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreX; int y = SkyblockerConfigManager.get().locations.dungeons.dungeonScore.scoreY; @@ -22,16 +25,20 @@ public class DungeonScoreHUD { MatrixStack matrixStack = context.getMatrices(); matrixStack.push(); matrixStack.scale(scale, scale, 0); - context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, Text.literal("Score: ").append(formatScore(DungeonScore.getScore())), (int) (x / scale), (int) (y / scale), 0xFFFFFFFF); + context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, getFormattedScoreText(), (int) (x / scale), (int) (y / scale), 0xFFFFFFFF); matrixStack.pop(); } + public static Text getFormattedScoreText() { + return Text.translatable("skyblocker.dungeons.dungeonScore.scoreText", formatScore(DungeonScore.getScore())); + } + private static Text formatScore(int score) { - if (score < 100) return Text.literal(String.format("%03d", score)).withColor(0xDC1A1A).append(Text.literal(" (D) ").formatted(Formatting.GRAY)); - if (score < 160) return Text.literal(String.format("%03d", score)).withColor(0x4141FF).append(Text.literal(" (C) ").formatted(Formatting.GRAY)); - if (score < 230) return Text.literal(String.format("%03d", score)).withColor(0x7FCC19).append(Text.literal(" (B) ").formatted(Formatting.GRAY)); - if (score < 270) return Text.literal(String.format("%03d", score)).withColor(0x7F3FB2).append(Text.literal(" (A) ").formatted(Formatting.GRAY)); - if (score < 300) return Text.literal(String.format("%03d", score)).withColor(0xF1E252).append(Text.literal(" (S) ").formatted(Formatting.GRAY)); - return Text.literal(String.format("%03d", score)).withColor(0xF1E252).formatted(Formatting.BOLD).append(Text.literal(" (S+)").formatted(Formatting.GRAY)); + if (score < 100) return Text.literal(String.format("%03d", score)).withColor(0xDC1A1A).append(Text.literal(" (D)").formatted(Formatting.GRAY)).append(extraSpace); + if (score < 160) return Text.literal(String.format("%03d", score)).withColor(0x4141FF).append(Text.literal(" (C)").formatted(Formatting.GRAY)).append(extraSpace); + if (score < 230) return Text.literal(String.format("%03d", score)).withColor(0x7FCC19).append(Text.literal(" (B)").formatted(Formatting.GRAY)).append(extraSpace); + if (score < 270) return Text.literal(String.format("%03d", score)).withColor(0x7F3FB2).append(Text.literal(" (A)").formatted(Formatting.GRAY)).append(extraSpace); + if (score < 300) return Text.literal(String.format("%03d", score)).withColor(0xF1E252).append(Text.literal(" (S)").formatted(Formatting.GRAY)).append(extraSpace); + return Text.literal("").append(Text.literal(String.format("%03d", score)).withColor(0xF1E252).formatted(Formatting.BOLD)).append(Text.literal(" (S+)").formatted(Formatting.GRAY)); } } diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index c151c77b..38b14170 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -340,6 +340,7 @@ "skyblocker.dungeons.secrets.customWaypointAdded": "§rAdded a custom waypoint at X: %d, Y: %d, Z: %d for room %s secret #%d of category %s with name '%s'.", "skyblocker.dungeons.secrets.customWaypointRemoved": "§rRemoved custom waypoint at X: %d, Y: %d, Z: %d for room %s secret #%d of category %s with name '%s'.", "skyblocker.dungeons.secrets.customWaypointNotFound": "§cNo custom waypoint found at X: %d, Y: %d, Z: %d for room %s.", + "skyblocker.dungeons.dungeonScore.scoreText": "Score: %s", "skyblocker.dungeons.secretsTracker.feedback": "%s§f found %s§f secrets. %s", "skyblocker.dungeons.secretsTracker.failFeedback": "§cUnable to calculate the amount of secrets everybody did this run!", |