From dead4f21a8fbbc46813633a85d03f9334644c6dd Mon Sep 17 00:00:00 2001 From: "Ansgar [Hiajen]" Date: Wed, 23 Jun 2021 20:27:19 +0200 Subject: [PATCH] add new Tag, Use Style instead of Textformating, implement grade indicator, fix offset --- gradle.properties | 2 +- .../eaa/custom/ping/CustomPlayerListHud.java | 11 ++++--- .../saltymc/eaa/custom/ping/PingColors.java | 2 +- .../net/saltymc/eaa/custom/ping/TagDTO.java | 33 +++++++++++++++++++ .../saltymc/eaa/function/CheckFunction.java | 6 ++-- .../net/saltymc/eaa/function/TagFunction.java | 14 ++++---- .../net/saltymc/eaa/util/database/DB_Tag.java | 23 +++++-------- 7 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/saltymc/eaa/custom/ping/TagDTO.java diff --git a/gradle.properties b/gradle.properties index a5a1f56..3f6f809 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.11.3 # Mod Properties - mod_version = 1.0.1 + mod_version = 1.0.2 maven_group = net.saltymc.eaa archives_base_name = EAA_MOD diff --git a/src/main/java/net/saltymc/eaa/custom/ping/CustomPlayerListHud.java b/src/main/java/net/saltymc/eaa/custom/ping/CustomPlayerListHud.java index 3e909b3..ee02343 100644 --- a/src/main/java/net/saltymc/eaa/custom/ping/CustomPlayerListHud.java +++ b/src/main/java/net/saltymc/eaa/custom/ping/CustomPlayerListHud.java @@ -27,7 +27,6 @@ import net.minecraft.text.OrderedText; import net.minecraft.text.Text; import net.minecraft.world.GameMode; import net.saltymc.eaa.function.TagFunction; -import net.saltymc.eaa.util.database.DB_Tag; /** * By: https://github.com/vladmarica/better-ping-display-fabric/ @@ -165,9 +164,11 @@ public final class CustomPlayerListHud { * PLAYER TAG */ int offset_tag_playername = aa; - DB_Tag.Type playerTAG = TagFunction.getScoreboardTag(player.getProfile().getId().toString()); - mc.textRenderer.drawWithShadow(stack, playerTAG.getTag(), (float)aa, (float)ab, playerTAG.getColor()); - offset_tag_playername += mc.textRenderer.getWidth(playerTAG.getTag()) + 2; + TagDTO playerTAG = TagFunction.getScoreboardTag(player.getProfile().getId().toString()); + mc.textRenderer.drawWithShadow(stack, playerTAG.getType().getTag(), (float)aa, (float)ab, playerTAG.getType().getColor()); + offset_tag_playername += mc.textRenderer.getWidth(playerTAG.getType().getTag()) + 1; + mc.textRenderer.drawWithShadow(stack,"|", (float) offset_tag_playername, (float) ab, playerTAG.getGradeColor()); + offset_tag_playername += mc.textRenderer.getWidth("|") + 2; Text playerName = hud.getPlayerName(player); @@ -178,7 +179,7 @@ public final class CustomPlayerListHud { } if (obj != null && player.getGameMode() != GameMode.SPECTATOR) { - int ag = aa + i + 1; + int ag = offset_tag_playername + i + 1; ah = ag + q; if (ah - ag > 5) { PlayerListHudUtil.renderScoreboardObjective(hud, stack, obj, ab, gameProfile.getName(), ag, ah, player); diff --git a/src/main/java/net/saltymc/eaa/custom/ping/PingColors.java b/src/main/java/net/saltymc/eaa/custom/ping/PingColors.java index 6521f62..43a42f0 100644 --- a/src/main/java/net/saltymc/eaa/custom/ping/PingColors.java +++ b/src/main/java/net/saltymc/eaa/custom/ping/PingColors.java @@ -33,7 +33,7 @@ public class PingColors { computeOffset(PING_MID, PING_END, Math.min(ping, PING_END))); } - static float computeOffset(int start, int end, int value) { + public static float computeOffset(int start, int end, int value) { float offset = (value - start) / (float) ( end - start); return MathHelper.clamp(offset, 0.0F, 1.0F); } diff --git a/src/main/java/net/saltymc/eaa/custom/ping/TagDTO.java b/src/main/java/net/saltymc/eaa/custom/ping/TagDTO.java new file mode 100644 index 0000000..aa41272 --- /dev/null +++ b/src/main/java/net/saltymc/eaa/custom/ping/TagDTO.java @@ -0,0 +1,33 @@ +package net.saltymc.eaa.custom.ping; + +import net.saltymc.eaa.util.database.DB_Tag; + +import static net.saltymc.eaa.custom.ping.PingColors.computeOffset; + +public class TagDTO { + final int gradeColor; + final DB_Tag.Type type; + + public TagDTO(int grade, DB_Tag.Type type) { + this.gradeColor = calcGradient(grade); + this.type = type; + } + + public int getGradeColor() { + return gradeColor; + } + + public DB_Tag.Type getType() { + return type; + } + + private static int calcGradient(int grade){ + if (grade < 1) + return 0xaaaaaa; + + return ColorUtil.interpolate( + 0xffffff, + 0x0000aa, + computeOffset(0, 10, grade)); + } +} diff --git a/src/main/java/net/saltymc/eaa/function/CheckFunction.java b/src/main/java/net/saltymc/eaa/function/CheckFunction.java index 29d12e3..f7a1d11 100644 --- a/src/main/java/net/saltymc/eaa/function/CheckFunction.java +++ b/src/main/java/net/saltymc/eaa/function/CheckFunction.java @@ -4,7 +4,9 @@ import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.client.toast.SystemToast; import net.minecraft.text.LiteralText; +import net.minecraft.text.Style; import net.minecraft.text.Text; +import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; import net.saltymc.eaa.util.database.DB_Player; import net.saltymc.eaa.util.database.DB_Tag; @@ -57,7 +59,7 @@ public class CheckFunction { source.sendFeedback(new LiteralText(dateformat.format(curr.getTagDate())).formatted(Formatting.GRAY) .append(new LiteralText(" | ")) - .append(new LiteralText(curr.getType().getTag()).formatted(curr.getType().getFormatting())) + .append(new LiteralText(curr.getType().getTag()).setStyle(Style.EMPTY.withColor(TextColor.fromRgb(curr.getType().getColor())))) .append(new LiteralText(" (" + curr.getGrade() + ") ").formatted(getScaleFormat(curr.getGrade()))) ); } @@ -71,7 +73,7 @@ public class CheckFunction { } } - private static Formatting getScaleFormat(int grade){ + public static Formatting getScaleFormat(int grade){ if (grade <= 5) return Formatting.WHITE; else if (grade < 9) diff --git a/src/main/java/net/saltymc/eaa/function/TagFunction.java b/src/main/java/net/saltymc/eaa/function/TagFunction.java index 435969d..9e09a2d 100644 --- a/src/main/java/net/saltymc/eaa/function/TagFunction.java +++ b/src/main/java/net/saltymc/eaa/function/TagFunction.java @@ -1,9 +1,9 @@ package net.saltymc.eaa.function; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.toast.SystemToast; import net.minecraft.text.Text; +import net.saltymc.eaa.custom.ping.TagDTO; import net.saltymc.eaa.util.database.DB_Player; import net.saltymc.eaa.util.database.DB_Tag; import net.saltymc.eaa.util.mojangApi.PlayerInfo; @@ -23,16 +23,18 @@ public class TagFunction { } } - public static DB_Tag.Type getScoreboardTag(String uuid){ - if (player_tags.containsKey(uuid)) - return player_tags.get(uuid).getType(); - else { + public static TagDTO getScoreboardTag(String uuid){ + if (player_tags.containsKey(uuid)) { + DB_Tag tag = player_tags.get(uuid); + return new TagDTO(tag.getGrade(), tag.getType()); + + } else { if (free) { free = false; loadPlayer(uuid, false); } } - return DB_Tag.Type.NOTLOADED; + return new TagDTO(-1, DB_Tag.Type.NOTLOADED); } public static void tagPlayer(String player, DB_Tag.Type tag, int grade, FabricClientCommandSource source){ diff --git a/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java b/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java index cac36f5..05dbf8a 100644 --- a/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java +++ b/src/main/java/net/saltymc/eaa/util/database/DB_Tag.java @@ -96,31 +96,30 @@ public class DB_Tag { public enum Type { HACKER( - "HAX", "PLayer who hacks", 0xaa0000, Formatting.RED + "HAX", "PLayer who hacks", 0xaa0000 ), FRIENDLY( - "FND", "Player you like", 0x55ff55, Formatting.GREEN + "FND", "Player you like", 0x55ff55 ), GOODPLAYER( - "PRO", "Fair player with good skill", 0xffaa00, Formatting.GOLD + "PRO", "Fair player with good skill", 0xffaa00 ), IDIOT( - "BAD", "Person who is annoying and bad", 0x55ffff, Formatting.AQUA + "A$$", "Person who is annoying and bad", 0x55ffff + ), NOOB( + "BAD", "Person with low skill", 0xff55ff ), NOTTAGGED( - "NaN", "Player is not tagged", 0x555555, Formatting.DARK_GRAY + "NaN", "Player is not tagged", 0x555555 ), NOTLOADED( - "---", "PLayer not loaded", 0xffffff, Formatting.WHITE + "---", "PLayer not loaded", 0xffffff ); String tag, description; int color; - Formatting formatting; - Type(String tag, String description, int color, Formatting formatting){ + Type(String tag, String description, int color){ this.tag = tag; this.description = description; this.color = color; - this.formatting = formatting; } - public String getTag() { return tag; } @@ -132,9 +131,5 @@ public class DB_Tag { public int getColor() { return color; } - - public Formatting getFormatting(){ - return formatting; - } } }