Add zeros to minutes and hours too in Clock.kt
This commit is contained in:
parent
104f1631e5
commit
59370fab4c
@ -3,23 +3,26 @@ package fr.username404.snowygui.gui.feature
|
|||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.Snowy.Companion.onEvent
|
import fr.username404.snowygui.Snowy.Companion.onEvent
|
||||||
import fr.username404.snowygui.gui.FontUtil
|
import fr.username404.snowygui.gui.FontUtil
|
||||||
|
import kotlinx.datetime.Clock as DatetimeClock
|
||||||
import kotlinx.datetime.TimeZone
|
import kotlinx.datetime.TimeZone
|
||||||
import kotlinx.datetime.toLocalDateTime
|
import kotlinx.datetime.toLocalDateTime
|
||||||
import kotlinx.datetime.Clock as DatetimeClock
|
|
||||||
|
|
||||||
@ButtonInfo(Category.MISC)
|
@ButtonInfo(Category.MISC)
|
||||||
object Clock: ButtonImpl() {
|
object Clock: ButtonImpl() {
|
||||||
private val currentTimezone = TimeZone.currentSystemDefault()
|
private val currentTimezone = TimeZone.currentSystemDefault()
|
||||||
|
override fun toString(): String = DatetimeClock.System.now().toLocalDateTime(currentTimezone).run {
|
||||||
|
arrayOf(hour, minute, second).map {
|
||||||
|
(it.takeIf { (it >= 10) } ?: "0$it").toString()
|
||||||
|
}.reduce { previous, current -> "$previous:$current"}
|
||||||
|
}
|
||||||
init {
|
init {
|
||||||
onEvent("HudRender") {
|
onEvent("HudRender") {
|
||||||
if (toggled) {
|
if (toggled) {
|
||||||
with(DatetimeClock.System.now().toLocalDateTime(currentTimezone)) {
|
FontUtil.drawScaled(it.first() as PoseStack,
|
||||||
FontUtil.drawScaled(it.first() as PoseStack,
|
this@Clock.toString(),
|
||||||
"$hour:$minute:${second.let { if (it >= 10) it else "0$it" }}",
|
5.0, 5.0,
|
||||||
5.0, 5.0,
|
0.85F, color = Colors.GOLD
|
||||||
0.85F, color = Colors.GOLD
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user