mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-20 15:18:52 -05:00
MutableText.onHover() now is actually drawn if text is being hovered
#480
This commit is contained in:
1 parent
4e2f7d3bc5
commit
4e9d45d38c
2 files changed
+17
-4
No files matched your search
@@ -122,16 +122,25 @@ fun drawText(
|
||||
y: Number,
|
||||
centered: Boolean = false,
|
||||
colour: Int,
|
||||
shadow: Boolean = true
|
||||
shadow: Boolean = true,
|
||||
pMouseX: Int? = null,
|
||||
pMouseY: Int? = null
|
||||
) {
|
||||
val comp = if (font == null) text else text.setStyle(text.style.withFont(font))
|
||||
val textRenderer = MinecraftClient.getInstance().textRenderer
|
||||
var x = x
|
||||
val width = textRenderer.getWidth(comp)
|
||||
if (centered) {
|
||||
val width = textRenderer.getWidth(comp)
|
||||
x = x.toDouble() - width / 2
|
||||
}
|
||||
context.drawText(textRenderer, comp, x.toInt(), y.toInt(), colour, shadow)
|
||||
|
||||
// Check is text is hovered
|
||||
if (pMouseY != null && pMouseX != null) {
|
||||
if (pMouseX >= x.toInt() && pMouseX <= x.toInt() + width && pMouseY >= y.toInt() && pMouseY <= y.toInt() + textRenderer.fontHeight) {
|
||||
context.drawHoverEvent(textRenderer, text.style, pMouseX, pMouseY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun drawText(
|
||||
|
||||
@@ -177,7 +177,9 @@ fun drawScaledText(
|
||||
maxCharacterWidth: Int = Int.MAX_VALUE,
|
||||
colour: Int = 0x00FFFFFF + ((opacity.toFloat() * 255).toInt() shl 24),
|
||||
centered: Boolean = false,
|
||||
shadow: Boolean = false
|
||||
shadow: Boolean = false,
|
||||
pMouseX: Int? = null,
|
||||
pMouseY: Int? = null
|
||||
) {
|
||||
if (opacity.toFloat() < 0.05F) {
|
||||
return
|
||||
@@ -197,7 +199,9 @@ fun drawScaledText(
|
||||
y = y.toFloat() / (scale * extraScale) + (1 - extraScale) * fontHeight * scale,
|
||||
centered = centered,
|
||||
colour = colour,
|
||||
shadow = shadow
|
||||
shadow = shadow,
|
||||
pMouseX = pMouseX,
|
||||
pMouseY = pMouseY
|
||||
)
|
||||
matrices.pop()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user