From 0f0c4de85b2c2501bfe7125a3f78383438712483 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Sat, 1 May 2021 16:35:23 +0200 Subject: [PATCH] Add titles to buttons --- .../src/main/kotlin/fr/username404/snowygui/ClickGui.kt | 4 +--- .../fr/username404/snowygui/gui/elements/ClickButton.kt | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt index 19a5776..0d93b5e 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/ClickGui.kt @@ -4,15 +4,13 @@ import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickButton -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import net.minecraft.network.chat.TranslatableComponent object ClickGui: SnowyScreen() { private var GuiDragging: Boolean = false override val components: MutableSet = mutableSetOf( ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"), mutableListOf( - ClickButton(color = 0x6C9E9D), + ClickButton(color = 0x6C9E9D, Title = "Fullbright"), ClickButton(color = 0x6C9E9D) )), ClickBox(90.0, 4.0, TranslatableComponent("snowy.clickbox.rendering"), mutableListOf( diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt index 0e9fbd5..f47937d 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickButton.kt @@ -6,13 +6,15 @@ import fr.username404.snowygui.gui.ColoredElement import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import net.minecraft.client.Minecraft import net.minecraft.client.gui.components.events.GuiEventListener class ClickButton( x: Double = 0.0, y: Double = 0.0, width: Int = 73, height: Int = 8, color: Int, private val kind: Type = Type.TOGGLE, - val action: (() -> Unit)? = null + private val Title: String? = null, + private val action: (() -> Unit)? = null, ): ColoredElement(x, y, width, height, color, 0.60F), GuiEventListener { companion object { enum class Type { @@ -43,9 +45,7 @@ class ClickButton( if (wasWithinBounds) { lightDown() execAction() - } - - return false + }; return false } override fun render(poseStack: PoseStack?) { RenderSystem.disableTexture() @@ -53,5 +53,6 @@ class ClickButton( defaultRectFunc() RenderSystem.enableTexture() RenderSystem.disableBlend() + if (Title != null) Minecraft.getInstance().font.draw(poseStack, Title, x.toFloat() + 1, y.toFloat(), TransparentColor) } } \ No newline at end of file