[/B]
package sweetie.evaware.client.ui.widget.overlay;
import com.nimbusds.oauth2.sdk.id.Identifier;
import net.minecraft.client.texture.AbstractTexture;
import net.minecraft.client.util.math.MatrixStack;
import sweetie.evaware.api.utils.media.MediaUtils;
import sweetie.evaware.api.utils.render.RenderUtil;
import sweetie.evaware.api.utils.render.fonts.Font;
import sweetie.evaware.api.utils.render.fonts.Fonts;
import sweetie.evaware.client.features.modules.render.InterfaceModule;
import sweetie.evaware.client.ui.widget.Widget;
import java.awt.*;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class MusicBarWidget extends Widget {
private static final char WIFI_GLYPH = 'D';
private Font iconFont;
private float[] waveHeights;
private float[] waveTargets;
private long lastWaveUpdate = 0L;
public MusicBarWidget() {
super(0f, 8f);
}
@Override
public String getName() {
return "MusicBar";
}
@Override
public void render(MatrixStack matrixStack) {
if (!InterfaceModule.getInstance().watermarkElements.isEnabled("MusicBar")) {
return;
}
MediaUtils.MediaInfo mediaInfo = MediaUtils.getCurrentMedia();
if (mediaInfo == null) return;
String title = mediaInfo.title == null ? "" : mediaInfo.title;
String artist = mediaInfo.artist == null ? "" : mediaInfo.artist;
String label = artist.isEmpty() ? title : (title + " - " + artist);
if (label.isEmpty()) return;
AbstractTexture artTexture = mediaInfo.getTexture();
if (artTexture == null) return;
float screenWidth = mc.getWindow().getScaledWidth();
Font font = Fonts.SF_REGULAR;
float fontSize = scaled(8.0f);
float padding = scaled(7.0f);
float artSize = scaled(14.0f);
float radius = scaled(6.6f);
String timeStr = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm"));
float timeWidth = font.getWidth(timeStr, fontSize);
float timeGap = scaled(7.0f);
int bars = 4;
float barWidth = scaled(3.0f);
float barGap = scaled(1.7f);
float waveBlockWidth = bars * barWidth + (bars - 1) * barGap + scaled(4.0f);
float maxTextWidth = scaled(170.0f);
String text = trimToWidth(font, label, fontSize, maxTextWidth);
float textWidth = font.getWidth(text, fontSize);
float wifiSize = scaled(9.0f);
Font wifiFont = getIconFont();
float wifiWidth = wifiFont != null ? wifiFont.getWidth(String.valueOf(WIFI_GLYPH), wifiSize) : 0.0f;
float wifiGap = scaled(8.0f);
float panelWidth = padding + artSize + scaled(7.0f) + textWidth + scaled(9.0f)
+ waveBlockWidth + padding - scaled(5.9f);
float height = scaled(19.6f) - scaled(2.1f);
float totalWidth = timeWidth + timeGap + panelWidth + wifiGap + wifiWidth;
float groupX = (screenWidth - totalWidth) / 2.0f;
float y = getDraggable().getY();
float barX = groupX + timeWidth + timeGap;
float centerY = y + height / 2.0f;
font.drawText(matrixStack, timeStr, groupX, centerY +1.0f - (fontSize / 2.0f) - scaled(0.9f), fontSize, new Color(0, 0, 0, 255));
RenderUtil.BLUR_RECT.draw(matrixStack, barX, y, panelWidth, height, radius, new Color(255, 255, 255, 200));
RenderUtil.RECT.draw(matrixStack, barX, y, panelWidth, height, radius, new Color(0, 0, 0, 120));
float currentX = barX + padding;
drawTexture(matrixStack, artTexture, currentX, centerY - artSize / 2.0f, artSize, artSize, scaled(5.5f));
currentX += artSize + scaled(3.0f);
font.drawText(matrixStack, text, currentX, centerY +1.1f - (fontSize / 2.0f) - scaled(1.0f), fontSize, new Color(255, 255, 255, 255));
currentX += textWidth + scaled(9.0f);
updateMusicWave(bars);
float barBaseY = centerY + scaled(5.0f);
for (int i = 0; i < bars; i++) {
float barHeight = waveHeights[i];
RenderUtil.RECT.draw(matrixStack,
currentX + i * (barWidth + barGap),
barBaseY - barHeight,
barWidth,
barHeight,
scaled(1.0f),
new Color(255, 255, 255, 255));
}
if (wifiFont != null) {
float wifiX = barX + panelWidth + wifiGap;
wifiFont.drawText(matrixStack, String.valueOf(WIFI_GLYPH), wifiX, centerY - (wifiSize / 2.0f) - scaled(1.0f), wifiSize,
new Color(0, 0, 0, 200));
}
getDraggable().setWidth(totalWidth);
getDraggable().setHeight(height);
getDraggable().setX(groupX);
}
private void drawTexture(MatrixStack matrixStack, AbstractTexture texture, float x, float y, float w, float h, float radius) {
RenderUtil.TEXTURE_RECT.draw(matrixStack, x, y, w, h, radius, new Color(255, 255, 255, 255), 0f, 0f, 1f, 1f, texture.getGlId());
}
private String trimToWidth(Font font, String text, float size, float maxWidth) {
if (font.getWidth(text, size) <= maxWidth) return text;
String trimmed = text;
while (trimmed.length() > 3 && font.getWidth(trimmed + "...", size) > maxWidth) {
trimmed = trimmed.substring(0, trimmed.length() - 1);
}
return trimmed.length() > 3 ? trimmed + "..." : trimmed;
}
private void updateMusicWave(int bars) {
if (waveHeights == null || waveHeights.length != bars) {
waveHeights = new float[bars];
waveTargets = new float[bars];
for (int i = 0; i < bars; i++) {
waveHeights[i] = scaled(5.0f);
waveTargets[i] = scaled(5.0f);
}
}
if (System.currentTimeMillis() - lastWaveUpdate > 150) {
lastWaveUpdate = System.currentTimeMillis();
for (int i = 0; i < bars; i++) {
waveTargets[i] = scaled(3.0f) + (float) (Math.random() * scaled(10.0f));
}
}
for (int i = 0; i < bars; i++) {
waveHeights[i] += (waveTargets[i] - waveHeights[i]) * 0.5f;
}
}
private Font getIconFont() {
if (iconFont != null) return iconFont;
if (mc.getResourceManager() == null) return null;
iconFont = Font.builder().find("dettex/iconf").load();
return iconFont;
}
}
[B]