aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/dulkirmod/utils/TitleUtils.kt
blob: f5c63253128efeac926f87bb4794ce6ee5eb8e78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package dulkirmod.utils

import dulkirmod.DulkirMod.Companion.mc
import dulkirmod.config.DulkirConfig
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.math.min

object TitleUtils {
    var curString = ""
    var endTime: Long = 0

    @SubscribeEvent
    fun onRender(event: RenderGameOverlayEvent.Text) {
        if (System.currentTimeMillis() > endTime) return
        val width = mc.fontRendererObj.getStringWidth(curString)
        val screenWidth = ScaledResolution(mc).scaledWidth_double
        val screenHeight = ScaledResolution(mc).scaledHeight_double
        var scale = ((screenWidth - 100) * DulkirConfig.bestiaryNotifSize) / width
        scale = min(scale, 10.0)
        GlStateManager.pushMatrix()
        GlStateManager.translate((screenWidth / 2 - width * scale / 2), screenHeight / 2 - (4.5 * scale), 0.0)
        GlStateManager.scale(scale, scale, scale)
        mc.fontRendererObj.drawString(curString, 0f, 0f, 0, DulkirConfig.bestiaryTextShadow)
        GlStateManager.popMatrix()
    }

    fun drawStringForTime(string: String, time: Int) {
        this.curString = string
        this.endTime = time.toLong() + System.currentTimeMillis()
    }

}