Add a colorEnd() method to the companion object of ColoredElement, render more things in the ClickBox class and edit en_us.json

This commit is contained in:
Username404-59 2021-04-11 12:23:53 +02:00
parent f3d291e180
commit 31bb7be602
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 24 additions and 9 deletions

View File

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

View File

@ -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<Float> {

View File

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