74 lines
2.4 KiB
Kotlin
74 lines
2.4 KiB
Kotlin
package net.shadowfacts.phycon.client.screen.console
|
|
|
|
import net.minecraft.client.MinecraftClient
|
|
import net.minecraft.text.TranslatableText
|
|
import net.shadowfacts.cacao.geometry.Axis
|
|
import net.shadowfacts.cacao.util.Color
|
|
import net.shadowfacts.cacao.view.Label
|
|
import net.shadowfacts.cacao.view.StackView
|
|
import net.shadowfacts.cacao.view.button.EnumButton
|
|
import net.shadowfacts.cacao.view.textfield.TextField
|
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
|
import net.shadowfacts.kiwidsl.dsl
|
|
import net.shadowfacts.phycon.api.util.IPAddress
|
|
import net.shadowfacts.phycon.block.redstone_controller.RedstoneControllerBlockEntity
|
|
import net.shadowfacts.phycon.networking.C2SConfigureDevice
|
|
import net.shadowfacts.phycon.util.RedstoneMode
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class RedstoneControllerViewController(val device: RedstoneControllerBlockEntity): ViewController() {
|
|
|
|
override fun viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
val modeLabel = Label(TranslatableText("gui.phycon.console.redstone.mode")).apply {
|
|
textColor = Color.TEXT
|
|
}
|
|
view.addSubview(modeLabel)
|
|
|
|
val managedDevicesLabel = Label(TranslatableText("gui.phycon.console.redstone.devices")).apply {
|
|
textColor = Color.TEXT
|
|
}
|
|
view.addSubview(managedDevicesLabel)
|
|
|
|
val controls = StackView(Axis.VERTICAL, StackView.Distribution.FILL, spacing = 4.0)
|
|
view.addSubview(controls)
|
|
|
|
val mode = EnumButton(device.redstoneMode, RedstoneMode::friendlyName)
|
|
mode.handler = {
|
|
device.redstoneMode = it.value
|
|
MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device))
|
|
}
|
|
controls.addArrangedSubview(mode)
|
|
|
|
val textFields = (0 until 5).map { i ->
|
|
TextField(device.managedDevices[i]?.toString() ?: "") {
|
|
device.managedDevices[i] = IPAddress.parse(it.text)
|
|
MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device))
|
|
}
|
|
}
|
|
textFields.forEach(controls::addArrangedSubview)
|
|
|
|
view.solver.dsl {
|
|
controls.widthAnchor equalTo 100
|
|
controls.rightAnchor equalTo view.rightAnchor
|
|
controls.topAnchor equalTo view.topAnchor
|
|
|
|
mode.heightAnchor equalTo 20
|
|
|
|
textFields.forEach {
|
|
it.heightAnchor equalTo 20
|
|
}
|
|
|
|
modeLabel.centerYAnchor equalTo mode.centerYAnchor
|
|
modeLabel.rightAnchor equalTo (mode.leftAnchor - 4)
|
|
|
|
managedDevicesLabel.centerYAnchor equalTo textFields.first().centerYAnchor
|
|
managedDevicesLabel.rightAnchor equalTo (textFields.first().leftAnchor - 4)
|
|
}
|
|
}
|
|
|
|
}
|