Fix and restyle the emote wheel
The slot index was taken before the middle slot was skipped, so page one showed emotes 0-4 and 6-8: emote 5 never appeared and emote 8 showed on two pages. Emotes now fill the eight cells around the middle in order, and slots past the last emote aren't drawn, so they can't play a null emote. Emotes show as EmoteTiles: the preview in its own colors (it was tinted, almost black on hover), the name under it, an accent outline on hover, and an icon when an emote has no preview. The middle cell holds the page and its arrows when there's more than one page. Emote names and cosmetic names share Utils.nameFromId. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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.withAlpha(0.72f, 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user