Replace duplicated code using the RenderingUtil.kt methods
This commit is contained in:
parent
e5f0cd0ab2
commit
dd2234be71
|
@ -1,6 +1,5 @@
|
||||||
package fr.username404.snowygui.gui.elements
|
package fr.username404.snowygui.gui.elements
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
|
||||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
import com.mojang.blaze3d.vertex.DefaultVertexFormat
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.Snowy.Companion.MissingComponent
|
import fr.username404.snowygui.Snowy.Companion.MissingComponent
|
||||||
|
@ -10,6 +9,8 @@ import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
import fr.username404.snowygui.gui.feature.Category
|
import fr.username404.snowygui.gui.feature.Category
|
||||||
import fr.username404.snowygui.gui.feature.Colors
|
import fr.username404.snowygui.gui.feature.Colors
|
||||||
import fr.username404.snowygui.utils.RenderingUtil.buffer
|
import fr.username404.snowygui.utils.RenderingUtil.buffer
|
||||||
|
import fr.username404.snowygui.utils.RenderingUtil.endDraw
|
||||||
|
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
|
||||||
import fr.username404.snowygui.utils.RenderingUtil.tessellator
|
import fr.username404.snowygui.utils.RenderingUtil.tessellator
|
||||||
import io.github.config4k.extract
|
import io.github.config4k.extract
|
||||||
import kotlinx.coroutines.CoroutineStart
|
import kotlinx.coroutines.CoroutineStart
|
||||||
|
@ -46,12 +47,9 @@ class ClickBox(
|
||||||
) {
|
) {
|
||||||
override val color: Int get() = this@ClickBox.color
|
override val color: Int get() = this@ClickBox.color
|
||||||
override fun render(poseStack: PoseStack?) {
|
override fun render(poseStack: PoseStack?) {
|
||||||
RenderSystem.disableTexture()
|
prepareDraw()
|
||||||
RenderSystem.enableBlend()
|
|
||||||
RenderSystem.defaultBlendFunc()
|
|
||||||
defaultRectFunc()
|
defaultRectFunc()
|
||||||
RenderSystem.disableBlend()
|
endDraw()
|
||||||
RenderSystem.enableTexture()
|
|
||||||
}
|
}
|
||||||
init { height = 8 }
|
init { height = 8 }
|
||||||
}
|
}
|
||||||
|
@ -82,9 +80,7 @@ class ClickBox(
|
||||||
}
|
}
|
||||||
override fun render(poseStack: PoseStack?) {
|
override fun render(poseStack: PoseStack?) {
|
||||||
runBlocking {
|
runBlocking {
|
||||||
RenderSystem.disableTexture()
|
prepareDraw()
|
||||||
RenderSystem.enableBlend()
|
|
||||||
RenderSystem.defaultBlendFunc()
|
|
||||||
with(buffer) {
|
with(buffer) {
|
||||||
begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR)
|
begin(GL20.GL_POLYGON, DefaultVertexFormat.POSITION_COLOR)
|
||||||
// Render the header:
|
// Render the header:
|
||||||
|
@ -105,8 +101,7 @@ class ClickBox(
|
||||||
vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
|
vertex(x + width, y + height, 0.0).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||||
tessellator.end()
|
tessellator.end()
|
||||||
}
|
}
|
||||||
RenderSystem.enableTexture()
|
endDraw()
|
||||||
RenderSystem.disableBlend()
|
|
||||||
|
|
||||||
val renderButtons = if (buttons.isNotEmpty()) launch(start = CoroutineStart.UNDISPATCHED) {
|
val renderButtons = if (buttons.isNotEmpty()) launch(start = CoroutineStart.UNDISPATCHED) {
|
||||||
buttonsProgressBar.apply {
|
buttonsProgressBar.apply {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package fr.username404.snowygui.gui.feature
|
package fr.username404.snowygui.gui.feature
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem
|
|
||||||
import com.mojang.blaze3d.vertex.PoseStack
|
import com.mojang.blaze3d.vertex.PoseStack
|
||||||
import fr.username404.snowygui.ClickGui
|
import fr.username404.snowygui.ClickGui
|
||||||
import fr.username404.snowygui.Snowy
|
import fr.username404.snowygui.Snowy
|
||||||
|
@ -8,6 +7,8 @@ import fr.username404.snowygui.config.Configuration
|
||||||
import fr.username404.snowygui.gui.ColoredElement
|
import fr.username404.snowygui.gui.ColoredElement
|
||||||
import fr.username404.snowygui.utils.FontUtil
|
import fr.username404.snowygui.utils.FontUtil
|
||||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||||
|
import fr.username404.snowygui.utils.RenderingUtil.endDraw
|
||||||
|
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
|
||||||
import kotlin.reflect.full.findAnnotation
|
import kotlin.reflect.full.findAnnotation
|
||||||
|
|
||||||
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||||
|
@ -89,11 +90,9 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||||
}; return false
|
}; return false
|
||||||
}
|
}
|
||||||
override fun render(poseStack: PoseStack?) {
|
override fun render(poseStack: PoseStack?) {
|
||||||
RenderSystem.disableTexture()
|
prepareDraw()
|
||||||
RenderSystem.enableBlend()
|
|
||||||
defaultRectFunc()
|
defaultRectFunc()
|
||||||
RenderSystem.enableTexture()
|
endDraw()
|
||||||
RenderSystem.disableBlend()
|
|
||||||
if (poseStack != null) {
|
if (poseStack != null) {
|
||||||
FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F)
|
FontUtil.drawScaled(poseStack, title, x + 1, y + 1, 0.75F)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue