fix(mod): smaller module description plaque, tooltip auto-scale to GUI scale

Claude-Session: https://claude.ai/code/session_01F1M1Jic1wTSn4igUENynmZ
This commit is contained in:
loki5512344 2026-10-02 09:49:02 +02:00
parent 0504be5b57
commit e604a48c31
Signed by: boba
GPG key ID: 253067914055423B
5 changed files with 32 additions and 18 deletions

View file

@ -14,7 +14,7 @@ import java.util.List;
* cursor and fades out when nothing is hovered.
*/
final class ModulesMenuDescriptionRenderer {
private static final int MAX_LINES = 3;
private static final int MAX_LINES = 2;
private ModulesMenuDescriptionRenderer() {
}
@ -35,25 +35,25 @@ final class ModulesMenuDescriptionRenderer {
ModulesMenuChromeRenderer.ensureFonts();
TextRenderer titleFont = ModulesMenuChromeRenderer.medium;
TextRenderer bodyFont = ModulesMenuChromeRenderer.regular;
float titleSize = 9.0f * scale;
float bodySize = 7.5f * scale;
float pad = 9.0f * scale;
float w = Math.min(screen.areaW * 0.6f, 300.0f * scale);
float titleSize = 7.4f * scale;
float bodySize = 6.2f * scale;
float pad = 6.0f * scale;
float w = Math.min(screen.areaW * 0.36f, 190.0f * scale);
List<String> lines = DescriptionLines.wrap(screen.descText, w - pad * 2.0f,
s -> ClickGuiRenderer.textWidth(bodyFont, s, bodySize), MAX_LINES);
float titleH = ModulesMenuLayout.textHeight(titleFont, titleSize);
float lineH = ModulesMenuLayout.textHeight(bodyFont, bodySize) + 1.5f * scale;
float h = pad * 2.0f + titleH + 3.0f * scale + lines.size() * lineH;
float h = pad * 2.0f + titleH + 2.0f * scale + lines.size() * lineH;
float x = screen.areaX + (screen.areaW - w) * 0.5f;
float y = Math.max(screen.areaY + 6.0f * scale, panelsTop(screen) - h - 10.0f * scale) + (1.0f - alpha) * 6.0f * scale;
float y = Math.max(screen.areaY + 6.0f * scale, panelsTop(screen) - h - 8.0f * scale) + (1.0f - alpha) * 6.0f * scale;
float radius = 8.0f * scale;
float radius = 6.0f * scale;
ModulesMenuGlassRenderer.drawLiquidGlass(x, y, w, h, radius, false, alpha >= 0.999f ? 1.0f : alpha, scale);
int veil = ModulesMenuLayout.withAlpha(ModulesMenuStyle.panelBgGlassDark(), alpha * 0.35f);
LayoutRender2D.roundedQuad(x, y, w, h, radius, veil, veil, veil, veil);
ClickGuiRenderer.drawText(titleFont, screen.descTitle, x + pad, y + pad, titleSize,
ModulesMenuLayout.withAlpha(ModulesMenuStyle.text(), alpha), false);
float ty = y + pad + titleH + 3.0f * scale;
float ty = y + pad + titleH + 2.0f * scale;
int bodyColor = ModulesMenuLayout.withAlpha(ModulesMenuStyle.textMuted(), alpha);
for (String line : lines) {
ClickGuiRenderer.drawText(bodyFont, line, x + pad, ty, bodySize, bodyColor, false);

View file

@ -60,6 +60,7 @@ public final class BetterTooltips extends AbstractHudElement {
private final BooleanValue itemInfoColorize = bool("item_info_colorize", true);
private final ModeValue tooltipFont = mode("tooltip_font", "Iosevka", TOOLTIP_FONT_OPTIONS);
private final NumberValue<Float> tooltipTextSize = num("tooltip_text_size", 1.0f, 0.5f, 2.0f);
private final BooleanValue tooltipAutoScale = bool("tooltip_auto_scale", true);
private final ItemIdSetValue topIgnore = registerTopIgnore();
private final NumberValue<Float> shulkerPreviewSlotSize =
visibleWhen(num("shulker_slot_size", 18.0f, 12.0f, 24.0f), this::isShulkerPreviewEnabled);
@ -101,6 +102,13 @@ public final class BetterTooltips extends AbstractHudElement {
}
String tooltipFontValue() { return tooltipFont.get(); }
float tooltipTextSizeValue() { return tooltipTextSize.get(); }
/** Множитель под масштаб интерфейса: эталон GUI Scale 3, при 2 тултип крупнее, при 4 мельче. */
float tooltipAutoScale() {
if (!tooltipAutoScale.get()) return 1.0f;
double gui = Math.max(1.0, net.minecraft.client.Minecraft.getInstance().getWindow().getGuiScale());
return (float) Math.max(0.7, Math.min(2.2, 3.0 / gui));
}
UiScriptModuleHandle tooltipPanelHandle() { return tooltipPanelHandle; }
CachedUiScriptRuntime tooltipRuntime() { return tooltipRuntime; }

View file

@ -127,19 +127,23 @@ final class TooltipPanelRenderer {
if (tr == null) return;
PreviewLayout preview = ShulkerPreviewCache.buildLayout();
List<TooltipLine> finalLines = TooltipState.prepareLines(lines, preview != null);
float scale = BetterTooltips.TOOLTIP_TEXT_SCALE * TooltipState.getScaleOverride() * instance.tooltipTextSizeValue();
float auto = instance.tooltipAutoScale();
float scale = BetterTooltips.TOOLTIP_TEXT_SCALE * TooltipState.getScaleOverride() * instance.tooltipTextSizeValue() * auto;
int padX = Math.round(BetterTooltips.TOOLTIP_PAD_X * auto);
int padY = Math.round(BetterTooltips.TOOLTIP_PAD_Y * auto);
int titleGap = Math.round(BetterTooltips.TOOLTIP_TITLE_GAP * auto);
tr.begin(scale, false, false);
int maxW = 0;
for (TooltipLine l : finalLines) maxW = Math.max(maxW, (int) Math.ceil(tr.getWidth(l.text(), false)));
int lh = (int) Math.ceil(tr.getHeight(false));
tr.end();
if (finalLines.isEmpty()) finalLines = List.of(new TooltipLine(" ", Theme.theme().textPrimary()));
int textH = finalLines.size() * lh + (finalLines.size() > 1 ? BetterTooltips.TOOLTIP_TITLE_GAP : 0) + Math.max(0, finalLines.size() - 2) * BetterTooltips.TOOLTIP_LINE_GAP;
int textH = finalLines.size() * lh + (finalLines.size() > 1 ? titleGap : 0) + Math.max(0, finalLines.size() - 2) * BetterTooltips.TOOLTIP_LINE_GAP;
int pw = preview != null ? preview.width() : 0;
int ph = preview != null ? preview.height() : 0;
int contentW = Math.max(maxW, pw);
int totalW = contentW + BetterTooltips.TOOLTIP_PAD_X * 2;
int totalH = BetterTooltips.TOOLTIP_PAD_Y * 2 + textH + (preview != null ? BetterTooltips.TOOLTIP_PREVIEW_GAP + ph : 0);
int totalW = contentW + padX * 2;
int totalH = padY * 2 + textH + (preview != null ? BetterTooltips.TOOLTIP_PREVIEW_GAP + ph : 0);
int x = mouseX, y = mouseY;
if (pos != null) {
Vector2ic p = pos.positionTooltip(mc.getWindow().getGuiScaledWidth(), mc.getWindow().getGuiScaledHeight(), mouseX, mouseY, totalW, totalH);
@ -157,20 +161,20 @@ final class TooltipPanelRenderer {
ViewportContext.beginScaled(ctx);
boolean rendered = renderScripted(mc, Renderer2D.COLOR, tr, x, y, totalW, totalH, bg, tl, trc, br, bl, glow, BetterTooltips.TOOLTIP_STROKE_WIDTH, BetterTooltips.TOOLTIP_GLOW_SIZE, 1.0f, instance.tooltipPanelHandle(), instance.tooltipRuntime(), ctx);
if (!rendered) drawFallback(x, y, totalW, totalH, bg, tl, trc, br, bl, glow);
int tx = x + BetterTooltips.TOOLTIP_PAD_X, ty = y + BetterTooltips.TOOLTIP_PAD_Y;
int tx = x + padX, ty = y + padY;
tr.begin(scale, false, false);
for (int i = 0; i < finalLines.size(); i++) {
TooltipLine l = finalLines.get(i);
tr.render(l.text(), tx, ty, new RenderColor(l.color()), true);
ty += lh;
if (i == 0 && finalLines.size() > 1) ty += BetterTooltips.TOOLTIP_TITLE_GAP; else if (i + 1 < finalLines.size()) ty += BetterTooltips.TOOLTIP_LINE_GAP;
if (i == 0 && finalLines.size() > 1) ty += titleGap; else if (i + 1 < finalLines.size()) ty += BetterTooltips.TOOLTIP_LINE_GAP;
}
tr.end();
ViewportContext.end(ctx);
if (preview != null) {
int cw = totalW - BetterTooltips.TOOLTIP_PAD_X * 2;
int px = x + BetterTooltips.TOOLTIP_PAD_X + Math.max(0, (cw - preview.width()) / 2);
int py = y + BetterTooltips.TOOLTIP_PAD_Y + textH + BetterTooltips.TOOLTIP_PREVIEW_GAP;
int cw = totalW - padX * 2;
int px = x + padX + Math.max(0, (cw - preview.width()) / 2);
int py = y + padY + textH + BetterTooltips.TOOLTIP_PREVIEW_GAP;
ShulkerPreviewRenderer.render(preview, px, py, ctx);
}
}

View file

@ -2925,6 +2925,7 @@
"setting.common.shulker_bg_softness": "Background softness",
"setting.common.shulker_padding": "Padding",
"setting.common.tooltip_font": "Tooltip font",
"setting.common.tooltip_auto_scale": "Auto-scale to GUI scale",
"setting.common.tooltip_text_size": "Tooltip text size",
"setting.common.shulker_preview": "Shulker Preview",
"setting.common.shulker_preview_hold": "Preview hold",

View file

@ -2729,6 +2729,7 @@
"setting.common.shulker_bg_softness": "Мягкость фона",
"setting.common.shulker_padding": "Отступ",
"setting.common.tooltip_font": "Шрифт тултипа",
"setting.common.tooltip_auto_scale": "Автоподстройка под размер интерфейса",
"setting.common.tooltip_text_size": "Размер текста тултипа",
"setting.common.shulker_preview": "Превью шалкера",
"setting.common.shulker_preview_hold": "Удержание превью",