mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
tooltip ui update
This commit is contained in:
@@ -25,6 +25,8 @@ class EntryPoint : ModuleEntryPoint() {
|
||||
|
||||
override fun invoke() {
|
||||
|
||||
printdbg(this, "Hello, world!")
|
||||
|
||||
// the order of invocation is important! Material should be the first as blocks and items are depend on it.
|
||||
ModMgr.GameMaterialLoader.invoke(moduleName)
|
||||
ModMgr.GameBlockLoader.invoke(moduleName)
|
||||
|
||||
@@ -683,7 +683,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
|
||||
wires?.forEach {
|
||||
val wireActor = getOrMakeWireActor(wiringCounter)
|
||||
|
||||
if (WireCodex[it].renderClass == selectedWireRenderClass) {
|
||||
if (WireCodex[it].renderClass == selectedWireRenderClass || selectedWireRenderClass == "wire_render_all") {
|
||||
wireActor.isUpdate = true
|
||||
wireActor.isVisible = true
|
||||
wireActor.forceDormant = false
|
||||
|
||||
@@ -94,7 +94,8 @@ object PlayerBuilderSigrid {
|
||||
inventory.add("item@basegame:2") // iron pick
|
||||
inventory.add("item@basegame:3") // steel pick
|
||||
inventory.add("item@basegame:5", 385930603) // test tiki torch
|
||||
inventory.add("item@basegame:6", 95) // crafting table
|
||||
inventory.add("item@basegame:6", 95) // storage chest
|
||||
inventory.add("item@basegame:7", 1) // wire debugger
|
||||
|
||||
WireCodex.getAll().forEach {
|
||||
try {
|
||||
|
||||
@@ -90,7 +90,7 @@ class PickaxeCopper(originalID: ItemID) : GameItem(originalID) {
|
||||
override val isDynamic = true
|
||||
override val material = MaterialCodex["CUPR"]
|
||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||
override val itemImage: TextureRegion?
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(0,0)
|
||||
|
||||
init {
|
||||
@@ -117,7 +117,7 @@ class PickaxeIron(originalID: ItemID) : GameItem(originalID) {
|
||||
override val isDynamic = true
|
||||
override val material = MaterialCodex["IRON"]
|
||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||
override val itemImage: TextureRegion?
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(1,0)
|
||||
|
||||
init {
|
||||
@@ -144,7 +144,7 @@ class PickaxeSteel(originalID: ItemID) : GameItem(originalID) {
|
||||
override val isDynamic = true
|
||||
override val material = MaterialCodex["STAL"]
|
||||
override var baseMass = material.density.toDouble() / MaterialCodex["IRON"].density * BASE_MASS_AND_SIZE
|
||||
override val itemImage: TextureRegion?
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegionPack("basegame.items24").get(2,0)
|
||||
|
||||
init {
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.torvald.terrarum.modulebasegame.gameitems
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion
|
||||
import net.torvald.terrarum.*
|
||||
import net.torvald.terrarum.blockproperties.WireCodex
|
||||
import net.torvald.terrarum.gameitem.GameItem
|
||||
import net.torvald.terrarum.gameitem.ItemID
|
||||
import net.torvald.terrarum.gameworld.GameWorld
|
||||
import net.torvald.terrarum.itemproperties.MaterialCodex
|
||||
import net.torvald.terrarum.modulebasegame.TerrarumIngame
|
||||
import net.torvald.terrarum.modulebasegame.gameitems.PickaxeCore
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class WireGraphDebugger(originalID: ItemID) : GameItem(originalID) {
|
||||
|
||||
override val originalName = "WIRE_DEBUGGER"
|
||||
override var baseToolSize: Double? = PickaxeCore.BASE_MASS_AND_SIZE
|
||||
override var stackable = false
|
||||
override var inventoryCategory = Category.TOOL
|
||||
override val isUnique = true
|
||||
override val isDynamic = false
|
||||
override val material = MaterialCodex["CUPR"]
|
||||
override var baseMass = 2.0
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegion("itemplaceholder_24")
|
||||
|
||||
init {
|
||||
super.equipPosition = GameItem.EquipPosition.HAND_GRIP
|
||||
super.name = "Wire Debugger"
|
||||
}
|
||||
|
||||
private val sb = StringBuilder()
|
||||
|
||||
override fun effectWhenEquipped(delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = "wire_render_all"
|
||||
|
||||
|
||||
val mx = Terrarum.mouseTileX
|
||||
val my = Terrarum.mouseTileY
|
||||
|
||||
sb.clear()
|
||||
|
||||
Terrarum.ingame!!.world.getAllWiringGraph(mx, my)?.let {
|
||||
it.forEachIndexed { index, (itemID, simCell) ->
|
||||
if (sb.isNotEmpty()) sb.append('\n')
|
||||
|
||||
|
||||
val connexionIcon = (simCell.con + 0xE0A0).toChar()
|
||||
val wireName = WireCodex[itemID].nameKey
|
||||
|
||||
// todo
|
||||
|
||||
sb.append("$connexionIcon $wireName")
|
||||
}
|
||||
}
|
||||
|
||||
if (sb.isNotEmpty()) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(sb.toString())
|
||||
}
|
||||
else {
|
||||
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null)
|
||||
}
|
||||
}
|
||||
|
||||
override fun effectOnUnequip(delta: Float) {
|
||||
(Terrarum.ingame!! as TerrarumIngame).selectedWireRenderClass = ""
|
||||
(Terrarum.ingame!! as TerrarumIngame).setTooltipMessage(null)
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ class WirePieceSignalWire(originalID: ItemID, private val atlasID: String, priva
|
||||
override val isUnique = false
|
||||
override val isDynamic = false
|
||||
override val material = Material()
|
||||
override val itemImage: TextureRegion?
|
||||
override val itemImage: TextureRegion
|
||||
get() = CommonResourcePool.getAsTextureRegionPack(atlasID).get(sheetX, sheetY)
|
||||
|
||||
init {
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
|
||||
*/
|
||||
object FloatDrawer : Disposable {
|
||||
|
||||
val tile = TextureRegionPack("assets/graphics/gui/message_white_tileable.tga", 36, 36)
|
||||
val tile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36)
|
||||
|
||||
init {
|
||||
AppLoader.disposableSingletonsPool.add(this)
|
||||
|
||||
@@ -15,13 +15,17 @@ class UITooltip : UICanvas() {
|
||||
|
||||
override var openCloseTime: Second = 0f
|
||||
|
||||
private val tooltipBackCol = Color(0xd5d4d3ff.toInt())
|
||||
private val tooltipForeCol = Color(0x404040ff)
|
||||
private val tooltipBackCol = Color.WHITE
|
||||
private val tooltipForeCol = Color(0xfafafaff.toInt())
|
||||
|
||||
private var msgBuffer = ArrayList<String>()
|
||||
var message: String = ""
|
||||
set(value) {
|
||||
field = value
|
||||
msgWidth = font.getWidth(value)
|
||||
msgBuffer.clear()
|
||||
|
||||
msgBuffer.addAll(value.split('\n'))
|
||||
msgWidth = msgBuffer.fold(0) { acc, s -> font.getWidth(s).let { if (it > acc) it else acc } }
|
||||
}
|
||||
|
||||
private val font = AppLoader.fontGame
|
||||
@@ -37,21 +41,34 @@ class UITooltip : UICanvas() {
|
||||
set(value) { throw Error("You are not supposed to set the height of the tooltip manually.") }
|
||||
|
||||
override fun renderUI(batch: SpriteBatch, camera: Camera) {
|
||||
val mouseX = 4f
|
||||
val mouseY = 6f
|
||||
|
||||
val tooltipYoff = 50
|
||||
val tooltipY = mouseY - height + tooltipYoff
|
||||
|
||||
val mouseXoff = 28f
|
||||
val mouseYoff = 0f
|
||||
val txtW = msgWidth + 2f * textMarginX
|
||||
|
||||
val tooltipW = txtW
|
||||
val tooltipH = font.lineHeight * msgBuffer.size
|
||||
|
||||
val tooltipX = mouseXoff
|
||||
val tooltipY = mouseYoff - (tooltipH / 2)
|
||||
|
||||
|
||||
batch.color = tooltipBackCol
|
||||
FloatDrawer(batch, mouseX - textMarginX, tooltipY, txtW, font.lineHeight)
|
||||
batch.color = tooltipForeCol
|
||||
font.draw(batch, message,
|
||||
mouseX,
|
||||
mouseY - height + tooltipYoff
|
||||
|
||||
FloatDrawer(batch,
|
||||
tooltipX - textMarginX,
|
||||
tooltipY,
|
||||
tooltipW,
|
||||
font.lineHeight * msgBuffer.size
|
||||
)
|
||||
|
||||
batch.color = tooltipForeCol
|
||||
|
||||
msgBuffer.forEachIndexed { index, s ->
|
||||
font.draw(batch, s,
|
||||
tooltipX,
|
||||
tooltipY + font.lineHeight * index
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateUI(delta: Float) {
|
||||
|
||||
Reference in New Issue
Block a user