From b3cb37f5459afce7c6234b5ab3a8891447eb587a Mon Sep 17 00:00:00 2001 From: martimavocado <39881008+martimavocado@users.noreply.github.com> Date: Sat, 5 Oct 2024 09:07:15 +0000 Subject: Improvement: Make visitor GUI clickable to tp to barn (#2658) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../features/garden/visitor/TimerConfig.java | 1 + .../features/garden/visitor/GardenVisitorTimer.kt | 26 ++++++++++++++-------- .../at/hannibal2/skyhanni/utils/RenderUtils.kt | 3 ++- 3 files changed, 20 insertions(+), 10 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/TimerConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/TimerConfig.java index 32bff02de..a6b7e509e 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/TimerConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/visitor/TimerConfig.java @@ -34,5 +34,6 @@ public class TimerConfig { @Expose @ConfigLink(owner = TimerConfig.class, field = "enabled") + // TODO rename to position public Position pos = new Position(-200, 40, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt index 3a69f2ece..af31448d6 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorTimer.kt @@ -11,15 +11,17 @@ import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.features.garden.farming.GardenCropSpeed import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.test.command.ErrorManager +import at.hannibal2.skyhanni.utils.HypixelCommands import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst -import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderable import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.SoundUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TabListData import at.hannibal2.skyhanni.utils.TimeUtils import at.hannibal2.skyhanni.utils.TimeUtils.format +import at.hannibal2.skyhanni.utils.renderables.Renderable import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration @@ -36,10 +38,10 @@ object GardenVisitorTimer { private val timePattern by RepoPattern.pattern( "garden.visitor.timer.time.new", - " Next Visitor: §r(?.*)" + " Next Visitor: §r(?.*)", ) - private var display = "" + private var display: Renderable? = null private var lastMillis = 0.seconds private var sixthVisitorArrivalTime = SimpleTimeMark.farPast() private var visitorJustArrived = false @@ -65,7 +67,7 @@ object GardenVisitorTimer { @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { - display = "" + display = null lastMillis = 0.seconds sixthVisitorArrivalTime = SimpleTimeMark.farPast() visitorJustArrived = false @@ -84,7 +86,7 @@ object GardenVisitorTimer { TabListData.getTabList().matchFirst(timePattern) { val timeInfo = group("info").removeColor() if (timeInfo == "Not Unlocked!") { - display = "§cVisitors not unlocked!" + display = Renderable.string("§cVisitors not unlocked!") return } if (timeInfo == "Queue Full!") { @@ -97,7 +99,7 @@ object GardenVisitorTimer { millis = TimeUtils.getDuration(timeInfo) } } ?: run { - display = "§cVisitor time info not in tab list" + display = createDisplayText("§cVisitor time info not in tab list") return } @@ -140,7 +142,7 @@ object GardenVisitorTimer { if (lastMillis == Duration.INFINITE) { ErrorManager.logErrorStateWithData( "Found Visitor Timer bug, reset value", "lastMillis was infinite", - "lastMillis" to lastMillis + "lastMillis" to lastMillis, ) lastMillis = 0.seconds } @@ -168,14 +170,20 @@ object GardenVisitorTimer { "Next in §$formatColor$formatDuration$extraSpeed" } val visitorLabel = if (visitorsAmount == 1) "visitor" else "visitors" - display = "§b$visitorsAmount $visitorLabel §7($next§7)" + display = createDisplayText("§b$visitorsAmount $visitorLabel §7($next§7)") } + private fun createDisplayText(text: String) = Renderable.clickAndHover( + text, + listOf("§eClick to teleport to the barn!"), + onClick = { HypixelCommands.teleportToPlot("barn") }, + ) + @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!isEnabled()) return - config.pos.renderString(display, posLabel = "Garden Visitor Timer") + config.pos.renderRenderable(display, posLabel = "Garden Visitor Timer") } @SubscribeEvent diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index cf2339bf3..309f17f68 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -591,10 +591,11 @@ object RenderUtils { } fun Position.renderRenderable( - renderable: Renderable, + renderable: Renderable?, posLabel: String, addToGuiManager: Boolean = true, ) { + if (renderable == null) return GlStateManager.pushMatrix() val (x, y) = transform() Renderable.withMousePosition(x, y) { -- cgit