diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-17 22:07:06 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-17 22:07:06 +0200 |
commit | 1e725fe960da8d7c4705cebae6d8b4a4eb3658bb (patch) | |
tree | 273c3077bafd6bb109c1965881da795993176d8b /src/main/java/at/hannibal2/skyhanni | |
parent | 3e20798cfe3e04d2d85f1d8ef3f96b3d9631b04a (diff) | |
download | skyhanni-1e725fe960da8d7c4705cebae6d8b4a4eb3658bb.tar.gz skyhanni-1e725fe960da8d7c4705cebae6d8b4a4eb3658bb.tar.bz2 skyhanni-1e725fe960da8d7c4705cebae6d8b4a4eb3658bb.zip |
added optional renderable link texts
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt | 17 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt index 442c4d47f..0b86ac8cc 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt @@ -137,9 +137,9 @@ class GardenVisitorFeatures { list.add(" §7- ") list.add(itemStack) - list.add(Renderable.link("$name §8x${amount.addSeparators()}") { + list.add(Renderable.optionalLink("$name §8x${amount.addSeparators()}", { LorenzUtils.setTextIntoSign("$amount") - }) + }) { Minecraft.getMinecraft().currentScreen is GuiEditSign }) if (config.visitorNeedsShowPrice) { val price = NEUItems.getPrice(internalName) * amount 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 ce531846e..1d1313d03 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -30,12 +30,13 @@ interface Renderable { else -> null } - fun link(text: String, onClick: () -> Unit): Renderable = link(string(text), onClick) - fun link(renderable: Renderable, onClick: () -> Unit): Renderable { - return clickable(hoverable(underlined(renderable), renderable), onClick) + fun link(text: String, onClick: () -> Unit): Renderable = link(string(text), onClick) { true } + fun optionalLink(text: String, onClick: () -> Unit, condition: () -> Boolean = {true}): Renderable = link(string(text), onClick, condition) + fun link(renderable: Renderable, onClick: () -> Unit, condition: () -> Boolean = {true}): Renderable { + return clickable(hoverable(underlined(renderable), renderable, condition), onClick, 0, condition) } - fun clickable(render: Renderable, onClick: () -> Unit, button: Int = 0) = object : Renderable { + fun clickable(render: Renderable, onClick: () -> Unit, button: Int = 0, condition: () -> Boolean = {true}) = object : Renderable { override val width: Int get() = render.width @@ -44,7 +45,9 @@ interface Renderable { override fun render(posX: Int, posY: Int) { val isDown = Mouse.isButtonDown(button) if (isDown > wasDown && isHovered(posX, posY)) { - onClick() + if (condition()) { + onClick() + } } wasDown = isDown render.render(posX, posY) @@ -63,12 +66,12 @@ interface Renderable { } } - fun hoverable(hovered: Renderable, unhovered: Renderable) = object : Renderable { + fun hoverable(hovered: Renderable, unhovered: Renderable, condition: () -> Boolean = {true}) = object : Renderable { override val width: Int get() = max(hovered.width, unhovered.width) override fun render(posX: Int, posY: Int) { - if (isHovered(posX, posY)) + if (isHovered(posX, posY) && condition()) hovered.render(posX, posY) else unhovered.render(posX, posY) |