aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt7
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt (renamed from src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt)68
3 files changed, 50 insertions, 27 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
index 5c96ecde0..9fe8af976 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
@@ -442,6 +442,7 @@ import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUVersionCheck.checkIfNeuIsLoaded
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.UtilsPatterns
+import at.hannibal2.skyhanni.utils.renderables.RenderableTooltips
import at.hannibal2.skyhanni.utils.repopatterns.RepoPatternManager
import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
@@ -572,6 +573,7 @@ class SkyHanniMod {
loadModule(MiningAPI)
loadModule(FossilExcavatorAPI)
loadModule(ChocolateFactoryAPI)
+ loadModule(RenderableTooltips)
// features
loadModule(BazaarOrderHelper())
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 304e31141..fc1b0f45f 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/Renderable.kt
@@ -22,7 +22,6 @@ import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.calculateTableYOf
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXYAligned
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderYAligned
-import io.github.moulberry.notenoughupdates.util.Utils
import io.github.notenoughupdates.moulconfig.gui.GuiScreenElementWrapper
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.Gui
@@ -210,15 +209,11 @@ interface Renderable {
GlStateManager.pushMatrix()
GlStateManager.translate(0F, 0F, 400F)
- RenderLineTooltips.drawHoveringText(
- posX = posX,
- posY = posY,
+ RenderableTooltips.setTooltipForRender(
tips = tipsRender,
stack = stack,
borderColor = color,
snapsToTopIfToLong = snapsToTopIfToLong,
- mouseX = currentRenderPassMousePosition?.first ?: Utils.getMouseX(),
- mouseY = currentRenderPassMousePosition?.second ?: Utils.getMouseY(),
)
GlStateManager.popMatrix()
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt
index 09ab434d0..14e4fde13 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderLineTooltips.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/renderables/RenderableTooltips.kt
@@ -5,54 +5,66 @@ import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.RenderUtils
import at.hannibal2.skyhanni.utils.renderables.RenderableUtils.renderXAligned
import io.github.moulberry.notenoughupdates.util.Utils
-import java.awt.Color
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.RenderHelper
import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent.RenderTickEvent
+import java.awt.Color
-object RenderLineTooltips {
+object RenderableTooltips {
- fun drawHoveringText(
- posX: Int, posY: Int,
+ private var tooltip: DeferredTooltip? = null
+
+ @SubscribeEvent
+ fun onPostRenderTick(event: RenderTickEvent) {
+ if (event.phase == TickEvent.Phase.START) {
+ tooltip = null
+ } else if (event.phase == TickEvent.Phase.END) {
+ drawHoveringText()
+ }
+ }
+
+ fun setTooltipForRender(
tips: List<Renderable>,
stack: ItemStack? = null,
borderColor: LorenzColor? = null,
snapsToTopIfToLong: Boolean = true,
- mouseX: Int = Utils.getMouseX(),
- mouseY: Int = Utils.getMouseY(),
) {
- if (tips.isEmpty()) return
+ tooltip = DeferredTooltip(tips, stack, borderColor, snapsToTopIfToLong)
+ }
- val (xTranslate, yTranslate, _) = RenderUtils.absoluteTranslation
+ private fun drawHoveringText() {
+ val tooltip = tooltip ?: return
+ val tips = tooltip.tips
+ if (tips.isEmpty()) return
- val x = mouseX - posX + 12
- val y = mouseY - posY - if (tips.size > 1) 2 else -7
- val color: Char = borderColor?.chatColorCode ?: stack?.getLore()?.lastOrNull()?.take(4)?.get(1)
- ?: 'f'
- val colourInt = Minecraft.getMinecraft().fontRendererObj.getColorCode(color)
- val borderColorStart = Color(colourInt).darker().rgb and 0x00FFFFFF or (200 shl 24)
+ val x = Utils.getMouseX() + 12
+ val y = Utils.getMouseY() - if (tips.size > 1) 2 else -7
+ val borderColorStart = Color(tooltip.getBorderColor()).darker().rgb and 0x00FFFFFF or (200 shl 24)
val scaled = ScaledResolution(Minecraft.getMinecraft())
val tooltipTextWidth = tips.maxOf { it.width }
val tooltipHeight = tips.sumOf { it.height }
val tooltipY = when {
- y + yTranslate < 16 -> -yTranslate + 4 // Limit Top
- y + yTranslate + tooltipHeight > scaled.scaledHeight -> {
- if (snapsToTopIfToLong && tooltipHeight + 8 > scaled.scaledHeight)
- -yTranslate + 4 // Snap to Top if to Long
+ y < 16 -> 4 // Limit Top
+ y + tooltipHeight > scaled.scaledHeight -> {
+ if (tooltip.snapsToTopIfToLong && tooltipHeight + 8 > scaled.scaledHeight)
+ 4 // Snap to Top if to Long
else
- scaled.scaledHeight - tooltipHeight - 4 - yTranslate // Limit Bottom
+ scaled.scaledHeight - tooltipHeight - 4 // Limit Bottom
}
else -> {
y - 12 // normal
}
}
- val tooltipX = if (x + tooltipTextWidth + 4 + xTranslate > scaled.scaledWidth) {
- scaled.scaledWidth - tooltipTextWidth - 4 - xTranslate // Limit Right
+ val tooltipX = if (x + tooltipTextWidth + 4 > scaled.scaledWidth) {
+ scaled.scaledWidth - tooltipTextWidth - 4 // Limit Right
} else {
x // normal
}
@@ -146,3 +158,17 @@ object RenderLineTooltips {
GlStateManager.disableLighting()
}
}
+
+private data class DeferredTooltip(
+ val tips: List<Renderable>,
+ val stack: ItemStack? = null,
+ val borderColor: LorenzColor? = null,
+ val snapsToTopIfToLong: Boolean = true,
+) {
+
+ fun getBorderColor(): Int {
+ return Minecraft.getMinecraft().fontRendererObj.getColorCode(
+ borderColor?.chatColorCode ?: stack?.getLore()?.lastOrNull()?.take(4)?.get(1) ?: 'f'
+ )
+ }
+}