package zenith.zov.client.hud.elements.component;
import zenith.zov.Zenith;
import zenith.zov.base.animations.base.Animation;
import zenith.zov.base.animations.base.Easing;
import zenith.zov.base.font.Font;
import zenith.zov.base.font.Fonts;
import zenith.zov.base.theme.Theme;
import zenith.zov.client.hud.elements.draggable.DraggableHudElement;
import zenith.zov.utility.render.display.base.BorderRadius;
import zenith.zov.utility.render.display.base.CustomDrawContext;
import zenith.zov.utility.render.display.base.color.ColorRGBA;
import zenith.zov.utility.render.display.shader.DrawUtil;
import java.util.Locale;
public class InformationComponent extends DraggableHudElement {
public InformationComponent(String name, float initialX, float initialY, float windowWidth, float windowHeight, float offsetX, float offsetY, Align align) {
super(name,initialX, initialY,windowWidth,windowHeight,offsetX,offsetY,align);
}
Animation cordsWidthAnimation = new Animation(200, Easing.QUAD_IN_OUT);
Animation speedWidthAnimation = new Animation(200, Easing.QUAD_IN_OUT);
@Override
public void render(CustomDrawContext ctx) {
float iconSize = 6f;
float verticalPadding = 6f;
float iconTextSpacing = 4f;
float cellPadding = 5f;
float borderRadius = 4f;
Theme theme = Zenith.getInstance().getThemeManager().getCurrentTheme();
ColorRGBA mainBgColor =theme.getForegroundColor();
ColorRGBA highlightBgColor = theme.getForegroundLight();
ColorRGBA iconColor =theme.getColor();
ColorRGBA textColor = theme.getWhite();
ColorRGBA grayTextColor = theme.getGrayLight();
Font font = Fonts.MEDIUM.getFont(6);
String ipText = "Singleplayer";
if (mc.getNetworkHandler() != null && mc.getNetworkHandler().getServerInfo() != null) {
ipText = mc.getNetworkHandler().getServerInfo().address;
if (ipText.contains(":")) {
ipText = ipText.split(":")[0];
}
}
int ping = 0;
if (mc.player != null && mc.player.networkHandler != null && mc.player.networkHandler.getPlayerListEntry(mc.player.getUuid()) != null) {
ping = mc.player.networkHandler.getPlayerListEntry(mc.player.getUuid()).getLatency();
}
String pingText = String.valueOf(ping);
float ipWidth = cellPadding * 2 + iconSize + iconTextSpacing + font.width(ipText);
float pingWidth = cellPadding * 2 + iconSize + iconTextSpacing + font.width(pingText) + font.width("ms");
ipWidth = cordsWidthAnimation.update(ipWidth);
pingWidth = speedWidthAnimation.update(pingWidth);
float totalWidth = ipWidth + pingWidth;
float totalHeight = iconSize + (verticalPadding * 2);
this.width = totalWidth;
this.height = totalHeight;
DrawUtil.drawBlurHud(ctx.getMatrices(), x, y, ipWidth + pingWidth, totalHeight, 21, BorderRadius.all(4), ColorRGBA.WHITE);
ctx.drawRoundedRect(x, y, ipWidth, totalHeight, BorderRadius.left(borderRadius, borderRadius), highlightBgColor);
ctx.drawRoundedRect(x + ipWidth, y, pingWidth, totalHeight, BorderRadius.right(borderRadius, borderRadius), mainBgColor);
ctx.enableScissor((int) x, (int) y, (int) (x + ipWidth), (int) (y + height));
float currentX = x + cellPadding;
float iconY = y + (totalHeight - iconSize) / 2f;
float textY = y + (totalHeight - font.height()) / 2f;
Font iconFont = Fonts.ICONS.getFont(6);
ctx.drawText(iconFont, "4", currentX, iconY, iconColor);
currentX += iconSize + iconTextSpacing;
ctx.drawText(font, ipText, currentX, textY, textColor);
ctx.disableScissor();
currentX = x + ipWidth + cellPadding;
ctx.enableScissor((int) currentX, (int) y, (int) (currentX + pingWidth), (int) (y + height));
ctx.drawText(iconFont, "H", currentX, iconY, iconColor);
currentX += iconSize + iconTextSpacing;
currentX = drawPrefixedText(ctx, font, pingText, "ms", currentX, textY, textColor, grayTextColor);
ctx.disableScissor();
ctx.drawRoundedBorder(x, y, ipWidth + pingWidth, totalHeight, 0.1f, BorderRadius.all(4), theme.getForegroundStroke());
DrawUtil.drawRoundedCorner(ctx.getMatrices(), x, y, ipWidth + pingWidth, totalHeight, 0.1f, 12, theme.getColor(), BorderRadius.all(4));
}
private float drawPrefixedText(CustomDrawContext ctx, Font font, String prefix, String value, float x, float y, ColorRGBA prefixColor, ColorRGBA valueColor) {
ctx.drawText(font, prefix, x, y, prefixColor);
float prefixWidth = font.width(prefix);
ctx.drawText(font, value, x + prefixWidth, y, valueColor);
return x + prefix.length()*3.8f +value.length()*3.8f;
}
}