From a86058f8bd779c87fc8966cf9f064e4400a415db Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 13 Mar 2021 15:46:40 -0500 Subject: [PATCH] Add copy IP/MAC buttons --- .../phycon/screen/ClipboardButton.kt | 45 ++++++++++++++++++ .../console/DeviceDetailsViewController.kt | 18 +++++++ .../assets/phycon/textures/gui/icons.png | Bin 0 -> 894 bytes 3 files changed, 63 insertions(+) create mode 100644 src/main/kotlin/net/shadowfacts/phycon/screen/ClipboardButton.kt create mode 100644 src/main/resources/assets/phycon/textures/gui/icons.png 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 0000000000000000000000000000000000000000..8c8d0c294c28ca2dab51cc3f62dc690edc0df033 GIT binary patch literal 894 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$5xX)7d$|)7e>}peR2rGbfdS zL1SX=L|c!;4l+mMqn9e_^1W4fB(UUFl4Hn`z|{dQTnoc8t{!}HNk8M#ge5yHxYn_< z+l#H{(>u4zY6n--1NM&DvnMa=p7LY=k_$@5njhEg+5LS-HTw@~(Pgt@A2+OubhDZ% zuxV$g;*TzdLmdemi-nB8S_b+YEUvkG`1tkR7Uw_NeSglOT{)T2uCZd;%Qn|Njy8KU zU(Wg7xp<9==8@+|lG$P>{FwN9)9L&<-F&|*)2^IY^1O5L5vPsKPx;bRomJ;4^=Ynh z`}uFpX|CtG=dzX_i~9aVpXce;sj2HO%eV-2M>KIT8f9rLX5uc4G7a)sl4<|&p?tv~ zrJX57QxBfl*q{~S(I@|hzpgx6OilgHk^rU`bsOLICo1gVHhI16Z*9))v%(4=cw#bh z>$ftVshJd)pS@9eLB8~k9eLTGVcGrwhI{8<%r0_xBK9J-xH|jo z<1dUS0>W2HKX@P@p&9gT*YVxeR@J}1`>ftCUlmcbs*`P97cg4blDyqrfHV;NblzPL zq&N#aB8wRqxP?KOkzv*x37{Z*iKnkC`%`9K5oOt*;*&anF+OxxoXmBQUt)W{B=s21JKNE*Wz~1PATQ15d-h5E z*fm4%-|Zjj{0Hkkrpqzy*!KJ0jcsoY0zopr03W;+`Tzg` literal 0 HcmV?d00001