package org.saturnclient.ui.components; import org.saturnclient.common.ref.asset.IdentifierRef; import org.saturnclient.config.Theme; import org.saturnclient.cosmetics.Emotes; import org.saturnclient.ui.Element; import org.saturnclient.ui.ElementContext; import org.saturnclient.ui.RenderScope; import org.saturnclient.ui.resources.Fonts; import org.saturnclient.ui.resources.Textures; /** * One emote in the emote wheel: its preview in its own colors and its name. * An emote without a preview shows an icon instead. */ public class EmoteTile extends Element { public static final int SIZE = 86; private static final int INSET = 6; private static final int NAME_AREA = 20; private static final int PLACEHOLDER = 26; private static final float NAME_SCALE = 0.56f; private final String name; /** The preview, or null when the emote has none */ private final IdentifierRef preview; private final Runnable onPlay; public EmoteTile(String emote, Runnable onPlay) { IdentifierRef texture = Textures.getEmotePreview(emote); this.name = Emotes.getName(emote); this.preview = Textures.exists(texture) ? texture : null; this.onPlay = onPlay; this.width = SIZE; this.height = SIZE; } @Override public void render(RenderScope renderScope, ElementContext ctx) { boolean hovered = ctx.isHovering(); renderScope.drawRoundedRectangle(0, 0, width, height, Theme.WIDGET_RADIUS.value, hovered ? 2 : 1, Theme.PRIMARY.value, hovered ? Theme.ACCENT.value : Theme.withAlpha(0.06f, Theme.FOREGROUND.value)); int imageSize = height - INSET * 2 - NAME_AREA; if (preview != null) { renderScope.drawTexture(preview, (width - imageSize) / 2, INSET, 0, 0, imageSize, imageSize); } else { int iconY = INSET + (imageSize - PLACEHOLDER) / 2; renderScope.drawTexture(Textures.ICON_EMOTE, (width - PLACEHOLDER) / 2, iconY, 0, 0, PLACEHOLDER, PLACEHOLDER, Theme.getMutedFg()); } String text = Fonts.ellipsize(name, Theme.FONT.value, NAME_SCALE, width - INSET * 2); int textX = (width - (int) (Fonts.getWidth(text, Theme.FONT.value) * NAME_SCALE)) / 2; int textY = height - INSET - NAME_AREA + (NAME_AREA - (int) (Fonts.getHeight() * NAME_SCALE)) / 2; renderScope.drawText(NAME_SCALE, text, textX, textY, Theme.FONT.value, hovered ? Theme.FOREGROUND.value : Theme.PRIMARY_FG.value); } @Override public void click(int mouseX, int mouseY) { onPlay.run(); } }