mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-07 20:31:51 +09:00
tooltip ui update
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -4,3 +4,4 @@
|
||||
"3";"net.torvald.terrarum.modulebasegame.gameitems.PickaxeSteel"
|
||||
"5";"net.torvald.terrarum.modulebasegame.gameitems.TikiTorchTester"
|
||||
"6";"net.torvald.terrarum.modulebasegame.gameitems.ItemStorageChest"
|
||||
"7";"net.torvald.terrarum.modulebasegame.gameitems.WireGraphDebugger"
|
||||
|
||||
|
@@ -106,12 +106,23 @@ object ModMgr {
|
||||
|
||||
// run entry script in entry point
|
||||
if (entryPoint.isNotBlank()) {
|
||||
val newClass = Class.forName(entryPoint)
|
||||
val newClassConstructor = newClass.getConstructor(/* no args defined */)
|
||||
val newClassInstance = newClassConstructor.newInstance(/* no args defined */)
|
||||
var newClass: Class<*>? = null
|
||||
try {
|
||||
newClass = Class.forName(entryPoint)
|
||||
}
|
||||
catch (e: ClassNotFoundException) {
|
||||
printdbgerr(this, "$moduleName has nonexisting entry point, skipping...")
|
||||
printdbgerr(this, "\t$e")
|
||||
moduleInfo.remove(moduleName)
|
||||
}
|
||||
|
||||
entryPointClasses.add(newClassInstance as ModuleEntryPoint)
|
||||
(newClassInstance as ModuleEntryPoint).invoke()
|
||||
newClass?.let {
|
||||
val newClassConstructor = newClass.getConstructor(/* no args defined */)
|
||||
val newClassInstance = newClassConstructor.newInstance(/* no args defined */)
|
||||
|
||||
entryPointClasses.add(newClassInstance as ModuleEntryPoint)
|
||||
(newClassInstance as ModuleEntryPoint).invoke()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,8 +132,9 @@ object ModMgr {
|
||||
printdbgerr(this, "No such module: $moduleName, skipping...")
|
||||
moduleInfo.remove(moduleName)
|
||||
}
|
||||
catch (e: ClassNotFoundException) {
|
||||
printdbgerr(this, "$moduleName has nonexisting entry point, skipping...")
|
||||
catch (e: Throwable) {
|
||||
printdbgerr(this, "There was an error while loading module $moduleName")
|
||||
printdbgerr(this, "\t$e")
|
||||
moduleInfo.remove(moduleName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -366,6 +366,16 @@ open class GameWorld : Disposable {
|
||||
return wiringGraph[blockAddr]?.get(itemID)?.generatorState
|
||||
}
|
||||
|
||||
fun getWireConsumerStateOf(x: Int, y: Int, itemID: ItemID): ArrayList<WireConsumerState>? {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
return getWireConsumerStateUnsafe(blockAddr, itemID)
|
||||
}
|
||||
|
||||
fun getWireConsumerStateUnsafe(blockAddr: BlockAddress, itemID: ItemID): ArrayList<WireConsumerState>? {
|
||||
return wiringGraph[blockAddr]?.get(itemID)?.consumerStates
|
||||
}
|
||||
|
||||
fun setWireGraphOf(x: Int, y: Int, itemID: ItemID, byte: Byte) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
@@ -373,13 +383,12 @@ open class GameWorld : Disposable {
|
||||
}
|
||||
|
||||
fun setWireGraphOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, byte: Byte) {
|
||||
if (wiringGraph[blockAddr] == null) {
|
||||
if (wiringGraph[blockAddr] == null)
|
||||
wiringGraph[blockAddr] = HashMap()
|
||||
if (wiringGraph[blockAddr]!![itemID] == null)
|
||||
wiringGraph[blockAddr]!![itemID] = WiringSimCell(byte)
|
||||
}
|
||||
else {
|
||||
wiringGraph[blockAddr]!![itemID]!!.con = byte
|
||||
}
|
||||
|
||||
wiringGraph[blockAddr]!![itemID]!!.con = byte
|
||||
}
|
||||
|
||||
fun setWireGeneratorStateOf(x: Int, y: Int, itemID: ItemID, vector: Vector2) {
|
||||
@@ -389,12 +398,48 @@ open class GameWorld : Disposable {
|
||||
}
|
||||
|
||||
fun setWireGenenatorStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, vector: Vector2) {
|
||||
if (wiringGraph[blockAddr] == null) {
|
||||
if (wiringGraph[blockAddr] == null)
|
||||
wiringGraph[blockAddr] = HashMap()
|
||||
if (wiringGraph[blockAddr]!![itemID] == null)
|
||||
wiringGraph[blockAddr]!![itemID] = WiringSimCell(0, vector)
|
||||
}
|
||||
else {
|
||||
wiringGraph[blockAddr]!![itemID]!!.generatorState = vector
|
||||
|
||||
wiringGraph[blockAddr]!![itemID]!!.generatorState = vector
|
||||
}
|
||||
|
||||
fun addWireConsumerStateOf(x: Int, y: Int, itemID: ItemID, state: WireConsumerState) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
return addWireConsumerStateOfUnsafe(blockAddr, itemID, state)
|
||||
}
|
||||
|
||||
fun clearAllWireConsumerState(x: Int, y: Int) {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
return clearAllWireConsumerStateUnsafe(blockAddr)
|
||||
}
|
||||
|
||||
fun addWireConsumerStateOfUnsafe(blockAddr: BlockAddress, itemID: ItemID, state: WireConsumerState) {
|
||||
if (wiringGraph[blockAddr] == null)
|
||||
wiringGraph[blockAddr] = HashMap()
|
||||
if (wiringGraph[blockAddr]!![itemID] == null)
|
||||
wiringGraph[blockAddr]!![itemID] = WiringSimCell(0)
|
||||
|
||||
wiringGraph[blockAddr]!![itemID]!!.consumerStates.add(state)
|
||||
}
|
||||
|
||||
fun getAllWiringGraph(x: Int, y: Int): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
|
||||
val (x, y) = coerceXY(x, y)
|
||||
val blockAddr = LandUtil.getBlockAddr(this, x, y)
|
||||
return getAllWiringGraphUnsafe(blockAddr)
|
||||
}
|
||||
|
||||
fun getAllWiringGraphUnsafe(blockAddr: BlockAddress): Iterable<Map.Entry<ItemID, WiringSimCell>>? {
|
||||
return wiringGraph[blockAddr]?.asIterable()
|
||||
}
|
||||
|
||||
fun clearAllWireConsumerStateUnsafe(blockAddr: BlockAddress) {
|
||||
wiringGraph[blockAddr]?.forEach {
|
||||
it.value.consumerStates.clear()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user