101 lines
2.9 KiB
Kotlin
101 lines
2.9 KiB
Kotlin
package net.shadowfacts.phycon.client.screen.console
|
|
|
|
import net.minecraft.block.entity.BlockEntity
|
|
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.button.ToggleButton
|
|
import net.shadowfacts.cacao.view.textfield.NumberField
|
|
import net.shadowfacts.cacao.viewcontroller.ViewController
|
|
import net.shadowfacts.kiwidsl.dsl
|
|
import net.shadowfacts.phycon.block.netinterface.InterfaceBlockEntity
|
|
import net.shadowfacts.phycon.component.NetworkStackProvider
|
|
import net.shadowfacts.phycon.networking.C2SConfigureDevice
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class ProviderViewController<T>(
|
|
private val device: T
|
|
): ViewController() where T: BlockEntity, T: NetworkStackProvider {
|
|
|
|
private lateinit var field: NumberField
|
|
private var syncButton: ToggleButton? = null
|
|
|
|
override fun viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
val label = Label(TranslatableText("gui.phycon.console.provider.priority")).apply {
|
|
textColor = Color.TEXT
|
|
}
|
|
view.addSubview(label)
|
|
|
|
field = NumberField(device.providerPriority) {
|
|
if (it.number != null) {
|
|
device.providerPriority = it.number!!
|
|
|
|
if (device is InterfaceBlockEntity && device.syncPriorities) {
|
|
device.receiverPriority = it.number!!
|
|
}
|
|
|
|
MinecraftClient.getInstance().player!!.networkHandler.sendPacket(C2SConfigureDevice(device))
|
|
}
|
|
}
|
|
view.addSubview(field)
|
|
|
|
val desc = Label(TranslatableText("gui.phycon.console.provider.priority_desc")).apply {
|
|
textColor = Color.TEXT
|
|
}
|
|
view.addSubview(desc)
|
|
|
|
if (device is InterfaceBlockEntity) {
|
|
val syncLabel = Label(TranslatableText("gui.phycon.console.provider.sync")).apply {
|
|
textColor = Color.TEXT
|
|
textAlignment = Label.TextAlignment.RIGHT
|
|
}
|
|
view.addSubview(syncLabel)
|
|
|
|
val syncButton = ToggleButton(device.syncPriorities) {
|
|
device.syncPriorities = it.state
|
|
device.receiverPriority = device.providerPriority
|
|
}
|
|
this.syncButton = syncButton
|
|
view.addSubview(syncButton)
|
|
|
|
view.solver.dsl {
|
|
syncButton.topAnchor equalTo (desc.bottomAnchor + 4)
|
|
syncButton.leftAnchor equalTo field.leftAnchor
|
|
|
|
syncLabel.centerYAnchor equalTo syncButton.centerYAnchor
|
|
syncLabel.leftAnchor equalTo view.leftAnchor
|
|
syncLabel.rightAnchor equalTo (syncButton.leftAnchor - 4)
|
|
}
|
|
}
|
|
|
|
view.solver.dsl {
|
|
field.widthAnchor equalTo 100
|
|
field.heightAnchor equalTo 20
|
|
field.rightAnchor equalTo view.rightAnchor
|
|
field.topAnchor equalTo view.topAnchor
|
|
|
|
label.centerYAnchor equalTo field.centerYAnchor
|
|
label.rightAnchor equalTo (field.leftAnchor - 4)
|
|
|
|
desc.topAnchor equalTo (field.bottomAnchor + 4)
|
|
desc.leftAnchor equalTo view.leftAnchor
|
|
desc.rightAnchor equalTo view.rightAnchor
|
|
}
|
|
}
|
|
|
|
override fun viewWillAppear() {
|
|
super.viewWillAppear()
|
|
|
|
field.number = device.providerPriority
|
|
if (device is InterfaceBlockEntity) {
|
|
syncButton!!.state = device.syncPriorities
|
|
}
|
|
}
|
|
|
|
}
|