aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/dulkirfabric/util
diff options
context:
space:
mode:
authoringlettronald <inglettronald@gmail.com>2023-07-23 08:59:42 -0500
committeringlettronald <inglettronald@gmail.com>2023-07-23 08:59:42 -0500
commit362f71b14f864c6d86e7c805e51cd64a8194d9fb (patch)
tree6681eed0ecb0564050d74f805a10b78208aa01dc /src/main/kotlin/com/dulkirfabric/util
parent6028973423c664e4a4626c577f4884cc4d92cbe0 (diff)
downloadDulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.gz
DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.tar.bz2
DulkirMod-Fabric-362f71b14f864c6d86e7c805e51cd64a8194d9fb.zip
improved usability of Title Util
Diffstat (limited to 'src/main/kotlin/com/dulkirfabric/util')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt b/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
index 02b79f7..327afdd 100644
--- a/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
+++ b/src/main/kotlin/com/dulkirfabric/util/HudRenderUtil.kt
@@ -1,11 +1,18 @@
package com.dulkirfabric.util
import com.dulkirfabric.DulkirModFabric.mc
+import com.dulkirfabric.events.HudRenderEvent
+import meteordevelopment.orbit.EventHandler
import net.minecraft.client.gui.DrawContext
import net.minecraft.text.Text
+import java.time.Duration
object HudRenderUtil {
- fun drawTitle(context: DrawContext, content: Text) {
+
+ private var curTitle: Text? = null
+ private var clearTime: Long = -1
+
+ private fun drawTitle(context: DrawContext, content: Text) {
val matrices = context.matrices
val tr = mc.textRenderer
val w = tr.getWidth(content)
@@ -16,4 +23,19 @@ object HudRenderUtil {
context.drawText(tr, content, 0, -tr.fontHeight / 2, -1, true)
matrices.pop()
}
+
+ fun drawTitle(content: Text, duration: Duration) {
+ curTitle = content
+ clearTime = System.currentTimeMillis() + duration.toMillis()
+ }
+
+ @EventHandler
+ fun onHudRender(event: HudRenderEvent) {
+ val content = curTitle ?: return
+ if (System.currentTimeMillis() >= clearTime) {
+ curTitle = null
+ return
+ }
+ drawTitle(event.context, content)
+ }
} \ No newline at end of file