package org.saturnclient.ui.components; import org.saturnclient.client.ServiceClient; import org.saturnclient.common.provider.Providers; import org.saturnclient.common.ref.asset.IdentifierRef; import org.saturnclient.config.Config; import org.saturnclient.config.Theme; import org.saturnclient.ui.Element; import org.saturnclient.ui.ElementContext; import org.saturnclient.ui.RenderScope; import org.saturnclient.ui.elements.Field; import org.saturnclient.ui.resources.Fonts; /** * The signed-in player: their skin's face, their name, and a dot that's green * while connected to Saturn. */ public class AccountChip extends Element { public static final int HEIGHT = 32; private static final int HEAD = 18; private static final int PADDING = 7; private static final int GAP = 8; private static final int DOT = 6; private static final float NAME_SCALE = 0.55f; private static final int CONNECTED = 0xFF7FD1A8; private final String name; public AccountChip() { String username = Providers.saturn.getClient().getUsername(); this.name = username != null ? username : "Player"; this.height = HEIGHT; this.width = PADDING + HEAD + GAP + (int) (Fonts.getWidth(name, Theme.FONT.value) * NAME_SCALE) + GAP + DOT + GAP + 2; } @Override public void render(RenderScope renderScope, ElementContext ctx) { renderScope.drawGlassRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value, Config.widgetBlur.value, 1, Theme.getPanelBg(), Theme.getBorder()); // The face, then the hat layer over it, from the 64x64 skin IdentifierRef skin = Providers.saturn.getPlayerSkin(); int headY = (height - HEAD) / 2; renderScope.drawTexture(skin, PADDING, headY, 8, 8, HEAD, HEAD, 8, 8, 64, 64); renderScope.drawTexture(skin, PADDING, headY, 40, 8, HEAD, HEAD, 8, 8, 64, 64); int nameX = PADDING + HEAD + GAP; renderScope.drawText(NAME_SCALE, name, nameX, Field.textY(height, NAME_SCALE), Theme.FONT.value, Theme.FOREGROUND.value); int dotX = nameX + (int) (Fonts.getWidth(name, Theme.FONT.value) * NAME_SCALE) + GAP; renderScope.drawRoundedRectangle(dotX, (height - DOT) / 2, DOT, DOT, DOT / 2, ServiceClient.isConnected() ? CONNECTED : Theme.withAlpha(0.3f, Theme.FOREGROUND.value)); } }