From 34e9f01594e498ed16ebe55f51ba990948635456 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:14:49 +0200 Subject: Backend: MultiClickable (#1407) --- .../skyhanni/utils/renderables/Renderable.kt | 53 ++++++++++++++++++---- 1 file changed, 45 insertions(+), 8 deletions(-) (limited to 'src/main') 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 a73e408d6..09591c62d 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -83,7 +83,8 @@ interface Renderable { bypassChecks: Boolean = false, highlightsOnHoverSlots: List = emptyList(), condition: () -> Boolean = { true }, - ): Renderable = link(string(text), onClick, bypassChecks, highlightsOnHoverSlots = highlightsOnHoverSlots, condition) + ): Renderable = + link(string(text), onClick, bypassChecks, highlightsOnHoverSlots = highlightsOnHoverSlots, condition) fun link( renderable: Renderable, @@ -119,6 +120,20 @@ interface Renderable { ) } + fun multiClickAndHover( + text: Any, + tips: List, + bypassChecks: Boolean = false, + click: Map Unit>, + onHover: () -> Unit = {}, + ): Renderable { + return multiClickable( + hoverTips(text, tips, bypassChecks = bypassChecks, onHover = onHover), + click, + bypassChecks = bypassChecks + ) + } + fun clickable( render: Renderable, onClick: () -> Unit, @@ -141,6 +156,28 @@ interface Renderable { } } + fun multiClickable( + render: Renderable, + click: Map Unit>, + bypassChecks: Boolean = false, + condition: () -> Boolean = { true }, + ) = object : Renderable { + override val width = render.width + override val height = render.height + override val horizontalAlign = render.horizontalAlign + override val verticalAlign = render.verticalAlign + + override fun render(posX: Int, posY: Int) { + if (isHovered(posX, posY) && condition() && + shouldAllowLink(true, bypassChecks) + ) for ((button, onClick) in click) { + if ((button - 100).isKeyClicked()) + onClick() + } + render.render(posX, posY) + } + } + fun hoverTips( content: Any, tips: List, @@ -259,13 +296,13 @@ interface Renderable { override fun render(posX: Int, posY: Int) { val pair = Pair(posX, posY) - isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) { - hovered.render(posX, posY) - HighlightOnHoverSlot.currentSlots[pair] = highlightsOnHoverSlots - true - } else { - unhovered.render(posX, posY) - HighlightOnHoverSlot.currentSlots.remove(pair) + isHovered = if (isHovered(posX, posY) && condition() && shouldAllowLink(true, bypassChecks)) { + hovered.render(posX, posY) + HighlightOnHoverSlot.currentSlots[pair] = highlightsOnHoverSlots + true + } else { + unhovered.render(posX, posY) + HighlightOnHoverSlot.currentSlots.remove(pair) false } } -- cgit