diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-07-15 20:14:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-15 20:14:42 +0200 |
commit | 3875fd1658028708e6b990c45599142df8ec7d38 (patch) | |
tree | 10a760297eb559948043ea3b21e25ea7b6394d35 /src/main/java | |
parent | 61b8122645de0eb948a938da9d4a452265f36c08 (diff) | |
download | skyhanni-3875fd1658028708e6b990c45599142df8ec7d38.tar.gz skyhanni-3875fd1658028708e6b990c45599142df8ec7d38.tar.bz2 skyhanni-3875fd1658028708e6b990c45599142df8ec7d38.zip |
Improvement: Compact Rancher Speed GUI (#2137)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java')
3 files changed, 69 insertions, 37 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/OptimalSpeedConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/OptimalSpeedConfig.java index 07a049bf5..6e44ecfec 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/OptimalSpeedConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/garden/optimalspeed/OptimalSpeedConfig.java @@ -28,6 +28,11 @@ public class OptimalSpeedConfig { public boolean signEnabled = true; @Expose + @ConfigOption(name = "Compact GUI", desc = "Compact the Rancher Boots GUI only showing crop icons") + @ConfigEditorBoolean + public boolean compactRancherGui = false; + + @Expose @ConfigLink(owner = OptimalSpeedConfig.class, field = "signEnabled") public Position signPosition = new Position(20, -195, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt index 1af272051..5eb89a138 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenOptimalSpeed.kt @@ -8,10 +8,11 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule import at.hannibal2.skyhanni.utils.ChatUtils import at.hannibal2.skyhanni.utils.ConditionalUtils +import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.SimpleTimeMark import at.hannibal2.skyhanni.utils.renderables.Renderable import io.github.notenoughupdates.moulconfig.observer.Property @@ -20,7 +21,6 @@ import net.minecraft.client.gui.inventory.GuiEditSign import net.minecraftforge.client.event.GuiOpenEvent import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @SkyHanniModule @@ -29,9 +29,10 @@ object GardenOptimalSpeed { private val config get() = GardenAPI.config.optimalSpeeds private val configCustomSpeed get() = config.customSpeed + private var sneakingSince = SimpleTimeMark.farFuture() private var sneakingTime = 0.seconds private val sneaking get() = Minecraft.getMinecraft().thePlayer.isSneaking - private val sneakingPersistent get() = sneakingTime > 5.seconds + private val sneakingPersistent get() = sneakingSince.passedSince() > 5.seconds /** * This speed value represents the walking speed, not the speed stat. @@ -47,46 +48,70 @@ object GardenOptimalSpeed { */ private var currentSpeed = 100 - private var optimalSpeed = -1 - private var lastWarnTime = 0L + private var optimalSpeed: Int? = null + private var lastWarnTime = SimpleTimeMark.farPast() private var cropInHand: CropType? = null - private var rancherOverlayList: List<List<Any?>> = emptyList() + private var lastCrop: CropType? = null + private var display = listOf<Renderable>() private var lastToolSwitch = SimpleTimeMark.farPast() @SubscribeEvent fun onTick(event: LorenzTickEvent) { + if (!GardenAPI.inGarden()) return currentSpeed = (Minecraft.getMinecraft().thePlayer.capabilities.walkSpeed * 1000).toInt() - if (sneaking) { + if (sneaking && !sneakingSince.isInPast()) { + sneakingSince = SimpleTimeMark.now() currentSpeed = (currentSpeed * 0.3).toInt() - sneakingTime += 50.milliseconds - } else { + } else if (!sneaking && sneakingSince.isInPast()) { sneakingTime = 0.seconds + sneakingSince = SimpleTimeMark.farFuture() } } @SubscribeEvent fun onGuiOpen(event: GuiOpenEvent) { if (!isRancherOverlayEnabled()) return - val gui = event.gui - if (gui !is GuiEditSign) return + val gui = event.gui as? GuiEditSign ?: return if (!gui.isRancherSign()) return - rancherOverlayList = CropType.entries.map { crop -> - listOf(crop.icon, Renderable.link("${crop.cropName} - ${crop.getOptimalSpeed()}") { - LorenzUtils.setTextIntoSign("${crop.getOptimalSpeed()}") - }) + + val crops = CropType.entries.map { it to it.getOptimalSpeed() } + + display = if (config.compactRancherGui) { + crops.groupBy({ it.second }, { it.first }).map { (speed, crops) -> + val color = if (lastCrop in crops) LorenzColor.GOLD else LorenzColor.WHITE + val renderable = Renderable.horizontalContainer( + listOf( + Renderable.horizontalContainer(crops.map { Renderable.itemStack(it.icon) }), + Renderable.string("${color.getChatColor()} - $speed"), + ), + spacing = 2, + ) + Renderable.link(renderable, underlineColor = color.toColor(), onClick = { LorenzUtils.setTextIntoSign("$speed") }) + } + } else { + crops.map { (crop, speed) -> + val color = if (lastCrop == crop) LorenzColor.GOLD else LorenzColor.WHITE + val renderable = Renderable.horizontalContainer( + listOf( + Renderable.itemStack(crop.icon), + Renderable.string("${color.getChatColor()}${crop.cropName} - $speed"), + ), + spacing = 2, + ) + Renderable.link(renderable, underlineColor = color.toColor(), onClick = { LorenzUtils.setTextIntoSign("$speed") }) + } } } @SubscribeEvent fun onGuiRender(event: DrawScreenEvent.Post) { if (!isRancherOverlayEnabled()) return - val gui = event.gui - if (gui !is GuiEditSign) return + val gui = event.gui as? GuiEditSign ?: return if (!gui.isRancherSign()) return - config.signPosition.renderStringsAndItems( - rancherOverlayList, - posLabel = "Optimal Speed Rancher Overlay" + config.signPosition.renderRenderables( + display, + posLabel = "Optimal Speed Rancher Overlay", ) } @@ -94,7 +119,8 @@ object GardenOptimalSpeed { fun onGardenToolChange(event: GardenToolChangeEvent) { lastToolSwitch = SimpleTimeMark.now() cropInHand = event.crop - optimalSpeed = cropInHand?.getOptimalSpeed() ?: -1 + event.crop?.let { lastCrop = it } + optimalSpeed = cropInHand?.getOptimalSpeed() } @SubscribeEvent @@ -129,12 +155,12 @@ object GardenOptimalSpeed { fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { if (!GardenAPI.inGarden()) return - if (optimalSpeed == -1) return + val speed = optimalSpeed ?: return if (GardenAPI.hideExtraGuis()) return - var text = "Optimal Speed: §f$optimalSpeed" - if (optimalSpeed != currentSpeed) { + var text = "Optimal Speed: §f$speed" + if (speed != currentSpeed) { text += " (§eCurrent: §f$currentSpeed" if (sneaking) text += " §7[Sneaking]" text += "§f)" @@ -143,25 +169,24 @@ object GardenOptimalSpeed { val recentlySwitchedTool = lastToolSwitch.passedSince() < 1.5.seconds val recentlyStartedSneaking = sneaking && !sneakingPersistent - val colorCode = - if (recentlySwitchedTool || recentlyStartedSneaking) "7" else if (optimalSpeed != currentSpeed) "c" else "a" + val colorCode = if (recentlySwitchedTool || recentlyStartedSneaking) "7" else if (speed != currentSpeed) "c" else "a" if (config.showOnHUD) config.pos.renderString("§$colorCode$text", posLabel = "Garden Optimal Speed") - if (optimalSpeed != currentSpeed && !recentlySwitchedTool && !recentlyStartedSneaking) warn() + if (speed != currentSpeed && !recentlySwitchedTool && !recentlyStartedSneaking) warn(speed) } - private fun warn() { - if (!config.warning) return + private fun warn(speed: Int) { if (!Minecraft.getMinecraft().thePlayer.onGround) return if (GardenAPI.onBarnPlot) return - if (System.currentTimeMillis() < lastWarnTime + 20_000) return + if (!config.warning) return + if (lastWarnTime.passedSince() < 20.seconds) return - lastWarnTime = System.currentTimeMillis() + lastWarnTime = SimpleTimeMark.now() LorenzUtils.sendTitle("§cWrong speed!", 3.seconds) cropInHand?.let { var text = "Wrong speed for ${it.cropName}: §f$currentSpeed" if (sneaking) text += " §7[Sneaking]" - text += " §e(§f$optimalSpeed §eis optimal)" + text += " §e(§f$speed §eis optimal)" ChatUtils.chat(text) } 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 b12668d72..464515241 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt @@ -84,7 +84,7 @@ interface Renderable { } fun link(text: String, bypassChecks: Boolean = false, onClick: () -> Unit): Renderable = - link(string(text), onClick, bypassChecks = bypassChecks) { true } + link(string(text), onClick, bypassChecks = bypassChecks) fun optionalLink( text: String, @@ -101,10 +101,11 @@ interface Renderable { bypassChecks: Boolean = false, highlightsOnHoverSlots: List<Int> = emptyList(), condition: () -> Boolean = { true }, + underlineColor: Color = Color.WHITE, ): Renderable { return clickable( hoverable( - underlined(renderable), renderable, bypassChecks, + underlined(renderable, underlineColor), renderable, bypassChecks, condition = condition, highlightsOnHoverSlots = highlightsOnHoverSlots, ), @@ -282,15 +283,16 @@ interface Renderable { return result } - fun underlined(renderable: Renderable) = object : Renderable { + fun underlined(renderable: Renderable, color: Color = Color.WHITE) = object : Renderable { override val width: Int get() = renderable.width - override val height = 10 + override val height: Int + get() = renderable.height + 1 override val horizontalAlign = renderable.horizontalAlign override val verticalAlign = renderable.verticalAlign override fun render(posX: Int, posY: Int) { - Gui.drawRect(0, 10, width, 11, 0xFFFFFFFF.toInt()) + Gui.drawRect(0, height, width, 11, color.rgb) GlStateManager.color(1F, 1F, 1F, 1F) renderable.render(posX, posY) } |