Search in sources :

Example 1 with FontManagerAccessor

use of com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor in project SpeedRunIGT by RedLime.

the class TimerCustomizeScreen method render.

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    saveButton.active = changed;
    this.renderBackground(matrices);
    drawer.draw();
    this.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 16777215);
    if (!hide) {
        if (!igtButton.active || !rtaButton.active) {
            if (drawer.isLocked()) {
                drawCenteredText(matrices, this.textRenderer, new TranslatableText("speedrunigt.option.timer_position.description.lock"), this.width / 2, this.height / 2 - 80, 16777215);
            } else {
                drawCenteredText(matrices, this.textRenderer, new TranslatableText("speedrunigt.option.timer_position.description"), this.width / 2, this.height / 2 - 80, 16777215);
                drawCenteredText(matrices, this.textRenderer, new TranslatableText("speedrunigt.option.timer_position.description.move"), this.width / 2, this.height / 2 - 69, 16777215);
            }
        }
        if (!fontButton.active && client != null) {
            int c = fontPage * 3;
            FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
            for (int i = 0; i < fontSelectButtons.size(); i++) {
                if (c + i < availableFonts.size()) {
                    Identifier fontIdentifier = availableFonts.get(c + i);
                    LiteralText text = new LiteralText(fontIdentifier.getPath());
                    if (client != null && fontManager.getFontStorages().containsKey(fontIdentifier)) {
                        text.setStyle(text.getStyle().withFont(fontIdentifier));
                    } else {
                        text.append(new LiteralText(" (Unavailable)")).formatted(Formatting.RED);
                    }
                    if (fontIdentifier.toString().equals(drawer.getTimerFont().toString())) {
                        text.append(" [Selected]").formatted(Formatting.ITALIC);
                    }
                    drawCenteredText(matrices, this.textRenderer, text, this.width / 2 - 30, this.height / 2 - 11 + (i * 22), 16777215);
                }
            }
        }
    }
    super.render(matrices, mouseX, mouseY, delta);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) Identifier(net.minecraft.util.Identifier) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) LiteralText(net.minecraft.text.LiteralText)

Example 2 with FontManagerAccessor

use of com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor in project SpeedRunIGT by RedLime.

the class MinecraftClientMixin method onInit.

/**
 * Add import font system
 */
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/debug/DebugRenderer;<init>(Lnet/minecraft/client/MinecraftClient;)V", shift = At.Shift.BEFORE))
public void onInit(RunArgs args, CallbackInfo ci) {
    this.resourceManager.registerListener(new SinglePreparationResourceReloadListener<Map<Identifier, List<Font>>>() {

        @Override
        protected Map<Identifier, List<Font>> prepare(ResourceManager manager, Profiler profiler) {
            SpeedRunIGT.FONT_MAPS.clear();
            try {
                HashMap<Identifier, List<Font>> map = new HashMap<>();
                File[] fontFiles = SpeedRunIGT.FONT_PATH.toFile().listFiles();
                if (fontFiles == null)
                    return new HashMap<>();
                for (File file : Arrays.stream(fontFiles).filter(file -> file.getName().endsWith(".ttf")).collect(Collectors.toList())) {
                    File config = SpeedRunIGT.FONT_PATH.resolve(file.getName().substring(0, file.getName().length() - 4) + ".json").toFile();
                    if (config.exists()) {
                        FontUtils.addFont(map, file, config);
                    } else {
                        FontUtils.addFont(map, file, null);
                    }
                }
                return map;
            } catch (Throwable e) {
                return new HashMap<>();
            }
        }

        @Override
        protected void apply(Map<Identifier, List<Font>> loader, ResourceManager manager, Profiler profiler) {
            try {
                FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) MinecraftClient.getInstance()).getFontManager();
                for (Map.Entry<Identifier, List<Font>> listEntry : loader.entrySet()) {
                    FontStorage fontStorage = new FontStorage(fontManager.getTextureManager(), listEntry.getKey());
                    fontStorage.setFonts(listEntry.getValue());
                    fontManager.getFontStorages().put(listEntry.getKey(), fontStorage);
                }
                TimerDrawer.fontHeightMap.clear();
            } catch (Throwable e) {
                SpeedRunIGT.error("Error! failed import timer fonts!");
                e.printStackTrace();
            }
        }
    });
}
Also used : MinecraftClientAccessor(com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor) HashMap(java.util.HashMap) ReloadableResourceManager(net.minecraft.resource.ReloadableResourceManager) ResourceManager(net.minecraft.resource.ResourceManager) Font(net.minecraft.client.font.Font) Identifier(net.minecraft.util.Identifier) Profiler(net.minecraft.util.profiler.Profiler) FontStorage(net.minecraft.client.font.FontStorage) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with FontManagerAccessor

