diff options
-rw-r--r-- | src/main/kotlin/features/inventory/buttons/InventoryButtons.kt | 29 | ||||
-rw-r--r-- | translations/en_us.json | 2 |
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.", |