From ae9482ca94504e809c8effa02530fa4697845542 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:08:14 +0200 Subject: Feature: Added Tooltip Move (#1581) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../features/event/ChocolateFactoryConfig.java | 10 +++ .../chocolatefactory/clicks/CompactFactoryClick.kt | 46 ------------- .../clicks/FactoryItemTooltipFeatures.kt | 77 ++++++++++++++++++++++ 4 files changed, 89 insertions(+), 48 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/CompactFactoryClick.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/FactoryItemTooltipFeatures.kt (limited to 'src/main/java/at') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 885bffe30..a92e2fb1b 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -133,7 +133,7 @@ import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityCollectionSt import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggLocator import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsManager import at.hannibal2.skyhanni.features.event.chocolatefactory.HoppityEggsShared -import at.hannibal2.skyhanni.features.event.chocolatefactory.clicks.CompactFactoryClick +import at.hannibal2.skyhanni.features.event.chocolatefactory.clicks.FactoryItemTooltipFeatures import at.hannibal2.skyhanni.features.event.diana.AllBurrowsList import at.hannibal2.skyhanni.features.event.diana.BurrowWarpHelper import at.hannibal2.skyhanni.features.event.diana.DianaProfitTracker @@ -626,7 +626,7 @@ class SkyHanniMod { loadModule(ChocolateFactoryBarnManager) loadModule(ChocolateFactoryInventory) loadModule(ChocolateFactoryStats) - loadModule(CompactFactoryClick) + loadModule(FactoryItemTooltipFeatures) loadModule(HoppityEggsManager) loadModule(HoppityEggLocator) loadModule(HoppityEggsShared) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java index 99d4b5862..2a0d47892 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/event/ChocolateFactoryConfig.java @@ -108,4 +108,14 @@ public class ChocolateFactoryConfig { @ConfigOption(name = "Always Compact", desc = "Always Compact the item toolip on the chocolate. Requires the above option to be enabled.") @ConfigEditorBoolean public boolean compactOnClickAlways = false; + + @Expose + @ConfigOption(name = "Tooltip Move", desc = "Move Tooltip away from the item you hover over while inside the Chocolate Factory.") + @ConfigEditorBoolean + @FeatureToggle + public boolean tooltipMove = false; + + @Expose + @ConfigLink(owner = ChocolateFactoryConfig.class, field = "tooltipMove") + public Position tooltipMovePosition = new Position(-380, 150, false, true); } diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/CompactFactoryClick.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/CompactFactoryClick.kt deleted file mode 100644 index 64f30de04..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/CompactFactoryClick.kt +++ /dev/null @@ -1,46 +0,0 @@ -package at.hannibal2.skyhanni.features.event.chocolatefactory.clicks - -import at.hannibal2.skyhanni.events.GuiContainerEvent -import at.hannibal2.skyhanni.events.LorenzToolTipEvent -import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryAPI -import at.hannibal2.skyhanni.utils.CollectionUtils.getOrNull -import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name -import at.hannibal2.skyhanni.utils.SimpleTimeMark -import net.minecraftforge.fml.common.eventhandler.EventPriority -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.time.Duration.Companion.seconds - -object CompactFactoryClick { - private val config get() = ChocolateFactoryAPI.config - - private var lastClick = SimpleTimeMark.farPast() - - @SubscribeEvent - fun onTooltip(event: LorenzToolTipEvent) { - if (!ChocolateFactoryAPI.inChocolateFactory) return - if (!config.compactOnClick) return - - val itemStack = event.itemStack - val lore = itemStack.getLore() - if (!lore.any { it == "§7§eClick to uncover the meaning of life!" }) return - if (lastClick.passedSince() >= 1.seconds && !config.compactOnClickAlways) return - val list = mutableListOf() - list.add(itemStack.name) - lore.getOrNull(5)?.let { - list.add(it) - } - event.toolTip = list - return - } - - @SubscribeEvent(priority = EventPriority.HIGH) - fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { - - if (ChocolateFactoryAPI.inChocolateFactory) { - if (event.slotId == 13) { - lastClick = SimpleTimeMark.now() - } - } - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/FactoryItemTooltipFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/FactoryItemTooltipFeatures.kt new file mode 100644 index 000000000..a7d2a3c79 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/event/chocolatefactory/clicks/FactoryItemTooltipFeatures.kt @@ -0,0 +1,77 @@ +package at.hannibal2.skyhanni.features.event.chocolatefactory.clicks + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.LorenzToolTipEvent +import at.hannibal2.skyhanni.features.event.chocolatefactory.ChocolateFactoryAPI +import at.hannibal2.skyhanni.utils.CollectionUtils.getOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.milliseconds +import kotlin.time.Duration.Companion.seconds + +object FactoryItemTooltipFeatures { + private val config get() = ChocolateFactoryAPI.config + + private var lastClick = SimpleTimeMark.farPast() + private var lastHover = SimpleTimeMark.farPast() + private var tooltipToHover = listOf() + + @SubscribeEvent + fun onTooltip(event: LorenzToolTipEvent) { + if (!ChocolateFactoryAPI.inChocolateFactory) return + + if (config.tooltipMove) { + if (event.slot.slotNumber <= 44) { + lastHover = SimpleTimeMark.now() + tooltipToHover = event.toolTip.toList() + event.cancel() + } else { + lastHover = SimpleTimeMark.farPast() + } + return + } + + onCompactClick(event) + } + + @SubscribeEvent + fun onBackgroundDraw(event: GuiRenderEvent.ChestGuiOverlayRenderEvent) { + if (!ChocolateFactoryAPI.inChocolateFactory) return + if (config.tooltipMove) { + if (lastHover.passedSince() < 300.milliseconds) { + config.tooltipMovePosition.renderStrings(tooltipToHover, posLabel = "Tooltip Move") + } + } + } + + private fun onCompactClick(event: LorenzToolTipEvent) { + if (!config.compactOnClick) return + + val itemStack = event.itemStack + val lore = itemStack.getLore() + if (!lore.any { it == "§7§eClick to uncover the meaning of life!" }) return + if (lastClick.passedSince() >= 1.seconds && !config.compactOnClickAlways) return + val list = mutableListOf() + list.add(itemStack.name) + lore.getOrNull(5)?.let { + list.add(it) + } + event.toolTip = list + return + } + + @SubscribeEvent(priority = EventPriority.HIGH) + fun onSlotClick(event: GuiContainerEvent.SlotClickEvent) { + + if (ChocolateFactoryAPI.inChocolateFactory) { + if (event.slotId == 13) { + lastClick = SimpleTimeMark.now() + } + } + } +} -- cgit