53 lines
1.6 KiB
Kotlin
53 lines
1.6 KiB
Kotlin
package net.shadowfacts.asmr.ui.block
|
|
|
|
import net.minecraft.util.Identifier
|
|
import net.shadowfacts.asmr.ASMR
|
|
import net.shadowfacts.asmr.program.ProgramBlockInput
|
|
import net.shadowfacts.asmr.program.ProgramBlockOutput
|
|
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 ProgramBlockParamView(val input: ProgramBlockInput<*>?, val output: ProgramBlockOutput<*>?): View() {
|
|
|
|
companion object {
|
|
val emptyConnection = Texture(Identifier(ASMR.modid, "textures/gui/programmer/program_connections.png"), u = 0, v = 0)
|
|
val parameterConnection = Texture(Identifier(ASMR.modid, "textures/gui/programmer/program_connections.png"), u = 14, v = 0)
|
|
}
|
|
|
|
lateinit var textureView: TextureView
|
|
|
|
constructor(input: ProgramBlockInput<*>): this(input, null)
|
|
constructor(output: ProgramBlockOutput<*>): this(null, output)
|
|
|
|
init {
|
|
if (input == null && output == null) {
|
|
throw RuntimeException("One of input or output 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 (input != null) input.source != null else output!!.destinations.isNotEmpty()
|
|
textureView.texture = if (active) parameterConnection else emptyConnection
|
|
}
|
|
|
|
} |