package net.shadowfacts.phycon.client.screen.console import net.minecraft.client.MinecraftClient import net.minecraft.text.TranslatableText import net.shadowfacts.cacao.util.Color import net.shadowfacts.cacao.view.Label 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.p2p.P2PReceiverBlockEntity import net.shadowfacts.phycon.networking.C2SConfigureDevice /** * @author shadowfacts */ class P2PReceiverViewController( val device: P2PReceiverBlockEntity, ): ViewController() { override fun viewDidLoad() { super.viewDidLoad() val label = Label(TranslatableText("gui.phycon.console.p2p_receiver.target")).apply { textColor = Color.TEXT } view.addSubview(label) val textField = TextField(device.target?.toString() ?: "") { device.target = IPAddress.parse(it.text) MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device)) } view.addSubview(textField) val status = Label(device.status.displayName).apply { textColor = Color.TEXT } view.addSubview(status) device.clientObserver = { status.text = device.status.displayName } view.solver.dsl { textField.widthAnchor equalTo 100 textField.heightAnchor equalTo 20 textField.topAnchor equalTo view.topAnchor textField.rightAnchor equalTo view.rightAnchor label.centerYAnchor equalTo textField.centerYAnchor label.rightAnchor equalTo (textField.leftAnchor - 4) status.centerXAnchor equalTo view.centerXAnchor status.centerYAnchor equalTo (view.centerYAnchor - 10) } } }