use of com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor in project SpeedRunIGT by RedLime.

the class TimerCustomizeScreen method init.

@Override
protected void init() {
    normalOptions.clear();
    igtOptions.clear();
    rtaOptions.clear();
    fontOptions.clear();
    availableFonts.clear();
    fontSelectButtons.clear();
    backgroundOptions.clear();
    if (client != null) {
        FontManagerAccessor fontManager = (FontManagerAccessor) ((MinecraftClientAccessor) client).getFontManager();
        if (!fontManager.getFontStorages().containsKey(drawer.getTimerFont())) {
            availableFonts.add(drawer.getTimerFont());
        }
        availableFonts.addAll(fontManager.getFontStorages().keySet());
    }
    initNormal();
    initIGTButtons();
    initRTAButtons();
    initFontButtons();
    initBackgroundButtons();
    this.normalButton = addButton(new ButtonWidget(width / 2 - 149, height / 2 - 48, 58, 20, new TranslatableText("options.title").append("..."), (ButtonWidget button) -> openTab(0)));
    this.igtButton = addButton(new ButtonWidget(width / 2 - 89, height / 2 - 48, 58, 20, new LiteralText("IGT..."), (ButtonWidget button) -> openTab(1)));
    this.rtaButton = addButton(new ButtonWidget(width / 2 - 29, height / 2 - 48, 58, 20, new LiteralText("RTA..."), (ButtonWidget button) -> openTab(2)));
    this.fontButton = addButton(new ButtonWidget(width / 2 + 31, height / 2 - 48, 58, 20, new TranslatableText("speedrunigt.title.font"), (ButtonWidget button) -> {
        openTab(3);
        openFontPage();
    }));
    this.backgroundButton = addButton(new ButtonWidget(width / 2 + 91, height / 2 - 48, 58, 20, new TranslatableText("speedrunigt.title.background"), (ButtonWidget button) -> openTab(4)));
    addButton(new ButtonWidget(width / 2 - 89, height / 2 + 62, 58, 20, new TranslatableText("speedrunigt.option.hide"), (ButtonWidget button) -> {
        hide = !hide;
        for (AbstractButtonWidget normalOption : normalOptions) {
            normalOption.visible = !hide && currentTab == 0;
        }
        for (AbstractButtonWidget igtOption : igtOptions) {
            igtOption.visible = !hide && currentTab == 1;
        }
        for (AbstractButtonWidget rtaOption : rtaOptions) {
            rtaOption.visible = !hide && currentTab == 2;
        }
        for (AbstractButtonWidget fontOption : fontOptions) {
            fontOption.visible = !hide && currentTab == 3;
        }
        for (AbstractButtonWidget backgroundOption : backgroundOptions) {
            backgroundOption.visible = !hide && currentTab == 4;
        }
        openTab(currentTab);
        button.setMessage(new TranslatableText("speedrunigt.option." + (!hide ? "hide" : "show")));
    }));
    this.saveButton = addButton(new ButtonWidget(width / 2 - 29, height / 2 + 62, 58, 20, new TranslatableText("selectWorld.edit.save"), (ButtonWidget button) -> {
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_POSITION_X, drawer.getIGT_XPos());
        SpeedRunIGT.TIMER_DRAWER.setIGT_XPos(drawer.getIGT_XPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_POSITION_Y, drawer.getIGT_YPos());
        SpeedRunIGT.TIMER_DRAWER.setIGT_YPos(drawer.getIGT_YPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_SCALE, drawer.getIGTScale());
        SpeedRunIGT.TIMER_DRAWER.setIGTScale(drawer.getIGTScale());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_COLOR, drawer.getIGTColor());
        SpeedRunIGT.TIMER_DRAWER.setIGTColor(drawer.getIGTColor());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_IGT_DECO, drawer.getIGTDecoration());
        SpeedRunIGT.TIMER_DRAWER.setIGTDecoration(drawer.getIGTDecoration());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_POSITION_X, drawer.getRTA_XPos());
        SpeedRunIGT.TIMER_DRAWER.setRTA_XPos(drawer.getRTA_XPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_POSITION_Y, drawer.getRTA_YPos());
        SpeedRunIGT.TIMER_DRAWER.setRTA_YPos(drawer.getRTA_YPos());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_SCALE, drawer.getRTAScale());
        SpeedRunIGT.TIMER_DRAWER.setRTAScale(drawer.getRTAScale());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_COLOR, drawer.getRTAColor());
        SpeedRunIGT.TIMER_DRAWER.setRTAColor(drawer.getRTAColor());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_RTA_DECO, drawer.getRTADecoration());
        SpeedRunIGT.TIMER_DRAWER.setRTADecoration(drawer.getRTADecoration());
        SpeedRunOption.setOption(SpeedRunOptions.DISPLAY_TIME_ONLY, drawer.isSimplyTimer());
        SpeedRunIGT.TIMER_DRAWER.setSimplyTimer(drawer.isSimplyTimer());
        SpeedRunOption.setOption(SpeedRunOptions.LOCK_TIMER_POSITION, drawer.isLocked());
        SpeedRunIGT.TIMER_DRAWER.setLocked(drawer.isLocked());
        SpeedRunOption.setOption(SpeedRunOptions.DISPLAY_DECIMALS, drawer.getTimerDecimals());
        SpeedRunIGT.TIMER_DRAWER.setTimerDecimals(drawer.getTimerDecimals());
        SpeedRunOption.setOption(SpeedRunOptions.TIMER_TEXT_FONT, drawer.getTimerFont());
        SpeedRunIGT.TIMER_DRAWER.setTimerFont(drawer.getTimerFont());
        SpeedRunOption.setOption(SpeedRunOptions.BACKGROUND_OPACITY, drawer.getBGOpacity());
        SpeedRunIGT.TIMER_DRAWER.setBGOpacity(drawer.getBGOpacity());
        SpeedRunOption.setOption(SpeedRunOptions.RTA_BACKGROUND_PADDING, drawer.getRTAPadding());
        SpeedRunIGT.TIMER_DRAWER.setRTAPadding(drawer.getRTAPadding());
        SpeedRunOption.setOption(SpeedRunOptions.IGT_BACKGROUND_PADDING, drawer.getIGTPadding());
        SpeedRunIGT.TIMER_DRAWER.setIGTPadding(drawer.getIGTPadding());
        changed = false;
    }));
    addButton(new ButtonWidget(width / 2 + 31, height / 2 + 62, 58, 20, ScreenTexts.CANCEL, (ButtonWidget button) -> {
        if (client != null)
            client.openScreen(parent);
    }));
    fontConfigButton.visible = false;
    openTab(0);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) FontManagerAccessor(com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) AbstractButtonWidget(net.minecraft.client.gui.widget.AbstractButtonWidget) LiteralText(net.minecraft.text.LiteralText)

Example 4 with FontManagerAccessor

use of com.redlimerl.speedrunigt.mixins.access.FontManagerAccessor 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)4 LiteralText (net.minecraft.text.LiteralText)3 Identifier (net.minecraft.util.Identifier)3 MinecraftClientAccessor (com.redlimerl.speedrunigt.mixins.access.MinecraftClientAccessor)2 HashMap (java.util.HashMap)2 TranslatableText (net.minecraft.text.TranslatableText)2 FontStorageAccessor (com.redlimerl.speedrunigt.mixins.access.FontStorageAccessor)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 File (java.io.File)1 List (java.util.List)1 Map (java.util.Map)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 Font (net.minecraft.client.font.Font)1 FontStorage (net.minecraft.client.font.FontStorage)1 RenderableGlyph (net.minecraft.client.font.RenderableGlyph)1 DrawableHelper (net.minecraft.client.gui.DrawableHelper)1 BackgroundHelper (net.minecraft.client.gui.hud.BackgroundHelper)1