diff --git a/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt b/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt index e8013a8..73875fc 100644 --- a/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt +++ b/src/main/kotlin/net/shadowfacts/cacao/view/button/AbstractButton.kt @@ -1,6 +1,7 @@ package net.shadowfacts.cacao.view.button import net.minecraft.client.util.math.MatrixStack +import net.minecraft.text.Text import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.util.MouseButton import net.shadowfacts.cacao.util.texture.NinePatchTexture @@ -58,6 +59,11 @@ abstract class AbstractButton>(val content: View, val */ var disabledBackground: View? = NinePatchView(NinePatchTexture.BUTTON_DISABLED_BG) + /** + * The tooltip text shown when this button is hovered. + */ + var tooltip: Text? = null + override fun wasAdded() { solver.dsl { addSubview(content) @@ -97,6 +103,10 @@ abstract class AbstractButton>(val content: View, val // don't draw subviews, otherwise all background views + content will get drawn RenderHelper.popMatrix() + + if (tooltip != null && mouse in bounds) { + window!!.drawTooltip(listOf(tooltip!!)) + } } override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean { diff --git a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/SettingButton.kt b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/SettingButton.kt index 330e592..b05d5c2 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/block/terminal/SettingButton.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/block/terminal/SettingButton.kt @@ -1,6 +1,5 @@ package net.shadowfacts.phycon.block.terminal -import net.minecraft.client.util.math.MatrixStack import net.shadowfacts.cacao.geometry.Point import net.shadowfacts.cacao.geometry.Size import net.shadowfacts.cacao.util.EnumHelper @@ -31,14 +30,15 @@ class SettingButton( get() = content as TextureView init { - updateTexture() + update() } - private fun updateTexture() { + private fun update() { textureView.texture = textureCache.getOrPut(key.value) { val uv = key.value.uv Texture(key.value.iconTexture, uv[0], uv[1]) } + tooltip = key.value.tooltip } override fun mouseClicked(point: Point, mouseButton: MouseButton): Boolean { @@ -53,20 +53,10 @@ class SettingButton( PhysicalConnectivityClient.terminalSettings[key] = newValue - updateTexture() + update() } return super.mouseClicked(point, mouseButton) } - override fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) { - super.draw(matrixStack, mouse, delta) - - if (mouse in bounds) { - key.value.tooltip?.also { - window!!.drawTooltip(listOf(it)) - } - } - } - }