aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-04-15 20:14:49 +0200
committerGitHub <noreply@github.com>2024-04-15 20:14:49 +0200
commit34e9f01594e498ed16ebe55f51ba990948635456 (patch)
treed311d985605ddad153aeb9f0c585f3b93eb341f2 /src/main/java/at/hannibal2/skyhanni
parentce66db7d2cb76a46bb0705b8e02436c15191e4d0 (diff)
downloadskyhanni-34e9f01594e498ed16ebe55f51ba990948635456.tar.gz
skyhanni-34e9f01594e498ed16ebe55f51ba990948635456.tar.bz2
skyhanni-34e9f01594e498ed16ebe55f51ba990948635456.zip
Backend: MultiClickable (#1407)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt53
1 files changed, 45 insertions, 8 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 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<Int> = 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<Any>,
+ bypassChecks: Boolean = false,
+ click: Map<Int, () -> 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<Int, () -> 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<Any>,
@@ -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
}
}