Search in sources :

Example 1 with RenderableGlyph

use of net.minecraft.client.font.RenderableGlyph in project SpeedRunIGT by RedLime.

the class TimerDrawer method draw.

public void draw() {
    if (!toggle)
        return;
    client.getProfiler().push("create");
    MutableText igtText = getIGTText();
    MutableText rtaText = getRTAText();
    client.getProfiler().swap("font");
    // 폰트 조정
    float fontHeight = 8;
    FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
    if (getTimerFont() != MinecraftClient.DEFAULT_FONT_ID && fontManager.getFontStorages().containsKey(getTimerFont())) {
        rtaText.setStyle(rtaText.getStyle().withFont(getTimerFont()));
        igtText.setStyle(igtText.getStyle().withFont(getTimerFont()));
        fontHeight = fontHeightMap.computeIfAbsent(getTimerFont().toString(), key -> {
            RenderableGlyph glyph = ((FontStorageAccessor) fontManager.getFontStorages().get(getTimerFont())).invokeRenderableGlyph('I');
            return glyph.getHeight() / glyph.getOversample();
        });
    }
    // 초기 값 조정
    client.getProfiler().swap("init");
    TimerElement igtTimerElement = new TimerElement();
    TimerElement rtaTimerElement = new TimerElement();
    rtaTimerElement.init(rtaXPos, rtaYPos, rtaScale, rtaText, rtaColor, rtaDecoration, fontHeight);
    igtTimerElement.init(igtXPos, igtYPos, igtScale, igtText, igtColor, igtDecoration, fontHeight);
    MatrixStack matrixStack = new MatrixStack();
    // 배경 렌더
    client.getProfiler().swap("background");
    if (bgOpacity > 0.01f) {
        Position rtaMin = new Position(rtaTimerElement.getPosition().getX() - rtaPadding, rtaTimerElement.getPosition().getY() - rtaPadding);
        Position rtaMax = new Position(rtaMin.getX() + rtaTimerElement.getScaledTextWidth() + ((rtaPadding - 1) + rtaPadding), rtaMin.getY() + rtaTimerElement.getScaledTextHeight() + ((rtaPadding - 1) + rtaPadding));
        Position igtMin = new Position(igtTimerElement.getPosition().getX() - igtPadding, igtTimerElement.getPosition().getY() - igtPadding);
        Position igtMax = new Position(igtMin.getX() + igtTimerElement.getScaledTextWidth() + ((igtPadding - 1) + igtPadding), igtMin.getY() + igtTimerElement.getScaledTextHeight() + ((igtPadding - 1) + igtPadding));
        int opacity = BackgroundHelper.ColorMixer.getArgb((int) (bgOpacity * 255), 0, 0, 0);
        if (rtaMin.getX() < igtMax.getX() && rtaMin.getY() < igtMax.getY() && igtMin.getX() < rtaMax.getX() && igtMin.getY() < rtaMax.getY()) {
            DrawableHelper.fill(matrixStack, Math.min(rtaMin.getX(), igtMin.getX()), Math.min(rtaMin.getY(), igtMin.getY()), Math.max(rtaMax.getX(), igtMax.getX()), Math.max(rtaMax.getY(), igtMax.getY()), opacity);
        } else {
            if (rtaScale != 0)
                DrawableHelper.fill(matrixStack, rtaMin.getX(), rtaMin.getY(), rtaMax.getX(), rtaMax.getY(), opacity);
            if (igtScale != 0)
                DrawableHelper.fill(matrixStack, igtMin.getX(), igtMin.getY(), igtMax.getX(), igtMax.getY(), opacity);
        }
    }
    // 렌더
    client.getProfiler().swap("draw");
    if (igtScale != 0)
        igtTimerElement.draw(matrixStack, translateZ);
    if (rtaScale != 0)
        rtaTimerElement.draw(matrixStack, translateZ);
    client.getProfiler().pop();
}
Also used : MutableText(net.minecraft.text.MutableText) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) SpeedRunOption(com.redlimerl.speedrunigt.option.SpeedRunOption) SpeedRunOptions(com.redlimerl.speedrunigt.option.SpeedRunOptions) LiteralText(net.minecraft.text.LiteralText) FontStorageAccessor(com.redlimerl.speedrunigt.mixins.access.FontStorageAccessor) MatrixStack(net.minecraft.client.util.math.MatrixStack) HashMap(java.util.HashMap) TimerDecimals(com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecimals) MinecraftClientAccessor(com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor) DrawableHelper(net.minecraft.client.gui.DrawableHelper) TimerDecoration(com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecoration) RenderableGlyph(net.minecraft.client.font.RenderableGlyph) MutableText(net.minecraft.text.MutableText) Identifier(net.minecraft.util.Identifier) MinecraftClient(net.minecraft.client.MinecraftClient) BackgroundHelper(net.minecraft.client.gui.hud.BackgroundHelper) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) MatrixStack(net.minecraft.client.util.math.MatrixStack) RenderableGlyph(net.minecraft.client.font.RenderableGlyph)

Aggregations

FontManagerAccessor (com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor)1 FontStorageAccessor (com.redlimerl.speedrunigt.mixins.access.FontStorageAccessor)1 MinecraftClientAccessor (com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor)1 SpeedRunOption (com.redlimerl.speedrunigt.option.SpeedRunOption)1 SpeedRunOptions (com.redlimerl.speedrunigt.option.SpeedRunOptions)1 TimerDecimals (com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecimals)1 TimerDecoration (com.redlimerl.speedrunigt.option.SpeedRunOptions.TimerDecoration)1 HashMap (java.util.HashMap)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 RenderableGlyph (net.minecraft.client.font.RenderableGlyph)1 DrawableHelper (net.minecraft.client.gui.DrawableHelper)1 BackgroundHelper (net.minecraft.client.gui.hud.BackgroundHelper)1 MatrixStack (net.minecraft.client.util.math.MatrixStack)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1 Identifier (net.minecraft.util.Identifier)1