97 lines
3.1 KiB
Kotlin
97 lines
3.1 KiB
Kotlin
package net.shadowfacts.phycon.screen
|
|
|
|
import com.mojang.blaze3d.systems.RenderSystem
|
|
import net.minecraft.client.gui.screen.Screen
|
|
import net.minecraft.client.gui.widget.ButtonWidget
|
|
import net.minecraft.client.gui.widget.TextFieldWidget
|
|
import net.minecraft.client.util.math.MatrixStack
|
|
import net.minecraft.text.LiteralText
|
|
import net.shadowfacts.phycon.api.util.IPAddress
|
|
import net.shadowfacts.phycon.network.block.redstone.RedstoneControllerBlockEntity
|
|
import net.shadowfacts.phycon.networking.C2SConfigureRedstoneController
|
|
import net.shadowfacts.phycon.util.next
|
|
import org.lwjgl.glfw.GLFW
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class RedstoneControllerConsoleScreen(
|
|
val device: RedstoneControllerBlockEntity
|
|
): Screen(device.cachedState.block.name) {
|
|
|
|
private val backgroundWidth = 252
|
|
private val backgroundHeight = 222
|
|
|
|
private val ipAddressTextFields = mutableListOf<TextFieldWidget>()
|
|
|
|
override fun init() {
|
|
super.init()
|
|
|
|
buttons.clear()
|
|
ipAddressTextFields.clear()
|
|
|
|
val minX = (width - backgroundWidth) / 2
|
|
val minY = (height - backgroundHeight) / 2
|
|
|
|
val mode = EnumButton(device::redstoneMode, minX + 5, minY + 25, 75, 20) {
|
|
client!!.player!!.networkHandler.sendPacket(C2SConfigureRedstoneController(device))
|
|
}
|
|
addButton(mode)
|
|
|
|
for (i in 0 until 5) {
|
|
// todo: field name
|
|
val field = TextFieldWidget(textRenderer, minX + 5, minY + 50 + 22 * i, backgroundWidth / 2, 20, LiteralText(""))
|
|
field.setMaxLength(15)
|
|
field.setHasBorder(true)
|
|
field.isVisible = true
|
|
field.setEditableColor(0xffffff)
|
|
field.text = device.managedDevices[i]?.toString()
|
|
field.setChangedListener { newVal ->
|
|
device.managedDevices[i] = IPAddress.parse(newVal)
|
|
client!!.player!!.networkHandler.sendPacket(C2SConfigureRedstoneController(device))
|
|
}
|
|
addChild(field)
|
|
ipAddressTextFields.add(field)
|
|
}
|
|
}
|
|
|
|
override fun isPauseScreen() = false
|
|
|
|
override fun keyPressed(key: Int, j: Int, k: Int): Boolean {
|
|
if (key == GLFW.GLFW_KEY_E) {
|
|
onClose()
|
|
return true
|
|
}
|
|
return super.keyPressed(key, j, k)
|
|
}
|
|
|
|
override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
|
|
val clickedField = ipAddressTextFields.find { it.x <= mouseX && it.x + it.width >= mouseX && it.y <= mouseY && it.y + it.height >= mouseY }
|
|
if (clickedField != null) {
|
|
ipAddressTextFields.forEach {
|
|
if (it !== clickedField) it.setSelected(false)
|
|
}
|
|
}
|
|
return super.mouseClicked(mouseX, mouseY, button)
|
|
}
|
|
|
|
override fun render(matrixStack: MatrixStack, mouseX: Int, mouseY: Int, delta: Float) {
|
|
renderBackground(matrixStack)
|
|
|
|
val minX = (width - backgroundWidth) / 2
|
|
val minY = (height - backgroundHeight) / 2
|
|
|
|
RenderSystem.color4f(1f, 1f, 1f, 1f)
|
|
client!!.textureManager.bindTexture(DeviceConsoleScreen.BACKGROUND)
|
|
drawTexture(matrixStack, minX, minY, 0, 0, backgroundWidth, backgroundHeight)
|
|
|
|
super.render(matrixStack, mouseX, mouseY, delta)
|
|
|
|
ipAddressTextFields.forEach { it.render(matrixStack, mouseX, mouseY, delta) }
|
|
|
|
textRenderer.draw(matrixStack, "IP Address: ${device.ipAddress}", minX + 5f, minY + 5f, 0x404040)
|
|
textRenderer.draw(matrixStack, "MAC Address: ${device.macAddress}", minX + 5f, minY + 15f, 0x404040)
|
|
}
|
|
|
|
}
|