simple tooltip system for fixtures

This commit is contained in:
minjaesong
2024-09-10 19:41:06 +09:00
parent 180d36eb10
commit f50c2a385b
3 changed files with 36 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitems.GameItem
import net.torvald.terrarum.gameitems.ItemID
import net.torvald.terrarum.gameworld.fmod
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
@@ -49,6 +50,8 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
@Transient var inOperation = false
@Transient private val tooltipObjects = ArrayList<Pair<String?, ()-> String>>()
// @Transient var mainUIopenFun: ((UICanvas) -> Unit)? = null
internal var actorThatInstalledThisFixture: UUID? = null
@@ -56,6 +59,15 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
protected constructor() : super(RenderOrder.BEHIND, PhysProperties.IMMOBILE(), null)
protected constructor(renderOrder: RenderOrder, physProp: PhysProperties, id: ActorID?) : super(renderOrder, physProp, id)
// call on init()
fun addQuickLookupParam(name: String?, valueFun: () -> String) {
tooltipObjects.add(name to valueFun)
}
// call on init()
fun addQuickLookupParam(valueFun: () -> String) {
tooltipObjects.add(null to valueFun)
}
/**
* Callend whenever the fixture was spawned successfully.
*
@@ -427,6 +439,18 @@ open class FixtureBase : ActorWithBody, CuedByTerrainChange {
override fun updateImpl(delta: Float) {
super.updateImpl(delta)
chunkAnchoring = inOperation
tooltipObjects.map { (name, valueFun) ->
if (name != null)
"${Lang[name]}: ${valueFun()}"
else
"${valueFun()}"
}.filter { it.isNotBlank() }.let {
tooltipText = if (it.isNotEmpty())
it.joinToString("\n")
else
null
}
}
/**

View File

@@ -93,6 +93,12 @@ class FixtureJukebox : Electric, PlaysMusic {
despawnHook = {
stopGracefully()
}
addQuickLookupParam {
musicNowPlaying.let {
if (it == null) "" else "${App.fontGame.toColorCode(5,15,5)}${it.name}${App.fontGame.noColorCode}"
}
}
}
@Transient override var lightBoxList = arrayListOf(Lightbox(Hitbox(0.0, 0.0, TILE_SIZED * 2, TILE_SIZED * 3), Cvec(0.44f, 0.41f, 0.40f, 0.2f)))

View File

@@ -57,6 +57,12 @@ class FixtureMusicalTurntable : Electric, PlaysMusic {
despawnHook = {
stopGracefully()
}
addQuickLookupParam {
musicNowPlaying.let {
if (it == null) "" else "${App.fontGame.toColorCode(5,15,5)}${it.name}${App.fontGame.noColorCode}"
}
}
}
internal var disc: ItemID? = null