add new Tag, Use Style instead of Textformating, implement grade indicator, fix offset #6

Merged
hiajen merged 3 commits from #4-#3-add_new_tag_and_implement_grade_indication into master 2021-06-25 22:07:33 +02:00
7 changed files with 62 additions and 29 deletions
Showing only changes of commit dead4f21a8 - Show all commits

View file

@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 1.0.1 mod_version = 1.0.2
maven_group = net.saltymc.eaa maven_group = net.saltymc.eaa
archives_base_name = EAA_MOD archives_base_name = EAA_MOD

View file

@ -27,7 +27,6 @@ import net.minecraft.text.OrderedText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
import net.saltymc.eaa.function.TagFunction; import net.saltymc.eaa.function.TagFunction;
import net.saltymc.eaa.util.database.DB_Tag;
/** /**
* By: https://github.com/vladmarica/better-ping-display-fabric/ * By: https://github.com/vladmarica/better-ping-display-fabric/
@ -165,9 +164,11 @@ public final class CustomPlayerListHud {
* PLAYER TAG * PLAYER TAG
*/ */
int offset_tag_playername = aa; int offset_tag_playername = aa;
DB_Tag.Type playerTAG = TagFunction.getScoreboardTag(player.getProfile().getId().toString()); TagDTO playerTAG = TagFunction.getScoreboardTag(player.getProfile().getId().toString());
mc.textRenderer.drawWithShadow(stack, playerTAG.getTag(), (float)aa, (float)ab, playerTAG.getColor()); mc.textRenderer.drawWithShadow(stack, playerTAG.getType().getTag(), (float)aa, (float)ab, playerTAG.getType().getColor());
offset_tag_playername += mc.textRenderer.getWidth(playerTAG.getTag()) + 2; 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); Text playerName = hud.getPlayerName(player);
@ -178,7 +179,7 @@ public final class CustomPlayerListHud {
} }
if (obj != null && player.getGameMode() != GameMode.SPECTATOR) { if (obj != null && player.getGameMode() != GameMode.SPECTATOR) {
int ag = aa + i + 1; int ag = offset_tag_playername + i + 1;
ah = ag + q; ah = ag + q;
if (ah - ag > 5) { if (ah - ag > 5) {
PlayerListHudUtil.renderScoreboardObjective(hud, stack, obj, ab, gameProfile.getName(), ag, ah, player); PlayerListHudUtil.renderScoreboardObjective(hud, stack, obj, ab, gameProfile.getName(), ag, ah, player);

View file

@ -33,7 +33,7 @@ public class PingColors {
computeOffset(PING_MID, PING_END, Math.min(ping, PING_END))); 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); float offset = (value - start) / (float) ( end - start);
return MathHelper.clamp(offset, 0.0F, 1.0F); return MathHelper.clamp(offset, 0.0F, 1.0F);
} }

View file

@ -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));
}
}

View file

@ -4,7 +4,9 @@ import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.saltymc.eaa.util.database.DB_Player; import net.saltymc.eaa.util.database.DB_Player;
import net.saltymc.eaa.util.database.DB_Tag; 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) source.sendFeedback(new LiteralText(dateformat.format(curr.getTagDate())).formatted(Formatting.GRAY)
.append(new LiteralText(" | ")) .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()))) .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) if (grade <= 5)
return Formatting.WHITE; return Formatting.WHITE;
else if (grade < 9) else if (grade < 9)

View file

@ -1,9 +1,9 @@
package net.saltymc.eaa.function; package net.saltymc.eaa.function;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource; import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.toast.SystemToast; import net.minecraft.client.toast.SystemToast;
import net.minecraft.text.Text; 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_Player;
import net.saltymc.eaa.util.database.DB_Tag; import net.saltymc.eaa.util.database.DB_Tag;
import net.saltymc.eaa.util.mojangApi.PlayerInfo; import net.saltymc.eaa.util.mojangApi.PlayerInfo;
@ -23,16 +23,18 @@ public class TagFunction {
} }
} }
public static DB_Tag.Type getScoreboardTag(String uuid){ public static TagDTO getScoreboardTag(String uuid){
if (player_tags.containsKey(uuid)) if (player_tags.containsKey(uuid)) {
return player_tags.get(uuid).getType(); DB_Tag tag = player_tags.get(uuid);
else { return new TagDTO(tag.getGrade(), tag.getType());
} else {
if (free) { if (free) {
free = false; free = false;
loadPlayer(uuid, 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){ public static void tagPlayer(String player, DB_Tag.Type tag, int grade, FabricClientCommandSource source){

View file

@ -96,31 +96,30 @@ public class DB_Tag {
public enum Type { public enum Type {
HACKER( HACKER(
"HAX", "PLayer who hacks", 0xaa0000, Formatting.RED "HAX", "PLayer who hacks", 0xaa0000
), FRIENDLY( ), FRIENDLY(
"FND", "Player you like", 0x55ff55, Formatting.GREEN "FND", "Player you like", 0x55ff55
), GOODPLAYER( ), GOODPLAYER(
"PRO", "Fair player with good skill", 0xffaa00, Formatting.GOLD "PRO", "Fair player with good skill", 0xffaa00
), IDIOT( ), 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( ), NOTTAGGED(
"NaN", "Player is not tagged", 0x555555, Formatting.DARK_GRAY "NaN", "Player is not tagged", 0x555555
), NOTLOADED( ), NOTLOADED(
"---", "PLayer not loaded", 0xffffff, Formatting.WHITE "---", "PLayer not loaded", 0xffffff
); );
String tag, description; String tag, description;
int color; int color;
Formatting formatting;
Type(String tag, String description, int color, Formatting formatting){ Type(String tag, String description, int color){
this.tag = tag; this.tag = tag;
this.description = description; this.description = description;
this.color = color; this.color = color;
this.formatting = formatting;
} }
public String getTag() { public String getTag() {
return tag; return tag;
} }
@ -132,9 +131,5 @@ public class DB_Tag {
public int getColor() { public int getColor() {
return color; return color;
} }
public Formatting getFormatting(){
return formatting;
}
} }
} }