tooltipmanager

This commit is contained in:
minjaesong
2024-10-11 15:02:11 +09:00
parent 048777a845
commit 60e54c2bc0
29 changed files with 118 additions and 238 deletions

View File

@@ -0,0 +1,47 @@
package net.torvald.terrarum
/**
* Created by minjaesong on 2024-10-11.
*/
object TooltipManager {
/**
* Special hash values:
* - 10001: Encumbrance bar
* - 10002: Pickaxe
*/
val tooltipShowing = HashMap<Long, Boolean>()
}
/**
* Tooltip works like a "bus" principle: you acquire the control on the tooltip-bus to show a tooltip; you
* release the control to the bus to hide it. `unsetToolTip()` will release the bus and forcibly closes
* the tooltip UI.
*
* Created by minjaesong on 2024-10-11.
*/
abstract class TooltipListener {
open val tooltipHash = System.nanoTime()
fun acquireTooltip(message: String?) {
INGAME.setTooltipMessage(message)
TooltipManager.tooltipShowing[tooltipHash] = true
}
fun releaseTooltip() {
// TooltipManager.tooltipShowing[tooltipHash] = false // I doubt this is not really necessary...?
TooltipManager.tooltipShowing.remove(tooltipHash)
}
fun removeFromTooltipRecord() {
TooltipManager.tooltipShowing.remove(tooltipHash)
}
fun clearTooltip() {
TooltipManager.tooltipShowing.clear()
INGAME.setTooltipMessage(null)
}
fun tooltipAcquired() = TooltipManager.tooltipShowing[tooltipHash] ?: false
}