aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-06-04 19:03:35 +0200
committerLinnea Gräf <nea@nea.moe>2025-06-04 19:05:09 +0200
commitcd35e18c9c08d129987a9faa0cbcd9dfd0340c0f (patch)
treeedcd1e838984cc82f07bb61c73bbf941ec101bc3
parent6b697b8936c41b14b005704553de7004f6c7ce18 (diff)
downloadFirmament-cd35e18c9c08d129987a9faa0cbcd9dfd0340c0f.tar.gz
Firmament-cd35e18c9c08d129987a9faa0cbcd9dfd0340c0f.tar.bz2
Firmament-cd35e18c9c08d129987a9faa0cbcd9dfd0340c0f.zip
fix: Only show hover tooltip after duration
-rw-r--r--src/main/kotlin/features/inventory/buttons/InventoryButtons.kt29
-rw-r--r--translations/en_us.json2
2 files changed, 21 insertions, 10 deletions
diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
index f443323..361e8d0 100644
--- a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
+++ b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt
@@ -5,6 +5,7 @@ package moe.nea.firmament.features.inventory.buttons
import me.shedaniel.math.Rectangle
import kotlinx.serialization.Serializable
import kotlinx.serialization.serializer
+import kotlin.time.Duration.Companion.seconds
import net.minecraft.client.MinecraftClient
import net.minecraft.text.Text
import moe.nea.firmament.annotations.Subscribe
@@ -12,9 +13,11 @@ import moe.nea.firmament.events.HandledScreenClickEvent
import moe.nea.firmament.events.HandledScreenForegroundEvent
import moe.nea.firmament.events.HandledScreenPushREIEvent
import moe.nea.firmament.features.FirmamentFeature
+import moe.nea.firmament.gui.FirmHoverComponent
import moe.nea.firmament.gui.config.ManagedConfig
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.ScreenUtil
+import moe.nea.firmament.util.TimeMark
import moe.nea.firmament.util.data.DataHolder
import moe.nea.firmament.util.accessors.getRectangle
import moe.nea.firmament.util.gold
@@ -64,10 +67,14 @@ object InventoryButtons : FirmamentFeature {
}
}
+ var lastHoveredComponent: InventoryButton? = null
+ var lastMouseMove = TimeMark.farPast()
+
@Subscribe
fun onRenderForeground(it: HandledScreenForegroundEvent) {
val bounds = it.screen.getRectangle()
+ var hoveredComponent: InventoryButton? = null
for (button in getValidButtons()) {
val buttonBounds = button.getBounds(bounds)
it.context.matrices.push()
@@ -75,17 +82,21 @@ object InventoryButtons : FirmamentFeature {
button.render(it.context)
it.context.matrices.pop()
- if (buttonBounds.contains(it.mouseX, it.mouseY) && TConfig.hoverText) {
- it.context.drawText(
- MinecraftClient.getInstance().textRenderer,
- Text.literal(button.command).gold(),
- buttonBounds.minX - 15,
- buttonBounds.minY + 20,
- 0xFFFF00,
- false
- )
+ if (buttonBounds.contains(it.mouseX, it.mouseY) && TConfig.hoverText && hoveredComponent == null) {
+ hoveredComponent = button
+ if (lastMouseMove.passedTime() > 0.6.seconds && lastHoveredComponent === button) {
+ it.context.drawTooltip(
+ MC.font,
+ listOf(Text.literal(button.command).gold()),
+ buttonBounds.minX - 15,
+ buttonBounds.maxY + 20,
+ )
+ }
}
}
+ if (hoveredComponent !== lastHoveredComponent)
+ lastMouseMove = TimeMark.now()
+ lastHoveredComponent = hoveredComponent
lastRectangle = bounds
}
diff --git a/translations/en_us.json b/translations/en_us.json
index 4e20ca1..2f66c84 100644
--- a/translations/en_us.json
+++ b/translations/en_us.json
@@ -129,7 +129,7 @@
"firmament.config.fixes.player-skins": "Fix unsigned Player Skins",
"firmament.config.fixes.player-skins.description": "Mark all player skins as signed, preventing console spam, and some rendering issues.",
"firmament.config.inventory-buttons": "Inventory buttons",
- "firmament.config.inventory-buttons.hover-text": "Hover Text",
+ "firmament.config.inventory-buttons.hover-text": "Hover Tooltip",
"firmament.config.inventory-buttons.hover-text.description": "Hovering over inventory buttons will show the command they run.",
"firmament.config.inventory-buttons.open-editor": "Open Editor",
"firmament.config.inventory-buttons.open-editor.description": "Click anywhere to create a new inventory button or to edit one. Hold SHIFT to grid align.",