diff --git a/src/main/kotlin/net/shadowfacts/phycon/screen/ClipboardButton.kt b/src/main/kotlin/net/shadowfacts/phycon/screen/ClipboardButton.kt new file mode 100644 index 0000000..b519cab --- /dev/null +++ b/src/main/kotlin/net/shadowfacts/phycon/screen/ClipboardButton.kt @@ -0,0 +1,45 @@ +package net.shadowfacts.phycon.screen + +import net.minecraft.client.util.math.MatrixStack +import net.minecraft.util.Identifier +import net.shadowfacts.cacao.geometry.Point +import net.shadowfacts.cacao.geometry.Size +import net.shadowfacts.cacao.util.texture.Texture +import net.shadowfacts.cacao.view.TextureView +import net.shadowfacts.cacao.view.button.AbstractButton +import net.shadowfacts.phycon.PhysicalConnectivity + +/** + * @author shadowfacts + */ +class ClipboardButton( + handler: (ClipboardButton) -> Unit, +): AbstractButton( + TextureView(DEFAULT) +) { + + companion object { + private val DEFAULT = Texture(Identifier(PhysicalConnectivity.MODID, "textures/gui/icons.png"), 16, 0) + private val HOVER = Texture(Identifier(PhysicalConnectivity.MODID, "textures/gui/icons.png"), 0, 0) + } + + private val textureView: TextureView + get() = content as TextureView + + init { + intrinsicContentSize = Size(9.0, 7.0) + content.intrinsicContentSize = Size(9.0, 7.0) + + this.handler = handler + + this.background = null + this.hoveredBackground = null + this.disabledBackground = null + } + + override fun draw(matrixStack: MatrixStack, mouse: Point, delta: Float) { + textureView.texture = if (mouse in bounds) HOVER else DEFAULT + super.draw(matrixStack, mouse, delta) + } + +} diff --git a/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceDetailsViewController.kt b/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceDetailsViewController.kt index 4c6765a..b625752 100644 --- a/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceDetailsViewController.kt +++ b/src/main/kotlin/net/shadowfacts/phycon/screen/console/DeviceDetailsViewController.kt @@ -1,13 +1,16 @@ package net.shadowfacts.phycon.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.View import net.shadowfacts.cacao.viewcontroller.ViewController import net.shadowfacts.kiwidsl.dsl import net.shadowfacts.phycon.block.DeviceBlockEntity +import net.shadowfacts.phycon.screen.ClipboardButton /** * @author shadowfacts @@ -30,14 +33,29 @@ class DeviceDetailsViewController(val device: DeviceBlockEntity): ViewController textColor = Color.TEXT } stack.addArrangedSubview(ipLabel) + val copyIP = ClipboardButton { + MinecraftClient.getInstance().keyboard.clipboard = device.ipAddress.toString() + } + view.addSubview(copyIP) + val macLabel = Label(TranslatableText("gui.phycon.console.details.mac", device.macAddress.toString())).apply { textColor = Color.TEXT } stack.addArrangedSubview(macLabel) + val copyMAC = ClipboardButton { + MinecraftClient.getInstance().keyboard.clipboard = device.macAddress.toString() + } + view.addSubview(copyMAC) view.solver.dsl { stack.leftAnchor equalTo view.leftAnchor stack.topAnchor equalTo view.topAnchor + + copyIP.leftAnchor equalTo (ipLabel.rightAnchor + 2) + copyIP.topAnchor equalTo ipLabel.topAnchor + + copyMAC.leftAnchor equalTo (macLabel.rightAnchor + 2) + copyMAC.topAnchor equalTo macLabel.topAnchor } } diff --git a/src/main/resources/assets/phycon/textures/gui/icons.png b/src/main/resources/assets/phycon/textures/gui/icons.png new file mode 100644 index 0000000..8c8d0c2 Binary files /dev/null and b/src/main/resources/assets/phycon/textures/gui/icons.png differ