Rename Box to ClickBox, make a ColoredElement class, draw strings and add more translations

This commit is contained in:
Username404-59 2021-04-10 19:17:46 +02:00
parent 029382c9b5
commit 3636c74851
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
6 changed files with 61 additions and 13 deletions

View File

@ -1,10 +1,13 @@
package fr.username404.snowygui
import fr.username404.snowygui.gui.ClickBox
import fr.username404.snowygui.gui.Element
import fr.username404.snowygui.gui.SnowyScreen
import net.minecraft.network.chat.TranslatableComponent
class ClickGui: SnowyScreen() {
override val components: MutableSet<Element> = mutableSetOf(
ClickBox(4.0, 4.0, TranslatableComponent("snowy.clickbox.misc"))
// TODO Add components to the ClickGui
)
}

View File

@ -1,9 +0,0 @@
package fr.username404.snowygui.gui
import com.mojang.blaze3d.vertex.PoseStack
class Box(x: Int, y: Int, scale: Int): Element(x, y, 20 * scale, 10 * scale) {
override fun render(poseStack: PoseStack?) {
}
}

View File

@ -0,0 +1,31 @@
package fr.username404.snowygui.gui
import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.DefaultVertexFormat
import com.mojang.blaze3d.vertex.PoseStack
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 + 10, y + 10, 80, 10, 0x6C9E9D) {
var opacity = 0.5F
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()
tessellator.end()
}
RenderSystem.enableTexture()
RenderSystem.disableBlend()
if (name != null) {
Minecraft.getInstance().font.draw(poseStack, name.string, x.toFloat() + 2, y.toFloat() + 1, TransparentColor)
}
}
}

View File

@ -3,17 +3,38 @@ package fr.username404.snowygui.gui
import com.mojang.blaze3d.vertex.BufferBuilder
import com.mojang.blaze3d.vertex.PoseStack
import com.mojang.blaze3d.vertex.Tesselator
import com.mojang.blaze3d.vertex.VertexConsumer
fun interface Renderable { fun render(poseStack: PoseStack?) }
abstract class Element(
var x: Int, var y: Int,
var x: Double, var y: Double,
val width: Int, val height: Int
): Renderable {
companion object Rendering {
@JvmStatic protected val tessellator: Tesselator = Tesselator.getInstance()
@JvmStatic protected val buffer: BufferBuilder = tessellator.builder
const val TransparentColor: Int = -0x1
}
fun display(stack: PoseStack? = null) { if (!hidden) render(stack) }
var hidden: Boolean = false
}
abstract class ColoredElement(x: Double, y: Double, width: Int, height: Int, val color: Int) : Element(x, y, width, height) {
companion object {
const val TransparentColor: Int = -0x1
@JvmStatic protected fun VertexConsumer.colorIt(color: Int, opacity: Float = 1F): VertexConsumer {
with(hextoRGB(color)) {
return this@colorIt.color(get(0), get(1), get(2), opacity)
}
}
}
}
fun hextoRGB(hex: Int): MutableList<Float> {
val returnedColorList = mutableListOf<Float>()
for (i in 2 downTo 0) {
returnedColorList.add(
(hex shr (i * 8) and 255) / 255.0F
)
}
return returnedColorList
}

View File

@ -3,5 +3,6 @@
"screen.snowy.config": "Snowy configuration screen",
"category.snowy.keycategory": "SnowyGUI",
"key.snowy.opengui": "Open the snowy gui",
"key.snowy.configkey": "Open the snowy configuration screen"
"key.snowy.configkey": "Open the snowy configuration screen",
"snowy.clickbox.misc": "Misc"
}

View File

@ -3,5 +3,6 @@
"screen.snowy.config": "Configuration de snowy",
"category.snowy.keycategory": "SnowyGUI",
"key.snowy.opengui": "Ouvrir l'interface de snowy",
"key.snowy.configkey": "Ouvrir l'écran de configuration de snowy"
"key.snowy.configkey": "Ouvrir l'écran de configuration de snowy",
"snowy.clickbox.misc": "Divers"
}