mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-13 20:14:05 +09:00
tooltipmanager
This commit is contained in:
47
src/net/torvald/terrarum/TooltipManager.kt
Normal file
47
src/net/torvald/terrarum/TooltipManager.kt
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user