diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-04-03 21:17:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 21:17:57 +0200 |
commit | ad5879d319b236ddec744978dfaebebf91135209 (patch) | |
tree | 2f5ccdf6ec25b9d25b1a47163583e644033a8dbf /src/main/java/at/hannibal2 | |
parent | 82a65251bb57f87459a6ef664c6321542b5cfccc (diff) | |
download | skyhanni-ad5879d319b236ddec744978dfaebebf91135209.tar.gz skyhanni-ad5879d319b236ddec744978dfaebebf91135209.tar.bz2 skyhanni-ad5879d319b236ddec744978dfaebebf91135209.zip |
Backend: Renderable advanced Strings (#888)
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt index 8a57ded54..30b595186 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -292,19 +292,26 @@ interface Renderable { fun string( text: String, + scale: Double = 1.0, color: Color = Color.WHITE, horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, verticalAlign: VerticalAlignment = VerticalAlignment.TOP, ) = object : Renderable { - override val width: Int - get() = Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) - override val height = 10 + override val width by lazy { (Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) * scale).toInt() + 1 } + override val height = (9 * scale).toInt() + 1 override val horizontalAlign = horizontalAlign override val verticalAlign = verticalAlign + val inverseScale = 1 / scale + override fun render(posX: Int, posY: Int) { - Minecraft.getMinecraft().fontRendererObj.drawStringWithShadow(text, 1f, 1f, color.rgb) + val fontRenderer = Minecraft.getMinecraft().fontRendererObj + GlStateManager.translate(1.0, 1.0, 0.0) + GlStateManager.scale(scale, scale, 1.0) + fontRenderer.drawStringWithShadow(text, 0f, 0f, color.rgb) + GlStateManager.scale(inverseScale, inverseScale, 1.0) + GlStateManager.translate(-1.0, -1.0, 0.0) } } @@ -318,6 +325,47 @@ interface Renderable { } } + fun wrappedString( + text: String, + width: Int, + scale: Double = 1.0, + color: Color = Color.WHITE, + horizontalAlign: HorizontalAlignment = HorizontalAlignment.LEFT, + verticalAlign: VerticalAlignment = VerticalAlignment.TOP, + ) = object : Renderable { + + val list by lazy { + Minecraft.getMinecraft().fontRendererObj.listFormattedStringToWidth( + text, (width / scale).toInt() + ) + } + + override val width by lazy { + if (list.size == 1) { + (Minecraft.getMinecraft().fontRendererObj.getStringWidth(text) / scale).toInt() + 1 + } else { + (width / scale).toInt() + 1 + } + } + + override val height by lazy { list.size * ((9 * scale).toInt() + 1) } + override val horizontalAlign = horizontalAlign + override val verticalAlign = verticalAlign + + val inverseScale = 1 / scale + + override fun render(posX: Int, posY: Int) { + val fontRenderer = Minecraft.getMinecraft().fontRendererObj + GlStateManager.translate(1.0, 1.0, 0.0) + GlStateManager.scale(scale, scale, 1.0) + list.forEachIndexed { index, text -> + fontRenderer.drawStringWithShadow(text, 0f, index * 10.0f, color.rgb) + } + GlStateManager.scale(inverseScale, inverseScale, 1.0) + GlStateManager.translate(-1.0, -1.0, 0.0) + } + } + fun progressBar( percent: Double, startColor: Color = Color(255, 0, 0), |