53 lines
1.7 KiB
Kotlin
53 lines
1.7 KiB
Kotlin
package net.shadowfacts.asmr.ui.block
|
|
|
|
import net.minecraft.util.Identifier
|
|
import net.shadowfacts.asmr.ASMR
|
|
import net.shadowfacts.asmr.program.execution.IncomingExecutionFlow
|
|
import net.shadowfacts.asmr.program.execution.OutgoingExecutionFlow
|
|
import net.shadowfacts.cacao.util.texture.Texture
|
|
import net.shadowfacts.cacao.view.TextureView
|
|
import net.shadowfacts.cacao.view.View
|
|
import net.shadowfacts.kiwidsl.dsl
|
|
import java.lang.RuntimeException
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class ProgramBlockExecutionView(val incoming: IncomingExecutionFlow?, val outgoing: OutgoingExecutionFlow?): View() {
|
|
|
|
companion object {
|
|
val emptyConnection = Texture(Identifier(ASMR.modid, "textures/gui/programmer/program_connections.png"), u = 0, v = 0)
|
|
val executionConnection = Texture(Identifier(ASMR.modid, "textures/gui/programmer/program_connections.png"), u = 7, v = 0)
|
|
}
|
|
|
|
lateinit var textureView: TextureView
|
|
|
|
constructor(incoming: IncomingExecutionFlow?): this(incoming, null)
|
|
constructor(outgoing: OutgoingExecutionFlow?): this(null, outgoing)
|
|
|
|
init {
|
|
if (incoming == null && outgoing == null) {
|
|
throw RuntimeException("One of incoming or outgoing must be non-null")
|
|
}
|
|
}
|
|
|
|
override fun wasAdded() {
|
|
super.wasAdded()
|
|
|
|
textureView = addSubview(TextureView(emptyConnection))
|
|
updateTexture()
|
|
|
|
solver.dsl {
|
|
textureView.leftAnchor equalTo leftAnchor
|
|
textureView.rightAnchor equalTo rightAnchor
|
|
textureView.topAnchor equalTo topAnchor
|
|
textureView.bottomAnchor equalTo bottomAnchor
|
|
}
|
|
}
|
|
|
|
fun updateTexture() {
|
|
val active = if (incoming != null) incoming.source != null else outgoing!!.destination != null
|
|
textureView.texture = if (active) executionConnection else emptyConnection
|
|
}
|
|
|
|
} |