diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt index 25c9d94..c168605 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/ClickBox.kt @@ -7,25 +7,39 @@ import net.minecraft.client.Minecraft import net.minecraft.network.chat.TranslatableComponent import org.lwjgl.opengl.GL20 -class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? = null): ColoredElement(x, y, 80, 10, 0x6C9E9D) { - var opacity = 0.5F +class ClickBox(x: Double, y: Double, private val name: TranslatableComponent? = null): ColoredElement(x, y, 80, 10, 0x6C9E9D, 0.5F) { + private companion object { + const val inclination: Double = 2.5 + } override fun render(poseStack: PoseStack?) { RenderSystem.disableTexture() RenderSystem.enableBlend() RenderSystem.defaultBlendFunc() with(buffer) { begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR) - vertex(x, y + height, 0.0).colorIt(color, opacity).endVertex() - vertex(x + width, y + height, 0.0).colorIt(color, opacity).endVertex() - vertex(x + width, y, 0.0).colorIt(color, opacity).endVertex() - vertex(x, y, 0.0).colorIt(color, opacity).endVertex() + // Render the header: + vertex(x, y + height, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() + vertex(x + width, y, 0.0).colorEnd() + vertex(x + inclination, y, 0.0).colorEnd() + + // Render the box: + val fullHeight = (y + height) * 6 + vertex(x, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, fullHeight, 0.0).colorEnd() + vertex(x + width + inclination, y + height, 0.0).colorEnd() + tessellator.end() + + begin(GL20.GL_LINES, DefaultVertexFormat.POSITION_COLOR) + vertex(x + inclination, y + height, 0.0).colorIt(0xF2F2FC).endVertex() + vertex(x + width, y + height, 0.0).colorIt(0xF2F2FC).endVertex() tessellator.end() } RenderSystem.enableTexture() RenderSystem.disableBlend() if ((name != null) && (poseStack != null)) { - Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 2, y.toFloat() + 1.5F, TransparentColor) + Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 5, y.toFloat() + 1.5F, TransparentColor) } } } \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt index 4b89363..213d3e8 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/Element.kt @@ -18,7 +18,7 @@ abstract class Element( var hidden: Boolean = false } -abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val color: Int) : Element(x, y, width, height) { +abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val color: Int, val opacity: Float) : Element(x, y, width, height) { companion object { const val TransparentColor: Int = -0x1 @JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer { @@ -27,6 +27,7 @@ abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val } } } + protected fun VertexConsumer.colorEnd() = colorIt(color, opacity).endVertex() } fun hextoRGB(hex: Int): MutableList { diff --git a/common/src/main/resources/assets/snowygui/lang/en_us.json b/common/src/main/resources/assets/snowygui/lang/en_us.json index 2c01491..95dab0e 100644 --- a/common/src/main/resources/assets/snowygui/lang/en_us.json +++ b/common/src/main/resources/assets/snowygui/lang/en_us.json @@ -4,6 +4,6 @@ "category.snowy.keycategory": "SnowyGUI", "key.snowy.opengui": "Open the snowy gui", "key.snowy.configkey": "Open the snowy configuration screen", - "snowy.clickbox.misc": "Misc", + "snowy.clickbox.misc": "Miscellaneous", "snowy.clickbox.rendering": "Rendering" } \ No newline at end of file