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 fr.username404.snowygui.Snowy.Companion.onEvent
|
||||
import fr.username404.snowygui.gui.FontUtil
|
||||
import kotlinx.datetime.Clock as DatetimeClock
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.toLocalDateTime
|
||||
import kotlinx.datetime.Clock as DatetimeClock
|
||||
|
||||
@ButtonInfo(Category.MISC)
|
||||
object Clock: ButtonImpl() {
|
||||
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 {
|
||||
onEvent("HudRender") {
|
||||
if (toggled) {
|
||||
with(DatetimeClock.System.now().toLocalDateTime(currentTimezone)) {
|
||||
FontUtil.drawScaled(it.first() as PoseStack,
|
||||
"$hour:$minute:${second.let { if (it >= 10) it else "0$it" }}",
|
||||
5.0, 5.0,
|
||||
0.85F, color = Colors.GOLD
|
||||
)
|
||||
}
|
||||
FontUtil.drawScaled(it.first() as PoseStack,
|
||||
this@Clock.toString(),
|
||||
5.0, 5.0,
|
||||
0.85F, color = Colors.GOLD
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue