Add copy IP/MAC buttons

This commit is contained in:
Shadowfacts 2021-03-13 15:46:40 -05:00
parent 9305b1e0ef
commit a86058f8bd
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 63 additions and 0 deletions

View File

@ -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<ClipboardButton>(
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)
}
}

View File

@ -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
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B